出于某种原因,我无法使用 Runtime.getRuntime().exec("/system/bin/reboot"); 重新启动 Android 设备。我现在已经在 3 台设备上尝试了以下代码,但没有运气。一个是从 rowboat-android 源构建的。另外两个是摩托罗拉 Droid Pro(Rooted,股票)和 HTC Ledgent(Rooted,Cynogen Mod)。所有设备都运行 Android 2.2 Froyo。
有谁知道为什么?su 工作以及超级用户应用程序是可见的。我应该注意到其他各种 shell 命令确实有效,例如 netcfg (chmod' to 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;
}