Android gets the instance code for root permission _android

Source: Internet
Author: User

Getting Android's root privileges is simple, as long as you execute the command "SU" under Runtime.

Copy Code code as follows:

Get root Permissions
public void Get_root () {

if (Is_root ()) {
Toast.maketext (Mctx, "already has root privileges!", Toast.length_long). Show ();
}
else{
try{
Progress_dialog = Progressdialog.show (Mctx,
"Root", "Getting root permission ...", true, false);
Runtime.getruntime (). EXEC ("su");
}
catch (Exception e) {
Toast.maketext (mctx, "Error getting root permission!", Toast.length_long). Show ();
}
}

}

where Is_root () determines whether the root permission is already in existence. As long as one of the two files in/system/bin/su,/system/xbin/su, indicates that you already have root permissions, and if two do not exist, you do not have root permissions.

Copy Code code as follows:

Determining whether to have root permissions
public static Boolean Is_root () {

Boolean res = false;

try{
if ((!new File ("/system/bin/su"). Exists ()) &&
(!new File ("/system/xbin/su"). Exists ())) {
res = false;
}
else {
res = true;
};
}
catch (Exception e) {

}
return res;

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.