find Front Facing Camera - Android android.hardware

Android examples for android.hardware:Front Camera

Description

find Front Facing Camera

Demo Code

import android.hardware.Camera;
import android.util.Log;

public class Main{

    public static final int INVALID_CAMERA_ID = -1;

    public static int findFrontFacingCamera() {
        int cameraId = INVALID_CAMERA_ID;
        // Search for the front facing camera
        int numberOfCameras = Camera.getNumberOfCameras();
        for (int i = 0; i < numberOfCameras; i++) {
            Camera.CameraInfo info = new Camera.CameraInfo();
            Camera.getCameraInfo(i, info);
            if (info.facing == Camera.CameraInfo.CAMERA_FACING_FRONT) {
                Log.d("CameraUtil", "Camera found");
                cameraId = i;/*from w w w  .  j  av  a 2s .co m*/
                break;
            }
        }
        return cameraId;
    }

}

Related Tutorials