Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Reboot the phone on a button click

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?

like image 710
IntelSoftApps Avatar asked Feb 11 '11 07:02

IntelSoftApps


2 Answers

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

like image 135
Zelimir Avatar answered Oct 06 '22 19:10

Zelimir


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);
          }

        }
  }
like image 30
mboy Avatar answered Oct 06 '22 20:10

mboy