The second Android 11 Developer Preview is now available, test it out and share your feedback.

LifecycleCameraProvider

interface LifecycleCameraProvider
androidx.camera.lifecycle.LifecycleCameraProvider

Provides access to a camera which has has its opening and closing controlled by a LifecycleOwner.

Summary

Public methods

abstract Boolean
hasCamera(@NonNull cameraSelector: CameraSelector)

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

abstract Boolean
isBound(@NonNull useCase: UseCase)

Returns true if the UseCase is bound to a lifecycle.

abstract Unit
unbind(@NonNull vararg useCases: UseCase!)

Unbinds all specified use cases from the lifecycle provider.

abstract Unit

Unbinds all use cases from the lifecycle provider and removes them from CameraX.

Public methods

hasCamera

abstract fun hasCamera(@NonNull cameraSelector: CameraSelector): Boolean

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
cameraSelector CameraSelector: the CameraSelector that filters available cameras.
Return
Boolean: true if the device has at least one available camera, otherwise false.
Exceptions
CameraInfoUnavailableException if unable to access cameras, perhaps due to insufficient permissions.

isBound

abstract fun isBound(@NonNull useCase: UseCase): Boolean

Returns true if the UseCase is bound to a lifecycle. Otherwise returns false.

After binding a use case, use cases remain bound until the lifecycle reaches a Lifecycle.State#DESTROYED state or if is unbound by calls to unbind(UseCase...) or unbindAll().

unbind

abstract fun unbind(@NonNull vararg useCases: UseCase!): Unit

Unbinds all specified use cases from the lifecycle provider.

This will initiate a close of every open camera which has zero UseCase associated with it at the end of this call.

If a use case in the argument list is not bound, then it is simply ignored.

After unbinding a UseCase, the UseCase can be bound to another Lifecycle however listeners and settings should be reset by the application.

Parameters
useCases UseCase!: The collection of use cases to remove.
Exceptions
IllegalStateException If not called on main thread.

unbindAll

abstract fun unbindAll(): Unit

Unbinds all use cases from the lifecycle provider and removes them from CameraX.

This will initiate a close of every currently open camera.

Exceptions
IllegalStateException If not called on main thread.