[Q] Check whether device is rooted or not programmatically?

Hello guys,

I would like to take your best suggestions and help for this issue. I have written function to check whether my device is rooted or not? Actually this function is working properly with other devices excepting Samsung Galaxy S4 MINI and Galaxy S5 rooted device. So we can say it is not working to the level of 100%. So kinldy help me to solve this issue and give your best suggestions with effective solution which can work on all the devices.

My Code is something like below :


Code:

/** * Checks if the device is rooted. * * @return <code>true</code> if the device is rooted, <code>false</code> otherwise. */ public static boolean isRooted() {

// get from build info String buildTags = android.os.Build.TAGS; if (buildTags != null && buildTags.contains("test-keys")) { return true; }

// check if /system/app/Superuser.apk is present try { File file = new File("/system/app/Superuser.apk"); if (file.exists()) { return true; } } 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 private static boolean canExecuteCommand(String command) { boolean executedSuccesfully; try { Runtime.getRuntime().exec(command); executedSuccesfully = true; } catch (Exception e) { executedSuccesfully = false; }

return executedSuccesfully; }

Waiting for your reply guys ASAP,

Thanks

Show Accepted Answer

Guest Quick Reply (No URL, BBcode or HTML)

Last post by slabadie
36 minutes ago
Last post by harber.brock
36 minutes ago
Last post by wilhelm.reichel
4 hours ago
Last post by wellington04
3 hours ago
Last post by adela.howell
3 hours ago
Last post by craig.runolfsson
3 hours ago
Last post by arlo54
45 minutes ago