Java tutorial
//package com.java2s; //License from project: Open Source License import android.hardware.Camera; import android.hardware.Camera.CameraInfo; public class Main { private static Camera openBackCamera() { return Camera.open(getCameraId(CameraInfo.CAMERA_FACING_BACK)); } /** * Get camera id of specified camera face * @param cameraFace must be one of {@link CameraInfo#CAMERA_FACING_FRONT} * and {@link CameraInfo#CAMERA_FACING_BACK} * @return the camera id */ public static int getCameraId(int cameraFace) { int cameraId = 0; int numberOfCameras = Camera.getNumberOfCameras(); CameraInfo cameraInfo = new CameraInfo(); for (int i = 0; i < numberOfCameras; i++) { Camera.getCameraInfo(i, cameraInfo); if (cameraInfo.facing == cameraFace) { cameraId = i; break; } } return cameraId; } }