android os FileUriExposedException file storage emulated 0 test tx
错误出现原因: 在Android版本7.0以上,应用之间文件访问权限修改。 解决办法: 我们需要使用FileProvider允许其他应用访问本应用创建的文件或文件夹,首先需要创建继承android.support.v4.content.FileProvider的类,以确保我们的FileProvider与在导入的依赖关系中声明的FileProvider不冲突,详细在这里 ####步骤 使用content:// uri取代 file:// uri 创建继承FileProvider的类
public class myFileProvider extends FileProvider {}
复制代码
在AndroidManifest.xml中添加如下代码:
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"...<application...<providerandroid:name=".myFileProvider"android:authorities="${applicationId}.provider"android:exported="false"android:grantUriPermissions="true"><meta-dataandroid:name="android.support.FILE_PROVIDER_PATHS"android:resource="@xml/provider_paths"/></provider></application>
</manifest>
复制代码
注意: authorities:app的包名.fileProvider grantUriPermissions:必须是true,表示授予 URI 临时访问权限 exported:必须是false resource:中的@xml/file_paths是我们接下来要添加的文件
在res目录下新建一个xml文件夹,并且新建一个file_paths的xml文件(如下图)
file_paths内容:
<?xml version="1.0" encoding="utf-8"?>
<paths>
<-- apk保存的目录为:Android/data/包名/...--><external-path path="Android/data/包名/" name="files_root" /><external-path path="." name="external_storage_root" />
</paths>
复制代码
path:需要临时授权访问的路径(.代表所有路径) name:就是你给这个访问路径起个名字
修改代码适配Android N apk保存的目录为:Android/data/包名/
Intent intent = new Intent(Intent.ACTION_VIEW);
//判断是否是AndroidN以及更高的版本
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N) {intent.setFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION);Uri contentUri = FileProvider.getUriForFile(context, BuildConfig.APPLICATION_ID + ".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);
}
startActivity(intent);
复制代码
转载于:https://juejin.im/post/5a31d4b151882507ae26027e
android os FileUriExposedException file storage emulated 0 test tx相关推荐
- Android7.0解决 android.os.FileUriExposedException: file:///storage/emulated/0/
解决Android N文件访问crash android.os.FileUriExposedException file:///storage/emulated/0/xxx 原因: Android N ...
- 解决 Android N 上报错:android.os.FileUriExposedException: file:///storage/emulated/0/
解决android N文件访问crash android.os.FileUriExposedException file:///storage/emulated/0/xxx 原因: Android N ...
- Android打开相机,报出 android.os.FileUriExposedException: file:///storage/emulated/0/test/img.jpg exposed
执行以下代码后,打开相机 //调用相机自带的照相功能 指定图片目录 if (Environment.getExternalStorageState().endsWith(Environment.MED ...
- android.os.FileUriExposedException: file:///storage/emulated/0/pictures/1564739776566.jpg exposed be
问题: 原因:Android N(对应sdk24)(版本7.0)及以上对访问文件权限收回,按照Android N的要求,若要在应用间共享文件,您应发送一项 content://URI,并授予 URI ...
- android.os.FileUriExposedException: file:///storage/emulated/0/myxmpp/154094
在项目的MainActivity的开始添加下面这段代码 if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N) {StrictMode.VmPol ...
- android.os.FileUriExposedException: file:///storage/emulated/0/myimage/15115
复制的https://blog.csdn.net/qq_33210042/article/details/78626701 管用!已收藏 //取消严格模式 FileProvider if (Build ...
- FileUriExposedException: file:///storage/emulated/0/Android/data/com.skyrin.bingo/cache/app/app.apk
安卓在app更新的时候file parseuri 报错FileuriExposedException:.................exposed beyond app through Inten ...
- FileUriExposedException: file:///storage/emulated/0/001/1612321465868.mp4 exposed beyond app through
我在调用系统相机的时候报错 private void openCamera() {Intent intent = new Intent(MediaStore.ACTION_VIDEO_CAPTURE) ...
- 安卓开发拍照时闪退遇到问题: file:///storage/emulated/0/0.jpg exposed beyond app through ClipData.Item.getUri()
问题描述: 打开摄像头拍照时程序闪退,错误提示如下: android.os.FileUriExposedException: file:///storage/emulated/0/RadioDirec ...
最新文章
- SIM PIN Lock
- Scala Implicit Conversion
- DGA域名可以是色情网站域名
- 浅析ASP.NET的Page.IsPostBack 属性http://www.sina.com.cn 2008年05月06日 11:33 IT168.com
- Java基础知识强化之IO流笔记13:递归之不死神兔问题(斐波那契数列)
- java基础--IO流之File类
- (四)Paint函数实现QTableView中增加QCheckBox的方法
- linux内核态删除文件函数,初探Linux内核态——通过proc文件系统作快速问题定位...
- 深入理解Nginx~Nginx配置的通用语法
- ANSI SQL标准和准则
- python题目-完数
- 震网三代在metasploit-framework上的复现与利用
- 报修管理系统微信小程序源码
- 领域对象映射到微服务代码模型
- 什么是智能无损网络?
- 计算机网络,概念,发展历史,分类,协议
- 博客篇-如何使用阿里云搭建网站
- wma格式怎么转换mp3,4种方法超快学
- 自定义竖向SeekBar (VerticalSeekBar)
- AForge学习笔记(5):AForge.Imaging(下)
热门文章
- 【软件测试】单元测试是软件测试的最基础环节
- 1034. 有理数四则运算(20)-PAT乙级真题
- Oracle 当前用户给另一个用户授权查询指定表或视图的权,否则另一个用户提示不存在视图或表
- 2-06 使用网络存储SAN和NAS
- AGG第四十二课 Blitting an image over another with transparency
- 《Effective Debugging:软件和系统调试的66个有效方法》一第2条:在网上确切地查询你所遇到的问题,以寻求解决问题的灵感...
- ios textView显示不全
- JavaScript的学习--生成二维码
- PHP 处理TXT文件(打开/关闭/检查/读取)
- 从世界杯看德国,再看国内