CameraState.StateError
@AutoValue
public abstract class CameraState.StateError
Error that the camera has encountered.
The camera may report an error when it's in one of the following states: OPENING, OPEN, CLOSING and CLOSED.
CameraX attempts to recover from certain errors it encounters when opening the camera device, in these instances, the error is recoverable, otherwise, the error is critical.
When CameraX encounters a critical error, the developer and/or user must intervene to restore camera function. When the error is recoverable, the developer and/or user can still aid in the recovery process, as shown in the following table.
| State | Error Code | Recoverable | How to handle it |
|---|---|---|---|
OPEN |
ERROR_STREAM_CONFIG |
No | Make sure you set up your use cases correctly. |
OPENING |
ERROR_CAMERA_IN_USE |
Yes | Close the camera, or ask the user to close another camera app that is using the camera. |
OPENING |
ERROR_MAX_CAMERAS_IN_USE |
Yes | Close another open camera in the app, or ask the user to close another camera app that's using the camera. |
OPENING |
ERROR_OTHER_RECOVERABLE_ERROR |
Yes | N/A |
CLOSING |
ERROR_CAMERA_DISABLED |
No | Ask the user to enable the device's cameras. |
CLOSING |
ERROR_CAMERA_FATAL_ERROR |
No | Ask the user to reboot the device to restore camera function. |
CLOSED |
ERROR_DO_NOT_DISTURB_MODE_ENABLED |
No | Ask the user to disable "Do Not Disturb" mode, then open the camera again. |
CLOSED |
ERROR_CAMERA_REMOVED |
No | The camera is offline. To use it again, the user must reconnect the device. The application should listen for the onCameraAdded event. |
Summary
Public constructors |
|---|
Public methods |
|
|---|---|
static @NonNull CameraState.StateError |
create(int error)Creates a |
static @NonNull CameraState.StateError |
Creates a |
abstract @Nullable Throwable |
getCause()Returns a potential cause of this error. |
abstract int |
getCode()Returns the code of this error. |
@NonNull CameraState.ErrorType |
getType()Returns the type of this error. |
Public constructors
Public methods
create
public static @NonNull CameraState.StateError create(int error)
Creates a StateError with an error code.
A StateError is not expected to be instantiated in normal operation.
create
public static @NonNull CameraState.StateError create(int error, @Nullable Throwable cause)
Creates a StateError with an error code and a cause.
A StateError is not expected to be instantiated in normal operation.
getCause
public abstract @Nullable Throwable getCause()
Returns a potential cause of this error.
getCode
public abstract int getCode()
Returns the code of this error.
The error's code is one of the following: ERROR_CAMERA_IN_USE, ERROR_MAX_CAMERAS_IN_USE, ERROR_OTHER_RECOVERABLE_ERROR, ERROR_STREAM_CONFIG, ERROR_CAMERA_DISABLED, ERROR_CAMERA_FATAL_ERROR, ERROR_DO_NOT_DISTURB_MODE_ENABLED and ERROR_CAMERA_REMOVED.
| Returns | |
|---|---|
int |
The code of this error. |
getType
public @NonNull CameraState.ErrorType getType()
Returns the type of this error.
An error can either be recoverable or critical.
| Returns | |
|---|---|
@NonNull CameraState.ErrorType |
The type of this error |