重新启动恢复Android
我终于设法让重新启动代码工作。我使用下面的代码:重新启动恢复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.我没有发现任何代码重新启动在恢复,有没有什么办法可以通过代码恢复重启?
如果reboot命令,并呼吁该设备支持它的后端的版本,这可能工作:当然
String command="/system/bin/reboot recovery";
意识到分钟你用你玩不支持修改苏程序的android。
你为什么不使用:
((电源管理器)getSystemService(Context.POWER_SERVICE))重启( “恢复”)。
? http://developer.android.com/reference/android/os/PowerManager.html#reboot%28java.lang.String%29
此api需要REBOOT(android.permission.REBOOT)权限。根据此权限声明(在frameworks/base/core/res/AndroidManifest.xml中),其保护级别为'签名'。也就是说,使用此api的应用程序的apk应该使用与声明权限的应用程序相同的证书进行签名,即'framework-res'。如果签名的证书不可用,则更容易在不使用'/ system/bin/reboot'的情况下完成此操作。 – accuya
像Chris上面说的,但是我会把'su -c reboot recovery'写成'su'已经在Android系统路径中定义了,所以你不需要提供应用程序的完整路径。 – ChuongPham
@Chuong - 没有。该代码执行一个'su'进程和管道命令输入,因为'su'hacks并不都接受命令行执行的命令。由于在输入命令字符串时'su'已经在运行,所以您不希望再次在命令中包含'su'。此外,以root身份执行某些操作时,您不希望信任可能已被攻击者更改的路径设置,而是明确指定目标可执行文件。 –
我忘了提到OP可以运行上面提供的命令,而不是激活'su',然后运行像'/ system/bin/reboot recovery'这样的工作进程。无论哪种方式都适用于OP。 :) – ChuongPham