Search code examples
xamarin.formsxamarin.androidpermissionsandroid-cameraruntimeexception

Xamarin Forms Java.Lang.RuntimeException: Fail to connect to camera service


I am trying to implement a copy of https://learn.microsoft.com/en-us/samples/xamarin/xamarin-forms-samples/customrenderers-contentpage/. The downloaded source file works fine. But when I try to run my code which I copied from it, it always give me the below error. I have added the necessary permissions in manifest also.

Java.Lang.RuntimeException: Fail to connect to camera service

enter image description here


Solution

  • Just make a conclusion of the comments:

    You need to request permissions at runtime when you want to use camera in Android project.

    To request permissions, you can use Xamarin.Essentials: Permissions:

     var status = await Permissions.RequestAsync<Permissions.Camera>();
    

    There are also many other permission request information in the document.