Android Java su命令权限被拒绝

时间:2018-06-08 05:32:19

标签: java android emulation su

尝试使用adb install命令以静默方式安装/更新APK时遇到了一些问题。我指的是this thread

这是我的代码:

public boolean installApk(Activity mActivity){
    boolean success = false;
    String fullPath = scanDirectoryForApk();
    try {
        String command;
        command = "adb install -r " + fullPath;
        Process proc = Runtime.getRuntime().exec(new String[] { "su", "-c", command });
        proc.waitFor();
        success = true;
    } catch (Exception e) {
        e.printStackTrace();
    }
}

在我的AndroidManifest.xml中:

<uses-permission android:name="android.permission.INSTALL_PACKAGES"/>
<uses-permission android:name="android.permission.WRITE_SYNC_SETTINGS"/>
<uses-permission android:name="android.permission.REBOOT" />

这样的logcat:

java.io.IOException: Cannot run program "su": error=13, Permission denied
06-08 03:46:37.612 5438-5905/com.mainapp W/System.err:     at java.lang.ProcessBuilder.start(ProcessBuilder.java:1048)
    at java.lang.Runtime.exec(Runtime.java:692)
    at java.lang.Runtime.exec(Runtime.java:560)
    at com.thermofisher.viewmodel.vuViewModel.installApk(vuViewModel.java:281)
    at com.mainapp.asynctask.evuTask.doInBackground(evuTask.java:67)
06-08 03:46:37.614 5438-5905/com.mainapp W/System.err:     at com.mainapp.asynctask.evuTask.doInBackground(evuTask.java:17)
    at android.os.AsyncTask$2.call(AsyncTask.java:333)
    at java.util.concurrent.FutureTask.run(FutureTask.java:266)
06-08 03:46:37.615 5438-5905/com.mainapp W/System.err:     at android.os.AsyncTask$SerialExecutor$1.run(AsyncTask.java:245)
    at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1162)
    at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:636)
    at java.lang.Thread.run(Thread.java:764)

我正在使用Android Emulator运行该应用程序。当我运行模拟器时,我已经设置了命令使其变为root。

有什么想法吗?谢谢!

0 个答案:

没有答案