标签:receiving skip 广播 Intent allowed intent execution
1、隐式广播权限
android O系统后,隐式广播收到的限制,一定要指定包名才能发送出来。
否则会报错:
Background execution not allowed: receiving Intent { act=android.bluetooth.anw.action.PAIR_REQUEST flg=0x10 (has extras) } to com.anwsdk.sample/.BTMsgReceiver
但是在实际开发测试时,有些旧的app应用还是发送的隐式广播,导致接收不到,临时修改系统源码解决:
源码:\frameworks\base\services\core\java\com\android\server\am\BroadcastQueue.java
processNextBroadcastLocked()对广播进行了判断和处理:
if (!skip) {
final int allowed = mService.getAppStartModeLocked(
info.activityInfo.applicationInfo.uid, info.activityInfo.packageName,
info.activityInfo.applicationInfo.targetSdkVersion, -1, true, false, false);
if (allowed != ActivityManager.APP_START_MODE_NORMAL) {
// We won't allow this receiver to be launched if the app has been
// completely disabled from launches, or it was not explicitly sent
// to it and the app is in a state that should not receive it
// (depending on how getAppStartModeLocked has determined that).
if (allowed == ActivityManager.APP_START_MODE_DISABLED) {
Slog.w(TAG, "Background execution disabled: receiving "
+ r.intent + " to "
+ component.flattenToShortString());
skip = true;
} else if (((r.intent.getFlags()&Intent.FLAG_RECEIVER_EXCLUDE_BACKGROUND) != 0)
|| (r.intent.getComponent() == null
&& r.intent.getPackage() == null
&& ((r.intent.getFlags()
& Intent.FLAG_RECEIVER_INCLUDE_BACKGROUND) == 0)
&& !isSignaturePerm(r.requiredPermissions))) {
mService.addBackgroundCheckViolationLocked(r.intent.getAction(),
component.getPackageName());
Slog.w(TAG, "Background execution not allowed: receiving "
+ r.intent + " to "
+ component.flattenToShortString());
//取消skip=true,让广播依旧可以发送出去
//skip = true;
}
}
}
2、受保护的广播
报错:
ActivityManager: Sending non-protected broadcast …Throwable at
系统中发送的广播必须是受保护的广播,否则发送失败。
源码:\frameworks\base\core\res\AndroidManifest.xml
增加:
<protected-broadcast android:name="android.intent.action.DOCK_IDLE" />
<protected-broadcast android:name="android.intent.action.DOCK_ACTIVE" />
标签:receiving,skip,广播,Intent,allowed,intent,execution 来源: https://blog.csdn.net/Sunxiaolin2016/article/details/100016752
本站声明: 1. iCode9 技术分享网(下文简称本站)提供的所有内容,仅供技术学习、探讨和分享; 2. 关于本站的所有留言、评论、转载及引用,纯属内容发起人的个人观点,与本站观点和立场无关; 3. 关于本站的所有言论和文字,纯属内容发起人的个人观点,与本站观点和立场无关; 4. 本站文章均是网友提供,不完全保证技术分享内容的完整性、准确性、时效性、风险性和版权归属;如您发现该文章侵犯了您的权益,可联系我们第一时间进行删除; 5. 本站为非盈利性的个人网站,所有内容不会用来进行牟利,也不会利用任何形式的广告来间接获益,纯粹是为了广大技术爱好者提供技术内容和技术思想的分享性交流网站。