androidimage-gallery

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


Solution

  • 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.