Skip to content
com.iristick.smartglass.support.camera2

Class CameraDevice.StateCallback

  • java.lang.Object
    • com.iristick.smartglass.support.camera2.CameraDevice.StateCallback
Enclosing interface:
CameraDevice

public abstract static class CameraDevice.StateCallback
extends Object
A callback objects for receiving updates about the state of a camera device.

A callback instance must be provided to the CameraManager.openCamera(java.lang.String, com.iristick.smartglass.support.camera2.CameraDevice.StateCallback, android.os.Handler) method to open a camera device.

These state updates include notifications about the device completing startup ( allowing for CameraDevice.createCaptureSession(java.util.List<android.view.Surface>, com.iristick.smartglass.support.camera2.CameraCaptureSession.StateCallback, android.os.Handler) to be called), about device disconnection or closure, and about unexpected device errors.

Events about the progress of specific CaptureRequests are provided through a CameraCaptureSession.CaptureCallback given to the CameraCaptureSession.capture(com.iristick.smartglass.support.camera2.CaptureRequest, com.iristick.smartglass.support.camera2.CameraCaptureSession.CaptureCallback, android.os.Handler), CameraCaptureSession.captureBurst(java.util.List<com.iristick.smartglass.support.camera2.CaptureRequest>, com.iristick.smartglass.support.camera2.CameraCaptureSession.CaptureCallback, android.os.Handler), CameraCaptureSession.setRepeatingRequest(com.iristick.smartglass.support.camera2.CaptureRequest, com.iristick.smartglass.support.camera2.CameraCaptureSession.CaptureCallback, android.os.Handler), or CameraCaptureSession.setRepeatingBurst(java.util.List<com.iristick.smartglass.support.camera2.CaptureRequest>, com.iristick.smartglass.support.camera2.CameraCaptureSession.CaptureCallback, android.os.Handler) methods.

See Also:
CameraManager.openCamera(java.lang.String, com.iristick.smartglass.support.camera2.CameraDevice.StateCallback, android.os.Handler)

Field Summary

Modifier and Type Field and Description
static int ERROR_CAMERA_DEVICE
An error code that can be reported by onError(com.iristick.smartglass.support.camera2.CameraDevice, int) indicating that the camera device has encountered a fatal error.
static int ERROR_CAMERA_DISABLED
An error code that can be reported by onError(com.iristick.smartglass.support.camera2.CameraDevice, int) indicating that the camera device could not be opened due to a device policy.
static int ERROR_CAMERA_IN_USE
An error code that can be reported by onError(com.iristick.smartglass.support.camera2.CameraDevice, int) indicating that the camera device is in use already.
static int ERROR_CAMERA_SERVICE
An error code that can be reported by onError(com.iristick.smartglass.support.camera2.CameraDevice, int) indicating that the camera service has encountered a fatal error.
static int ERROR_MAX_CAMERAS_IN_USE
An error code that can be reported by onError(com.iristick.smartglass.support.camera2.CameraDevice, int) indicating that the camera device could not be opened because there are too many other open camera devices.

Constructor Summary

Constructor and Description
StateCallback() 

Method Summary

Modifier and Type Method and Description
void onClosed(CameraDevice camera)
The method called when a camera device has been closed with CameraDevice.close().
abstract void onDisconnected(CameraDevice camera)
The method called when a camera device is no longer available for use.
abstract void onError(CameraDevice camera, int error)
The method called when a camera device has encountered a serious error.
abstract void onOpened(CameraDevice camera)
The method called when a camera device has finished opening.

Methods inherited from class java.lang.Object

equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait

Field Detail

ERROR_CAMERA_IN_USE

public static final int ERROR_CAMERA_IN_USE
An error code that can be reported by onError(com.iristick.smartglass.support.camera2.CameraDevice, int) indicating that the camera device is in use already.

This error can be produced when opening the camera fails due to the camera being used by a higher-priority camera API client.

See Also:
onError(com.iristick.smartglass.support.camera2.CameraDevice, int)

ERROR_MAX_CAMERAS_IN_USE

public static final int ERROR_MAX_CAMERAS_IN_USE
An error code that can be reported by onError(com.iristick.smartglass.support.camera2.CameraDevice, int) indicating that the camera device could not be opened because there are too many other open camera devices.

The system-wide limit for number of open cameras has been reached, and more camera devices cannot be opened until previous instances are closed.

This error can be produced when opening the camera fails.

See Also:
onError(com.iristick.smartglass.support.camera2.CameraDevice, int)

ERROR_CAMERA_DISABLED

public static final int ERROR_CAMERA_DISABLED
An error code that can be reported by onError(com.iristick.smartglass.support.camera2.CameraDevice, int) indicating that the camera device could not be opened due to a device policy.
See Also:
DevicePolicyManager.setCameraDisabled(android.content.ComponentName, boolean), onError(com.iristick.smartglass.support.camera2.CameraDevice, int)

ERROR_CAMERA_DEVICE

public static final int ERROR_CAMERA_DEVICE
An error code that can be reported by onError(com.iristick.smartglass.support.camera2.CameraDevice, int) indicating that the camera device has encountered a fatal error.

The camera device needs to be re-opened to be used again.

See Also:
onError(com.iristick.smartglass.support.camera2.CameraDevice, int)

ERROR_CAMERA_SERVICE

public static final int ERROR_CAMERA_SERVICE
An error code that can be reported by onError(com.iristick.smartglass.support.camera2.CameraDevice, int) indicating that the camera service has encountered a fatal error.

The Android device may need to be shut down and restarted to restore camera function, or there may be a persistent hardware problem.

An attempt at recovery may be possible by closing the CameraDevice and the CameraManager, and trying to acquire all resources again from scratch.

See Also:
onError(com.iristick.smartglass.support.camera2.CameraDevice, int)

Constructor Detail

StateCallback

public StateCallback()

Method Detail

onOpened

public abstract void onOpened(CameraDevice camera)
The method called when a camera device has finished opening.

At this point, the camera device is ready to use, and CameraDevice.createCaptureSession(java.util.List<android.view.Surface>, com.iristick.smartglass.support.camera2.CameraCaptureSession.StateCallback, android.os.Handler) can be called to set up the first capture session.

Parameters:
camera - the camera device that has become opened

onClosed

public void onClosed(CameraDevice camera)
The method called when a camera device has been closed with CameraDevice.close().

Any attempt to call methods on this CameraDevice in the future will throw a IllegalStateException.

The default implementation of this method does nothing.

Parameters:
camera - the camera device that has become closed

onDisconnected

public abstract void onDisconnected(CameraDevice camera)
The method called when a camera device is no longer available for use.

This callback may be called instead of onOpened(com.iristick.smartglass.support.camera2.CameraDevice) if opening the camera fails.

Any attempt to call methods on this CameraDevice will throw a CameraAccessException. The disconnection could be due to a change in security policy or permissions; the physical disconnection of a removable camera device; or the camera being needed for a higher-priority camera API client.

There may still be capture callbacks that are invoked after this method is called, or new image buffers that are delivered to active outputs.

The default implementation logs a notice to the system log about the disconnection.

You should clean up the camera with CameraDevice.close() after this happens, as it is not recoverable until the camera can be opened again. For most use cases, this will be when the camera again becomes available.

Parameters:
camera - the device that has been disconnected

onError

public abstract void onError(CameraDevice camera,
                             int error)
The method called when a camera device has encountered a serious error.

This callback may be called instead of onOpened(com.iristick.smartglass.support.camera2.CameraDevice) if opening the camera fails.

This indicates a failure of the camera device or camera service in some way. Any attempt to call methods on this CameraDevice in the future will throw a CameraAccessException with the CAMERA_ERROR reason.

There may still be capture completion or camera stream callbacks that will be called after this error is received.

You should clean up the camera with CameraDevice.close() after this happens. Further attempts at recovery are error-code specific.

Parameters:
camera - The device reporting the error
error - The error code.
See Also:
ERROR_CAMERA_IN_USE, ERROR_MAX_CAMERAS_IN_USE, ERROR_CAMERA_DISABLED, ERROR_CAMERA_DEVICE, ERROR_CAMERA_SERVICE