public final class

CameraSelector.Builder

extends java.lang.Object

 java.lang.Object

↳androidx.camera.core.CameraSelector.Builder

Overview

Builder for a CameraSelector.

Summary

Constructors
publicBuilder()

Methods
public CameraSelector.BuilderaddCameraFilter(CameraFilter cameraFilter)

Adds a CameraFilter to the current set of filters.

public CameraSelectorbuild()

Builds the CameraSelector.

public static CameraSelector.BuilderfromSelector(CameraSelector cameraSelector)

Generates a Builder from another CameraSelector object.

public CameraSelector.BuilderrequireLensFacing(int lensFacing)

Requires a camera with the specified lens facing.

public CameraSelector.BuildersetPhysicalCameraId(java.lang.String physicalCameraId)

Sets the physical camera id.

from java.lang.Objectclone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait

Constructors

public Builder()

Methods

public CameraSelector.Builder requireLensFacing(int lensFacing)

Requires a camera with the specified lens facing.

Valid values for lens facing are CameraSelector.LENS_FACING_FRONT, CameraSelector.LENS_FACING_BACK and CameraSelector.LENS_FACING_EXTERNAL. However, requiring CameraSelector.LENS_FACING_EXTERNAL is currently experimental and may produce unexpected behaviors.

If lens facing is already set, this will add extra requirement for lens facing instead of replacing the previous setting.

Parameters:

lensFacing: the lens facing for selecting cameras with.

Returns:

this builder.

public CameraSelector.Builder addCameraFilter(CameraFilter cameraFilter)

Adds a CameraFilter to the current set of filters. It can be used to select a specific camera based on customized criteria like Camera2 characteristics.

Multiple filters can be added. All filters will be applied by the order they were added when the CameraSelector is used, and the first camera output from the filters will be selected.

Parameters:

cameraFilter: the CameraFilter for selecting cameras with.

Returns:

this builder.

public static CameraSelector.Builder fromSelector(CameraSelector cameraSelector)

Generates a Builder from another CameraSelector object.

Parameters:

cameraSelector: An existing CameraSelector.

Returns:

The new Builder.

public CameraSelector.Builder setPhysicalCameraId(java.lang.String physicalCameraId)

Sets the physical camera id.

A logical camera is a grouping of two or more of those physical cameras. See Multi-camera API

If we want to open one physical camera, for example ultra wide, we just need to set physical camera id in CameraSelector and bind to lifecycle. All CameraX features will work normally when only a single physical camera is used.

If we want to open multiple physical cameras, we need to have multiple CameraSelectors and set physical camera id on each, then bind to lifecycle with the CameraSelectors. Internally each physical camera id will be set on UseCase, for example, Preview and call .

Currently only two physical cameras for the same logical camera id are allowed and the device needs to support physical cameras by checking CameraInfo.isLogicalMultiCameraSupported(). In addition, there is no guarantee or API to query whether the device supports multiple physical camera opening or not. Internally the library checks android.hardware.camera2.CameraDevice, if the device does not support the multiple physical camera configuration, java.lang.IllegalArgumentException will be thrown when binding to lifecycle.

Parameters:

physicalCameraId: physical camera id.

Returns:

this builder.

public CameraSelector build()

Builds the CameraSelector.