Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can check android Device is Rooted Device? [duplicate]

Tags:

android

adb

How can i check if android device is rooted or not? I am using the following code:

Process proc = Runtime.getRuntime ().exec ("su");

and when I run it on a device I got following exception.

Causes by:Permission denied

But running on an emulator does not give any exception.

I am using another way to check. Entering adb shell in the commend line for emulator returns #, but for device writing adb shell gives the following error:

shell@android:/ $ su  
su   
/system/bin/sh: su: not found   
127|shell@android:/ $  

So how can I check if device is rooted or not.

Thanks in Advance.

like image 684
Silambarasan Damodaran Avatar asked Nov 19 '12 06:11

Silambarasan Damodaran


People also ask

How do you tell if your phone has been rooted?

Here's how to check if the phone is rooted via the Settings app: Step 1: Open Settings, and click the "About phone" > "Status information" > "Phone status" option. Step 2: If your device has an official phone status, it is not rooted. Instead, if there is a custom tag on the screen, your phone has been rooted.

Why my device is showing rooted device?

A rooted device is an Android gadget that has been jailbroken to install unapproved apps, update OS, delete unwanted apps, underclock or overclock the processor, replace firmware and customize anything else. For an average mobile user, rooting a smartphone can be a sophisticated and scary process.

Which app is used to check the rooted device?

#6) SuperSU Best for the root access of Android devices for free. SuperSU is a great root access management tool developed for Android devices. The app is root-only software that helps you manage app permissions on your rooted device. Using the app allows you to protect your device from harmful apps after rooting.


1 Answers

I use this class:

private void CheckRoot()
    {                    
        Process p;

        try {  
               // Preform su to get root privledges  
               p = Runtime.getRuntime().exec("su");   

               // Attempt to write a file to a root-only  
               DataOutputStream os = new DataOutputStream(p.getOutputStream());  
               os.writeBytes("echo \"Do I have root?\" >/data/LandeRootCheck.txt\n");  

               // Close the terminal  
               os.writeBytes("exit\n");  
               os.flush();  
               try {  
                  p.waitFor();  
                       if (p.exitValue() == 0) {  
                          // TODO Code to run on success                         
                         this.IsRoot=true;
                       }  
                       else {  
                           // TODO Code to run on unsuccessful  
                           this.IsRoot=false;  
                       }  
               } catch (InterruptedException e) {  
                  // TODO Code to run in interrupted exception  
                   toastMessage("not root");  
               }  
            } catch (IOException e) {  
               // TODO Code to run in input/output exception  
                toastMessage("not root");  
            }  
    }
like image 55
Carlos Landeras Avatar answered Sep 24 '22 16:09

Carlos Landeras