Search code examples
xamarin.formsxamarin.androidandroid-camera2

How to use Xamarin Android.Hardware.Camera2;


I can't really understand the usage of Android.Hardware.Camera2 in Xamarin can anyone explain me how to use OpenCamera method and how do i define the AvailabilityCallback?

Here is my code

if (Android.OS.Build.VERSION.SdkInt >= Android.OS.BuildVersionCodes.Lollipop)
{
    CameraManager cameraManager = ((CameraManager)Context.GetSystemService(Context.CameraService));
    //AvailabilityCallback stateCallback = ;


    Control.Preview = cameraManager.OpenCamera(cameraManager.GetCameraIdList()[0], WHAT_HERE?, null);
 }
 else
 {
    Control.Preview = Camera.Open((int)e.NewElement.Camera);
 }

Many thanks in advance.


Solution

  • WHAT_HERE?

    CameraDevice.StateCallback

    There is a Camera2 demo app in mono samples repository https://github.com/xamarin/monodroid-samples/tree/master/android5.0/Camera2Basic

    here is the callback implementation class https://github.com/xamarin/monodroid-samples/blob/master/android5.0/Camera2Basic/Camera2Basic/Listeners/CameraStateListener.cs