Get the highest privileges in code first the phone is root, no root please don't look down.
The first is to write a static method
Copy Code code as follows:
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 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.
The time of the call
Copy Code code as follows:
IsRoot (Getpackagecodepath ());
So the phone will prompt the program to obtain the highest permission to agree, if the point is then acquired.
If you want to know the result, you can write.
Copy Code code as follows:
Boolean Rootresult=isroot (Getpackagecodepath ());
Rootresult is the result.