To grant the Root permission to the Android app, the Android device must have the Root permission.
How an application obtains Root permissions: grant the highest permissions to the Code Execution directory of the application. In Linux, chmod 777
[Code] java code:
/**
* If the application runs the command to obtain the Root permission, the device must be cracked (obtain the ROOT permission)
*
* @ Return application Yes/No get Root permission
*/
Public static boolean upgradeRootPermission (String pkgCodePath ){
Process process = null;
DataOutputStream OS = null;
Try {
String cmd = "chmod 777" + pkgCodePath;
Process = runtime.getruntime(cmd.exe c ("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;
}
Call code:
[Code] java code:
@ Override
Public void onCreate (Bundle savedInstanceState ){
Super. onCreate (savedInstanceState );
SetContentView (R. layout. main );
// Code execution directory of the current application
UpgradeRootPermission (getPackageCodePath ());
}
After executing the above Code, the system will pop up the dialog box "whether to allow the Root permission to be obtained". Then, select allow.