Code to check is Device rooted or not,Android.

write these two lines inside onCreate() method:
boolean isRooted=isRooted();
        System.out.println("---------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 {
        Runtime.getRuntime().exec(command);
        executedSuccesfully = true;
      } catch (Exception e) {
        executedSuccesfully = false;
      }

      return executedSuccesfully;

    }

Comments

  1. Hi Pavan

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

    Regards,
    Bala.

    ReplyDelete

Post a Comment

Popular posts from this blog

Custom Dialog with no title and full screen in Android

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

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