在我的应用程序中,有一个重新启动的功能,它可以很好地与任何根设备配合使用。。。直到现在。
我最新的测试设备(Android 4.2)没有任何反应。但是,将adb提示符与相同的命令一起使用可以达到目的。
首先我确定设备是否有根,返回true:
String[] places = {"/sbin/", "/system/bin/", "/system/xbin/", "/data/local/xbin/", "/data/local/bin/", "/system/sd/xbin/", "/system/bin/failsafe/", "/data/local/"};
for (String where : places) {
if (new File(where + "su").exists()) {
isDeviceRootedResult = true;
break;
}
}
之后,我尝试执行如下命令:
Process rebootProcess = null;
rebootProcess = Runtime.getRuntime().exec("su -c reboot now");
if (rebootProcess != null) rebootProcess.waitFor();
我在我的LogCat中没有看到任何输出,没有异常,没有投掷,什么都没有。。。
虽然"相同"的adb命令运行良好:
adb.exe shell "su -c reboot now"
如果您的设备没有根,则无法以编程方式重新启动设备!它It’这是一个安全问题。您可能没有超级用户权限