[英]Getting File or full path from Content URI returned on OnActivityResult
I want the user to select any file type, I use the following code to do so: 我希望用户选择任何文件类型,我使用以下代码进行选择:
Intent intent = new Intent(Intent.ACTION_GET_CONTENT);
intent.setType("*/*"); // TODO filter types
startActivityForResult(intent, CONVERSATION_ATTACHMENT_REQ_CODE);
However, on onActivityResult
I try to get the file path using data.getDataString
but I get content://
uri. 但是,在
onActivityResult
我尝试使用data.getDataString
获取文件路径,但得到content://
uri。
How do I get the absolute file path from this uri ? 如何从此uri获取绝对文件路径?
Will I always get content://
uri's or I need to handle different data types ? 我会总是得到
content://
uri还是需要处理不同的数据类型?
How do I get the absolute file path from this uri ?
如何从此uri获取绝对文件路径?
You don't, just as you do not get an absolute path on your hard drive for https://stackoverflow.com/questions/33576566/getting-file-or-full-path-from-content-uri-returned-on-onactivityresult
(the URL for this question) from the URL itself. 您没有,就像您没有在硬盘上获得
https://stackoverflow.com/questions/33576566/getting-file-or-full-path-from-content-uri-returned-on-onactivityresult
的绝对路径一样URL本身的https://stackoverflow.com/questions/33576566/getting-file-or-full-path-from-content-uri-returned-on-onactivityresult
(此问题的URL)。 Neither a URL nor a Uri
is a file . URL和
Uri
都不是文件 。
Use a ContentResolver
, and methods like openInputStream()
, to consume the content identified by that Uri
. 使用
ContentResolver
和诸如openInputStream()
类的方法来使用该Uri
标识的内容。
Will I always get content:// uri's or I need to handle different data types ?
我会总是得到content:// uri还是需要处理不同的数据类型?
You will get whatever the activity that the user chooses to handle your implicit Intent
elects to return. 您将获得用户选择用来处理隐式
Intent
选择返回的任何活动。 That's supposed to be content:
Uri
values. 那应该很
content:
Uri
值。 It might be file:
Uri
values, though ContentResolver
can handle those as well. 它可能是
file:
Uri
值,尽管ContentResolver
也可以处理这些值。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.