简体   繁体   中英

cannot reboot Android from terminal

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)

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"

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM