启动广播接收器不工作,onReceive() 中没有任何内容
public class BootReceived extends BroadcastReceiver {
@Override
public void onReceive(Context context, Intent intent) {
if (Intent.ACTION_BOOT_COMPLETED.equals(intent.getAction())) {
Toast.makeText(context, intent.getAction(), Toast.LENGTH_LONG).show();
Log.d("IfWalaBooot", intent.getAction());
Intent intent1 = new Intent(context, MainActivity.class);
intent1.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
context.startActivity(intent1);
Intent tni = new Intent(context, MainService.class);
tni.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
context.startService(tni);
}
最佳答案
- 确保您已在 Manifest 中注册您的接收器。
- Implicit Broadcast Exceptions请参阅此链接以检查您的隐式接收器是否 是否在异常(exception)列表中。
- 如果没有异常(exception),您可以制作作业调度程序或在您的代码本身中注册您的接收器。这是一个不错的 fragment ,您可以引用 It’s time to kiss goodbye to your implicit BroadcastReceivers
关于android - 广播接收器在 oreo 和 pie android 中不起作用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/55429554/