• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1# Interface (Flash)
2<!--Kit: Camera Kit-->
3<!--Subsystem: Multimedia-->
4<!--Owner: @qano-->
5<!--SE: @leo_ysl-->
6<!--TSE: @xchaosioda-->
7
8> **NOTE**
9>
10> - 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.
11> - The initial APIs of this interface are supported since API version 11.
12
13Flash inherits from [FlashQuery](arkts-apis-camera-FlashQuery.md).
14
15It provides APIs related to the flash.
16
17## Modules to Import
18
19```ts
20import { camera } from '@kit.CameraKit';
21```
22
23## setFlashMode<sup>11+</sup>
24
25setFlashMode(flashMode: FlashMode): void
26
27Sets a flash mode.
28
29Before the setting, do the following checks:
30
311. Use [hasFlash](arkts-apis-camera-FlashQuery.md#hasflash11) to check whether the camera device has flash.
322. Use [isFlashModeSupported](arkts-apis-camera-FlashQuery.md#isflashmodesupported11) to check whether the camera device supports the flash mode.
33
34**Atomic service API**: This API can be used in atomic services since API version 19.
35
36**System capability**: SystemCapability.Multimedia.Camera.Core
37
38**Parameters**
39
40| Name      | Type                    | Mandatory| Description                 |
41| --------- | ----------------------- | ---- | --------------------- |
42| flashMode | [FlashMode](arkts-apis-camera-e.md#flashmode) | Yes  | Flash mode. If the input parameter is null or undefined, it is treated as 0 and the flash is turned off.      |
43
44**Error codes**
45
46For details about the error codes, see [Camera Error Codes](errorcode-camera.md).
47
48| ID        | Error Message       |
49| --------------- | --------------- |
50| 7400103                |  Session not config.                                   |
51
52**Example**
53
54```ts
55import { BusinessError } from '@kit.BasicServicesKit';
56
57function setFlashMode(photoSession: camera.PhotoSession): void {
58  try {
59    photoSession.setFlashMode(camera.FlashMode.FLASH_MODE_AUTO);
60  } catch (error) {
61    // If the operation fails, error.code is returned and processed.
62    let err = error as BusinessError;
63    console.error(`The setFlashMode call failed. error code: ${err.code}`);
64  }
65}
66```
67
68## getFlashMode<sup>11+</sup>
69
70getFlashMode(): FlashMode
71
72Obtains the flash mode in use.
73
74**Atomic service API**: This API can be used in atomic services since API version 19.
75
76**System capability**: SystemCapability.Multimedia.Camera.Core
77
78**Return value**
79
80| Type       | Description                         |
81| ---------- | ----------------------------- |
82| [FlashMode](arkts-apis-camera-e.md#flashmode)    | Flash mode obtained. If the operation fails, an error code defined in [CameraErrorCode](arkts-apis-camera-e.md#cameraerrorcode) is returned.|
83
84**Error codes**
85
86For details about the error codes, see [Camera Error Codes](errorcode-camera.md).
87
88| ID        | Error Message       |
89| --------------- | --------------- |
90| 7400103                |  Session not config.                                   |
91
92**Example**
93
94```ts
95import { BusinessError } from '@kit.BasicServicesKit';
96
97function getFlashMode(photoSession: camera.PhotoSession): camera.FlashMode | undefined {
98  let flashMode: camera.FlashMode | undefined = undefined;
99  try {
100    flashMode = photoSession.getFlashMode();
101  } catch (error) {
102    // If the operation fails, error.code is returned and processed.
103    let err = error as BusinessError;
104    console.error(`The getFlashMode call failed.error code: ${err.code}`);
105  }
106  return flashMode;
107}
108```
109