2012年 新年あけましておめでとうございます
SUGARSPOTとして仕事を開始して、みなさまのご支援いただきながら無事に1年を迎える事ができました。誠にありがとうございました
本年もよろしく昨年同様によろしくお願い致します
2012年1月1日 SUGARSPOT 佐藤 慎也
2012年1月1日日曜日
2011年12月8日木曜日
[Android]ブラウザからアプリを起動する際のメモ
ブラウザからアプリを起動する際のschemeについてメモ
まず、基本的なところから書いておくと起動したいアプリのapplicationにintent-filterを設定する
この時、ブラウザからの呼び出しに呼応するように
<category android:name="android.intent.category.BROWSABLE"/>
の記述が必要
次に、schemeの指定について
ブラウザから<a href="hoge://">ほげ起動</a>のような指定で起動させたい場合は、次のように指定する
<intent-filter>
<action android:name="android.intent.action.VIEW"/>
<category android:name="android.intent.category.DEFAULT"/>
<category android:name="android.intent.category.BROWSABLE"/>
<data android:scheme="hoge"/>
</intent-filter>
でも、これだと
<a href="hoge://fuga">
<a href="hoge://hidebu">
でも起動しちゃうので、もう少し条件をつけて<a href="hoge://fuga">の場合だけ起動するようにする
この場合は、hostを指定すればOK
<intent-filter>
<action android:name="android.intent.action.VIEW"/>
<category android:name="android.intent.category.DEFAULT"/>
<category android:name="android.intent.category.BROWSABLE"/>
<data android:scheme="hoge" android:host="fuga" />
</intent-filter>
これだけでもほぼ大丈夫だけど、さらに分岐させたい場合
例えば
<a href="hoge://fuga/init">で初期処理をして起動
<a href="hoge://fuga/restart">で前回の続きから起動
とかしたい場合は、pathを指定してpathを判別してから処理を振り分けるなどすれば良い
intent-filterの指定はこんな感じ
<intent-filter>
<action android:name="android.intent.action.VIEW"/>
<category android:name="android.intent.category.DEFAULT"/>
<category android:name="android.intent.category.BROWSABLE"/>
<data android:scheme="hoge" android:host="fuga" android:path="/init"/>
</intent-filter>
ここで忘れちゃいけないのが、pathは
android:path="init"
ではなく
android:path="/init"
であること。"/"を忘れないように!
まとめると、URLが <a href="scheme://host/path">といった感じになるので、それに合わせてintent-filterを指定すればOK
他にも色々と指定できるパラメータがあるので、そのあたりは公式なドキュメントをどうぞ
http://developer.android.com/guide/topics/manifest/data-element.html
まず、基本的なところから書いておくと起動したいアプリのapplicationにintent-filterを設定する
この時、ブラウザからの呼び出しに呼応するように
<category android:name="android.intent.category.BROWSABLE"/>
の記述が必要
次に、schemeの指定について
ブラウザから<a href="hoge://">ほげ起動</a>のような指定で起動させたい場合は、次のように指定する
<intent-filter>
<action android:name="android.intent.action.VIEW"/>
<category android:name="android.intent.category.DEFAULT"/>
<category android:name="android.intent.category.BROWSABLE"/>
<data android:scheme="hoge"/>
</intent-filter>
でも、これだと
<a href="hoge://fuga">
<a href="hoge://hidebu">
でも起動しちゃうので、もう少し条件をつけて<a href="hoge://fuga">の場合だけ起動するようにする
この場合は、hostを指定すればOK
<intent-filter>
<action android:name="android.intent.action.VIEW"/>
<category android:name="android.intent.category.DEFAULT"/>
<category android:name="android.intent.category.BROWSABLE"/>
<data android:scheme="hoge" android:host="fuga" />
</intent-filter>
これだけでもほぼ大丈夫だけど、さらに分岐させたい場合
例えば
<a href="hoge://fuga/init">で初期処理をして起動
<a href="hoge://fuga/restart">で前回の続きから起動
とかしたい場合は、pathを指定してpathを判別してから処理を振り分けるなどすれば良い
intent-filterの指定はこんな感じ
<intent-filter>
<action android:name="android.intent.action.VIEW"/>
<category android:name="android.intent.category.DEFAULT"/>
<category android:name="android.intent.category.BROWSABLE"/>
<data android:scheme="hoge" android:host="fuga" android:path="/init"/>
</intent-filter>
ここで忘れちゃいけないのが、pathは
android:path="init"
ではなく
android:path="/init"
であること。"/"を忘れないように!
まとめると、URLが <a href="scheme://host/path">といった感じになるので、それに合わせてintent-filterを指定すればOK
他にも色々と指定できるパラメータがあるので、そのあたりは公式なドキュメントをどうぞ
http://developer.android.com/guide/topics/manifest/data-element.html
2011年12月2日金曜日
[Android]UNEXPECTED TOP-LEVEL EXCEPTIONでビルドできない
外部ライブラリを使用している古いアプリ(ADT14以前?)をビルドしようとしたら、次のようなエラーがでた
そこで、私がとった対策としては、.classpathのファイルを開いて外部ライブラリの参照を消して再度ビルド。それで問題なく動くようになりました
※ライブラリの参照やら、配置やらを色々と変えて確認したり、色々な方法を試したあとで上記方法を作業しました。ですので、上記方法だけで本当に解消するのか保障はできませんが、いまは再現させられない状態なので、ひとまず参考程度と思ってください
[2011-12-02 20:03:16 - xxxxxx] Dxどうやら、ライブラリを重複して登録しようとしてエラーが発生しているようだ
UNEXPECTED TOP-LEVEL EXCEPTION:
java.lang.IllegalArgumentException: already added: Lxxx/xxxx/xxx/XxxxxxxActivity;
そこで、私がとった対策としては、.classpathのファイルを開いて外部ライブラリの参照を消して再度ビルド。それで問題なく動くようになりました
※ライブラリの参照やら、配置やらを色々と変えて確認したり、色々な方法を試したあとで上記方法を作業しました。ですので、上記方法だけで本当に解消するのか保障はできませんが、いまは再現させられない状態なので、ひとまず参考程度と思ってください
2011年11月21日月曜日
[Android]HttpClientでサイズの大きい画像が取得できない場合
サイズが大きいといっても1MBや2MBといった話しではなく数百キロByteの場合でもHttpResponseのcontentから取得できたInputStreamをBitmapFactoryに流し込んでもエラーとなる事がある
こんな感じにね
そんな時は、BufferedHttpEntityを使いましょう
実際のコードを以下に。(画像のURLは適当です)
--- decoder->decode returned false
こんな感じにね
そんな時は、BufferedHttpEntityを使いましょう
実際のコードを以下に。(画像のURLは適当です)
HttpUriRequest httpRequest = new HttpGet("http://hogehoge.com/sample.jpg");
HttpClient httpclient = new DefaultHttpClient();
HttpResponse httpResponse = httpclient.execute(httpRequest);
HttpEntity httpEntity = httpResponse.getEntity();
BufferedHttpEntity bufHttpEntity = new BufferedHttpEntity(httpEntity);Bitmap image = BitmapFactory.decodeStream(bufHttpEntity.getContent());
2011年11月8日火曜日
[Android] BeanをIntentにセットできるようにParcelableにする
よく忘れるので自分用にメモ
必要なこと
必要なこと
- Parcelableを実装したクラスにする( implements Parcelable)
- Parcelable.Createrを実装したCREATERというstaticな変数を用意する
- Parcelを引数にとるコンストラクタを用意する
- writeToParcelで登録する順番と、上に書いたコンストラクタで読み出す順番を同じにする
import android.os.Parcel;
import android.os.Parcelable;
public class Employ implements Parcelable {
public int id;
public String name;
public int age;
public String address;
public Employ() {
}
private Employ(Parcel in) {
id = in.readInt();
name = in.readString();
age = in.readInt();
address = in.readString();
}
@Override
public int describeContents() {
return 0;
}
@Override
public void writeToParcel(Parcel dest, int flags) {
dest.writeInt(id);
dest.writeString(name);
dest.writeInt(age);
dest.writeString(address);
}
public static final Parcelable.Creator<Employ> CREATOR = new Parcelable.Creator<Employ>() {
public EmploycreateFromParcel(Parcel in) {
return new Employ(in);
}
public Employ[] newArray(int size) {
return new Employ[size];
}
};
}
[Android]EditTextのカーソルを左上にする
よく忘れるので自分用にメモ。
EditTextのgravityを指定するだけ
EditTextのgravityを指定するだけ
<EditText
android:id="@+id/memo"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:height="100dip"
android:gravity="top|left"/>
2011年11月3日木曜日
BinaryNumber BatteryWidgetをバージョンアップ
ずっと前から気にはしていたのですが、海外ユーザーさんからメールを貰って修正する気力が沸いてきて、ようやく修正しました
メールを貰ったのは9/20で、気力が沸いたのがついさっきです
問題だったのは、バッテリーウィジェットがバッテリーの残量が変化するのを監視しているの訳ですが、この監視するサービスが強制停止されてしまうと、その後でバッテリーが変化しても表示が変わらないという問題
で、これを解決する方法はネットを探すと色々と情報が出てきます
やった事は2つ
1)AndroidManifest.xmlのintent-filterに以下を追加
これは、ユーザーがスリープ状態から復帰するのを通知して貰う為に追加
2)そして、その通知を受けたら監視を再開するようにBroadcastReceiverのonReceiveに処理を追加
たったそれだけ
これで使いやすく?なった BinaryNumber BatteryWidgetを、どうぞご利用ください(一部のマニア向けですが・・・)
http://sugarspot.net/android_app/bnbw.html
メールを貰ったのは9/20で、気力が沸いたのがついさっきです
問題だったのは、バッテリーウィジェットがバッテリーの残量が変化するのを監視しているの訳ですが、この監視するサービスが強制停止されてしまうと、その後でバッテリーが変化しても表示が変わらないという問題
で、これを解決する方法はネットを探すと色々と情報が出てきます
やった事は2つ
1)AndroidManifest.xmlのintent-filterに以下を追加
<action android:name="android.intent.action.USER_PRESENT" />
これは、ユーザーがスリープ状態から復帰するのを通知して貰う為に追加
2)そして、その通知を受けたら監視を再開するようにBroadcastReceiverのonReceiveに処理を追加
if (action.equals(Intent.ACTION_USER_PRESENT)) {
Intent forceUpIntent = new Intent(context,
BatteryWidget.UpdateService.class);
context.startService(forceUpIntent);
}
Intent forceUpIntent = new Intent(context,
BatteryWidget.UpdateService.class);
context.startService(forceUpIntent);
}
たったそれだけ
これで使いやすく?なった BinaryNumber BatteryWidgetを、どうぞご利用ください(一部のマニア向けですが・・・)
http://sugarspot.net/android_app/bnbw.html
登録:
投稿 (Atom)