Android 7 nougat,如何从传入 Intent 的uri获取文件路径?

标签 android android-intent filepath android-7.0-nougat android-fileprovider

FileProvider:- Setting up file sharing

我知道更改 android nougat 中的文件策略。 文件共享到其他应用程序的所需应用程序通过 FileProvider 生成 uri。 uri 格式为 content://com.example.myapp.fileprovider/myimages/default_image.jpg

我想知道如何从 FileProvider.getUriForFile() 生成的 uri 中获取文件路径。 因为我的应用程序需要知道物理文件路径才能保存、加载、读取信息等。 有可能吗

[简而言之]

  1. 我的应用程序收到了其他应用程序在 andorid 7 nougat 上的 intent uri。
  2. uri 格式为 content://com.example.myapp.fileprovider/myimages/default_image.jpg
  3. 可能是由 FileProvider.getUriForFile 生成的。
  4. 我想知道从 uri 获取文件路径的方法。
  5. 我可以从 getContentResolver().openFileDescriptor() 中获取 mime 类型、显示名称、文件大小和读取 binay。 但我想知道文件路径。

最佳答案

您无法获得 Uri 的“文件路径”,原因很简单,因为不要求 Uri 指向文件。使用 ContentResolver和 openInputStream() 之类的方法来访问 Uri 表示的内容。

To share a file with another app using a content URI, your app has to generate the content URI. To generate the content URI, create a new File for the file, then pass the File to getUriForFile(). You can send the content URI returned by getUriForFile() to another app in an Intent. The client app that receives the content URI can open the file and access its contents by calling ContentResolver.openFileDescriptor to get a ParcelFileDescriptor. Source: Android developers

关于Android 7 nougat,如何从传入 Intent 的uri获取文件路径?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/43178911/

相关文章:

python - 在Python中为不同操作系统构建文件路径

r - 将 PDF 嵌入 Shiny 的应用程序

Python - 在没有文件路径依赖的情况下访问应用程序资源

android - 杀死 Android 上长时间运行的 native 代码

java - Realm android 一对多 - 无法通过父级获取子级

android - 要求用户打开 Wi-Fi

android - 通知打开 Activity ,按后退按钮,防止打开后退堆栈 Activity ?

Android覆盖主页键

Android 在特定时间运行一些代码但只运行一次

Android App Widget - 更改 TextView 内容的按钮