Android App request root permission

Source: Internet
Author: User
Tags root access

runtime = Runtime.getruntime ();

The effect of this sentence in Java is to obtain a computer terminal, for example, under Window is a DOS window, such as: Runtime.exec ("Color 2D") and directly under DOS directly input color 2D effect.

In wirelessly equivalent to get to the Linux terminal.

To get root access for Android apps, the Android device must have root access first.

How the app gets root permissions: Let the app's code execute the directory to get the highest permissions. chmod 777 [Code Execution directory] in Linux

/**
* Application Run command to get root permission, the device must be cracked (root access)
*
* @return App Yes/no get root permissions
*/
public static Boolean upgraderootpermission (String pkgcodepath) {
Process process = NULL;
DataOutputStream OS = null;
try {
String cmd= "chmod 777" + Pkgcodepath;
Process = Runtime.getruntime (). EXEC ("su"); Switch to root account
OS = new DataOutputStream (Process.getoutputstream ());

Os. WriteChars (cmd+ "\ n");
Os. WriteChars ("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;
}

Where pkgcodepath can be obtained by Getpackagecodepath ()

No root privileges required, only declaration: <uses-permission android:name= "Android.permission.READ_LOGS"/>

Can get the phone all the log information, that is, in the development of logcat inside the content displayed, this part of the content by WindowManager maintenance.

1. You can see what apps the user installed.

2. You can see your own application errors, convenient post-software maintenance log crawl.

Android App request root permission

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.