Skip to main content

CameraSelector

CameraSelector class is used to determine the requirements and priorities to select cameras.

Default CameraSelectors​

There are some default CameraSelectors that we can use out-of-the-box:

Default CameraSelectorDescription
DEFAULT_BACK_CAMERAA static CameraSelector that selects the default back facing camera.
DEFAULT_FRONT_CAMERAA static CameraSelector that selects the default front facing camera.

Here's the equivalent of each constants:

// DEFAULT_BACK_CAMERA
public static final CameraSelector DEFAULT_BACK_CAMERA = new CameraSelector.Builder()
.requireLensFacing(LENS_FACING_BACK)
.build();

// DEFAULT_FRONT_CAMERA
public static final CameraSelector DEFAULT_FRONT_CAMERA = new CameraSelector.Builder()
.requireLensFacing(LENS_FACING_FRONT)
.build();

Lens Facing Types​

As you can see on the above section, CameraSelector class contains some constants that represent the types of camera an app has based on its facing direction. There are 4 of these constants available:

Lens Facing Type
LENS_FACING_FRONTA camera on the device facing the same direction as the device's screen.
LENS_FACING_BACKA camera on the device facing the opposite direction as the device's screen.
LENS_FACING_EXTERNALAn external camera that has no fixed facing relative to the device's screen. The behavior of an external camera highly depends on the manufacturer. Currently it's treated similar to a front facing camera with little verification. So it's considered experimental and should be used with caution.
LENS_FACING_UNKNOWNA camera on the devices that its lens facing is resolved.

References​