is System Rooted - Android Android OS

Android examples for Android OS:Root

Description

is System Rooted

Demo Code

import java.io.DataOutputStream;
import java.io.IOException;

public class Main {

  public static boolean isRooted() {
    boolean result = false;
    try {/* w  w w  .j  av  a  2  s . c  o m*/
      Process process = Runtime.getRuntime().exec("su -");
      DataOutputStream dos = new DataOutputStream(process.getOutputStream());
      dos.writeBytes("ls /data/\n");
      dos.flush();
      dos.writeBytes("exit\n");
      dos.flush();
      try {
        if (process.waitFor() == 0) {
          result = true;
        }
      } catch (InterruptedException e) {
        e.printStackTrace();
      }
      process.destroy();
    } catch (IOException e) {
      e.printStackTrace();
    }
    return result;
  }

}

Related Tutorials