1

我终于设法让重新启动代码工作。我使用了以下代码:

        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。我没有找到任何用于在恢复中重新启动的代码,有没有办法通过代码在恢复中重新启动?

4

2 回答 2

1

如果 reboot 命令的版本和它在该设备上调用的后端支持它,这可能会起作用:

String command="/system/bin/reboot recovery";

当然要意识到,在您使用 su 程序的那一刻,您正在使用不受支持的 android 修改。

于 2011-08-18T18:21:58.517 回答
1

你为什么不使用:

((PowerManager) getSystemService(Context.POWER_SERVICE)).reboot("recovery");

? http://developer.android.com/reference/android/os/PowerManager.html#reboot%28java.lang.String%29

于 2011-09-14T00:18:28.730 回答