# 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)

*** ** * ** ***


```
class CameraSelector
```

<br />

*** ** * ** ***

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

## Summary

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

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

| ### Public functions |
|---|---|
| `(https://kotlinlang.org/api/core/kotlin-stdlib/kotlin.collections/-mutable-list/index.html)https://kotlinlang.org/api/core/kotlin-stdlib/kotlin.collections/-list/index.html<https://developer.android.com/reference/kotlin/androidx/camera/core/CameraInfo!>` | `https://developer.android.com/reference/kotlin/androidx/camera/core/CameraSelector#filter(java.util.List<androidx.camera.core.CameraInfo>)(cameraInfos: (https://kotlinlang.org/api/core/kotlin-stdlib/kotlin.collections/-mutable-list/index.html)https://kotlinlang.org/api/core/kotlin-stdlib/kotlin.collections/-list/index.html<https://developer.android.com/reference/kotlin/androidx/camera/core/CameraInfo!>)` Filters the input `https://developer.android.com/reference/kotlin/androidx/camera/core/CameraInfo`s using the `https://developer.android.com/reference/kotlin/androidx/camera/core/CameraFilter`s assigned to the selector. |
| `https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-string/index.html?` | `https://developer.android.com/reference/kotlin/androidx/camera/core/CameraSelector#getPhysicalCameraId()()` Returns the physical camera id. |
| `java-static https://developer.android.com/reference/kotlin/androidx/camera/core/CameraSelector` | `https://developer.android.com/reference/kotlin/androidx/camera/core/CameraSelector#of(androidx.camera.core.CameraIdentifier...)(cameraIdentifiers: https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-array/index.html<https://developer.android.com/reference/kotlin/androidx/camera/core/CameraIdentifier>)` Creates a `https://developer.android.com/reference/kotlin/androidx/camera/core/CameraSelector` that specifically targets the camera(s) represented by the given `https://developer.android.com/reference/kotlin/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)

```
const val DEFAULT_BACK_CAMERA: CameraSelector
```

A static `https://developer.android.com/reference/kotlin/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)

```
const val DEFAULT_FRONT_CAMERA: CameraSelector
```

A static `https://developer.android.com/reference/kotlin/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)

```
const val LENS_FACING_BACK = 1: Int
```

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
const val LENS_FACING_EXTERNAL = 2: Int
```

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)

```
const val LENS_FACING_FRONT = 0: Int
```

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)

```
const val LENS_FACING_UNKNOWN = -1: Int
```

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

## Public functions

### filter

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

```
fun filter(cameraInfos: (Mutable)List<CameraInfo!>): (Mutable)List<CameraInfo!>
```

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

If the `https://developer.android.com/reference/kotlin/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/kotlin/androidx/camera/core/CameraInfo`s for all available back facing cameras.

```kotlin
eg.

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

| Parameters |
|---|---|
| `cameraInfos: (https://kotlinlang.org/api/core/kotlin-stdlib/kotlin.collections/-mutable-list/index.html)https://kotlinlang.org/api/core/kotlin-stdlib/kotlin.collections/-list/index.html<https://developer.android.com/reference/kotlin/androidx/camera/core/CameraInfo!>` | The camera infos list being filtered. |

| Returns |
|---|---|
| `(https://kotlinlang.org/api/core/kotlin-stdlib/kotlin.collections/-mutable-list/index.html)https://kotlinlang.org/api/core/kotlin-stdlib/kotlin.collections/-list/index.html<https://developer.android.com/reference/kotlin/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/kotlin/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)

```
fun getPhysicalCameraId(): String?
```

Returns the physical camera id.

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

| Returns |
|---|---|
| `https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-string/index.html?` | Physical camera id. |

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

### of

```
java-static fun of(cameraIdentifiers: Array<CameraIdentifier>): CameraSelector
```

Creates a `https://developer.android.com/reference/kotlin/androidx/camera/core/CameraSelector` that specifically targets the camera(s) represented by the given `https://developer.android.com/reference/kotlin/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 |
|---|---|
| `cameraIdentifiers: https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-array/index.html<https://developer.android.com/reference/kotlin/androidx/camera/core/CameraIdentifier>` | A varargs array of one or more non-null `https://developer.android.com/reference/kotlin/androidx/camera/core/CameraIdentifier`s. |

| Returns |
|---|---|
| `https://developer.android.com/reference/kotlin/androidx/camera/core/CameraSelector` | A non-null `https://developer.android.com/reference/kotlin/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. |