CameraProvider


public interface CameraProvider

Known direct subclasses
ProcessCameraProvider

A singleton which can be used to bind the lifecycle of cameras to any LifecycleOwner within an application's process.


A 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 CameraProvider allows the applications to check whether any camera exists to fulfill the requirements or to get CameraInfo instances of all cameras to retrieve the camera information.

Summary

Public methods

abstract @NonNull List<@NonNull CameraInfo>

The CameraInfo instances of the available cameras.

default @NonNull CameraInfo

Returns the CameraInfo instance of the camera resulted from the specified CameraSelector.

abstract boolean
hasCamera(@NonNull CameraSelector cameraSelector)

Checks whether this provider supports at least one camera that meets the requirements from a CameraSelector.

Public methods

getAvailableCameraInfos

Added in 1.1.0
abstract @NonNull List<@NonNull CameraInfogetAvailableCameraInfos()

The CameraInfo instances of the available cameras.

While iterating through all the available CameraInfo, if one of them meets some predefined requirements, a CameraSelector that uniquely identifies its camera can be retrieved using CameraInfo.getCameraSelector, which can then be used to bind use cases to that camera.

getCameraInfo

Added in 1.4.0
default @NonNull CameraInfo getCameraInfo(@NonNull CameraSelector cameraSelector)

Returns the CameraInfo instance of the camera resulted from the specified CameraSelector.

The returned CameraInfo corresponds to the camera that will be bound when calling bindToLifecycle with the specified CameraSelector.

Parameters
@NonNull CameraSelector cameraSelector

the CameraSelector to use for selecting the camera to receive information about.

Returns
@NonNull CameraInfo

the corresponding CameraInfo.

Throws
kotlin.IllegalArgumentException

if the given CameraSelector can't result in a valid camera to provide the CameraInfo.

hasCamera

Added in 1.1.0
abstract boolean hasCamera(@NonNull CameraSelector cameraSelector)

Checks whether this provider supports at least one camera that meets the requirements from a CameraSelector.

If this method returns true, then the camera selector can be used to bind use cases and retrieve a Camera instance.

Parameters
@NonNull CameraSelector cameraSelector

the CameraSelector that filters available cameras.

Returns
boolean

true if the device has at least one available camera, otherwise false.

Throws
androidx.camera.core.CameraInfoUnavailableException

if unable to access cameras, perhaps due to insufficient permissions.