[英]Broadcast receiver is not working in oreo and pie android
啟動廣播接收器不工作,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);
}
}
您需要使用registerReceiver才能在android oreo及更高版本中工作。 從oreo開始,存在背景限制。
您可以使用此鏈接進行了解。 https://www.journaldev.com/23653/android-oreo-implicit-and-explicit-broadcast-receiver
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.