davs davs - 4 months ago 26
Android Question

android get real path by Uri.getPath()

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


How can I convert this path to real one (just like '
/sdcard/image.png
') ?

Thanks

Answer

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.