CameraState.Type

public static final enum CameraState.Type
extends Enum<CameraState.Type>

java.lang.Object
   ↳ java.lang.Enum<androidx.camera.core.CameraState.Type>
     ↳ androidx.camera.core.CameraState.Type


States the camera can be in.

Summary

Enum values

CameraState.Type  CLOSED

Represents a state where the camera device is closed. 

CameraState.Type  CLOSING

Represents a state where the camera device is currently closing. 

CameraState.Type  OPEN

Represents a state where the camera device is open. 

CameraState.Type  OPENING

Represents a state where the camera device is currently opening. 

CameraState.Type  PENDING_OPEN

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

Public methods

static CameraState.Type valueOf(String name)
static final Type[] values()

Inherited methods

Enum values

CLOSED

public static final CameraState.Type 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 CLOSING or OPENING state: It moves to this state from a CLOSING state after the camera device successfully closes, and from an OPENING state when opening a camera device that is unavailable due to NotificationManager.Policy, 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.

CLOSING

public static final CameraState.Type CLOSING

Represents a state where the camera device is currently closing.

The camera can move to this state from an OPEN or OPENING state: It moves to this state from an 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 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.

OPEN

public static final CameraState.Type OPEN

Represents a state where the camera device is open.

The camera can only move to this state from an 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.

OPENING

public static final CameraState.Type OPENING

Represents a state where the camera device is currently opening.

The camera can move to this state from a PENDING_OPEN or CLOSED state: It moves to this state from a PENDING_OPEN state after it receives a signal that the camera is available to open, and from a 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 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.

PENDING_OPEN

public static final CameraState.Type 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 CLOSED or OPENING state:

  • It moves to this state from a 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 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.

Public methods

valueOf

public static CameraState.Type valueOf (String name)

Parameters
name String

Returns
CameraState.Type

values

public static final Type[] values ()

Returns
Type[]