[英]Broadcast receiver is not working in oreo and pie android
Boot broadcast receiver is not working and there is nothing in onReceive()启动广播接收器不工作,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);
}
} }
You need to use registerReceiver in order to work in android oreo & above. 您需要使用registerReceiver才能在android oreo及更高版本中工作。 Starting from oreo there is background restriction.
从oreo开始,存在背景限制。
You can use this link to learn about it. 您可以使用此链接进行了解。 https://www.journaldev.com/23653/android-oreo-implicit-and-explicit-broadcast-receiver
https://www.journaldev.com/23653/android-oreo-implicit-and-explicit-broadcast-receiver
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.