public enum

CameraState.Type

extends java.lang.Enum<CameraState.Type>

 java.lang.Object

↳java.lang.Enum<CameraState.Type>

↳androidx.camera.core.CameraState.Type

Overview

States the camera can be in.

Summary

Enum Constants
CLOSEDRepresents a state where the camera device is closed.
CLOSINGRepresents a state where the camera device is currently closing.
OPENRepresents a state where the camera device is open.
OPENINGRepresents a state where the camera device is currently opening.
PENDING_OPENRepresents a state where the camera is waiting for a signal to attempt to open the camera device.
Methods
public static CameraState.TypevalueOf(java.lang.String name)

public static CameraState.Typevalues()

from java.lang.Enum<E>clone, compareTo, equals, finalize, getDeclaringClass, hashCode, name, ordinal, toString, valueOf
from java.lang.ObjectgetClass, notify, notifyAll, wait, wait, wait

Enum Constants

PENDING_OPEN

Represents a state where the camera is waiting for a signal to attempt to open the camera device.

The camera can move to this state from a CameraState.Type.CLOSED or CameraState.Type.OPENING state:

  • It moves to this state from a CameraState.Type.CLOSED state if it attempts to open an unavailable camera device. A camera device is unavailable for opening if (a) it's already in use by another camera client, for example one with higher priority or (b) the maximum number of cameras allowed to be open at the same time in CameraX has been reached, this limit is currently set to 1.
  • It moves to this state from an CameraState.Type.OPENING state if it reaches the maximum number of camera reopen attempts while trying to recover from a camera opening error.

While in this state, the camera waits for an external signal from the camera service or an internal one from CameraX to attempt to reopen the camera device.

Developers may rely on this state to close any other open cameras in the app, or request their user close an open camera in another app.

OPENING

Represents a state where the camera device is currently opening.

The camera can move to this state from a CameraState.Type.PENDING_OPEN or CameraState.Type.CLOSED state: It moves to this state from a CameraState.Type.PENDING_OPEN state after it receives a signal that the camera is available to open, and from a CameraState.Type.CLOSED state after a request to open the camera is made, and the camera is available to open.

While in this state, the camera is actively attempting to open the camera device. This takes several hundred milliseconds on most devices. If it succeeds, the state moves to the CameraState.Type.OPEN state. If it fails however, the camera may attempt to reopen the camera device a certain number of times. While this is happening, the camera state remains the same, i.e. in an opening state, and it exposes the error it encountered through CameraState.getError().

Developers can rely on this state to be aware of when the camera is actively attempting to open the camera device, this allows them to communicate it to their users through the UI.

OPEN

Represents a state where the camera device is open.

The camera can only move to this state from an CameraState.Type.OPENING state.

Once in this state, active use cases attached to this camera could expect to shortly start receiving camera frames.

Developers can rely on this state to be notified of when the camera device is actually ready for use, and can then set up camera dependent resources, especially if they're heavyweight.

CLOSING

Represents a state where the camera device is currently closing.

The camera can move to this state from an CameraState.Type.OPEN or CameraState.Type.OPENING state: It moves to this state from an CameraState.Type.OPEN state after it receives a signal to close the camera device, this can be after all its attached use cases are detached, and from an CameraState.Type.OPENING state if the camera encounters a fatal error it cannot recover from.

Developers can rely on this state to be aware of when the camera device is actually in the process of closing. this allows them to communicate it to their users through the UI.

CLOSED

Represents a state where the camera device is closed.

The camera is initially in this state, and can move back to it from a CameraState.Type.CLOSING or CameraState.Type.OPENING state: It moves to this state from a CameraState.Type.CLOSING state after the camera device successfully closes, and from an CameraState.Type.OPENING state when opening a camera device that is unavailable due to , as some API level 28 devices cannot access the camera when the device is in "Do Not Disturb" mode.

Developers can rely on this state to be notified of when the camera device is actually closed, and then use this signal to free up camera resources, or start the camera device with another camera client.

Methods

public static CameraState.Type values()

public static CameraState.Type valueOf(java.lang.String name)