1

マニフェストに受信者を登録しました。

<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
    package="com.example.receiverdemo"
    android:versionCode="1"
    android:versionName="1.0" >

    <uses-sdk
        android:minSdkVersion="8"
        android:targetSdkVersion="17" />

    <application
        android:allowBackup="true"
        android:icon="@drawable/ic_launcher"
        android:label="@string/app_name"
        android:theme="@style/AppTheme" >
        <activity
            android:name="com.example.receiverdemo.MainActivity"
            android:label="@string/app_name" >
            <intent-filter>
                <action android:name="android.intent.action.MAIN" />
                <category android:name="android.intent.category.LAUNCHER" />
            </intent-filter>
        </activity>

        <receiver
            android:name="Receiver"
            android:exported="false" >
            <intent-filter>
                <action android:name="com.example.receiverdemo.RECEIVER" />
            </intent-filter>
        </receiver>
    </application>
</manifest>

そして、adbシェルからブロードキャストを送信しています

adb shell am broadcast -a com.example.receiverdemo.RECEIVER

上記のコマンドは適切に実行され、その後onReceive()メソッドがReceiver呼び出されるはずです。

これは予期される動作です。

Android 4.2 を実行している場合でもこの動作を確認できますが、Android 4.1.1 を実行している場合でも期待どおりにemulator動作せず、コマンドが適切に実行されていてもメソッドが呼び出されません。galaxy nexusHTC one XHTC-desire-xonReceive()am broadcast

出力は次のように表示されます

shell@android:/ $ am broadcast -a com.example.receiverdemo.RECEIVER
am broadcast -a com.example.receiverdemo.RECEIVER
Broadcasting: Intent { act=com.example.receiverdemo.RECEIVER }
Broadcast completed: result=0

Receiverクラスは以下の通り、

public class Receiver extends BroadcastReceiver {

    public static final String ACTION_RECEIVER = "com.example.receiverdemo.RECEIVER";

    @Override
    public void onReceive(Context arg0, Intent arg1) {
        Log.i("DEMO", "Working");
    }
}

ここで何が問題なのかわかりません。API のバージョンや ROM、開発者の設定などに関連するものはありますか?

4

2 に答える 2