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