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

Class CameraManager


Deprecated. 
Not maintained anymore. Please use the com.iristick.smartglass.core.camera package instead.

@Deprecated
public abstract class CameraManager
extends Object

A service manager for detecting, characterizing, and connecting to CameraDevices.

The service manager is the main entry point in the interaction between the application and the camera devices. It allows getCameraIdList() querying the available devices, requesting their characteristics and opening a particular device.

This interface follows the singleton pattern. You can get an instance through getInstance(android.content.Context).

Since:
Android API level 21

Nested Class Summary

Modifier and Type Class and Description
static class  CameraManager.AvailabilityCallback
Deprecated. 
A callback for camera devices becoming available or unavailable to open.
static interface  CameraManager.HeadsetCallback
Deprecated. 
A callback for Iristick Smartglass headsets connecting or disconnecting.
static class  CameraManager.TorchCallback
Deprecated. 
A callback for camera flash torch modes becoming unavailable, disabled, or enabled.

Constructor Summary

Constructor and Description
CameraManager()
Deprecated. 
 

Method Summary

Modifier and Type Method and Description
abstract CameraCharacteristics getCameraCharacteristics(String cameraId)
Deprecated. 
Query the capabilities of a camera device.
abstract String[] getCameraIdList()
Deprecated. 
Return the list of currently connected camera devices by identifier, including cameras that may be in use by other camera API clients.
static CameraManager getInstance(Context context)
Deprecated. 
abstract void openCamera(String cameraId, CameraDevice.StateCallback callback, Handler handler)
Deprecated. 
Open a connection to a camera with the given ID.
abstract void registerAvailabilityCallback(CameraManager.AvailabilityCallback callback, Handler handler)
Deprecated. 
Register a callback to be notified about camera device availability.
abstract void registerHeadsetCallback(CameraManager.HeadsetCallback callback, Handler handler)
Deprecated. 
Register a callback to be notified about headset connection status.
abstract void registerTorchCallback(CameraManager.TorchCallback callback, Handler handler)
Deprecated. 
Register a callback to be notified about torch mode status.
abstract void setTorchMode(String cameraId, boolean enabled)
Deprecated. 
Set the flash unit's torch mode of the camera of the given ID without opening the camera device.
abstract void unregisterAvailabilityCallback(CameraManager.AvailabilityCallback callback)
Deprecated. 
Remove a previously-added callback; the callback will no longer receive connection and disconnection callbacks.
abstract void unregisterHeadsetCallback(CameraManager.HeadsetCallback callback)
Deprecated. 
Remove a previously-added callback; the callback will no longer receive headset status callbacks.
abstract void unregisterTorchCallback(CameraManager.TorchCallback callback)
Deprecated. 
Remove a previously-added callback; the callback will no longer receive torch mode status callbacks.

Methods inherited from class java.lang.Object

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

Constructor Detail

CameraManager

public CameraManager()
Deprecated. 

Method Detail

getInstance

public static CameraManager getInstance(Context context)
Deprecated. 

Fetches a CameraManager given the application environment.

When this library is used in combination with the Iristick app support library, make sure any calls to this method happen after the Iristick app support library is initialized.

Parameters:
context - The execution context of the application.
Returns:
A camera manager object

getCameraIdList

public abstract String[] getCameraIdList()
                                  throws CameraAccessException
Deprecated. 
Return the list of currently connected camera devices by identifier, including cameras that may be in use by other camera API clients.

Non-removable cameras use integers starting at 0 for their identifiers, while removable cameras have a unique identifier for each individual device, even if they are the same model.

Returns:
The list of currently connected camera devices.
Throws:
CameraAccessException - on error.

registerAvailabilityCallback

public abstract void registerAvailabilityCallback(CameraManager.AvailabilityCallback callback,
                                                  Handler handler)
Deprecated. 
Register a callback to be notified about camera device availability.

Registering the same callback again will replace the handler with the new one provided.

The first time a callback is registered, it is immediately called with the availability status of all currently known camera devices.

CameraManager.AvailabilityCallback.onCameraUnavailable(String) will be called whenever a camera device is opened by any camera API client. As of API level 23, other camera API clients may still be able to open such a camera device, evicting the existing client if they have higher priority than the existing client of a camera device. See open() for more details.

Since this callback will be registered with the camera service, remember to unregister it once it is no longer needed; otherwise the callback will continue to receive events indefinitely and it may prevent other resources from being released. Specifically, the callbacks will be invoked independently of the general activity lifecycle and independently of the state of individual CameraManager instances.

Parameters:
callback - the new callback to send camera availability notices to
handler - The handler on which the callback should be invoked, or null to use the current thread's looper.
Throws:
IllegalArgumentException - if the handler is null but the current thread has no looper.

unregisterAvailabilityCallback

public abstract void unregisterAvailabilityCallback(CameraManager.AvailabilityCallback callback)
Deprecated. 
Remove a previously-added callback; the callback will no longer receive connection and disconnection callbacks.

Removing a callback that isn't registered has no effect.

Parameters:
callback - The callback to remove from the notification list

registerTorchCallback

public abstract void registerTorchCallback(CameraManager.TorchCallback callback,
                                           Handler handler)
Deprecated. 
Register a callback to be notified about torch mode status.

Registering the same callback again will replace the handler with the new one provided.

The first time a callback is registered, it is immediately called with the torch mode status of all currently known camera devices with a flash unit.

Since this callback will be registered with the camera service, remember to unregister it once it is no longer needed; otherwise the callback will continue to receive events indefinitely and it may prevent other resources from being released. Specifically, the callbacks will be invoked independently of the general activity lifecycle and independently of the state of individual CameraManager instances.

Parameters:
callback - The new callback to send torch mode status to
handler - The handler on which the callback should be invoked, or null to use the current thread's looper.
Throws:
IllegalArgumentException - if the handler is null but the current thread has no looper.

unregisterTorchCallback

public abstract void unregisterTorchCallback(CameraManager.TorchCallback callback)
Deprecated. 
Remove a previously-added callback; the callback will no longer receive torch mode status callbacks.

Removing a callback that isn't registered has no effect.

Parameters:
callback - The callback to remove from the notification list

registerHeadsetCallback

public abstract void registerHeadsetCallback(CameraManager.HeadsetCallback callback,
                                             Handler handler)
Deprecated. 
Register a callback to be notified about headset connection status.

Registering the same callback again will replace the handler with the new one provided.

The first time a callback is registered, it is immediately called with the status of all currently connected headsets.

Since this callback will be registered with the camera service, remember to unregister it once it is no longer needed; otherwise the callback will continue to receive events indefinitely and it may prevent other resources from being released. Specifically, the callbacks will be invoked independently of the general activity lifecycle and independently of the state of individual CameraManager instances.

Parameters:
callback - The new callback to send torch mode status to
handler - The handler on which the callback should be invoked, or null to use the current thread's looper.
Throws:
IllegalArgumentException - if the handler is null but the current thread has no looper.

unregisterHeadsetCallback

public abstract void unregisterHeadsetCallback(CameraManager.HeadsetCallback callback)
Deprecated. 
Remove a previously-added callback; the callback will no longer receive headset status callbacks.

Removing a callback that isn't registered has no effect.

Parameters:
callback - The callback to remove from the notification list

getCameraCharacteristics

public abstract CameraCharacteristics getCameraCharacteristics(String cameraId)
                                                        throws CameraAccessException
Deprecated. 

Query the capabilities of a camera device. These capabilities are immutable for a given camera.

Parameters:
cameraId - The id of the camera device to query
Returns:
The properties of the given camera
Throws:
IllegalArgumentException - if the cameraId does not match any known camera device.
CameraAccessException - if the camera device has been disconnected.
See Also:
getCameraIdList(), DevicePolicyManager.setCameraDisabled(android.content.ComponentName, boolean)

openCamera

public abstract void openCamera(String cameraId,
                                CameraDevice.StateCallback callback,
                                Handler handler)
                         throws CameraAccessException
Deprecated. 
Open a connection to a camera with the given ID.

Use getCameraIdList() to get the list of available camera devices. Note that even if an id is listed, open may fail if the device is disconnected between the calls to getCameraIdList() and openCamera(java.lang.String, com.iristick.smartglass.support.camera2.CameraDevice.StateCallback, android.os.Handler), or if a higher-priority camera API client begins using the camera device.

As of API level 23, devices for which the CameraManager.AvailabilityCallback.onCameraUnavailable(String) callback has been called due to the device being in use by a lower-priority, background camera API client can still potentially be opened by calling this method when the calling camera API client has a higher priority than the current camera API client using this device. In general, if the top, foreground activity is running within your application process, your process will be given the highest priority when accessing the camera, and this method will succeed even if the camera device is in use by another camera API client. Any lower-priority application that loses control of the camera in this way will receive an CameraDevice.StateCallback.onDisconnected(com.iristick.smartglass.support.camera2.CameraDevice) callback.

Once the camera is successfully opened, CameraDevice.StateCallback.onOpened(com.iristick.smartglass.support.camera2.CameraDevice) will be invoked with the newly opened CameraDevice. The camera device can then be set up for operation by calling CameraDevice.createCaptureSession(java.util.List<android.view.Surface>, com.iristick.smartglass.support.camera2.CameraCaptureSession.StateCallback, android.os.Handler) and CameraDevice.createCaptureRequest(int)

If the camera becomes disconnected during initialization after this function call returns, CameraDevice.StateCallback.onDisconnected(com.iristick.smartglass.support.camera2.CameraDevice) with a CameraDevice in the disconnected state (and CameraDevice.StateCallback.onOpened(com.iristick.smartglass.support.camera2.CameraDevice) will be skipped).

If opening the camera device fails, then the device callback's onError method will be called, and subsequent calls on the camera device will throw a CameraAccessException.

Parameters:
cameraId - The unique identifier of the camera device to open
callback - The callback which is invoked once the camera is opened
handler - The handler on which the callback should be invoked, or null to use the current thread's looper.
Throws:
CameraAccessException - if the camera is disabled by device policy, has been disconnected, or is being used by a higher-priority camera API client.
IllegalArgumentException - if cameraId or the callback was null, or the cameraId does not match any currently or previously available camera device.
SecurityException - if the application does not have permission to access the camera
See Also:
getCameraIdList(), DevicePolicyManager.setCameraDisabled(android.content.ComponentName, boolean)

setTorchMode

public abstract void setTorchMode(String cameraId,
                                  boolean enabled)
                           throws CameraAccessException
Deprecated. 
Set the flash unit's torch mode of the camera of the given ID without opening the camera device.

Use getCameraIdList() to get the list of available camera devices and use getCameraCharacteristics(java.lang.String) to check whether the camera device has a flash unit. Note that even if a camera device has a flash unit, turning on the torch mode may fail if the camera device or other camera resources needed to turn on the torch mode are in use.

If setTorchMode(java.lang.String, boolean) is called to turn on or off the torch mode successfully, CameraManager.TorchCallback.onTorchModeChanged(java.lang.String, boolean) will be invoked. However, even if turning on the torch mode is successful, the application does not have the exclusive ownership of the flash unit or the camera device. The torch mode will be turned off and becomes unavailable when the camera device that the flash unit belongs to becomes unavailable or when other camera resources to keep the torch on become unavailable ( CameraManager.TorchCallback.onTorchModeUnavailable(java.lang.String) will be invoked). Also, other applications are free to call setTorchMode(java.lang.String, boolean) to turn off the torch mode ( CameraManager.TorchCallback.onTorchModeChanged(java.lang.String, boolean) will be invoked). If the latest application that turned on the torch mode exits, the torch mode will be turned off.

Parameters:
cameraId - The unique identifier of the camera device that the flash unit belongs to.
enabled - The desired state of the torch mode for the target camera device. Set to true to turn on the torch mode. Set to false to turn off the torch mode.
Throws:
CameraAccessException - if it failed to access the flash unit. CameraAccessException.CAMERA_IN_USE will be thrown if the camera device is in use. CameraAccessException.MAX_CAMERAS_IN_USE will be thrown if other camera resources needed to turn on the torch mode are in use. CameraAccessException.CAMERA_DISCONNECTED will be thrown if camera service is not available.
IllegalArgumentException - if cameraId was null, cameraId doesn't match any currently or previously available camera device, or the camera device doesn't have a flash unit.