• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1# Functions
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
12## Modules to Import
13
14```ts
15import { camera } from '@kit.CameraKit';
16```
17
18## camera.getCameraManager
19
20getCameraManager(context: Context): CameraManager
21
22Obtains a CameraManager instance. This API returns the result synchronously.
23
24**Atomic service API**: This API can be used in atomic services since API version 19.
25
26**System capability**: SystemCapability.Multimedia.Camera.Core
27
28**Parameters**
29
30| Name    | Type                                            | Mandatory| Description                          |
31| -------- | ----------------------------------------------- | ---- | ---------------------------- |
32| context  | [Context](../apis-ability-kit/js-apis-inner-application-context.md)      | Yes  | Application context.                  |
33
34**Return value**
35
36| Type                                            | Description                          |
37| ----------------------------------------------- | ---------------------------- |
38| [CameraManager](arkts-apis-camera-CameraManager.md)           | CameraManager instance obtained.                  |
39
40**Error codes**
41
42For details about the error codes, see [Camera Error Codes](errorcode-camera.md).
43
44| ID        | Error Message       |
45| --------------- | --------------- |
46| 7400101                |  Parameter missing or parameter type incorrect.               |
47| 7400201                |  Camera service fatal error.                                  |
48
49**Example**
50
51```ts
52import { common } from '@kit.AbilityKit';
53import { BusinessError } from '@kit.BasicServicesKit';
54
55function getCameraManager(context: common.BaseContext): camera.CameraManager | undefined {
56  let cameraManager: camera.CameraManager | undefined = undefined;
57  try {
58    cameraManager = camera.getCameraManager(context);
59  } catch (error) {
60    let err = error as BusinessError;
61    console.error(`The getCameraManager call failed. error code: ${err.code}`);
62  }
63  return cameraManager;
64}
65```
66