欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页  >  移动技术

MTK FAQ-Android O版本发送广播受限问题

程序员文章站 2022-03-20 20:24:35
Android O版本对后台进程做了限制广播的发送,对隐式广播也做了限制;隐式广播发送:sendBroadcast(new Intent("android.intent.action.MY_BROADCAST_TEST2"));制定组件然后发送:Intent mIntent=new Intent(B ......

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”,转载请注明出处