CameraState.Type


public enum CameraState.Type


States the camera can be in.

Summary

Enum Values

CLOSED

Represents a state where the camera device is closed.

CLOSING

Represents a state where the camera device is currently closing.

OPEN

Represents a state where the camera device is open.

OPENING

Represents a state where the camera device is currently opening.

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

Returns the enum constant of this type with the specified name.

static CameraState.Type[]

Returns an array containing the constants of this enum type, in the order they're declared.

Enum Values

CLOSED

CameraState.Type 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 android.app.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

CameraState.Type 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

CameraState.Type 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

CameraState.Type 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 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

CameraState.Type 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

Added in 1.1.0
public static CameraState.Type valueOf(String name)

Returns the enum constant of this type with the specified name. The string must match exactly an identifier used to declare an enum constant in this type. (Extraneous whitespace characters are not permitted.)

Returns
CameraState.Type

the enum constant with the specified name

Throws
java.lang.IllegalArgumentException

if this enum type has no constant with the specified name

values

Added in 1.1.0
public static CameraState.Type[] values()

Returns an array containing the constants of this enum type, in the order they're declared. This method may be used to iterate over the constants.

Returns
CameraState.Type[]

an array containing the constants of this enum type, in the order they're declared