提供了查询设备的闪光灯状态和模式的能力。
hasFlash(): boolean
检测是否有闪光灯,返回是否支持闪光灯。
元服务API: 从API version 19开始,该接口支持在元服务中使用。
系统能力: SystemCapability.Multimedia.Camera.Core
返回值:
| 类型 | 说明 |
|---|---|
| boolean | 表示设备是否支持闪光灯。true表示支持闪光灯,false表示不支持闪光灯。 如果返回false,则isFlashModeSupported、setFlashMode和getFlashMode都不会生效。 接口调用失败会返回相应错误码,错误码类型CameraErrorCode。 |
错误码:
以下错误码的详细介绍请参见Camera错误码。
| 错误码ID | 错误信息 |
|---|---|
| 7400103 | Session not config, only throw in session usage. |
示例:
import { BusinessError } from '@kit.BasicServicesKit';
function hasFlash(photoSession: camera.PhotoSession): boolean {
let status: boolean = false;
try {
status = photoSession.hasFlash();
} catch (error) {
// 失败返回错误码error.code并处理。
let err = error as BusinessError;
console.error(`The hasFlash call failed. error code: ${err.code}`);
}
return status;
} isFlashModeSupported(flashMode: FlashMode): boolean
检测闪光灯模式是否支持。
元服务API: 从API version 19开始,该接口支持在元服务中使用。
系统能力: SystemCapability.Multimedia.Camera.Core
参数:
| 参数名 | 类型 | 必填 | 说明 |
|---|---|---|---|
| flashMode | FlashMode | 是 | 指定闪光灯模式。传参为null或者undefined,作为0处理,闪光灯关闭。 |
返回值:
| 类型 | 说明 |
|---|---|
| boolean | 检测表示支持该闪光灯模式。true表示支持,false表示不支持。接口调用失败会抛出相应错误码并返回undefined,错误码类型CameraErrorCode。 |
错误码:
以下错误码的详细介绍请参见Camera错误码。
| 错误码ID | 错误信息 |
|---|---|
| 7400103 | Session not config, only throw in session usage. |
示例:
import { BusinessError } from '@kit.BasicServicesKit';
function isFlashModeSupported(photoSession: camera.PhotoSession): boolean {
let status: boolean = false;
try {
status = photoSession.isFlashModeSupported(camera.FlashMode.FLASH_MODE_AUTO);
} catch (error) {
// 失败返回错误码error.code并处理。
let err = error as BusinessError;
console.error(`The isFlashModeSupported call failed. error code: ${err.code}`);
}
return status;
}