Is it possible to shut down the whole phone by an app? How? Do I need to root the phone?
Asked
Active
Viewed 5,943 times
0
-
1I wouldn't suggest designing your app in such a way that it distinguishes between "rooted" and "non-rooted" devices. – Alex Lockwood Apr 09 '12 at 16:25
-
possible duplicate of [How to shutdown an android mobile programatically?](http://stackoverflow.com/questions/10411650/how-to-shutdown-an-android-mobile-programatically) – Flow Apr 15 '14 at 12:19
-
Not possible unless your application is System app. – Umang Kothari Jul 17 '15 at 10:14
2 Answers
2
You need the DEVICE_POWER permission in order to shut the phone completely off which requires the device being rooted.
You can use the PowerManager to get it to sleep or reboot.
http://developer.android.com/reference/android/os/PowerManager.html#reboot(java.lang.String)
Reboot also requires a permission:
http://developer.android.com/reference/android/Manifest.permission.html#REBOOT

HardCoder
- 3,026
- 6
- 32
- 52
0
1、you device need root
2、code like this
private void powerOff() {
try {
Process proc = Runtime.getRuntime()
.exec(new String[]{ "su", "-c", "reboot -p" });
proc.waitFor();
} catch (Exception ex) {
ex.printStackTrace();
}
}
private void reboot() {
try {
Process proc = Runtime.getRuntime().exec(new String[]{ "su", "-c", "reboot" });
proc.waitFor();
} catch (Exception e) {
e.printStackTrace();
}
}