本文主要是介绍Android O版本发送广播受限问题,希望对大家解决编程问题提供一定的参考价值,需要的开发者们随着小编来一起学习吧!
Android O版本对后台进程做了限制广播的发送,对隐式广播也做了限制;
隐式广播发送:
sendBroadcast(new Intent("android.intent.action.MY_BROADCAST_TEST2"));
制定组件然后发送:
Intent mIntent=new Intent(BroadcastTestActivity.this,MyReceiver.class);
mIntent.setAction("android.intent.action.MY_BROADCAST_TEST2");
sendBroadcast(mIntent);
[SOLUTION]
O版本:
(1)
配置targetSdkVersion<=25
sendBroadcast(new Intent("android.intent.action.MY_BROADCAST_TEST2"));
APP处于前台,可以正常发送;
(2)
配置targetSdkVersion>=26
Intent mIntent=new Intent(BroadcastTestActivity.this,MyReceiver.class);
mIntent.setAction("android.intent.action.MY_BROADCAST_TEST2");
sendBroadcast(mIntent);
APP处于前台,可以正常发送;
(3)
配置targetSdkVersion>=26
sendBroadcast(new Intent("android.intent.action.MY_BROADCAST_TEST2"));
前台、后台发送受限;
log如下:
01-02 00:49:35.317 916-1039/system_process W/BroadcastQueue: Background execution not
allowed: receiving Intent { act=android.intent.action.MY_BROADCAST_TEST2 flg=0x10 } to
com.mtk14456.myapplication/.MyReceiver
(4)
应用处于后台时,发送广播会受限;参考官方文档;
https://developer.android.com/about/versions/oreo/android-8.0-changes#back-all
本文选自“http://bbs.16rd.com/thread-474487-1-1.html”
这篇关于Android O版本发送广播受限问题的文章就介绍到这儿,希望我们推荐的文章对编程师们有所帮助!