Causes the current thread to wait until another thread invokes the
notify() method or the
notifyAll() method for this object, or
some other thread interrupts the current thread, or a certain
amount of real time has elapsed.

As of API level 23, devices for which the
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
onDisconnected(CameraDevice) callback.

registerAvailabilityCallback

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.

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

CameraManager.AvailabilityCallback: the new callback to send camera availability notices to

This value must never be null.

handler

Handler: The handler on which the callback should be invoked, or null to use
the current thread's looper.

registerTorchCallback

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

CameraManager.TorchCallback: The new callback to send torch mode status to

This value must never be null.

handler

Handler: The handler on which the callback should be invoked, or null to use
the current thread's looper.

setTorchMode

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(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(String, boolean) is called to turn on or off the torch mode successfully,
onTorchModeChanged(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 (
onTorchModeUnavailable(String) will be invoked). Also,
other applications are free to call setTorchMode(String, boolean) to turn off the torch mode (
onTorchModeChanged(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

String: The unique identifier of the camera device that the flash unit belongs to.

This value must never be null.

enabled

boolean: 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.

if it failed to access the flash unit.
CAMERA_IN_USE will be thrown if the camera device
is in use. MAX_CAMERAS_IN_USE will be thrown if
other camera resources needed to turn on the torch mode are in use.
CAMERA_DISCONNECTED will be thrown if camera
service is not available.