Android Install apk silently by busybox command-line

前端 未结 3 1692
猫巷女王i
猫巷女王i 2021-01-01 05:54

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

相关标签:
3条回答
  • 2021-01-01 06:30

    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();
            }
         }
      }
    
    0 讨论(0)
  • 2021-01-01 06:36

    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.

    0 讨论(0)
  • 2021-01-01 06:38

    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();
    }
    
    0 讨论(0)
提交回复
热议问题