Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Android 2.2: Reboot device programmatically

Tags:

android

reboot

I would like to know if there is a way to reboot the device through code. Ive tried:

Intent i = new Intent(Intent.ACTION_REBOOT); 
i.putExtra("nowait", 1); 
i.putExtra("interval", 1); 
i.putExtra("window", 0); 
sendBroadcast(i);

And added permissions for REBOOT but it still doesnt work.

Thanks

like image 384
Johan Avatar asked Jan 02 '11 20:01

Johan


1 Answers

This seemed to work for me:

try {
        Process proc = Runtime.getRuntime().exec(new String[] { "su", "-c", "reboot" });
        proc.waitFor();
    } catch (Exception ex) {
        Log.i(TAG, "Could not reboot", ex);
    }
like image 181
saulpower Avatar answered Oct 22 '22 06:10

saulpower