xyz rety xyz rety - 8 months ago 108
Android Question

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. I've looked at lot of of answers but none worked for me. I'm using marshmallow 6.0.1. The image URI is



sendImageFromFolder.setOnClickListener(new View.OnClickListener() {
public void onClick(View view) {
Intent intent = new Intent();
intent.putExtra(Intent.EXTRA_ALLOW_MULTIPLE, true);
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. A Uri does not have to represent a file on the filesystem that you can access. The Uri might point to content that is:

  • stored on removable storage, which you cannot access
  • stored on internal storage of another app, which you cannot access
  • stored in an encrypted form, where a ContentProvider needs to decrypt it
  • stored in a BLOB column of a SQLite database, where a ContentProvider needs to load it and serve it
  • stored in "the cloud", where a ContentProvider needs to download it
  • generated on the fly, the way this Web page is
  • and so on

You can use ContentResolver and openInputStream() to get an InputStream on the content represented by the Uri. You can create a FileOutputStream on some file that you control. 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.