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.AvailabilityListener | A listener for camera devices becoming available or unavailable to open. |
Public Methods | |||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|
Register a listener to be notified about camera device availability.
| |||||||||||
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.
| |||||||||||
Remove a previously-added listener; the listener will no longer receive
connection and disconnection callbacks.
|
[Expand]
Inherited Methods | |||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|
From class
java.lang.Object
|
Register a listener to be notified about camera device availability.
Registering the same listener again will replace the handler with the new one provided.
listener | The new listener to send camera availability notices to |
---|---|
handler | The handler on which the listener should be invoked, or
null to use the current thread's looper .
|
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 currently connected camera device. |
---|---|
CameraAccessException | if the camera is disabled by device policy. |
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.StateListener, 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 listener'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 |
---|---|
listener | The listener which is invoked once the camera is opened |
handler | The handler on which the listener 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 listener 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 |
Remove a previously-added listener; the listener will no longer receive connection and disconnection callbacks.
Removing a listener that isn't registered has no effect.
listener | The listener to remove from the notification list |
---|