1

I am using following code to convert the Android.Net.Uri path to physical path:

       private string GetPathToImage (Android.Net.Uri uri)
    {
        string path = null;
        // The projection contains the columns we want to return in our query.
        string[] projection = new[] { Android.Provider.MediaStore.Images.Media.InterfaceConsts.Data };

        using (ICursor cursor = ManagedQuery (uri, projection, null, null, null)) {
            if (cursor != null) {
                int columnIndex = cursor.GetColumnIndexOrThrow (Android.Provider.MediaStore.Images.Media.InterfaceConsts.Data);
                cursor.MoveToFirst ();
                path = cursor.GetString (columnIndex);

            }
        }
        return path;
    }

But its not working. I am getting null value in "path". The Android.Net.Uri path is as follows:

//com.android.providers.media.documents/document/image%3A43306

And I want the physcial path like:

files/Pictures/temp/IMG_20151201_194231.jpg

How I can achieve this?

Regards, Anand Dubey

anand
  • 1,259
  • 4
  • 21
  • 51

1 Answers1

0

Try something similar to this :

public String getRealPathFromURI(Context context, Uri contentUri) {
  Cursor cursor = null;
  try { 
    String[] proj = { MediaStore.Images.Media.DATA };
    cursor = context.getContentResolver().query(contentUri,  proj, null, null, null);
    int column_index = cursor.getColumnIndexOrThrow(MediaStore.Images.Media.DATA);
    cursor.moveToFirst();
    return cursor.getString(column_index);
  } finally {
    if (cursor != null) {
      cursor.close();
    }
  }
}

Refer : https://stackoverflow.com/a/3414749/3891036

Community
  • 1
  • 1
Yksh
  • 3,899
  • 10
  • 53
  • 101