Android 7牛轧糖,如何从传入意图的uri获取文件路径? [英] Android 7 nougat, how to get the file path from uri of incoming intent?

查看:212
本文介绍了Android 7牛轧糖,如何从传入意图的uri获取文件路径?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

FileProvider:-设置文件共享

我知道在android牛轧糖中更改文件策略. 文件共享给其他应用程序的通缉应用程序由FileProvider生成uri. uri格式为content://com.example.myapp.fileprovider/myimages/default_image.jpg.

I know that change the file policy in android nougat. The wanted app that file share to other apps generate the uri by FileProvider. The uri format is content://com.example.myapp.fileprovider/myimages/default_image.jpg.

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

I want know that how can I get filepath from the uri that generate by FileProvider.getUriForFile(). because the my app is need to know the physical filepath in order to save, load, readinfo, etc. is it possible

[简而言之]

  1. 我的应用收到了Andorid 7牛轧糖上其他应用的意图uri.
  2. uri格式为content://com.example.myapp.fileprovider/myimages/default_image.jpg
  3. 也许它是由FileProvider.getUriForFile生成的.
  4. 我想知道从uri获取文件路径的方法.
  5. 我可以从getContentResolver().openFileDescriptor()中获取哑剧类型,显示名称,文件大小并读取binay. 但我想知道文件路径.
  1. My app received the intent uri by other apps on andorid 7 nougat.
  2. The uri format is content://com.example.myapp.fileprovider/myimages/default_image.jpg
  3. Maybe it was generate by FileProvider.getUriForFile.
  4. I want to know way that get the file path from uri.
  5. I can just get the mime type, display name, file size and read binay from getContentResolver().openFileDescriptor(). but I wnat to know the filepath.

推荐答案

您无法获得Uri的文件路径",原因很简单,即不需要Uri指向文件.使用 ContentResolver 和诸如openInputStream()之类的方法来访问由表示的内容乌里.

You cannot get a "file path" for a Uri, for the simple reason that there is no requirement that a Uri point to a file. Use ContentResolver and methods like openInputStream() to access the content represented by the Uri.

要使用内容URI与其他应用共享文件,您的应用必须 生成内容URI.要生成内容URI,请创建一个新的 文件的文件,然后将文件传递给getUriForFile().你可以发送 getUriForFile()返回到另一个应用中的内容URI 意图.接收内容URI的客户端应用可以打开文件 并通过调用ContentResolver.openFileDescriptor访问其内容 获得一个ParcelFileDescriptor. 来源: Android开发人员

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牛轧糖,如何从传入意图的uri获取文件路径?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆