get Front Camera Id from Camera.CameraInfo - Android android.hardware

Android examples for android.hardware:Front Camera

Description

get Front Camera Id from Camera.CameraInfo

Demo Code

import android.app.Activity;
import android.content.Context;
import android.content.pm.PackageManager;
import android.hardware.Camera;
import android.view.Surface;

public class Main{

    public static int getFrontCameraId() {
        int cameraCount = 0;
        Camera.CameraInfo cameraInfo = new Camera.CameraInfo();
        cameraCount = Camera.getNumberOfCameras();
        for (int camIdx = 0; camIdx < cameraCount; camIdx++) {
            Camera.getCameraInfo(camIdx, cameraInfo);
            if (cameraInfo.facing == Camera.CameraInfo.CAMERA_FACING_FRONT) {
                return camIdx;
            }/*from  w  ww  .j  a va2 s . c  o m*/
        }
        return -1;
    }

}

Related Tutorials