[Android] the app obtains the highest permissions of users.

Source: Internet
Author: User

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.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.