我終於設法讓重新啓動代碼工作。我使用下面的代碼:重新啓動恢復Android
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) {
}
現在我想要一個代碼,將設備重新啓動到恢復模式。該應用程序將只爲三星Galaxy S.我沒有發現任何代碼重新啓動在恢復,有沒有什麼辦法可以通過代碼恢復重啓?
像Chris上面說的,但是我會把'su -c reboot recovery'寫成'su'已經在Android系統路徑中定義了,所以你不需要提供應用程序的完整路徑。 – ChuongPham
@Chuong - 沒有。該代碼執行一個'su'進程和管道命令輸入,因爲'su'hacks並不都接受命令行執行的命令。由於在輸入命令字符串時'su'已經在運行,所以您不希望再次在命令中包含'su'。此外,以root身份執行某些操作時,您不希望信任可能已被攻擊者更改的路徑設置,而是明確指定目標可執行文件。 –
我忘了提到OP可以運行上面提供的命令,而不是激活'su',然後運行像'/ system/bin/reboot recovery'這樣的工作進程。無論哪種方式都適用於OP。 :) – ChuongPham