,这不是一个真正的应用程序.主要目的是在我的测试期间重新启动电话(我在视频聊天应用程序上工作,有时我需要重新启动,当一切都向南)
我观察到重新启动手机远远超过终端(例如adb shell或ConnectBot)中的重新引导,而不是像 ACTION_REBOOT 那样重新启动,我无法使用.
目前,我可以获得超级用户权限
Process root = Runtime.getRuntime().exec("su");
但是我无法实际重新启动.我试用G1(HTC)和Galaxy S(三星),没有任何成功.我在/ system / bin / reboot中找到reboot可执行文件
这是我的一些尝试:
Process reboot = Runtime.getRuntime().exec("/system/bin/reboot");
Process reboot = Runtime.getRuntime().exec("reboot");
Process reboot = Runtime.getRuntime().exec("su reboot");
我读了 this article 关于Runtime.exec()的陷阱,但我认为我不在这种情况.
使用ConnectBot可以让我做这样的一个动作,我很确定这是可能的.请不要告诉我去看看 ConnectBot code ,这是一个大而复杂的项目:)
你能帮我解决这个问题吗?
谢谢.
重新启动在Android中正常工作.你可能没有正确地执行runtime.exec().
你需要处理
public static void rebootSU() {
Runtime runtime = Runtime.getRuntime();
Process proc = null;
OutputStreamWriter osw = null;
StringBuilder sbstdOut = new StringBuilder();
StringBuilder sbstdErr = new StringBuilder();
String command="/system/bin/reboot";
try { // Run Script
proc = runtime.exec("su");
osw = new OutputStreamWriter(proc.getOutputStream());
osw.write(command);
osw.flush();
osw.close();
} catch (IOException ex) {
ex.printStackTrace();
} finally {
if (osw != null) {
try {
osw.close();
} catch (IOException e) {
e.printStackTrace();
}
}
}
try {
if (proc != null)
proc.waitFor();
} catch (InterruptedException e) {
e.printStackTrace();
}
sbstdOut.append(ReadBufferedReader(new InputStreamReader(proc
.getInputStream())));
sbstdErr.append(ReadBufferedReader(new InputStreamReader(proc
.getErrorStream())));
if (proc.exitValue() != 0) {
}
}
http://stackoverflow.com/questions/5484535/runtime-exec-reboot-in-android