1# Interface (FlashQuery) 2<!--Kit: Camera Kit--> 3<!--Subsystem: Multimedia--> 4<!--Owner: @qano--> 5<!--Designer: @leo_ysl--> 6<!--Tester: @xchaosioda--> 7<!--Adviser: @zengyawen--> 8 9> **说明:** 10> 11> - 本模块首批接口从API version 10开始支持。后续版本的新增接口,采用上角标单独标记接口的起始版本。 12> - 本Interface的起始版本为API version 12。接口在API version 12发生兼容变更,保留了内层元素的起始版本信息,会出现外层元素@since版本号大于内层元素的情况,不影响接口使用。 13 14提供了查询设备的闪光灯状态和模式的能力。 15 16## 导入模块 17 18```ts 19import { camera } from '@kit.CameraKit'; 20``` 21 22## hasFlash<sup>11+</sup> 23 24hasFlash(): boolean 25 26检测是否有闪光灯,返回是否支持闪光灯。 27 28**原子化服务API:** 从API version 19开始,该接口支持在原子化服务中使用。 29 30**系统能力:** SystemCapability.Multimedia.Camera.Core 31 32**返回值:** 33 34| 类型 | 说明 | 35| ---------- | ----------------------------- | 36| boolean | 设备是否支持闪光灯。true表示支持,false表示不支持。接口调用失败会返回相应错误码,错误码类型[CameraErrorCode](arkts-apis-camera-e.md#cameraerrorcode)。 | 37 38**错误码:** 39 40以下错误码的详细介绍请参见[Camera错误码](errorcode-camera.md)。 41 42| 错误码ID | 错误信息 | 43| --------------- | --------------- | 44| 7400103 | Session not config, only throw in session usage. | 45 46**示例:** 47 48```ts 49import { BusinessError } from '@kit.BasicServicesKit'; 50 51function hasFlash(photoSession: camera.PhotoSession): boolean { 52 let status: boolean = false; 53 try { 54 status = photoSession.hasFlash(); 55 } catch (error) { 56 // 失败返回错误码error.code并处理。 57 let err = error as BusinessError; 58 console.error(`The hasFlash call failed. error code: ${err.code}`); 59 } 60 return status; 61} 62``` 63 64## isFlashModeSupported<sup>11+</sup> 65 66isFlashModeSupported(flashMode: FlashMode): boolean 67 68检测闪光灯模式是否支持。 69 70**原子化服务API:** 从API version 19开始,该接口支持在原子化服务中使用。 71 72**系统能力:** SystemCapability.Multimedia.Camera.Core 73 74**参数:** 75 76| 参数名 | 类型 | 必填 | 说明 | 77| --------- | ----------------------- | ---- | --------------------------------- | 78| flashMode | [FlashMode](arkts-apis-camera-e.md#flashmode) | 是 | 指定闪光灯模式。传参为null或者undefined,作为0处理,闪光灯关闭。 | 79 80**返回值:** 81 82| 类型 | 说明 | 83| ---------- | ----------------------------- | 84| boolean | 检测表示支持该闪光灯模式。true表示支持,false表示不支持。接口调用失败会返回相应错误码,错误码类型[CameraErrorCode](arkts-apis-camera-e.md#cameraerrorcode)。 | 85 86**错误码:** 87 88以下错误码的详细介绍请参见[Camera错误码](errorcode-camera.md)。 89 90| 错误码ID | 错误信息 | 91| --------------- | --------------- | 92| 7400103 | Session not config, only throw in session usage. | 93 94**示例:** 95 96```ts 97import { BusinessError } from '@kit.BasicServicesKit'; 98 99function isFlashModeSupported(photoSession: camera.PhotoSession): boolean { 100 let status: boolean = false; 101 try { 102 status = photoSession.isFlashModeSupported(camera.FlashMode.FLASH_MODE_AUTO); 103 } catch (error) { 104 // 失败返回错误码error.code并处理。 105 let err = error as BusinessError; 106 console.error(`The isFlashModeSupported call failed. error code: ${err.code}`); 107 } 108 return status; 109} 110``` 111