openharmony 鸿蒙 arkts-apis-camera-FlashQuery

2026-08-25 浏览 (1)

Interface (FlashQuery)

FlashQuery provides APIs to query the flash status and mode of a camera device.

NOTE

  • The initial APIs of this module are supported since API version 10. Newly added APIs will be marked with a superscript to indicate their earliest API version.
  • This interface was first introduced in API version 12. In this version, a compatibility change was made that preserved the initial version information of inner elements. As a result, you might see outer element's @since version number being higher than that of the inner elements. However, this discrepancy does not affect the functionality of the interface.

Modules to Import

import { camera } from '@kit.CameraKit';

hasFlash11+

hasFlash(): boolean

Checks whether the camera device has flash.

Atomic service API: This API can be used in atomic services since API version 19.

System capability: SystemCapability.Multimedia.Camera.Core

Return value

TypeDescription
booleanWhether the camera has flash. true if it has, false otherwise.
If false is returned, isFlashModeSupported, setFlashMode, and getFlashMode do not take effect.
If the operation fails, an error code defined in CameraErrorCode is returned.

Error codes

For details about the error codes, see Camera Error Codes.

IDError Message
7400103Session not config, only throw in session usage.

Example

import { BusinessError } from '@kit.BasicServicesKit';

function hasFlash(photoSession: camera.PhotoSession): boolean {
  let status: boolean = false;
  try {
    status = photoSession.hasFlash();
  } catch (error) {
    // If the operation fails, error.code is returned and processed.
    let err = error as BusinessError;
    console.error(`The hasFlash call failed. error code: ${err.code}`);
  }
  return status;
}

isFlashModeSupported11+

isFlashModeSupported(flashMode: FlashMode): boolean

Checks whether a flash mode is supported.

Atomic service API: This API can be used in atomic services since API version 19.

System capability: SystemCapability.Multimedia.Camera.Core

Parameters

NameTypeMandatoryDescription
flashModeFlashModeYesFlash mode. If the input parameter is null or undefined, it is treated as 0 and the flash is turned off.

Return value

TypeDescription
booleanCheck result for the support of the flash mode. true if supported, false otherwise. If the operation fails, undefined is returned and an error code defined in CameraErrorCode is thrown.

Error codes

For details about the error codes, see Camera Error Codes.

IDError Message
7400103Session not config, only throw in session usage.

Example

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) {
    // If the operation fails, error.code is returned and processed.
    let err = error as BusinessError;
    console.error(`The isFlashModeSupported call failed. error code: ${err.code}`);
  }
  return status;
}

你可能感兴趣的鸿蒙文章

openharmony 鸿蒙 capi-oh-camera-capturesession-callbacks

openharmony 鸿蒙 arkts-apis-camera-OIS

openharmony 鸿蒙 capi-oh-camera-camera-devicequeryinfo

openharmony 鸿蒙 capi-oh-camera-camera-frameraterange

openharmony 鸿蒙 capi-oh-camera-camera-outputcapability

openharmony 鸿蒙 arkts-apis-camera-Photo

openharmony 鸿蒙 capi-oh-camera-camera-profile

openharmony 鸿蒙 capi-oh-camera-camera-manager

openharmony 鸿蒙 capi-oh-camera-previewoutput-callbacks

openharmony 鸿蒙 arkts-apis-camera-ManualExposureQuery

  • 所属分类: 后端技术
  • 本文标签: 软件 鸿蒙
  • 版权声明: 本文链接 https://seaxiang.com/blog/XqopBSCN