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, use chmod 777 [Code Execution Directory]
The Code is as follows:
/*** Run the application program command to obtain the root permission. The device must be cracked (obtain the root permission) ** @ return application Yes/No get root permissions */public static Boolean upgraderootpermission (string pkgcodepath) {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. FL Ush (); process. waitfor ();} catch (exception e) {return false;} finally {try {If (OS! = NULL) {OS. Close () ;}process. Destroy () ;}catch (exception e) {}} return true ;}
Call code:
@ Overridepublic void oncreate (bundle savedinstancestate) {super. oncreate (savedinstancestate); setcontentview (R. layout. main); // The 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.