簡體   English   中英

java.lang.SecurityException:權限拒絕:不允許發送廣播android.hardware.usb.action.USB_STATE

[英]java.lang.SecurityException: Permission Denial: not allowed to send broadcast android.hardware.usb.action.USB_STATE

我正在嘗試使apk安裝在設備中並管理USB狀態。

apk將廣播發送到設備,例如...

Intent intent = new Intent(ACTION_USB_STATE);
sendBroadcast(intent);

在AndroidManifest.xml中,我聲明了權限部分。

<uses-permission android:name="android.permission.BROADCAST_STICKY" />

但是,即使我已經表示同意,但錯誤仍然存​​在時。

日志是...。

W/ActivityManager(  850): Permission Denial: not allowed to send broadcast android.hardware.usb.action.USB_STATE from pid=16082, uid=10109
E/AndroidRuntime(16082): FATAL EXCEPTION: main
E/AndroidRuntime(16082): java.lang.SecurityException: Permission Denial: not allowed to send broadcast android.hardware.usb.action.USB_STATE from pid=16082, uid=10109
E/AndroidRuntime(16082):    at android.os.Parcel.readException(Parcel.java:1425)
E/AndroidRuntime(16082):    at android.os.Parcel.readException(Parcel.java:1379)
E/AndroidRuntime(16082):    at android.app.ActivityManagerProxy.broadcastIntent(ActivityManagerNative.java:2098)
E/AndroidRuntime(16082):    at android.app.ContextImpl.sendBroadcast(ContextImpl.java:1003)
E/AndroidRuntime(16082):    at android.content.ContextWrapper.sendBroadcast(ContextWrapper.java:312)
E/AndroidRuntime(16082):    at com.example.usb_mode_change.USBModeSettingActivity$1.onClick(USBModeSettingActivity.java:43)
E/AndroidRuntime(16082):    at android.view.View.performClick(View.java:4101)
E/AndroidRuntime(16082):    at android.view.View$PerformClick.run(View.java:17082)
E/AndroidRuntime(16082):    at android.os.Handler.handleCallback(Handler.java:615)
E/AndroidRuntime(16082):    at android.os.Handler.dispatchMessage(Handler.java:92)
E/AndroidRuntime(16082):    at android.os.Looper.loop(Looper.java:137)
E/AndroidRuntime(16082):    at android.app.ActivityThread.main(ActivityThread.java:4911)
E/AndroidRuntime(16082):    at java.lang.reflect.Method.invokeNative(Native Method)
E/AndroidRuntime(16082):    at java.lang.reflect.Method.invoke(Method.java:511)
E/AndroidRuntime(16082):    at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:795)
E/AndroidRuntime(16082):    at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:562)
E/AndroidRuntime(16082):    at dalvik.system.NativeStart.main(Native Method)
W/ActivityManager(  850):   Force finishing activity com.example.usb_mode_change/.USBModeSettingActivity

我不知道我做錯了什么..

任何線索都會有所幫助。

謝謝。

您可以在framework / base / core / res / AndroidManifest.xml中找到此聲明

此廣播在此部分中:

  24     <!-- ================================================ -->
  25     <!-- Special broadcasts that only the system can send -->
  26     <!-- ================================================ -->

 106     <protected-broadcast android:name="android.hardware.usb.action.USB_STATE" />

我相信你能理解。 您必須生成自己的固件才能廣播此意圖。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM