get Default Camera ID - Android Camera

Android examples for Camera:Camera Attribute

Description

get Default Camera ID

Demo Code


//package com.java2s;

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

public class Main {
    public static int getDefaultCameraID() {
        int camerasCnt = getAvailableCamerasCount();
        int defaultCameraID = 0;
        CameraInfo cameraInfo = new CameraInfo();
        for (int i = 0; i < camerasCnt; i++) {
            Camera.getCameraInfo(i, cameraInfo);
            if (cameraInfo.facing == CameraInfo.CAMERA_FACING_BACK) {
                defaultCameraID = i;//w ww  . j  a  v a2  s .c om
            }
        }
        return defaultCameraID;
    }

    public static int getAvailableCamerasCount() {
        return Camera.getNumberOfCameras();
    }
}

Related Tutorials