David Novák David Novák - 2 months ago 25
Android Question

How to get id of front facing camera using Camera2?

How can I get id of front facing camera using new Camera2 library? I can't find it anywhere in documentation.

Answer

I have found solution, i could get camera characteristics by calling getCameraCharacteristics(cameraId); on CameraManager object.

String getFrontFacingCameraId(CameraManager cManager){
    for(final String cameraId : cManager.getCameraIdList()){
        CameraCharacteristics characteristics = cManager.getCameraCharacteristics(cameraId);
        int cOrientation = characteristics.get(CameraCharacteristics.LENS_FACING);
        if(cOrientation == CameraCharacteristics.LENS_FACING_FRONT) return cameraId;
    }
    return null;
}
Comments