0

I'm trying to reboot programmatically my Galaxy S3.

Things that I've tried:

    try {
        Process proc = Runtime.getRuntime().exec(new String[] { "su", "-c", "reboot" });
        proc.waitFor();
    } catch (Exception ex) {
        Log.i("RebootActivity", "Could not reboot", ex);
    }

    try {
        Runtime.getRuntime().exec(new String[]{"su","-c","reboot now"});
    } catch (IOException e) {
        e.printStackTrace();
    }

    try 
    {           
        Process process = Runtime.getRuntime().exec("su");
        DataOutputStream os = new DataOutputStream(process.getOutputStream());
        os.writeBytes("reboot now\n");
    } 
    catch (Throwable t)
    {
        t.printStackTrace();
    }

Do you guys have any idea how to accomplish this?

Thanks.

Maurício Giordano
  • 3,116
  • 4
  • 32
  • 60

2 Answers2

0

Try to do one normal string looking like 《su \n reboot; \n》 instead of an array. Try to get the answer from the shell, that helps a lot for debugging.

What are the permissions of your su binary? If they would be wrong, you could try to 《chmod 7777 /system/xbin/su》 after 《mount -o remount,rw /system》

Here is some example code: (to run the string command, which is a \n and or ; separated list of linux shell commands)

StringBuffer commandOutput = new StringBuffer();
    try {
        Process process = Runtime.getRuntime().exec("su\n");
        DataOutputStream out = new DataOutputStream(process.getOutputStream());
        out.writeBytes("export LD_LIBRARY_PATH=$LD_LIBRARY_PATH:/vendor/lib:/system/lib\n");
        out.writeBytes(command+"\n");
        out.flush();

        process.waitFor();
        BufferedReader in = new BufferedReader(new InputStreamReader(process.getInputStream()));
        int numRead;
        char[] buffer = new char[1000];
        while ((numRead = in.read(buffer)) > 0) {
            commandOutput.append(buffer, 0, numRead);
        }
        in.close();
        process.waitFor();
    } catch ...

    return commandOutput.toString();
user3387542
  • 611
  • 1
  • 8
  • 28
0

You could possibly use the PowerManager to make it reboot (this does not guarantee that it'll reboot - OS may cancel it): http://developer.android.com/reference/android/os/PowerManager.html#reboot(java.lang.String


http://developer.android.com/reference/android/Manifest.permission.html#REBOOT

biegleux
  • 13,179
  • 11
  • 45
  • 52
Muhammad Waleed
  • 2,517
  • 4
  • 27
  • 75