当前位置: 代码迷 >> 综合 >> 关于Uri.fromFile(File)的思考
  详细解决方案

关于Uri.fromFile(File)的思考

热度:33   发布时间:2024-01-03 23:30:53.0

看到太多网上对7.0兼容,对于文件共享的限制。

Uri.fromFile(file) : file:///storage/emulated/0/DCIM/download/aaa.jpg
FileProvider.getUriForFile(context, BuildConfig.APPLICATION_ID + ".fileProvider", file):content://com.taikang.simtest.fileProvider/camera_photos/DCIM/download/aaa.jpg
Uri.parse(file.getAbsolutePath()):/storage/emulated/0/DCIM/download/aaa.jpg

7.0对于直接由文件生成Uri这一方法并没有限制,如果把生成的Url用作发送通知什么的,并没有任何问题。

若是用于打开外部动作,则会在StrictMode.onFileUriExposed 校验失败,抛出FileUriExposedException异常

  相关解决方案