Register now for Android Dev Summit 2019!

CameraManagerCompat

class CameraManagerCompat
kotlin.Any
   ↳ androidx.camera.camera2.impl.compat.CameraManagerCompat

Helper for accessing features in CameraManager in a backwards compatible fashion.

Summary

Public methods

static CameraManagerCompat!
from(context: Context!)

Get a CameraManagerCompat instance for a provided context.

Unit
openCamera(@NonNull cameraId: String, @NonNull executor: Executor, @NonNull callback: StateCallback)

Open a connection to a camera with the given ID.

Unit
registerAvailabilityCallback(@NonNull executor: Executor, @NonNull callback: AvailabilityCallback)

Register a callback to be notified about camera device availability.

Unit

Remove a previously-added callback; the callback will no longer receive connection and disconnection callbacks.

CameraManager

Gets the underlying framework CameraManager object.

Public methods

from

static fun from(context: Context!): CameraManagerCompat!

Get a CameraManagerCompat instance for a provided context.

openCamera

fun openCamera(@NonNull cameraId: String, @NonNull executor: Executor, @NonNull callback: StateCallback): Unit

Open a connection to a camera with the given ID.

The behavior of this method matches that of CameraManager#openCamera(String, CameraDevice.StateCallback, Handler), except that it uses Executor as an argument instead of Handler.

Parameters
cameraId String: The unique identifier of the camera device to open
executor String: The executor which will be used when invoking the callback.
callback String: The callback which is invoked once the camera is opened
Exceptions
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, the callback or the executor 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

registerAvailabilityCallback

fun registerAvailabilityCallback(@NonNull executor: Executor, @NonNull callback: AvailabilityCallback): Unit

Register a callback to be notified about camera device availability.

The behavior of this method matches that of , except that it uses Executor as an argument instead of Handler.

When registering an availability callback with registerAvailabilityCallback(Executor, CameraManager.AvailabilityCallback), it should always be unregistered by calling unregisterAvailabilityCallback(CameraManager.AvailabilityCallback) on the same instance of CameraManagerCompat. Unregistering through a difference instance or directly through CameraManager may fail to unregister the callback with the camera service.

Parameters
executor Executor: The executor which will be used to invoke the callback.
callback Executor: the new callback to send camera availability notices to
Exceptions
IllegalArgumentException if the executor is null.

unregisterAvailabilityCallback

fun unregisterAvailabilityCallback(@NonNull callback: AvailabilityCallback): Unit

Remove a previously-added callback; the callback will no longer receive connection and disconnection callbacks.

All callbacks registered through an instance of CameraManagerCompat should be unregistered through the same instance, otherwise the callback may fail to unregister with the camera service.

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

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

unwrap

@NonNull fun unwrap(): CameraManager

Gets the underlying framework CameraManager object.

This method can be used gain access to CameraManager methods not exposed by CameraManagerCompat.