# CameraSelector.Builder

Artifact: [androidx.camera:camera-core](https://developer.android.com/jetpack/androidx/releases/camera) [View Source](https://cs.android.com/search?q=file:androidx/camera/core/CameraSelector.java+class:androidx.camera.core.CameraSelector.Builder) Added in [1.0.0](https://developer.android.com/jetpack/androidx/releases/camera#1.0.0)

*** ** * ** ***


```
public final class CameraSelector.Builder
```

<br />

*** ** * ** ***

Builder for a `https://developer.android.com/reference/androidx/camera/core/CameraSelector`.

## Summary

| ### Public constructors |
|---|
| `https://developer.android.com/reference/androidx/camera/core/CameraSelector.Builder#Builder()()` |

| ### Public methods |
|---|---|
| `@https://jspecify.dev/docs/api/org/jspecify/annotations/NonNull.html https://developer.android.com/reference/androidx/camera/core/CameraSelector.Builder` | `https://developer.android.com/reference/androidx/camera/core/CameraSelector.Builder#addCameraFilter(androidx.camera.core.CameraFilter)(@https://jspecify.dev/docs/api/org/jspecify/annotations/NonNull.html https://developer.android.com/reference/androidx/camera/core/CameraFilter cameraFilter)` Adds a `https://developer.android.com/reference/androidx/camera/core/CameraFilter` to the current set of filters. |
| `@https://jspecify.dev/docs/api/org/jspecify/annotations/NonNull.html https://developer.android.com/reference/androidx/camera/core/CameraSelector` | `https://developer.android.com/reference/androidx/camera/core/CameraSelector.Builder#build()()` Builds the `https://developer.android.com/reference/androidx/camera/core/CameraSelector`. |
| `@https://jspecify.dev/docs/api/org/jspecify/annotations/NonNull.html https://developer.android.com/reference/androidx/camera/core/CameraSelector.Builder` | `https://developer.android.com/reference/androidx/camera/core/CameraSelector.Builder#requireLensFacing(int)(int lensFacing)` Requires a camera with the specified lens facing. |
| `@https://jspecify.dev/docs/api/org/jspecify/annotations/NonNull.html https://developer.android.com/reference/androidx/camera/core/CameraSelector.Builder` | `https://developer.android.com/reference/androidx/camera/core/CameraSelector.Builder#setPhysicalCameraId(java.lang.String)(@https://jspecify.dev/docs/api/org/jspecify/annotations/NonNull.html https://developer.android.com/reference/java/lang/String.html physicalCameraId)` Sets the physical camera id. |

## Public constructors

### Builder

Added in [1.0.0](https://developer.android.com/jetpack/androidx/releases/camera#1.0.0)

```
public Builder()
```

## Public methods

### addCameraFilter

Added in [1.0.0](https://developer.android.com/jetpack/androidx/releases/camera#1.0.0)

```
public @NonNull CameraSelector.Builder addCameraFilter(@NonNull CameraFilter cameraFilter)
```

Adds a `https://developer.android.com/reference/androidx/camera/core/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 |
|---|---|
| `@https://jspecify.dev/docs/api/org/jspecify/annotations/NonNull.html https://developer.android.com/reference/androidx/camera/core/CameraFilter cameraFilter` | The `https://developer.android.com/reference/androidx/camera/core/CameraFilter` for selecting cameras with. |

| Returns |
|---|---|
| `@https://jspecify.dev/docs/api/org/jspecify/annotations/NonNull.html https://developer.android.com/reference/androidx/camera/core/CameraSelector.Builder` | This builder. |

### build

Added in [1.0.0](https://developer.android.com/jetpack/androidx/releases/camera#1.0.0)

```
public @NonNull CameraSelector build()
```

Builds the `https://developer.android.com/reference/androidx/camera/core/CameraSelector`.

### requireLensFacing

Added in [1.0.0](https://developer.android.com/jetpack/androidx/releases/camera#1.0.0)

```
public @NonNull CameraSelector.Builder requireLensFacing(int lensFacing)
```

Requires a camera with the specified lens facing.

Valid values for lens facing are `https://developer.android.com/reference/androidx/camera/core/CameraSelector#LENS_FACING_FRONT()`, `https://developer.android.com/reference/androidx/camera/core/CameraSelector#LENS_FACING_BACK()` and `https://developer.android.com/reference/androidx/camera/core/CameraSelector#LENS_FACING_EXTERNAL()`. However, requiring `https://developer.android.com/reference/androidx/camera/core/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 |
|---|---|
| `int lensFacing` | The lens facing for selecting cameras with. |

| Returns |
|---|---|
| `@https://jspecify.dev/docs/api/org/jspecify/annotations/NonNull.html https://developer.android.com/reference/androidx/camera/core/CameraSelector.Builder` | This builder. |

### setPhysicalCameraId

Added in [1.4.0](https://developer.android.com/jetpack/androidx/releases/camera#1.4.0)

```
public @NonNull CameraSelector.Builder setPhysicalCameraId(@NonNull 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](https://developer.android.com/media/camera/camera2/multi-camera)

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 `https://developer.android.com/reference/androidx/camera/core/CameraSelector`s and set physical camera id on each, then bind to lifecycle with the `https://developer.android.com/reference/androidx/camera/core/CameraSelector`s. Internally each physical camera id will be set on `https://developer.android.com/reference/androidx/camera/core/UseCase`, for example, `https://developer.android.com/reference/androidx/camera/core/Preview` and call `https://developer.android.com/reference/android/hardware/camera2/params/OutputConfiguration.html#setPhysicalCameraId(java.lang.String)`.

Currently only two physical cameras for the same logical camera id are allowed and the device needs to support physical cameras by checking `https://developer.android.com/reference/androidx/camera/core/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 `https://developer.android.com/reference/android/hardware/camera2/CameraDevice.html#isSessionConfigurationSupported(android.hardware.camera2.params.SessionConfiguration)`, if the device does not support the multiple physical camera configuration, `https://developer.android.com/reference/java/lang/IllegalArgumentException.html` will be thrown when binding to lifecycle.

Setting both a physical camera ID via `https://developer.android.com/reference/androidx/camera/core/CameraSelector.Builder#setPhysicalCameraId(java.lang.String)` and a lens category via `https://developer.android.com/reference/androidx/camera/core/CameraSelector.Builder#setLensCategory(int)` on the same builder will cause `https://developer.android.com/reference/androidx/camera/core/CameraSelector.Builder#build()` to throw an `https://developer.android.com/reference/java/lang/IllegalArgumentException.html`.

| Parameters |
|---|---|
| `@https://jspecify.dev/docs/api/org/jspecify/annotations/NonNull.html https://developer.android.com/reference/java/lang/String.html physicalCameraId` | Physical camera id. |

| Returns |
|---|---|
| `@https://jspecify.dev/docs/api/org/jspecify/annotations/NonNull.html https://developer.android.com/reference/androidx/camera/core/CameraSelector.Builder` | this builder. |