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

请按照以下操作,它工作正常。我在你的接收器里放了一个 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.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 回答