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

```
public interface CameraProvider
```

<br />

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

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

*** ** * ** ***

A `https://developer.android.com/reference/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/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/androidx/camera/core/CameraInfo` instances of all cameras to retrieve the camera information.

## Summary

| ### Public methods |
|---|---|
| `default void` | `https://developer.android.com/reference/androidx/camera/core/CameraProvider#addCameraPresenceListener(java.util.concurrent.Executor,androidx.camera.core.CameraPresenceListener)( @https://developer.android.com/reference/androidx/annotation/NonNull https://developer.android.com/reference/java/util/concurrent/Executor.html executor, @https://developer.android.com/reference/androidx/annotation/NonNull https://developer.android.com/reference/androidx/camera/core/CameraPresenceListener listener )` Adds a listener for changes in camera presence. |
| `abstract @https://developer.android.com/reference/androidx/annotation/NonNull https://developer.android.com/reference/java/util/List.html<@https://developer.android.com/reference/androidx/annotation/NonNull https://developer.android.com/reference/androidx/camera/core/CameraInfo>` | `https://developer.android.com/reference/androidx/camera/core/CameraProvider#getAvailableCameraInfos()()` The `https://developer.android.com/reference/androidx/camera/core/CameraInfo` instances of the available cameras. |
| `default @https://developer.android.com/reference/androidx/annotation/NonNull https://developer.android.com/reference/androidx/camera/core/CameraInfo` | `https://developer.android.com/reference/androidx/camera/core/CameraProvider#getCameraInfo(androidx.camera.core.CameraSelector)(@https://developer.android.com/reference/androidx/annotation/NonNull https://developer.android.com/reference/androidx/camera/core/CameraSelector cameraSelector)` Returns the `https://developer.android.com/reference/androidx/camera/core/CameraInfo` instance of the camera resulted from the specified `https://developer.android.com/reference/androidx/camera/core/CameraSelector`. |
| `default @https://developer.android.com/reference/androidx/annotation/NonNull https://developer.android.com/reference/androidx/camera/core/CameraInfo` | `https://developer.android.com/reference/androidx/camera/core/CameraProvider#getCameraInfo(androidx.camera.core.CameraSelector,androidx.camera.core.SessionConfig)( @https://developer.android.com/reference/androidx/annotation/NonNull https://developer.android.com/reference/androidx/camera/core/CameraSelector cameraSelector, @https://developer.android.com/reference/androidx/annotation/NonNull https://developer.android.com/reference/androidx/camera/core/SessionConfig sessionConfig )` Returns the `https://developer.android.com/reference/androidx/camera/core/CameraInfo` instance of the camera resulted from the specified `https://developer.android.com/reference/androidx/camera/core/CameraSelector` and `https://developer.android.com/reference/androidx/camera/core/SessionConfig`. |
| `abstract boolean` | `https://developer.android.com/reference/androidx/camera/core/CameraProvider#hasCamera(androidx.camera.core.CameraSelector)(@https://developer.android.com/reference/androidx/annotation/NonNull https://developer.android.com/reference/androidx/camera/core/CameraSelector cameraSelector)` Checks whether this provider supports at least one camera that meets the requirements from a `https://developer.android.com/reference/androidx/camera/core/CameraSelector`. |
| `default void` | `https://developer.android.com/reference/androidx/camera/core/CameraProvider#removeCameraPresenceListener(androidx.camera.core.CameraPresenceListener)(@https://developer.android.com/reference/androidx/annotation/NonNull https://developer.android.com/reference/androidx/camera/core/CameraPresenceListener listener)` Removes a previously registered camera presence listener. |

## Public methods

### addCameraPresenceListener

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

```
default void addCameraPresenceListener(
    @NonNull Executor executor,
    @NonNull CameraPresenceListener listener
)
```

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/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/androidx/camera/core/CameraPresenceListener#onCamerasAdded(java.util.Set<androidx.camera.core.CameraIdentifier>)` **once** on the provided `https://developer.android.com/reference/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 |
|---|---|
| `@https://developer.android.com/reference/androidx/annotation/NonNull https://developer.android.com/reference/java/util/concurrent/Executor.html executor` | The `https://developer.android.com/reference/java/util/concurrent/Executor.html` on which the listener's methods will be invoked. |
| `@https://developer.android.com/reference/androidx/annotation/NonNull https://developer.android.com/reference/androidx/camera/core/CameraPresenceListener listener` | The listener to be added. |

### getAvailableCameraInfos

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

```
abstract @NonNull List<@NonNull CameraInfo> getAvailableCameraInfos()
```

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

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

### getCameraInfo

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

```
default @NonNull CameraInfo getCameraInfo(@NonNull CameraSelector cameraSelector)
```

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

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

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

| Returns |
|---|---|
| `@https://developer.android.com/reference/androidx/annotation/NonNull https://developer.android.com/reference/androidx/camera/core/CameraInfo` | the corresponding `https://developer.android.com/reference/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/androidx/camera/core/CameraSelector` can't result in a valid camera to provide the `https://developer.android.com/reference/androidx/camera/core/CameraInfo`. |

### getCameraInfo

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

```
default @NonNull CameraInfo getCameraInfo(
    @NonNull CameraSelector cameraSelector,
    @NonNull SessionConfig sessionConfig
)
```

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

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

This method is used for the case when the input `https://developer.android.com/reference/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 |
|---|---|
| `@https://developer.android.com/reference/androidx/annotation/NonNull https://developer.android.com/reference/androidx/camera/core/CameraSelector cameraSelector` | the `https://developer.android.com/reference/androidx/camera/core/CameraSelector` to use for selecting the camera to receive information about. |
| `@https://developer.android.com/reference/androidx/annotation/NonNull https://developer.android.com/reference/androidx/camera/core/SessionConfig sessionConfig` | the `https://developer.android.com/reference/androidx/camera/core/SessionConfig` to use for selecting the camera to receive information about. |

| Returns |
|---|---|
| `@https://developer.android.com/reference/androidx/annotation/NonNull https://developer.android.com/reference/androidx/camera/core/CameraInfo` | the corresponding `https://developer.android.com/reference/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/androidx/camera/core/CameraSelector` and `https://developer.android.com/reference/androidx/camera/core/SessionConfig` can't result in a valid camera to provide the `https://developer.android.com/reference/androidx/camera/core/CameraInfo`. |

### hasCamera

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

```
abstract boolean hasCamera(@NonNull CameraSelector cameraSelector)
```

Checks whether this provider supports at least one camera that meets the requirements from a `https://developer.android.com/reference/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/androidx/camera/core/Camera` instance.

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

| Returns |
|---|---|
| `boolean` | `true` if the device has at least one available camera, otherwise `false`. |

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

```
default void removeCameraPresenceListener(@NonNull CameraPresenceListener listener)
```

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 |
|---|---|
| `@https://developer.android.com/reference/androidx/annotation/NonNull https://developer.android.com/reference/androidx/camera/core/CameraPresenceListener listener` | The same listener instance that was passed to `https://developer.android.com/reference/androidx/camera/core/CameraProvider#addCameraPresenceListener(java.util.concurrent.Executor,androidx.camera.core.CameraPresenceListener)`. |