MTK FAQ-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”,转载请注明出处
上一篇: 利用 Python 批量修改文件名
下一篇: 软件工程(2018)结对编程第二次作业