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(安卓)NDK c调用java代码
  2. Android(安卓)全屏与沉浸式
  3. android 启动其它apk
  4. android 开发中的Log
  5. 基于ffmpeg的Android播放器开源代码
  6. cmake 编译 ogre3D(version1.9) for android
  7. Android(安卓)ListView 滚动条的设置详解及实例代码
  8. eclipse中无法新建Android工程 出现问题:Plug-in org.eclipse.ajd
  9. Android(安卓)Studio 本地化配置gradle的buildToolsVersion和gra

随机推荐

  1. Android实现3个圆圈的动画
  2. Android简易注解View(java反射实现)
  3. android解析json小例子
  4. AndroidManifest.xml之 element详解
  5. android讲义9之向电话本进行批处理的插入
  6. cocos2d-x环境搭建 for eclipse
  7. Android 原生开发、H5、React-Native开发
  8. [实战示例] 带您深入探讨 Android 传感器
  9. Android一个textview显示多段文本不同颜
  10. Android下获取Root权限和设置目录属性