Code to check is Device rooted or not,Android.

write these two lines inside onCreate() method:
boolean isRooted=isRooted();
------------------and use below methods
     * Checks if the device is rooted.
     * @return <code>true</code> if the device is rooted, <code>false</code> otherwise.
    public static boolean isRooted() {

      // get from build info
      String buildTags = android.os.Build.TAGS;
      if (buildTags != null && buildTags.contains("test-keys")) {
        return true;

      // check if /system/app/Superuser.apk is present
      try {
        File file = new File("/system/app/Superuser.apk");
        if (file.exists()) {
          return true;
      } catch (Exception e1) {
        // ignore

      // try executing commands
      return canExecuteCommand("/system/xbin/which su")
          || canExecuteCommand("/system/bin/which su") || canExecuteCommand("which su");

    // executes a command on the system
    private static boolean canExecuteCommand(String command) {
      boolean executedSuccesfully;
      try {
        executedSuccesfully = true;
      } catch (Exception e) {
        executedSuccesfully = false;

      return executedSuccesfully;



  1. Hi Pavan

    Exactly what I was looking for.
    Your points seem very good and sure it will helpful for many people.



Post a Comment

Popular posts from this blog

Custom Dialog with no title and full screen in Android

code to display .pdf,.text,.DOC,.DOCX,.doc extension files exists in SDCard

Best working code to set Date limits on Date Picker Dialog,in Android