• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1# @ohos.file.sendablePhotoAccessHelper (基于Sendable对象的相册管理模块)
2
3该模块基于Sendable对象,提供相册管理模块能力,包括创建相册以及访问、修改相册中的媒体数据信息等。
4
5> **说明:**
6>
7> 本模块首批接口从API version 12开始支持。后续版本的新增接口,采用上角标单独标记接口的起始版本。
8
9## 导入模块
10
11```ts
12import { sendablePhotoAccessHelper } from '@kit.MediaLibraryKit';
13```
14
15## sendablePhotoAccessHelper.getPhotoAccessHelper
16
17getPhotoAccessHelper(context: Context): PhotoAccessHelper
18
19获取相册管理模块的实例,用于访问和修改相册中的媒体文件。
20
21**模型约束**: 此接口仅可在Stage模型下使用。
22
23**原子化服务API:** 从API version 12开始,该接口支持在原子化服务中使用。
24
25**系统能力**:SystemCapability.FileManagement.PhotoAccessHelper.Core
26
27**参数:**
28
29| 参数名  | 类型                                                         | 必填 | 说明                       |
30| ------- | ------------------------------------------------------------ | ---- | -------------------------- |
31| context | [Context](../apis-ability-kit/js-apis-inner-application-context.md) | 是   | 传入Ability实例的Context。 |
32
33**返回值:**
34
35| 类型                                    | 说明                 |
36| --------------------------------------- | :------------------- |
37| [PhotoAccessHelper](#photoaccesshelper) | 相册管理模块的实例。 |
38
39**错误码:**
40
41接口抛出错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)。
42
43| 错误码ID | 错误信息                                                     |
44| -------- | ------------------------------------------------------------ |
45| 401      | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types; 3. Parameter verification failed. |
46
47**示例:**
48
49```ts
50//此处获取的phAccessHelper实例为全局对象,后续使用到phAccessHelper的地方默认为使用此处获取的对象,如未添加此段代码报phAccessHelper未定义的错误请自行添加。
51let context = getContext(this);
52let phAccessHelper = sendablePhotoAccessHelper.getPhotoAccessHelper(context);
53```
54
55## PhotoAccessHelper
56
57### getAssets
58
59getAssets(options: photoAccessHelper.FetchOptions): Promise<FetchResult<PhotoAsset>>
60
61获取图片和视频资源,使用Promise方式返回结果。
62
63**系统能力**:SystemCapability.FileManagement.PhotoAccessHelper.Core
64
65**需要权限**:ohos.permission.READ_IMAGEVIDEO
66
67对于未申请'ohos.permission.READ_IMAGEVIDEO'权限的应用,可以通过picker的方式调用该接口来查询指定uri对应的图片或视频资源,详情请参考[开发指南](../../media/medialibrary/photoAccessHelper-photoviewpicker.md#指定uri获取图片或视频资源)。
68
69**参数:**
70
71| 参数名  | 类型                                                      | 必填 | 说明                 |
72| ------- | --------------------------------------------------------- | ---- | -------------------- |
73| options | [photoAccessHelper.FetchOptions](js-apis-photoAccessHelper.md#fetchoptions) | 是   | 图片和视频检索选项。 |
74
75**返回值:**
76
77| 类型                                                         | 说明                                    |
78| ------------------------------------------------------------ | --------------------------------------- |
79| Promise<[FetchResult](#fetchresult)<[PhotoAsset](#photoasset)>> | Promise对象,返回图片和视频数据结果集。 |
80
81**错误码:**
82
83接口抛出错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)和[文件管理错误码](../apis-core-file-kit/errorcode-filemanagement.md)。
84
85| 错误码ID | 错误信息                                                     |
86| -------- | ------------------------------------------------------------ |
87| 401      | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types; 3. Parameter verification failed. |
88| 201      | Permission denied.                                           |
89| 14000011 | Internal system error.                                        |
90
91**示例:**
92
93
94
95```ts
96import { dataSharePredicates } from '@kit.ArkData';
97import { photoAccessHelper } from '@kit.MediaLibraryKit';
98
99async function example() {
100  console.info('getAssets');
101  let predicates: dataSharePredicates.DataSharePredicates = new dataSharePredicates.DataSharePredicates();
102  let fetchOptions: photoAccessHelper.FetchOptions = {
103    fetchColumns: [],
104    predicates: predicates
105  };
106  try {
107    let fetchResult: sendablePhotoAccessHelper.FetchResult<sendablePhotoAccessHelper.PhotoAsset> = await phAccessHelper.getAssets(fetchOptions);
108    if (fetchResult !== undefined) {
109      console.info('fetchResult success');
110      let photoAsset: sendablePhotoAccessHelper.PhotoAsset = await fetchResult.getFirstObject();
111      if (photoAsset !== undefined) {
112        console.info('photoAsset.displayName :' + photoAsset.displayName);
113      }
114    }
115  } catch (err) {
116    console.error(`getAssets failed, error: ${err.code}, ${err.message}`);
117  }
118}
119```
120
121### getBurstAssets
122
123getBurstAssets(burstKey: string, options: photoAccessHelper.FetchOptions): Promise&lt;FetchResult&lt;PhotoAsset&gt;&gt;
124
125获取连拍照片资源,使用Promise方式返回结果。
126
127**系统能力**:SystemCapability.FileManagement.PhotoAccessHelper.Core
128
129**需要权限**:ohos.permission.READ_IMAGEVIDEO
130
131**参数:**
132
133| 参数名   | 类型                                                      | 必填 | 说明                                                         |
134| -------- | --------------------------------------------------------- | ---- | ------------------------------------------------------------ |
135| burstKey | string                                                    | 是   | 一组连拍照片的唯一标识:uuid(可传入[PhotoKeys](js-apis-photoAccessHelper.md#photokeys)的BURST_KEY) |
136| options  | [photoAccessHelper.FetchOptions](js-apis-photoAccessHelper.md#fetchoptions) | 是   | 连拍照片检索选项。                                           |
137
138**返回值:**
139
140| 类型                                                         | 说明                                  |
141| ------------------------------------------------------------ | ------------------------------------- |
142| Promise&lt;[FetchResult](#fetchresult)&lt;[PhotoAsset](#photoasset)&gt;&gt; | Promise对象,返回连拍照片数据结果集。 |
143
144**错误码:**
145
146接口抛出错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)和[文件管理错误码](../apis-core-file-kit/errorcode-filemanagement.md)。
147
148| 错误码ID | 错误信息                                                     |
149| -------- | ------------------------------------------------------------ |
150| 201      | Permission denied.                                           |
151| 401      | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types; 3. Parameter verification failed. |
152| 14000011 | Internal system error.                                       |
153
154**示例:**
155
156```ts
157import { photoAccessHelper } from '@kit.MediaLibraryKit';
158import { dataSharePredicates } from '@kit.ArkData';
159
160async function example() {
161  console.info('getBurstAssets');
162  let predicates: dataSharePredicates.DataSharePredicates = new dataSharePredicates.DataSharePredicates();
163  let fetchOption: photoAccessHelper.FetchOptions = {
164    fetchColumns: [],
165    predicates: predicates
166  };
167  let fetchResult: sendablePhotoAccessHelper.FetchResult<sendablePhotoAccessHelper.PhotoAsset> = await phAccessHelper.getAssets(fetchOption);
168  let photoAssetList: Array<sendablePhotoAccessHelper.PhotoAsset> = await fetchResult.getAllObjects();
169  let photoAsset: sendablePhotoAccessHelper.PhotoAsset;
170  // burstKey为36位的uuid,可以根据photoAccessHelper.PhotoKeys获取。
171  for(photoAsset of photoAssetList){
172    let burstKey: string = photoAccessHelper.PhotoKeys.BURST_KEY.toString();
173    let photoAccessBurstKey: photoAccessHelper.MemberType = photoAsset.get(burstKey).toString();
174    try {
175      let fetchResult: sendablePhotoAccessHelper.FetchResult<sendablePhotoAccessHelper.PhotoAsset> = await
176      phAccessHelper.getBurstAssets(photoAccessBurstKey, fetchOption);
177      if (fetchResult !== undefined) {
178        console.info('fetchResult success');
179        let photoAsset: sendablePhotoAccessHelper.PhotoAsset = await fetchResult.getFirstObject();
180        if (photoAsset !== undefined) {
181          console.info('photoAsset.displayName :' + photoAsset.displayName);
182        }
183      }
184    } catch (err) {
185      console.error(`getBurstAssets failed, error: ${err.code}, ${err.message}`);
186    }
187  }
188}
189```
190
191### createAsset
192
193createAsset(photoType: PhotoType, extension: string, options?: photoAccessHelper.CreateOptions): Promise&lt;string&gt;
194
195指定待创建的文件类型、后缀和创建选项,创建图片或视频资源,使用Promise方式返回结果。
196
197此接口在未申请相册管理模块权限'ohos.permission.WRITE_IMAGEVIDEO'时,可以使用安全控件创建媒体资源,详情请参考[开发指南](../../media/medialibrary/photoAccessHelper-savebutton.md)。
198
199**原子化服务API:** 从API version 12开始,该接口支持在原子化服务中使用。
200
201**系统能力**:SystemCapability.FileManagement.PhotoAccessHelper.Core
202
203**需要权限**:ohos.permission.WRITE_IMAGEVIDEO
204
205**参数:**
206
207| 参数名    | 类型                                                        | 必填 | 说明                                 |
208| --------- | ----------------------------------------------------------- | ---- | ------------------------------------ |
209| photoType | [PhotoType](#phototype)                                     | 是   | 创建的文件类型,IMAGE或者VIDEO类型。 |
210| extension | string                                                      | 是   | 文件名后缀参数,例如:'jpg'。        |
211| options   | [photoAccessHelper.CreateOptions](js-apis-photoAccessHelper.md#createoptions) | 否   | 创建选项,例如{title: 'testPhoto'}。 |
212
213**返回值:**
214
215| 类型                  | 说明                                     |
216| --------------------- | ---------------------------------------- |
217| Promise&lt;string&gt; | Promise对象,返回创建的图片和视频的uri。 |
218
219**错误码:**
220
221接口抛出错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)和[文件管理错误码](../apis-core-file-kit/errorcode-filemanagement.md)。
222
223| 错误码ID | 错误信息                                                     |
224| -------- | ------------------------------------------------------------ |
225| 401      | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types; 3. Parameter verification failed. |
226| 201      | Permission denied.                                           |
227| 14000011 | Internal system error.                                        |
228
229**示例:**
230
231```ts
232import { photoAccessHelper } from '@kit.MediaLibraryKit';
233
234async function example() {
235  console.info('createAssetDemo');
236  try {
237    let photoType: sendablePhotoAccessHelper.PhotoType = sendablePhotoAccessHelper.PhotoType.IMAGE;
238    let extension: string = 'jpg';
239    let options: photoAccessHelper.CreateOptions = {
240      title: 'testPhoto'
241    }
242    let uri: string = await phAccessHelper.createAsset(photoType, extension, options);
243    console.info('createAsset uri' + uri);
244    console.info('createAsset successfully');
245  } catch (err) {
246    console.error(`createAsset failed, error: ${err.code}, ${err.message}`);
247  }
248}
249```
250
251### getAlbums
252
253getAlbums(type: AlbumType, subtype: AlbumSubtype, options?: photoAccessHelper.FetchOptions): Promise&lt;FetchResult&lt;Album&gt;&gt;
254
255根据检索选项和相册类型获取相册,使用Promise方式返回结果。
256
257获取相册前需先保证相册存在。
258
259**系统能力**:SystemCapability.FileManagement.PhotoAccessHelper.Core
260
261**需要权限**:ohos.permission.READ_IMAGEVIDEO
262
263**参数:**
264
265| 参数名  | 类型                                                      | 必填 | 说明                                   |
266| ------- | --------------------------------------------------------- | ---- | -------------------------------------- |
267| type    | [AlbumType](#albumtype)                                   | 是   | 相册类型。                             |
268| subtype | [AlbumSubtype](#albumsubtype)                             | 是   | 相册子类型。                           |
269| options | [photoAccessHelper.FetchOptions](js-apis-photoAccessHelper.md#fetchoptions) | 否   | 检索选项,不填时默认根据相册类型检索。 |
270
271**返回值:**
272
273| 类型                                                         | 说明                                |
274| ------------------------------------------------------------ | ----------------------------------- |
275| Promise&lt;[FetchResult](#fetchresult)&lt;[Album](#album)&gt;&gt; | Promise对象,返回获取相册的结果集。 |
276
277**错误码:**
278
279接口抛出错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)和[文件管理错误码](../apis-core-file-kit/errorcode-filemanagement.md)。
280
281| 错误码ID | 错误信息                                                     |
282| -------- | ------------------------------------------------------------ |
283| 401      | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types; 3. Parameter verification failed. |
284| 201      | Permission denied.                                           |
285| 14000011 | Internal system error.                                        |
286
287**示例:**
288
289```ts
290import { dataSharePredicates } from '@kit.ArkData';
291import { BusinessError } from '@kit.BasicServicesKit';
292import { photoAccessHelper } from '@kit.MediaLibraryKit';
293
294async function example() {
295  // 示例代码中为获取相册名为newAlbumName的相册。
296  console.info('getAlbumsDemo');
297  let predicates: dataSharePredicates.DataSharePredicates = new dataSharePredicates.DataSharePredicates();
298  predicates.equalTo('album_name', 'newAlbumName');
299  let fetchOptions: photoAccessHelper.FetchOptions = {
300    fetchColumns: [],
301    predicates: predicates
302  };
303  phAccessHelper.getAlbums(sendablePhotoAccessHelper.AlbumType.USER, sendablePhotoAccessHelper.AlbumSubtype.USER_GENERIC, fetchOptions).then( async (fetchResult) => {
304    if (fetchResult === undefined) {
305      console.error('getAlbumsPromise fetchResult is undefined');
306      return;
307    }
308    let album: sendablePhotoAccessHelper.Album = await fetchResult.getFirstObject();
309    console.info('getAlbumsPromise successfully, albumName: ' + album.albumName);
310    fetchResult.close();
311  }).catch((err: BusinessError) => {
312    console.error(`getAlbumsPromise failed with err: ${err.code}, ${err.message}`);
313  });
314}
315```
316
317### getAlbums
318
319getAlbums(options: photoAccessHelper.FetchOptions): Promise&lt;FetchResult&lt;Album&gt;&gt;
320
321根据检索选项获取相册,使用Promise方式返回结果。
322
323获取相册前需先保证相册存在。
324
325**系统能力**:SystemCapability.FileManagement.PhotoAccessHelper.Core
326
327**需要权限**:ohos.permission.READ_IMAGEVIDEO
328
329**参数:**
330
331| 参数名  | 类型                                                      | 必填 | 说明     |
332| ------- | --------------------------------------------------------- | ---- | -------- |
333| options | [photoAccessHelper.FetchOptions](js-apis-photoAccessHelper.md#fetchoptions) | 是   | 检索选项。 |
334
335**返回值:**
336
337| 类型                                                         | 说明                                |
338| ------------------------------------------------------------ | ----------------------------------- |
339| Promise&lt;[FetchResult](#fetchresult)&lt;[Album](#album)&gt;&gt; | Promise对象,返回获取相册的结果集。 |
340
341**错误码:**
342
343接口抛出错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)和[文件管理错误码](../apis-core-file-kit/errorcode-filemanagement.md)。
344
345| 错误码ID | 错误信息                                                     |
346| -------- | ------------------------------------------------------------ |
347| 401      | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types; 3. Parameter verification failed. |
348| 201      | Permission denied.                                           |
349| 14000011 | Internal system error.                                        |
350
351**示例:**
352
353```ts
354import { dataSharePredicates } from '@kit.ArkData';
355import { BusinessError } from '@kit.BasicServicesKit';
356import { photoAccessHelper } from '@kit.MediaLibraryKit';
357
358async function example() {
359  // 示例代码中为获取相册名为newAlbumName的相册。
360  console.info('getAlbumsDemo');
361  let predicates: dataSharePredicates.DataSharePredicates = new dataSharePredicates.DataSharePredicates();
362  predicates.equalTo('album_name', 'newAlbumName');
363  let fetchOptions: photoAccessHelper.FetchOptions = {
364    fetchColumns: [],
365    predicates: predicates
366  };
367  phAccessHelper.getAlbums(fetchOptions).then( async (fetchResult) => {
368    if (fetchResult === undefined) {
369      console.error('getAlbumsPromise fetchResult is undefined');
370      return;
371    }
372    let album: sendablePhotoAccessHelper.Album = await fetchResult.getFirstObject();
373    console.info('getAlbumsPromise successfully, albumName: ' + album.albumName);
374    fetchResult.close();
375  }).catch((err: BusinessError) => {
376    console.error(`getAlbumsPromise failed with err: ${err.code}, ${err.message}`);
377  });
378}
379```
380
381### release
382
383release(): Promise&lt;void&gt;
384
385释放PhotoAccessHelper实例,使用Promise方式返回结果。
386当后续不需要使用PhotoAccessHelper 实例中的方法时调用。
387
388**系统能力**:SystemCapability.FileManagement.PhotoAccessHelper.Core
389
390**返回值:**
391
392| 类型                | 说明                    |
393| ------------------- | ----------------------- |
394| Promise&lt;void&gt; | Promise对象,返回void。 |
395
396**错误码:**
397
398接口抛出错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)和[文件管理错误码](../apis-core-file-kit/errorcode-filemanagement.md)。
399
400| 错误码ID | 错误信息                                                     |
401| -------- | ------------------------------------------------------------ |
402| 14000011 | Internal system error.                                        |
403
404**示例:**
405
406```ts
407async function example() {
408  console.info('releaseDemo');
409  try {
410    console.info('use function...');
411  } catch (err) {
412    console.error(`function error ...`);
413  }finally{
414      try{
415          phAccessHelper?.release();
416          console.info(`release success`);
417      } catch(e){
418          console.error(`release error :${e}`);
419      }
420  }
421}
422```
423
424## PhotoAsset
425
426提供封装文件属性的方法。
427
428### 属性
429
430**系统能力**:SystemCapability.FileManagement.PhotoAccessHelper.Core
431
432| 名称        | 类型                    | 只读 | 可选 | 说明                                                         |
433| ----------- | ----------------------- | ---- | ---- | ------------------------------------------------------------ |
434| uri<sup>12+</sup>         | string                  | 是   | 否   | 媒体文件资源uri(如:file://media/Photo/1/IMG_datetime_0001/displayName.jpg),详情参见用户文件uri介绍中的[媒体文件uri](../../file-management/user-file-uri-intro.md#媒体文件uri)。 |
435| photoType<sup>12+</sup>   | [PhotoType](#phototype) | 是   | 否   | 媒体文件类型。                                               |
436| displayName<sup>12+</sup> | string                  | 是   | 否   | 显示文件名,包含后缀名。                                     |
437
438### convertToPhotoAsset
439
440convertToPhotoAsset():  photoAccessHelper.PhotoAsset
441
442将Sendable类型PhotoAsset转换为非Sendable类型PhotoAsset。
443
444**系统能力**:SystemCapability.FileManagement.PhotoAccessHelper.Core
445
446**返回值:**
447
448| 类型                         | 说明                                                         |
449| ---------------------------- | ------------------------------------------------------------ |
450| photoAccessHelper.PhotoAsset | 返回非Sendable类型的[PhotoAsset](js-apis-photoAccessHelper.md#photoasset)。 |
451
452**错误码:**
453
454接口抛出错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)和[文件管理错误码](../apis-core-file-kit/errorcode-filemanagement.md)。
455
456| 错误码ID | 错误信息                                                     |
457| -------- | ------------------------------------------------------------ |
458| 201      | Permission denied.                                           |
459| 14000011 | Internal system error.                                        |
460
461**示例:**
462
463```ts
464import { dataSharePredicates } from '@kit.ArkData';
465import { photoAccessHelper } from '@kit.MediaLibraryKit';
466
467async function example() {
468  console.info('convertToPhotoAssetDemo');
469  try {
470    let predicates: dataSharePredicates.DataSharePredicates = new dataSharePredicates.DataSharePredicates();
471    let fetchOption: photoAccessHelper.FetchOptions = {
472      fetchColumns: ['title'],
473      predicates: predicates
474    };
475    let fetchResult: sendablePhotoAccessHelper.FetchResult<sendablePhotoAccessHelper.PhotoAsset> = await phAccessHelper.getAssets(fetchOption);
476    let sendablePhotoAsset: sendablePhotoAccessHelper.PhotoAsset = await fetchResult.getFirstObject();
477    let photoAsset: photoAccessHelper.PhotoAsset = sendablePhotoAsset.convertToPhotoAsset();
478    console.log(`get no sendable uri success : ${photoAsset.uri}`);
479  } catch (err) {
480    console.error(`convertToPhotoAsset failed. error: ${err.code}, ${err.message}`);
481  }
482}
483```
484
485### get
486
487get(member: string): photoAccessHelper.MemberType
488
489获取PhotoAsset成员参数。
490
491**系统能力**:SystemCapability.FileManagement.PhotoAccessHelper.Core
492
493**参数:**
494
495| 参数名 | 类型   | 必填 | 说明                                                         |
496| ------ | ------ | ---- | ------------------------------------------------------------ |
497| member | string | 是   | 成员参数名称,在get时,除了'uri'、'media_type'、'subtype'和'display_name'四个属性之外,其他的属性都需要在fetchColumns中填入需要get的[PhotoKeys](js-apis-photoAccessHelper.md#photokeys),例如:get title属性fetchColumns: ['title']。 |
498
499**返回值:**
500
501| 类型                                                  | 说明                         |
502| ----------------------------------------------------- | ---------------------------- |
503| [photoAccessHelper.MemberType](js-apis-photoAccessHelper.md#membertype) | 获取PhotoAsset成员参数的值。 |
504
505**错误码:**
506
507接口抛出错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)和[文件管理错误码](../apis-core-file-kit/errorcode-filemanagement.md)。
508
509| 错误码ID | 错误信息                                                     |
510| -------- | ------------------------------------------------------------ |
511| 401      | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types; 3. Parameter verification failed. |
512
513**示例:**
514
515```ts
516import { dataSharePredicates } from '@kit.ArkData';
517import { photoAccessHelper } from '@kit.MediaLibraryKit';
518
519async function example() {
520  console.info('photoAssetGetDemo');
521  try {
522    let predicates: dataSharePredicates.DataSharePredicates = new dataSharePredicates.DataSharePredicates();
523    let fetchOption: photoAccessHelper.FetchOptions = {
524      fetchColumns: ['title'],
525      predicates: predicates
526    };
527    let fetchResult: sendablePhotoAccessHelper.FetchResult<sendablePhotoAccessHelper.PhotoAsset> = await phAccessHelper.getAssets(fetchOption);
528    let photoAsset: sendablePhotoAccessHelper.PhotoAsset = await fetchResult.getFirstObject();
529    let title: photoAccessHelper.PhotoKeys = photoAccessHelper.PhotoKeys.TITLE;
530    let photoAssetTitle: photoAccessHelper.MemberType = photoAsset.get(title.toString());
531    console.info('photoAsset Get photoAssetTitle = ', photoAssetTitle);
532  } catch (err) {
533    console.error(`get failed. error: ${err.code}, ${err.message}`);
534  }
535}
536```
537
538### set
539
540set(member: string, value: string): void
541
542设置PhotoAsset成员参数。
543
544**系统能力**:SystemCapability.FileManagement.PhotoAccessHelper.Core
545
546**参数:**
547
548| 参数名 | 类型   | 必填 | 说明                                                         |
549| ------ | ------ | ---- | ------------------------------------------------------------ |
550| member | string | 是   | 成员参数名称例如:[PhotoKeys](js-apis-photoAccessHelper.md#photokeys).TITLE。 |
551| value  | string | 是   | 设置成员参数名称,只能修改[PhotoKeys](js-apis-photoAccessHelper.md#photokeys).TITLE的值。 |
552
553**错误码:**
554
555接口抛出错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)和[文件管理错误码](../apis-core-file-kit/errorcode-filemanagement.md)。
556
557| 错误码ID | 错误信息                                                     |
558| -------- | ------------------------------------------------------------ |
559| 401      | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types; 3. Parameter verification failed. |
560
561**示例:**
562
563```ts
564import { dataSharePredicates } from '@kit.ArkData';
565import { photoAccessHelper } from '@kit.MediaLibraryKit';
566
567async function example() {
568  console.info('photoAssetSetDemo');
569  try {
570    let predicates: dataSharePredicates.DataSharePredicates = new dataSharePredicates.DataSharePredicates();
571    let fetchOption: photoAccessHelper.FetchOptions = {
572      fetchColumns: ['title'],
573      predicates: predicates
574    };
575    let fetchResult: sendablePhotoAccessHelper.FetchResult<sendablePhotoAccessHelper.PhotoAsset> = await phAccessHelper.getAssets(fetchOption);
576    let photoAsset: sendablePhotoAccessHelper.PhotoAsset = await fetchResult.getFirstObject();
577    let title: string = photoAccessHelper.PhotoKeys.TITLE.toString();
578    photoAsset.set(title, 'newTitle');
579  } catch (err) {
580    console.error(`set failed. error: ${err.code}, ${err.message}`);
581  }
582}
583```
584
585### commitModify
586
587commitModify(): Promise&lt;void&gt;
588
589修改文件的元数据,使用Promise方式返回异步结果。
590
591**需要权限**:ohos.permission.WRITE_IMAGEVIDEO
592
593**原子化服务API:** 从API version 12开始,该接口支持在原子化服务中使用。
594
595**系统能力**:SystemCapability.FileManagement.PhotoAccessHelper.Core
596
597**返回值:**
598
599| 类型                | 说明                    |
600| ------------------- | ----------------------- |
601| Promise&lt;void&gt; | Promise对象,返回void。 |
602
603**错误码:**
604
605接口抛出错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)和[文件管理错误码](../apis-core-file-kit/errorcode-filemanagement.md)。
606
607| 错误码ID | 错误信息                                                     |
608| -------- | ------------------------------------------------------------ |
609| 401      | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types; 3. Parameter verification failed. |
610| 201      | Permission denied.                                           |
611| 14000011 | Internal system error.                                        |
612
613**示例:**
614
615```ts
616import { dataSharePredicates } from '@kit.ArkData';
617import { photoAccessHelper } from '@kit.MediaLibraryKit';
618
619async function example() {
620  console.info('commitModifyDemo');
621  let predicates: dataSharePredicates.DataSharePredicates = new dataSharePredicates.DataSharePredicates();
622  let fetchOption: photoAccessHelper.FetchOptions = {
623    fetchColumns: ['title'],
624    predicates: predicates
625  };
626  let fetchResult: sendablePhotoAccessHelper.FetchResult<sendablePhotoAccessHelper.PhotoAsset> = await phAccessHelper.getAssets(fetchOption);
627  let photoAsset: sendablePhotoAccessHelper.PhotoAsset = await fetchResult.getFirstObject();
628  let title: string = photoAccessHelper.PhotoKeys.TITLE.toString();
629  let photoAssetTitle: photoAccessHelper.MemberType = photoAsset.get(title);
630  console.info('photoAsset get photoAssetTitle = ', photoAssetTitle);
631  photoAsset.set(title, 'newTitle3');
632  try {
633    await photoAsset.commitModify();
634    let newPhotoAssetTitle: photoAccessHelper.MemberType = photoAsset.get(title);
635    console.info('photoAsset get newPhotoAssetTitle = ', newPhotoAssetTitle);
636  } catch (err) {
637    console.error(`commitModify failed. error: ${err.code}, ${err.message}`);
638  }
639}
640```
641
642### getThumbnail
643
644getThumbnail(size?: image.Size): Promise&lt;image.PixelMap&gt;
645
646获取文件的缩略图,传入缩略图尺寸,使用Promise方式返回异步结果。
647
648**需要权限**:ohos.permission.READ_IMAGEVIDEO
649
650**系统能力**:SystemCapability.FileManagement.PhotoAccessHelper.Core
651
652**参数:**
653
654| 参数名 | 类型                                                  | 必填 | 说明         |
655| ------ | ----------------------------------------------------- | ---- | ------------ |
656| size   | [image.Size](../apis-image-kit/js-apis-image.md#size) | 否   | 缩略图尺寸。 |
657
658**返回值:**
659
660| 类型                                                         | 说明                                |
661| ------------------------------------------------------------ | ----------------------------------- |
662| Promise&lt;[image.PixelMap](../apis-image-kit/js-apis-image.md#pixelmap7)&gt; | Promise对象,返回缩略图的PixelMap。 |
663
664**错误码:**
665
666接口抛出错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)和[文件管理错误码](../apis-core-file-kit/errorcode-filemanagement.md)。
667
668| 错误码ID | 错误信息                                                     |
669| -------- | ------------------------------------------------------------ |
670| 401      | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types; 3. Parameter verification failed. |
671| 201      | Permission denied.                                           |
672| 14000011 | Internal system error.                                        |
673
674**示例:**
675
676```ts
677import { dataSharePredicates } from '@kit.ArkData';
678import { image } from '@kit.ImageKit';
679import { BusinessError } from '@kit.BasicServicesKit';
680import { photoAccessHelper } from '@kit.MediaLibraryKit';
681
682async function example() {
683  console.info('getThumbnailDemo');
684  let predicates: dataSharePredicates.DataSharePredicates = new dataSharePredicates.DataSharePredicates();
685  let fetchOption: photoAccessHelper.FetchOptions = {
686    fetchColumns: [],
687    predicates: predicates
688  };
689  let size: image.Size = { width: 720, height: 720 };
690  let fetchResult: sendablePhotoAccessHelper.FetchResult<sendablePhotoAccessHelper.PhotoAsset> = await phAccessHelper.getAssets(fetchOption);
691  let asset = await fetchResult.getFirstObject();
692  console.info('asset displayName = ', asset.displayName);
693  asset.getThumbnail(size).then((pixelMap) => {
694    console.info('getThumbnail successful ' + pixelMap);
695  }).catch((err: BusinessError) => {
696    console.error(`getThumbnail fail with error: ${err.code}, ${err.message}`);
697  });
698}
699```
700
701## FetchResult
702
703文件检索结果集。
704
705### getCount
706
707getCount(): number
708
709获取文件检索结果中的文件总数。
710
711**系统能力**:SystemCapability.FileManagement.PhotoAccessHelper.Core
712
713**返回值:**
714
715| 类型   | 说明               |
716| ------ | ------------------ |
717| number | 检索到的文件总数。 |
718
719**错误码:**
720
721接口抛出错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)和[文件管理错误码](../apis-core-file-kit/errorcode-filemanagement.md)。
722
723| 错误码ID | 错误信息                                                     |
724| -------- | ------------------------------------------------------------ |
725| 14000011 | Internal system error.                                        |
726
727**示例:**
728
729```ts
730import { dataSharePredicates } from '@kit.ArkData';
731import { photoAccessHelper } from '@kit.MediaLibraryKit';
732
733async function example() {
734  console.info('getCountDemo');
735  let predicates: dataSharePredicates.DataSharePredicates = new dataSharePredicates.DataSharePredicates();
736  let fetchOption: photoAccessHelper.FetchOptions = {
737    fetchColumns: [],
738    predicates: predicates
739  };
740  let fetchResult: sendablePhotoAccessHelper.FetchResult<sendablePhotoAccessHelper.PhotoAsset> = await phAccessHelper.getAssets(fetchOption);
741  let fetchCount = fetchResult.getCount();
742  console.info('fetchCount = ', fetchCount);
743}
744```
745
746### isAfterLast
747
748isAfterLast(): boolean
749
750检查结果集是否指向最后一行。
751
752**系统能力**:SystemCapability.FileManagement.PhotoAccessHelper.Core
753
754**返回值:**
755
756| 类型    | 说明                                                        |
757| ------- | ----------------------------------------------------------- |
758| boolean | 当读到最后一条记录后,后续没有记录返回true,否则返回false。 |
759
760**错误码:**
761
762接口抛出错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)和[文件管理错误码](../apis-core-file-kit/errorcode-filemanagement.md)。
763
764| 错误码ID | 错误信息                                                     |
765| -------- | ------------------------------------------------------------ |
766| 14000011 | Internal system error.                                        |
767
768**示例:**
769
770```ts
771import { dataSharePredicates } from '@kit.ArkData';
772import { photoAccessHelper } from '@kit.MediaLibraryKit';
773
774async function example() {
775  let predicates: dataSharePredicates.DataSharePredicates = new dataSharePredicates.DataSharePredicates();
776  let fetchOption: photoAccessHelper.FetchOptions = {
777    fetchColumns: [],
778    predicates: predicates
779  };
780  let fetchResult: sendablePhotoAccessHelper.FetchResult<sendablePhotoAccessHelper.PhotoAsset> = await phAccessHelper.getAssets(fetchOption);
781  let fetchCount = fetchResult.getCount();
782  console.info('count:' + fetchCount);
783  let photoAsset: sendablePhotoAccessHelper.PhotoAsset = await fetchResult.getLastObject();
784  if (fetchResult.isAfterLast()) {
785    console.info('photoAsset isAfterLast displayName = ', photoAsset.displayName);
786  } else {
787    console.info('photoAsset not isAfterLast.');
788  }
789}
790```
791
792### close
793
794close(): void
795
796释放FetchResult实例并使其失效。无法调用其他方法。
797
798**系统能力**:SystemCapability.FileManagement.PhotoAccessHelper.Core
799
800**错误码:**
801
802接口抛出错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)和[文件管理错误码](../apis-core-file-kit/errorcode-filemanagement.md)。
803
804| 错误码ID | 错误信息                                                     |
805| -------- | ------------------------------------------------------------ |
806| 14000011 | Internal system error.                                        |
807
808**示例:**
809
810```ts
811import { dataSharePredicates } from '@kit.ArkData';
812import { photoAccessHelper } from '@kit.MediaLibraryKit';
813
814async function example() {
815  console.info('fetchResultCloseDemo');
816  let predicates: dataSharePredicates.DataSharePredicates = new dataSharePredicates.DataSharePredicates();
817  let fetchOption: photoAccessHelper.FetchOptions = {
818    fetchColumns: [],
819    predicates: predicates
820  };
821  try {
822    let fetchResult: sendablePhotoAccessHelper.FetchResult<sendablePhotoAccessHelper.PhotoAsset> = await phAccessHelper.getAssets(fetchOption);
823    fetchResult.close();
824    console.info('close succeed.');
825  } catch (err) {
826    console.error(`close fail. error: ${err.code}, ${err.message}`);
827  }
828}
829```
830
831### getFirstObject
832
833getFirstObject(): Promise&lt;T&gt;
834
835获取文件检索结果中的第一个文件资产。此方法使用Promise方式来异步返回。
836
837**系统能力**:SystemCapability.FileManagement.PhotoAccessHelper.Core
838
839**返回值:**
840
841| 类型             | 说明                                  |
842| ---------------- | ------------------------------------- |
843| Promise&lt;T&gt; | Promise对象,返回结果集中第一个对象。 |
844
845**错误码:**
846
847接口抛出错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)和[文件管理错误码](../apis-core-file-kit/errorcode-filemanagement.md)。
848
849| 错误码ID | 错误信息                                                     |
850| -------- | ------------------------------------------------------------ |
851| 14000011 | Internal system error.                                        |
852
853**示例:**
854
855```ts
856import { dataSharePredicates } from '@kit.ArkData';
857import { photoAccessHelper } from '@kit.MediaLibraryKit';
858
859async function example() {
860  console.info('getFirstObjectDemo');
861  let predicates: dataSharePredicates.DataSharePredicates = new dataSharePredicates.DataSharePredicates();
862  let fetchOption: photoAccessHelper.FetchOptions = {
863    fetchColumns: [],
864    predicates: predicates
865  };
866  let fetchResult: sendablePhotoAccessHelper.FetchResult<sendablePhotoAccessHelper.PhotoAsset> = await phAccessHelper.getAssets(fetchOption);
867  let photoAsset: sendablePhotoAccessHelper.PhotoAsset = await fetchResult.getFirstObject();
868  console.info('photoAsset displayName: ', photoAsset.displayName);
869}
870```
871
872### getNextObject
873
874getNextObject(): Promise&lt;T&gt;
875
876获取文件检索结果中的下一个文件资产。此方法使用Promise方式来异步返回。
877在调用此方法之前,必须使用[isAfterLast()](#isafterlast)来检查当前位置是否为最后一行。
878
879**系统能力**:SystemCapability.FileManagement.PhotoAccessHelper.Core
880
881**返回值:**
882
883| 类型             | 说明                                  |
884| ---------------- | ------------------------------------- |
885| Promise&lt;T&gt; | Promise对象,返回结果集中下一个对象。 |
886
887**错误码:**
888
889接口抛出错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)和[文件管理错误码](../apis-core-file-kit/errorcode-filemanagement.md)。
890
891| 错误码ID | 错误信息                                                     |
892| -------- | ------------------------------------------------------------ |
893| 14000011 | Internal system error.                                        |
894
895**示例:**
896
897```ts
898import { dataSharePredicates } from '@kit.ArkData';
899import { photoAccessHelper } from '@kit.MediaLibraryKit';
900
901async function example() {
902  console.info('getNextObjectDemo');
903  let predicates: dataSharePredicates.DataSharePredicates = new dataSharePredicates.DataSharePredicates();
904  let fetchOption: photoAccessHelper.FetchOptions = {
905    fetchColumns: [],
906    predicates: predicates
907  };
908  let fetchResult: sendablePhotoAccessHelper.FetchResult<sendablePhotoAccessHelper.PhotoAsset> = await phAccessHelper.getAssets(fetchOption);
909  await fetchResult.getFirstObject();
910  let photoAsset: sendablePhotoAccessHelper.PhotoAsset = await fetchResult.getNextObject();
911  console.info('photoAsset displayName: ', photoAsset.displayName);
912}
913```
914
915### getLastObject
916
917getLastObject(): Promise&lt;T&gt;
918
919获取文件检索结果中的最后一个文件资产。此方法使用Promise方式来返回。
920
921**系统能力**:SystemCapability.FileManagement.PhotoAccessHelper.Core
922
923**返回值:**
924
925| 类型             | 说明                                    |
926| ---------------- | --------------------------------------- |
927| Promise&lt;T&gt; | Promise对象,返回结果集中最后一个对象。 |
928
929**错误码:**
930
931接口抛出错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)和[文件管理错误码](../apis-core-file-kit/errorcode-filemanagement.md)。
932
933| 错误码ID | 错误信息                                                     |
934| -------- | ------------------------------------------------------------ |
935| 14000011 | Internal system error.                                        |
936
937**示例:**
938
939```ts
940import { dataSharePredicates } from '@kit.ArkData';
941import { photoAccessHelper } from '@kit.MediaLibraryKit';
942
943async function example() {
944  console.info('getLastObjectDemo');
945  let predicates: dataSharePredicates.DataSharePredicates = new dataSharePredicates.DataSharePredicates();
946  let fetchOption: photoAccessHelper.FetchOptions = {
947    fetchColumns: [],
948    predicates: predicates
949  };
950  let fetchResult: sendablePhotoAccessHelper.FetchResult<sendablePhotoAccessHelper.PhotoAsset> = await phAccessHelper.getAssets(fetchOption);
951  let photoAsset: sendablePhotoAccessHelper.PhotoAsset = await fetchResult.getLastObject();
952  console.info('photoAsset displayName: ', photoAsset.displayName);
953}
954```
955
956### getObjectByPosition
957
958getObjectByPosition(index: number): Promise&lt;T&gt;
959
960获取文件检索结果中具有指定索引的文件资产。此方法使用Promise形式返回文件Asset。
961
962**系统能力**:SystemCapability.FileManagement.PhotoAccessHelper.Core
963
964**参数:**
965
966| 参数名 | 类型   | 必填 | 说明                          |
967| ------ | ------ | ---- | ----------------------------- |
968| index  | number | 是   | 要获取的文件的索引,从0开始。 |
969
970**返回值:**
971
972| 类型             | 说明                                          |
973| ---------------- | --------------------------------------------- |
974| Promise&lt;T&gt; | Promise对象,返回结果集中指定索引的一个对象。 |
975
976**错误码:**
977
978接口抛出错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)和[文件管理错误码](../apis-core-file-kit/errorcode-filemanagement.md)。
979
980| 错误码ID | 错误信息                                                     |
981| -------- | ------------------------------------------------------------ |
982| 401      | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types; 3. Parameter verification failed. |
983| 14000011 | Internal system error.                                        |
984
985**示例:**
986
987```ts
988import { dataSharePredicates } from '@kit.ArkData';
989import { photoAccessHelper } from '@kit.MediaLibraryKit';
990
991async function example() {
992  console.info('getObjectByPositionDemo');
993  let predicates: dataSharePredicates.DataSharePredicates = new dataSharePredicates.DataSharePredicates();
994  let fetchOption: photoAccessHelper.FetchOptions = {
995    fetchColumns: [],
996    predicates: predicates
997  };
998  let fetchResult: sendablePhotoAccessHelper.FetchResult<sendablePhotoAccessHelper.PhotoAsset> = await phAccessHelper.getAssets(fetchOption);
999  let photoAsset: sendablePhotoAccessHelper.PhotoAsset = await fetchResult.getObjectByPosition(0);
1000  console.info('photoAsset displayName: ', photoAsset.displayName);
1001}
1002```
1003
1004### getAllObjects
1005
1006getAllObjects(): Promise&lt;Array&lt;T&gt;&gt;
1007
1008获取文件检索结果中的所有文件资产。此方法使用Promise方式来异步返回。
1009
1010**系统能力**:SystemCapability.FileManagement.PhotoAccessHelper.Core
1011
1012**返回值:**
1013
1014| 类型                          | 说明                                        |
1015| ----------------------------- | ------------------------------------------- |
1016| Promise&lt;Array&lt;T&gt;&gt; | Promise对象,返回结果集中所有文件资产数组。 |
1017
1018**错误码:**
1019
1020接口抛出错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)和[文件管理错误码](../apis-core-file-kit/errorcode-filemanagement.md)。
1021
1022| 错误码ID | 错误信息                                                     |
1023| -------- | ------------------------------------------------------------ |
1024| 14000011 | Internal system error.                                        |
1025
1026**示例:**
1027
1028```ts
1029import { dataSharePredicates } from '@kit.ArkData';
1030import { photoAccessHelper } from '@kit.MediaLibraryKit';
1031
1032async function example() {
1033  console.info('getAllObjectDemo');
1034  let predicates: dataSharePredicates.DataSharePredicates = new dataSharePredicates.DataSharePredicates();
1035  let fetchOption: photoAccessHelper.FetchOptions = {
1036    fetchColumns: [],
1037    predicates: predicates
1038  };
1039  let fetchResult: sendablePhotoAccessHelper.FetchResult<sendablePhotoAccessHelper.PhotoAsset> = await phAccessHelper.getAssets(fetchOption);
1040  let photoAssetList: Array<sendablePhotoAccessHelper.PhotoAsset> = await fetchResult.getAllObjects();
1041  console.info('photoAssetList length: ', photoAssetList.length);
1042}
1043```
1044
1045## Album
1046
1047实体相册
1048
1049### 属性
1050
1051**系统能力**:SystemCapability.FileManagement.PhotoAccessHelper.Core
1052
1053| 名称         | 类型                          | 只读                         | 可选 | 说明             |
1054| ------------ | ----------------------------- | ---------------------------- | ---- | ---------------- |
1055| albumType    | [AlbumType](#albumtype)       | 是                           | 否   | 相册类型。       |
1056| albumSubtype | [AlbumSubtype](#albumsubtype) | 是                           | 否   | 相册子类型。     |
1057| albumName    | string                        | 用户相册可写,预置相册不可写 | 否   | 相册名称。       |
1058| albumUri     | string                        | 是                           | 否   | 相册Uri。        |
1059| count        | number                        | 是                           | 否   | 相册中文件数量。 |
1060| coverUri     | string                        | 是                           | 否   | 封面文件Uri。    |
1061| imageCount   | number                        | 是                           | 是   | 相册中图片数量。 |
1062| videoCount   | number                        | 是                           | 是   | 相册中视频数量。 |
1063
1064### convertToPhotoAlbum
1065
1066convertToPhotoAlbum(): photoAccessHelper.Album
1067
1068将Sendable类型Album转换为非Sendable类型Album。
1069
1070**需要权限**:ohos.permission.READ_IMAGEVIDEO
1071
1072**系统能力**:SystemCapability.FileManagement.PhotoAccessHelper.Core
1073
1074| 类型                    | 说明                                                      |
1075| ----------------------- | --------------------------------------------------------- |
1076| photoAccessHelper.Album | 非Sendable类型[Album](js-apis-photoAccessHelper.md#album) |
1077
1078**错误码:**
1079
1080接口抛出错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)和[文件管理错误码](../apis-core-file-kit/errorcode-filemanagement.md)。
1081
1082| 错误码ID | 错误信息                                                     |
1083| -------- | ------------------------------------------------------------ |
1084| 201      | Permission denied.                                           |
1085| 14000011 | Internal system error.                                        |
1086
1087**示例:**
1088
1089```ts
1090import { dataSharePredicates } from '@kit.ArkData';
1091import { BusinessError } from '@kit.BasicServicesKit';
1092import { photoAccessHelper } from '@kit.MediaLibraryKit';
1093
1094async function example() {
1095  console.info('convertToPhotoAlbumDemo');
1096  let predicates: dataSharePredicates.DataSharePredicates = new dataSharePredicates.DataSharePredicates();
1097  let albumFetchOptions: photoAccessHelper.FetchOptions = {
1098    fetchColumns: [],
1099    predicates: predicates
1100  };
1101  let fetchOption: photoAccessHelper.FetchOptions = {
1102    fetchColumns: [],
1103    predicates: predicates
1104  };
1105  let albumList: sendablePhotoAccessHelper.FetchResult<sendablePhotoAccessHelper.Album> = await phAccessHelper.getAlbums(sendablePhotoAccessHelper.AlbumType.USER, sendablePhotoAccessHelper.AlbumSubtype.USER_GENERIC, albumFetchOptions);
1106  let sendableAlbum: sendablePhotoAccessHelper.Album = await albumList.getFirstObject();
1107  let album: photoAccessHelper.Album = sendableAlbum.convertToPhotoAlbum();
1108  album.getAssets(fetchOption).then((albumFetchResult) => {
1109    console.info('convertToPhotoAlbum successfully, getCount: ' + albumFetchResult.getCount());
1110  }).catch((err: BusinessError) => {
1111    console.error(`convertToPhotoAlbum failed with error: ${err.code}, ${err.message}`);
1112  });
1113}
1114```
1115
1116### getAssets
1117
1118getAssets(options: FetchOptions): Promise&lt;FetchResult&lt;PhotoAsset&gt;&gt;
1119
1120获取相册中的文件。该方法使用Promise来返回文件。
1121
1122**需要权限**:ohos.permission.READ_IMAGEVIDEO
1123
1124**系统能力**:SystemCapability.FileManagement.PhotoAccessHelper.Core
1125
1126**参数:**
1127
1128| 参数名  | 类型                                                      | 必填 | 说明       |
1129| ------- | --------------------------------------------------------- | ---- | ---------- |
1130| options | [FetchOptions](js-apis-photoAccessHelper.md#fetchoptions) | 是   | 检索选项。 |
1131
1132**返回值:**
1133
1134| 类型                                                         | 说明                                    |
1135| ------------------------------------------------------------ | --------------------------------------- |
1136| Promise&lt;[FetchResult](#fetchresult)&lt;[PhotoAsset](#photoasset)&gt;&gt; | Promise对象,返回图片和视频数据结果集。 |
1137
1138**错误码:**
1139
1140接口抛出错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)和[文件管理错误码](../apis-core-file-kit/errorcode-filemanagement.md)。
1141
1142| 错误码ID | 错误信息                                                     |
1143| -------- | ------------------------------------------------------------ |
1144| 401      | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types; 3. Parameter verification failed. |
1145| 201      | Permission denied.                                           |
1146| 13900020 | Invalid argument.                                            |
1147| 14000011 | Internal system error.                                        |
1148
1149**示例:**
1150
1151```ts
1152import { dataSharePredicates } from '@kit.ArkData';
1153import { BusinessError } from '@kit.BasicServicesKit';
1154import { photoAccessHelper } from '@kit.MediaLibraryKit';
1155
1156async function example() {
1157  console.info('albumGetAssetsDemoPromise');
1158  let predicates: dataSharePredicates.DataSharePredicates = new dataSharePredicates.DataSharePredicates();
1159  let albumFetchOptions: photoAccessHelper.FetchOptions = {
1160    fetchColumns: [],
1161    predicates: predicates
1162  };
1163  let fetchOption: photoAccessHelper.FetchOptions = {
1164    fetchColumns: [],
1165    predicates: predicates
1166  };
1167  let albumList: sendablePhotoAccessHelper.FetchResult<sendablePhotoAccessHelper.Album> = await phAccessHelper.getAlbums(sendablePhotoAccessHelper.AlbumType.USER, sendablePhotoAccessHelper.AlbumSubtype.USER_GENERIC, albumFetchOptions);
1168  let album: sendablePhotoAccessHelper.Album = await albumList.getFirstObject();
1169  album.getAssets(fetchOption).then((albumFetchResult) => {
1170    console.info('album getAssets successfully, getCount: ' + albumFetchResult.getCount());
1171  }).catch((err: BusinessError) => {
1172    console.error(`album getAssets failed with error: ${err.code}, ${err.message}`);
1173  });
1174}
1175```
1176
1177### commitModify
1178
1179commitModify(): Promise&lt;void&gt;
1180
1181更新相册属性修改到数据库中。该方法使用Promise来返回结果。
1182
1183**需要权限**:ohos.permission.WRITE_IMAGEVIDEO
1184
1185**系统能力**:SystemCapability.FileManagement.PhotoAccessHelper.Core
1186
1187**返回值:**
1188
1189| 类型                | 说明                    |
1190| ------------------- | ----------------------- |
1191| Promise&lt;void&gt; | Promise对象,返回void。 |
1192
1193**错误码:**
1194
1195接口抛出错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)和[文件管理错误码](../apis-core-file-kit/errorcode-filemanagement.md)。
1196
1197| 错误码ID | 错误信息                                                     |
1198| -------- | ------------------------------------------------------------ |
1199| 201      | Permission denied.                                           |
1200| 14000011 | Internal system error.                                        |
1201
1202**示例:**
1203
1204```ts
1205import { dataSharePredicates } from '@kit.ArkData';
1206import { BusinessError } from '@kit.BasicServicesKit';
1207import { photoAccessHelper } from '@kit.MediaLibraryKit';
1208
1209async function example() {
1210  console.info('albumCommitModifyDemo');
1211  let predicates: dataSharePredicates.DataSharePredicates = new dataSharePredicates.DataSharePredicates();
1212  let albumFetchOptions: photoAccessHelper.FetchOptions = {
1213    fetchColumns: [],
1214    predicates: predicates
1215  };
1216  let albumList: sendablePhotoAccessHelper.FetchResult<sendablePhotoAccessHelper.Album> = await phAccessHelper.getAlbums(sendablePhotoAccessHelper.AlbumType.USER, sendablePhotoAccessHelper.AlbumSubtype.USER_GENERIC, albumFetchOptions);
1217  let album: sendablePhotoAccessHelper.Album = await albumList.getFirstObject();
1218  album.albumName = 'hello';
1219  album.commitModify().then(() => {
1220    console.info('commitModify successfully');
1221  }).catch((err: BusinessError) => {
1222    console.error(`commitModify failed with error: ${err.code}, ${err.message}`);
1223  });
1224}
1225```
1226
1227## PhotoType
1228
1229枚举,媒体文件类型。
1230
1231**原子化服务API:** 从API version 12开始,该接口支持在原子化服务中使用。
1232
1233**系统能力**:SystemCapability.FileManagement.PhotoAccessHelper.Core
1234
1235| 名称  | 值   | 说明   |
1236| ----- | ---- | ------ |
1237| IMAGE | 1    | 图片。 |
1238| VIDEO | 2    | 视频。 |
1239
1240## PhotoSubtype<sup>14+</sup>
1241
1242枚举,不同[PhotoAsset](#photoasset)的类型。
1243
1244**原子化服务API:** 从API version 14开始,该接口支持在原子化服务中使用。
1245
1246**系统能力**:SystemCapability.FileManagement.PhotoAccessHelper.Core
1247
1248| 名称  |  值 |  说明 |
1249| ----- |  ---- |  ---- |
1250| DEFAULT |  0 |  默认照片类型。 |
1251| MOVING_PHOTO |  3 |  动态照片文件类型。 |
1252| BURST |  4 |  连拍照片文件类型。 |
1253
1254## DynamicRangeType<sup>14+</sup>
1255
1256枚举,媒体文件的动态范围类型。
1257
1258**系统能力**: SystemCapability.FileManagement.PhotoAccessHelper.Core
1259
1260| 名称  |  值 |  说明 |
1261| ----- |  ---- |  ---- |
1262| SDR |  0 |  标准动态范围类型。|
1263| HDR |  1 |  高动态范围类型。  |
1264
1265## AlbumType
1266
1267枚举,相册类型,表示是用户相册还是系统预置相册。
1268
1269**系统能力**:SystemCapability.FileManagement.PhotoAccessHelper.Core
1270
1271| 名称   | 值   | 说明           |
1272| ------ | ---- | -------------- |
1273| USER   | 0    | 用户相册。     |
1274| SYSTEM | 1024 | 系统预置相册。 |
1275
1276## AlbumSubtype
1277
1278枚举,相册子类型,表示具体的相册类型。
1279
1280**系统能力**:SystemCapability.FileManagement.PhotoAccessHelper.Core
1281
1282| 名称          | 值         | 说明       |
1283| ------------- | ---------- | ---------- |
1284| USER\_GENERIC | 1          | 用户相册。 |
1285| FAVORITE      | 1025       | 收藏夹。   |
1286| VIDEO         | 1026       | 视频相册。 |
1287| IMAGE         | 1031       | 图片相册。 |
1288| ANY           | 2147483647 | 任意相册。 |
1289