应用宝、360应用、豌豆荚等等都有一个比较好的功能就是下载应用自行安装,不用弹出安装应用对话框,他是怎么做到的呢?
这边采用在应用内部使用shell实现,但前提必须root,代码很简单:
- 
         public static void InstallAPK(String filename){
 - 
            File file = new File(filename); 
 - 
            if(file.exists()){
 - 
                try {   
 - 
                    String command;
 - 
                    command = "pm install -r " + filename;
 - 
                    Process proc = Runtime.getRuntime().exec(new String[] { "su", "-c", command });
 - 
                    proc.waitFor();
 - 
                } catch (Exception e) {
 - 
                e.printStackTrace();
 - 
                }
 - 
             }
 - 
          }
 
 
复制代码 
直接调用InstallAPK,给出apk的位置即可,比如:InstallAPK("/sdcard/JustTest.apk");
大功告成。Android静默安装应用
原文:http://blog.csdn.net/guanxiaomingniu/article/details/43482717