简体   繁体   中英

How can I open front camera using xamarin android

I want to open the front camera of my device for face verification in my app with a title "Smile for the camera".How can I do this, currently I am getting the back camera default, how do I change to front camera and also hide the back camera option.

please help me

Here is my code to open camera

  Intent intent = new Intent(MediaStore.ActionImageCapture);
  StartActivityForResult(intent, 0);

From what I understand you have to iterate through the available hardware devices that match the identifier of camera.

This SO answer suggests:

Camera.CameraInfo camInfo = new Camera.CameraInfo ();
for (int i = 0; i < Camera.NumberOfCameras; i++) {
    Camera.GetCameraInfo (i, camInfo);
    if (camInfo.Facing == CameraFacing.Front){
        try {
            return Camera.Open(i);
        } catch (Exception e) {
            // log or something
        }
    }
}
return null;

There's also a question on the xamarin forums regarding this which appeared to give a similar approach, can be found here.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM