android 7.0安装apk失败
来源:互联网 发布:红米note3数据连接不上 编辑:程序博客网 时间:2024/05/16 16:10
7.0中通过FileProvider 来对Content URI读取授权处理 可参考谷歌官网对FileProvider的说明点击打开链接。
1.在AndroidManifest.xml中定义FileProvider:
<manifest xmlns:android="http://schemas.android.com/apk/res/android">
<application>
</application><provider android:name="android.support.v4.content.FileProvider"android:authorities="包名.fileProvider" android:exported="false" android:grantUriPermissions="true"> <meta-data android:name="android.support.FILE_PROVIDER_PATHS"<!--定义自己的存储路径文件--> android:resource="@xml/file_paths" /> </provider>
</manifest>
2.在res报下创建xml包并在xml包下创建file_paths.xml文件:<?xml version="1.0" encoding="utf-8"?><paths> <external-path path="Android/data/包名/" name="files_root" /> <external-path path="." name="external_storage_root" /></paths>
3.在安装apk的时候检测并调用:
over ! ! !//mSavePath :apk的下载到本地的存储路径
//fileName:apk的名字
File file = new File(mSavePath, fileName);Uri downloadFileUri = Uri.fromFile(file);Intent install = new Intent(Intent.ACTION_VIEW);if (downloadFileUri != null) { if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N) { install.setFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION); Uri contentUri = FileProvider.getUriForFile(context, "包名.fileProvider", file); install.setDataAndType(contentUri, "application/vnd.android.package-archive"); } else { install.setDataAndType(Uri.fromFile(file), "application/vnd.android.package-archive"); install.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK); } context.getApplicationContext().startActivity(install);}
阅读全文
0 0
- android 7.0安装apk失败
- android studio安装apk失败
- android apk包过大安装失败
- android 5.0 apk 安装失败提示INSTALL_FAILED_INVALID_URI
- android 5.0 apk 安装失败提示INSTALL_FAILED_INVALID_URI
- Android 5.0 权限管理, apk安装失败
- Android模拟器安装apk失败解决方案
- Android apk安装失败 Failure [INSTALL_FAILED_OLDER_SDK]
- APK安装失败汇总~
- INSTALL_FAILED_INSUFFICIENT_STORAGE apk安装失败
- APK安装失败
- androidstudio安装apk失败
- apk安装失败笔记
- apk安装失败
- Apk安装失败原因
- Android 版本更新下载自动安装APK,并解决Android6.0,7.0安装失败的问题
- Android 打包apk 安装失败 应用未安装的问题
- android studio安装apk安装失败的问题。
- 文章标题
- Java static 关键字
- Elasticsearch配置文件
- JVM和Dalvik的区别
- java.util.ConcurrentModificationException迭代器出错
- android 7.0安装apk失败
- xcode9报错compiling ib doucument for earlier than ios7 is no longer supported
- Kotlin官方文档翻译—概述
- python实践项目(六)
- 猜计算机随机数
- ImageLoader图片加载框架
- php利用腾讯ip分享计划获取地理位置示例分享
- 运行.xcworkspace项目后报错:'React/RCTBundleURLProvider.h’ file not found
- Spark学习之路-Spark集群搭建