1# @ohos.file.sendablePhotoAccessHelper (Album Management Based on a Sendable object) 2 3The **sendablePhotoAccessHelper** module provides APIs for album management, including creating an album and accessing and modifying media data in an album, based on a sendable object. 4 5> **NOTE** 6> 7> The initial APIs of this module are supported since API version 12. Newly added APIs will be marked with a superscript to indicate their earliest API version. 8 9## Modules to Import 10 11```ts 12import { sendablePhotoAccessHelper } from '@kit.MediaLibraryKit'; 13``` 14 15## sendablePhotoAccessHelper.getPhotoAccessHelper 16 17getPhotoAccessHelper(context: Context): PhotoAccessHelper 18 19Obtains a **PhotoAccessHelper** instance, which can be used for accessing and modifying the media files in an album. 20 21**Model restriction**: This API can be used only in the stage model. 22 23**Atomic service API**: This API can be used in atomic services since API version 12. 24 25**System capability**: SystemCapability.FileManagement.PhotoAccessHelper.Core 26 27**Parameters** 28 29| Name | Type | Mandatory| Description | 30| ------- | ------------------------------------------------------------ | ---- | -------------------------- | 31| context | [Context](../apis-ability-kit/js-apis-inner-application-context.md) | Yes | Context of the ability instance.| 32 33**Return value** 34 35| Type | Description | 36| --------------------------------------- | :------------------- | 37| [PhotoAccessHelper](#photoaccesshelper) | **PhotoAccessHelper** instance obtained.| 38 39**Error codes** 40 41For details about the error codes, see [Universal Error Codes](../errorcode-universal.md). 42 43| ID| Error Message | 44| -------- | ------------------------------------------------------------ | 45| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types; 3. Parameter verification failed. | 46 47**Example** 48 49```ts 50// The phAccessHelper instance obtained is a global object. It is used by default in subsequent operations. If the code snippet is not added, an error will be reported indicating that phAccessHelper is not defined. 51let context = getContext(this); 52let phAccessHelper = sendablePhotoAccessHelper.getPhotoAccessHelper(context); 53``` 54 55## PhotoAccessHelper 56 57### getAssets 58 59getAssets(options: FetchOptions): Promise<FetchResult<PhotoAsset>> 60 61Obtains media assets. This API uses a promise to return the result. 62 63**System capability**: SystemCapability.FileManagement.PhotoAccessHelper.Core 64 65**Required permissions**: ohos.permission.READ_IMAGEVIDEO 66 67If the caller does not have the ohos.permission.READ_IMAGEVIDEO permission, use Picker to access the file and then call this API based on the URI obtained by Picker. For details, see [Obtaining an Image or Video by URI](../../media/medialibrary/photoAccessHelper-photoviewpicker.md#obtaining-an-image-or-video-by-uri). 68 69**Parameters** 70 71| Name | Type | Mandatory| Description | 72| ------- | --------------------------------------------------------- | ---- | -------------------- | 73| options | [FetchOptions](js-apis-photoAccessHelper.md#fetchoptions) | Yes | Options for fetching the media assets. | 74 75**Return value** 76 77| Type | Description | 78| ------------------------------------------------------------ | ------------------------------------------------- | 79| Promise<[FetchResult](#fetchresult)<[PhotoAsset](#photoasset)>> | Promise used to return the media assets obtained. | 80 81**Error codes** 82 83For details about the error codes, see [Universal Error Codes](../errorcode-universal.md) and [File Management Error Codes](../apis-core-file-kit/errorcode-filemanagement.md). 84 85| ID| Error Message | 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**Example** 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<FetchResult<PhotoAsset>> 124 125Obtains burst assets. This API uses a promise to return the result. 126 127**System capability**: SystemCapability.FileManagement.PhotoAccessHelper.Core 128 129**Required permissions**: ohos.permission.READ_IMAGEVIDEO 130 131**Parameters** 132 133| Name | Type | Mandatory| Description | 134| -------- | --------------------------------------------------------- | ---- | ------------------------------------------------------------ | 135| burstKey | string | Yes | Universally Unique Identifier (UUID) of a group of burst photos, that is, **BURST_KEY** of [PhotoKeys](js-apis-photoAccessHelper.md#photokeys).| 136| options | [FetchOptions](js-apis-photoAccessHelper.md#fetchoptions) | Yes | Options for fetching the burst photos. | 137 138**Return value** 139 140| Type | Description | 141| ------------------------------------------------------------ | ------------------------------------------------- | 142| Promise<[FetchResult](#fetchresult)<[PhotoAsset](#photoasset)>> | Promise used to return the burst photos obtained. | 143 144**Error codes** 145 146For details about the error codes, see [Universal Error Codes](../errorcode-universal.md) and [File Management Error Codes](../apis-core-file-kit/errorcode-filemanagement.md). 147 148| ID| Error Message | 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**Example** 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 is a 36-bit UUID, which can be obtained from 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<string> 194 195Creates a media asset with the specified file type, file name extension, and options. This API uses a promise to return the result. 196 197If the caller does not have the ohos.permission.WRITE_IMAGEVIDEO permission, you can create a media asset by using a security component. For details, see [Creating a Media Asset Using a Security Component](../../media/medialibrary/photoAccessHelper-savebutton.md). 198 199**Atomic service API**: This API can be used in atomic services since API version 12. 200 201**System capability**: SystemCapability.FileManagement.PhotoAccessHelper.Core 202 203**Required permissions**: ohos.permission.WRITE_IMAGEVIDEO 204 205**Parameters** 206 207| Name | Type | Mandatory| Description | 208| --------- | ----------------------------------------------------------- | ---- | ------------------------------------ | 209| photoType | [PhotoType](#phototype) | Yes | Type of the file to create, which can be **IMAGE** or **VIDEO**.| 210| extension | string | Yes | File name extension, for example, **'jpg'**. | 211| options | [CreateOptions](js-apis-photoAccessHelper.md#createoptions) | No | Options for creating the asset, for example, **{title: 'testPhoto'}**. | 212 213**Return value** 214 215| Type | Description | 216| --------------------- | ---------------------------------------- | 217| Promise<string> | Promise used to return the URI of the created asset. | 218 219**Error codes** 220 221For details about the error codes, see [Universal Error Codes](../errorcode-universal.md) and [File Management Error Codes](../apis-core-file-kit/errorcode-filemanagement.md). 222 223| ID| Error Message | 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**Example** 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<FetchResult<Album>> 253 254Obtains albums based on the specified options and album type. This API uses a promise to return the result. 255 256Before the operation, ensure that the albums to obtain exist. 257 258**System capability**: SystemCapability.FileManagement.PhotoAccessHelper.Core 259 260**Required permissions**: ohos.permission.READ_IMAGEVIDEO 261 262**Parameters** 263 264| Name | Type | Mandatory| Description | 265| ------- | --------------------------------------------------------- | ---- | -------------------------------------- | 266| type | [AlbumType](#albumtype) | Yes | Type of the albums to obtain. | 267| subtype | [AlbumSubtype](#albumsubtype) | Yes | Subtype of the album. | 268| options | [FetchOptions](js-apis-photoAccessHelper.md#fetchoptions) | No | Options for fetching the albums. If this parameter is not specified, the albums are obtained based on the album type by default.| 269 270**Return value** 271 272| Type | Description | 273| ------------------------------------------------------------ | ------------------------------------------- | 274| Promise<[FetchResult](#fetchresult)<[Album](#album)>> | Promise used to return the albums obtained. | 275 276**Error codes** 277 278For details about the error codes, see [Universal Error Codes](../errorcode-universal.md) and [File Management Error Codes](../apis-core-file-kit/errorcode-filemanagement.md). 279 280| ID| Error Message | 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**Example** 288 289```ts 290import { dataSharePredicates } from '@kit.ArkData'; 291import { BusinessError } from '@kit.BasicServicesKit'; 292 293async function example() { 294 // Obtain the album named 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<FetchResult<Album>> 319 320Obtains albums. This API uses a promise to return the result. 321 322Before the operation, ensure that the albums to obtain exist. 323 324**System capability**: SystemCapability.FileManagement.PhotoAccessHelper.Core 325 326**Required permissions**: ohos.permission.READ_IMAGEVIDEO 327 328**Parameters** 329 330| Name | Type | Mandatory| Description | 331| ------- | --------------------------------------------------------- | ---- | -------- | 332| options | [FetchOptions](js-apis-photoAccessHelper.md#fetchoptions) | Yes | Options for obtaining the albums.| 333 334**Return value** 335 336| Type | Description | 337| ------------------------------------------------------------ | ------------------------------------------- | 338| Promise<[FetchResult](#fetchresult)<[Album](#album)>> | Promise used to return the albums obtained. | 339 340**Error codes** 341 342For details about the error codes, see [Universal Error Codes](../errorcode-universal.md) and [File Management Error Codes](../apis-core-file-kit/errorcode-filemanagement.md). 343 344| ID| Error Message | 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**Example** 352 353```ts 354import { dataSharePredicates } from '@kit.ArkData'; 355import { BusinessError } from '@kit.BasicServicesKit'; 356 357async function example() { 358 // Obtain the album named 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<void> 383 384Releases this **PhotoAccessHelper** instance. This API uses a promise to return the result. 385 386Call this API when the **PhotoAccessHelper** instance is no longer required. 387 388**System capability**: SystemCapability.FileManagement.PhotoAccessHelper.Core 389 390**Return value** 391 392| Type | Description | 393| ------------------- | ----------------------- | 394| Promise<void> | Promise that returns no value.| 395 396**Error codes** 397 398For details about the error codes, see [Universal Error Codes](../errorcode-universal.md) and [File Management Error Codes](../apis-core-file-kit/errorcode-filemanagement.md). 399 400| ID| Error Message | 401| -------- | ------------------------------------------------------------ | 402| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types. | 403| 13900020 | Invalid argument. | 404| 14000011 | Internal system error | 405 406**Example** 407 408```ts 409async function example() { 410 console.info('releaseDemo'); 411 try { 412 console.info('use function...'); 413 } catch (err) { 414 console.error(`function error ...`); 415 }finally{ 416 try{ 417 phAccessHelper?.release(); 418 console.info(`release success`); 419 } catch(e){ 420 console.error(`release error :${e}`); 421 } 422 } 423} 424``` 425 426## PhotoAsset 427 428Provides APIs for encapsulating file asset attributes. 429 430### Properties 431 432**System capability**: SystemCapability.FileManagement.PhotoAccessHelper.Core 433 434| Name | Type | Read-Only| Optional| Description | 435| ----------- | ----------------------- | ---- | ---- | ------------------------------------------------------------ | 436| uri | string | Yes | No | Media asset URI, for example, **file://media/Photo/1/IMG_datetime_0001/displayName.jpg**. For details, see [Media File URI](../../file-management/user-file-uri-intro.md#media-file-uri).| 437| photoType | [PhotoType](#phototype) | Yes | No | Type of the file. | 438| displayName | string | Yes | No | File name, including the file name extension, to display. | 439 440### convertToPhotoAsset 441 442convertToPhotoAsset(): photoAccessHelper.PhotoAsset 443 444Converts a sendable **PhotoAsset** object to a non-sendable **PhotoAsset** object. 445 446**System capability**: SystemCapability.FileManagement.PhotoAccessHelper.Core 447 448**Return value** 449 450| Type | Description | 451| ---------------------------- | ------------------------------------------------------------ | 452| photoAccessHelper.PhotoAsset | [PhotoAsset](js-apis-photoAccessHelper.md#photoasset) object of the non-sendable type.| 453 454**Error codes** 455 456For details about the error codes, see [Universal Error Codes](../errorcode-universal.md) and [File Management Error Codes](../apis-core-file-kit/errorcode-filemanagement.md). 457 458| ID| Error Message | 459| -------- | ------------------------------------------------------------ | 460| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types; 3. Parameter verification failed. | 461| 13900020 | Invalid argument. | 462| 14000014 | Member is not a valid PhotoKey. | 463 464**Example** 465 466```ts 467import { dataSharePredicates } from '@kit.ArkData'; 468import { photoAccessHelper } from '@kit.MediaLibraryKit'; 469 470async function example() { 471 console.info('convertToPhotoAssetDemo'); 472 try { 473 let predicates: dataSharePredicates.DataSharePredicates = new dataSharePredicates.DataSharePredicates(); 474 let fetchOption: photoAccessHelper.FetchOptions = { 475 fetchColumns: ['title'], 476 predicates: predicates 477 }; 478 let fetchResult: sendablePhotoAccessHelper.FetchResult<sendablePhotoAccessHelper.PhotoAsset> = await phAccessHelper.getAssets(fetchOption); 479 let sendablePhotoAsset: sendablePhotoAccessHelper.PhotoAsset = await fetchResult.getFirstObject(); 480 let photoAsset: photoAccessHelper.PhotoAsset = sendablePhotoAsset.convertToPhotoAsset(); 481 console.log(`get no sendable uri success : ${photoAsset.uri}`); 482 } catch (err) { 483 console.error(`convertToPhotoAsset failed. error: ${err.code}, ${err.message}`); 484 } 485} 486``` 487 488### get 489 490get(member: string): MemberType 491 492Obtains a **PhotoAsset** member parameter. 493 494**System capability**: SystemCapability.FileManagement.PhotoAccessHelper.Core 495 496**Parameters** 497 498| Name| Type | Mandatory| Description | 499| ------ | ------ | ---- | ------------------------------------------------------------ | 500| member | string | Yes | Name of the member parameter to obtain. <br/>Except **'uri'**, **'media_type'**, **'subtype'**, and **'display_name'**, you must pass in [PhotoKeys](js-apis-photoAccessHelper.md#photokeys) in **fetchColumns**. For example, to obtain the title, pass in **fetchColumns: ['title']**. | 501 502**Return value** 503 504| Type | Description | 505| ----------------------------------------------------- | ---------------------------- | 506| [MemberType](js-apis-photoAccessHelper.md#membertype) | **PhotoAsset** member parameter obtained.| 507 508**Error codes** 509 510For details about the error codes, see [Universal Error Codes](../errorcode-universal.md) and [File Management Error Codes](../apis-core-file-kit/errorcode-filemanagement.md). 511 512| ID| Error Message | 513| -------- | ------------------------------------------------------------ | 514| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types; 3. Parameter verification failed. | 515| 13900020 | Invalid argument. | 516| 14000014 | Member is not a valid PhotoKey. | 517 518**Example** 519 520```ts 521import { dataSharePredicates } from '@kit.ArkData'; 522 523async function example() { 524 console.info('photoAssetGetDemo'); 525 try { 526 let predicates: dataSharePredicates.DataSharePredicates = new dataSharePredicates.DataSharePredicates(); 527 let fetchOption: photoAccessHelper.FetchOptions = { 528 fetchColumns: ['title'], 529 predicates: predicates 530 }; 531 let fetchResult: sendablePhotoAccessHelper.FetchResult<sendablePhotoAccessHelper.PhotoAsset> = await phAccessHelper.getAssets(fetchOption); 532 let photoAsset: sendablePhotoAccessHelper.PhotoAsset = await fetchResult.getFirstObject(); 533 let title: photoAccessHelper.PhotoKeys = photoAccessHelper.PhotoKeys.TITLE; 534 let photoAssetTitle: photoAccessHelper.MemberType = photoAsset.get(title.toString()); 535 console.info('photoAsset Get photoAssetTitle = ', photoAssetTitle); 536 } catch (err) { 537 console.error(`get failed. error: ${err.code}, ${err.message}`); 538 } 539} 540``` 541 542### set 543 544set(member: string, value: string): void 545 546Sets a **PhotoAsset** member parameter. 547 548**System capability**: SystemCapability.FileManagement.PhotoAccessHelper.Core 549 550**Parameters** 551 552| Name| Type | Mandatory| Description | 553| ------ | ------ | ---- | ------------------------------------------------------------ | 554| member | string | Yes | Name of the parameter to set, for example, [PhotoKeys](js-apis-photoAccessHelper.md#photokeys).TITLE.| 555| value | string | Yes | Value to set. Only the value of [PhotoKeys](js-apis-photoAccessHelper.md#photokeys).TITLE can be changed.| 556 557**Error codes** 558 559For details about the error codes, see [Universal Error Codes](../errorcode-universal.md) and [File Management Error Codes](../apis-core-file-kit/errorcode-filemanagement.md). 560 561| ID| Error Message | 562| -------- | ------------------------------------------------------------ | 563| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types; 3. Parameter verification failed. | 564| 13900020 | Invalid argument. | 565| 14000014 | Member is not a valid PhotoKey. | 566 567**Example** 568 569```ts 570import { dataSharePredicates } from '@kit.ArkData'; 571 572async function example() { 573 console.info('photoAssetSetDemo'); 574 try { 575 let predicates: dataSharePredicates.DataSharePredicates = new dataSharePredicates.DataSharePredicates(); 576 let fetchOption: photoAccessHelper.FetchOptions = { 577 fetchColumns: ['title'], 578 predicates: predicates 579 }; 580 let fetchResult: sendablePhotoAccessHelper.FetchResult<sendablePhotoAccessHelper.PhotoAsset> = await phAccessHelper.getAssets(fetchOption); 581 let photoAsset: sendablePhotoAccessHelper.PhotoAsset = await fetchResult.getFirstObject(); 582 let title: string = photoAccessHelper.PhotoKeys.TITLE.toString(); 583 photoAsset.set(title, 'newTitle'); 584 } catch (err) { 585 console.error(`set failed. error: ${err.code}, ${err.message}`); 586 } 587} 588``` 589 590### commitModify 591 592commitModify(): Promise<void> 593 594Commits the modification on the file metadata to the database. This API uses a promise to return the result. 595 596**Required permissions**: ohos.permission.WRITE_IMAGEVIDEO 597 598**Atomic service API**: This API can be used in atomic services since API version 12. 599 600**System capability**: SystemCapability.FileManagement.PhotoAccessHelper.Core 601 602**Return value** 603 604| Type | Description | 605| ------------------- | ----------------------- | 606| Promise<void> | Promise that returns no value.| 607 608**Error codes** 609 610For details about the error codes, see [Universal Error Codes](../errorcode-universal.md) and [File Management Error Codes](../apis-core-file-kit/errorcode-filemanagement.md). 611 612| ID| Error Message | 613| -------- | ------------------------------------------------------------ | 614| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types. | 615| 201 | Permission denied. | 616| 13900020 | Invalid argument. | 617| 14000001 | Invalid display name. | 618| 14000011 | Internal system error | 619 620**Example** 621 622```ts 623import { dataSharePredicates } from '@kit.ArkData'; 624 625async function example() { 626 console.info('commitModifyDemo'); 627 let predicates: dataSharePredicates.DataSharePredicates = new dataSharePredicates.DataSharePredicates(); 628 let fetchOption: photoAccessHelper.FetchOptions = { 629 fetchColumns: ['title'], 630 predicates: predicates 631 }; 632 let fetchResult: sendablePhotoAccessHelper.FetchResult<sendablePhotoAccessHelper.PhotoAsset> = await phAccessHelper.getAssets(fetchOption); 633 let photoAsset: sendablePhotoAccessHelper.PhotoAsset = await fetchResult.getFirstObject(); 634 let title: string = photoAccessHelper.PhotoKeys.TITLE.toString(); 635 let photoAssetTitle: photoAccessHelper.MemberType = photoAsset.get(title); 636 console.info('photoAsset get photoAssetTitle = ', photoAssetTitle); 637 photoAsset.set(title, 'newTitle3'); 638 try { 639 await photoAsset.commitModify(); 640 let newPhotoAssetTitle: photoAccessHelper.MemberType = photoAsset.get(title); 641 console.info('photoAsset get newPhotoAssetTitle = ', newPhotoAssetTitle); 642 } catch (err) { 643 console.error(`commitModify failed. error: ${err.code}, ${err.message}`); 644 } 645} 646``` 647 648### getThumbnail 649 650getThumbnail(size?: image.Size): Promise<image.PixelMap> 651 652Obtains the file thumbnail of the given size. This API uses a promise to return the result. 653 654**Required permissions**: ohos.permission.READ_IMAGEVIDEO 655 656**System capability**: SystemCapability.FileManagement.PhotoAccessHelper.Core 657 658**Parameters** 659 660| Name| Type | Mandatory| Description | 661| ------ | ----------------------------------------------------- | ---- | ------------ | 662| size | [image.Size](../apis-image-kit/js-apis-image.md#size) | No | Size of the thumbnail.| 663 664**Return value** 665 666| Type | Description | 667| ------------------------------------------------------------ | ----------------------------------- | 668| Promise<[image.PixelMap](../apis-image-kit/js-apis-image.md#pixelmap7)> | Promise used to return the PixelMap of the thumbnail.| 669 670**Error codes** 671 672For details about the error codes, see [Universal Error Codes](../errorcode-universal.md) and [File Management Error Codes](../apis-core-file-kit/errorcode-filemanagement.md). 673 674| ID| Error Message | 675| -------- | ------------------------------------------------------------ | 676| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types; 3. Parameter verification failed. | 677| 201 | Permission denied. | 678| 13900020 | Invalid argument. | 679| 14000011 | Internal system error | 680 681**Example** 682 683```ts 684import { dataSharePredicates } from '@kit.ArkData'; 685import { image } from '@kit.ImageKit'; 686import { BusinessError } from '@kit.BasicServicesKit'; 687 688async function example() { 689 console.info('getThumbnailDemo'); 690 let predicates: dataSharePredicates.DataSharePredicates = new dataSharePredicates.DataSharePredicates(); 691 let fetchOption: photoAccessHelper.FetchOptions = { 692 fetchColumns: [], 693 predicates: predicates 694 }; 695 let size: image.Size = { width: 720, height: 720 }; 696 let fetchResult: sendablePhotoAccessHelper.FetchResult<sendablePhotoAccessHelper.PhotoAsset> = await phAccessHelper.getAssets(fetchOption); 697 let asset = await fetchResult.getFirstObject(); 698 console.info('asset displayName = ', asset.displayName); 699 asset.getThumbnail(size).then((pixelMap) => { 700 console.info('getThumbnail successful ' + pixelMap); 701 }).catch((err: BusinessError) => { 702 console.error(`getThumbnail fail with error: ${err.code}, ${err.message}`); 703 }); 704} 705``` 706 707## FetchResult 708 709Provides APIs to manage the file retrieval result. 710 711### getCount 712 713getCount(): number 714 715Obtains the total number of files in the result set. 716 717**System capability**: SystemCapability.FileManagement.PhotoAccessHelper.Core 718 719**Return value** 720 721| Type | Description | 722| ------ | ------------------ | 723| number | Total number of files obtained. | 724 725**Error codes** 726 727For details about the error codes, see [Universal Error Codes](../errorcode-universal.md) and [File Management Error Codes](../apis-core-file-kit/errorcode-filemanagement.md). 728 729| ID| Error Message | 730| -------- | ------------------------------------------------------------ | 731| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types. | 732| 13900020 | Invalid argument. | 733| 14000011 | Internal system error | 734 735**Example** 736 737```ts 738import { dataSharePredicates } from '@kit.ArkData'; 739 740async function example() { 741 console.info('getCountDemo'); 742 let predicates: dataSharePredicates.DataSharePredicates = new dataSharePredicates.DataSharePredicates(); 743 let fetchOption: photoAccessHelper.FetchOptions = { 744 fetchColumns: [], 745 predicates: predicates 746 }; 747 let fetchResult: sendablePhotoAccessHelper.FetchResult<sendablePhotoAccessHelper.PhotoAsset> = await phAccessHelper.getAssets(fetchOption); 748 let fetchCount = fetchResult.getCount(); 749 console.info('fetchCount = ', fetchCount); 750} 751``` 752 753### isAfterLast 754 755isAfterLast(): boolean 756 757Checks whether the cursor is in the last row of the result set. 758 759**System capability**: SystemCapability.FileManagement.PhotoAccessHelper.Core 760 761**Return value** 762 763| Type | Description | 764| ------- | ----------------------------------------------------------- | 765| boolean | Returns **true** if the cursor is in the last row of the result set; returns **false** otherwise.| 766 767**Error codes** 768 769For details about the error codes, see [Universal Error Codes](../errorcode-universal.md) and [File Management Error Codes](../apis-core-file-kit/errorcode-filemanagement.md). 770 771| ID| Error Message | 772| -------- | ------------------------------------------------------------ | 773| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types. | 774| 13900020 | Invalid argument. | 775| 14000011 | Internal system error | 776 777**Example** 778 779```ts 780import { dataSharePredicates } from '@kit.ArkData'; 781 782async function example() { 783 let predicates: dataSharePredicates.DataSharePredicates = new dataSharePredicates.DataSharePredicates(); 784 let fetchOption: photoAccessHelper.FetchOptions = { 785 fetchColumns: [], 786 predicates: predicates 787 }; 788 let fetchResult: sendablePhotoAccessHelper.FetchResult<sendablePhotoAccessHelper.PhotoAsset> = await phAccessHelper.getAssets(fetchOption); 789 let fetchCount = fetchResult.getCount(); 790 console.info('count:' + fetchCount); 791 let photoAsset: sendablePhotoAccessHelper.PhotoAsset = await fetchResult.getLastObject(); 792 if (fetchResult.isAfterLast()) { 793 console.info('photoAsset isAfterLast displayName = ', photoAsset.displayName); 794 } else { 795 console.info('photoAsset not isAfterLast.'); 796 } 797} 798``` 799 800### close 801 802close(): void 803 804Closes this **FetchFileResult** instance to invalidate it. After the instance is closed, the APIs in this instance cannot be invoked. 805 806**System capability**: SystemCapability.FileManagement.PhotoAccessHelper.Core 807 808**Error codes** 809 810For details about the error codes, see [Universal Error Codes](../errorcode-universal.md) and [File Management Error Codes](../apis-core-file-kit/errorcode-filemanagement.md). 811 812| ID| Error Message | 813| -------- | ------------------------------------------------------------ | 814| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types. | 815| 13900020 | Invalid argument. | 816| 14000011 | Internal system error | 817 818**Example** 819 820```ts 821import { dataSharePredicates } from '@kit.ArkData'; 822 823async function example() { 824 console.info('fetchResultCloseDemo'); 825 let predicates: dataSharePredicates.DataSharePredicates = new dataSharePredicates.DataSharePredicates(); 826 let fetchOption: photoAccessHelper.FetchOptions = { 827 fetchColumns: [], 828 predicates: predicates 829 }; 830 try { 831 let fetchResult: sendablePhotoAccessHelper.FetchResult<sendablePhotoAccessHelper.PhotoAsset> = await phAccessHelper.getAssets(fetchOption); 832 fetchResult.close(); 833 console.info('close succeed.'); 834 } catch (err) { 835 console.error(`close fail. error: ${err.code}, ${err.message}`); 836 } 837} 838``` 839 840### getFirstObject 841 842getFirstObject(): Promise<T> 843 844Obtains the first asset in the result set. This API uses a promise to return the result. 845 846**System capability**: SystemCapability.FileManagement.PhotoAccessHelper.Core 847 848**Return value** 849 850| Type | Description | 851| ---------------- | ------------------------------------- | 852| Promise<T> | Promise used to return the first object in the result set.| 853 854**Error codes** 855 856For details about the error codes, see [Universal Error Codes](../errorcode-universal.md) and [File Management Error Codes](../apis-core-file-kit/errorcode-filemanagement.md). 857 858| ID| Error Message | 859| -------- | ------------------------------------------------------------ | 860| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types. | 861| 13900020 | Invalid argument. | 862| 14000011 | Internal system error | 863 864**Example** 865 866```ts 867import { dataSharePredicates } from '@kit.ArkData'; 868 869async function example() { 870 console.info('getFirstObjectDemo'); 871 let predicates: dataSharePredicates.DataSharePredicates = new dataSharePredicates.DataSharePredicates(); 872 let fetchOption: photoAccessHelper.FetchOptions = { 873 fetchColumns: [], 874 predicates: predicates 875 }; 876 let fetchResult: sendablePhotoAccessHelper.FetchResult<sendablePhotoAccessHelper.PhotoAsset> = await phAccessHelper.getAssets(fetchOption); 877 let photoAsset: sendablePhotoAccessHelper.PhotoAsset = await fetchResult.getFirstObject(); 878 console.info('photoAsset displayName: ', photoAsset.displayName); 879} 880``` 881 882### getNextObject 883 884getNextObject(): Promise<T> 885 886Obtains the next asset in the result set. This API uses a promise to return the result. 887Before using this API, you must use [isAfterLast()](#isafterlast) to check whether the current position is the end of the result set. 888 889**System capability**: SystemCapability.FileManagement.PhotoAccessHelper.Core 890 891**Return value** 892 893| Type | Description | 894| ---------------- | ------------------------------------- | 895| Promise<T> | Promise used to return the next object in the result set.| 896 897**Error codes** 898 899For details about the error codes, see [Universal Error Codes](../errorcode-universal.md) and [File Management Error Codes](../apis-core-file-kit/errorcode-filemanagement.md). 900 901| ID| Error Message | 902| -------- | ------------------------------------------------------------ | 903| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types. | 904| 13900020 | Invalid argument. | 905| 14000011 | Internal system error | 906 907**Example** 908 909```ts 910import { dataSharePredicates } from '@kit.ArkData'; 911 912async function example() { 913 console.info('getNextObjectDemo'); 914 let predicates: dataSharePredicates.DataSharePredicates = new dataSharePredicates.DataSharePredicates(); 915 let fetchOption: photoAccessHelper.FetchOptions = { 916 fetchColumns: [], 917 predicates: predicates 918 }; 919 let fetchResult: sendablePhotoAccessHelper.FetchResult<sendablePhotoAccessHelper.PhotoAsset> = await phAccessHelper.getAssets(fetchOption); 920 await fetchResult.getFirstObject(); 921 let photoAsset: sendablePhotoAccessHelper.PhotoAsset = await fetchResult.getNextObject(); 922 console.info('photoAsset displayName: ', photoAsset.displayName); 923} 924``` 925 926### getLastObject 927 928getLastObject(): Promise<T> 929 930Obtains the last asset in the result set. This API uses a promise to return the result. 931 932**System capability**: SystemCapability.FileManagement.PhotoAccessHelper.Core 933 934**Return value** 935 936| Type | Description | 937| ---------------- | --------------------------------------- | 938| Promise<T> | Promise used to return the last object in the result set.| 939 940**Error codes** 941 942For details about the error codes, see [Universal Error Codes](../errorcode-universal.md) and [File Management Error Codes](../apis-core-file-kit/errorcode-filemanagement.md). 943 944| ID| Error Message | 945| -------- | ------------------------------------------------------------ | 946| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types. | 947| 13900020 | Invalid argument. | 948| 14000011 | Internal system error | 949 950**Example** 951 952```ts 953import { dataSharePredicates } from '@kit.ArkData'; 954 955async function example() { 956 console.info('getLastObjectDemo'); 957 let predicates: dataSharePredicates.DataSharePredicates = new dataSharePredicates.DataSharePredicates(); 958 let fetchOption: photoAccessHelper.FetchOptions = { 959 fetchColumns: [], 960 predicates: predicates 961 }; 962 let fetchResult: sendablePhotoAccessHelper.FetchResult<sendablePhotoAccessHelper.PhotoAsset> = await phAccessHelper.getAssets(fetchOption); 963 let photoAsset: sendablePhotoAccessHelper.PhotoAsset = await fetchResult.getLastObject(); 964 console.info('photoAsset displayName: ', photoAsset.displayName); 965} 966``` 967 968### getObjectByPosition 969 970getObjectByPosition(index: number): Promise<T> 971 972Obtains the asset with the given index in the result set. This API uses a promise to return the result. 973 974**System capability**: SystemCapability.FileManagement.PhotoAccessHelper.Core 975 976**Parameters** 977 978| Name| Type | Mandatory| Description | 979| ------ | ------ | ---- | ----------------------------- | 980| index | number | Yes | Index of the asset to obtain, which starts from **0**. | 981 982**Return value** 983 984| Type | Description | 985| ---------------- | --------------------------------------------- | 986| Promise<T> | Promise used to return the asset obtained. | 987 988**Error codes** 989 990For details about the error codes, see [Universal Error Codes](../errorcode-universal.md) and [File Management Error Codes](../apis-core-file-kit/errorcode-filemanagement.md). 991 992| ID| Error Message | 993| -------- | ------------------------------------------------------------ | 994| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types; 3. Parameter verification failed. | 995| 13900020 | Invalid argument. | 996| 14000011 | Internal system error | 997 998**Example** 999 1000```ts 1001import { dataSharePredicates } from '@kit.ArkData'; 1002 1003async function example() { 1004 console.info('getObjectByPositionDemo'); 1005 let predicates: dataSharePredicates.DataSharePredicates = new dataSharePredicates.DataSharePredicates(); 1006 let fetchOption: photoAccessHelper.FetchOptions = { 1007 fetchColumns: [], 1008 predicates: predicates 1009 }; 1010 let fetchResult: sendablePhotoAccessHelper.FetchResult<sendablePhotoAccessHelper.PhotoAsset> = await phAccessHelper.getAssets(fetchOption); 1011 let photoAsset: sendablePhotoAccessHelper.PhotoAsset = await fetchResult.getObjectByPosition(0); 1012 console.info('photoAsset displayName: ', photoAsset.displayName); 1013} 1014``` 1015 1016### getAllObjects 1017 1018getAllObjects(): Promise<Array<T>> 1019 1020Obtains all the assets in the result set. This API uses a promise to return the result. 1021 1022**System capability**: SystemCapability.FileManagement.PhotoAccessHelper.Core 1023 1024**Return value** 1025 1026| Type | Description | 1027| ----------------------------- | ------------------------------------------- | 1028| Promise<Array<T>> | Promise used to return all the assets in the result set. | 1029 1030**Error codes** 1031 1032For details about the error codes, see [Universal Error Codes](../errorcode-universal.md) and [File Management Error Codes](../apis-core-file-kit/errorcode-filemanagement.md). 1033 1034| ID| Error Message | 1035| -------- | ------------------------------------------------------------ | 1036| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types. | 1037| 13900020 | Invalid argument. | 1038| 14000011 | Internal system error | 1039 1040**Example** 1041 1042```ts 1043import { dataSharePredicates } from '@kit.ArkData'; 1044 1045async function example() { 1046 console.info('getAllObjectDemo'); 1047 let predicates: dataSharePredicates.DataSharePredicates = new dataSharePredicates.DataSharePredicates(); 1048 let fetchOption: photoAccessHelper.FetchOptions = { 1049 fetchColumns: [], 1050 predicates: predicates 1051 }; 1052 let fetchResult: sendablePhotoAccessHelper.FetchResult<sendablePhotoAccessHelper.PhotoAsset> = await phAccessHelper.getAssets(fetchOption); 1053 let photoAssetList: Array<sendablePhotoAccessHelper.PhotoAsset> = await fetchResult.getAllObjects(); 1054 console.info('photoAssetList length: ', photoAssetList.length); 1055} 1056``` 1057 1058## Album 1059 1060Provides APIs to manage albums. 1061 1062### Properties 1063 1064**System capability**: SystemCapability.FileManagement.PhotoAccessHelper.Core 1065 1066| Name | Type | Read-Only | Optional| Description | 1067| ------------ | ----------------------------- | ---------------------------- | ---- | ---------------- | 1068| albumType | [AlbumType](#albumtype) | Yes | No | Type of the album. | 1069| albumSubtype | [AlbumSubtype](#albumsubtype) | Yes | No | Subtype of the album. | 1070| albumName | string | Yes for a user album; no for a system album.| No | Name of the album. | 1071| albumUri | string | Yes | No | URI of the album. | 1072| count | number | Yes | No | Number of files in the album.| 1073| coverUri | string | Yes | No | URI of the cover file of the album. | 1074| imageCount | number | Yes | Yes | Number of images in the album.| 1075| videoCount | number | Yes | Yes | Number of videos in the album.| 1076 1077### convertToPhotoAlbum 1078 1079convertToPhotoAlbum(): photoAccessHelper.Album 1080 1081Converts this sendable album to a non-sendable album. 1082 1083**Required permissions**: ohos.permission.READ_IMAGEVIDEO 1084 1085**System capability**: SystemCapability.FileManagement.PhotoAccessHelper.Core 1086 1087**Return value** 1088 1089| Type | Description | 1090| ----------------------- | --------------------------------------------------------- | 1091| photoAccessHelper.Album | Non-sendable [album](js-apis-photoAccessHelper.md#album). | 1092 1093**Error codes** 1094 1095For details about the error codes, see [Universal Error Codes](../errorcode-universal.md) and [File Management Error Codes](../apis-core-file-kit/errorcode-filemanagement.md). 1096 1097| ID| Error Message | 1098| -------- | ------------------------------------------------------------ | 1099| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types; 3. Parameter verification failed. | 1100| 201 | Permission denied. | 1101| 13900020 | Invalid argument. | 1102| 14000011 | Internal system error | 1103 1104**Example** 1105 1106```ts 1107import { dataSharePredicates } from '@kit.ArkData'; 1108import { BusinessError } from '@kit.BasicServicesKit'; 1109import { photoAccessHelper } from '@kit.MediaLibraryKit'; 1110 1111async function example() { 1112 console.info('convertToPhotoAlbumDemo'); 1113 let predicates: dataSharePredicates.DataSharePredicates = new dataSharePredicates.DataSharePredicates(); 1114 let albumFetchOptions: photoAccessHelper.FetchOptions = { 1115 fetchColumns: [], 1116 predicates: predicates 1117 }; 1118 let fetchOption: photoAccessHelper.FetchOptions = { 1119 fetchColumns: [], 1120 predicates: predicates 1121 }; 1122 let albumList: sendablePhotoAccessHelper.FetchResult<sendablePhotoAccessHelper.Album> = await phAccessHelper.getAlbums(sendablePhotoAccessHelper.AlbumType.USER, sendablePhotoAccessHelper.AlbumSubtype.USER_GENERIC, albumFetchOptions); 1123 let sendableAlbum: sendablePhotoAccessHelper.Album = await albumList.getFirstObject(); 1124 let album: photoAccessHelper.Album = sendableAlbum.convertToPhotoAlbum(); 1125 album.getAssets(fetchOption).then((albumFetchResult) => { 1126 console.info('convertToPhotoAlbum successfully, getCount: ' + albumFetchResult.getCount()); 1127 }).catch((err: BusinessError) => { 1128 console.error(`convertToPhotoAlbum failed with error: ${err.code}, ${err.message}`); 1129 }); 1130} 1131``` 1132 1133### getAssets 1134 1135getAssets(options: FetchOptions): Promise<FetchResult<PhotoAsset>> 1136 1137Obtains image and video assets. This API uses a promise to return the result. 1138 1139**Required permissions**: ohos.permission.READ_IMAGEVIDEO 1140 1141**System capability**: SystemCapability.FileManagement.PhotoAccessHelper.Core 1142 1143**Parameters** 1144 1145| Name | Type | Mandatory| Description | 1146| ------- | --------------------------------------------------------- | ---- | ---------- | 1147| options | [FetchOptions](js-apis-photoAccessHelper.md#fetchoptions) | Yes | Options for fetching the assets.| 1148 1149**Return value** 1150 1151| Type | Description | 1152| ------------------------------------------------------------ | --------------------------------------- | 1153| Promise<[FetchResult](#fetchresult)<[PhotoAsset](#photoasset)>> | Promise used to return the image and video assets obtained.| 1154 1155**Error codes** 1156 1157For details about the error codes, see [Universal Error Codes](../errorcode-universal.md) and [File Management Error Codes](../apis-core-file-kit/errorcode-filemanagement.md). 1158 1159| ID| Error Message | 1160| -------- | ------------------------------------------------------------ | 1161| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types; 3. Parameter verification failed. | 1162| 201 | Permission denied. | 1163| 13900020 | Invalid argument. | 1164| 14000011 | Internal system error | 1165 1166**Example** 1167 1168```ts 1169import { dataSharePredicates } from '@kit.ArkData'; 1170import { BusinessError } from '@kit.BasicServicesKit'; 1171 1172async function example() { 1173 console.info('albumGetAssetsDemoPromise'); 1174 let predicates: dataSharePredicates.DataSharePredicates = new dataSharePredicates.DataSharePredicates(); 1175 let albumFetchOptions: photoAccessHelper.FetchOptions = { 1176 fetchColumns: [], 1177 predicates: predicates 1178 }; 1179 let fetchOption: photoAccessHelper.FetchOptions = { 1180 fetchColumns: [], 1181 predicates: predicates 1182 }; 1183 let albumList: sendablePhotoAccessHelper.FetchResult<sendablePhotoAccessHelper.Album> = await phAccessHelper.getAlbums(sendablePhotoAccessHelper.AlbumType.USER, sendablePhotoAccessHelper.AlbumSubtype.USER_GENERIC, albumFetchOptions); 1184 let album: sendablePhotoAccessHelper.Album = await albumList.getFirstObject(); 1185 album.getAssets(fetchOption).then((albumFetchResult) => { 1186 console.info('album getAssets successfully, getCount: ' + albumFetchResult.getCount()); 1187 }).catch((err: BusinessError) => { 1188 console.error(`album getAssets failed with error: ${err.code}, ${err.message}`); 1189 }); 1190} 1191``` 1192 1193### commitModify 1194 1195commitModify(): Promise<void> 1196 1197Commits the modification on the album attributes to the database. This API uses a promise to return the result. 1198 1199**Required permissions**: ohos.permission.WRITE_IMAGEVIDEO 1200 1201**System capability**: SystemCapability.FileManagement.PhotoAccessHelper.Core 1202 1203**Return value** 1204 1205| Type | Description | 1206| ------------------- | ----------------------- | 1207| Promise<void> | Promise that returns no value.| 1208 1209**Error codes** 1210 1211For details about the error codes, see [Universal Error Codes](../errorcode-universal.md) and [File Management Error Codes](../apis-core-file-kit/errorcode-filemanagement.md). 1212 1213| ID| Error Message | 1214| -------- | ------------------------------------------------------------ | 1215| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types. | 1216| 201 | Permission denied. | 1217| 13900020 | Invalid argument. | 1218| 14000011 | Internal system error | 1219 1220**Example** 1221 1222```ts 1223import { dataSharePredicates } from '@kit.ArkData'; 1224import { BusinessError } from '@kit.BasicServicesKit'; 1225 1226async function example() { 1227 console.info('albumCommitModifyDemo'); 1228 let predicates: dataSharePredicates.DataSharePredicates = new dataSharePredicates.DataSharePredicates(); 1229 let albumFetchOptions: photoAccessHelper.FetchOptions = { 1230 fetchColumns: [], 1231 predicates: predicates 1232 }; 1233 let albumList: sendablePhotoAccessHelper.FetchResult<sendablePhotoAccessHelper.Album> = await phAccessHelper.getAlbums(sendablePhotoAccessHelper.AlbumType.USER, sendablePhotoAccessHelper.AlbumSubtype.USER_GENERIC, albumFetchOptions); 1234 let album: sendablePhotoAccessHelper.Album = await albumList.getFirstObject(); 1235 album.albumName = 'hello'; 1236 album.commitModify().then(() => { 1237 console.info('commitModify successfully'); 1238 }).catch((err: BusinessError) => { 1239 console.error(`commitModify failed with error: ${err.code}, ${err.message}`); 1240 }); 1241} 1242``` 1243 1244## PhotoType 1245 1246Enumerates media file types. 1247 1248**Atomic service API**: This API can be used in atomic services since API version 12. 1249 1250**System capability**: SystemCapability.FileManagement.PhotoAccessHelper.Core 1251 1252| Name | Value | Description | 1253| ----- | ---- | ------ | 1254| IMAGE | 1 | Image.| 1255| VIDEO | 2 | Video.| 1256 1257## AlbumType 1258 1259Enumerates the album types. 1260 1261**System capability**: SystemCapability.FileManagement.PhotoAccessHelper.Core 1262 1263| Name | Value | Description | 1264| ------ | ---- | -------------- | 1265| USER | 0 | User album. | 1266| SYSTEM | 1024 | System album.| 1267 1268## AlbumSubtype 1269 1270Enumerate the album subtypes. 1271 1272**System capability**: SystemCapability.FileManagement.PhotoAccessHelper.Core 1273 1274| Name | Value | Description | 1275| ------------- | ---------- | ---------- | 1276| USER\_GENERIC | 1 | User album.| 1277| FAVORITE | 1025 | Favorites. | 1278| VIDEO | 1026 | Video album.| 1279| IMAGE | 1031 | Photo album.| 1280| ANY | 2147483647 | Any album.| 1281