安装:
String str = "/CanavaCancel.apk";
String fileName = Environment.getExternalStorageDirectory() + str;
Intent intent = new Intent(Intent.ACTION_VIEW);
intent.setDataAndType(Uri.fromFile(new File(fileName)), "application/vnd.android.package-archive");
startActivity(intent);
卸载:
Uri packageURI = Uri.parse("package:com.demo.CanavaCancel");   
Intent uninstallIntent = new Intent(Intent.ACTION_DELETE, packageURI);   
startActivity(uninstallIntent);
Environment拥有一些可以获取环境变量的方法 
package:com.demo.CanavaCancel 这个形式是 package:程序完整的路径 (包名+程序名).

//下载apk程序代码
protected File downLoadFile(String httpUrl) {
                // TODO Auto-generated method stub
                final String fileName = "updata.apk";
                File tmpFile = new File("/sdcard/update");
                if (!tmpFile.exists()) {
                        tmpFile.mkdir();
                }
                final File file = new File("/sdcard/update/" + fileName);
                try {
                        URL url = new URL(httpUrl);
                        try {
                                HttpURLConnection conn = (HttpURLConnection) url
                                                .openConnection();
                                InputStream is = conn.getInputStream();
                                FileOutputStream fos = new FileOutputStream(file);
                                byte[] buf = new byte[256];
                                conn.connect();
                                double count = 0;
                                if (conn.getResponseCode() >= 400) {
                                        Toast.makeText(Main.this, "连接超时", Toast.LENGTH_SHORT)
                                                        .show();
                                } else {
                                        while (count <= 100) {
                                                if (is != null) {
                                                        int numRead = is.read(buf);
                                                        if (numRead <= 0) {
                                                                break;
                                                        } else {
                                                                fos.write(buf, 0, numRead);
                                                        }
                                                } else {
                                                        break;
                                                }
                                        }
                                }
                                conn.disconnect();
                                fos.close();
                                is.close();
                        } catch (IOException e) {
                                // TODO Auto-generated catch block
                                e.printStackTrace();
                        }
                } catch (MalformedURLException e) {
                        // TODO Auto-generated catch block
                        e.printStackTrace();
                }
                return file;
        }
//打开APK程序代码
private void openFile(File file) {
                // TODO Auto-generated method stub
                Log.e("OpenFile", file.getName());
                Intent intent = new Intent();
                intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
                intent.setAction(android.content.Intent.ACTION_VIEW);
                intent.setDataAndType(Uri.fromFile(file),
                                "application/vnd.android.package-archive");
                startActivity(intent);
        }

Android实现文件下载并自动安装apk包相关推荐

  1. appium自动化脚本之自动安装apk包到手机

    Appium基础篇3-第一个appium自动化脚本之自动安装apk包到手机 这篇,我们开始来一个实战练习,如何通过appium自动把电脑上一个安卓程序包给安装到一台安卓手机中.在写脚本之前,我们需要统 ...

  2. Appium基础篇3-第一个appium自动化脚本之自动安装apk包到手机

    这篇,我们开始来一个实战练习,如何通过appium自动把电脑上一个安卓程序包给安装到一台安卓手机中.在写脚本之前,我们需要统一下方法和工具.我们知道Appium和selenium一样都支持Java和P ...

  3. android下载完成不能自动安装失败,android 8.0以上自动安装apk失败的解决问题

    随着android 系统的不断更新和发展,针对应用的权限管理也是越来越严格.这可是坑坏了我们这些搬砖的程序员,因为在一些上架平台,都一一宣布,以后的android应用 targetSdkVersion ...

  4. android apk自动安装包下载,Android实现应用下载并自动安装apk包

    安装: String str = "/CanavaCancel.apk"; String fileName = Environment.getExternalStorageDire ...

  5. android.os.FileUriExposedException 自动安装APK报错 5分钟搞定Android 7.0+ FileProvider

    android.os.FileUriExposedException 自动安装APK报错  5分钟搞定Android 7.0+ FileProvider 适配步骤: 1. 创建file_paths.x ...

  6. Android使用adb有线跟无线安装apk包

    有线的情况下 1.手机USB与电脑相连,win+r打开输入cmd命令 2.adb devices查看是否已连接设备 3.adb install 包(地址)安装apk包 也可以通过adb install ...

  7. python自动安装apk文件

    最近在学习python,在前一段时间用dos写了一脚本,自动安装apk文件,于是也试着用python写了一这样的脚本. dos脚本地址:http://blog.csdn.net/lyhdream/ar ...

  8. Android P使用pm install安装apk报错

    Android P使用pm install安装apk报错 avc: denied { read } for scontext=u:r:system_server:s0 tcontext=u:objec ...

  9. adb命令 (安装apk包格式:adb install 电脑上apk地址包名)

    1.adb基础命令 配置好环境变量后,在cmd窗口打开命令行,敲adb device,验证adb连接设备成功 (前置条件:adb环境配置成功.开发者选项开启了USB调试模式) 1.1.进入手机的设置- ...

最新文章

  1. ViewPager 实现界面加载不同的数据
  2. WritePrivateProfileString、GetPrivateProfileString 读写配置文件
  3. Python分式计算
  4. mscoreei.dll没有被指定在windows上运行_windows注册表详解
  5. Inconsistent behavior between text type in Webclient UI and backend customizing
  6. How to increase sales, in addition to manufacturing different phones
  7. MongoDB在windows下的安装步骤:
  8. Atitit.用户权限服务 登录退出功能
  9. 华为悦盒EC6018V9E线刷linux教程
  10. 不同的count用法
  11. java web查询某个时间段记录
  12. 游戏数据库版本更新神器Flyway
  13. 【Python3】抓取Github吉祥物Octocat昵图并下载到本地
  14. java使用ftp上传文件
  15. 推荐130 个相见恨晚的神器网站
  16. 网上购车平台,利弊知多少
  17. MATLAB编程之PTB:把实验结果和实验前录入信息整合
  18. Selenium2相关知识最全总结
  19. 重新开张,谢天谢地。
  20. MySQL-Test-Run测试工具

热门文章

  1. 带你看看获得鲁班奖的数据中心工程建设的有多完美!!
  2. 成功解决raise Py4JError py4j.protocol.Py4JError: py4j.protocol.Py4JError: Could not find py4j jar at
  3. 成功解决ERROR: Failed building wheel for pycocotools
  4. DL之GCN:GCN算法的简介(论文介绍)、架构详解、案例应用等配图集合之详细攻略
  5. JAVA_OA管理系统(三):Spring参数注入
  6. 蓝桥杯_风险度量(一题多解)
  7. Mysql升级过程的问题
  8. TCP socket编程记录(C语言)
  9. 使用Mapping实现的以太坊智能合约的代码
  10. Cocos2d-x之Sprite