public final class CameraKit extends Object
In general, the camera workflow is as follows:
CameraKit#getInstance(Context) to obtain a CameraKit instance.
CameraKit#registerCameraDeviceCallback(CameraDeviceCallback, EventHandler)
and unregister the callback by CameraKit#unregisterCameraDeviceCallback(CameraDeviceCallback).
CameraKit#getCameraIds().
CameraKit#getCameraInfo(String).
The information includes the camera facing direction, physical cameras that belong to the logical camera,
and connection types of physical cameras.
CameraKit#getCameraAbility(String)
and query the supported abilities and their configuration ranges through a specific ability querying method.
For example, you can query the support for the zoom function by using CameraAbility#getSupportedZoom().
CameraKit#createCamera(String,
CameraStateCallback, EventHandler).
Camera.
SystemCapability.Multimedia#CAMERA| 限定符和类型 | 方法 | 说明 |
|---|---|---|
void |
createCamera(String cameraId,
CameraStateCallback callback,
EventHandler handler) |
Creates a camera object.
|
CameraAbility |
getCameraAbility(String cameraId) |
Gets the static ability of a specified logical or physical camera.
|
String[] |
getCameraIds() |
Gets current logical camera IDs.
|
CameraInfo |
getCameraInfo(String cameraId) |
Gets a
CameraInfo object about a specified logical camera. |
static CameraKit |
getInstance(Context context) |
Gets a
CameraKit instance. |
void |
registerCameraDeviceCallback(CameraDeviceCallback callback,
EventHandler handler) |
Registers a callback for camera usage states.
|
void |
setFlashlight(String cameraId,
boolean isEnable) |
Enables or disables the flashlight.
|
void |
unregisterCameraDeviceCallback(CameraDeviceCallback callback) |
Unregisters a callback for camera usage states.
|
public static CameraKit getInstance(Context context)
CameraKit instance.
This method provides the only CameraKit object accessed by all applications.
context - Indicates the application context.CameraKit instance if the input parameter is valid; returns null otherwise.public String[] getCameraIds()
IllegalStateException - Throws this exception if camera service is not initialized.public CameraInfo getCameraInfo(String cameraId)
CameraInfo object about a specified logical camera.
The logical camera ID can be obtained by CameraKit#getCameraIds().
cameraId - Indicates the ID of the logical camera.null if the ID is invalid or the query fails.IllegalStateException - Throws this exception if camera service is not initialized.public CameraAbility getCameraAbility(String cameraId)
Use the methods provided in CameraAbility to use the ability.
cameraId - Indicates the ID of a logical or physical camera.
A logical camera ID can be obtained by CameraKit#getCameraIds().
A physical camera ID can be obtained by CameraInfo#getPhysicalIdList().
null if the ID is invalid or the query fails.IllegalStateException - Throws this exception if camera service is not initialized.public void createCamera(String cameraId, CameraStateCallback callback, EventHandler handler)
All parameters must not be null.
After the camera is created, CameraStateCallback#onCreated(Camera) is called.
cameraId - Indicates the ID of a logical or physical camera.
A logical camera ID can be obtained by CameraKit#getCameraIds().
A physical camera ID can be obtained by CameraInfo#getPhysicalIdList().
callback - Indicates the callback for camera creation and running states. If the callback is null, an
exception will be thrown.handler - Indicates a handler of the callback for internal camera operations. If the handler is null, an
exception will be thrown.
The handler should be valid throughout the camera lifecycle. If the handler is released earlier than excepted, an error may occur, or an exception can be thrown.
NullPointerException - Throws this exception if an input parameter is null.IllegalStateException - Throws this exception if camera service is not initialized.public void setFlashlight(String cameraId, boolean isEnable)
When the flashlight is enabled or disabled successfully,
CameraDeviceCallback#onFlashlightStatus(String, int) is called.
When the flashlight is unavailable, for example, when the camera is being occupied by another application,
CameraDeviceCallback#onFlashlightStatus(String, int) is called.
cameraId - Indicates the camera ID.isEnable - Indicates whether the flashlight is enabled. true indicates that the flashlight is
enabled; false indicates that the flashlight is disabled.public void registerCameraDeviceCallback(CameraDeviceCallback callback, EventHandler handler)
This method can be used to monitor camera states.
This method can be called multiple times. If the same callback is passed repeatedly, only the callback passed for the first time is valid.
callback - Indicates a callback for camera usage states.handler - Indicates a handler of the callback. The handler must not be null, and the callback will be
invoked in the handler.
The handler must be valid throughout the camera lifecycle. If the handler is released before expected, an exception may be thrown.
NullPointerException - Throws this exception if an input parameter is null.IllegalStateException - Throws this exception if camera service is not initialized.public void unregisterCameraDeviceCallback(CameraDeviceCallback callback)
If the same callback is passed repeatedly, only the callback passed for the first time is valid. After a callback is unregistered, camera usage states will not be received. An invalid callback or one passed repeatedly will be ignored.
callback - Indicates a callback for camera usage states.NullPointerException - Throws this exception if an input parameter is null.IllegalStateException - Throws this exception if camera service is not initialized.