Get first Front Facing Camera Id - Android Camera

Android examples for Camera:Front Camera

Description

Get first Front Facing Camera Id

Demo Code


//package com.java2s;

import android.hardware.Camera;
import android.hardware.Camera.CameraInfo;

public class Main {
    public static int firstFrontFacingCameraId() {
        return firstArgFacingCameraId(CameraInfo.CAMERA_FACING_FRONT);
    }/*w  w w.j a v a2  s .com*/

    private static int firstArgFacingCameraId(final int cameraFacing) {
        final int numberOfCameras = Camera.getNumberOfCameras();

        int cameraId = 0;

        for (int i = 0; i < numberOfCameras; i++) {
            final CameraInfo info = new CameraInfo();
            Camera.getCameraInfo(i, info);

            if (info.facing == cameraFacing) {
                return i;
            }
        }

        return cameraId;
    }
}

Related Tutorials