Reboot the phone on a button click
Asked Answered
A

3

11

I am making an Android app that needs to have the phone reboot or turn off when a button is clicked. Is this possible? Or will the phone require root access?

Architectonics answered 11/2, 2011 at 7:13 Comment(2)
I am not sure if users appreciate that their device is suddenly reooting or stopping. We are talking about a mobile phone here and not a Windows PC.Crysta
Yes.its mobile phone.haha and the reboot won't be suddenly they will know what will happen if they choose that button.Architectonics
S
21

You can do that using android.os.PowerManager. Function reboot(String reason) is available, you need permission:

android.permission.REBOOT

Official site:

http://developer.android.com/reference/android/os/PowerManager.html#reboot(java.lang.String)

Of course, you are likely to get that permission only if your application is signed with the system signing key:

How to compile Android Application with system permissions

Swish answered 11/2, 2011 at 7:21 Comment(2)
you won't be granted this permission!Shala
@Swish what should i pass the this function reboot(String reason)..can you post some of sample code pleasePone
S
2

I did this in my app by calling the method below.

Notes: 1. Make sure the phone is rooted 2. Allow the app in your root manager to automatically grant root permission.

    void reboot() {
        if (reboot) {

          try {
              Process proc = Runtime.getRuntime().exec(new String[]{"/system/bin/su", "-c", "reboot"});
              proc.waitFor();
          } catch (Exception ex) {
              Log.e(TAG, "Error ", ex);
          }

        }
  }
Siouxie answered 10/12, 2016 at 6:3 Comment(0)
S
1

If your device is rooted device then you can use below code.

Runtime.getRuntime().exec(new String[]{"/system/bin/su", "-c", "reboot now"});
Samarium answered 22/7, 2016 at 4:37 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.