Android Install apk silently by busybox command-line

点点圈 提交于 2019-11-30 10:21:02
Ferdiyan Syah

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

After a lot of investigations on many android devices I realized that this code is correct and works!

There was just some problem with one device (Samsung Galaxy Tab 2 7.0 - 4.0.3 ICS). Maybe that is some strange feature of ICS. After updating firmware to 4.1.2 (Jelly Bean) problem has been resolved.

You can simply use adb install command to install/update APK silently. Sample code is below

public static void InstallAPK(String filename){
    File file = new File(filename); 
    if(file.exists()){
        try {   
            String command;
            filename = StringUtil.insertEscape(filename);
            command = "adb install -r " + filename;
            Process proc = Runtime.getRuntime().exec(new String[] { "su", "-c", command });
            proc.waitFor();
        } catch (Exception e) {
        e.printStackTrace();
        }
     }
  }
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!