2

I would like to programmatically shutdown the users device from within my app. Since I know it is impossible to shut it down directly, I was wondering if there is a way for me to instead show the confirmation dialog box that would show up if you were to press "Power off".

Nick Gable
  • 21
  • 1
  • 4
  • You could just execute a process using `reboot -p` - but you'd need root access – CodingIntrigue Mar 12 '15 at 12:55
  • 1
    possible duplicate of [SDK Android : How to open Shutdown/Reboot dialog for the device](http://stackoverflow.com/questions/19930790/sdk-android-how-to-open-shutdown-reboot-dialog-for-the-device) – Rod Mar 12 '15 at 12:55
  • Possible duplicate of [Simulating power button press to display switch off dialog box](https://stackoverflow.com/questions/11338022/simulating-power-button-press-to-display-switch-off-dialog-box) – Jonas Czech Oct 24 '19 at 19:33

2 Answers2

1

If your app has root access you can run the following as root:

am start -a android.intent.action.ACTION_REQUEST_SHUTDOWN

Nova Entropy
  • 5,727
  • 1
  • 19
  • 32
0

how can you see here you can't do this directly, but there are some workaround in this link

Community
  • 1
  • 1
Rod
  • 754
  • 11
  • 21
  • I wanted to be able to show the confirm box (Your phone will be shut down, OK / Cancel), how could I do this after stimulating the power off menu – Nick Gable Mar 12 '15 at 13:02
  • I fixed the second link (that was wrong), it holds your answer – Rod Mar 12 '15 at 13:04