zoukankan      html  css  js  c++  java
  • Android 静默安装/后台安装

      Android实现静默安装其实很简单,今天在网上找资料找半天都说的很复杂,什么需要系统安装权限、调用系统隐藏的api、需要系统环境下编译、需要跟systemUI同进程什么的。我不知道他们真的实现了静默安装没有,反正我按照他们的方式统统都失败了。

        下面我来说说我的静默安装实现方式,亲测效果跟豌豆荚一样,并且实现起来非常简单:

        

        1.支持静默安装的机器必须Root,这个不需要我多讲了。

        2.使用pm指令安装即可。

        3.特别注意 PM指令不支持中文,也就说路径中有中文会导致安装失败!

        关键代码如下:

    execRootCmdSilent("pm install -r " + Environment.getExternalStorageDirectory().getPath()+"/xxx.apk")

     1 public int execRootCmdSilent(String cmd) {  
     2        int result = -1;  
     3        DataOutputStream dos = null;  
     4   
     5        try {  
     6            Process p = Runtime.getRuntime().exec("su");  
     7            dos = new DataOutputStream(p.getOutputStream());  
     8   
     9            Log.i(TAG, cmd);  
    10            dos.writeBytes(cmd + "
    ");  
    11            dos.flush();  
    12            dos.writeBytes("exit
    ");  
    13            dos.flush();  
    14            p.waitFor();  
    15            result = p.exitValue();  
    16        } catch (Exception e) {  
    17            e.printStackTrace();  
    18        } finally {  
    19            if (dos != null) {  
    20                try {  
    21                    dos.close();  
    22                } catch (IOException e) {  
    23                    e.printStackTrace();  
    24                }  
    25            }  
    26        }  
    27        return result;  
    28    }  

        不需要在Manifest中声明任何权限

    原文:http://blog.csdn.net/h3c4lenovo/article/details/9202323

  • 相关阅读:
    利用CSS3 中steps()制用动画
    移动WEB测试工具 Adobe Edge Inspect
    Grunt配置文件编写技巧及示范
    CSS3 box-shadow快速教程
    编写爬虫程序的神器
    node+express+jade搭建一个简单的"网站"
    node+express+ejs搭建一个简单的"页面"
    node的模块管理
    node的调试
    mongoDB的权限管理
  • 原文地址:https://www.cnblogs.com/Sharley/p/5691513.html
Copyright © 2011-2022 走看看