0

これはかなり簡単なはずですが、どうにかしてブロードキャスト レシーバーの onReceive メソッドをトリガーすることができません。以下の詳細:

アプリ B は、ブロードキャスト レシーバーを提供します。マニフェスト:

<receiver android:name=".MyNotificationReceiver">
            <intent-filter>
                <action android:name="com.go.foo.A_ACTION" />
            </intent-filter>
        </receiver>

ジャワ:

public class MyNotificationReceiver extends BroadcastReceiver {

    private final String TAG= "MyNotificationReceiver";

    @Override
    public void onReceive(Context context, Intent intent) {
        Toast.makeText(context, "this is not shown"     , Toast.LENGTH_LONG).show();
    }
}

アプリ A はブロードキャスト送信アプリです。

ジャワ

            Intent intent = new Intent();
            intent.setAction("com.go.foo.A_ACTION");
            sendBroadcast(intent);
            Log.d(TAG, "broadcast intent sent...");

ブロードキャストが送信されたが、受信者の onReceive() コールバックがトリガーされていないというログ ステートメントを確認できます。私は何か間違ったことをしていますか?

4

2 に答える 2

0

なぜ機能しないのか興味深い。これを試してみてください。と のデフォルト値は知ってexportedenabledますtrue。しかし、まだ試してみてください。

<receiver android:name=".MyNotificationReceiver" android:enabled="true" android:exported="true">
    <intent-filter>
        <action android:name="com.go.foo.A_ACTION" />
    </intent-filter>
</receiver>
于 2015-10-23T16:10:13.713 に答える
0

今日新しいことを学びました。Android 4.1 以降、システムはアクティビティのないアプリ コンポーネントにブロードキャストを送信しなくなりました。マニフェストにアクティビティを追加した後、受信したブロードキャストが機能し始めました。

于 2015-10-26T02:27:16.290 に答える