This is what I use:
public static boolean isDeviceRooted () { boolean ret = false; String path = null; Map<String,String> env = System.getenv(); if (env != null && (path = env.get("PATH")) != null) { setDevicePath(path); String [] dirs = path.split(":"); for (String dir : dirs){ String suPath = dir + "/" + "su"; File suFile = new File(suPath); if (suFile != null && suFile.exists()) { setSuLocation(suPath); ret = true; } } } return ret; }
Theoretically, it will not work in all cases, because the user can put "su" in a non-standard location that is not in PATH, but practically, if he does, other applications that need to know where "su" will not find him, therefore the rooting goal will be defeated.
source share