Rahul Patil
Rahul Patil

Reputation: 53

Reboot in Recovery Android

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?

Upvotes: 1

Views: 8523

Answers (2)

user848640
user848640

Reputation: 66

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

Upvotes: 1

Chris Stratton
Chris Stratton

Reputation: 40347

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.

Upvotes: 1

Related Questions