get Front Facing Camera Id - Android Camera

Android examples for Camera:Front Camera

Description

get Front Facing Camera Id

Demo Code


//package com.java2s;

import android.hardware.Camera;

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

    public static int getFrontFacingCameraId() {
        int cameraId = -1;
        // Search for the front facing camera
        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_FRONT) {

                cameraId = i;/*from  w w  w .j av  a  2  s .co m*/
                mCameraId = i;
                break;
            }
        }
        return cameraId;
    }
}

Related Tutorials