Get Camera Id by facing - Android Camera

Android examples for Camera:Camera Facing

Description

Get Camera Id by facing

Demo Code


//package com.java2s;

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

public class Main {
    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;
            }//from  w w  w.  j a v  a  2  s .  c  om
        }

        return cameraId;
    }
}

Related Tutorials