The Android 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:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
/**
* 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 = 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:

1
2
3
4
5
6
7
@ 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.

Related Article

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.