-1

I need to restart my app often to test the behavior of some components. So I want to use a cmd from terminal in order to not waste time closing / opening manually. I have found this code but when I put on the terminal it returns a permission error.

CMD to reboot from terminal:

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

Terminal Response:

java.lang.SecurityException: Permission Denial: not allowed to send broadcast android.intent.action.BOOT_COMPLETED from pid=13940, uid=2000
        at android.os.Parcel.readException(Parcel.java:1665)
        at android.os.Parcel.readException(Parcel.java:1618)
        at android.app.ActivityManagerProxy.broadcastIntent(ActivityManagerNative.java:3533)
        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)

1 Answers1

0

That broadcast won't work as it is a system privileged Intent. If you just need to restart your app clean in a certain activity, the am command has an option to force stop the running process (-S) before delivering the Intent:

adb shell am -S -a "android.action.MAIN" -c "android.category.DEFAULT" -n "your.package.name/.YourActivityName"
Larry Schiefer
  • 15,687
  • 2
  • 27
  • 33
  • i don need to restart the app. I need to fire the event of the reboot of the sistem, without closing/opening manuall operations. – Giorgio Cafiso Mar 12 '19 at 13:08
  • OK, that was not clear from your question. You cannot directly simulate boot complete by sending that `Intent`. The system only allows it to be sent by the internal Android framework. – Larry Schiefer Mar 12 '19 at 16:58