Install Android APK without prompt

后端 未结 2 1720
伪装坚强ぢ
伪装坚强ぢ 2020-12-07 15:05

We are writing an Android app that shows ads on large screens. We have a backend where advertisers can select the ads, so they are updated almost instantly. Because there wi

相关标签:
2条回答
  • 2020-12-07 15:26
    public void InstallAPK(String filename){
    
        Process process = Runtime.getRuntime().exec("su");
        OutputStream out = process.getOutputStream();
        String reinstall = "pm install -r " + filename + "\n";
        String am = "am start -a android.intent.action.MAIN -n yourPackage/.MainActivity";
        String cmd = reinstall + am + " &";
        out.write(cmd.getBytes());
        out.flush();
        out.close();
        process.waitFor();
    
    }
    
    0 讨论(0)
  • 2020-12-07 15:34

    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;
                command = "adb install -r " + filename;
                Process proc = Runtime.getRuntime().exec(new String[] { "su", "-c", command });
                proc.waitFor();
            } catch (Exception e) {
            e.printStackTrace();
            }
         }
      }
    

    OR

    Please check http://paulononaka.wordpress.com/2011/07/02/how-to-install-a-application-in-background-on-android/

    0 讨论(0)
提交回复
热议问题