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

LifecycleCameraProvider

public 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(CameraSelector cameraSelector)

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

abstract boolean isBound(UseCase useCase)

Returns true if the UseCase is bound to a lifecycle.

abstract void unbind(UseCase... useCases)

Unbinds all specified use cases from the lifecycle provider.

abstract void unbindAll()

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

Public methods

hasCamera

public abstract boolean hasCamera (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
cameraSelector CameraSelector: the CameraSelector that filters available cameras.

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

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

isBound

public abstract boolean isBound (UseCase useCase)

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().

Parameters
useCase UseCase

Returns
boolean

unbind

public abstract void unbind (UseCase... useCases)

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.

Throws
IllegalStateException If not called on main thread.

unbindAll

public abstract void unbindAll ()

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

This will initiate a close of every currently open camera.

Throws
IllegalStateException If not called on main thread.