get Facing Camera Id - Android Camera

Android examples for Camera:Camera Facing

Description

get Facing Camera Id

Demo Code


import android.app.Activity;
import android.content.Context;
import android.hardware.Camera;
import android.net.Uri;
import android.os.Environment;
import android.util.DisplayMetrics;
import android.view.Surface;
import android.view.ViewGroup;
import android.view.WindowManager;
import java.io.File;
import java.text.SimpleDateFormat;
import java.util.Date;

public class Main{
    public static int getFacingCameraId(int facing) {
        int cameraId = AppConstants.NOT_SET;

        try {/* w w w . j  a  v a  2s .c o m*/
            int nCameras = Camera.getNumberOfCameras();
            Camera.CameraInfo cameraInfo = new Camera.CameraInfo();

            for (int cameraInfoId = 0; cameraInfoId < nCameras; cameraInfoId++) {
                Camera.getCameraInfo(cameraInfoId, cameraInfo);
                if (cameraInfo.facing == facing) {
                    cameraId = cameraInfoId;
                    break;
                }
            }
        } catch (Exception e) {
            //Log.e(LOG_TAG, "Error in getFacingCameraId: " + e.getMessage());
        }

        return cameraId;
    }
}

Related Tutorials