android BootCompletedReceiver 未启动

android BootCompletedReceiver not fire

我有一个 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 方法内部触发时,请给我提示。

请按如下操作,效果很好。 我在你的接收器中放了一个 Toast 以通知接收器被调用 -

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.Whosebug">

<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>