• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1# Interface (AbsAlbum)
2<!--Kit: Media Library Kit-->
3<!--Subsystem: Multimedia-->
4<!--Owner: @yixiaoff-->
5<!--SE: @liweilu1-->
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 { photoAccessHelper } from '@kit.MediaLibraryKit';
16```
17
18## Properties
19
20**System capability**: SystemCapability.FileManagement.PhotoAccessHelper.Core
21
22| Name          | Type   | Readable  | Writable | Description  |
23| ------------ | ------ | ---- | ---- | ------- |
24| albumType | [AlbumType](arkts-apis-photoAccessHelper-e.md#albumtype) | Yes   | No   | Type of the album.   |
25| albumSubtype | [AlbumSubtype](arkts-apis-photoAccessHelper-e.md#albumsubtype) | Yes   | No  | Subtype of the album.   |
26| albumName | string | Yes   | Yes for a user album; no for a system album.  | Name of the album.   |
27| albumUri | string | Yes   | No   | URI of the album.  |
28| count | number | Yes   | No   |  Number of files in the album.|
29| coverUri | string | Yes   | No   | URI of the cover file of the album.|
30
31## getAssets
32
33getAssets(options: FetchOptions, callback: AsyncCallback&lt;FetchResult&lt;PhotoAsset&gt;&gt;): void
34
35Obtains image and video assets. This API uses an asynchronous callback to return the result.
36
37**Required permissions**: ohos.permission.READ_IMAGEVIDEO
38
39**System capability**: SystemCapability.FileManagement.PhotoAccessHelper.Core
40
41**Parameters**
42
43| Name  | Type                     | Mandatory| Description      |
44| -------- | ------------------------- | ---- | ---------- |
45| options | [FetchOptions](arkts-apis-photoAccessHelper-i.md#fetchoptions) | Yes  | Retrieval options.|
46| callback | AsyncCallback&lt;[FetchResult](arkts-apis-photoAccessHelper-FetchResult.md)&lt;[PhotoAsset](arkts-apis-photoAccessHelper-PhotoAsset.md)&gt;&gt; | Yes  | Callback used to return the image and video assets obtained.|
47
48**Error codes**
49
50For details about the error codes, see [Universal Error Codes](../errorcode-universal.md) and [File Management Error Codes](../apis-core-file-kit/errorcode-filemanagement.md).
51
52In API version 13 and earlier versions, if the caller does not have the required permission, error code 13900012 is returned. Starting from API version 14, the same situation raises error code 201.
53
54| ID| Error Message|
55| -------- | ---------------------------------------- |
56| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types; 3. Parameter verification failed. |
57| 201     | Permission denied.         |
58| 13900020     | Invalid argument.         |
59| 14000011       | System inner fail.         |
60
61**Example**
62
63For details about how to create a phAccessHelper instance, see the example provided in [photoAccessHelper.getPhotoAccessHelper](arkts-apis-photoAccessHelper-f.md#photoaccesshelpergetphotoaccesshelper).
64
65```ts
66import { dataSharePredicates } from '@kit.ArkData';
67
68async function example(phAccessHelper: photoAccessHelper.PhotoAccessHelper) {
69  console.info('albumGetAssetsDemoCallback');
70  let predicates: dataSharePredicates.DataSharePredicates = new dataSharePredicates.DataSharePredicates();
71  let albumFetchOptions: photoAccessHelper.FetchOptions = {
72    fetchColumns: [],
73    predicates: predicates
74  };
75  let fetchOption: photoAccessHelper.FetchOptions = {
76    fetchColumns: [],
77    predicates: predicates
78  };
79  let albumList: photoAccessHelper.FetchResult<photoAccessHelper.Album> = await phAccessHelper.getAlbums(photoAccessHelper.AlbumType.USER, photoAccessHelper.AlbumSubtype.USER_GENERIC, albumFetchOptions);
80  let album: photoAccessHelper.Album = await albumList.getFirstObject();
81  album.getAssets(fetchOption, (err, albumFetchResult) => {
82    if (albumFetchResult !== undefined) {
83      console.info('album getAssets successfully, getCount: ' + albumFetchResult.getCount());
84    } else {
85      console.error(`album getAssets failed with error: ${err.code}, ${err.message}`);
86    }
87  });
88}
89```
90
91## getAssets
92
93getAssets(options: FetchOptions): Promise&lt;FetchResult&lt;PhotoAsset&gt;&gt;
94
95Obtains image and video assets. This API uses a promise to return the result.
96
97**Atomic service API**: This API can be used in atomic services since API version 20.
98
99**Required permissions**: ohos.permission.READ_IMAGEVIDEO
100
101**System capability**: SystemCapability.FileManagement.PhotoAccessHelper.Core
102
103**Parameters**
104
105| Name  | Type                     | Mandatory| Description      |
106| -------- | ------------------------- | ---- | ---------- |
107| options | [FetchOptions](arkts-apis-photoAccessHelper-i.md#fetchoptions) | Yes  | Retrieval options.|
108
109**Return value**
110
111| Type                                   | Description             |
112| --------------------------------------- | ----------------- |
113| Promise&lt;[FetchResult](arkts-apis-photoAccessHelper-FetchResult.md)&lt;[PhotoAsset](arkts-apis-photoAccessHelper-PhotoAsset.md)&gt;&gt; | Promise used to return the image and video assets obtained.|
114
115**Error codes**
116
117For details about the error codes, see [Universal Error Codes](../errorcode-universal.md) and [File Management Error Codes](../apis-core-file-kit/errorcode-filemanagement.md).
118
119In API version 13 and earlier versions, if the caller does not have the required permission, error code 13900012 is returned. Starting from API version 14, the same situation raises error code 201.
120
121| ID| Error Message|
122| -------- | ---------------------------------------- |
123| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types; 3. Parameter verification failed. |
124| 201     | Permission denied.         |
125| 13900020     | Invalid argument.         |
126| 14000011       | System inner fail.         |
127
128**Example**
129
130For details about how to create a phAccessHelper instance, see the example provided in [photoAccessHelper.getPhotoAccessHelper](arkts-apis-photoAccessHelper-f.md#photoaccesshelpergetphotoaccesshelper).
131
132```ts
133import { dataSharePredicates } from '@kit.ArkData';
134import { BusinessError } from '@kit.BasicServicesKit';
135
136async function example(phAccessHelper: photoAccessHelper.PhotoAccessHelper) {
137  console.info('albumGetAssetsDemoPromise');
138  let predicates: dataSharePredicates.DataSharePredicates = new dataSharePredicates.DataSharePredicates();
139  let albumFetchOptions: photoAccessHelper.FetchOptions = {
140    fetchColumns: [],
141    predicates: predicates
142  };
143  let fetchOption: photoAccessHelper.FetchOptions = {
144    fetchColumns: [],
145    predicates: predicates
146  };
147  let albumList: photoAccessHelper.FetchResult<photoAccessHelper.Album> = await phAccessHelper.getAlbums(photoAccessHelper.AlbumType.USER, photoAccessHelper.AlbumSubtype.USER_GENERIC, albumFetchOptions);
148  let album: photoAccessHelper.Album = await albumList.getFirstObject();
149  album.getAssets(fetchOption).then((albumFetchResult) => {
150    console.info('album getAssets successfully, getCount: ' + albumFetchResult.getCount());
151  }).catch((err: BusinessError) => {
152    console.error(`album getAssets failed with error: ${err.code}, ${err.message}`);
153  });
154}
155```
156