由于某种原因,我无法使用 Runtime.getRuntime().exec("/system/bin/reboot"); 重新启动 Android 设备。我已经在 3 台设备上尝试了以下代码,但没有成功。一个是从 rowboat-android 源代码构建的。另外两款是 Motorola Droid Pro(已 Root,库存)和 HTC Ledgent(已 Root,Cynogen Mod)。所有设备均运行 Android 2.2 Froyo。
有谁知道为什么? su 可以正常工作,超级用户应用程序也可见。我应该注意到其他各种 shell 命令也可以工作,例如 netcfg(chmod' 到 777)和 ls。
public static boolean executeCommand(SHELL_CMD iShellCmd){
String cmd = null;
String line = null;
String fullResponse = null;
Process lPs = null;
Log.d(Global.TAG,"--> !!!!! Running shell command");
if (iShellCmd == SHELL_CMD.restart_device){
cmd = "reboot";
}
Log.d(Global.TAG,"--> About to exec: " + cmd);
try {
lPs = Runtime.getRuntime().exec("su");
lPs = Runtime.getRuntime().exec("/system/bin/reboot");
} catch (Exception e) {
e.printStackTrace();
}
BufferedWriter out = new BufferedWriter(new OutputStreamWriter(lPs.getOutputStream()));
BufferedReader in = new BufferedReader(new InputStreamReader(lPs.getInputStream()));
try {
while ((line = in.readLine()) != null) {
Log.d(Global.TAG,"--> Command result line: " + line);
if (fullResponse == null){
fullResponse = line;
}else{
fullResponse = fullResponse + "\n" + line;
}
}
} catch (Exception e) {
e.printStackTrace();
}
Log.d(Global.TAG,"--> Full response was: " + fullResponse);
return true;
}
根据您在设备上获取 root 权限的方式,您可以执行以下任一操作:
Runtime.getRuntime().exec(new String[]{"/system/xbin/su","-c","reboot"});
or
Runtime.getRuntime().exec(new String[]{"/system/bin/su","-c","reboot"});
or
Runtime.getRuntime().exec(new String[]{"su","-c","reboot"});
可能更好地测试应用程序中的所有三个场景。
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)