【发布时间】:2011-04-09 06:08:46
【问题描述】:
由于某种原因,我无法使用 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;
}
【问题讨论】:
-
如果您从终端模拟器运行该命令是否有效?你试过
reboot而不是/system/bin/reboot吗? -
调用“重新启动”不起作用并锁定应用程序并显示 ANR(强制退出)。如果我使用 adb shell 在设备上调用 reboot ,系统会正确重启。然后我需要重新启动系统才能再次使用 runtime.exec 发出 shell 命令。
-
强制退出后的logcat是什么?搜索单词
FATAL之后的任何内容