安卓得到真正的路径由Uri.getPath()路径、Uri、getPath

2023-09-11 20:09:38 作者:闲蛋小超人

我试图从库获取的图像。

I'm trying to get image from gallery.

Intent intent = new Intent();
intent.setType("image/*");
intent.setAction(Intent.ACTION_GET_CONTENT);
startActivityForResult(Intent.createChooser(intent, "Select picture"), resultCode );

在我从这次活动我有一个数据,其中包含乌里返回。它看起来像:

After I returned from this activity I have a data, which contains Uri. It looks like:

content://media/external/images/1

我怎么能这样的路径转换为真实的(就像' /sdcard/image.png ')?

感谢

推荐答案

难道真的有必要让你获得一个物理路径? 例如, ImageView.setImageUri() ContentResolver.openInputStream()允许您访问文件的内容而不知道它的真实路径。

Is it really necessary for you to get a physical path? For example, ImageView.setImageUri() and ContentResolver.openInputStream() allow you to access the contents of a file without knowing its real path.