4

I am building an app, which needs to start a service automatically when the device boots up.

I want to test this functionality with adb. When I issue the following command from adb

adb shell am broadcast -a android.intent.action.BOOT_COMPLETED

I get the following error.

Broadcasting: Intent { act=android.intent.action.BOOT_COMPLETED }
java.lang.SecurityException: Permission Denial: not allowed to send broadcast android.intent.action.BOOT_COMPLETED from pid=3566, uid=2000
        at android.os.Parcel.readException(Parcel.java:1683)
        at android.os.Parcel.readException(Parcel.java:1636)
        at android.app.ActivityManagerProxy.broadcastIntent(ActivityManagerNative.java:3507)
        at com.android.commands.am.Am.sendBroadcast(Am.java:772)
        at com.android.commands.am.Am.onRun(Am.java:404)
        at com.android.internal.os.BaseCommand.run(BaseCommand.java:51)
        at com.android.commands.am.Am.main(Am.java:121)
        at com.android.internal.os.RuntimeInit.nativeFinishInit(Native Method)
        at com.android.internal.os.RuntimeInit.main(RuntimeInit.java:262)

According to this answer stackoverflow.com/a/10105047/106248 others didn't face this problem.

The OS version I am testing on is Android 7.0. I am facing the same problem on both real device and emulator.

Please help me solve the problem.

Thank you

Community
  • 1
  • 1
samsri
  • 1,104
  • 14
  • 25
  • The answer you are referencing is from 2014. It doesn't prove that people don't face this problem today – David Rawson Jan 29 '17 at 03:19
  • Did you try the advice in the comment: http://stackoverflow.com/questions/5051687/broadcastreceiver-not-receiving-boot-completed/10105047#comment51750239_10105047 – David Rawson Jan 29 '17 at 03:20
  • @DavidRawson Yes I did – samsri Jan 29 '17 at 03:27
  • Actually I couldn't get it working either :( assumed it is just some new security setting for Nougat and left it at that. – David Rawson Jan 29 '17 at 08:52
  • There seem to be a lot of questions about this same thing though: https://stackoverflow.com/search?q=android.intent.action.BOOT_COMPLETED – David Rawson Jan 29 '17 at 08:59
  • http://stackoverflow.com/questions/40698450/android-trying-to-test-a-service-on-boot-java-lang-securityexception-permiss This solved my problem. The question didn't turn up when I searched. Hope this would direct others to correct answer – samsri Apr 09 '17 at 02:57

1 Answers1

5

Restarting ADB in root mode has solved this problem for me:

adb root
Vadim Kotov
  • 8,084
  • 8
  • 48
  • 62
Tanya Y
  • 116
  • 2
  • 5
  • Hi, knowing that you answered the question a while back, may I know the exact commadn you used? Did you do `adb root` and then the broadcast commadn or did you do `adb root shell am...`? – vatbub Mar 27 '18 at 13:43
  • It's `adb root` (assuming you have one device), which should return message "restarting adbd as root". Then it's a separate call to `adb shell` to get to shell (as root). As far as I understand, this can only be done to an emulator. – jj. Jul 13 '20 at 23:30
  • 1
    I get `adbd cannot run as root in production builds` from a real device. Does it only work with emulators then? – JCarlosR Jul 08 '21 at 16:18