[英]How to convert URI to real path in marshmallow?
I have an image URI and I want to convert this URI to a real path. 我有一个图像URI,我想将此URI转换为真实路径。 I've looked at lot of of answers but none worked for me. 我看了很多答案,但没有一个对我有用。 I'm using marshmallow 6.0.1. 我正在使用棉花糖6.0.1。 The image URI is content://com.android.providers.media.documents/document/image%3A52530
. 图像URI为content://com.android.providers.media.documents/document/image%3A52530
。
Code: 码:
sendImageFromFolder.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
Intent intent = new Intent();
intent.setType("image/*");
intent.putExtra(Intent.EXTRA_ALLOW_MULTIPLE, true);
intent.setAction(Intent.ACTION_GET_CONTENT);
startActivityForResult(Intent.createChooser(intent,"Select Picture"), 1);
}
});
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
super.onActivityResult(requestCode, resultCode, data);
if(requestCode==1) {
Uri uri = data.getData();//how to convert this uri to real path .
}
}
A Uri
is not a File
. Uri
不是File
。 A Uri
does not have to represent a file on the filesystem that you can access. Uri
不必代表您可以访问的文件系统上的文件。 The Uri
might point to content that is: Uri
可能指向以下内容:
ContentProvider
needs to decrypt it 以加密形式存储, ContentProvider
需要对其进行解密 ContentProvider
needs to load it and serve it 存储在SQLite数据库的BLOB列中, ContentProvider
需要在该列中加载并提供服务 ContentProvider
needs to download it 存储在“云”中, ContentProvider
需要在此下载它 You can use ContentResolver
and openInputStream()
to get an InputStream
on the content represented by the Uri
. 您可以使用ContentResolver
和openInputStream()
在Uri
表示的内容上获取InputStream
。 You can create a FileOutputStream
on some file that you control. 您可以在您控制的某个文件上创建FileOutputStream
。 And, you can use Java I/O to copy from the InputStream
to the OutputStream
, making your own copy of the content in a file that you control. 而且,您可以使用Java I / O从InputStream
复制到OutputStream
,在您控制的文件中创建内容的自己的副本。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.