java.lang.Object | |
↳ | android.hardware.camera2.CameraDevice |
The CameraDevice class is a representation of a single camera connected to an Android device, allowing for fine-grain control of image capture and post-processing at high frame rates.
Your application must declare the
Camera
permission in its manifest
in order to access camera devices.
A given camera device may provide support at one of two levels: limited or
full. If a device only supports the limited level, then Camera2 exposes a
feature set that is roughly equivalent to the older
Camera
API, although with a cleaner and more
efficient interface. Devices that implement the full level of support
provide substantially improved capabilities over the older camera
API. Applications that target the limited level devices will run unchanged on
the full-level devices; if your application requires a full-level device for
proper operation, declare the "android.hardware.camera2.full" feature in your
manifest.
Nested Classes | |||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|
CameraDevice.CaptureListener |
This class is deprecated.
Use CameraCaptureSession.CaptureListener instead
|
||||||||||
CameraDevice.StateListener | A listener for notifications about the state of a camera device. |
Constants | |||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|
int | TEMPLATE_MANUAL | A basic template for direct application control of capture parameters. | |||||||||
int | TEMPLATE_PREVIEW | Create a request suitable for a camera preview window. | |||||||||
int | TEMPLATE_RECORD | Create a request suitable for video recording. | |||||||||
int | TEMPLATE_STILL_CAPTURE | Create a request suitable for still image capture. | |||||||||
int | TEMPLATE_VIDEO_SNAPSHOT | Create a request suitable for still image capture while recording video. | |||||||||
int | TEMPLATE_ZERO_SHUTTER_LAG | Create a request suitable for zero shutter lag still capture. |
Public Methods | |||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|
This method is deprecated.
Use
capture(CaptureRequest, CameraCaptureSession.CaptureListener, Handler) instead
| |||||||||||
This method is deprecated.
Use
captureBurst(List instead
| |||||||||||
Close the connection to this camera device as quickly as possible.
| |||||||||||
This method is deprecated.
Use
createCaptureSession(List instead
| |||||||||||
Create a | |||||||||||
Create a new camera capture session by providing the target output set of Surfaces to the camera device. | |||||||||||
This method is deprecated.
Use
abortCaptures() instead
| |||||||||||
Get the ID of this camera device.
| |||||||||||
This method is deprecated.
Use
setRepeatingBurst(List instead
| |||||||||||
This method is deprecated.
Use
setRepeatingRequest(CaptureRequest, CameraCaptureSession.CaptureListener, Handler) instead
| |||||||||||
This method is deprecated.
Use
stopRepeating() instead
|
[Expand]
Inherited Methods | |||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|
From class
java.lang.Object
| |||||||||||
From interface
java.lang.AutoCloseable
|
A basic template for direct application control of capture parameters. All automatic control is disabled (auto-exposure, auto-white balance, auto-focus), and post-processing parameters are set to preview quality. The manual capture parameters (exposure, sensitivity, and so on) are set to reasonable defaults, but should be overriden by the application depending on the intended use case.
Create a request suitable for a camera preview window. Specifically, this
means that high frame rate is given priority over the highest-quality
post-processing. These requests would normally be used with the
setRepeatingRequest(CaptureRequest, CameraCaptureSession.CaptureListener, Handler)
method.
Create a request suitable for video recording. Specifically, this means
that a stable frame rate is used, and post-processing is set for
recording quality. These requests would commonly be used with the
setRepeatingRequest(CaptureRequest, CameraCaptureSession.CaptureListener, Handler)
method.
Create a request suitable for still image capture. Specifically, this
means prioritizing image quality over frame rate. These requests would
commonly be used with the capture(CaptureRequest, CameraCaptureSession.CaptureListener, Handler)
method.
Create a request suitable for still image capture while recording
video. Specifically, this means maximizing image quality without
disrupting the ongoing recording. These requests would commonly be used
with the capture(CaptureRequest, CameraCaptureSession.CaptureListener, Handler)
method while a request based on
TEMPLATE_RECORD
is is in use with setRepeatingRequest(CaptureRequest, CameraCaptureSession.CaptureListener, Handler)
.
Create a request suitable for zero shutter lag still capture. This means means maximizing image quality without compromising preview frame rate. AE/AWB/AF should be on auto mode.
This method is deprecated.
Use capture(CaptureRequest, CameraCaptureSession.CaptureListener, Handler)
instead
Submit a request for an image to be captured by this CameraDevice.
CameraAccessException |
---|
This method is deprecated.
Use captureBurst(List
instead
Submit a list of requests to be captured in sequence as a burst.
CameraAccessException |
---|
Close the connection to this camera device as quickly as possible.
Immediately after this call, all calls to the camera device or active session interface
will throw a IllegalStateException
, except for calls to close(). Once the device has
fully shut down, the onClosed(CameraDevice)
callback will be called, and the camera
is free to be re-opened.
Immediately after this call, besides the final onClosed(CameraDevice)
calls, no
further callbacks from the device or the active session will occur, and any remaining
submitted capture requests will be discarded, as if
abortCaptures()
had been called, except that no success or failure
callbacks will be invoked.
This method is deprecated.
Use createCaptureSession(List
instead
Set up a new output set of Surfaces for the camera device.
CameraAccessException |
---|
Create a CaptureRequest.Builder
for new capture requests,
initialized with template for a target use case. The settings are chosen
to be the best options for the specific camera device, so it is not
recommended to reuse the same request for a different camera device;
create a builder specific for that device and template and override the
settings as desired, instead.
templateType | An enumeration selecting the use case for this request; one of the CameraDevice.TEMPLATE_ values. |
---|
IllegalArgumentException | if the templateType is not in the list of supported templates. |
---|---|
CameraAccessException | if the camera device is no longer connected or has encountered a fatal error |
IllegalStateException | if the camera device has been closed |
Create a new camera capture session by providing the target output set of Surfaces to the camera device.
The active capture session determines the set of potential output Surfaces for
the camera device for each capture request. A given request may use all
or a only some of the outputs. Once the CameraCaptureSession is created, requests can be
can be submitted with capture
,
captureBurst
,
setRepeatingRequest
, or
setRepeatingBurst
.
Surfaces suitable for inclusion as a camera output can be created for various use cases and targets:
SurfaceView
: Once the SurfaceView's
Surface is created
, set the
size of the Surface with setFixedSize(int, int)
to be one of the
sizes returned by
getOutputSizes(SurfaceHolder.class)
and then obtain the Surface by calling getSurface()
.SurfaceTexture
: Set the size of
the SurfaceTexture with
setDefaultBufferSize(int, int)
to be one
of the sizes returned by
getOutputSizes(SurfaceTexture.class)
before creating a Surface from the SurfaceTexture with
Surface(SurfaceTexture)
.MediaCodec
: Call
createInputSurface()
after configuring
the media codec to use one of the sizes returned by
getOutputSizes(MediaCodec.class)
MediaRecorder
: Call
getSurface()
after configuring the media recorder to use
one of the sizes returned by
getOutputSizes(MediaRecorder.class)
,
or configuring it to use one of the supported
CamcorderProfiles
.android.renderscript
:
Create a RenderScript
Allocation
with a supported YUV
type, the IO_INPUT flag, and one of the sizes returned by
getOutputSizes(Allocation.class)
,
Then obtain the Surface with
getSurface()
.ImageReader
object with one of the supported output formats given by
getOutputFormats()
, setting its size to one of the
corresponding supported sizes by passing the chosen output format into
getOutputSizes(int)
. Then obtain a
Surface
from it with getSurface()
.
The camera device will query each Surface's size and formats upon this call, so they must be set to a valid setting at this time.
It can take several hundred milliseconds for the session's configuration to complete,
since camera hardware may need to be powered on or reconfigured. Once the configuration is
complete and the session is ready to actually capture data, the provided
CameraCaptureSession.StateListener
's
onConfigured(CameraCaptureSession)
callback will be called.
If a prior CameraCaptureSession already exists when a new one is created, the previous
session is closed. Any in-progress capture requests made on the prior session will be
completed before the new session is configured and is able to start capturing its own
requests. To minimize the transition time, the abortCaptures()
call can be used to discard the remaining requests for the prior capture session before a new
one is created. Note that once the new session is created, the old one can no longer have its
captures aborted.
Using larger resolution outputs, or more outputs, can result in slower output rate from the device.
Configuring a session with an empty or null list will close the current session, if any. This can be used to release the current session's target surfaces for another use.
outputs | The new set of Surfaces that should be made available as targets for captured image data. |
---|---|
listener | The listener to notify about the status of the new capture session. |
handler | The handler on which the listener should be invoked, or null to use
the current thread's looper . |
IllegalArgumentException | if the set of output Surfaces do not meet the requirements, the listener is null, or the handler is null but the current thread has no looper. |
---|---|
CameraAccessException | if the camera device is no longer connected or has encountered a fatal error |
IllegalStateException | if the camera device has been closed |
This method is deprecated.
Use abortCaptures()
instead
Flush all captures currently pending and in-progress as fast as possible.
CameraAccessException |
---|
Get the ID of this camera device.
This matches the ID given to openCamera(String, CameraDevice.StateListener, Handler)
to instantiate this
this camera device.
This ID can be used to query the camera device's fixed properties
with getCameraCharacteristics(String)
.
This method can be called even if the device has been closed or has encountered a serious error.
This method is deprecated.
Use setRepeatingBurst(List
instead
Request endlessly repeating capture of a sequence of images by this CameraDevice.
CameraAccessException |
---|
This method is deprecated.
Use setRepeatingRequest(CaptureRequest, CameraCaptureSession.CaptureListener, Handler)
instead
Request endlessly repeating capture of images by this CameraDevice.
CameraAccessException |
---|
This method is deprecated.
Use stopRepeating()
instead
Cancel any ongoing repeating capture set by either
setRepeatingRequest
or
setRepeatingBurst(List
.
CameraAccessException |
---|