set Default Camera Id - Android Camera

Android examples for Camera:Camera Attribute

Description

set Default Camera Id

Demo Code


//package com.java2s;

import android.hardware.Camera;

public class Main {
    private static int mCameraId = -1;

    public static void setDefaultCameraId() {
        int numberOfCameras = Camera.getNumberOfCameras();
        for (int i = 0; i < numberOfCameras; i++) {
            Camera.CameraInfo info = new Camera.CameraInfo();
            Camera.getCameraInfo(i, info);
            if (info.facing == Camera.CameraInfo.CAMERA_FACING_BACK) {
                mCameraId = i;//from   w w w  .  j a  va  2  s  .  c  o m
                break;
            } else if (info.facing == Camera.CameraInfo.CAMERA_FACING_FRONT) {
                mCameraId = i;
                break;
            }
        }
    }
}

Related Tutorials