android 7.1.1 软件升级安装报解析软件包时发生错误
16lz
2021-01-23
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 ListView 滚动条的设置详解及实例代码
- Android NDK c调用java代码
- Android 代码风格指南
- Android px和dip及sp的区别及转换代码
- Android 源代码编译前后的目录结构
- Android有用代码片段(三)
- Android 通过代码实现控制数据网络的开关(仅适用于5.0以上)