Real path of media file using Xamarin.Media => GetMediaFileExtraAsync

Hi there,

I would like to have path to my file in Android that I open using Xamarin.Media.

var picker = new MediaPicker(Activity); Intent intent = picker.GetPickPhotoUI(); StartActivityForResult(intent, 1);

... data.GetMediaFileExtraAsync(Activity).ContinueWith(dataResult => { var path = dataResult.Result.Path;

path is not real path, but temp path like

and I would like to see more like


  • MarkSmith.8123MarkSmith.8123 USXamarin Team, University, XamUProfessors Xamurai
    edited February 2015

    Hi Jakub,

    I'm not sure what you are asking for. The path is a real file path. For example, if I retrieve an existing image from a real device, I'll get back something like:


    The /storage/emulated/ path is the external storage directory on my Android device (I get the same path if I call Environment.getExternalStorageDirectory).

    However, this is not the actual camera file, which is what I think you are asking about. That path should be something like:


    or possibly /sd/xxx/ if it's on an SD card.

    This is because the picker API returns a temp copy of the file - this is the Android picker, not the component. Normally, you'd not actually use the file at all, but instead use the returned stream and load it into a Bitmap, for example (this is Java):

    final Uri imageUri = imageReturnedIntent.getData();
    final InputStream imageStream = getContentResolver().openInputStream(imageUri);
    final Bitmap selectedImage = BitmapFactory.decodeStream(imageStream);

    The component pulls the extra metadata out of the content resolver to get the underlying temp filename. That's what you are getting here. If you'd like to keep the actual file, you will need to copy it off somewhere that you have access to as the file is deleted when the MediaFile is disposed or collected.

    I'm not aware of any way to get to the actual camera file - I don't think the Intent.ACTION_PICK supports it.

    I hope that helps, feel free to add more details if I misunderstood what you are looking for.


  • jakub.mielczarkowskijakub.mielczarkowski USUniversity
    edited February 2015

    Well I was using something like:

    Intent myIntent = new Intent ();
    myIntent.SetType ("image/*");
    myIntent.SetAction (Intent.ActionPick);
    this.StartActivityForResult (myIntent, 1);

    and then OnActivityResult

    Uri contentUri = data.Data;
    string realPath = Utils.getRealPathFromURI(contentUri, Activity);

    Utils.getRealPathFromURI() return me path to real file like you said actual sd card file (not copy)

    So API returns a temp copy, and there is no way to get picked file path? I am using it to check if user is not picking same image :)

  • Another question is why returned Intent data in OnActivityResult is null?

    var picker = new MediaPicker(Activity);
    if (!picker.PhotosSupported) return;
    Intent intent = picker.GetPickPhotoUI();
    StartActivityForResult(intent, 1);
    public override void OnActivityResult (int requestCode, int resultCode, Intent data)
    if (data != null)
    Uri image = data.Data; // image is always null, because data.Data is null :neutral: 
  • MarkSmith.8123MarkSmith.8123 USXamarin Team, University, XamUProfessors Xamurai

    Hmm. That sounds kinda like a bug ;)

    Why don't you download the source from and step through it to see if the data is supplied by the underlying Android picker.. let me know!


  • Ok I will let you know if I find something

  • MarkSmith.8123MarkSmith.8123 USXamarin Team, University, XamUProfessors Xamurai

    Any luck?

Sign In or Register to comment.