Forum Xamarin.Forms
We are excited to announce that the Xamarin Forums are moving to the new Microsoft Q&A experience. Q&A is the home for technical questions and answers at across all products at Microsoft now including Xamarin!

We encourage you to head over to Microsoft Q&A for .NET for posting new questions and get involved today.

Xamarin Forms Android Camera not working after update Android OS 11

AnbuMani27AnbuMani27 USMember ✭✭✭

Hi All,

I am facing issues on camera after updating to Android OS 11.

When i tried to read the value from android stored image file path, it returns NULL.

Same kind of issues were posted in the below blog.
https://www.gizchina.com/2020/09/26/android-11-has-some-annoying-bugs-camera-app-crash-broken-multitasking-black-screen-flickers/

Note: Same Code works Android OS 10.

Thanks

Posts

  • AnbuMani27AnbuMani27 USMember ✭✭✭

    Working Code:

    var filePath = Droid.MainActivity.Instance.GetExternalFilesDir(Android.OS.Environment.DirectoryPictures).Path;
    Java.IO.File file;
    
    private void TakeAPicture(object sender, EventArgs eventArgs)
    {
       var intent = new Intent(MediaStore.ActionImageCapture);
    
       file = new Java.IO.File(filePath, string.Format("Image_{0}.jpg", Guid.NewGuid()));
       (new Java.IO.File(filePath)).SetWritable(true, false);
       intent.PutExtra(MediaStore.ExtraOutput, Android.Net.Uri.FromFile(file));
       StartActivityForResult(intent, 102);
    }
    
    protected override void OnActivityResult(int requestCode, Result resultCode, Intent data)
    {
        if (requestCode == 102 && resultCode == Result.Ok)
         {
           byte[] imageByteArray = Utils.HandleRotationBitmap.GetRotatedImageByteArray(Forms.Context, file);
           if (imageByteArray != null)
           {
             ImgView.SetImageBitmap(imageByteArray);
           }
           else
           {
              //NULL
           }
        }
    }
    
Sign In or Register to comment.