LifecycleCameraController
public
final
class
LifecycleCameraController
extends CameraController
| java.lang.Object | ||
| ↳ | androidx.camera.view.CameraController | |
| ↳ | androidx.camera.view.LifecycleCameraController | |
A controller that provides most of the CameraX features.
This a high level controller that provides most of the CameraX core features
in a single class. It handles camera initialization, creates and configures UseCases,
and bind them to a LifecycleOwner when ready. It also listens to device motion sensor
and set the target rotation for the use cases.
Code sample:
// Setup.
CameraController controller = new LifecycleCameraController(context);
controller.bindToLifecycle(lifecycleOwner);
PreviewView previewView = findViewById(R.id.preview_view);
previewView.setController(controller);
// Use case features
controller.takePicture(...);
// Camera control features
controller.setZoomRatio(.5F);
Summary
Inherited constants |
|---|
Public constructors | |
|---|---|
LifecycleCameraController(Context context)
|
|
Public methods | |
|---|---|
void
|
bindToLifecycle(LifecycleOwner lifecycleOwner)
Sets the |
void
|
unbind()
Clears the previously set |
Inherited methods | |
|---|---|
Public constructors
LifecycleCameraController
public LifecycleCameraController (Context context)
| Parameters | |
|---|---|
context |
Context |
Public methods
bindToLifecycle
public void bindToLifecycle (LifecycleOwner lifecycleOwner)
Sets the LifecycleOwner to be bound with the controller.
The state of the lifecycle will determine when the cameras are open, started, stopped
and closed. When the LifecycleOwner's state is start or greater, the controller
receives camera data. It stops once the LifecycleOwner is destroyed.
| Parameters | |
|---|---|
lifecycleOwner |
LifecycleOwner |
| Throws | |
|---|---|
IllegalStateException |
If the provided camera selector is unable to resolve a camera to be used for the given use cases. |
unbind
public void unbind ()
Clears the previously set LifecycleOwner and stops the camera.
See also: