CameraSelector


public final class CameraSelector


A set of requirements and priorities used to select a camera or return a filtered set of cameras.

Summary

Nested types

public final class CameraSelector.Builder

Builder for a CameraSelector.

Constants

static final @NonNull CameraSelector

A static CameraSelector that selects the default back facing camera.

static final @NonNull CameraSelector

A static CameraSelector that selects the default front facing camera.

static final int

A camera on the device facing the opposite direction as the device's screen.

static final int

An external camera that has no fixed facing relative to the device's screen.

static final int

A camera on the device facing the same direction as the device's screen.

static final int

A camera on the devices that its lens facing is resolved.

Public methods

@NonNull List<CameraInfo>
filter(@NonNull List<CameraInfo> cameraInfos)

Filters the input CameraInfos using the CameraFilters assigned to the selector.

@Nullable String

Returns the physical camera id.

Constants

DEFAULT_BACK_CAMERA

Added in 1.0.0
public static final @NonNull CameraSelector DEFAULT_BACK_CAMERA

A static CameraSelector that selects the default back facing camera.

DEFAULT_FRONT_CAMERA

Added in 1.0.0
public static final @NonNull CameraSelector DEFAULT_FRONT_CAMERA

A static CameraSelector that selects the default front facing camera.

LENS_FACING_BACK

Added in 1.0.0
public static final int LENS_FACING_BACK = 1

A camera on the device facing the opposite direction as the device's screen.

LENS_FACING_EXTERNAL

Added in 1.3.0
@ExperimentalLensFacing
public static final int LENS_FACING_EXTERNAL = 2

An 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_FRONT

Added in 1.0.0
public static final int LENS_FACING_FRONT = 0

A camera on the device facing the same direction as the device's screen.

LENS_FACING_UNKNOWN

Added in 1.3.0
public static final int LENS_FACING_UNKNOWN = -1

A camera on the devices that its lens facing is resolved.

Public methods

filter

Added in 1.1.0
public @NonNull List<CameraInfofilter(@NonNull List<CameraInfo> cameraInfos)

Filters the input CameraInfos using the CameraFilters assigned to the selector.

If the CameraFilters assigned to this selector produce a camera info that is not part of the input list, the output list will be empty.

An example use case for using this function is when you want to get all CameraInfos for all available back facing cameras.

eg.

          
CameraInfo defaultBackCameraInfo = null;
CameraSelector selector = new CameraSelector.Builder()
     .requireLensFacing(LENS_FACING_BACK).build();
List<CameraInfo> cameraInfos = selector.filter(cameraProvider.getAvailableCameraInfos());
Parameters
@NonNull List<CameraInfo> cameraInfos

The camera infos list being filtered.

Returns
@NonNull List<CameraInfo>

The remaining list of camera infos.

Throws
java.lang.UnsupportedOperationException

If the CameraFilters assigned to the selector try to modify the input camera infos list.

java.lang.IllegalArgumentException

If the device cannot return the necessary information for filtering, it will throw this exception.

getPhysicalCameraId

Added in 1.4.0
public @Nullable String getPhysicalCameraId()

Returns the physical camera id.

If physical camera id is not set via setPhysicalCameraId, it will return null.

Returns
@Nullable String

physical camera id.