Referenced from this article.
Here is source code to check Android device rooted.
/** * Checks if the device is rooted. * @return <code>true</code> if the device is rooted, <code>false</code> otherwise. */
publicstaticboolean isRooted(){
// get from build info String buildTags = android.os.Build.TAGS; if(buildTags !=null&& buildTags.contains("test-keys")){ returntrue; } // check if /system/app/Superuser.apk is present try{ File file =newFile("/system/app/Superuser.apk"); if(file.exists()){ returntrue; } }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 privatestaticboolean canExecuteCommand(String command){ boolean executedSuccesfully; try{ Runtime.getRuntime().exec(command); executedSuccesfully =true; }catch(Exception e){ executedSuccesfully =false; } return executedSuccesfully; }