调用相册打开图片 startActivity时报了个错

startActivityForResult error:file:///storage/emulated/0/Android/data/xxx.jpg exposed beyond app through Intent.getData()

调查发现是AndroidStudio7.0之后官方对这权限做了调整:官方解答:出于用户隐私安全考虑,对于面向 Android 7.0 的应用,Android 框架执行的 StrictMode API 政策禁止在您的应用外部公开 file://URI。传递软件包网域外的 file://URI 可能给接收器留下无法访问的路径。因此,尝试传递 file://URI会触发 FileUriExposedException。分享私有文件内容的推荐方法是使用 FileProvider。

1.添加在Manifest.xml中

        <providerandroid:name="android.support.v4.content.FileProvider"android:authorities="xxx.fileprovider"android:exported="false"android:grantUriPermissions="true"><meta-dataandroid:name="android.support.FILE_PROVIDER_PATHS"android:resource="@xml/provider_paths" /></provider>

2. 在新建的资源文件@xml/provider_paths中添加如下代码:

<?xml version="1.0" encoding="utf-8"?>
<paths xmlns:android="http://schemas.android.com/apk/res/android"><external-path path="." name="external_storage_root" />
</paths>

下面为文件的子节点

3.URI获取方法

出现该问题时:

File file = new File(filePath);
Uri uri = Uri.fromFile(file);

正确的方法:

Uri contentUri = FileProvider.getUriForFile(context, "xxx.fileprovider", file);

startActivity报错exposed beyond app through Intent.getData()相关推荐

  1. exposed beyond app through Intent.getData(),或FileUriExposedException

    Android7.0及以上版本拍照报错 exposed beyond app through Intent.getData(),或FileUriExposedException 解决方法: 在Appl ...

  2. app内执行apk安装报错:exposed beyond app through Intent.getData()

    文章目录 一. 问题: app内执行apk安装报错:exposed beyond app through Intent.getData() 二. 解决方法 1. AndroidManifest中增加F ...

  3. 解决Android 7.0及以上版本文件暴露异常exposed beyond app through Intent.getData()的方法

    转载:https://www.icode9.com/content-4-619191.html 我们在APP升级的时候进行下载安装,却在Android 7.0及以上版本会报错 android.os.F ...

  4. Android exposed beyond app through Intent.getData()

    前言 今天在做项目功能的时候遇到一个bug exposed beyond app through Intent.getData() 在项目中点击文件路径跳转过去,编译器报错android os Fil ...

  5. AndroidStudio:apk exposed beyond app through Intent.getData()

    今天做app版本升级,发现下载好了之后无法自动安装,检查发现,APP已经下载到了本地,就是最后安装的时候捕捉到了异常,根据异常(apk exposed beyond app through Inten ...

  6. ionic android升级错误 exposed beyond app through Intent.getData()

    应用内自动升级,下载安装包后抛出异常,先贴个错误 Log: android.os.FileUriExposedException: file:///storage/emulated/0/aiyou.a ...

  7. 解决AndroidStudio报错:Cannot resolve constructor ‘Intent()...‘

    项目场景: 安卓项目开发中,单击列表中的item,跳转其他页面. 问题描述: 对ListView中的item添加单击监听器,打开新页面部分的代码标红报错:Cannot resolve construc ...

  8. centos在yum install报错:Another app is currently holding the yum lock解决方法

    centos在yum install报错:Another app is currently holding the yum lock解决方法 参考文章: (1)centos在yum install报错 ...

  9. leakcanary内存泄露检测工具报错 Dumping memory, app will freeze. Brrr

    官网地址 https://github.com/square/leakcanary 报错信息:Dumping memory, app will freeze. Brrr 点击查看leaks小黄标,看到 ...

  10. 报错:[nodemon] app crashed - waiting for file changes before starting...

    目录 前言 方法 总结 前言 遇到 [nodemon] app crashed - waiting for file changes before starting... 报错 可以参考本文方法,尝试 ...

最新文章

  1. 2022-2028全球及中国呼吸麻醉消耗品行业研究及十四五规划分析报告
  2. Java遗传算法并行多机调度程序
  3. Apache ZooKeeper - 选举Leader源码流程深度解析
  4. DataGrid内容的导出
  5. js粘贴板为什么获取不到图片信息_【第1829期】复制黏贴上传图片和跨浏览器自动化测试...
  6. css检测,CSS检测工具 CSS Lint简介
  7. error: command 'gcc' failed with exit status 1
  8. java随机一个数字和字母_java怎么实现随机4个带有数字和字母的验证码?
  9. 微信小程序开发手机商城部分代码(不包括支付功能)
  10. 服务器系统win12可以安装CAD,技术员教你解决win10系统安装CAD2012的教程介绍
  11. 基于springboot的物流管理系统设计与实现 JAVA MYSQL
  12. SNMP Trap 报文
  13. qscrollbar 固定滑块大小_模仁、镶件、斜顶、滑块等模具零件的加工工艺分析
  14. 【时空智友】“采购入库单” 增加导入Excel模板的方式
  15. 【C++】-- STL容器适配器之stack
  16. python中write是什么意思_Python中操作文件之write()方法的使用教程
  17. 2019世界机器人大会
  18. cv2.boundingRect
  19. BuuCTF难题详解| Misc | [HDCTF2019]你能发现什么蛛丝马迹吗
  20. 罗马数字转换成阿拉伯数字

热门文章

  1. winrar 命令行参数使用
  2. OCR文字识别,PDF格式转换
  3. 求PSASP大神指教一下安装问题
  4. java acr122 读取数据_acr122读写器软件下载-Acr122读写软件 1.59 官方版 - 河东下载站...
  5. 程序员入门必备经典书单
  6. 项目进度计划检查方法与项目进度管理相关模版表单(干货+资料)
  7. 暴力猴加脚本的适当应用
  8. 微博表情包大全,截止2022年5月
  9. excel多元线性拟合_[求助]excel里面的linest函数中多元回归怎么用啊?
  10. 没了珊瑚虫你用谁?八大QQ主流修改版大比拼