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