android 系统内自定义广播Sending non-protected broadcast
08-27 16:54:06.682 7359 7789 E ActivityManager: Sending non-protected broadcast android.provider.Telephony.SMS_RECEIVED_SHOUJIODM from system 7701:com.android.phone/1001 pkg com.android.phone
08-27 16:54:06.682 7359 7789 E ActivityManager: java.lang.Throwable
08-27 16:54:06.682 7359 7789 E ActivityManager: at com.android.server.am.ActivityManagerService.checkBroadcastFromSystem(ActivityManagerService.java:16073)
08-27 16:54:06.682 7359 7789 E ActivityManager: at com.android.server.am.ActivityManagerService.broadcastIntentLocked(ActivityManagerService.java:16751)
08-27 16:54:06.682 7359 7789 E ActivityManager: at com.android.server.am.ActivityManagerService.broadcastIntentLocked(ActivityManagerService.java:16090)
08-27 16:54:06.682 7359 7789 E ActivityManager: at com.android.server.am.ActivityManagerService.broadcastIntentWithFeature(ActivityManagerService.java:16908)
08-27 16:54:06.682 7359 7789 E ActivityManager: at android.app.IActivityManager$Stub.onTransact(IActivityManager.java:2306)
08-27 16:54:06.682 7359 7789 E ActivityManager: at com.android.server.am.ActivityManagerService.onTransact(ActivityManagerService.java:2907)
08-27 16:54:06.682 7359 7789 E ActivityManager: at android.os.Binder.execTransactInternal(Binder.java:1159)
08-27 16:54:06.682 7359 7789 E ActivityManager: at android.os.Binder.execTransact(Binder.java:1123)
08-27 16:54:06.683 7359 7789 D BroadcastQueue: Add broadcast <BroadcastRecord{6eadd8a u0 android.provider.Telephony.SMS_RECEIVED_SHOUJIODM}> into [ordered | background], pending size 0
08-27 16:54:06.683 7359 7789 D BroadcastQueue: Header is BroadcastRecord{6eadd8a u0 android.provider.Telephony.SMS_RECEIVED_SHOUJIODM} now
解决方案:
1 如果是在framework层非应用内发送广播则需要在:aosp/framework/base/core/res/AndroidMainfest.xml内添加你的自定义的广播action,如:
<!-- add by androidodm -->
<protected-broadcast android:name="android.provider.Telephony.SMS_RECEIVED_SHOUJIODM" />//替换成你自己的广播 action
2 如你在系统原有的某个APP内或是系统内置的你自己的APP内发送广播,则需要在你的APP的项目清单文件AndroidMainfest.xml中添加
<!-- add by androidodm -->
<protected-broadcast android:name="android.provider.Telephony.SMS_RECEIVED_SHOUJIODM" />//替换成你自己的广播 action
//android 8.0之后必须是发送显示广播
08-27 18:43:14.116 19428 21188 D BroadcastQueue: Add broadcast <BroadcastRecord{239a5cd u0 android.provider.Telephony.SMS_RECEIVED_SHOUJIODM}> into [ordered | background], pending size 0
08-27 18:43:14.116 19428 21188 D BroadcastQueue: Header is BroadcastRecord{239a5cd u0 android.provider.Telephony.SMS_RECEIVED_SHOUJIODM} now
08-27 18:43:14.117 19428 19458 V ActivityManager_MU: isSingleton(com.android.settings, ApplicationInfo{c9e3e82 com.android.settings}, com.android.settings.SOSBroadcastReceiver, 0x0) = false
08-27 18:43:14.117 19428 19458 W BroadcastQueue: Background execution not allowed: receiving Intent { act=android.provider.Telephony.SMS_RECEIVED_SHOUJIODM flg=0x10 } to com.android.settings/.SOSBroadcastReceiver
08-27 18:43:14.117 19428 19458 D BroadcastQueue: Skipping delivery of ordered [background] BroadcastRecord{239a5cd u0 android.provider.Telephony.SMS_RECEIVED_SHOUJIODM} for reason described above
08-27 18:43:14.118 19428 19458 D BroadcastQueue: Finished with ordered broadcast BroadcastRecord{239a5cd u0 android.provider.Telephony.SMS_RECEIVED_SHOUJIODM} receivers:(1) take 0ms in [background], remains -1
Intent intent= new Intent();
intent.setAction("android.provider.Telephony.SMS_RECEIVED_BIRD");/ /替换成你自己的广播 action
intent.setComponent(new ComponentName("com.android.youapppackagename",com.android.settings.XXXBroadcastReceiver.class));//指定setComponent 即为显示广播
getContext().sendBroadcast(intent);
评论