2

I am trying to make an apk to install in a device and manage usb state.

apk sends broadcast to device like...

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

In AndroidManifest.xml I stated permission part..

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

but when error occours even though i already stated permission.

log is....

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

I have no idea what i've done wrong..

Any clues will help.

Thank you.

Vinay
  • 6,891
  • 4
  • 32
  • 50
HJJ
  • 21
  • 1
  • 2
  • 1
    Well this is easy, your not allowed to send the android.hardware.usb.action.USB_STATE intent. This intent is for client applications that some device has been connected/disconnected. What do you want to do with it? – RvdK Apr 03 '13 at 08:29
  • Thanks for your help. I'm trying to change the usb connection mode with this app. is it possible? – HJJ Apr 03 '13 at 23:07
  • What do you mean with 'connection mode'? Disable or enable USB? USB Host? – RvdK Apr 04 '13 at 07:19

1 Answers1

6

You can find this declaration in framework/base/core/res/AndroidManifest.xml

This broadcast is in this section:

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

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

I believe you can understand this. You must be generating your own firmware to broadcast this intent.

Robin
  • 10,052
  • 6
  • 31
  • 52
  • Thanks for your help. I'm trying to change the usb connection mode with this app. is it possible? – HJJ Apr 03 '13 at 23:04
  • Try to root your device, remount your system partition as R/W and put your apk into /system/app directory. – Robin Apr 07 '13 at 08:14
  • @HJJ You probably should accept this answer since it seems to explain why you are getting a SecurityException (and so resolves your question) – Codebling Apr 29 '13 at 10:54