spences10
1/21/2013 - 6:31 PM

Root checker

Root checker

 public static boolean hasRootPermission() {
        Process process = null;
        DataOutputStream os = null;
        boolean rooted = true;
        try {
            process = Runtime.getRuntime().exec("su");
            os = new DataOutputStream(process.getOutputStream());
            os.writeBytes("exit\n");
            os.flush();
            process.waitFor();
            if (process.exitValue() != 0) rooted = false;
        } catch (Exception e) {
            rooted = false;
        } finally {
            if (os != null) {
                try {
                    os.close();
                    process.destroy();
                } catch (Exception e) {
                }
            }
        }
        return rooted;
    }