何らかの理由で、Runtime.getRuntime().exec("/system/bin/reboot"); を使用して Android デバイスを再起動できません。現在、3 つのデバイスで次のコードを試してみましたが、うまくいきませんでした。1 つは、rowboat-android ソースからビルドされました。他の 2 つは Motorola Droid Pro (Rooted、ストック) と HTC Ledgent (Rooted、Cynogen Mod) です。すべてのデバイスで Android 2.2 Froyo が実行されています。
誰かが理由を知っていますか?su は機能し、スーパー ユーザー アプリケーションが表示されます。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;
}