Broadcast receiver is not working in oreo and pie android

拈花ヽ惹草 提交于 2020-05-09 06:37:10

问题


Boot broadcast receiver is not working and there is nothing in 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);

    }

}


回答1:


  1. Make sure that you have registered your receiver in Manifest .
  2. Implicit Broadcast Exceptions refer to this link to check if your implicit receiver is in exception list or not.
  3. if not in exception the you can make job scheduler or register your receiver in your code itself .Here is a nice snippet you could refer on It’s time to kiss goodbye to your implicit BroadcastReceivers


来源:https://stackoverflow.com/questions/55429554/broadcast-receiver-is-not-working-in-oreo-and-pie-android

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!