1e41f4b71Sopenharmony_ci# @ohos.file.RecentPhotoComponent (RecentPhotoComponent)
2e41f4b71Sopenharmony_ci
3e41f4b71Sopenharmony_ciThe **RecentPhotoComponent** component embedded in the UI of an application allows the application to access the latest image or video in the user directory without the required permission. This component grants the application only the read permission.
4e41f4b71Sopenharmony_ci
5e41f4b71Sopenharmony_ci> **NOTE**
6e41f4b71Sopenharmony_ci>
7e41f4b71Sopenharmony_ci> This component is supported since API version 12. Updates will be marked with a superscript to indicate their earliest API version.
8e41f4b71Sopenharmony_ci
9e41f4b71Sopenharmony_ci## Modules to Import
10e41f4b71Sopenharmony_ci
11e41f4b71Sopenharmony_ci```ts
12e41f4b71Sopenharmony_ciimport {
13e41f4b71Sopenharmony_ci  RecentPhotoComponent, RecentPhotoOptions, RecentPhotoCheckResultCallback,
14e41f4b71Sopenharmony_ci  RecentPhotoClickCallback, PhotoSource
15e41f4b71Sopenharmony_ci} from '@ohos.file.RecentPhotoComponent';
16e41f4b71Sopenharmony_ci```
17e41f4b71Sopenharmony_ci
18e41f4b71Sopenharmony_ci## Properties
19e41f4b71Sopenharmony_ci
20e41f4b71Sopenharmony_ciThe [universal properties](../apis-arkui/arkui-ts/ts-universal-attributes-size.md) are supported.
21e41f4b71Sopenharmony_ci
22e41f4b71Sopenharmony_ci## RecentPhotoComponent
23e41f4b71Sopenharmony_ci
24e41f4b71Sopenharmony_ciRecentPhotoComponent({
25e41f4b71Sopenharmony_ci  recentPhotoOptions?: RecentPhotoOptions,
26e41f4b71Sopenharmony_ci  onRecentPhotoCheckResult?: RecentPhotoCheckResultCallback,
27e41f4b71Sopenharmony_ci  onRecentPhotoClick: RecentPhotoClickCallback
28e41f4b71Sopenharmony_ci})
29e41f4b71Sopenharmony_ci
30e41f4b71Sopenharmony_ciAllows the application  to access the latest image or video in the user directory without the media access permission.
31e41f4b71Sopenharmony_ci
32e41f4b71Sopenharmony_ci**Decorator**: @Component
33e41f4b71Sopenharmony_ci
34e41f4b71Sopenharmony_ci**Atomic service API**: This API can be used in atomic services since API version 12.
35e41f4b71Sopenharmony_ci
36e41f4b71Sopenharmony_ci**System capability**: SystemCapability.FileManagement.PhotoAccessHelper.Core
37e41f4b71Sopenharmony_ci
38e41f4b71Sopenharmony_ci**Parameters**
39e41f4b71Sopenharmony_ci
40e41f4b71Sopenharmony_ci| Name         | Type           | Mandatory | Decorator Description     | Description                |
41e41f4b71Sopenharmony_ci|---------------|-----------------|-------|-----------------|--------------------------|
42e41f4b71Sopenharmony_ci| recentPhotoOptions         | [RecentPhotoOptions](#recentphotooptions)                             | No  | - | Configuration of the latest image or video. |
43e41f4b71Sopenharmony_ci| onRecentPhotoCheckResult   | [RecentPhotoCheckResultCallback](#recentphotocheckresultcallback)     | No  | - | Callback used to return the query result of the latest image or video. |
44e41f4b71Sopenharmony_ci| onRecentPhotoClick         | [RecentPhotoClickCallback](#recentphotoclickcallback)                 | Yes  | - | Callback to be called when the latest image or video is selected.     |
45e41f4b71Sopenharmony_ci
46e41f4b71Sopenharmony_ci## RecentPhotoOptions
47e41f4b71Sopenharmony_ci
48e41f4b71Sopenharmony_ciRepresents the configuration of the latest image or video.
49e41f4b71Sopenharmony_ci
50e41f4b71Sopenharmony_ci**Atomic service API**: This API can be used in atomic services since API version 12.
51e41f4b71Sopenharmony_ci
52e41f4b71Sopenharmony_ci**System capability**: SystemCapability.FileManagement.PhotoAccessHelper.Core
53e41f4b71Sopenharmony_ci
54e41f4b71Sopenharmony_ci| Name                   | Type                                   | Mandatory | Description  |
55e41f4b71Sopenharmony_ci|-------------------------|-----------------------------------------|-------|--------|
56e41f4b71Sopenharmony_ci| period                  | number                                  | No   | Time period for the latest image or video, in seconds. The maximum value is **86400** seconds (one day), which is also the default value. If there is no image or video in the specified period, the component is not displayed. |
57e41f4b71Sopenharmony_ci| MIMEType                | [PhotoViewMIMETypes](js-apis-photoAccessHelper.md#photoviewmimetypes)   | No   | Types of the file displayed. The default value is **PhotoViewMIMETypes.IMAGE_VIDEO_TYPE**.                        |
58e41f4b71Sopenharmony_ci| photoSource             | [PhotoSource](#photosource)                                 | No   | Source of the latest image or video, for example, photo or video taken by the camera or screenshot. By default, the source is not restricted.                              |
59e41f4b71Sopenharmony_ci
60e41f4b71Sopenharmony_ci## RecentPhotoCheckResultCallback
61e41f4b71Sopenharmony_ci
62e41f4b71Sopenharmony_citype RecentPhotoCheckResultCallback = (recentPhotoExists: boolean) => void
63e41f4b71Sopenharmony_ci
64e41f4b71Sopenharmony_ciCalled to return the query result of the latest image or video.
65e41f4b71Sopenharmony_ci
66e41f4b71Sopenharmony_ci**Atomic service API**: This API can be used in atomic services since API version 12.
67e41f4b71Sopenharmony_ci
68e41f4b71Sopenharmony_ci**System capability**: SystemCapability.FileManagement.PhotoAccessHelper.Core
69e41f4b71Sopenharmony_ci
70e41f4b71Sopenharmony_ci**Parameters**
71e41f4b71Sopenharmony_ci
72e41f4b71Sopenharmony_ci| Name| Type| Mandatory| Description|
73e41f4b71Sopenharmony_ci| -------- | -------- | -------- | -------- |
74e41f4b71Sopenharmony_ci| recentPhotoExists | boolean | Yes| Whether the latest image or video exists.|
75e41f4b71Sopenharmony_ci
76e41f4b71Sopenharmony_ci## RecentPhotoClickCallback
77e41f4b71Sopenharmony_ci
78e41f4b71Sopenharmony_citype RecentPhotoClickCallback = (recentPhotoInfo: BaseItemInfo) => boolean
79e41f4b71Sopenharmony_ci
80e41f4b71Sopenharmony_ciCalled when the latest image or video is selected.
81e41f4b71Sopenharmony_ci
82e41f4b71Sopenharmony_ci**Atomic service API**: This API can be used in atomic services since API version 12.
83e41f4b71Sopenharmony_ci
84e41f4b71Sopenharmony_ci**System capability**: SystemCapability.FileManagement.PhotoAccessHelper.Core
85e41f4b71Sopenharmony_ci
86e41f4b71Sopenharmony_ci**Parameters**
87e41f4b71Sopenharmony_ci
88e41f4b71Sopenharmony_ci| Name| Type| Mandatory| Description|
89e41f4b71Sopenharmony_ci| -------- | -------- | -------- | -------- |
90e41f4b71Sopenharmony_ci| recentPhotoInfo | [BaseItemInfo](ohos-file-PhotoPickerComponent.md#baseiteminfo) | Yes| Information about the latest image or video.|
91e41f4b71Sopenharmony_ci
92e41f4b71Sopenharmony_ci**Return value**
93e41f4b71Sopenharmony_ci
94e41f4b71Sopenharmony_ci| Type   | Description                                                        |
95e41f4b71Sopenharmony_ci| ------- | ------------------------------------------------------------ |
96e41f4b71Sopenharmony_ci| boolean | Processing result of the latest image or video.|
97e41f4b71Sopenharmony_ci
98e41f4b71Sopenharmony_ci## PhotoSource
99e41f4b71Sopenharmony_ci
100e41f4b71Sopenharmony_ciEnumerates the sources of the image or video data.
101e41f4b71Sopenharmony_ci
102e41f4b71Sopenharmony_ci**Atomic service API**: This API can be used in atomic services since API version 12.
103e41f4b71Sopenharmony_ci
104e41f4b71Sopenharmony_ci**System capability**: SystemCapability.FileManagement.PhotoAccessHelper.Core
105e41f4b71Sopenharmony_ci
106e41f4b71Sopenharmony_ci| Name               | Value  | Description                                                                                                                |
107e41f4b71Sopenharmony_ci|-------------------|-----|--------------------------------------------------------------------------------------------------------------------|
108e41f4b71Sopenharmony_ci| ALL | 0   | Images and videos from all sources.|
109e41f4b71Sopenharmony_ci| CAMERA | 1   | Photo or video taken by the camera.|
110e41f4b71Sopenharmony_ci| SCREENSHOT | 2   | Screenshot or screen capture video.|
111e41f4b71Sopenharmony_ci
112e41f4b71Sopenharmony_ci## Example
113e41f4b71Sopenharmony_ci
114e41f4b71Sopenharmony_ci```ts
115e41f4b71Sopenharmony_ci// xxx.ets
116e41f4b71Sopenharmony_ciimport {
117e41f4b71Sopenharmony_ci  photoAccessHelper
118e41f4b71Sopenharmony_ci} from '@kit.MediaLibraryKit';
119e41f4b71Sopenharmony_ciimport {
120e41f4b71Sopenharmony_ci  RecentPhotoComponent, RecentPhotoOptions, PhotoSource, RecentPhotoCheckResultCallback, RecentPhotoClickCallback
121e41f4b71Sopenharmony_ci} from '@ohos.file.RecentPhotoComponent';
122e41f4b71Sopenharmony_ciimport {
123e41f4b71Sopenharmony_ci  BaseItemInfo
124e41f4b71Sopenharmony_ci} from '@ohos.file.PhotoPickerComponent';
125e41f4b71Sopenharmony_ci
126e41f4b71Sopenharmony_ci@Entry
127e41f4b71Sopenharmony_ci@Component
128e41f4b71Sopenharmony_cistruct PickerDemo {
129e41f4b71Sopenharmony_ci  private recentPhotoOptions: RecentPhotoOptions = new RecentPhotoOptions();
130e41f4b71Sopenharmony_ci  private recentPhotoCheckResultCallback: RecentPhotoCheckResultCallback = (recentPhotoExists: boolean) => this.onRecentPhotoCheckResult(recentPhotoExists);
131e41f4b71Sopenharmony_ci  private recentPhotoClickCallback: RecentPhotoClickCallback = (recentPhotoInfo: BaseItemInfo): boolean => this.onRecentPhotoClick(recentPhotoInfo);
132e41f4b71Sopenharmony_ci
133e41f4b71Sopenharmony_ci  aboutToAppear() {
134e41f4b71Sopenharmony_ci    this.recentPhotoOptions.MIMEType = photoAccessHelper.PhotoViewMIMETypes.IMAGE_VIDEO_TYPE;
135e41f4b71Sopenharmony_ci    this.recentPhotoOptions.period = 30;
136e41f4b71Sopenharmony_ci    this.recentPhotoOptions.photoSource = PhotoSource.ALL;
137e41f4b71Sopenharmony_ci  }
138e41f4b71Sopenharmony_ci
139e41f4b71Sopenharmony_ci  private onRecentPhotoCheckResult(recentPhotoExists: boolean): void {
140e41f4b71Sopenharmony_ci    // Photo or video that meets the search criteria exists.
141e41f4b71Sopenharmony_ci    if (recentPhotoExists) {
142e41f4b71Sopenharmony_ci      console.info('The photo is exist.');
143e41f4b71Sopenharmony_ci    }
144e41f4b71Sopenharmony_ci  }
145e41f4b71Sopenharmony_ci
146e41f4b71Sopenharmony_ci  private onRecentPhotoClick(recentPhotoInfo: BaseItemInfo): boolean {
147e41f4b71Sopenharmony_ci    // Return the photo or video.
148e41f4b71Sopenharmony_ci    if (recentPhotoInfo) {
149e41f4b71Sopenharmony_ci      console.info('The photo uri is ' + recentPhotoInfo.uri);
150e41f4b71Sopenharmony_ci      return true;
151e41f4b71Sopenharmony_ci    }
152e41f4b71Sopenharmony_ci    return true;
153e41f4b71Sopenharmony_ci  }
154e41f4b71Sopenharmony_ci
155e41f4b71Sopenharmony_ci  build() {
156e41f4b71Sopenharmony_ci    Stack() {
157e41f4b71Sopenharmony_ci      RecentPhotoComponent({
158e41f4b71Sopenharmony_ci        recentPhotoOptions: this.recentPhotoOptions,
159e41f4b71Sopenharmony_ci        onRecentPhotoCheckResult: this.recentPhotoCheckResultCallback,
160e41f4b71Sopenharmony_ci        onRecentPhotoClick: this.recentPhotoClickCallback,
161e41f4b71Sopenharmony_ci      }).height('100%').width('100%')
162e41f4b71Sopenharmony_ci    }
163e41f4b71Sopenharmony_ci  }
164e41f4b71Sopenharmony_ci}
165e41f4b71Sopenharmony_ci```
166