There was a need to check for root rights on the device before launching the application. If they are absent, do not launch the application. It simply works until a certain event (pressing the button) only then requests permission, and not at the start. How can this be implemented?

    1 answer 1

    There are many methods, the most reinforced concrete:

    boolean isRoot=canExecuteCommand("/system/xbin/which su") || canExecuteCommand("/system/bin/which su") || canExecuteCommand("which su"); private static boolean canExecuteCommand(String command) { try { Runtime.getRuntime().exec(command); return true; } catch (Exception e) { return false; } } 
    • do not tell me, what's the point of going through the paths, because in theory it would be enough to use only "which su"? - ZigZag
    • just which su can give a false result if we put in the home which thread is a stupid stub with the name su - Barmaley
    • Thanks, the idea is clear, although in my opinion the above code will still work on a “stub” at home - ZigZag