java.lang.Object | |
↳ | android.hardware.camera2.CameraManager |
A system service manager for detecting, characterizing, and connecting to
CameraDevices
.
You can get an instance of this class by calling
Context.getSystemService()
.
CameraManager manager = (CameraManager) getSystemService(Context.CAMERA_SERVICE);
For more details about communicating with camera devices, read the Camera
developer guide or the camera2
package documentation.
Nested Classes | |||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|
CameraManager.AvailabilityCallback | A callback for camera devices becoming available or unavailable to open. |
Public Methods | |||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|
Query the capabilities of a camera device. | |||||||||||
Return the list of currently connected camera devices by
identifier.
| |||||||||||
Open a connection to a camera with the given ID.
| |||||||||||
Register a callback to be notified about camera device availability.
| |||||||||||
Remove a previously-added callback; the callback will no longer receive connection and
disconnection callbacks.
|
[Expand]
Inherited Methods | |||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|
![]() |
Query the capabilities of a camera device. These capabilities are immutable for a given camera.
cameraId | The id of the camera device to query |
---|
IllegalArgumentException | if the cameraId does not match any known camera device. |
---|---|
CameraAccessException | if the camera is disabled by device policy, or the camera device has been disconnected. |
SecurityException | if the application does not have permission to access the camera |
Return the list of currently connected camera devices by identifier.
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.
CameraAccessException |
---|
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(String, CameraDevice.StateCallback, Handler)
.
Once the camera is successfully opened, onOpened(CameraDevice)
will
be invoked with the newly opened CameraDevice
. The camera device can then be set up
for operation by calling createCaptureSession(List
and
createCaptureRequest(int)
If the camera becomes disconnected during initialization
after this function call returns,
onDisconnected(CameraDevice)
with a
CameraDevice
in the disconnected state (and
onOpened(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
.
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 . |
CameraAccessException | if the camera is disabled by device policy, or the camera has become or was disconnected. |
---|---|
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 |
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.
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 .
|
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.
callback | The callback to remove from the notification list |
---|