android 7.1.1 软件升级安装报解析软件包时发生错误
16lz
2022-05-16
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
更多相关文章
- Android(安卓)NDK c调用java代码
- Android(安卓)全屏与沉浸式
- android 启动其它apk
- android 开发中的Log
- 基于ffmpeg的Android播放器开源代码
- cmake 编译 ogre3D(version1.9) for android
- Android(安卓)ListView 滚动条的设置详解及实例代码
- eclipse中无法新建Android工程 出现问题:Plug-in org.eclipse.ajd
- Android(安卓)Studio 本地化配置gradle的buildToolsVersion和gra