get Default Camera by position - Android Camera

Android examples for Camera:Camera Facing

Description

get Default Camera by position

Demo Code


//package com.java2s;
import android.hardware.Camera;

public class Main {
    public static Camera getDefaultCamera(int position) {
        // Find the total number of cameras available
        int mNumberOfCameras = Camera.getNumberOfCameras();

        // Find the ID of the back-facing ("default") camera
        Camera.CameraInfo cameraInfo = new Camera.CameraInfo();
        for (int i = 0; i < mNumberOfCameras; i++) {
            Camera.getCameraInfo(i, cameraInfo);
            if (cameraInfo.facing == position) {
                return Camera.open(i);
            }/*  w  w  w .j  a v  a  2 s.  com*/
        }

        return null;
    }
}

Related Tutorials