【发布时间】:2017-08-27 23:34:14
【问题描述】:
FileProvider:- Setting up file sharing
我知道在 android nougat 中更改文件策略。
文件共享给其他应用程序的所需应用程序通过 FileProvider 生成 uri。
uri 格式为content://com.example.myapp.fileprovider/myimages/default_image.jpg。
我想知道如何从 FileProvider.getUriForFile() 生成的 uri 中获取文件路径。
因为我的应用程序需要知道物理文件路径才能保存、加载、读取信息等。
有没有可能
[简而言之]
- 我的应用收到了其他应用在 andorid 7 nougat 上的意图 uri。
- uri 格式为
content://com.example.myapp.fileprovider/myimages/default_image.jpg - 可能是
FileProvider.getUriForFile生成的。 - 我想知道从 uri 获取文件路径的方法。
- 我可以从
getContentResolver().openFileDescriptor()获取 mime 类型、显示名称、文件大小和读取二进制文件。 但我想知道文件路径。
【问题讨论】:
-
如果可以从流中二进制读取,则可以从流中读取。用它。不需要文件路径。只有文件提供者应该能够告诉你文件路径,但它不会。重新思考。重新设计。您不需要文件路径。
-
"我的应用需要知道物理文件路径才能保存、加载、读取信息等。" -- 然后使用
ContentResolver和openInputStream()制作您自己的内容副本。您不仅无法确定路径,而且即使可以,您也很可能无论如何都没有文件系统访问该文件的权限。 -
您找到解决方案了吗?
标签: android android-intent filepath android-7.0-nougat android-fileprovider