1# @ohos.multimedia.cameraPicker (Camera Picker)
2
3The cameraPicker module provides APIs for an application to select a camera to take photos or record videos, depending on the media type specified by the application. The APIs of this module must be called in a UIAbility of the page type. Otherwise, the camera picker cannot be started.
4
5> **NOTE**
6>
7> The initial APIs of this module are supported since API version 11. Newly added APIs will be marked with a superscript to indicate their earliest API version.
8
9## Modules to Import
10
11```ts
12import { cameraPicker as picker } from '@kit.CameraKit';
13```
14
15## pick
16
17pick(context: Context, mediaTypes: Array\<PickerMediaType\>, pickerProfile: PickerProfile): Promise\<PickerResult\>
18
19Starts a camera picker and enters the corresponding mode based on the media type. This API uses a promise to return the result.
20
21**Atomic service API**: This API can be used in atomic services since API version 12.
22
23**System capability**: SystemCapability.Multimedia.Camera.Core
24
25**Parameters**
26
27| Name         | Type                                             | Mandatory| Description                          |
28| -------------- |-------------------------------------------------| ---- | ---------------------------- |
29| context        | [Context](../apis-ability-kit/js-apis-inner-application-context.md) | Yes  | Application context.                  |
30| mediaTypes     | Array\<[PickerMediaType](#pickermediatype)\>    | Yes  | Media type.                   |
31| pickerProfile  | [PickerProfile](#pickerprofile)                 | Yes  | Profile of the camera picker.           |
32
33**Return value**
34
35| Type                                            | Description                                                                                  |
36| ----------------------------------------------- | -------------------------------------------------------------------------------------- |
37| Promise\<PickerResult\>                         | Promise used to return the result, which is specified by [PickerResult](#pickerresult).          |
38
39
40**Example**
41
42```ts
43import { cameraPicker as picker } from '@kit.CameraKit';
44import { camera } from '@kit.CameraKit';
45import { common } from '@kit.AbilityKit';
46import { BusinessError } from '@kit.BasicServicesKit';
47let mContext = getContext(this) as common.Context;
48
49async function demo() {
50  try {
51    let pickerProfile: picker.PickerProfile = {
52      cameraPosition: camera.CameraPosition.CAMERA_POSITION_BACK
53    };
54    let pickerResult: picker.PickerResult = await picker.pick(mContext,
55      [picker.PickerMediaType.PHOTO, picker.PickerMediaType.VIDEO], pickerProfile);
56    console.log("the pick pickerResult is:" + JSON.stringify(pickerResult));
57  } catch (error) {
58    let err = error as BusinessError;
59    console.error(`the pick call failed. error code: ${err.code}`);
60  }
61}
62```
63
64## PickerMediaType
65
66Enumerates the media types displayed in the camera picker.
67
68**Atomic service API**: This API can be used in atomic services since API version 12.
69
70**System capability**: SystemCapability.Multimedia.Camera.Core
71
72| Name            | Value   | Description    |
73| ----------------| ----  | ---------|
74| PHOTO           | photo | Photo mode. |
75| VIDEO           | video | Record mode. |
76
77
78## PickerProfile
79
80Defines the configuration information about the camera picker.
81
82**Atomic service API**: This API can be used in atomic services since API version 12.
83
84**System capability**: SystemCapability.Multimedia.Camera.Core
85
86| Name          | Type                              | Mandatory  | Description        |
87| -------------- | --------------------------------- | ----- | ------------ |
88| cameraPosition       | [camera.CameraPosition](js-apis-camera.md#cameraposition) | Yes   | Camera position.  |
89| saveUri        | string                            | No   | URI for saving the configuration information.|
90| videoDuration  | number                            | No   | Maximum recording duration.|
91
92
93## PickerResult
94
95Defines the processing result of the camera picker.
96
97**Atomic service API**: This API can be used in atomic services since API version 12.
98
99**System capability**: SystemCapability.Multimedia.Camera.Core
100
101| Name          | Type                               | Mandatory | Description                           |
102| -------------- | ---------------------------------- | ----- | -------------------------------- |
103| resultCode     | number                             | Yes   | Result code. The value **0** means that the processing is successful, and **-1** means that the processing fails.|
104| resultUri      | string                             | Yes   | URI of the result. If **saveUri** is empty, **resultUri** is a public media path. If **saveUri** is not empty and the application has the write permission on the URI, the value of **resultUri** is the same as that of **saveUri**. If **saveUri** is not empty and the application does not have the write permission on the URI, **resultUri** cannot be obtained.|
105| mediaType      | [PickerMediaType](#pickermediatype)| Yes   | Media type.                 |
106