Install apps silently, with granted INSTALL_PACKAGES permission

后端 未结 16 2443
梦谈多话
梦谈多话 2020-11-22 10:32

I am trying to silently install apk into the system. My app is located in /system/app and successfully granted permission \"android.permission.INSTALL_PACKAGES\"

Ho

16条回答
  •  爱一瞬间的悲伤
    2020-11-22 10:48

    I tried on rooted Android 4.2.2 and this method works for me:

    private void installApk(String filename) {
        File file = new File(filename); 
        if(file.exists()){
            try {   
                final String command = "pm install -r " + file.getAbsolutePath();
                Process proc = Runtime.getRuntime().exec(new String[] { "su", "-c", command });
                proc.waitFor();
            } catch (Exception e) {
                e.printStackTrace();
            }
         }
    }
    

提交回复
热议问题