八月 27.2018.
0 Comment
手上的小米平板1,更新到MIUI 9.6.24后,用Root刷机精灵给root了。地铁上看书时,不看了直接关机。MIUI之前有关机、重启的桌面小工具,可是升级了之后就没有了。于是我想自己实现一个。
在网上看了一阵代码后,之前有一种基于/system/xbin/ru来实现的,可是通过RE管理器,看到xbin下面没有ru。试了如下的方法之后:
public static int shutdown() {
int r = 0;
try {
Process process = Runtime.getRuntime().exec(new String[]{"su" , "-c" ,"reboot -p"});
r = process.waitFor();
java.lang.System.out.println("r:" + r );
} catch (IOException e) {
e.printStackTrace();
r = -1;
} catch (InterruptedException e) {
e.printStackTrace();
r = -1;
}
return r;
}
reboot重启的代码:
public static int reboot() {
int r = 0;
try {
Process process = Runtime.getRuntime().exec("su -c reboot");
r = process.waitFor();
java.lang.System.out.println("r:" + r );
} catch (IOException e) {
e.printStackTrace();
r = -1;
} catch (InterruptedException e) {
e.printStackTrace();
r = -1;
}
return r;
}
经过试验可以使用。
打赏
微信扫一扫,打赏作者吧~