Android Reboot

目前的使用方法為su -c "reboot",但是必須要有su的權限

MyReboot.java
1
2
3
4
5
6
7
try {
String[] commands = new String[] {"su", "-c", "reboot"};
Runtime.getRuntime().exec(commands);
return true;
} catch (IOException e) {
return false;
}

Method 1 : adb

su -c "reboot"
toolbox reboot
reboot -d 8 -f
busybox killall system_server
start|stop

Method 2 : PowerManager

Reboot.java
1
2
3
4
5
6
7
8
9
@TargetApi(8)
public void reboot() {
PowerManager pm = (PowerManager) context.getSystemService(Context.POWER_SERVICE);
pm.reboot("recovery");
pm.reboot(null);

// not working:
// reboot(null);
}

Source: