Skip to content

Instantly share code, notes, and snippets.

Last active October 26, 2015 16:46
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
Star You must be signed in to star a gist
Save r4hulp/19aac056ff6789198c14 to your computer and use it in GitHub Desktop.
GetPathToImage Xamarin's implementation
protected override void OnActivityResult(int requestCode, Result resultCode, Intent data)
if ((requestCode == PickImageId) && (resultCode == Result.Ok) && (data != null))
Uri uri = data.Data;
string path = GetPathToImage(uri);
Toast.MakeText(this, path, ToastLength.Long);
private string GetPathToImage(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);
path = cursor.GetString(columnIndex);
return path;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment