開発した Android アプリ をデバッグ時、端末をPCに接続しPC側 DOSプロンプトから
コマンド起動する場合、あるいは他のアプリから起動させる場合、AndroidManifest.xml に
記述するメインで起動する(通常の起動)の Activity の Intent Filter を
もう1つ追加する。
AndroidManifest.xml 例)
<activity
android:label="@string/app_name"
android:name="org.uran..SampleActivity" android:configChanges="keyboardHidden|orientation" >
<intent-filter >
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
<!-- 追加する Intent Filter -->
<intent-filter>
<action android:name="org.uran.EXT_WAKE"/>
<category android:name="android.intent.category.DEFAULT"/>
<category android:name="android.intent.category.BROWSABLE"/>
<data android:scheme="http"/>
</intent-filter>
</activity>
起動するコマンドは、adb shell start -a アクション名 parameter の形式
例)
adb shell start -a org.uran.EXT_WAKE http://m.yahoo.co.jp/
のように、android:scheme で指定したキーで始まるパラメータを渡す。
起動される Activity は、コマンドで起動されたか判断するのは、以下のように、
onCreate メソッドで getIntent でパラメータを受け取れたかどうかである。
String url = getIntent().getDataString();
if (url != null){
// PC コマンドから起動
}else{
// 通常の起動
}