Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to check if android phone is rooted? [duplicate]

Tags:

android

root

I want to programatically find in my application if the android phone is rooted. I found many links like: Determine if running on a rooted device Effective way to programatically check if I'm rooted on Android? discussing on the same topic. However, as mentioned in those links there is no one and definite way to find out. These posts are pretty old and I was wondering if there is anything better to achieve it now in recent releases?

Thanks in advance!

like image 793
Keya Avatar asked Oct 10 '13 06:10

Keya


2 Answers

I've wrapped this code (working ok without any other external jar/lib) from RootTools

private static boolean isRooted() {
    return findBinary("su");
}



public static boolean findBinary(String binaryName) {
    boolean found = false;
    if (!found) {
        String[] places = {"/sbin/", "/system/bin/", "/system/xbin/", "/data/local/xbin/",
                "/data/local/bin/", "/system/sd/xbin/", "/system/bin/failsafe/", "/data/local/"};
        for (String where : places) {
            if ( new File( where + binaryName ).exists() ) {
                found = true;
                break;
            }
        }
    }
    return found;
}
like image 160
StErMi Avatar answered Sep 22 '22 19:09

StErMi


You can use the roottools library. They offer a method to check for root access. https://code.google.com/p/roottools/

like image 22
MatF Avatar answered Sep 20 '22 19:09

MatF