# CameraSelector

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) Added in [1.0.0](https://developer.android.com/jetpack/androidx/releases/camera#1.0.0)

*** ** * ** ***


```
public final class CameraSelector
```

<br />

*** ** * ** ***

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

## Summary

| ### Nested types |
|---|
| `public final class https://developer.android.com/reference/androidx/camera/core/CameraSelector.Builder` Builder for a `https://developer.android.com/reference/androidx/camera/core/CameraSelector`. |

| ### Constants |
|---|---|
| `static final @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#DEFAULT_BACK_CAMERA()` A static `https://developer.android.com/reference/androidx/camera/core/CameraSelector` that selects the default back facing camera. |
| `static final @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#DEFAULT_FRONT_CAMERA()` A static `https://developer.android.com/reference/androidx/camera/core/CameraSelector` that selects the default front facing camera. |
| `static final int` | `https://developer.android.com/reference/androidx/camera/core/CameraSelector#LENS_FACING_BACK() = 1` A camera on the device facing the opposite direction as the device's screen. |
| `static final int` | `@https://developer.android.com/reference/androidx/camera/core/ExperimentalLensFacing https://developer.android.com/reference/androidx/camera/core/CameraSelector#LENS_FACING_EXTERNAL() = 2` An external camera that has no fixed facing relative to the device's screen. |
| `static final int` | `https://developer.android.com/reference/androidx/camera/core/CameraSelector#LENS_FACING_FRONT() = 0` A camera on the device facing the same direction as the device's screen. |
| `static final int` | `https://developer.android.com/reference/androidx/camera/core/CameraSelector#LENS_FACING_UNKNOWN() = -1` A camera on the device whose lens facing is not resolved. |

| ### Public methods |
|---|---|
| `@https://jspecify.dev/docs/api/org/jspecify/annotations/NonNull.html https://developer.android.com/reference/java/util/List.html<https://developer.android.com/reference/androidx/camera/core/CameraInfo>` | `https://developer.android.com/reference/androidx/camera/core/CameraSelector#filter(java.util.List<androidx.camera.core.CameraInfo>)(@https://jspecify.dev/docs/api/org/jspecify/annotations/NonNull.html https://developer.android.com/reference/java/util/List.html<https://developer.android.com/reference/androidx/camera/core/CameraInfo> cameraInfos)` Filters the input `https://developer.android.com/reference/androidx/camera/core/CameraInfo`s using the `https://developer.android.com/reference/androidx/camera/core/CameraFilter`s assigned to the selector. |
| `@https://jspecify.dev/docs/api/org/jspecify/annotations/Nullable.html https://developer.android.com/reference/java/lang/String.html` | `https://developer.android.com/reference/androidx/camera/core/CameraSelector#getPhysicalCameraId()()` Returns the physical camera id. |
| `static @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#of(androidx.camera.core.CameraIdentifier...)(@https://jspecify.dev/docs/api/org/jspecify/annotations/NonNull.html CameraIdentifier[] cameraIdentifiers)` Creates a `https://developer.android.com/reference/androidx/camera/core/CameraSelector` that specifically targets the camera(s) represented by the given `https://developer.android.com/reference/androidx/camera/core/CameraIdentifier`s. |

## Constants

### DEFAULT_BACK_CAMERA

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

```
public static final @NonNull CameraSelector DEFAULT_BACK_CAMERA
```

A static `https://developer.android.com/reference/androidx/camera/core/CameraSelector` that selects the default back facing camera.

### DEFAULT_FRONT_CAMERA

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

```
public static final @NonNull CameraSelector DEFAULT_FRONT_CAMERA
```

A static `https://developer.android.com/reference/androidx/camera/core/CameraSelector` that selects the default front facing camera.

### LENS_FACING_BACK

Added in [1.0.0](https://developer.android.com/jetpack/androidx/releases/camera#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](https://developer.android.com/jetpack/androidx/releases/camera#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](https://developer.android.com/jetpack/androidx/releases/camera#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](https://developer.android.com/jetpack/androidx/releases/camera#1.3.0)

```
public static final int LENS_FACING_UNKNOWN = -1
```

A camera on the device whose lens facing is not resolved.

## Public methods

### filter

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

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

Filters the input `https://developer.android.com/reference/androidx/camera/core/CameraInfo`s using the `https://developer.android.com/reference/androidx/camera/core/CameraFilter`s assigned to the selector.

If the `https://developer.android.com/reference/androidx/camera/core/CameraFilter`s 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 `https://developer.android.com/reference/androidx/camera/core/CameraInfo`s 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 |
|---|---|
| `@https://jspecify.dev/docs/api/org/jspecify/annotations/NonNull.html https://developer.android.com/reference/java/util/List.html<https://developer.android.com/reference/androidx/camera/core/CameraInfo> cameraInfos` | The camera infos list being filtered. |

| Returns |
|---|---|
| `@https://jspecify.dev/docs/api/org/jspecify/annotations/NonNull.html https://developer.android.com/reference/java/util/List.html<https://developer.android.com/reference/androidx/camera/core/CameraInfo>` | The remaining list of camera infos. |

| Throws |
|---|---|
| `https://developer.android.com/reference/java/lang/UnsupportedOperationException.html` | If the `https://developer.android.com/reference/androidx/camera/core/CameraFilter`s assigned to the selector try to modify the input camera infos list. |
| `https://developer.android.com/reference/java/lang/IllegalArgumentException.html` | If the device cannot return the necessary information for filtering, it will throw this exception. |

### getPhysicalCameraId

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

```
public @Nullable String getPhysicalCameraId()
```

Returns the physical camera id.

If physical camera id is not set via `https://developer.android.com/reference/androidx/camera/core/CameraSelector.Builder#setPhysicalCameraId(java.lang.String)`, it will return `null`.

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

| See also |
|---|---|
| `https://developer.android.com/reference/androidx/camera/core/CameraSelector.Builder#setPhysicalCameraId(java.lang.String)` |   |

### of

```
public static @NonNull CameraSelector of(@NonNull CameraIdentifier[] cameraIdentifiers)
```

Creates a `https://developer.android.com/reference/androidx/camera/core/CameraSelector` that specifically targets the camera(s) represented by the given `https://developer.android.com/reference/androidx/camera/core/CameraIdentifier`s.

When multiple identifiers are provided, they are treated as a prioritized list. CameraX will attempt to select and bind the camera for the first identifier. If that camera is not available, it will attempt to use the second, and so on.

| Parameters |
|---|---|
| `@https://jspecify.dev/docs/api/org/jspecify/annotations/NonNull.html CameraIdentifier[] cameraIdentifiers` | A varargs array of one or more non-null `https://developer.android.com/reference/androidx/camera/core/CameraIdentifier`s. |

| Returns |
|---|---|
| `@https://jspecify.dev/docs/api/org/jspecify/annotations/NonNull.html https://developer.android.com/reference/androidx/camera/core/CameraSelector` | A non-null `https://developer.android.com/reference/androidx/camera/core/CameraSelector` configured to select one of the specific cameras. |

| Throws |
|---|---|
| `https://developer.android.com/reference/java/lang/IllegalArgumentException.html` | if no identifiers are provided. |