Permission Denial: not allowed to send broadcast in android

Process: com.example.android_sapphire_navigationbar_test, PID: 2710
                                                                                                    java.lang.SecurityException: Permission Denial: not allowed to send broadcast com.systemui.navigationbar.show from pid=2710, uid=10076
                                                                                                    	at android.os.Parcel.createException(Parcel.java:1950)
                                                                                                    	at android.os.Parcel.readException(Parcel.java:1918)
                                                                                                    	at android.os.Parcel.readException(Parcel.java:1868)
                                                                                                    	at android.app.IActivityManager$Stub$Proxy.broadcastIntent(IActivityManager.java:3895)
                                                                                                    	at android.app.ContextImpl.sendBroadcast(ContextImpl.java:1009)
                                                                                                    	at android.content.ContextWrapper.sendBroadcast(ContextWrapper.java:444)
                                                                                                    	at android.content.ContextWrapper.sendBroadcast(ContextWrapper.java:444)
                                                                                                    	at com.example.android_sapphire_navigationbar_test.MainActivity.showSystemUI(MainActivity.java:133)
                                                                                                    	at com.example.android_sapphire_navigationbar_test.MainActivity.onClick(MainActivity.java:60)
                                                                                                    	at android.view.View.performClick(View.java:6597)
                                                                                                    	at com.google.android.material.button.MaterialButton.performClick(MaterialButton.java:1202)
                                                                                                    	at android.view.View.performClickInternal(View.java:6574)
                                                                                                    	at android.view.View.access$3100(View.java:778)
                                                                                                    	at android.view.View$PerformClick.run(View.java:25885)
                                                                                                    	at android.os.Handler.handleCallback(Handler.java:873)
                                                                                                    	at android.os.Handler.dispatchMessage(Handler.java:99)
                                                                                                    	at android.os.Looper.loop(Looper.java:193)
                                                                                                    	at android.app.ActivityThread.main(ActivityThread.java:6718)
                                                                                                    	at java.lang.reflect.Method.invoke(Native Method)
                                                                                                    	at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:493)
                                                                                                    	at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:858)
                                                                                                    Caused by: android.os.RemoteException: Remote stack trace:
                                                                                                    	at com.android.server.am.ActivityManagerService.broadcastIntentLocked(ActivityManagerService.java:21447)
                                                                                                    	at com.android.server.am.ActivityManagerService.broadcastIntent(ActivityManagerService.java:22076)
                                                                                                    	at android.app.IActivityManager$Stub.onTransact$broadcastIntent$(IActivityManager.java:10175)
                                                                                                    	at android.app.IActivityManager$Stub.onTransact(IActivityManager.java:167)
                                                                                                    	at com.android.server.am.ActivityManagerService.onTransact(ActivityManagerService.java:3300)

Because the Intent in the project recently used the broadcast "android.intent.action.MEDIA_MOUNTED", I was prompted with insufficient permissions. After checking the reason, it was because starting from 4.4, the official began to restrict the use of this broadcast, and added  protected permissions. Can be used internally within the system. As follows:

   <protected-broadcast android:name="android.intent.action.MEDIA_MOUNTED" />
  • protected -broadcast (I have found so many from the Internet for the time being, I don’t know whether it is right or wrong, so I will keep it for now)

    "Protected broadcast", the first-level tag <protected-broadcast> in some AndroidManifest.xml, has its specific function:

    Specify a broadcast here, which can only be sent by the system.

    Note: Only the system appliaction can define Protected Broadcast in its AndroidManifest.xml. The system appliaction includes packages under /system/framework, /system/app, and vendor/app. Therefore, if Protected Broadcast is defined in the third-party apk installed in the device , then this Protected Broadcast will not take effect.

    Simply put, Android believes that there are some broadcasts that can only be sent by the system. If this tag is written in a system-level AndroidManifest.xml, then when PKMS parses the file, it will put the "protective broadcast" tag in The name (usually an Action string) is recorded.

    After the system is running, if an application that does not have system permissions attempts to send a "protective broadcast" in the system, AMS will throw an exception and prompt "Permission Denial: not allowed to send broadcast".

    You can see the specific writing method of <protected-broadcast> tag in the code, as follows

    <protected-broadcast android:name="android.intent.action.SERVICE_STATE" />
    <protected-broadcast android:name="android.intent.action.RADIO_TECHNOLOGY" />

    The role of protected-broadcast-CSDN Blog
  • Permission Denial: not allowed to send broadcast in android-CSDN博客

Guess you like

Origin blog.csdn.net/xiaowang_lj/article/details/135068527