1

I want to get the name of the captured image with camera.When user click button camera is open fine but i want to get the name of currently captured Image.

This is the Button Click event when user press the button then camera is opened.

fab3.Click += (o, e) =>
            {
              Intent intent = new Intent(MediaStore.ActionImageCapture);
              StartActivityForResult(intent, 0);
              CloseFabMenu();

            };

And here is i want to read the name of captured image.

 protected override void OnActivityResult(int requestCode, [GeneratedEnum] Result resultCode, Intent data)
    {
      base.OnActivityResult(requestCode, resultCode, data);
      //if ((requestCode == PickImageId) && (resultCode == Result.Ok) && (data != null))
      //{

        switch (requestCode)
        {
          case 0:
            if (resultCode == Result.Ok)
            {
              Bitmap bitmap = (Bitmap)data.Extras.Get("data");


            }

            break;
}

On Debugging Mode i Get This output. enter image description here

pvsfair
  • 161
  • 1
  • 13
Zubair Munir
  • 458
  • 3
  • 22

1 Answers1

1

How to Get The name of Captured Image with Camera In Xamarin Android

Convert the Android.Net.Uri to actual path and get the image name from that path.

Then, you could get the actual path and file name in OnActivityResult :

protected override void OnActivityResult(int requestCode, Result resultCode, Intent data)
{
    base.OnActivityResult(requestCode, resultCode, data);
    if (requestCode == 0)
    {
        var uri = data.Data;
        string path = GetActualPathFromFile(uri);
        System.Diagnostics.Debug.WriteLine("Image path == " + path);
        string fileName = Path.GetFileName(path);
    }
}

Update:

You could refer to Aamirkhan's answer Getting path of captured image in Android using camera intent, it works fine on my side.

York Shen
  • 9,014
  • 1
  • 16
  • 40