Skip to content

Instantly share code, notes, and snippets.

@spences10
Created January 21, 2013 18:31
Show Gist options
  • Save spences10/4588160 to your computer and use it in GitHub Desktop.
Save spences10/4588160 to your computer and use it in GitHub Desktop.
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;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment