David Novák David Novák - 1 year ago 116
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 Source

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;
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download