• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1# Interface (CameraManager)
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
12CameraManager implements camera management. Before calling any API in CameraManager, you must use [getCameraManager](arkts-apis-camera-f.md#cameragetcameramanager) to obtain a CameraManager instance.
13
14## Modules to Import
15
16```ts
17import { camera } from '@kit.CameraKit';
18```
19
20## getSupportedCameras
21
22getSupportedCameras(): Array\<CameraDevice\>
23
24Obtains the supported camera devices. This API returns the result synchronously.
25
26**Atomic service API**: This API can be used in atomic services since API version 19.
27
28**System capability**: SystemCapability.Multimedia.Camera.Core
29
30**Return value**
31
32| Type                                            | Description                          |
33| ----------------------------------------------- | ---------------------------- |
34|  Array\<[CameraDevice](arkts-apis-camera-i.md#cameradevice)>            | Array of camera devices supported.                  |
35
36**Example**
37
38```ts
39import { BusinessError } from '@kit.BasicServicesKit';
40
41function getSupportedCameras(cameraManager: camera.CameraManager): Array<camera.CameraDevice> {
42  let cameras: Array<camera.CameraDevice> = [];
43  try {
44    cameras = cameraManager.getSupportedCameras();
45  } catch (error) {
46    let err = error as BusinessError;
47    console.error(`The getSupportedCameras call failed. error code: ${err.code}`);
48  }
49  return cameras;
50}
51```
52
53## getSupportedSceneModes<sup>11+</sup>
54
55getSupportedSceneModes(camera: CameraDevice): Array\<SceneMode\>
56
57Obtains the scene modes supported by a camera device. This API returns the result synchronously.
58
59**Atomic service API**: This API can be used in atomic services since API version 19.
60
61**System capability**: SystemCapability.Multimedia.Camera.Core
62
63**Parameters**
64
65| Name        | Type                                                           | Mandatory| Description                     |
66| ------------ |--------------------------------------------------------------- | -- | -------------------------- |
67| camera | [CameraDevice](arkts-apis-camera-i.md#cameradevice)                              | Yes| CameraDevice instance, which is obtained through [getSupportedCameras](#getsupportedcameras). An error code is returned if the input parameter is invalid.      |
68
69**Return value**
70
71| Type                                            | Description                          |
72| ----------------------------------------------- | ---------------------------- |
73|  Array\<[SceneMode](arkts-apis-camera-e.md#scenemode11)>            | Array of scene modes supported.                  |
74
75**Example**
76
77```ts
78import { BusinessError } from '@kit.BasicServicesKit';
79
80function getSupportedSceneModes(cameraManager: camera.CameraManager, camera: camera.CameraDevice): Array<camera.SceneMode> {
81  let modes: Array<camera.SceneMode> = [];
82  try {
83    modes = cameraManager.getSupportedSceneModes(camera);
84  } catch (error) {
85    let err = error as BusinessError;
86    console.error(`The getSupportedSceneModes call failed. error code: ${err.code}`);
87  }
88  return modes;
89}
90```
91
92## getSupportedOutputCapability<sup>11+</sup>
93
94getSupportedOutputCapability(camera: CameraDevice, mode: SceneMode): CameraOutputCapability
95
96Obtains the output capability supported by a camera device in a given scene mode. This API returns the result synchronously.
97
98**Atomic service API**: This API can be used in atomic services since API version 19.
99
100**System capability**: SystemCapability.Multimedia.Camera.Core
101
102**Parameters**
103
104| Name        | Type                                                           | Mandatory| Description                     |
105| ------------ |--------------------------------------------------------------- | -- | -------------------------- |
106| camera | [CameraDevice](arkts-apis-camera-i.md#cameradevice)                              | Yes| CameraDevice instance, which is obtained through [getSupportedCameras](#getsupportedcameras).      |
107| mode | [SceneMode](arkts-apis-camera-e.md#scenemode11)                              | Yes| Scene mode, which is obtained through [getSupportedSceneModes](#getsupportedscenemodes11).      |
108
109**Return value**
110
111| Type                                            | Description                          |
112| ----------------------------------------------- | ---------------------------- |
113| [CameraOutputCapability](arkts-apis-camera-i.md#cameraoutputcapability)            | Camera output capability obtained.                  |
114
115**Example**
116
117```ts
118function getSupportedOutputCapability(camera: camera.CameraDevice, cameraManager: camera.CameraManager, sceneMode: camera.SceneMode): camera.CameraOutputCapability {
119  let cameraOutputCapability: camera.CameraOutputCapability = cameraManager.getSupportedOutputCapability(camera, sceneMode);
120  return cameraOutputCapability;
121}
122```
123
124## isCameraMuted
125
126isCameraMuted(): boolean
127
128Checks whether this camera is muted.
129
130**Atomic service API**: This API can be used in atomic services since API version 19.
131
132**System capability**: SystemCapability.Multimedia.Camera.Core
133
134**Return value**
135
136| Type       | Description                                        |
137| ---------- | -------------------------------------------- |
138| boolean    | Check result. The value **true** means that the camera device is muted, and **false** means the opposite.|
139
140**Example**
141
142```ts
143function isCameraMuted(cameraManager: camera.CameraManager): boolean {
144  let isMuted: boolean = cameraManager.isCameraMuted();
145  return isMuted;
146}
147```
148
149## createCameraInput
150
151createCameraInput(camera: CameraDevice): CameraInput
152
153Creates a CameraInput instance with the specified CameraDevice instance. This API returns the result synchronously.
154
155Before calling this API, call [getSupportedCameras](#getsupportedcameras) to obtain the list of supported camera devices, select the camera device that meets the requirements based on the actual usage scenario, and then create the CameraInput instance.
156
157**Required permissions**: ohos.permission.CAMERA
158
159**Atomic service API**: This API can be used in atomic services since API version 19.
160
161**System capability**: SystemCapability.Multimedia.Camera.Core
162
163**Parameters**
164
165| Name    | Type                                        | Mandatory| Description                                              |
166| -------- | ------------------------------------------- | ---- |--------------------------------------------------|
167| camera  | [CameraDevice](arkts-apis-camera-i.md#cameradevice)         | Yes  | CameraDevice instance, which is obtained through [getSupportedCameras](#getsupportedcameras).|
168
169**Return value**
170
171| Type       | Description                         |
172| ---------- | ----------------------------- |
173| [CameraInput](arkts-apis-camera-CameraInput.md)    | CameraInput instance created. If the operation fails, an error code defined in [CameraErrorCode](arkts-apis-camera-e.md#cameraerrorcode) is returned.|
174
175**Error codes**
176
177For details about the error codes, see [Camera Error Codes](errorcode-camera.md).
178
179| ID        | Error Message       |
180| --------------- | --------------- |
181| 7400101                |  Parameter missing or parameter type incorrect.               |
182| 7400102                |  Operation not allowed.               |
183| 7400201                |  Camera service fatal error.               |
184
185**Example**
186
187```ts
188import { BusinessError } from '@kit.BasicServicesKit';
189
190function createCameraInput(camera: camera.CameraDevice, cameraManager: camera.CameraManager): camera.CameraInput | undefined {
191  let cameraInput: camera.CameraInput | undefined = undefined;
192  try {
193    cameraInput = cameraManager.createCameraInput(camera);
194  } catch (error) {
195    // If the operation fails, error.code is returned and processed.
196    let err = error as BusinessError;
197    console.error(`The createCameraInput call failed. error code: ${err.code}`);
198  }
199  return cameraInput;
200}
201```
202
203## createCameraInput
204
205createCameraInput(position: CameraPosition, type: CameraType): CameraInput
206
207Creates a CameraInput instance with the specified camera position and type. This API returns the result synchronously.
208
209Before calling this API, specify the camera position and type based on the usage scenario. For example, open the front camera for the selfie feature
210
211**Required permissions**: ohos.permission.CAMERA
212
213**Atomic service API**: This API can be used in atomic services since API version 19.
214
215**System capability**: SystemCapability.Multimedia.Camera.Core
216
217**Parameters**
218
219| Name    | Type                                       | Mandatory| Description                               |
220| -------- | ------------------------------------------- | ---- | --------------------------------- |
221| position | [CameraPosition](arkts-apis-camera-e.md#cameraposition)           | Yes  | Camera position. You need to obtain the supported camera object by calling [getSupportedCameras](#getsupportedcameras) and then obtain the device position information based on the returned camera object. |
222| type     | [CameraType](arkts-apis-camera-e.md#cameratype)                   | Yes  | Camera type. You need to obtain the supported camera object by calling [getSupportedCameras](#getsupportedcameras) and then obtain the camera type based on the returned camera object.|
223
224**Return value**
225
226| Type       | Description                         |
227| ---------- | ----------------------------- |
228| [CameraInput](arkts-apis-camera-CameraInput.md)    | CameraInput instance created. If the operation fails, an error code defined in [CameraErrorCode](arkts-apis-camera-e.md#cameraerrorcode) is returned.|
229
230**Error codes**
231
232For details about the error codes, see [Camera Error Codes](errorcode-camera.md).
233
234| ID        | Error Message       |
235| --------------- | --------------- |
236| 7400101                |  Parameter missing or parameter type incorrect.               |
237| 7400102                |  Operation not allowed.               |
238| 7400201                |  Camera service fatal error.               |
239
240**Example**
241
242```ts
243import { BusinessError } from '@kit.BasicServicesKit';
244
245function createCameraInput(camera: camera.CameraDevice, cameraManager: camera.CameraManager): camera.CameraInput | undefined {
246  let position: camera.CameraPosition = camera.cameraPosition;
247  let type: camera.CameraType = camera.cameraType;
248  let cameraInput: camera.CameraInput | undefined = undefined;
249  try {
250    cameraInput = cameraManager.createCameraInput(position, type);
251  } catch (error) {
252    // If the operation fails, error.code is returned and processed.
253    let err = error as BusinessError;
254    console.error(`The createCameraInput call failed. error code: ${err.code}`);
255  }
256  return cameraInput;
257}
258```
259
260## createPreviewOutput
261
262createPreviewOutput(profile: Profile, surfaceId: string): PreviewOutput
263
264Creates a PreviewOutput instance. This API returns the result synchronously.
265
266**Atomic service API**: This API can be used in atomic services since API version 19.
267
268**System capability**: SystemCapability.Multimedia.Camera.Core
269
270**Parameters**
271
272| Name    | Type                                            | Mandatory| Description                             |
273| -------- | ----------------------------------------------- | ---- | ------------------------------- |
274| profile  | [Profile](arkts-apis-camera-i.md#profile)                             | Yes  | Supported preview profile, which is obtained through [getSupportedOutputCapability](#getsupportedoutputcapability11).|
275| surfaceId| string | Yes  | Surface ID, which is obtained from [XComponent](../apis-arkui/arkui-ts/ts-basic-components-xcomponent.md) or [ImageReceiver](../apis-image-kit/arkts-apis-image-ImageReceiver.md).|
276
277**Return value**
278
279| Type       | Description                         |
280| ---------- | ----------------------------- |
281| [PreviewOutput](arkts-apis-camera-PreviewOutput.md)  | PreviewOutput instance created. If the operation fails, an error code defined in [CameraErrorCode](arkts-apis-camera-e.md#cameraerrorcode) is returned.|
282
283**Error codes**
284
285For details about the error codes, see [Camera Error Codes](errorcode-camera.md).
286
287| ID        | Error Message       |
288| --------------- | --------------- |
289| 7400101                |  Parameter missing or parameter type incorrect.               |
290| 7400201                |  Camera service fatal error.               |
291
292**Example**
293
294```ts
295import { BusinessError } from '@kit.BasicServicesKit';
296
297function createPreviewOutput(cameraOutputCapability: camera.CameraOutputCapability, cameraManager: camera.CameraManager, surfaceId: string): camera.PreviewOutput | undefined {
298  let profile: camera.Profile = cameraOutputCapability.previewProfiles[0];
299  let previewOutput: camera.PreviewOutput | undefined = undefined;
300  try {
301    previewOutput = cameraManager.createPreviewOutput(profile, surfaceId);
302  } catch (error) {
303    // If the operation fails, error.code is returned and processed.
304    let err = error as BusinessError;
305    console.error(`The createPreviewOutput call failed. error code: ${err.code}`);
306  }
307  return previewOutput;
308}
309```
310
311## createPreviewOutput<sup>12+</sup>
312
313createPreviewOutput(surfaceId: string): PreviewOutput
314
315Creates a PreviewOutput instance without configuration. This API returns the result synchronously. It must be used with [preconfig](arkts-apis-camera-PhotoSession.md#preconfig12).
316
317**Atomic service API**: This API can be used in atomic services since API version 19.
318
319**System capability**: SystemCapability.Multimedia.Camera.Core
320
321**Parameters**
322
323| Name    | Type                                            | Mandatory| Description                             |
324| -------- | ----------------------------------------------- | ---- | ------------------------------- |
325| surfaceId| string | Yes  | Surface ID, which is obtained from [XComponent](../apis-arkui/arkui-ts/ts-basic-components-xcomponent.md) or [ImageReceiver](../apis-image-kit/arkts-apis-image-ImageReceiver.md).|
326
327**Return value**
328
329| Type       | Description                         |
330| ---------- | ----------------------------- |
331| [PreviewOutput](arkts-apis-camera-PreviewOutput.md)    | PreviewOutput instance created. If the operation fails, an error code defined in [CameraErrorCode](arkts-apis-camera-e.md#cameraerrorcode) is returned.|
332
333**Error codes**
334
335For details about the error codes, see [Camera Error Codes](errorcode-camera.md).
336
337| ID  | Error Message                                          |
338|---------|------------------------------------------------|
339| 7400101 | Parameter missing or parameter type incorrect. |
340| 7400201 | Camera service fatal error.                    |
341
342**Example**
343
344```ts
345import { BusinessError } from '@kit.BasicServicesKit';
346
347function createPreviewOutput(cameraManager: camera.CameraManager, surfaceId: string): camera.PreviewOutput | undefined {
348  let previewOutput: camera.PreviewOutput | undefined = undefined;
349  try {
350    previewOutput = cameraManager.createPreviewOutput(surfaceId);
351  } catch (error) {
352    // If the operation fails, error.code is returned and processed.
353    let err = error as BusinessError;
354    console.error(`The createPreviewOutput call failed. error code: ${err.code}`);
355  }
356  return previewOutput;
357}
358```
359
360## createPhotoOutput<sup>11+</sup>
361
362createPhotoOutput(profile?: Profile): PhotoOutput
363
364Creates a PhotoOutput instance. This API returns the result synchronously.
365
366**Atomic service API**: This API can be used in atomic services since API version 19.
367
368**System capability**: SystemCapability.Multimedia.Camera.Core
369
370**Parameters**
371
372| Name    | Type                                        | Mandatory| Description                                 |
373| -------- | ------------------------------------------- |----| ----------------------------------- |
374| profile  | [Profile](arkts-apis-camera-i.md#profile)                         | No | Supported photo profile, which is obtained through [getSupportedOutputCapability](#getsupportedoutputcapability11).<br>In API version 11, this parameter is mandatory. Since API version 12, it will overwrite the preconfigured parameters passed in through [preconfig](arkts-apis-camera-PhotoSession.md#preconfig12).|
375
376**Return value**
377
378| Type       | Description                         |
379| ---------- | ----------------------------- |
380| [PhotoOutput](arkts-apis-camera-PhotoOutput.md)   | PhotoOutput instance created. If the operation fails, an error code defined in [CameraErrorCode](arkts-apis-camera-e.md#cameraerrorcode) is returned.|
381
382**Error codes**
383
384For details about the error codes, see [Camera Error Codes](errorcode-camera.md).
385
386| ID   | Error Message                                          |
387|----------|------------------------------------------------|
388| 7400101  | Parameter missing or parameter type incorrect. |
389| 7400201  | Camera service fatal error.                    |
390
391**Example**
392
393```ts
394import { BusinessError } from '@kit.BasicServicesKit';
395
396function createPhotoOutput(cameraOutputCapability: camera.CameraOutputCapability, cameraManager: camera.CameraManager): camera.PhotoOutput | undefined {
397  let profile: camera.Profile = cameraOutputCapability.photoProfiles[0];
398  let photoOutput: camera.PhotoOutput | undefined = undefined;
399  try {
400    photoOutput = cameraManager.createPhotoOutput(profile);
401  } catch (error) {
402    // If the operation fails, error.code is returned and processed.
403    let err = error as BusinessError;
404    console.error(`The createPhotoOutput call failed. error code: ${err.code}`);
405  }
406  return photoOutput;
407}
408```
409
410## createVideoOutput
411
412createVideoOutput(profile: VideoProfile, surfaceId: string): VideoOutput
413
414Creates a VideoOutput instance. This API returns the result synchronously.
415
416**Atomic service API**: This API can be used in atomic services since API version 19.
417
418**System capability**: SystemCapability.Multimedia.Camera.Core
419
420**Parameters**
421
422| Name    | Type                                       | Mandatory| Description                             |
423| -------- | ------------------------------------------- | ---- | ------------------------------ |
424| profile  | [VideoProfile](arkts-apis-camera-i.md#videoprofile)               | Yes  | Supported video profile, which is obtained through [getSupportedOutputCapability](#getsupportedoutputcapability11).|
425| surfaceId| string          | Yes  | Surface ID, which is obtained from [AVRecorder](../apis-media-kit/arkts-apis-media-AVRecorder.md).|
426
427**Return value**
428
429| Type       | Description                         |
430| ---------- | ----------------------------- |
431| [VideoOutput](arkts-apis-camera-VideoOutput.md)   | VideoOutput instance created. If the operation fails, an error code defined in [CameraErrorCode](arkts-apis-camera-e.md#cameraerrorcode) is returned.|
432
433**Error codes**
434
435For details about the error codes, see [Camera Error Codes](errorcode-camera.md).
436
437| ID        | Error Message       |
438| --------------- | --------------- |
439| 7400101                |  Parameter missing or parameter type incorrect.               |
440| 7400201                |  Camera service fatal error.               |
441
442**Example**
443
444```ts
445import { BusinessError } from '@kit.BasicServicesKit';
446
447function createVideoOutput(cameraOutputCapability: camera.CameraOutputCapability, cameraManager: camera.CameraManager, surfaceId: string): camera.VideoOutput | undefined {
448  let profile: camera.VideoProfile = cameraOutputCapability.videoProfiles[0];
449  let videoOutput: camera.VideoOutput | undefined = undefined;
450  try {
451    videoOutput = cameraManager.createVideoOutput(profile, surfaceId);
452  } catch (error) {
453    // If the operation fails, error.code is returned and processed.
454    let err = error as BusinessError;
455    console.error(`The createVideoOutput call failed. error code: ${err.code}`);
456  }
457  return videoOutput;
458}
459```
460
461## createVideoOutput<sup>12+</sup>
462
463createVideoOutput(surfaceId: string): VideoOutput
464
465Creates a VideoOutput instance without configuration. This API returns the result synchronously. It must be used with [preconfig](arkts-apis-camera-VideoSession.md#preconfig12).
466
467**Atomic service API**: This API can be used in atomic services since API version 19.
468
469**System capability**: SystemCapability.Multimedia.Camera.Core
470
471**Parameters**
472
473| Name      | Type    | Mandatory   | Description                                                                        |
474|-----------|--------|-------|----------------------------------------------------------------------------|
475| surfaceId | string | Yes    | Surface ID, which is obtained from [AVRecorder](../apis-media-kit/arkts-apis-media-AVRecorder.md).|
476
477**Return value**
478
479| Type       | Description                         |
480| ---------- | ----------------------------- |
481| [VideoOutput](arkts-apis-camera-VideoOutput.md)   | VideoOutput instance created. If the operation fails, an error code defined in [CameraErrorCode](arkts-apis-camera-e.md#cameraerrorcode) is returned.|
482
483**Error codes**
484
485For details about the error codes, see [Camera Error Codes](errorcode-camera.md).
486
487| ID   | Error Message                                          |
488|----------|------------------------------------------------|
489| 7400101  | Parameter missing or parameter type incorrect. |
490| 7400201  | Camera service fatal error.                    |
491
492**Example**
493
494```ts
495import { BusinessError } from '@kit.BasicServicesKit';
496
497function createVideoOutput(cameraManager: camera.CameraManager, surfaceId: string): camera.VideoOutput | undefined {
498  let videoOutput: camera.VideoOutput | undefined = undefined;
499  try {
500    videoOutput = cameraManager.createVideoOutput(surfaceId);
501  } catch (error) {
502    // If the operation fails, error.code is returned and processed.
503    let err = error as BusinessError;
504    console.error(`The createVideoOutput call failed. error code: ${err.code}`);
505  }
506  return videoOutput;
507}
508```
509
510## createMetadataOutput
511
512createMetadataOutput(metadataObjectTypes: Array\<MetadataObjectType\>): MetadataOutput
513
514Creates a MetadataOutput instance. This API returns the result synchronously.
515
516**Atomic service API**: This API can be used in atomic services since API version 19.
517
518**System capability**: SystemCapability.Multimedia.Camera.Core
519
520**Parameters**
521
522| Name                 | Type                                              | Mandatory| Description                         |
523| -------------------- | -------------------------------------------------- | --- | ---------------------------- |
524| metadataObjectTypes  | Array\<[MetadataObjectType](arkts-apis-camera-e.md#metadataobjecttype)\>  | Yes | Metadata object types, which are obtained through [getSupportedOutputCapability](#getsupportedoutputcapability11).|
525
526**Return value**
527
528| Type       | Description                         |
529| ---------- | ----------------------------- |
530| [MetadataOutput](arkts-apis-camera-MetadataOutput.md)   | MetadataOutput instance created. If the operation fails, an error code defined in [CameraErrorCode](arkts-apis-camera-e.md#cameraerrorcode) is returned.|
531
532**Error codes**
533
534For details about the error codes, see [Camera Error Codes](errorcode-camera.md).
535
536| ID        | Error Message       |
537| --------------- | --------------- |
538| 7400101                |  Parameter missing or parameter type incorrect.               |
539| 7400201                |  Camera service fatal error.               |
540
541**Example**
542
543```ts
544import { BusinessError } from '@kit.BasicServicesKit';
545
546function createMetadataOutput(cameraManager: camera.CameraManager, cameraOutputCapability: camera.CameraOutputCapability): void {
547  let metadataObjectTypes: Array<camera.MetadataObjectType> = cameraOutputCapability.supportedMetadataObjectTypes;
548  let metadataOutput: camera.MetadataOutput | undefined = undefined;
549  try {
550    metadataOutput = cameraManager.createMetadataOutput(metadataObjectTypes);
551  } catch (error) {
552    // If the operation fails, error.code is returned and processed.
553    let err = error as BusinessError;
554    console.error(`createMetadataOutput error. error code: ${err.code}`);
555  }
556}
557```
558
559## createSession<sup>11+</sup>
560
561createSession\<T extends Session\>(mode: SceneMode): T
562
563Creates a Session instance with a given scene mode. This API returns the result synchronously.
564
565**Atomic service API**: This API can be used in atomic services since API version 19.
566
567**System capability**: SystemCapability.Multimedia.Camera.Core
568
569**Parameters**
570
571| Name  | Type             | Mandatory| Description      |
572| -------- | -----------------| ---- | --------- |
573| mode     | [SceneMode](arkts-apis-camera-e.md#scenemode11)     | Yes  | Scene mode. The API does not take effect if the input parameter is invalid (for example, the value is out of range, null, or undefined).|
574
575**Return value**
576
577| Type       | Description                         |
578| ---------- | ----------------------------- |
579| [T extends Session](arkts-apis-camera-Session.md)   | Session instance created. If the operation fails, an error code defined in [CameraErrorCode](arkts-apis-camera-e.md#cameraerrorcode) is returned.|
580
581**Error codes**
582
583For details about the error codes, see [Camera Error Codes](errorcode-camera.md).
584
585| ID  | Error Message                                                                                                                                          |
586|---------|------------------------------------------------------------------------------------------------------------------------------------------------|
587| 7400101 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types; 3.Parameter verification failed. |
588| 7400201 | Camera service fatal error.                                                                                                                    |
589
590**Example**
591
592```ts
593import { BusinessError } from '@kit.BasicServicesKit';
594
595function createSession(cameraManager: camera.CameraManager, mode: camera.SceneMode): camera.Session | undefined {
596  let photoSession: camera.PhotoSession | undefined = undefined;
597  try {
598    photoSession = cameraManager.createSession(mode) as camera.PhotoSession;
599  } catch (error) {
600    // If the operation fails, error.code is returned and processed.
601    let err = error as BusinessError;
602    console.error(`createCaptureSession error. error code: ${err.code}`);
603  }
604  return photoSession;
605}
606```
607
608## on('cameraStatus')
609
610on(type: 'cameraStatus', callback: AsyncCallback\<CameraStatusInfo\>): void
611
612Subscribes to camera status events. This API uses an asynchronous callback to return the result.
613
614> **NOTE**
615>
616> Currently, you cannot use **off()** to unregister the callback in the callback method of **on()**.
617
618**Atomic service API**: This API can be used in atomic services since API version 19.
619
620**System capability**: SystemCapability.Multimedia.Camera.Core
621
622**Parameters**
623
624| Name    | Type           | Mandatory| Description      |
625| -------- | -----------------| ---- | --------- |
626| type     | string           | Yes  | Event type. The value is fixed at **'cameraStatus'**. The event can be listened for when a CameraManager instance is obtained. This event is triggered and the corresponding information is returned only when the camera device is enabled or disabled.|
627| callback | AsyncCallback\<[CameraStatusInfo](arkts-apis-camera-i.md#camerastatusinfo)\> | Yes  | Callback used to return the camera status change.|
628
629**Example**
630
631```ts
632import { BusinessError } from '@kit.BasicServicesKit';
633
634function callback(err: BusinessError, cameraStatusInfo: camera.CameraStatusInfo): void {
635  if (err !== undefined && err.code !== 0) {
636    console.error('cameraStatus with errorCode = ' + err.code);
637    return;
638  }
639  console.info(`camera : ${cameraStatusInfo.camera.cameraId}`);
640  console.info(`status: ${cameraStatusInfo.status}`);
641}
642
643function registerCameraStatus(cameraManager: camera.CameraManager): void {
644  cameraManager.on('cameraStatus', callback);
645}
646```
647
648## off('cameraStatus')
649
650off(type: 'cameraStatus', callback?: AsyncCallback\<CameraStatusInfo\>): void
651
652Unsubscribes from camera status events. This API uses an asynchronous callback to return the result.
653
654**Atomic service API**: This API can be used in atomic services since API version 19.
655
656**System capability**: SystemCapability.Multimedia.Camera.Core
657
658**Parameters**
659
660| Name    | Type           | Mandatory| Description      |
661| -------- | -----------------| ---- | --------- |
662| type     | string           | Yes  | Event type. The value is fixed at **'cameraStatus'**. The event can be listened for when a CameraManager instance is obtained.|
663| callback | AsyncCallback\<[CameraStatusInfo](arkts-apis-camera-i.md#camerastatusinfo)\> | No  | Callback used to return the result. If this parameter is specified, the subscription to the specified event with the specified callback is canceled. (The callback object cannot be an anonymous function.) Otherwise, the subscriptions to the specified event with all the callbacks are canceled.|
664
665**Example**
666
667```ts
668function unregisterCameraStatus(cameraManager: camera.CameraManager): void {
669  cameraManager.off('cameraStatus');
670}
671```
672
673## on('foldStatusChange')<sup>12+</sup>
674
675on(type: 'foldStatusChange', callback: AsyncCallback\<FoldStatusInfo\>): void
676
677Subscribes to fold status change events of the foldable device. This API uses an asynchronous callback to return the result.
678
679> **NOTE**
680>
681> Currently, you cannot use **off()** to unregister the callback in the callback method of **on()**.
682
683**Atomic service API**: This API can be used in atomic services since API version 19.
684
685**System capability**: SystemCapability.Multimedia.Camera.Core
686
687**Parameters**
688
689| Name    | Type           | Mandatory| Description      |
690| -------- | -----------------| ---- | --------- |
691| type     | string           | Yes  | Event type. The value is fixed at **'foldStatusChange'**. The event is triggered when the fold state of the foldable device changes.|
692| callback | AsyncCallback\<[FoldStatusInfo](arkts-apis-camera-i.md#foldstatusinfo12)\> | Yes  | Callback used to return the fold state information about the foldable device.|
693
694**Example**
695
696```ts
697import { BusinessError } from '@kit.BasicServicesKit';
698
699function callback(err: BusinessError, foldStatusInfo: camera.FoldStatusInfo): void {
700  if (err !== undefined && err.code !== 0) {
701    console.error('foldStatusChange with errorCode = ' + err.code);
702    return;
703  }
704  console.info(`camera length: ${foldStatusInfo.supportedCameras.length}`);
705  console.info(`foldStatus: ${foldStatusInfo.foldStatus}`);
706}
707
708function registerFoldStatusChange(cameraManager: camera.CameraManager): void {
709  cameraManager.on('foldStatusChange', callback);
710}
711```
712
713## off('foldStatusChange')<sup>12+</sup>
714
715off(type: 'foldStatusChange', callback?: AsyncCallback\<FoldStatusInfo\>): void
716
717Unsubscribes from fold state change events of the foldable device.
718
719**Atomic service API**: This API can be used in atomic services since API version 19.
720
721**System capability**: SystemCapability.Multimedia.Camera.Core
722
723**Parameters**
724
725| Name    | Type           | Mandatory| Description      |
726| -------- | -----------------| ---- | --------- |
727| type     | string           | Yes  | Event type. The value is fixed at **'foldStatusChange'**. The event is triggered when the fold state of the foldable device changes.|
728| callback | AsyncCallback\<[FoldStatusInfo](arkts-apis-camera-i.md#foldstatusinfo12)\> | No  | Callback used to return the fold state information about the foldable device. If this parameter is specified, the subscription to the specified event with the specified callback is canceled. (The callback object cannot be an anonymous function.) Otherwise, the subscriptions to the specified event with all the callbacks are canceled.|
729
730**Example**
731
732```ts
733function unregisterFoldStatusChange(cameraManager: camera.CameraManager): void {
734  cameraManager.off('foldStatusChange');
735}
736```
737
738## isTorchSupported<sup>11+</sup>
739
740isTorchSupported(): boolean
741
742Checks whether the camera device supports the flashlight.
743
744**Atomic service API**: This API can be used in atomic services since API version 19.
745
746**System capability**: SystemCapability.Multimedia.Camera.Core
747
748**Return value**
749
750| Type       | Description                         |
751| ---------- | ----------------------------- |
752| boolean    | Check result for the support of the flashlight. **true** if supported, **false** otherwise.|
753
754**Example**
755
756```ts
757function isTorchSupported(cameraManager: camera.CameraManager): boolean {
758  let isSupported = cameraManager.isTorchSupported();
759  return isSupported;
760}
761```
762
763## isTorchModeSupported<sup>11+</sup>
764
765isTorchModeSupported(mode: TorchMode): boolean
766
767Checks whether a flashlight mode is supported.
768
769**Atomic service API**: This API can be used in atomic services since API version 19.
770
771**System capability**: SystemCapability.Multimedia.Camera.Core
772
773**Parameters**
774
775| Name    | Type            | Mandatory| Description      |
776| -------- | --------------- | ---- | --------- |
777| mode | [TorchMode](arkts-apis-camera-e.md#torchmode11) | Yes| Flashlight mode. If the input parameter is null or undefined, it is treated as 0 and the flashlight is turned off.|
778
779**Return value**
780
781| Type       | Description                         |
782| ---------- | ----------------------------- |
783| boolean    | Check result for the support of the flashlight mode. **true** if supported, **false** otherwise.|
784
785**Example**
786
787```ts
788function isTorchModeSupported(cameraManager: camera.CameraManager, torchMode: camera.TorchMode): boolean {
789  let isSupported = cameraManager.isTorchModeSupported(torchMode);
790  return isSupported;
791}
792```
793
794## getTorchMode<sup>11+</sup>
795
796getTorchMode(): TorchMode
797
798Obtains the flashlight mode of this camera device.
799
800**Atomic service API**: This API can be used in atomic services since API version 19.
801
802**System capability**: SystemCapability.Multimedia.Camera.Core
803
804**Return value**
805
806| Type       | Description                         |
807| ---------- | ----------------------------- |
808| [TorchMode](arkts-apis-camera-e.md#torchmode11)    | Flashlight mode.|
809
810**Example**
811
812```ts
813function getTorchMode(cameraManager: camera.CameraManager): camera.TorchMode | undefined {
814  let torchMode: camera.TorchMode | undefined = undefined;
815  torchMode = cameraManager.getTorchMode();
816  return torchMode;
817}
818```
819
820## setTorchMode<sup>11+</sup>
821
822setTorchMode(mode: TorchMode): void
823
824Sets the flashlight mode.
825
826**Atomic service API**: This API can be used in atomic services since API version 19.
827
828**System capability**: SystemCapability.Multimedia.Camera.Core
829
830**Parameters**
831
832| Name    | Type            | Mandatory| Description      |
833| -------- | --------------- | ---- | --------- |
834| mode | [TorchMode](arkts-apis-camera-e.md#torchmode11) | Yes| Flashlight mode. If the input parameter is null or undefined, it is treated as 0 and the flashlight is turned off.|
835
836**Error codes**
837
838For details about the error codes, see [Camera Error Codes](errorcode-camera.md).
839
840| ID        | Error Message       |
841| --------------- | --------------- |
842| 7400102 | Operation not allowed. |
843| 7400201 | Camera service fatal error. |
844
845**Example**
846
847```ts
848import { BusinessError } from '@kit.BasicServicesKit';
849
850function setTorchMode(cameraManager: camera.CameraManager, torchMode: camera.TorchMode): void {
851  try {
852    cameraManager.setTorchMode(torchMode);
853  } catch (error) {
854    // If the operation fails, error.code is returned and processed.
855    let err = error as BusinessError;
856    console.error(`The setTorchMode call failed. error code: ${err.code}`);
857  }
858}
859```
860
861## on('torchStatusChange')<sup>11+</sup>
862
863on(type: 'torchStatusChange', callback: AsyncCallback\<TorchStatusInfo\>): void
864
865Subscribes to flashlight status change events. This API uses an asynchronous callback to return the result.
866
867> **NOTE**
868>
869> Currently, you cannot use **off()** to unregister the callback in the callback method of **on()**.
870
871**Atomic service API**: This API can be used in atomic services since API version 19.
872
873**System capability**: SystemCapability.Multimedia.Camera.Core
874
875**Parameters**
876
877| Name    | Type            | Mandatory| Description      |
878| -------- | --------------- | ---- | --------- |
879| type     | string          | Yes  | Event type. The value is fixed at **'torchStatusChange'**. The event can be listened for when a CameraManager instance is obtained. Currently, this event is triggered only in the following scenarios: The flashlight is turned on or turned off, or becomes unavailable or available.|
880| callback | AsyncCallback\<TorchStatusInfo> | Yes  | Callback used to return the flashlight status.              |
881
882**Example**
883
884```ts
885import { BusinessError } from '@kit.BasicServicesKit';
886
887function callback(err: BusinessError, torchStatusInfo: camera.TorchStatusInfo): void {
888  if (err !== undefined && err.code !== 0) {
889    console.error(`Callback Error, errorCode: ${err.code}`);
890    return;
891  }
892  console.info(`onTorchStatusChange, isTorchAvailable: ${torchStatusInfo.isTorchAvailable}, isTorchActive: ${torchStatusInfo.isTorchActive}, level: ${torchStatusInfo.torchLevel}`);
893}
894
895function registerTorchStatusChange(cameraManager: camera.CameraManager): void {
896  cameraManager.on('torchStatusChange', callback);
897}
898```
899
900## off('torchStatusChange')<sup>11+</sup>
901
902off(type: 'torchStatusChange', callback?: AsyncCallback\<TorchStatusInfo\>): void
903
904Unsubscribes from flashlight status change events. This API uses an asynchronous callback to return the result.
905
906**Atomic service API**: This API can be used in atomic services since API version 19.
907
908**System capability**: SystemCapability.Multimedia.Camera.Core
909
910**Parameters**
911
912| Name    | Type            | Mandatory| Description      |
913| -------- | --------------- | ---- | --------- |
914| type     | string          | Yes  | Event type. The value is fixed at **'torchStatusChange'**. The event can be listened for when a CameraManager instance is obtained.|
915| callback | AsyncCallback\<TorchStatusInfo> | No  | Callback used to return the result. If this parameter is specified, the subscription to the specified event with the specified callback is canceled. (The callback object cannot be an anonymous function.) Otherwise, the subscriptions to the specified event with all the callbacks are canceled.|
916
917**Example**
918
919```ts
920function unregisterTorchStatusChange(cameraManager: camera.CameraManager): void {
921  cameraManager.off('torchStatusChange');
922}
923```
924
925## getCameraDevice<sup>18+</sup>
926
927getCameraDevice(position:CameraPosition, type: CameraType): CameraDevice
928
929Obtains the specified camera based on the camera position and type.
930
931**Atomic service API**: This API can be used in atomic services since API version 19.
932
933**System capability**: SystemCapability.Multimedia.Camera.Core
934
935**Parameters**
936
937| Name    | Type            | Mandatory| Description      |
938| -------- | --------------- | ---- | --------- |
939| position | [CameraPosition](arkts-apis-camera-e.md#cameraposition)   | Yes  | Camera position.|
940| type     | [CameraType](arkts-apis-camera-e.md#cameratype)   | Yes  | Camera type.|
941
942**Return value**
943
944| Type            | Description                    |
945| -----------------| ------------------------ |
946|  [CameraDevice](arkts-apis-camera-i.md#cameradevice)     | Camera obtained.     |
947
948**Error codes**
949
950For details about the error codes, see [Universal Error Codes](../errorcode-universal.md) and [Camera Error Codes](errorcode-camera.md).
951
952| ID        | Error Message       |
953| --------------- | --------------- |
954| 7400201 | Camera service fatal error. |
955
956**Example**
957
958```ts
959import { camera } from '@kit.CameraKit';
960import { BusinessError } from '@kit.BasicServicesKit';
961
962function getCameraDevice(cameraManager: camera.CameraManager, position: camera.CameraPosition, type: camera.CameraType): void {
963  try {
964    let curCameraDev: camera.CameraDevice | undefined = undefined;
965    curCameraDev = cameraManager.getCameraDevice(position, type);
966  } catch (error) {
967    // If the operation fails, an error code is returned and processed.
968    let err = error as BusinessError;
969    console.error(`The getCameraDevice call failed. error code: ${err.code}`);
970  }
971}
972```
973
974## getCameraConcurrentInfos<sup>18+</sup>
975
976getCameraConcurrentInfos(cameras: Array\<CameraDevice\>): Array\<CameraConcurrentInfo\>
977
978Obtains the concurrency information of the specified cameras. If the return value is an empty array, concurrency is not supported.
979
980**Atomic service API**: This API can be used in atomic services since API version 19.
981
982**System capability**: SystemCapability.Multimedia.Camera.Core
983
984**Parameters**
985
986| Name    | Type            | Mandatory| Description      |
987| -------- | --------------- | ---- | --------- |
988| cameras | Array\<[CameraDevice](arkts-apis-camera-i.md#cameradevice)\>  | Yes  | Array of CameraDevice objects. You are advised to use the front and rear cameras obtained by calling [getCameraDevice](#getcameradevice18).|
989
990**Return value**
991
992| Type            | Description                    |
993| -----------------| ------------------------ |
994|  Array\<[CameraConcurrentInfo](arkts-apis-camera-i.md#cameraconcurrentinfo18)\>    |  Array of concurrency information corresponding to the provided CameraDevice objects, with a one-to-one mapping.     |
995
996**Error codes**
997
998For details about the error codes, see [Universal Error Codes](../errorcode-universal.md) and [Camera Error Codes](errorcode-camera.md).
999
1000| ID        | Error Message       |
1001| --------------- | --------------- |
1002| 7400201 | Camera service fatal error. |
1003
1004**Example**
1005
1006```ts
1007import { camera } from '@kit.CameraKit';
1008import { BusinessError } from '@kit.BasicServicesKit';
1009
1010function getCameraConcurrentInfos(cameraManager: camera.CameraManager, cameraDeviceArray: Array<camera.CameraDevice>): void {
1011  try {
1012    let cameraConcurrentInfos: Array<camera.CameraConcurrentInfo> = [];
1013    cameraConcurrentInfos = cameraManager.getCameraConcurrentInfos(cameraDeviceArray);
1014  } catch (error) {
1015    // If the operation fails, an error code is returned and processed.
1016    let err = error as BusinessError;
1017    console.error(`The getCameraConcurrentInfos call failed. error code: ${err.code}`);
1018  }
1019}
1020```
1021
1022## getSupportedOutputCapability<sup>(deprecated)</sup>
1023
1024getSupportedOutputCapability(camera: CameraDevice): CameraOutputCapability
1025
1026Obtains the output capability supported by a camera device. This API returns the result synchronously.
1027
1028> **NOTE**
1029>
1030> This API is supported since API version 10 and deprecated since API version 11. You are advised to use [getSupportedOutputCapability](#getsupportedoutputcapability11) instead.
1031
1032**System capability**: SystemCapability.Multimedia.Camera.Core
1033
1034**Parameters**
1035
1036| Name        | Type                                                           | Mandatory| Description                     |
1037| ------------ |--------------------------------------------------------------- | -- | -------------------------- |
1038| camera | [CameraDevice](arkts-apis-camera-i.md#cameradevice)                              | Yes| CameraDevice instance, which is obtained through [getSupportedCameras](#getsupportedcameras). An error code is returned if the input parameter is invalid.     |
1039
1040**Return value**
1041
1042| Type                                            | Description                          |
1043| ----------------------------------------------- | ---------------------------- |
1044| [CameraOutputCapability](arkts-apis-camera-i.md#cameraoutputcapability)            | Camera output capability obtained.                  |
1045
1046**Example**
1047
1048```ts
1049function getSupportedOutputCapability(camera: camera.CameraDevice, cameraManager: camera.CameraManager): camera.CameraOutputCapability {
1050  let cameraOutputCapability: camera.CameraOutputCapability = cameraManager.getSupportedOutputCapability(camera);
1051  return cameraOutputCapability;
1052}
1053```
1054
1055## createPhotoOutput<sup>(deprecated)</sup>
1056
1057createPhotoOutput(profile: Profile, surfaceId: string): PhotoOutput
1058
1059Creates a PhotoOutput instance. This API returns the result synchronously.
1060
1061> **NOTE**
1062>
1063> This API is supported since API version 10 and deprecated since API version 11. You are advised to use [createPhotoOutput](#createphotooutput11) instead.
1064
1065**System capability**: SystemCapability.Multimedia.Camera.Core
1066
1067**Parameters**
1068
1069| Name    | Type                                        | Mandatory| Description                                 |
1070| -------- | ------------------------------------------- | ---- | ----------------------------------- |
1071| profile  | [Profile](arkts-apis-camera-i.md#profile)                         | Yes  | Supported photo profile, which is obtained through [getSupportedOutputCapability](#getsupportedoutputcapability11).|
1072| surfaceId| string            | Yes  | Surface ID, which is obtained from [ImageReceiver](../apis-image-kit/arkts-apis-image-ImageReceiver.md).|
1073
1074**Return value**
1075
1076| Type       | Description                         |
1077| ---------- | ----------------------------- |
1078| [PhotoOutput](arkts-apis-camera-PhotoOutput.md)   | PhotoOutput instance created. If the operation fails, an error code defined in [CameraErrorCode](arkts-apis-camera-e.md#cameraerrorcode) is returned.|
1079
1080**Error codes**
1081
1082For details about the error codes, see [Camera Error Codes](errorcode-camera.md).
1083
1084| ID        | Error Message       |
1085| --------------- | --------------- |
1086| 7400101                |  Parameter missing or parameter type incorrect.               |
1087
1088```ts
1089import { BusinessError } from '@kit.BasicServicesKit';
1090
1091function createPhotoOutput(cameraOutputCapability: camera.CameraOutputCapability, cameraManager: camera.CameraManager, surfaceId: string): camera.PhotoOutput | undefined {
1092  let profile: camera.Profile = cameraOutputCapability.photoProfiles[0];
1093  let photoOutput: camera.PhotoOutput | undefined = undefined;
1094  try {
1095    photoOutput = cameraManager.createPhotoOutput(profile, surfaceId);
1096  } catch (error) {
1097    // If the operation fails, error.code is returned and processed.
1098    let err = error as BusinessError;
1099    console.error(`The createPhotoOutput call failed. error code: ${err.code}`);
1100  }
1101  return photoOutput;
1102}
1103```
1104
1105## createCaptureSession<sup>(deprecated)</sup>
1106
1107createCaptureSession(): CaptureSession
1108
1109Creates a CaptureSession instance. This API returns the result synchronously.
1110
1111> **NOTE**
1112>
1113> This API is supported since API version 10 and deprecated since API version 11. You are advised to use [createSession](#createsession11) instead.
1114
1115**System capability**: SystemCapability.Multimedia.Camera.Core
1116
1117**Return value**
1118
1119| Type       | Description                         |
1120| ---------- | ----------------------------- |
1121| [CaptureSession](arkts-apis-camera-CaptureSession.md)   | CaptureSession instance created. If the operation fails, an error code defined in [CameraErrorCode](arkts-apis-camera-e.md#cameraerrorcode) is returned.|
1122
1123**Error codes**
1124
1125For details about the error codes, see [Camera Error Codes](errorcode-camera.md).
1126
1127| ID        | Error Message       |
1128| --------------- | --------------- |
1129| 7400201                |  Camera service fatal error.               |
1130
1131**Example**
1132
1133```ts
1134import { BusinessError } from '@kit.BasicServicesKit';
1135
1136function createCaptureSession(cameraManager: camera.CameraManager): camera.CaptureSession | undefined {
1137  let captureSession: camera.CaptureSession | undefined = undefined;
1138  try {
1139    captureSession = cameraManager.createCaptureSession();
1140  } catch (error) {
1141    // If the operation fails, error.code is returned and processed.
1142    let err = error as BusinessError;
1143    console.error(`createCaptureSession error. error code: ${err.code}`);
1144  }
1145  return captureSession;
1146}
1147```
1148