0

Manifest にこの構成を持つ Android アプリケーションがあります。

    <receiver android:name="ir.hamgam.fion.ec.mobile.services.BootCompletedReceiver">
        <intent-filter>
            <action android:name="android.intent.action.BOOT_COMPLETED"/>
        </intent-filter>
    </receiver>

私のレシーバーにはこれがあります:

public class BootCompletedReceiver extends BroadcastReceiver {
    @Override
    public void onReceive(Context context, Intent intent) {
        if (intent.getAction().equals(Intent.ACTION_BOOT_COMPLETED)) {
            Log.w("boot_broadcast_poc", "starting service...");
            APKUpdateReceiver.setAlarm(context);
            DataReceiver.setAlarm(context);
            NotificationUpdateReceiver.setAlarm(context);
        }
    }
}

アプリケーションが起動し、ブートが完了したのにメソッド onreceive 内で発火しない場合、ヒントを教えてください。

4

1 に答える 1

1

以下のようにしてください。正常に動作します。受信者が呼び出されたことを通知するために、受信者の中にトーストを入れました -

public class BootCompletedReceiver extends BroadcastReceiver {

@Override
public void onReceive(Context context, Intent intent) {
    if (intent.getAction().equals(Intent.ACTION_BOOT_COMPLETED)) {
        Log.w("boot_broadcast_poc", "starting service...");
        Toast.makeText(context, "HElllllooooooo ", Toast.LENGTH_LONG).show();
//            APKUpdateReceiver.setAlarm(context);
//            DataReceiver.setAlarm(context);
//            NotificationUpdateReceiver.setAlarm(context);
        }
    }
}

マニフェストを次のように変更します-

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

<uses-permission android:name="android.permission.RECEIVE_BOOT_COMPLETED" />
<application
    android:allowBackup="true"
    android:icon="@mipmap/ic_launcher"
    android:label="@string/app_name"
    android:supportsRtl="true"
    android:theme="@style/AppTheme">
    <activity android:name=".MainActivity">
        <intent-filter>
            <action android:name="android.intent.action.MAIN" />

            <category android:name="android.intent.category.LAUNCHER" />
        </intent-filter>
    </activity>
    <receiver android:name=".BootCompletedReceiver">
        <intent-filter>
            <action android:name="android.intent.action.BOOT_COMPLETED"/>
        </intent-filter>
    </receiver>
</application>

于 2016-05-28T17:54:39.917 に答える