<receiver
android:name=".receiver.MyReceiver"
android:exported="true"
android:permission="owner.custom.permission">
<intent-filter>
<action android:name="owner.custom.broadcast"/>
</intent-filter>
</receiver>
在MyReceiver#onReceive()
中,我使用enqueueWork()
调用一个名为MyService
的JobIntentService:
public class MyReceiver extends BroadcastReceiver {
@Override
public void onReceive(final Context context, final Intent intent) {
Log.i(TAG, "Received the broadcast");
MyService.enqueueWork(context, getServiceIntent(context));
}
private Intent getServiceIntent(final Context context) {
final Intent intent = new Intent(context, MyService.class);
intent.putExtra("someKey", true);
return intent;
}
}
我有一个方法在MyService
中:
public static void enqueueWork(final Context context, final Intent work) {
enqueueWork(context, MyService.class, 111, work);
}
现在,每当广播owner.custom.broadcast
时,MyReceiver
不会被触发,我可以看到以下日志:
07-23 03:56:29.755 3335 3361 W BroadcastQueue: Background execution not allowed: receiving Intent { act=owner.custom.broadcast flg=0x10 } to com.amazon.myApp/.receiver.MyReceiver
现在的问题是,我正在使用另一个不同的广播接收器监听另一个类似的第三方隐式广播,并在那里调用MyService
,它能够正常工作。我还在另一个广播接收器中监听BOOT_COMPLETED
广播,并在那里调用MyService
,那里也能正常工作。
有哪些可能导致这个错误,这将帮助我确定是否遗漏了什么。
更新:
现在我只是尝试让广播接收器触发,但我仍然得到相同的错误。我只在接收器中放置了一行日志记录:
public class MyReceiver extends BroadcastReceiver {
@Override
public void onReceive(final Context context, final Intent intent) {
Log.i(TAG, "Received the broadcast");
}
}