Android静默安装应用

来源:互联网 发布:中国人工智能技术 编辑:程序博客网 时间:2024/05/22 12:01

应用宝、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");

大功告成。

0 0