简体   繁体   中英

How can I give root permission to my Android app?

I'm trying to use linux command in my app. But I failed to get root permission. Could you please let me know how to get root permission?

 String[] cmd = {"su"};
 String result_process2 = runProcess2(cmd);
 public String runProcess2(String[] cmd) {
    try {
          Process process = Runtime.getRuntime().exec(cmd);

It looks like doesn't work. One thing weird is I found su in /system/xbin, but when I check this directory through ls in app, su file didn't exist there.

Command is

String ls = "ls -al /system/xbin/";
String resultls = runProcess((String)ls);
public String runProcess(String arg) {
    try {
        Process process = Runtime.getRuntime().exec(arg);

Do you know why I couldn't see su file in /system/xbin/ even though it can be found through adb shell in my laptop?

A standard Android device does not have access to root privileges. In order to attain this you will have to root the device. See this link for more information.

As for why you can find the file through the ADB shell and not from within the app is probably that you don't have read access for the file outside the ADB shell.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM