Created
January 21, 2013 18:31
-
-
Save spences10/4588160 to your computer and use it in GitHub Desktop.
Root checker
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment