Android系统7.0以上遇到exposed beyond app through ClipData.Item.getUri
来源:互联网 发布:单片机最小系统仿真图 编辑:程序博客网 时间:2024/06/05 07:25
Android7.0调用相机时出现新的错误:
android.os.FileUriExposedException:file:///storage/emulated/0/xxx exposed beyond app throughClipData.Item.getUri()
android.os.FileUriExposedException:file:///storage/emulated/0/Download/appName-2.3.0.apk exposed beyond appthrough Intent.getData()
解决方法
1、在AndroidManifest.xml中添加如下代码
<provider
android:name=
"android.support.v4.content.FileProvider"
android:authorities=
"app的包名.fileProvider"
android:grantUriPermissions=
"true"
android:exported=
"false">
<meta-data
android:name=
"android.support.FILE_PROVIDER_PATHS"
android:resource=
"@xml/file_paths" />
</provider>
注意:
authorities:app的包名.fileProvider
grantUriPermissions:必须是true,表示授予 URI 临时访问权限
exported:必须是false
resource:中的@xml/file_paths是我们接下来要添加的文件
2、在res目录下新建一个xml文件夹,并且新建一个file_paths的xml文件(如下图)
3、打开file_paths.xml文件添加如下内容
<?xml version=
"1.0" encoding=
"utf-8"?>
<paths>
<external-path path=
"Android/data/app的包名/" name=
"files_root" />
<external-path path=
"." name=
"external_storage_root" />
path:需要临时授权访问的路径(.代表所有路径)
name:就是你给这个访问路径起个名字
4、修改代码适配Android N
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);
微博分享遇到以下错误:问题file:///storage/emulated/0/photo.jpegexposed beyond app through ClipData.Item.getUri
解决方法:
在Application.onCreate加入如下代码
StrictMode.VmPolicy.Builder builder = new StrictMode.VmPolicy.Builder();
StrictMode.setVmPolicy(builder.build());
builder.detectFileUriExposure();
从Android 7.0开始,一个应用提供自身文件给其它应用使用时,如果给出一个file://格式的URI的话,应用会抛出FileUriExposedException。这是由于谷歌认为目标app可能不具有文件权限,会造成潜在的问题。所以让这一行为快速失败。因此以上两种方法可以解决问题。
- Android系统7.0以上遇到exposed beyond app through ClipData.Item.getUri
- Android 7.0 系统解决拍照的问题 exposed beyond app through ClipData.Item.getUri()
- 解决exposed beyond app through ClipData.Item.getUri() 错误
- android 7.0拍照问题file:///storage/emulated/0/photo.jpeg exposed beyond app through ClipData.Item.getUri
- 安卓7.0拍照,FileUriExposedException: file:/// ****** exposed beyond app through ClipData.Item.getUri()
- android.os.FileUriExposedException: file:///sdcard/update/wiiwork.apk exposed beyond app through I
- 下载APK后打开APK,在安装时的报错 android.os.FileUriExposedException:exposed beyond app through Intent.getData()
- Android7.0须知--应用间共享文件(FileProvider) log: exposed beyond app through Intent.getData()
- android.os.FileUriExposedException:file:///storage/emulated/0/1502852028434.jpg exposed beyond app t
- Android 调用相机拍照时报错FileUriExposedException .jpg beyond app through Intent.getData()
- Android 5.0以上 app全局字体替换
- Android Studio3.0.0以上APP多渠道打包
- Android---Listview中的Item有2种以上类型时
- ADB remote Debug Android App on G1 (Through WiFi)
- 探讨Android6.0及以上系统APP保活实现
- 记APP实现多语言(国际化)过程,兼容Android 7.0以上
- Android实现4.4以上系统状态栏透明
- Android 6.0以上系统webview的bug
- 剑指offer--从尾到头打印链表
- Mybatis之Mapper动态代理
- PHP 常用的header头部定义汇总
- java中的不可变类
- java 编写 #1051 : 补提交卡
- Android系统7.0以上遇到exposed beyond app through ClipData.Item.getUri
- 欢迎使用CSDN-markdown编辑器
- Jmeter参数化、断言、集合点
- MySQL中alter的用法
- Java中Set巧用,去掉重复数据
- TP框架----生成验证码的方式
- ubuntu 强制关机后 mysql无法启动
- node.js的常用命令
- 2017.10.16以前的学习(4)