This question already has an answer here:
-
Determine if running on a rooted device
20 answers
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!
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;
}
You can use the roottools library. They offer a method to check for root access.
https://code.google.com/p/roottools/