Collectives™ on Stack Overflow

Find centralized, trusted content and collaborate around the technologies you use most.

Learn more about Collectives

Teams

Q&A for work

Connect and share knowledge within a single location that is structured and easy to search.

Learn more about Teams

I was having some problem when trying to use adb install command to install/update APK silently. I am referring to this thread .

Here is my code:

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();

And in my 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" />

The logcat as such:

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)

I am running the application using Android Emulator. When I am running the emulator I already set the command to make it become rooted.

Any ideas? Thanks!

@RutvikBhatt But then I did set my emulator to become rooted by using the command like adb devices, adb root – user7691120 Jun 8, 2018 at 5:43 install root checker app from play store and check if your emulator is really rooted or not – Rutvik Bhatt Jun 8, 2018 at 5:45

Thanks for contributing an answer to Stack Overflow!

  • Please be sure to answer the question. Provide details and share your research!

But avoid

  • Asking for help, clarification, or responding to other answers.
  • Making statements based on opinion; back them up with references or personal experience.

To learn more, see our tips on writing great answers.