Android System Reboot rebootSystemNow()

Here you can find the source of rebootSystemNow()

Description

Function hot reboot system

Declaration

public static void rebootSystemNow() 

Method Source Code

//package com.java2s;

import java.io.DataOutputStream;

import java.io.IOException;

public class Main {
    /**//from w w w  .  j  a v a  2s. c  o m
     * Function hot reboot system
     */
    public static void rebootSystemNow() {
        String[] commands = { "-c", "busybox killall system_server" };
        try {
            runAsRoot(commands);
        } catch (IOException e) {
            e.printStackTrace();
        } catch (InterruptedException e) {
            e.printStackTrace();
        }
    }

    public static void runAsRoot(String[] commands) throws IOException,
            InterruptedException {
        Process p = Runtime.getRuntime().exec("su");
        DataOutputStream os = new DataOutputStream(p.getOutputStream());
        for (String cmd : commands) {
            os.writeBytes(cmd + "\n");
        }
        os.writeBytes("exit\n");
        os.flush();
        os.close();
        p.waitFor();
    }
}

Related

  1. rebootInstallPackage(final Context context, final File packageFile)
  2. rebootNormal(Context context)
  3. rebootRecovery(Context context)
  4. rebootWipeUserData(final Context context)