1

アプリケーションを作成して自分のデバイスにインストールしたことを知りたいのですが、放送受信機だけを使用してこのアプリケーションを起動することは可能ですか?

4

3 に答える 3

1

次のコードを使用して、アプリケーションが実行されていないときにアクティビティを開きます。

Intent myIntent = new Intent(context.getApplicationContext(), YourClassActivity.class);
Bundle bundle = new Bundle();
myIntent.putExtras(bundle);
myIntent.addFlags(
      Intent.FLAG_ACTIVITY_NEW_TASK
    | Intent.FLAG_ACTIVITY_CLEAR_TOP
    | Intent.FLAG_ACTIVITY_SINGLE_TOP);
context.getApplicationContext().startActivity(myIntent);

次のようなバンドル内の任意のデータを渡すことができます

bundle.putString("title", "from receiver");
于 2013-02-27T11:49:08.133 に答える
0

ブロードキャストを送信するときは、まだ実行されていないパッケージを開始するフラグを追加する必要があります。

getContext().sendBroadcast(new Intent("MY_ACTION").setFlags(Intent.FLAG_INCLUDE_STOPPED_PACKAGES), null);
于 2015-06-04T15:48:01.097 に答える
0

BroadcastReceiver がリッスンしている場合、アプリケーションも「実行中」です。アクティビティを開く場合は、

@Override
public void onReceive(Context context, Intent intent) {
    context.startActivity(new Intent(context, YourActivity.class));
}

マニフェストにレシーバーを静的に登録する必要があります(ドキュメントから)

You can either dynamically register an instance of this class with Context.registerReceiver() or statically publish an implementation through the <receiver> tag in your AndroidManifest.xml. キャッチできないインテントアクションも指定する必要があります

<receiver android:name=".YourReceiver"
    android:exported="true"
    android:enabled="true" >
    <intent-filter>
       <action android:name="android.net.wifi.WIFI_STATE_CHANGED" />
    </intent-filter>
</receiver>
于 2013-02-27T11:43:12.713 に答える