Android code to get the highest permissions after the phone root
- 2020-05-09 19:20:57
- OfStack
First the phone gets root without root, please do not look down.
The first is to write a static method
This method returns true and false.
When it's called
This will prompt the application on the phone to get the highest permission, and if so, it will get it.
You could write it this way if you wanted to know
rootResult is the result.
The first is to write a static method
public static boolean isRoot(String pkgCodePath) {
Process process = null;
DataOutputStream os = null;
try {
String cmd = "chmod 777 " + pkgCodePath;
process = Runtime.getRuntime().exec("su"); // Switch to the root account
os = new DataOutputStream(process.getOutputStream());
os.writeBytes(cmd + "\n");
os.writeBytes("exit\n");
os.flush();
process.waitFor();
} catch (Exception e) {
return false;
} finally {
try {
if (os != null) {
os.close();
}
process.destroy();
} catch (Exception e) {
}
}
return true;
}
This method returns true and false.
When it's called
isRoot(getPackageCodePath());
This will prompt the application on the phone to get the highest permission, and if so, it will get it.
You could write it this way if you wanted to know
boolean rootResult=isRoot(getPackageCodePath());
rootResult is the result.