I am creating app(only for Android 6) in which I have to give reboot functionality using button click. I am using following code:
PowerManager pm =(PowerMan
Please try
try {
Runtime.getRuntime().exec("su");
Runtime.getRuntime().exec("reboot");
} catch (IOException e) {
}
Runtime.getRuntime().exec(new String[]{"/system/bin/su","-c","reboot now"});
if that not work : Runtime.getRuntime().exec(new String[]{"su","-c","reboot now"});
instead
You could possibly use the PowerManager to make it reboot (this does not guarantee that it'll reboot - OS may cancel it):
http://developer.android.com/reference/android/os/PowerManager.html#reboot(java.lang.String)
Reboot the device. Will not return if the reboot is successful.Requires the REBOOT permission.
http://developer.android.com/reference/android/Manifest.permission.html#REBOOT
Required to be able to reboot the device. Not for use by third-party applications. Constant Value: "android.permission.REBOOT"
You cannot do this from an ordinary SDK application. Only applications signed with the system firmware signing key can do this.
You need to sign your app with the System Firmware Key
. But it's possible for your app with Root
privileges. Try using the following code (if you have SU access):
Shutdown:
try {
Process proc = Runtime.getRuntime()
.exec(new String[]{ "su", "-c", "reboot -p" });
proc.waitFor();
} catch (Exception ex) {
ex.printStackTrace();
}
Restart:
Same code, just use "reboot"
instead of "reboot -p"
.
These do not work on Stock HTC ROMs, but haven't confirmed myself