Android Install apk silently by busybox command-line

yuralife picture yuralife · Jan 18, 2013 · Viewed 7.8k times · Source

I want to install .apk silently in background by BusyBox command. I`ve seen some similar questions like THIS, but I still cant get working my code properly...

I have:

  1. My .apk I need to install on /sdcard/download/app.apk
  2. Root
  3. BusyBox installed

Code (not working):

String sss = Environment.getExternalStorageDirectory() + "/download/" + "app.apk";
Process install;
install = Runtime.getRuntime().exec("/system/xbin/busybox pm install " + sss); 
int success = install.waitFor();

If I use "install" instead of "pm install" it copies file well.

P.S. Code above is executing in AsyncTask. No errors, but also nothing happens... Please help!

Also I tried this, but I`m getting exit value 139 and no result:

        Process process;
        process = Runtime.getRuntime().exec("su");
        DataOutputStream os = new DataOutputStream(process.getOutputStream());
        os.writeBytes("pm install /mnt/sdcard/app.apk\n");
        os.flush();
        os.writeBytes("exit\n");
        os.flush();

        int i = process.waitFor();

Answer

Ferdiyan Syah picture Ferdiyan Syah · Oct 4, 2013

maybe this code will help you

Process p = null;
try
{
    p = Runtime.getRuntime().exec("su");
    DataOutputStream outs=new DataOutputStream(p.getOutputStream());

    String cmd="pm install /mnt/sdcard/app.apk";
    outs.writeBytes(cmd+"\n");
}
catch (IOException e)
{
    e.printStackTrace();
}