1、在AndroidManifest.xml中添加如下代码    2、在res目录下新建一个xml文件夹,并且新建一个file_paths的xml文件
<?xml version="1.0" encoding="utf-8"?><paths xmlns:android="http://schemas.android.com/apk/res/android">    <external-path        name="external_storage_root"        path="." />paths>
3、修改代码适配Android N
private void installApk() {    try {        File apkfile = new File(mSavePath, mHashMap.get("name"));        if (!apkfile.exists()) {            return;        }        Intent intent = new Intent(Intent.ACTION_VIEW);        // 判断版本大于等于7.0        if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N) {            intent.addFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION); //临时授权            Uri contentUri = FileProvider.getUriForFile(mContext, "com.ea.mp.ev3.fileProvider", apkfile);            intent.setDataAndType(contentUri, "application/vnd.android.package-archive");        } else {            intent.setDataAndType(Uri.fromFile(apkfile), "application/vnd.android.package-archive");            intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);        }        mContext.startActivity(intent);    } catch (Exception e) {        e.printStackTrace();    }}

  • 1

更多相关文章

  1. Android ListView 滚动条的设置详解及实例代码
  2. Android NDK c调用java代码
  3. Android 代码风格指南
  4. Android px和dip及sp的区别及转换代码
  5. Android 源代码编译前后的目录结构
  6. Android有用代码片段(三)
  7. Android 通过代码实现控制数据网络的开关(仅适用于5.0以上)

随机推荐

  1. intent
  2. android 关于焦点的获取与监听失效问题的
  3. Android模拟器adb命令介绍
  4. 003.android资源文件剖析(Resources)
  5. Android(安卓)rom开发:通过拨号使用暗码打
  6. JAVA数据结构及算法--Android中Activity
  7. (转载)Android之Intent的基本使用
  8. Android(安卓)模拟器窗口大小的修改
  9. Android上的Open×××-TAP模式/策略路由
  10. Android(安卓)SDK Installed On Mac