# CameraProvider

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/CameraProvider.kt+class:androidx.camera.core.CameraProvider) Added in [1.1.0](https://developer.android.com/jetpack/androidx/releases/camera#1.1.0)

*** ** * ** ***

<br />

```
interface CameraProvider
```

<br />

Known direct subclasses [LifecycleCameraProvider](https://developer.android.com/reference/kotlin/androidx/camera/lifecycle/LifecycleCameraProvider), [ProcessCameraProvider](https://developer.android.com/reference/kotlin/androidx/camera/lifecycle/ProcessCameraProvider)

|---|---|
| `https://developer.android.com/reference/kotlin/androidx/camera/lifecycle/LifecycleCameraProvider` | Provides access to a camera which has its opening and closing controlled by a `https://developer.android.com/reference/kotlin/androidx/lifecycle/LifecycleOwner`. |
| `https://developer.android.com/reference/kotlin/androidx/camera/lifecycle/ProcessCameraProvider` | A singleton which can be used to bind the lifecycle of cameras to any `https://developer.android.com/reference/kotlin/androidx/lifecycle/LifecycleOwner` within an application's process. |

*** ** * ** ***

A `https://developer.android.com/reference/kotlin/androidx/camera/core/CameraProvider` provides basic access to a set of cameras such as querying for camera existence or information.

A device might have multiple cameras. According to the applications' design, they might need to search for a suitable camera which supports their functions. A `https://developer.android.com/reference/kotlin/androidx/camera/core/CameraProvider` allows the applications to check whether any camera exists to fulfill the requirements or to get `https://developer.android.com/reference/kotlin/androidx/camera/core/CameraInfo` instances of all cameras to retrieve the camera information.

## Summary

| ### Public functions |
|---|---|
| `open https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-unit/index.html` | `https://developer.android.com/reference/kotlin/androidx/camera/core/CameraProvider#addCameraPresenceListener(java.util.concurrent.Executor,androidx.camera.core.CameraPresenceListener)( executor: https://developer.android.com/reference/java/util/concurrent/Executor.html, listener: https://developer.android.com/reference/kotlin/androidx/camera/core/CameraPresenceListener )` Adds a listener for changes in camera presence. |
| `open https://developer.android.com/reference/kotlin/androidx/camera/core/CameraInfo` | `https://developer.android.com/reference/kotlin/androidx/camera/core/CameraProvider#getCameraInfo(androidx.camera.core.CameraSelector)(cameraSelector: https://developer.android.com/reference/kotlin/androidx/camera/core/CameraSelector)` Returns the `https://developer.android.com/reference/kotlin/androidx/camera/core/CameraInfo` instance of the camera resulted from the specified `https://developer.android.com/reference/kotlin/androidx/camera/core/CameraSelector`. |
| `open https://developer.android.com/reference/kotlin/androidx/camera/core/CameraInfo` | `https://developer.android.com/reference/kotlin/androidx/camera/core/CameraProvider#getCameraInfo(androidx.camera.core.CameraSelector,androidx.camera.core.SessionConfig)( cameraSelector: https://developer.android.com/reference/kotlin/androidx/camera/core/CameraSelector, sessionConfig: https://developer.android.com/reference/kotlin/androidx/camera/core/SessionConfig )` Returns the `https://developer.android.com/reference/kotlin/androidx/camera/core/CameraInfo` instance of the camera resulted from the specified `https://developer.android.com/reference/kotlin/androidx/camera/core/CameraSelector` and `https://developer.android.com/reference/kotlin/androidx/camera/core/SessionConfig`. |
| `https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-boolean/index.html` | `https://developer.android.com/reference/kotlin/androidx/camera/core/CameraProvider#hasCamera(androidx.camera.core.CameraSelector)(cameraSelector: https://developer.android.com/reference/kotlin/androidx/camera/core/CameraSelector)` Checks whether this provider supports at least one camera that meets the requirements from a `https://developer.android.com/reference/kotlin/androidx/camera/core/CameraSelector`. |
| `open https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-unit/index.html` | `https://developer.android.com/reference/kotlin/androidx/camera/core/CameraProvider#removeCameraPresenceListener(androidx.camera.core.CameraPresenceListener)(listener: https://developer.android.com/reference/kotlin/androidx/camera/core/CameraPresenceListener)` Removes a previously registered camera presence listener. |

| ### Public properties |
|---|---|
| `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/CameraProvider#availableCameraInfos()` The `https://developer.android.com/reference/kotlin/androidx/camera/core/CameraInfo` instances of the available cameras. |

## Public functions

### addCameraPresenceListener

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

```
open fun addCameraPresenceListener(
    executor: Executor,
    listener: CameraPresenceListener
): Unit
```

Adds a listener for changes in camera presence.

The listener will be notified when cameras are added to or removed from the set of devices that can be used by CameraX. This list of "usable" cameras has already been processed by any configured `https://developer.android.com/reference/kotlin/androidx/camera/core/CameraSelector` limiters and compatibility filters.

**Important Note on Synchronization:** To prevent race conditions, this method immediately invokes `https://developer.android.com/reference/kotlin/androidx/camera/core/CameraPresenceListener#onCamerasAdded(java.util.Set<androidx.camera.core.CameraIdentifier>)` **once** on the provided `https://developer.android.com/reference/kotlin/androidx/camera/core/CameraProvider#addCameraPresenceListener(java.util.concurrent.Executor,androidx.camera.core.CameraPresenceListener)` with a `Set` containing all cameras that are currently available. This guarantees that the listener's state is synchronized with the provider's state at the moment of registration.

This listener reports on persistent hardware changes and does not fire for temporary, recoverable errors, such as when a camera is in use by another application.

| Parameters |
|---|---|
| `executor: https://developer.android.com/reference/java/util/concurrent/Executor.html` | The `https://developer.android.com/reference/java/util/concurrent/Executor.html` on which the listener's methods will be invoked. |
| `listener: https://developer.android.com/reference/kotlin/androidx/camera/core/CameraPresenceListener` | The listener to be added. |

### getCameraInfo

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

```
open fun getCameraInfo(cameraSelector: CameraSelector): CameraInfo
```

Returns the `https://developer.android.com/reference/kotlin/androidx/camera/core/CameraInfo` instance of the camera resulted from the specified `https://developer.android.com/reference/kotlin/androidx/camera/core/CameraSelector`.

The returned `https://developer.android.com/reference/kotlin/androidx/camera/core/CameraInfo` corresponds to the camera that will be bound when calling `bindToLifecycle` with the specified `https://developer.android.com/reference/kotlin/androidx/camera/core/CameraSelector`.

| Parameters |
|---|---|
| `cameraSelector: https://developer.android.com/reference/kotlin/androidx/camera/core/CameraSelector` | the `https://developer.android.com/reference/kotlin/androidx/camera/core/CameraSelector` to use for selecting the camera to receive information about. |

| Returns |
|---|---|
| `https://developer.android.com/reference/kotlin/androidx/camera/core/CameraInfo` | the corresponding `https://developer.android.com/reference/kotlin/androidx/camera/core/CameraInfo`. |

| Throws |
|---|---|
| `https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-illegal-argument-exception/index.html` | if the given `https://developer.android.com/reference/kotlin/androidx/camera/core/CameraSelector` can't result in a valid camera to provide the `https://developer.android.com/reference/kotlin/androidx/camera/core/CameraInfo`. |

### getCameraInfo

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

```
open fun getCameraInfo(
    cameraSelector: CameraSelector,
    sessionConfig: SessionConfig
): CameraInfo
```

Returns the `https://developer.android.com/reference/kotlin/androidx/camera/core/CameraInfo` instance of the camera resulted from the specified `https://developer.android.com/reference/kotlin/androidx/camera/core/CameraSelector` and `https://developer.android.com/reference/kotlin/androidx/camera/core/SessionConfig`.

The returned `https://developer.android.com/reference/kotlin/androidx/camera/core/CameraInfo` corresponds to the camera that will be bound when calling `bindToLifecycle` with the specified `https://developer.android.com/reference/kotlin/androidx/camera/core/CameraSelector` and `https://developer.android.com/reference/kotlin/androidx/camera/core/SessionConfig`.

This method is used for the case when the input `https://developer.android.com/reference/kotlin/androidx/camera/core/SessionConfig` can affect the camera selection or the information provided by the obtained CameraInfo object. For example, the `androidx.camera.extensions.ExtensionSessionConfig`.

| Parameters |
|---|---|
| `cameraSelector: https://developer.android.com/reference/kotlin/androidx/camera/core/CameraSelector` | the `https://developer.android.com/reference/kotlin/androidx/camera/core/CameraSelector` to use for selecting the camera to receive information about. |
| `sessionConfig: https://developer.android.com/reference/kotlin/androidx/camera/core/SessionConfig` | the `https://developer.android.com/reference/kotlin/androidx/camera/core/SessionConfig` to use for selecting the camera to receive information about. |

| Returns |
|---|---|
| `https://developer.android.com/reference/kotlin/androidx/camera/core/CameraInfo` | the corresponding `https://developer.android.com/reference/kotlin/androidx/camera/core/CameraInfo`. |

| Throws |
|---|---|
| `https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-illegal-argument-exception/index.html` | if the given `https://developer.android.com/reference/kotlin/androidx/camera/core/CameraSelector` and `https://developer.android.com/reference/kotlin/androidx/camera/core/SessionConfig` can't result in a valid camera to provide the `https://developer.android.com/reference/kotlin/androidx/camera/core/CameraInfo`. |

### hasCamera

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

```
fun hasCamera(cameraSelector: CameraSelector): Boolean
```

Checks whether this provider supports at least one camera that meets the requirements from a `https://developer.android.com/reference/kotlin/androidx/camera/core/CameraSelector`.

If this method returns `true`, then the camera selector can be used to bind use cases and retrieve a `https://developer.android.com/reference/kotlin/androidx/camera/core/Camera` instance.

| Parameters |
|---|---|
| `cameraSelector: https://developer.android.com/reference/kotlin/androidx/camera/core/CameraSelector` | the `https://developer.android.com/reference/kotlin/androidx/camera/core/CameraSelector` that filters available cameras. |

| Returns |
|---|---|
| `https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-boolean/index.html` | `true` if the device has at least one available camera, otherwise `false`. |

| Throws |
|---|---|
| `https://developer.android.com/reference/kotlin/androidx/camera/core/CameraInfoUnavailableException` | if unable to access cameras, perhaps due to insufficient permissions. |

### removeCameraPresenceListener

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

```
open fun removeCameraPresenceListener(listener: CameraPresenceListener): Unit
```

Removes a previously registered camera presence listener.

Once removed, the listener will no longer receive updates. If the listener was not previously registered, this method is a no-op.

| Parameters |
|---|---|
| `listener: https://developer.android.com/reference/kotlin/androidx/camera/core/CameraPresenceListener` | The same listener instance that was passed to `https://developer.android.com/reference/kotlin/androidx/camera/core/CameraProvider#addCameraPresenceListener(java.util.concurrent.Executor,androidx.camera.core.CameraPresenceListener)`. |

## Public properties

### availableCameraInfos

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

```
val availableCameraInfos: List<CameraInfo>
```

The `https://developer.android.com/reference/kotlin/androidx/camera/core/CameraInfo` instances of the available cameras.

While iterating through all the available `https://developer.android.com/reference/kotlin/androidx/camera/core/CameraInfo`, if one of them meets some predefined requirements, a `https://developer.android.com/reference/kotlin/androidx/camera/core/CameraSelector` that uniquely identifies its camera can be retrieved using `https://developer.android.com/reference/kotlin/androidx/camera/core/CameraInfo#getCameraSelector()`, which can then be used to bind `https://developer.android.com/reference/kotlin/androidx/camera/core/UseCase` to that camera.