开发者

Reboot in Recovery Android

开发者 https://www.devze.com 2023-03-29 06:02 出处:网络
I\'ve finally managed to get the Reboot code work. I used following code : Runtime runtime = Runtime.getRuntime();

I've finally managed to get the Reboot code work. I used following code :

        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) {
                    }

Now I want a code that will reboot the device into recovery mode. The application will be only for Samsung Galaxy S. I didn't found any code for reboot in recovery, is there any way to reboot in recovery via code?


If the version of the reboot command and the backend it calls on that device supports it, this may work:

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

Realize of course that the minute you use the su program you are playing with unsupported modifications of android.


Why are you not using:

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

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

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号