1# @ohos.file.photoAccessHelper (Album Management) (System API) 2 3The photoAccessHelper module provides APIs for album management, including creating an album and accessing and modifying media data in an album. 4 5> **NOTE** 6> 7> - The initial APIs of this module are supported since API version 10. Newly added APIs will be marked with a superscript to indicate their earliest API version. 8> - This topic describes only the system APIs provided by the module. For details about its public APIs, see [@ohos.file.photoAccessHelper (Album Management)](js-apis-photoAccessHelper.md). 9 10## Modules to Import 11 12```ts 13import { photoAccessHelper } from '@kit.MediaLibraryKit'; 14``` 15 16## PhotoAccessHelper 17 18### createAsset 19 20createAsset(displayName: string, callback: AsyncCallback<PhotoAsset>): void 21 22Creates an image or video asset with the specified file name. This API uses an asynchronous callback to return the result. 23 24The file name must comply with the following specifications: 25- The file name consists of a valid file name and an image or video file name extension. 26- The file name cannot exceed 255 characters. 27- The file name cannot contain any of the following characters:<br>API version 18 and later: \ / : * ? " < > | <br>API versions 10 to 17: . .. \ / : * ? " ' ` < > | { } [ ] 28 29**System API**: This is a system API. 30 31**System capability**: SystemCapability.FileManagement.PhotoAccessHelper.Core 32 33**Required permissions**: ohos.permission.WRITE_IMAGEVIDEO 34 35**Parameters** 36 37| Name | Type | Mandatory| Description | 38| -------- | ------------------------ | ---- | ------------------------- | 39| displayName | string | Yes | File name of the image or video to create. | 40| callback | AsyncCallback<[PhotoAsset](#photoasset)> | Yes | Callback used to return the image or video created.| 41 42**Error codes** 43 44For details about the error codes, see [Universal Error Codes](../errorcode-universal.md) and [File Management Error Codes](../apis-core-file-kit/errorcode-filemanagement.md). 45 46| ID| Error Message| 47| -------- | ---------------------------------------- | 48| 202 | Called by non-system application. | 49| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types; 3. Parameter verification failed. | 50| 13900012 | Permission denied. | 51| 13900020 | Invalid argument. | 52| 14000001 | Invalid display name. | 53| 14000011 | System inner fail. | 54 55**Example** 56 57```ts 58async function example() { 59 console.info('createAssetDemo'); 60 let testFileName: string = 'testFile' + Date.now() + '.jpg'; 61 phAccessHelper.createAsset(testFileName, (err, photoAsset) => { 62 if (photoAsset !== undefined) { 63 console.info('createAsset file displayName' + photoAsset.displayName); 64 console.info('createAsset successfully'); 65 } else { 66 console.error(`createAsset failed, error: ${err.code}, ${err.message}`); 67 } 68 }); 69} 70``` 71 72### createAsset 73 74createAsset(displayName: string): Promise<PhotoAsset> 75 76Creates an image or video asset with the specified file name. This API uses a promise to return the result. 77 78The file name must comply with the following specifications: 79- The file name consists of a valid file name and an image or video file name extension. 80- The file name cannot exceed 255 characters. 81- The file name cannot contain any of the following characters:<br>API version 18 and later: \ / : * ? " < > | <br>API versions 10 to 17: . .. \ / : * ? " ' ` < > | { } [ ] 82 83**System API**: This is a system API. 84 85**System capability**: SystemCapability.FileManagement.PhotoAccessHelper.Core 86 87**Required permissions**: ohos.permission.WRITE_IMAGEVIDEO 88 89**Parameters** 90 91| Name | Type | Mandatory| Description | 92| -------- | ------------------------ | ---- | ------------------------- | 93| displayName | string | Yes | File name of the image or video to create. | 94 95**Return value** 96 97| Type | Description | 98| --------------------------- | -------------- | 99| Promise<[PhotoAsset](#photoasset)> | Promise used to return the created image and video asset.| 100 101**Error codes** 102 103For details about the error codes, see [Universal Error Codes](../errorcode-universal.md) and [File Management Error Codes](../apis-core-file-kit/errorcode-filemanagement.md). 104 105| ID| Error Message| 106| -------- | ---------------------------------------- | 107| 202 | Called by non-system application. | 108| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types; 3. Parameter verification failed. | 109| 13900012 | Permission denied. | 110| 13900020 | Invalid argument. | 111| 14000001 | Invalid display name. | 112| 14000011 | System inner fail. | 113 114**Example** 115 116```ts 117async function example() { 118 console.info('createAssetDemo'); 119 try { 120 let testFileName: string = 'testFile' + Date.now() + '.jpg'; 121 let photoAsset: photoAccessHelper.PhotoAsset = await phAccessHelper.createAsset(testFileName); 122 console.info('createAsset file displayName' + photoAsset.displayName); 123 console.info('createAsset successfully'); 124 } catch (err) { 125 console.error(`createAsset failed, error: ${err.code}, ${err.message}`); 126 } 127} 128``` 129 130## PhotoSelectOptions 131 132Defines additional options for selecting media assets from Gallery. It inherits from **BaseSelectOptions**. It is used to start the picker of the corresponding user ID space. 133 134**System capability**: SystemCapability.FileManagement.PhotoAccessHelper.Core 135 136| Name| Type| Mandatory| Description| 137| -------- | -------- | -------- | -------- | 138| userId<sup>18+</sup> | number | No | ID of the user space to access. The default value is **-1**.<br>To use it as a parameter of [PhotoViewPicker.select](js-apis-photoAccessHelper.md#select), request the permission ohos.permission.INTERACTA_CROSS_LOCAL_ACCOUNTS.<br>**System API**: This is a system API.| 139 140**Example** 141 142```ts 143 private photoPicker() { 144 let picker = new photoAccessHelper.PhotoViewPicker(); 145 let option = new photoAccessHelper.PhotoSelectOptions(); 146 option.userId = 101; 147 picker.select(option); 148 } 149``` 150 151### createAsset 152 153createAsset(displayName: string, options: PhotoCreateOptions, callback: AsyncCallback<PhotoAsset>): void 154 155Creates an image or video asset with the specified file name and options. This API uses an asynchronous callback to return the result. 156 157The file name must comply with the following specifications: 158- The file name consists of a valid file name and an image or video file name extension. 159- The file name cannot exceed 255 characters. 160- The file name cannot contain any of the following characters:<br>API version 18 and later: \ / : * ? " < > | <br>API versions 10 to 17: . .. \ / : * ? " ' ` < > | { } [ ] 161 162**System API**: This is a system API. 163 164**System capability**: SystemCapability.FileManagement.PhotoAccessHelper.Core 165 166**Required permissions**: ohos.permission.WRITE_IMAGEVIDEO 167 168**Parameters** 169 170| Name | Type | Mandatory| Description | 171| -------- | ------------------------ | ---- | ------------------------- | 172| displayName | string | Yes | File name of the image or video to create. | 173| options | [PhotoCreateOptions](#photocreateoptions) | Yes | Options for creating an image or video asset. | 174| callback | AsyncCallback<[PhotoAsset](#photoasset)> | Yes | Callback used to return the image or video created.| 175 176**Error codes** 177 178For details about the error codes, see [Universal Error Codes](../errorcode-universal.md) and [File Management Error Codes](../apis-core-file-kit/errorcode-filemanagement.md). 179 180| ID| Error Message| 181| -------- | ---------------------------------------- | 182| 202 | Called by non-system application. | 183| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types; 3. Parameter verification failed. | 184| 13900012 | Permission denied. | 185| 13900020 | Invalid argument. | 186| 14000001 | Invalid display name. | 187| 14000011 | System inner fail. | 188 189**Example** 190 191```ts 192async function example() { 193 console.info('createAssetDemo'); 194 let testFileName: string = 'testFile' + Date.now() + '.jpg'; 195 let createOption: photoAccessHelper.PhotoCreateOptions = { 196 subtype: photoAccessHelper.PhotoSubtype.DEFAULT 197 } 198 phAccessHelper.createAsset(testFileName, createOption, (err, photoAsset) => { 199 if (photoAsset !== undefined) { 200 console.info('createAsset file displayName' + photoAsset.displayName); 201 console.info('createAsset successfully'); 202 } else { 203 console.error(`createAsset failed, error: ${err.code}, ${err.message}`); 204 } 205 }); 206} 207``` 208 209### createAsset 210 211createAsset(displayName: string, options: PhotoCreateOptions): Promise<PhotoAsset> 212 213Creates an image or video asset with the specified file name and options. This API uses a promise to return the result. 214 215The file name must comply with the following specifications: 216- The file name consists of a valid file name and an image or video file name extension. 217- The file name cannot exceed 255 characters. 218- The file name cannot contain any of the following characters:<br>API version 18 and later: \ / : * ? " < > | <br>API versions 10 to 17: . .. \ / : * ? " ' ` < > | { } [ ] 219 220**System API**: This is a system API. 221 222**System capability**: SystemCapability.FileManagement.PhotoAccessHelper.Core 223 224**Required permissions**: ohos.permission.WRITE_IMAGEVIDEO 225 226**Parameters** 227 228| Name | Type | Mandatory| Description | 229| -------- | ------------------------ | ---- | ------------------------- | 230| displayName | string | Yes | File name of the image or video to create. | 231| options | [PhotoCreateOptions](#photocreateoptions) | Yes | Options for creating an image or video asset. | 232 233**Return value** 234 235| Type | Description | 236| --------------------------- | -------------- | 237| Promise<[PhotoAsset](#photoasset)> | Promise used to return the created image and video asset.| 238 239**Error codes** 240 241For details about the error codes, see [Universal Error Codes](../errorcode-universal.md) and [File Management Error Codes](../apis-core-file-kit/errorcode-filemanagement.md). 242 243| ID| Error Message| 244| -------- | ---------------------------------------- | 245| 202 | Called by non-system application. | 246| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types; 3. Parameter verification failed. | 247| 13900012 | Permission denied. | 248| 13900020 | Invalid argument. | 249| 14000001 | Invalid display name. | 250| 14000011 | System inner fail. | 251 252**Example** 253 254```ts 255async function example() { 256 console.info('createAssetDemo'); 257 try { 258 let testFileName:string = 'testFile' + Date.now() + '.jpg'; 259 let createOption: photoAccessHelper.PhotoCreateOptions = { 260 subtype: photoAccessHelper.PhotoSubtype.DEFAULT 261 } 262 let photoAsset: photoAccessHelper.PhotoAsset = await phAccessHelper.createAsset(testFileName, createOption); 263 console.info('createAsset file displayName' + photoAsset.displayName); 264 console.info('createAsset successfully'); 265 } catch (err) { 266 console.error(`createAsset failed, error: ${err.code}, ${err.message}`); 267 } 268} 269``` 270 271### createAlbum<sup>(deprecated)</sup> 272 273createAlbum(name: string, callback: AsyncCallback<Album>): void 274 275Creates an album. This API uses an asynchronous callback to return the result. 276 277The album name must meet the following requirements: 278- The album name cannot exceed 255 characters. 279- The album name cannot contain any of the following characters:<br>. .. \ / : * ? " ' ` < > | { } [ ] 280- The album name is case-insensitive. 281- Duplicate album names are not allowed. 282 283> **NOTE** 284> 285> This API is supported since API version 10 and deprecated since API version 11. Use [MediaAlbumChangeRequest.createAlbumRequest](#createalbumrequest11) instead. 286 287**System API**: This is a system API. 288 289**System capability**: SystemCapability.FileManagement.PhotoAccessHelper.Core 290 291**Required permissions**: ohos.permission.WRITE_IMAGEVIDEO 292 293**Parameters** 294 295| Name | Type | Mandatory| Description | 296| -------- | ------------------------ | ---- | ------------------------- | 297| name | string | Yes | Name of the album to create. | 298| callback | AsyncCallback<[Album](#album)> | Yes | Callback used to return the created album instance.| 299 300**Error codes** 301 302For details about the error codes, see [Universal Error Codes](../errorcode-universal.md) and [File Management Error Codes](../apis-core-file-kit/errorcode-filemanagement.md). 303 304| ID| Error Message| 305| -------- | ---------------------------------------- | 306| 202 | Called by non-system application. | 307| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types; 3. Parameter verification failed. | 308| 13900012 | Permission denied. | 309| 13900015 | File exists. | 310| 13900020 | Invalid argument. | 311| 14000011 | System inner fail. | 312 313**Example** 314 315```ts 316async function example() { 317 console.info('createAlbumDemo'); 318 let albumName: string = 'newAlbumName' + new Date().getTime(); 319 phAccessHelper.createAlbum(albumName, (err, album) => { 320 if (err) { 321 console.error(`createAlbumCallback failed with err: ${err.code}, ${err.message}`); 322 return; 323 } 324 console.info('createAlbumCallback successfully, album: ' + album.albumName + ' album uri: ' + album.albumUri); 325 }); 326} 327``` 328 329### createAlbum<sup>(deprecated)</sup> 330 331createAlbum(name: string): Promise<Album> 332 333Creates an album. This API uses a promise to return the result. 334 335The album name must meet the following requirements: 336- The album name cannot exceed 255 characters. 337- The album name cannot contain any of the following characters:<br>. .. \ / : * ? " ' ` < > | { } [ ] 338- The album name is case-insensitive. 339- Duplicate album names are not allowed. 340 341> **NOTE** 342> 343> This API is supported since API version 10 and deprecated since API version 11. Use [MediaAlbumChangeRequest.createAlbumRequest](#createalbumrequest11) instead. 344 345**System API**: This is a system API. 346 347**System capability**: SystemCapability.FileManagement.PhotoAccessHelper.Core 348 349**Required permissions**: ohos.permission.WRITE_IMAGEVIDEO 350 351**Parameters** 352 353| Name | Type | Mandatory| Description | 354| -------- | ------------------------ | ---- | ------------------------- | 355| name | string | Yes | Name of the album to create. | 356 357**Return value** 358 359| Type | Description | 360| --------------------------- | -------------- | 361| Promise<[Album](#album)> | Promise used to return the created album instance.| 362 363**Error codes** 364 365For details about the error codes, see [Universal Error Codes](../errorcode-universal.md) and [File Management Error Codes](../apis-core-file-kit/errorcode-filemanagement.md). 366 367| ID| Error Message| 368| -------- | ---------------------------------------- | 369| 202 | Called by non-system application. | 370| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types; 3. Parameter verification failed. | 371| 13900012 | Permission denied. | 372| 13900015 | File exists. | 373| 13900020 | Invalid argument. | 374| 14000011 | System inner fail. | 375 376**Example** 377 378```ts 379import { BusinessError } from '@kit.BasicServicesKit'; 380 381async function example() { 382 console.info('createAlbumDemo'); 383 let albumName: string = 'newAlbumName' + new Date().getTime(); 384 phAccessHelper.createAlbum(albumName).then((album) => { 385 console.info('createAlbumPromise successfully, album: ' + album.albumName + ' album uri: ' + album.albumUri); 386 }).catch((err: BusinessError) => { 387 console.error(`createAlbumPromise failed with err: ${err.code}, ${err.message}`); 388 }); 389} 390``` 391 392### deleteAlbums<sup>(deprecated)</sup> 393 394deleteAlbums(albums: Array<Album>, callback: AsyncCallback<void>): void 395 396Deletes albums. This API uses an asynchronous callback to return the result. 397 398Ensure that the albums to be deleted exist. Only user albums can be deleted. 399 400> **NOTE** 401> 402> This API is supported since API version 10 and deprecated since API version 11. Use [MediaAlbumChangeRequest.deleteAlbums](#deletealbums11) instead. 403 404**System API**: This is a system API. 405 406**System capability**: SystemCapability.FileManagement.PhotoAccessHelper.Core 407 408**Required permissions**: ohos.permission.WRITE_IMAGEVIDEO 409 410**Parameters** 411 412| Name | Type | Mandatory| Description | 413| -------- | ------------------------ | ---- | ------------------------- | 414| albums | Array<[Album](#album)> | Yes | Albums to delete. | 415| callback | AsyncCallback<void> | Yes | Callback that returns no value.| 416 417**Error codes** 418 419For details about the error codes, see [Universal Error Codes](../errorcode-universal.md) and [File Management Error Codes](../apis-core-file-kit/errorcode-filemanagement.md). 420 421| ID| Error Message| 422| -------- | ---------------------------------------- | 423| 202 | Called by non-system application. | 424| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types; 3. Parameter verification failed. | 425| 13900012 | Permission denied. | 426| 13900020 | Invalid argument. | 427| 14000011 | System inner fail. | 428 429**Example** 430 431```ts 432import { dataSharePredicates } from '@kit.ArkData'; 433 434async function example() { 435 // Delete the album named newAlbumName. 436 console.info('deleteAlbumsDemo'); 437 let predicates: dataSharePredicates.DataSharePredicates = new dataSharePredicates.DataSharePredicates(); 438 predicates.equalTo('album_name', 'newAlbumName'); 439 let fetchOptions: photoAccessHelper.FetchOptions = { 440 fetchColumns: [], 441 predicates: predicates 442 }; 443 let fetchResult: photoAccessHelper.FetchResult<photoAccessHelper.Album> = await phAccessHelper.getAlbums(photoAccessHelper.AlbumType.USER, photoAccessHelper.AlbumSubtype.USER_GENERIC, fetchOptions); 444 let album: photoAccessHelper.Album = await fetchResult.getFirstObject(); 445 phAccessHelper.deleteAlbums([album], (err) => { 446 if (err) { 447 console.error(`deletePhotoAlbumsCallback failed with err: ${err.code}, ${err.message}`); 448 return; 449 } 450 console.info('deletePhotoAlbumsCallback successfully'); 451 }); 452 fetchResult.close(); 453} 454``` 455 456### deleteAlbums<sup>(deprecated)</sup> 457 458deleteAlbums(albums: Array<Album>): Promise<void> 459 460Deletes albums. This API uses a promise to return the result. 461 462Ensure that the albums to be deleted exist. Only user albums can be deleted. 463 464> **NOTE** 465> 466> This API is supported since API version 10 and deprecated since API version 11. Use [MediaAlbumChangeRequest.deleteAlbums](#deletealbums11) instead. 467 468**System API**: This is a system API. 469 470**System capability**: SystemCapability.FileManagement.PhotoAccessHelper.Core 471 472**Required permissions**: ohos.permission.WRITE_IMAGEVIDEO 473 474**Parameters** 475 476| Name | Type | Mandatory| Description | 477| -------- | ------------------------ | ---- | ------------------------- | 478| albums | Array<[Album](#album)> | Yes | Albums to delete. | 479 480**Return value** 481 482| Type | Description | 483| --------------------------- | -------------- | 484| Promise<void> | Promise that returns no value.| 485 486**Error codes** 487 488For details about the error codes, see [Universal Error Codes](../errorcode-universal.md) and [File Management Error Codes](../apis-core-file-kit/errorcode-filemanagement.md). 489 490| ID| Error Message| 491| -------- | ---------------------------------------- | 492| 202 | Called by non-system application. | 493| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types; 3. Parameter verification failed. | 494| 13900012 | Permission denied. | 495| 13900020 | Invalid argument. | 496| 14000011 | System inner fail. | 497 498**Example** 499 500```ts 501import { dataSharePredicates } from '@kit.ArkData'; 502import { BusinessError } from '@kit.BasicServicesKit'; 503 504async function example() { 505 // Delete the album named newAlbumName. 506 console.info('deleteAlbumsDemo'); 507 let predicates: dataSharePredicates.DataSharePredicates = new dataSharePredicates.DataSharePredicates(); 508 predicates.equalTo('album_name', 'newAlbumName'); 509 let fetchOptions: photoAccessHelper.FetchOptions = { 510 fetchColumns: [], 511 predicates: predicates 512 }; 513 let fetchResult: photoAccessHelper.FetchResult<photoAccessHelper.Album> = await phAccessHelper.getAlbums(photoAccessHelper.AlbumType.USER, photoAccessHelper.AlbumSubtype.USER_GENERIC, fetchOptions); 514 let album: photoAccessHelper.Album = await fetchResult.getFirstObject(); 515 phAccessHelper.deleteAlbums([album]).then(() => { 516 console.info('deletePhotoAlbumsPromise successfully'); 517 }).catch((err: BusinessError) => { 518 console.error(`deletePhotoAlbumsPromise failed with err: ${err.code}, ${err.message}`); 519 }); 520 fetchResult.close(); 521} 522``` 523 524### getHiddenAlbums<sup>11+</sup> 525 526getHiddenAlbums(mode: HiddenPhotosDisplayMode, options: FetchOptions, callback: AsyncCallback<FetchResult<Album>>): void 527 528Obtains hidden albums based on the specified display mode and retrieval options. This API uses an asynchronous callback to return the result. 529 530**System API**: This is a system API. 531 532**Required permissions**: ohos.permission.READ_IMAGEVIDEO and ohos.permission.MANAGE_PRIVATE_PHOTOS 533 534**System capability**: SystemCapability.FileManagement.PhotoAccessHelper.Core 535 536**Parameters** 537 538| Name | Type | Mandatory| Description | 539| -------- | ------------------------ | ---- | ------------------------- | 540| mode | [HiddenPhotosDisplayMode](#hiddenphotosdisplaymode11) | Yes | Display mode of hidden albums. | 541| options | [FetchOptions](js-apis-photoAccessHelper.md#fetchoptions) | Yes | Options for retrieving the hidden albums. | 542| callback | AsyncCallback<[FetchResult](js-apis-photoAccessHelper.md#fetchresult)<[Album](#album)>> | Callback used to return the result.| 543 544**Error codes** 545 546For details about the error codes, see [Universal Error Codes](../errorcode-universal.md) and [File Management Error Codes](../apis-core-file-kit/errorcode-filemanagement.md). 547 548| ID| Error Message| 549| -------- | ---------------------------------------- | 550| 201 | Permission verification failed, usually the result returned by VerifyAccessToken. | 551| 202 | Permission verification failed, application which is not a system application uses system API. | 552| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types; 3. Parameter verification failed. | 553| 14000011 | System inner fail. | 554 555**Example** 556 557```ts 558import { dataSharePredicates } from '@kit.ArkData'; 559 560// Obtain the album newAlbumName that contains hidden files. 561async function getHiddenAlbumsView() { 562 console.info('getHiddenAlbumsViewDemo'); 563 let predicates: dataSharePredicates.DataSharePredicates = new dataSharePredicates.DataSharePredicates(); 564 predicates.equalTo('album_name', 'newAlbumName'); 565 let fetchOptions: photoAccessHelper.FetchOptions = { 566 fetchColumns: [], 567 predicates: predicates 568 }; 569 phAccessHelper.getHiddenAlbums(photoAccessHelper.HiddenPhotosDisplayMode.ALBUMS_MODE, fetchOptions, 570 async (err, fetchResult) => { 571 if (fetchResult === undefined) { 572 console.error('getHiddenAlbumsViewCallback fetchResult is undefined'); 573 return; 574 } 575 let album = await fetchResult.getFirstObject(); 576 console.info('getHiddenAlbumsViewCallback successfully, album name: ' + album.albumName); 577 fetchResult.close(); 578 }); 579} 580``` 581 582### getHiddenAlbums<sup>11+</sup> 583 584getHiddenAlbums(mode: HiddenPhotosDisplayMode, callback: AsyncCallback<FetchResult<Album>>): void 585 586Obtains hidden albums based on the specified display mode. This API uses an asynchronous callback to return the result. 587 588**System API**: This is a system API. 589 590**Required permissions**: ohos.permission.READ_IMAGEVIDEO and ohos.permission.MANAGE_PRIVATE_PHOTOS 591 592**System capability**: SystemCapability.FileManagement.PhotoAccessHelper.Core 593 594**Parameters** 595 596| Name | Type | Mandatory| Description | 597| -------- | ------------------------ | ---- | ------------------------- | 598| mode | [HiddenPhotosDisplayMode](#hiddenphotosdisplaymode11) | Yes | Display mode of hidden albums. | 599| callback | AsyncCallback<[FetchResult](js-apis-photoAccessHelper.md#fetchresult)<[Album](#album)>> | Yes | Callback used to return the result.| 600 601**Error codes** 602 603For details about the error codes, see [Universal Error Codes](../errorcode-universal.md) and [File Management Error Codes](../apis-core-file-kit/errorcode-filemanagement.md). 604 605| ID| Error Message| 606| -------- | ---------------------------------------- | 607| 201 | Permission verification failed, usually the result returned by VerifyAccessToken. | 608| 202 | Permission verification failed, application which is not a system application uses system API. | 609| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types; 3. Parameter verification failed. | 610| 14000011 | System inner fail. | 611 612**Example** 613 614```ts 615import { dataSharePredicates } from '@kit.ArkData'; 616 617// Obtain the preset hidden album. 618async function getSysHiddenAlbum() { 619 console.info('getSysHiddenAlbumDemo'); 620 phAccessHelper.getHiddenAlbums(photoAccessHelper.HiddenPhotosDisplayMode.ASSETS_MODE, async (err, fetchResult) => { 621 if (fetchResult === undefined) { 622 console.error('getSysHiddenAlbumCallback fetchResult is undefined'); 623 return; 624 } 625 let hiddenAlbum: photoAccessHelper.Album = await fetchResult.getFirstObject(); 626 console.info('getSysHiddenAlbumCallback successfully, albumUri: ' + hiddenAlbum.albumUri); 627 fetchResult.close(); 628 }); 629} 630 631// Obtain the hidden albums displayed by album, that is, the albums with hidden files. Such albums do not include the preset hidden album and the albums in the trash. 632async function getHiddenAlbumsView() { 633 console.info('getHiddenAlbumsViewDemo'); 634 phAccessHelper.getHiddenAlbums(photoAccessHelper.HiddenPhotosDisplayMode.ALBUMS_MODE, async (err, fetchResult) => { 635 if (fetchResult === undefined) { 636 console.error('getHiddenAlbumsViewCallback fetchResult is undefined'); 637 return; 638 } 639 let albums: Array<photoAccessHelper.Album> = await fetchResult.getAllObjects(); 640 console.info('getHiddenAlbumsViewCallback successfully, albums size: ' + albums.length); 641 642 let predicates: dataSharePredicates.DataSharePredicates = new dataSharePredicates.DataSharePredicates(); 643 let fetchOption: photoAccessHelper.FetchOptions = { 644 fetchColumns: [], 645 predicates: predicates 646 }; 647 for (let i = 0; i < albums.length; i++) { 648 // Obtain hidden files in the album. 649 albums[i].getAssets(fetchOption, (err, assetFetchResult) => { 650 console.info('album get hidden assets successfully, getCount: ' + assetFetchResult.getCount()); 651 }); 652 } 653 fetchResult.close(); 654 }); 655} 656``` 657 658### getHiddenAlbums<sup>11+</sup> 659 660getHiddenAlbums(mode: HiddenPhotosDisplayMode, options?: FetchOptions): Promise<FetchResult<Album>> 661 662Obtains hidden albums based on the specified display mode and retrieval options. This API uses a promise to return the result. 663 664**System API**: This is a system API. 665 666**Required permissions**: ohos.permission.READ_IMAGEVIDEO and ohos.permission.MANAGE_PRIVATE_PHOTOS 667 668**System capability**: SystemCapability.FileManagement.PhotoAccessHelper.Core 669 670**Parameters** 671 672| Name | Type | Mandatory| Description | 673| -------- | ------------------------ | ---- | ------------------------- | 674| mode | [HiddenPhotosDisplayMode](#hiddenphotosdisplaymode11) | Yes | Display mode of hidden albums. | 675| options | [FetchOptions](js-apis-photoAccessHelper.md#fetchoptions) | No | Options for retrieving the files. If this parameter is not specified, the files are retrieved based on the display mode of hidden files. | 676 677**Return value** 678 679| Type | Description | 680| --------------------------- | -------------- | 681| Promise<[FetchResult](js-apis-photoAccessHelper.md#fetchresult)<[Album](#album)>> | Promise used to return the result. 682 683**Error codes** 684 685For details about the error codes, see [Universal Error Codes](../errorcode-universal.md) and [File Management Error Codes](../apis-core-file-kit/errorcode-filemanagement.md). 686 687| ID| Error Message| 688| -------- | ---------------------------------------- | 689| 201 | Permission verification failed, usually the result returned by VerifyAccessToken. | 690| 202 | Permission verification failed, application which is not a system application uses system API. | 691| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types; 3. Parameter verification failed. | 692| 14000011 | System inner fail. | 693 694**Example** 695 696```ts 697import { dataSharePredicates } from '@kit.ArkData'; 698import { BusinessError } from '@kit.BasicServicesKit'; 699 700// Obtain the preset hidden album. 701async function getSysHiddenAlbum() { 702 console.info('getSysHiddenAlbumDemo'); 703 phAccessHelper.getHiddenAlbums(photoAccessHelper.HiddenPhotosDisplayMode.ASSETS_MODE) 704 .then( async (fetchResult) => { 705 if (fetchResult === undefined) { 706 console.error('getSysHiddenAlbumPromise fetchResult is undefined'); 707 return; 708 } 709 let hiddenAlbum: photoAccessHelper.Album = await fetchResult.getFirstObject(); 710 console.info('getAlbumsPromise successfully, albumUri: ' + hiddenAlbum.albumUri); 711 fetchResult.close(); 712 }).catch((err: BusinessError) => { 713 console.error(`getSysHiddenAlbumPromise failed with err: ${err.code}, ${err.message}`); 714 }); 715} 716 717// Obtain the hidden albums displayed by album, that is, the albums with hidden files. Such albums do not include the preset hidden album and the albums in the trash. 718async function getHiddenAlbumsView() { 719 console.info('getHiddenAlbumsViewDemo'); 720 phAccessHelper.getHiddenAlbums(photoAccessHelper.HiddenPhotosDisplayMode.ALBUMS_MODE).then( async (fetchResult) => { 721 if (fetchResult === undefined) { 722 console.error('getHiddenAlbumsViewPromise fetchResult is undefined'); 723 return; 724 } 725 let albums: Array<photoAccessHelper.Album> = await fetchResult.getAllObjects(); 726 console.info('getHiddenAlbumsViewPromise successfully, albums size: ' + albums.length); 727 728 let predicates: dataSharePredicates.DataSharePredicates = new dataSharePredicates.DataSharePredicates(); 729 let fetchOption: photoAccessHelper.FetchOptions = { 730 fetchColumns: [], 731 predicates: predicates 732 }; 733 for (let i = 0; i < albums.length; i++) { 734 // Obtain hidden files in the album. 735 albums[i].getAssets(fetchOption).then((assetFetchResult) => { 736 console.info('album get hidden assets successfully, getCount: ' + assetFetchResult.getCount()); 737 }).catch((err: BusinessError) => { 738 console.error(`album get hidden assets failed with error: ${err.code}, ${err.message}`); 739 }); 740 } 741 fetchResult.close(); 742 }).catch((err: BusinessError) => { 743 console.error(`getHiddenAlbumsViewPromise failed with err: ${err.code}, ${err.message}`); 744 }); 745} 746``` 747 748### deleteAssets<sup>(deprecated)</sup> 749 750deleteAssets(uriList: Array<string>, callback: AsyncCallback<void>): void 751 752Deletes media assets. This API uses an asynchronous callback to return the result. The deleted assets are moved to the trash. 753 754> **NOTE** 755> 756> This API is supported since API version 10 and deprecated since API version 11. Use [MediaAssetChangeRequest.deleteAssets](js-apis-photoAccessHelper.md#deleteassets11) instead. 757 758**System API**: This is a system API. 759 760**Required permissions**: ohos.permission.WRITE_IMAGEVIDEO 761 762**System capability**: SystemCapability.FileManagement.PhotoAccessHelper.Core 763 764**Parameters** 765 766| Name | Type | Mandatory| Description | 767| -------- | ------------------------- | ---- | ---------- | 768| uriList | Array<string> | Yes | URIs of the media files to delete.| 769| callback | AsyncCallback<void> | Yes | Callback that returns no value.| 770 771**Error codes** 772 773For details about the error codes, see [Universal Error Codes](../errorcode-universal.md) and [File Management Error Codes](../apis-core-file-kit/errorcode-filemanagement.md). 774 775| ID| Error Message| 776| -------- | ---------------------------------------- | 777| 202 | Called by non-system application. | 778| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types; 3. Parameter verification failed. | 779| 13900012 | Permission denied. | 780| 13900020 | Invalid argument. | 781| 14000002 | Invalid uri. | 782| 14000011 | System inner fail. | 783 784**Example** 785 786```ts 787import { dataSharePredicates } from '@kit.ArkData'; 788 789async function example() { 790 console.info('deleteAssetDemo'); 791 let predicates: dataSharePredicates.DataSharePredicates = new dataSharePredicates.DataSharePredicates(); 792 let fetchOptions: photoAccessHelper.FetchOptions = { 793 fetchColumns: [], 794 predicates: predicates 795 }; 796 try { 797 let fetchResult: photoAccessHelper.FetchResult<photoAccessHelper.PhotoAsset> = await phAccessHelper.getAssets(fetchOptions); 798 let asset: photoAccessHelper.PhotoAsset = await fetchResult.getFirstObject(); 799 if (asset === undefined) { 800 console.error('asset not exist'); 801 return; 802 } 803 phAccessHelper.deleteAssets([asset.uri], (err) => { 804 if (err === undefined) { 805 console.info('deleteAssets successfully'); 806 } else { 807 console.error(`deleteAssets failed with error: ${err.code}, ${err.message}`); 808 } 809 }); 810 } catch (err) { 811 console.error(`fetch failed, error: ${err.code}, ${err.message}`); 812 } 813} 814``` 815 816### deleteAssets<sup>(deprecated)</sup> 817 818deleteAssets(uriList: Array<string>): Promise<void> 819 820Deletes media assets. This API uses a promise to return the result. The deleted assets are moved to the trash. 821 822> **NOTE** 823> 824> This API is supported since API version 10 and deprecated since API version 11. Use [MediaAssetChangeRequest.deleteAssets](js-apis-photoAccessHelper.md#deleteassets11) instead. 825 826**System API**: This is a system API. 827 828**Required permissions**: ohos.permission.WRITE_IMAGEVIDEO 829 830**System capability**: SystemCapability.FileManagement.PhotoAccessHelper.Core 831 832**Parameters** 833 834| Name | Type | Mandatory| Description | 835| -------- | ------------------------- | ---- | ---------- | 836| uriList | Array<string> | Yes | URIs of the media files to delete.| 837 838**Return value** 839 840| Type | Description | 841| --------------------------------------- | ----------------- | 842| Promise<void>| Promise that returns no value.| 843 844**Error codes** 845 846For details about the error codes, see [Universal Error Codes](../errorcode-universal.md) and [File Management Error Codes](../apis-core-file-kit/errorcode-filemanagement.md). 847 848| ID| Error Message| 849| -------- | ---------------------------------------- | 850| 202 | Called by non-system application. | 851| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types; 3. Parameter verification failed. | 852| 13900012 | Permission denied. | 853| 13900020 | Invalid argument. | 854| 14000002 | Invalid uri. | 855| 14000011 | System inner fail. | 856 857**Example** 858 859```ts 860import { dataSharePredicates } from '@kit.ArkData'; 861 862async function example() { 863 console.info('deleteDemo'); 864 let predicates: dataSharePredicates.DataSharePredicates = new dataSharePredicates.DataSharePredicates(); 865 let fetchOptions: photoAccessHelper.FetchOptions = { 866 fetchColumns: [], 867 predicates: predicates 868 }; 869 try { 870 let fetchResult: photoAccessHelper.FetchResult<photoAccessHelper.PhotoAsset> = await phAccessHelper.getAssets(fetchOptions); 871 let asset: photoAccessHelper.PhotoAsset = await fetchResult.getFirstObject(); 872 if (asset === undefined) { 873 console.error('asset not exist'); 874 return; 875 } 876 await phAccessHelper.deleteAssets([asset.uri]); 877 console.info('deleteAssets successfully'); 878 } catch (err) { 879 console.error(`deleteAssets failed with error: ${err.code}, ${err.message}`); 880 } 881} 882``` 883 884### getPhotoIndex 885 886getPhotoIndex(photoUri: string, albumUri: string, options: FetchOptions, callback: AsyncCallback<number>): void 887 888Obtains the index of an image or video in an album. This API uses an asynchronous callback to return the result. 889 890**System API**: This is a system API. 891 892**Required permissions**: ohos.permission.READ_IMAGEVIDEO 893 894**System capability**: SystemCapability.FileManagement.PhotoAccessHelper.Core 895 896**Parameters** 897 898| Name | Type | Mandatory| Description | 899| -------- | ------------------------- | ---- | ---------- | 900| photoUri | string | Yes | URI of the media asset whose index is to be obtained.| 901| albumUri | string | Yes | Album URI, which can be an empty string. If it is an empty string, all the media assets in the Gallery are obtained by default. | 902| options | [FetchOptions](js-apis-photoAccessHelper.md#fetchoptions) | Yes | Fetch options. Only one search condition or sorting mode must be set in **predicates**. If no value is set or multiple search criteria or sorting modes are set, the API cannot be called successfully. | 903| callback | AsyncCallback<number>| Yes | Callback used to return the index obtained.| 904 905**Error codes** 906 907For details about the error codes, see [Universal Error Codes](../errorcode-universal.md) and [File Management Error Codes](../apis-core-file-kit/errorcode-filemanagement.md). 908 909| ID| Error Message| 910| -------- | ---------------------------------------- | 911| 202 | Called by non-system application. | 912| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types; 3. Parameter verification failed. | 913| 13900012 | Permission denied. | 914| 13900020 | Invalid argument. | 915| 14000011 | System inner fail. | 916 917**Example** 918 919```ts 920import { dataSharePredicates } from '@kit.ArkData'; 921 922async function example() { 923 try { 924 console.info('getPhotoIndexDemo'); 925 let predicatesForGetAsset: dataSharePredicates.DataSharePredicates = new dataSharePredicates.DataSharePredicates(); 926 let fetchOp: photoAccessHelper.FetchOptions = { 927 fetchColumns: [], 928 predicates: predicatesForGetAsset 929 }; 930 // Obtain the uri of the album. 931 let albumFetchResult: photoAccessHelper.FetchResult<photoAccessHelper.Album> = await phAccessHelper.getAlbums(photoAccessHelper.AlbumType.SYSTEM, photoAccessHelper.AlbumSubtype.FAVORITE, fetchOp); 932 let album: photoAccessHelper.Album = await albumFetchResult.getFirstObject(); 933 let predicates: dataSharePredicates.DataSharePredicates = new dataSharePredicates.DataSharePredicates(); 934 predicates.orderByAsc(photoAccessHelper.PhotoKeys.DATE_MODIFIED); 935 let fetchOptions: photoAccessHelper.FetchOptions = { 936 fetchColumns: [photoAccessHelper.PhotoKeys.DATE_MODIFIED], 937 predicates: predicates 938 }; 939 let photoFetchResult: photoAccessHelper.FetchResult<photoAccessHelper.PhotoAsset> = await album.getAssets(fetchOptions); 940 let expectIndex = 1; 941 // Obtain the uri of the second file. 942 let photoAsset: photoAccessHelper.PhotoAsset = await photoFetchResult.getObjectByPosition(expectIndex); 943 944 phAccessHelper.getPhotoIndex(photoAsset.uri, album.albumUri, fetchOptions, (err, index) => { 945 if (err === undefined) { 946 console.info(`getPhotoIndex successfully and index is : ${index}`); 947 } else { 948 console.error(`getPhotoIndex failed; error: ${err.code}, ${err.message}`); 949 } 950 }); 951 } catch (error) { 952 console.error(`getPhotoIndex failed; error: ${error.code}, ${error.message}`); 953 } 954} 955``` 956 957### getPhotoIndex 958 959getPhotoIndex(photoUri: string, albumUri: string, options: FetchOptions): Promise<number> 960 961Obtains the index of an image or video in an album. This API uses a promise to return the result. 962 963**System API**: This is a system API. 964 965**Required permissions**: ohos.permission.READ_IMAGEVIDEO 966 967**System capability**: SystemCapability.FileManagement.PhotoAccessHelper.Core 968 969**Parameters** 970 971| Name | Type | Mandatory| Description | 972| -------- | ------------------------- | ---- | ---------- | 973| photoUri | string | Yes | URI of the media asset whose index is to be obtained.| 974| albumUri | string | Yes | Album URI, which can be an empty string. If it is an empty string, all the media assets in the Gallery are obtained by default. | 975| options | [FetchOptions](js-apis-photoAccessHelper.md#fetchoptions) | Yes | Fetch options. Only one search condition or sorting mode must be set in **predicates**. If no value is set or multiple search criteria or sorting modes are set, the API cannot be called successfully. | 976 977**Return value** 978 979| Type | Description | 980| --------------------------------------- | ----------------- | 981| Promise<number>| Promise used to return the index obtained.| 982 983**Error codes** 984 985For details about the error codes, see [Universal Error Codes](../errorcode-universal.md) and [File Management Error Codes](../apis-core-file-kit/errorcode-filemanagement.md). 986 987| ID| Error Message| 988| -------- | ---------------------------------------- | 989| 202 | Called by non-system application. | 990| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types; 3. Parameter verification failed. | 991| 13900012 | Permission denied. | 992| 13900020 | Invalid argument. | 993| 14000011 | System inner fail. | 994 995**Example** 996 997```ts 998import { dataSharePredicates } from '@kit.ArkData'; 999import { BusinessError } from '@kit.BasicServicesKit'; 1000 1001async function example() { 1002 try { 1003 console.info('getPhotoIndexDemo'); 1004 let predicatesForGetAsset: dataSharePredicates.DataSharePredicates = new dataSharePredicates.DataSharePredicates(); 1005 let fetchOp: photoAccessHelper.FetchOptions = { 1006 fetchColumns: [], 1007 predicates: predicatesForGetAsset 1008 }; 1009 // Obtain the uri of the album. 1010 let albumFetchResult: photoAccessHelper.FetchResult<photoAccessHelper.Album> = await phAccessHelper.getAlbums(photoAccessHelper.AlbumType.SYSTEM, photoAccessHelper.AlbumSubtype.FAVORITE, fetchOp); 1011 let album: photoAccessHelper.Album = await albumFetchResult.getFirstObject(); 1012 let predicates: dataSharePredicates.DataSharePredicates = new dataSharePredicates.DataSharePredicates(); 1013 predicates.orderByAsc(photoAccessHelper.PhotoKeys.DATE_MODIFIED); 1014 let fetchOptions: photoAccessHelper.FetchOptions = { 1015 fetchColumns: [photoAccessHelper.PhotoKeys.DATE_MODIFIED], 1016 predicates: predicates 1017 }; 1018 let photoFetchResult: photoAccessHelper.FetchResult<photoAccessHelper.PhotoAsset> = await album.getAssets(fetchOptions); 1019 let expectIndex = 1; 1020 // Obtain the uri of the second file. 1021 let photoAsset: photoAccessHelper.PhotoAsset = await photoFetchResult.getObjectByPosition(expectIndex); 1022 phAccessHelper.getPhotoIndex(photoAsset.uri, album.albumUri, fetchOptions).then((index) => { 1023 console.info(`getPhotoIndex successfully and index is : ${index}`); 1024 }).catch((err: BusinessError) => { 1025 console.error(`getPhotoIndex failed; error: ${err.code}, ${err.message}`); 1026 }); 1027 } catch (error) { 1028 console.error(`getPhotoIndex failed; error: ${error.code}, ${error.message}`); 1029 } 1030} 1031``` 1032 1033### saveFormInfo<sup>11+</sup> 1034 1035saveFormInfo(info:FormInfo, callback: AsyncCallback<void>):void 1036 1037Saves a Gallery widget. This API uses an asynchronous callback to return the result. 1038 1039**System API**: This is a system API. 1040 1041**Required permissions**: ohos.permission.WRITE_IMAGEVIDEO 1042 1043**System capability**: SystemCapability.FileManagement.PhotoAccessHelper.Core 1044 1045**Parameters** 1046 1047| Name | Type | Mandatory| Description | 1048| -------- | ------------------------ | ---- | ------------------------- | 1049| info | [FormInfo](#forminfo11) | Yes | Information about the Gallery widget to save, which includes the ID of the widget and the URI of the image bound to the widget. | 1050| callback | AsyncCallback<void> | Yes | Callback that returns no value.| 1051 1052**Error codes** 1053 1054For details about the error codes, see [Universal Error Codes](../errorcode-universal.md) and [File Management Error Codes](../apis-core-file-kit/errorcode-filemanagement.md). 1055 1056| ID| Error Message| 1057| -------- | ---------------------------------------- | 1058| 201 | Permission verification failed, usually the result returned by VerifyAccessToken. | 1059| 202 | Permission verification failed, application which is not a system application uses system API. | 1060| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types; 3. Parameter verification failed. | 1061| 14000011 | System inner fail. | 1062 1063 1064**Example** 1065 1066```ts 1067import { dataSharePredicates } from '@kit.ArkData'; 1068import { BusinessError } from '@kit.BasicServicesKit'; 1069 1070async function example() { 1071 console.info('saveFormInfoDemo'); 1072 let predicates: dataSharePredicates.DataSharePredicates = new dataSharePredicates.DataSharePredicates(); 1073 let fetchOptions: photoAccessHelper.FetchOptions = { 1074 fetchColumns: [], 1075 predicates: predicates 1076 }; 1077 let fetchResult: photoAccessHelper.FetchResult<photoAccessHelper.PhotoAsset> = await phAccessHelper.getAssets(fetchOptions); 1078 let photoAsset: photoAccessHelper.PhotoAsset = await fetchResult.getFirstObject(); 1079 1080 let info: photoAccessHelper.FormInfo = { 1081 // formId is a string consisting of only digits. uri indicates the URI of the image in Gallery. If there is no image in Gallery, uri must be an empty string. 1082 formId : "20230116123", 1083 uri: photoAsset.uri, 1084 } 1085 1086 phAccessHelper.saveFormInfo(info, async (err: BusinessError) => { 1087 if (err == undefined) { 1088 console.info('saveFormInfo success'); 1089 } else { 1090 console.error(`saveFormInfo fail with error: ${err.code}, ${err.message}`); 1091 } 1092 }); 1093} 1094``` 1095 1096### saveFormInfo<sup>11+</sup> 1097 1098saveFormInfo(info:FormInfo):Promise<void> 1099 1100Saves a Gallery widget. This API uses a promise to return the result. 1101 1102**System API**: This is a system API. 1103 1104**Required permissions**: ohos.permission.WRITE_IMAGEVIDEO 1105 1106**System capability**: SystemCapability.FileManagement.PhotoAccessHelper.Core 1107 1108**Parameters** 1109 1110| Name | Type | Mandatory| Description | 1111| -------- | ------------------------ | ---- | ------------------------- | 1112| info | [FormInfo](#forminfo11) | Yes | Information about the Gallery widget to save, which includes the ID of the widget and the URI of the image bound to the widget. | 1113 1114**Return value** 1115 1116| Type | Description | 1117| --------------------------------------- | ----------------- | 1118| Promise<void>| Promise that returns no value.| 1119 1120**Error codes** 1121 1122For details about the error codes, see [Universal Error Codes](../errorcode-universal.md) and [File Management Error Codes](../apis-core-file-kit/errorcode-filemanagement.md). 1123 1124| ID| Error Message| 1125| -------- | ---------------------------------------- | 1126| 201 | Permission verification failed, usually the result returned by VerifyAccessToken. | 1127| 202 | Permission verification failed, application which is not a system application uses system API. | 1128| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types; 3. Parameter verification failed. | 1129| 14000011 | System inner fail. | 1130 1131**Example** 1132 1133```ts 1134import { dataSharePredicates } from '@kit.ArkData'; 1135import { BusinessError } from '@kit.BasicServicesKit'; 1136 1137async function example() { 1138 console.info('saveFormInfoDemo'); 1139 let predicates: dataSharePredicates.DataSharePredicates = new dataSharePredicates.DataSharePredicates(); 1140 let fetchOptions: photoAccessHelper.FetchOptions = { 1141 fetchColumns: [], 1142 predicates: predicates 1143 }; 1144 let fetchResult: photoAccessHelper.FetchResult<photoAccessHelper.PhotoAsset> = await phAccessHelper.getAssets(fetchOptions); 1145 let photoAsset: photoAccessHelper.PhotoAsset = await fetchResult.getFirstObject(); 1146 1147 let info: photoAccessHelper.FormInfo = { 1148 // formId is a string consisting of only digits. uri indicates the URI of the image in Gallery. If there is no image in Gallery, uri must be an empty string. 1149 formId: "20230116123", 1150 uri: photoAsset.uri, 1151 } 1152 1153 phAccessHelper.saveFormInfo(info).then(() => { 1154 console.info('saveFormInfo successfully'); 1155 }).catch((err: BusinessError) => { 1156 console.error(`saveFormInfo failed with error: ${err.code}, ${err.message}`); 1157 }); 1158} 1159``` 1160 1161### removeFormInfo<sup>11+</sup> 1162 1163removeFormInfo(info:FormInfo, callback: AsyncCallback<void>):void 1164 1165Removes a Gallery widget. This API uses an asynchronous callback to return the result. 1166 1167**System API**: This is a system API. 1168 1169**Required permissions**: ohos.permission.WRITE_IMAGEVIDEO 1170 1171**System capability**: SystemCapability.FileManagement.PhotoAccessHelper.Core 1172 1173**Parameters** 1174 1175| Name | Type | Mandatory| Description | 1176| -------- | ------------------------ | ---- | ------------------------- | 1177| info | [FormInfo](#forminfo11) | Yes | Information about the Gallery widget to save, which includes the ID of the widget and the URI of the image bound to the widget. | 1178| callback | AsyncCallback<void> | Yes | Callback that returns no value.| 1179 1180**Error codes** 1181 1182For details about the error codes, see [Universal Error Codes](../errorcode-universal.md) and [File Management Error Codes](../apis-core-file-kit/errorcode-filemanagement.md). 1183 1184| ID| Error Message| 1185| -------- | ---------------------------------------- | 1186| 201 | Permission verification failed, usually the result returned by VerifyAccessToken. | 1187| 202 | Permission verification failed, application which is not a system application uses system API. | 1188| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types; 3. Parameter verification failed. | 1189| 14000011 | System inner fail. | 1190 1191**Example** 1192 1193```ts 1194import { BusinessError } from '@kit.BasicServicesKit'; 1195 1196async function example() { 1197 console.info('removeFormInfoDemo'); 1198 let info: photoAccessHelper.FormInfo = { 1199 // formId is a string consisting of only digits. When removing a widget, leave uri empty. 1200 formId: "20230116123", 1201 uri: "", 1202 } 1203 1204 phAccessHelper.removeFormInfo(info, async (err: BusinessError) => { 1205 if (err == undefined) { 1206 console.info('removeFormInfo success'); 1207 } else { 1208 console.error(`removeFormInfo fail with error: ${err.code}, ${err.message}`); 1209 } 1210 }); 1211} 1212``` 1213 1214### removeFormInfo<sup>11+</sup> 1215 1216removeFormInfo(info:FormInfo):Promise<void> 1217 1218Removes a Gallery widget. This API uses a promise to return the result. 1219 1220**System API**: This is a system API. 1221 1222**Required permissions**: ohos.permission.WRITE_IMAGEVIDEO 1223 1224**System capability**: SystemCapability.FileManagement.PhotoAccessHelper.Core 1225 1226**Parameters** 1227 1228| Name | Type | Mandatory| Description | 1229| -------- | ------------------------ | ---- | ------------------------- | 1230| info | [FormInfo](#forminfo11) | Yes | Information about the Gallery widget to save, which includes the ID of the widget and the URI of the image bound to the widget. | 1231 1232**Return value** 1233 1234| Type | Description | 1235| --------------------------------------- | ----------------- | 1236| Promise<void>| Promise that returns no value.| 1237 1238**Error codes** 1239 1240For details about the error codes, see [Universal Error Codes](../errorcode-universal.md) and [File Management Error Codes](../apis-core-file-kit/errorcode-filemanagement.md). 1241 1242| ID| Error Message| 1243| -------- | ---------------------------------------- | 1244| 201 | Permission verification failed, usually the result returned by VerifyAccessToken. | 1245| 202 | Permission verification failed, application which is not a system application uses system API. | 1246| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types; 3. Parameter verification failed. | 1247| 14000011 | System inner fail. | 1248 1249**Example** 1250 1251```ts 1252import { BusinessError } from '@kit.BasicServicesKit'; 1253 1254async function example() { 1255 console.info('removeFormInfoDemo'); 1256 let info: photoAccessHelper.FormInfo = { 1257 // formId is a string consisting of only digits. When removing a widget, leave uri empty. 1258 formId: "20230116123", 1259 uri: "", 1260 } 1261 1262 phAccessHelper.removeFormInfo(info).then(() => { 1263 console.info('removeFormInfo successfully'); 1264 }).catch((err: BusinessError) => { 1265 console.error(`removeFormInfo failed with error: ${err.code}, ${err.message}`); 1266 }); 1267} 1268``` 1269 1270### createAssetsForApp<sup>12+</sup> 1271 1272createAssetsForApp(bundleName: string, appName: string, appId: string, photoCreationConfigs: Array<PhotoCreationConfig>): Promise<Array<string>> 1273 1274Creates media assets for an application. The returned URIs has been granted with the permission for writing the media assets (images or videos). 1275 1276**System API**: This is a system API. 1277 1278**Required permissions**: ohos.permission.WRITE_IMAGEVIDEO 1279 1280**System capability**: SystemCapability.FileManagement.PhotoAccessHelper.Core 1281 1282**Parameters** 1283 1284| Name | Type | Mandatory| Description | 1285| -------- |----------------------------------------------------------------------| ---- | ------------------------- | 1286| bundleName | string | Yes| Bundle name of the target application.| 1287| appName | string | Yes| Name of the target application.| 1288| appId | string | Yes| ID of the target application.| 1289| photoCreationConfigs | Array<[PhotoCreationConfig](./js-apis-photoAccessHelper.md#photocreationconfig12)> | Yes| Configuration for creating (saving) the media assets in the media library.| 1290 1291**Return value** 1292 1293| Type | Description | 1294| --------------------------------------- | ----------------- | 1295| Promise<Array<string>> | Promise used to return the URIs of the media asset files in the media library. The target application (identified by **appid**) can write the media assets based on the URIs without requesting the write permission. If the URIs fail to be generated, a batch creation error code will be returned.<br>The error code **-3006** means that there are invalid characters; **-2004** means that the image type does not match the file name extension; **-203** means that the file operation is abnormal.| 1296 1297**Error codes** 1298 1299For details about the error codes, see [Universal Error Codes](../errorcode-universal.md) and [File Management Error Codes](../apis-core-file-kit/errorcode-filemanagement.md). 1300 1301| ID| Error Message| 1302| -------- | ---------------------------------------- | 1303| 201 | Permission denied. | 1304| 202 | Called by non-system application. | 1305| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameters types; 3. Parameter verification failed. | 1306| 14000011 | Internal system error. | 1307 1308**Example** 1309 1310```ts 1311async function example() { 1312 console.info('createAssetsForAppDemo.'); 1313 1314 try { 1315 let bundleName: string = 'testBundleName'; 1316 let appName: string = 'testAppName'; 1317 let appId: string = 'testAppId'; 1318 let photoCreationConfigs: Array<photoAccessHelper.PhotoCreationConfig> = [ 1319 { 1320 title: 'test', 1321 fileNameExtension: 'jpg', 1322 photoType: photoAccessHelper.PhotoType.IMAGE, 1323 subtype: photoAccessHelper.PhotoSubtype.DEFAULT, 1324 } 1325 ]; 1326 let desFileUris: Array<string> = await phAccessHelper.createAssetsForApp(bundleName, appName, appId, photoCreationConfigs); 1327 console.info('createAssetsForApp success, data is ' + desFileUris); 1328 } catch (err) { 1329 console.error(`createAssetsForApp failed with error: ${err.code}, ${err.message}`); 1330 } 1331} 1332``` 1333 1334### grantPhotoUriPermission<sup>15+</sup> 1335 1336grantPhotoUriPermission(tokenId: number, uri: string, photoPermissionType: PhotoPermissionType, hideSensitiveType: HideSensitiveType): Promise<number> 1337 1338Grants an application the permission to access a URI. This API uses a promise to return the result. 1339 1340**System API**: This is a system API. 1341 1342**System capability**: SystemCapability.FileManagement.PhotoAccessHelper.Core 1343 1344**Required permissions**: ohos.permission.WRITE_IMAGEVIDEO 1345 1346**Parameters** 1347 1348| Name | Type | Mandatory| Description | 1349| -------- |----------------------------------------------------------------------| ---- | ------------------------- | 1350| tokenId | number | Yes| ID of the target application.| 1351| uri | string | Yes| URI of the media asset.| 1352| photoPermissionType | [PhotoPermissionType](#photopermissiontype12) | Yes| Type of the permission to be granted. For details, see the enum.| 1353| hideSensitiveType | [HideSensitiveType](#hidesensitivetype12) | Yes| Type of the information to hide. This parameter is reserved. Currently, any enumerated value of **HideSensitiveType** can be passed in.| 1354 1355**Return value** 1356 1357| Type | Description | 1358| --------------------------------------- | ----------------- | 1359| Promise<number> | Promise used to return the result. The value **0** means the permission is granted to the application. The value **1** means the application already has the permission. The value **-1** means the permission fails to be granted.| 1360 1361**Error codes** 1362 1363For details about the error codes, see [Universal Error Codes](../errorcode-universal.md) and [File Management Error Codes](../apis-core-file-kit/errorcode-filemanagement.md). 1364 1365| ID| Error Message| 1366| -------- | ---------------------------------------- | 1367| 201 | Permission denied. | 1368| 202 | Called by non-system application. | 1369| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameters types; 3. Parameter verification failed. | 1370| 14000011 | Internal system error. | 1371 1372**Example** 1373 1374```ts 1375async function example() { 1376 console.info('grantPhotoUriPermissionDemo'); 1377 1378 try { 1379 let tokenId = 502334412; 1380 let result = await phAccessHelper.grantPhotoUriPermission(tokenId, 1381 'file://media/Photo/1/IMG_datetime_0001/displayName.jpg', 1382 photoAccessHelper.PhotoPermissionType.TEMPORARY_READ_IMAGEVIDEO, 1383 photoAccessHelper.HideSensitiveType.HIDE_LOCATION_AND_SHOTING_PARM); 1384 1385 console.info('grantPhotoUriPermission success, result=' + result); 1386 } catch (err) { 1387 console.error('grantPhotoUriPermission failed, error=' + err); 1388 } 1389} 1390``` 1391 1392### grantPhotoUrisPermission<sup>15+</sup> 1393 1394grantPhotoUrisPermission(tokenId: number, uriList: Array<string>, photoPermissionType: PhotoPermissionType, hideSensitiveType: HideSensitiveType): Promise<number> 1395 1396Grants an application the permission to access multiple URIs. This API uses a promise to return the result. 1397 1398**System API**: This is a system API. 1399 1400**System capability**: SystemCapability.FileManagement.PhotoAccessHelper.Core 1401 1402**Required permissions**: ohos.permission.WRITE_IMAGEVIDEO 1403 1404**Parameters** 1405 1406| Name | Type | Mandatory| Description | 1407| -------- |----------------------------------------------------------------------| ---- | ------------------------- | 1408| tokenId | number | Yes| ID of the target application.| 1409| uriList | Array<string> | Yes| A list of URIs, which cannot exceed 1000.| 1410| photoPermissionType | [PhotoPermissionType](#photopermissiontype12) | Yes| Type of the permission to be granted. For details, see the enum.| 1411| hideSensitiveType | [HideSensitiveType](#hidesensitivetype12) | Yes| Type of the information to hide. This parameter is reserved. Currently, any enumerated value of **HideSensitiveType** can be passed in.| 1412 1413**Return value** 1414 1415| Type | Description | 1416| --------------------------------------- | ----------------- | 1417| Promise<number> | Promise used to return the result. The value **0** means the operation is successful; the value **-1** means the opposite.| 1418 1419**Error codes** 1420 1421For details about the error codes, see [Universal Error Codes](../errorcode-universal.md) and [File Management Error Codes](../apis-core-file-kit/errorcode-filemanagement.md). 1422 1423| ID| Error Message| 1424| -------- | ---------------------------------------- | 1425| 201 | Permission denied. | 1426| 202 | Called by non-system application. | 1427| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameters types; 3. Parameter verification failed. | 1428| 14000011 | Internal system error. | 1429 1430**Example** 1431 1432```ts 1433async function example() { 1434 console.info('grantPhotoUrisPermissionDemo'); 1435 1436 try { 1437 // URIs of the media assets. 1438 let uris: Array<string> = [ 1439 'file://media/Photo/11/IMG_datetime_0001/displayName1.jpg', 1440 'file://media/Photo/22/IMG_datetime_0002/displayName2.jpg']; 1441 let tokenId = 502334412; 1442 let result = await phAccessHelper.grantPhotoUrisPermission(tokenId, uris, 1443 photoAccessHelper.PhotoPermissionType.TEMPORARY_READ_IMAGEVIDEO, 1444 photoAccessHelper.HideSensitiveType.HIDE_LOCATION_AND_SHOTING_PARM); 1445 1446 console.info('grantPhotoUrisPermission success, result=' + result); 1447 } catch (err) { 1448 console.error('grantPhotoUrisPermission failed, error=' + err); 1449 } 1450} 1451``` 1452 1453### cancelPhotoUriPermission<sup>15+</sup> 1454 1455cancelPhotoUriPermission(tokenId: number, uri: string, photoPermissionType: PhotoPermissionType): Promise<number> 1456 1457Cancels the permission for accessing an URI from an application. This API uses a promise to return the result. 1458 1459**System API**: This is a system API. 1460 1461**System capability**: SystemCapability.FileManagement.PhotoAccessHelper.Core 1462 1463**Required permissions**: ohos.permission.WRITE_IMAGEVIDEO 1464 1465**Parameters** 1466 1467| Name | Type | Mandatory| Description | 1468| -------- |----------------------------------------------------------------------| ---- | ------------------------- | 1469| tokenId | number | Yes| ID of the target application.| 1470| uri | string | Yes| URI of the media asset.| 1471| photoPermissionType | [PhotoPermissionType](#photopermissiontype12) | Yes| Permission type.| 1472 1473**Return value** 1474 1475| Type | Description | 1476| --------------------------------------- | ----------------- | 1477| Promise<number> | Promise used to return the result. The value **0** means the operation is successful; the value **-1** means the opposite.| 1478 1479**Error codes** 1480 1481For details about the error codes, see [Universal Error Codes](../errorcode-universal.md) and [File Management Error Codes](../apis-core-file-kit/errorcode-filemanagement.md). 1482 1483| ID| Error Message| 1484| -------- | ---------------------------------------- | 1485| 201 | Permission denied. | 1486| 202 | Called by non-system application. | 1487| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameters types; 3. Parameter verification failed. | 1488| 14000011 | Internal system error. | 1489 1490**Example** 1491 1492```ts 1493async function example() { 1494 console.info('cancelPhotoUriPermissionDemo'); 1495 1496 try { 1497 let tokenId = 502334412; 1498 let result = await phAccessHelper.cancelPhotoUriPermission(tokenId, 1499 'file://media/Photo/11/IMG_datetime_0001/displayName.jpg', 1500 photoAccessHelper.PhotoPermissionType.TEMPORARY_READ_IMAGEVIDEO); 1501 1502 console.info('cancelPhotoUriPermission success, result=' + result); 1503 } catch (err) { 1504 console.error('cancelPhotoUriPermission failed, error=' + err); 1505 } 1506} 1507``` 1508 1509### createAssetsForAppWithMode<sup>12+</sup> 1510 1511createAssetsForAppWithMode(boundleName: string, appName: string, appId: string, tokenId: number, authorizationMode: AuthorizationMode, photoCreationConfigs:Array\<PhotoCreationConfig>): Promise\<Array\<string>> 1512 1513Creates assets with a temporary permission. This API uses a promise to return the result. 1514 1515**System API**: This is a system API. 1516 1517**System capability**: SystemCapability.FileManagement.PhotoAccessHelper.Core 1518 1519**Required permissions**: ohos.permission.WRITE_IMAGEVIDEO 1520 1521**Parameters** 1522 1523| Name | Type | Mandatory| Description | 1524| -------- |----------------------------------------------------------------------| ---- | ------------------------- | 1525| boundleName| string | Yes| Bundle name of the target application.| 1526| appName| string | Yes| Name of the target application.| 1527| appId| string | Yes| ID of the target application.| 1528| tokenId| number| Yes| Unique identifier for the temporary authorization.| 1529| authorizationMode| [AuthorizationMode](#authorizationmode12)| Yes| Authorization mode. No confirmation dialog box is displayed when the application with the temporary permission saves media assets in the give period of time.| 1530| PhotoCreationConfig| Array\<[PhotoCreationConfig](js-apis-photoAccessHelper.md#photocreationconfig12)> | Yes| Configuration for creating (saving) the media assets in the media library.| 1531 1532**Return value** 1533 1534| Type | Description | 1535| --------------------------------------- | ----------------- | 1536| Promise\<Array\<string>> | Promise used to return the URIs of the media asset files in the media library. The target application (identified by **appid**) can write the assets based on the URIs without has been authorized to the application specified by appId to allow the application to write data. If the URIs fail to be generated, a batch creation error code will be returned.<br>The error code **-3006** means that there are invalid characters; **-2004** means that the image type does not match the file name extension; **-203** means that the file operation is abnormal.| 1537 1538**Error codes** 1539 1540For details about the error codes, see [Universal Error Codes](../errorcode-universal.md) and [File Management Error Codes](../apis-core-file-kit/errorcode-filemanagement.md). 1541 1542| ID| Error Message| 1543| -------- | ---------------------------------------- | 1544| 201 | Permission denied. | 1545| 202 | Called by non-system application. | 1546| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameters types; 3. Parameter verification failed. | 1547| 14000011 | Internal system error. | 1548 1549**Example** 1550 1551```ts 1552async function example() { 1553 console.info('createAssetsForAppWithModeDemo.'); 1554 1555 try { 1556 let photoCreationConfigs: Array<photoAccessHelper.PhotoCreationConfig> = [ 1557 { 1558 title: '123456', 1559 fileNameExtension: 'jpg', 1560 photoType: photoAccessHelper.PhotoType.IMAGE, 1561 subtype: photoAccessHelper.PhotoSubtype.DEFAULT, 1562 } 1563 ]; 1564 let bundleName: string = 'testBundleName'; 1565 let appName: string = 'testAppName'; 1566 let appId: string = 'testAppId'; 1567 let tokenId: number = 537197950; 1568 let authorizationMode: photoAccessHelper.AuthorizationMode = photoAccessHelper.AuthorizationMode.SHORT_TIME_AUTHORIZATION; 1569 let result: Array<string> = await phAccessHelper.createAssetsForAppWithMode(bundleName, appName, appId, tokenId, authorizationMode, photoCreationConfigs); 1570 console.info(`result: ${JSON.stringify(result)}`); 1571 console.info('Photo createAssetsForAppWithMode success.'); 1572 } catch (err) { 1573 console.error(`createAssetsForAppWithMode failed with error: ${err.code}, ${err.message}`); 1574 } 1575} 1576``` 1577 1578### getKeyFrameThumbnail<sup>18+</sup> 1579 1580getKeyFrameThumbnail(beginFrameTimeMs: number, type: ThumbnailType): Promise<image.PixelMap> 1581 1582Obtains the thumbnail of the specified type for the key frame. This API uses a promise to return the result. 1583 1584**System API**: This is a system API. 1585 1586**System capability**: SystemCapability.FileManagement.PhotoAccessHelper.Core 1587 1588**Required permissions**: ohos.permission.READ_IMAGEVIDEO 1589 1590**Parameters** 1591 1592| Name | Type | Mandatory | Description | 1593| ---- | -------------- | ---- | ----- | 1594| beginFrameTimeMs | number | Yes | Time of the start frame, in ms. <br>The value **0** indicates the cover frame.| 1595| type | [ThumbnailType](#thumbnailtype13)| Yes | Type of the thumbnail.| 1596 1597**Return value** 1598 1599| Type | Description | 1600| ----------------------------- | --------------------- | 1601| Promise<[image.PixelMap](../apis-image-kit/js-apis-image.md#pixelmap7)> | Promise used to return the PixelMap of the thumbnail obtained. The cover frame is returned by default if no thumbnail is obtained.| 1602 1603**Error codes** 1604 1605For details about the error codes, see [Universal Error Codes](../errorcode-universal.md) and [File Management Error Codes](../apis-core-file-kit/errorcode-filemanagement.md). 1606 1607| ID| Error Message| 1608| -------- | ---------------------------------------- | 1609| 201 | Permission denied. | 1610| 202 | Called by non-system application. | 1611| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types; 3. Parameter verification failed. | 1612| 14000011 | Internal system error. 1613 1614**Example** 1615 1616```ts 1617import { common } from '@kit.AbilityKit'; 1618import { photoAccessHelper } from '@kit.MediaLibraryKit'; 1619import { dataSharePredicates } from '@kit.ArkData'; 1620import { image } from '@kit.ImageKit'; 1621 1622async function example() { 1623 try{ 1624 console.info('getKeyFrameThumbnail demo'); 1625 let context = getContext(this) as common.UIAbilityContext; 1626 let phAccessHelper:photoAccessHelper.PhotoAccessHelper = photoAccessHelper.getPhotoAccessHelper(context); 1627 let predicates: dataSharePredicates.DataSharePredicates = new dataSharePredicates.DataSharePredicates(); 1628 predicates.equalTo(photoAccessHelper.PhotoKeys.PHOTO_TYPE, photoAccessHelper.PhotoType.VIDEO); 1629 let fetchOption: photoAccessHelper.FetchOptions = { 1630 fetchColumns: [], 1631 predicates: predicates 1632 }; 1633 let fetchResult: photoAccessHelper.FetchResult<photoAccessHelper.PhotoAsset> = await phAccessHelper.getAssets(fetchOption); 1634 let asset: photoAccessHelper.PhotoAsset = await fetchResult.getLastObject(); 1635 let pixelMap: image.PixelMap = await asset.getKeyFrameThumbnail(0, photoAccessHelper.ThumbnailType.LCD); 1636 console.info('getKeyFrameThumbnail success'); 1637 } catch (error) { 1638 console.error('getKeyFrameThumbnail failed, error: ' + JSON.stringify(error)); 1639 } 1640} 1641``` 1642 1643### saveGalleryFormInfo<sup>18+</sup> 1644 1645saveGalleryFormInfo(info:GalleryFormInfo):Promise<void> 1646 1647Saves a Gallery widget. This API uses a promise to return the result. 1648 1649**System API**: This is a system API. 1650 1651**Required permissions**: ohos.permission.WRITE_IMAGEVIDEO 1652 1653**System capability**: SystemCapability.FileManagement.PhotoAccessHelper.Core 1654 1655**Parameters** 1656 1657| Name | Type | Mandatory| Description | 1658| -------- | ------------------------ | ---- | ------------------------- | 1659| info | [GalleryFormInfo](#galleryforminfo18) | Yes | Information about the Gallery widget, which includes the ID of the widget and the URIs of the image or album bound to the widget. | 1660 1661**Return value** 1662 1663| Type | Description | 1664| --------------------------------------- | ----------------- | 1665| Promise<void>| Promise that returns no value.| 1666 1667**Error codes** 1668 1669For details about the error codes, see [Universal Error Codes](../errorcode-universal.md) and [File Management Error Codes](../apis-core-file-kit/errorcode-filemanagement.md). 1670 1671| ID| Error Message| 1672| -------- | ---------------------------------------- | 1673| 201 | Permission verification failed, usually the result returned by VerifyAccessToken. | 1674| 202 | Permission verification failed, application which is not a system application uses system API. | 1675| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types; 3. Parameter verification failed. | 1676| 14000011 | System inner fail. | 1677 1678**Example** 1679 1680```ts 1681import { dataSharePredicates } from '@kit.ArkData'; 1682import { BusinessError } from '@kit.BasicServicesKit'; 1683import {photoAccessHelper} from '@kit.MediaLibraryKit'; 1684const context = getContext(this); 1685let phAccessHelper = photoAccessHelper.getPhotoAccessHelper(context); 1686 1687async function example() { 1688 console.info('saveGalleryFormInfoDemo'); 1689 let predicates: dataSharePredicates.DataSharePredicates = new dataSharePredicates.DataSharePredicates(); 1690 let fetchOptions: photoAccessHelper.FetchOptions = { 1691 fetchColumns: [], 1692 predicates: predicates 1693 }; 1694 let fetchResult: photoAccessHelper.FetchResult<photoAccessHelper.PhotoAsset> = await phAccessHelper.getAssets(fetchOptions); 1695 let photoAsset: photoAccessHelper.PhotoAsset = await fetchResult.getFirstObject(); 1696 let uriList: Array<string> = [ 1697 photoAsset.uri, 1698 ]; 1699 let info: photoAccessHelper.GalleryFormInfo = { 1700 // formId is a string consisting of only digits. assetUris indicates the URIs of the images or albums in Gallery. 1701 formId: "20230116123", 1702 assetUris: uriList, 1703 } 1704 1705 phAccessHelper.saveGalleryFormInfo(info).then(() => { 1706 console.info('saveGalleryFormInfo successfully'); 1707 }).catch((err: BusinessError) => { 1708 console.error(`saveGalleryFormInfo failed with error: ${err.code}, ${err.message}`); 1709 }); 1710} 1711``` 1712 1713### updateGalleryFormInfo<sup>18+</sup> 1714 1715updateGalleryFormInfo(info:GalleryFormInfo):Promise<void> 1716 1717Updates the information about a Gallery widget and saves the information to the database. This API uses a promise to return the result. 1718 1719**System API**: This is a system API. 1720 1721**Required permissions**: ohos.permission.WRITE_IMAGEVIDEO 1722 1723**System capability**: SystemCapability.FileManagement.PhotoAccessHelper.Core 1724 1725**Parameters** 1726 1727| Name | Type | Mandatory| Description | 1728| -------- | ------------------------ | ---- | ------------------------- | 1729| info | [GalleryFormInfo](#galleryforminfo18) | Yes | Information about the Gallery widget, which includes the ID of the widget and the URIs of the image or album bound to the widget. | 1730 1731**Return value** 1732 1733| Type | Description | 1734| --------------------------------------- | ----------------- | 1735| Promise<void>| Promise that returns no value.| 1736 1737**Error codes** 1738 1739For details about the error codes, see [Universal Error Codes](../errorcode-universal.md) and [File Management Error Codes](../apis-core-file-kit/errorcode-filemanagement.md). 1740 1741| ID| Error Message| 1742| -------- | ---------------------------------------- | 1743| 201 | Permission verification failed, usually the result returned by VerifyAccessToken. | 1744| 202 | Permission verification failed, application which is not a system application uses system API. | 1745| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types; 3. Parameter verification failed. | 1746| 14000011 | System inner fail. | 1747 1748**Example** 1749 1750```ts 1751import { dataSharePredicates } from '@kit.ArkData'; 1752import { BusinessError } from '@kit.BasicServicesKit'; 1753import {photoAccessHelper} from '@kit.MediaLibraryKit'; 1754const context = getContext(this); 1755let phAccessHelper = photoAccessHelper.getPhotoAccessHelper(context); 1756 1757async function example() { 1758 console.info('updateGalleryFormInfoDemo'); 1759 let predicates: dataSharePredicates.DataSharePredicates = new dataSharePredicates.DataSharePredicates(); 1760 let fetchOptions: photoAccessHelper.FetchOptions = { 1761 fetchColumns: [], 1762 predicates: predicates 1763 }; 1764 let fetchResult: photoAccessHelper.FetchResult<photoAccessHelper.PhotoAsset> = await phAccessHelper.getAssets(fetchOptions); 1765 let photoAsset: photoAccessHelper.PhotoAsset = await fetchResult.getFirstObject(); 1766 let photoAssetLast: photoAccessHelper.PhotoAsset = await fetchResult.getLastObject(); 1767 let uriList: Array<string> = [ 1768 photoAsset.uri, 1769 photoAssetLast.uri 1770 ]; 1771 let info: photoAccessHelper.GalleryFormInfo = { 1772 // formId is a string consisting of only digits. assetUris indicates the URIs of the images or albums in Gallery. 1773 formId: "20230116123", 1774 assetUris: uriList, 1775 } 1776 1777 phAccessHelper.updateGalleryFormInfo(info).then(() => { 1778 console.info('updateGalleryFormInfo successfully'); 1779 }).catch((err: BusinessError) => { 1780 console.error(`updateGalleryFormInfo failed with error: ${err.code}, ${err.message}`); 1781 }); 1782} 1783``` 1784 1785### removeGalleryFormInfo<sup>18+</sup> 1786 1787removeGalleryFormInfo(info:GalleryFormInfo):Promise<void> 1788 1789Removes a Gallery widget. This API uses a promise to return the result. 1790 1791**System API**: This is a system API. 1792 1793**Required permissions**: ohos.permission.WRITE_IMAGEVIDEO 1794 1795**System capability**: SystemCapability.FileManagement.PhotoAccessHelper.Core 1796 1797**Parameters** 1798 1799| Name | Type | Mandatory| Description | 1800| -------- | ------------------------ | ---- | ------------------------- | 1801| info | [GalleryFormInfo](#galleryforminfo18) | Yes | Information about the Gallery widget, which includes the ID of the widget and the URIs of the image or album bound to the widget. | 1802 1803**Return value** 1804 1805| Type | Description | 1806| --------------------------------------- | ----------------- | 1807| Promise<void>| Promise that returns no value.| 1808 1809**Error codes** 1810 1811For details about the error codes, see [Universal Error Codes](../errorcode-universal.md) and [File Management Error Codes](../apis-core-file-kit/errorcode-filemanagement.md). 1812 1813| ID| Error Message| 1814| -------- | ---------------------------------------- | 1815| 201 | Permission verification failed, usually the result returned by VerifyAccessToken. | 1816| 202 | Permission verification failed, application which is not a system application uses system API. | 1817| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types; 3. Parameter verification failed. | 1818| 14000011 | System inner fail. | 1819 1820**Example** 1821 1822```ts 1823import { BusinessError } from '@kit.BasicServicesKit'; 1824import {photoAccessHelper} from '@kit.MediaLibraryKit'; 1825const context = getContext(this); 1826let phAccessHelper = photoAccessHelper.getPhotoAccessHelper(context); 1827 1828async function example() { 1829 console.info('removeGalleryFormInfoDemo'); 1830 let info: photoAccessHelper.GalleryFormInfo = { 1831 // formId is a string consisting of only digits. When removing a widget, leave assertUris empty. 1832 formId: "20230116123" 1833 } 1834 1835 phAccessHelper.removeGalleryFormInfo(info).then(() => { 1836 console.info('removeGalleryFormInfo successfully'); 1837 }).catch((err: BusinessError) => { 1838 console.error(`removeGalleryFormInfo failed with error: ${err.code}, ${err.message}`); 1839 }); 1840} 1841``` 1842## PhotoAsset 1843 1844Provides APIs for encapsulating file asset attributes. 1845 1846### open<sup>(deprecated)</sup> 1847 1848open(mode: string, callback: AsyncCallback<number>): void 1849 1850Opens this file asset. This API uses an asynchronous callback to return the result. 1851 1852> **NOTE** 1853> 1854> This API is supported since API version 10 and deprecated since API version 11. For security purposes, the API for obtaining the media file handle is no longer provided. 1855 1856> **NOTE**<br>A file can be opened in only one mode at a time. Use **close()** to close the FD returned when it is not required. 1857 1858**System API**: This is a system API. 1859 1860**Required permissions**: ohos.permission.READ_IMAGEVIDEO or ohos.permission.WRITE_IMAGEVIDEO 1861 1862**System capability**: SystemCapability.FileManagement.PhotoAccessHelper.Core 1863 1864**Parameters** 1865 1866| Name | Type | Mandatory | Description | 1867| -------- | --------------------------- | ---- | ----------------------------------- | 1868| mode | string | Yes | Mode for opening the file, which can be **'r'** (read-only), **'w'** (write-only), or **'rw'** (read/write).| 1869| callback | AsyncCallback<number> | Yes | Callback used to return the file descriptor (FD) of the file opened. | 1870 1871**Error codes** 1872 1873For details about the error codes, see [Universal Error Codes](../errorcode-universal.md) and [File Management Error Codes](../apis-core-file-kit/errorcode-filemanagement.md). 1874 1875| ID| Error Message| 1876| -------- | ---------------------------------------- | 1877| 202 | Called by non-system application. | 1878| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types; 3. Parameter verification failed. | 1879| 13900012 | Permission denied. | 1880| 13900020 | Invalid argument. | 1881| 14000011 | System inner fail. | 1882 1883**Example** 1884 1885```ts 1886async function example() { 1887 console.info('Open demo'); 1888 let testFileName: string = 'testFile' + Date.now() + '.jpg'; 1889 let photoAsset: photoAccessHelper.PhotoAsset = await phAccessHelper.createAsset(testFileName); 1890 photoAsset.open('rw', (err, fd) => { 1891 if (fd !== undefined) { 1892 console.info('File fd' + fd); 1893 photoAsset.close(fd); 1894 } else { 1895 console.error(`Open file err: ${err.code}, ${err.message}`); 1896 } 1897 }); 1898} 1899``` 1900 1901### open<sup>(deprecated)</sup> 1902 1903open(mode: string): Promise<number> 1904 1905Opens this file asset. This API uses a promise to return the result. 1906 1907> **NOTE** 1908> 1909> This API is supported since API version 10 and deprecated since API version 11. For security purposes, the API for obtaining the media file handle is no longer provided. 1910 1911> **NOTE**<br>A file can be opened in only one mode at a time. Use **close()** to close the FD returned when it is not required. 1912 1913**System API**: This is a system API. 1914 1915**Required permissions**: ohos.permission.READ_IMAGEVIDEO or ohos.permission.WRITE_IMAGEVIDEO 1916 1917**System capability**: SystemCapability.FileManagement.PhotoAccessHelper.Core 1918 1919**Parameters** 1920 1921| Name | Type | Mandatory | Description | 1922| ---- | ------ | ---- | ----------------------------------- | 1923| mode | string | Yes | Mode for opening the file, which can be **'r'** (read-only), **'w'** (write-only), or **'rw'** (read/write).| 1924 1925**Return value** 1926 1927| Type | Description | 1928| --------------------- | ------------- | 1929| Promise<number> | Promise used to return the FD of the file opened.| 1930 1931**Error codes** 1932 1933For details about the error codes, see [Universal Error Codes](../errorcode-universal.md) and [File Management Error Codes](../apis-core-file-kit/errorcode-filemanagement.md). 1934 1935| ID| Error Message| 1936| -------- | ---------------------------------------- | 1937| 202 | Called by non-system application. | 1938| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types; 3. Parameter verification failed. | 1939| 13900012 | Permission denied. | 1940| 13900020 | Invalid argument. | 1941| 14000011 | System inner fail. | 1942 1943**Example** 1944 1945```ts 1946async function example() { 1947 console.info('Open demo'); 1948 try { 1949 let testFileName: string = 'testFile' + Date.now() + '.jpg'; 1950 let photoAsset: photoAccessHelper.PhotoAsset = await phAccessHelper.createAsset(testFileName); 1951 let fd: number = await photoAsset.open('rw'); 1952 if (fd !== undefined) { 1953 console.info('File fd' + fd); 1954 photoAsset.close(fd); 1955 } else { 1956 console.error('Open file fail'); 1957 } 1958 } catch (err) { 1959 console.error(`Open demo err: ${err.code}, ${err.message}`); 1960 } 1961} 1962``` 1963 1964### setFavorite<sup>(deprecated)</sup> 1965 1966setFavorite(favoriteState: boolean, callback: AsyncCallback<void>): void 1967 1968Favorites or unfavorites this file. This API uses an asynchronous callback to return the result. 1969 1970> **NOTE** 1971> 1972> This API is supported since API version 10 and deprecated since API version 11. Use [MediaAssetChangeRequest.setFavorite](#setfavorite11) instead. 1973 1974**System API**: This is a system API. 1975 1976**Required permissions**: ohos.permission.WRITE_IMAGEVIDEO 1977 1978**System capability**: SystemCapability.FileManagement.PhotoAccessHelper.Core 1979 1980**Parameters** 1981 1982| Name | Type | Mandatory | Description | 1983| ---------- | ------------------------- | ---- | ---------------------------------- | 1984| favoriteState | boolean | Yes | Operation to perform. The value **true** means to favorite the file asset, and **false** means the opposite.| 1985| callback | AsyncCallback<void> | Yes | Callback that returns no value. | 1986 1987**Error codes** 1988 1989For details about the error codes, see [Universal Error Codes](../errorcode-universal.md) and [File Management Error Codes](../apis-core-file-kit/errorcode-filemanagement.md). 1990 1991| ID| Error Message| 1992| -------- | ---------------------------------------- | 1993| 202 | Called by non-system application. | 1994| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types; 3. Parameter verification failed. | 1995| 13900012 | Permission denied. | 1996| 13900020 | Invalid argument. | 1997| 14000011 | System inner fail. | 1998 1999**Example** 2000 2001```ts 2002import { dataSharePredicates } from '@kit.ArkData'; 2003 2004async function example() { 2005 console.info('setFavoriteDemo'); 2006 let predicates: dataSharePredicates.DataSharePredicates = new dataSharePredicates.DataSharePredicates(); 2007 let fetchOption: photoAccessHelper.FetchOptions = { 2008 fetchColumns: [], 2009 predicates: predicates 2010 }; 2011 let fetchResult: photoAccessHelper.FetchResult<photoAccessHelper.PhotoAsset> = await phAccessHelper.getAssets(fetchOption); 2012 let asset = await fetchResult.getFirstObject(); 2013 asset.setFavorite(true, (err) => { 2014 if (err === undefined) { 2015 console.info('favorite successfully'); 2016 } else { 2017 console.error(`favorite failed with error: ${err.code}, ${err.message}`); 2018 } 2019 }); 2020} 2021``` 2022 2023### setFavorite<sup>(deprecated)</sup> 2024 2025setFavorite(favoriteState: boolean): Promise<void> 2026 2027Favorites or unfavorites this file asset. This API uses a promise to return the result. 2028 2029> **NOTE** 2030> 2031> This API is supported since API version 10 and deprecated since API version 11. Use [MediaAssetChangeRequest.setFavorite](#setfavorite11) instead. 2032 2033**System API**: This is a system API. 2034 2035**Required permissions**: ohos.permission.WRITE_IMAGEVIDEO 2036 2037**System capability**: SystemCapability.FileManagement.PhotoAccessHelper.Core 2038 2039**Parameters** 2040 2041| Name | Type | Mandatory | Description | 2042| ---------- | ------- | ---- | ---------------------------------- | 2043| favoriteState | boolean | Yes | Operation to perform. The value **true** means to favorite the file asset, and **false** means the opposite.| 2044 2045**Return value** 2046 2047| Type | Description | 2048| ------------------- | ---------- | 2049| Promise<void> | Promise that returns no value.| 2050 2051**Error codes** 2052 2053For details about the error codes, see [Universal Error Codes](../errorcode-universal.md) and [File Management Error Codes](../apis-core-file-kit/errorcode-filemanagement.md). 2054 2055| ID| Error Message| 2056| -------- | ---------------------------------------- | 2057| 202 | Called by non-system application. | 2058| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types; 3. Parameter verification failed. | 2059| 13900012 | Permission denied. | 2060| 13900020 | Invalid argument. | 2061| 14000011 | System inner fail. | 2062 2063**Example** 2064 2065```ts 2066import { dataSharePredicates } from '@kit.ArkData'; 2067import { BusinessError } from '@kit.BasicServicesKit'; 2068 2069async function example() { 2070 console.info('setFavoriteDemo'); 2071 let predicates: dataSharePredicates.DataSharePredicates = new dataSharePredicates.DataSharePredicates(); 2072 let fetchOption: photoAccessHelper.FetchOptions = { 2073 fetchColumns: [], 2074 predicates: predicates 2075 }; 2076 let fetchResult: photoAccessHelper.FetchResult<photoAccessHelper.PhotoAsset> = await phAccessHelper.getAssets(fetchOption); 2077 let asset = await fetchResult.getFirstObject(); 2078 asset.setFavorite(true).then(() => { 2079 console.info('setFavorite successfully'); 2080 }).catch((err: BusinessError) => { 2081 console.error(`setFavorite failed with error: ${err.code}, ${err.message}`); 2082 }); 2083} 2084``` 2085 2086### setHidden<sup>(deprecated)</sup> 2087 2088setHidden(hiddenState: boolean, callback: AsyncCallback<void>): void 2089 2090Sets this file to hidden state. This API uses an asynchronous callback to return the result. 2091 2092Private files are stored in the private album. After obtaining private files from the private album, users can set **hiddenState** to **false** to remove them from the private album. 2093 2094> **NOTE** 2095> 2096> This API is supported since API version 10 and deprecated since API version 11. Use [MediaAssetChangeRequest.setHidden](#sethidden11) instead. 2097 2098**System API**: This is a system API. 2099 2100**Required permissions**: ohos.permission.WRITE_IMAGEVIDEO 2101 2102**System capability**: SystemCapability.FileManagement.PhotoAccessHelper.Core 2103 2104**Parameters** 2105 2106| Name | Type | Mandatory | Description | 2107| ---------- | ------------------------- | ---- | ---------------------------------- | 2108| hiddenState | boolean | Yes | Whether to set a file to hidden state. The value **true** means to hide the file; the value **false** means the opposite.| 2109| callback | AsyncCallback<void> | Yes | Callback that returns no value. | 2110 2111**Error codes** 2112 2113For details about the error codes, see [Universal Error Codes](../errorcode-universal.md) and [File Management Error Codes](../apis-core-file-kit/errorcode-filemanagement.md). 2114 2115| ID| Error Message| 2116| -------- | ---------------------------------------- | 2117| 202 | Called by non-system application. | 2118| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types; 3. Parameter verification failed. | 2119| 13900012 | Permission denied. | 2120| 13900020 | Invalid argument. | 2121| 14000011 | System inner fail. | 2122 2123**Example** 2124 2125```ts 2126import { dataSharePredicates } from '@kit.ArkData'; 2127 2128async function example() { 2129 console.info('setHiddenDemo'); 2130 let predicates: dataSharePredicates.DataSharePredicates = new dataSharePredicates.DataSharePredicates(); 2131 let fetchOption: photoAccessHelper.FetchOptions = { 2132 fetchColumns: [], 2133 predicates: predicates 2134 }; 2135 let fetchResult: photoAccessHelper.FetchResult<photoAccessHelper.PhotoAsset> = await phAccessHelper.getAssets(fetchOption); 2136 let asset = await fetchResult.getFirstObject(); 2137 asset.setHidden(true, (err) => { 2138 if (err === undefined) { 2139 console.info('setHidden successfully'); 2140 } else { 2141 console.error(`setHidden failed with error: ${err.code}, ${err.message}`); 2142 } 2143 }); 2144} 2145``` 2146 2147### setHidden<sup>(deprecated)</sup> 2148 2149setHidden(hiddenState: boolean): Promise<void> 2150 2151Sets this file asset to hidden state. This API uses a promise to return the result. 2152 2153Private files are stored in the private album. After obtaining private files from the private album, users can set **hiddenState** to **false** to remove them from the private album. 2154 2155> **NOTE** 2156> 2157> This API is supported since API version 10 and deprecated since API version 11. Use [MediaAssetChangeRequest.setHidden](#sethidden11) instead. 2158 2159**System API**: This is a system API. 2160 2161**Required permissions**: ohos.permission.WRITE_IMAGEVIDEO 2162 2163**System capability**: SystemCapability.FileManagement.PhotoAccessHelper.Core 2164 2165**Parameters** 2166 2167| Name | Type | Mandatory | Description | 2168| ---------- | ------- | ---- | ---------------------------------- | 2169| hiddenState | boolean | Yes | Whether to set a file to hidden state. The value **true** means to hide the file; the value **false** means the opposite.| 2170 2171**Return value** 2172 2173| Type | Description | 2174| ------------------- | ---------- | 2175| Promise<void> | Promise that returns no value.| 2176 2177**Error codes** 2178 2179For details about the error codes, see [Universal Error Codes](../errorcode-universal.md) and [File Management Error Codes](../apis-core-file-kit/errorcode-filemanagement.md). 2180 2181| ID| Error Message| 2182| -------- | ---------------------------------------- | 2183| 202 | Called by non-system application. | 2184| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types; 3. Parameter verification failed. | 2185| 13900012 | Permission denied. | 2186| 13900020 | Invalid argument. | 2187| 14000011 | System inner fail. | 2188 2189**Example** 2190 2191```ts 2192import { dataSharePredicates } from '@kit.ArkData'; 2193import { BusinessError } from '@kit.BasicServicesKit'; 2194 2195async function example() { 2196 // Restore a file from a hidden album. Before the operation, ensure that the file exists in the hidden album. 2197 console.info('setHiddenDemo'); 2198 let predicates: dataSharePredicates.DataSharePredicates = new dataSharePredicates.DataSharePredicates(); 2199 let fetchOption: photoAccessHelper.FetchOptions = { 2200 fetchColumns: [], 2201 predicates: predicates 2202 }; 2203 let albumList: photoAccessHelper.FetchResult<photoAccessHelper.Album> = await phAccessHelper.getAlbums(photoAccessHelper.AlbumType.SYSTEM, photoAccessHelper.AlbumSubtype.HIDDEN); 2204 let album = await albumList.getFirstObject(); 2205 let fetchResult: photoAccessHelper.FetchResult<photoAccessHelper.PhotoAsset> = await album.getAssets(fetchOption); 2206 let asset = await fetchResult.getFirstObject(); 2207 asset.setHidden(false).then(() => { 2208 console.info('setHidden successfully'); 2209 }).catch((err: BusinessError) => { 2210 console.error(`setHidden failed with error: ${err.code}, ${err.message}`); 2211 }); 2212} 2213``` 2214 2215### getExif 2216 2217getExif(): Promise<string> 2218 2219Obtains the exchangeable image file format (EXIF) data from a JPG image. This API uses a promise to return the result. 2220 2221The EXIF information obtained are provided by the [image](../apis-image-kit/js-apis-image.md) module. For details about the EXIF information, see [image.PropertyKey](../apis-image-kit/js-apis-image.md#propertykey7). 2222 2223> **NOTE**<br>This API returns a JSON string consisting of EXIF tags. The complete EXIF information consists of **all_exif** and [PhotoKeys.USER_COMMENT](#photokeys). These two fields must be passed in via **fetchColumns**. 2224 2225**System API**: This is a system API. 2226 2227**Required permissions**: ohos.permission.READ_IMAGEVIDEO 2228 2229**System capability**: SystemCapability.FileManagement.PhotoAccessHelper.Core 2230 2231**Return value** 2232 2233| Type | Description | 2234| --------------------------------------- | ----------------- | 2235| Promise<string> | Promise used to return the EXIF data, in JSON strings.| 2236 2237**Error codes** 2238 2239For details about the error codes, see [Universal Error Codes](../errorcode-universal.md) and [File Management Error Codes](../apis-core-file-kit/errorcode-filemanagement.md). 2240 2241| ID| Error Message| 2242| -------- | ---------------------------------------- | 2243| 202 | Called by non-system application. | 2244| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types. | 2245| 13900012 | Permission denied. | 2246| 13900020 | Invalid argument. | 2247| 14000011 | System inner fail. | 2248 2249**Example** 2250 2251```ts 2252import { dataSharePredicates } from '@kit.ArkData'; 2253 2254async function example() { 2255 try { 2256 console.info('getExifDemo'); 2257 let predicates: dataSharePredicates.DataSharePredicates = new dataSharePredicates.DataSharePredicates(); 2258 let fetchOptions: photoAccessHelper.FetchOptions = { 2259 fetchColumns: [ 'all_exif', photoAccessHelper.PhotoKeys.USER_COMMENT], 2260 predicates: predicates 2261 }; 2262 let fetchResult: photoAccessHelper.FetchResult<photoAccessHelper.PhotoAsset> = await phAccessHelper.getAssets(fetchOptions); 2263 let photoAsset: photoAccessHelper.PhotoAsset = await fetchResult.getFirstObject(); 2264 let exifMessage = await photoAsset.getExif(); 2265 let userCommentKey = 'UserComment'; 2266 let userComment = JSON.stringify(JSON.parse(exifMessage), [userCommentKey]); 2267 console.info('getExifDemo userComment: ' + JSON.stringify(userComment)); 2268 fetchResult.close(); 2269 } catch (err) { 2270 console.error(`getExifDemoCallback failed with error: ${err.code}, ${err.message}`); 2271 } 2272} 2273``` 2274 2275### getExif 2276 2277getExif(callback: AsyncCallback<string>): void 2278 2279Obtains the exchangeable image file format (EXIF) data from a JPG image. This API uses an asynchronous callback to return the result. 2280 2281The EXIF data obtained are provided by the [image](../apis-image-kit/js-apis-image.md) module. For details about the EXIF information, see [image.PropertyKey](../apis-image-kit/js-apis-image.md#propertykey7). 2282 2283> **NOTE**<br>This API returns a JSON string consisting of EXIF tags. The complete EXIF information consists of **all_exif** and [PhotoKeys.USER_COMMENT](#photokeys). These two fields must be passed in via **fetchColumns**. 2284 2285**System API**: This is a system API. 2286 2287**Required permissions**: ohos.permission.READ_IMAGEVIDEO 2288 2289**System capability**: SystemCapability.FileManagement.PhotoAccessHelper.Core 2290 2291**Parameters** 2292 2293| Name | Type | Mandatory| Description | 2294| -------- | ------------------------- | ---- | ---------- | 2295| callback | AsyncCallback<string> | Yes | Callback used to return the EXIF data, in JSON strings.| 2296 2297**Error codes** 2298 2299For details about the error codes, see [Universal Error Codes](../errorcode-universal.md) and [File Management Error Codes](../apis-core-file-kit/errorcode-filemanagement.md). 2300 2301| ID| Error Message| 2302| -------- | ---------------------------------------- | 2303| 202 | Called by non-system application. | 2304| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types. | 2305| 13900012 | Permission denied. | 2306| 13900020 | Invalid argument. | 2307| 14000011 | System inner fail. | 2308 2309**Example** 2310 2311```ts 2312import { dataSharePredicates } from '@kit.ArkData'; 2313 2314async function example() { 2315 try { 2316 console.info('getExifDemo'); 2317 let predicates: dataSharePredicates.DataSharePredicates = new dataSharePredicates.DataSharePredicates(); 2318 predicates.isNotNull('all_exif') 2319 let fetchOptions: photoAccessHelper.FetchOptions = { 2320 fetchColumns: ['all_exif', photoAccessHelper.PhotoKeys.USER_COMMENT], 2321 predicates: predicates 2322 }; 2323 let fetchResult: photoAccessHelper.FetchResult<photoAccessHelper.PhotoAsset> = await phAccessHelper.getAssets(fetchOptions); 2324 let photoAsset: photoAccessHelper.PhotoAsset = await fetchResult.getFirstObject(); 2325 console.info('getExifDemo photoAsset displayName: ' + JSON.stringify(photoAsset.displayName)); 2326 let userCommentKey = 'UserComment'; 2327 photoAsset.getExif((err, exifMessage) => { 2328 if (exifMessage !== undefined) { 2329 let userComment = JSON.stringify(JSON.parse(exifMessage), [userCommentKey]); 2330 console.info('getExifDemo userComment: ' + JSON.stringify(userComment)); 2331 } else { 2332 console.error(`getExif failed, error: ${err.code}, ${err.message}`); 2333 } 2334 }); 2335 fetchResult.close(); 2336 } catch (err) { 2337 console.error(`getExifDemoCallback failed with error: ${err.code}, ${err.message}`); 2338 } 2339} 2340``` 2341 2342### setUserComment<sup>(deprecated)</sup> 2343 2344setUserComment(userComment: string): Promise<void> 2345 2346Sets user comment information of an image or video. This API uses a promise to return the result. 2347 2348> **NOTE** 2349> 2350> This API is supported since API version 10 and deprecated since API version 11. Use [MediaAssetChangeRequest.setUserComment](#setusercomment11) instead. 2351 2352**NOTE**<br>This API can be used to modify the comment information of only images or videos. 2353 2354**System API**: This is a system API. 2355 2356**Required permissions**: ohos.permission.WRITE_IMAGEVIDEO 2357 2358**System capability**: SystemCapability.FileManagement.PhotoAccessHelper.Core 2359 2360**Parameters** 2361 2362| Name | Type | Mandatory| Description | 2363| -------- | ------------------------- | ---- | ---------- | 2364| userComment | string | Yes | User comment information to set, which cannot exceed 420 characters.| 2365 2366**Return value** 2367 2368| Type | Description | 2369| --------------------------------------- | ----------------- | 2370|Promise<void> | Promise that returns no value.| 2371 2372**Error codes** 2373 2374For details about the error codes, see [Universal Error Codes](../errorcode-universal.md) and [File Management Error Codes](../apis-core-file-kit/errorcode-filemanagement.md). 2375 2376| ID| Error Message| 2377| -------- | ---------------------------------------- | 2378| 202 | Called by non-system application. | 2379| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types; 3. Parameter verification failed. | 2380| 13900012 | Permission denied. | 2381| 13900020 | Invalid argument. | 2382| 14000011 | System inner fail. | 2383 2384**Example** 2385 2386```ts 2387import { dataSharePredicates } from '@kit.ArkData'; 2388 2389async function example() { 2390 try { 2391 console.info('setUserCommentDemo') 2392 let predicates: dataSharePredicates.DataSharePredicates = new dataSharePredicates.DataSharePredicates(); 2393 let fetchOptions: photoAccessHelper.FetchOptions = { 2394 fetchColumns: [], 2395 predicates: predicates 2396 }; 2397 let fetchResult: photoAccessHelper.FetchResult<photoAccessHelper.PhotoAsset> = await phAccessHelper.getAssets(fetchOptions); 2398 let photoAsset: photoAccessHelper.PhotoAsset = await fetchResult.getFirstObject(); 2399 let userComment = 'test_set_user_comment'; 2400 await photoAsset.setUserComment(userComment); 2401 } catch (err) { 2402 console.error(`setUserCommentDemoPromise failed with error: ${err.code}, ${err.message}`); 2403 } 2404} 2405``` 2406 2407### setUserComment<sup>(deprecated)</sup> 2408 2409setUserComment(userComment: string, callback: AsyncCallback<void>): void 2410 2411Sets user comment information of an image or video. This API uses an asynchronous callback to return the result. 2412 2413> **NOTE** 2414> 2415> This API is supported since API version 10 and deprecated since API version 11. Use [MediaAssetChangeRequest.setUserComment](#setusercomment11) instead. 2416 2417**NOTE**<br>This API can be used to modify the comment information of only images or videos. 2418 2419**System API**: This is a system API. 2420 2421**Required permissions**: ohos.permission.WRITE_IMAGEVIDEO 2422 2423**System capability**: SystemCapability.FileManagement.PhotoAccessHelper.Core 2424 2425**Parameters** 2426 2427| Name | Type | Mandatory| Description | 2428| -------- | ------------------------- | ---- | ---------- | 2429| userComment | string | Yes | User comment information to set, which cannot exceed 420 characters.| 2430| callback | AsyncCallback<void> | Yes | Callback that returns no value.| 2431 2432**Error codes** 2433 2434For details about the error codes, see [Universal Error Codes](../errorcode-universal.md) and [File Management Error Codes](../apis-core-file-kit/errorcode-filemanagement.md). 2435 2436| ID| Error Message| 2437| -------- | ---------------------------------------- | 2438| 202 | Called by non-system application. | 2439| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types; 3. Parameter verification failed. | 2440| 13900012 | Permission denied. | 2441| 13900020 | Invalid argument. | 2442| 14000011 | System inner fail. | 2443 2444**Example** 2445 2446```ts 2447import { dataSharePredicates } from '@kit.ArkData'; 2448 2449async function example() { 2450 try { 2451 console.info('setUserCommentDemo') 2452 let predicates: dataSharePredicates.DataSharePredicates = new dataSharePredicates.DataSharePredicates(); 2453 let fetchOptions: photoAccessHelper.FetchOptions = { 2454 fetchColumns: [], 2455 predicates: predicates 2456 }; 2457 let fetchResult: photoAccessHelper.FetchResult<photoAccessHelper.PhotoAsset> = await phAccessHelper.getAssets(fetchOptions); 2458 let photoAsset: photoAccessHelper.PhotoAsset = await fetchResult.getFirstObject(); 2459 let userComment = 'test_set_user_comment'; 2460 photoAsset.setUserComment(userComment, (err) => { 2461 if (err === undefined) { 2462 console.info('setUserComment successfully'); 2463 } else { 2464 console.error(`setUserComment failed with error: ${err.code}, ${err.message}`); 2465 } 2466 }); 2467 } catch (err) { 2468 console.error(`setUserCommentDemoCallback failed with error: ${err.code}, ${err.message}`); 2469 } 2470} 2471``` 2472 2473### setPending<sup>11+</sup> 2474 2475setPending(pendingState: boolean, callback: AsyncCallback<void>): void 2476 2477Sets the pending state for this image or video asset. This API uses an asynchronous callback to return the result. 2478 2479The pending state can be removed only through **setPending(false)**. You can use **photoAsset.get(photoAccessHelper.PhotoKeys.PENDING)** to check whether the asset state is pending. If the asset is in pending state, **true** is returned. Otherwise, **false** is returned. 2480 2481**NOTE**<br>**setPending** can be used only during the file creation process. Once the FD is closed, **setPending(true)** cannot be used to set the pending state for the file. 2482 2483**System API**: This is a system API. 2484 2485**Required permissions**: ohos.permission.WRITE_IMAGEVIDEO 2486 2487**System capability**: SystemCapability.FileManagement.PhotoAccessHelper.Core 2488 2489**Parameters** 2490 2491| Name | Type | Mandatory | Description | 2492| ---------- | ------- | ---- | ---------------------------------- | 2493| pendingState | boolean | Yes | Whether to set the file to pending state. The value **true** means to set the file to pending state, and the value **false** means to remove the pending state.| 2494| callback | AsyncCallback<void> | Yes | Callback that returns no value.| 2495 2496**Error codes** 2497 2498For details about the error codes, see [Universal Error Codes](../errorcode-universal.md) and [File Management Error Codes](../apis-core-file-kit/errorcode-filemanagement.md). 2499 2500| ID| Error Message| 2501| -------- | ---------------------------------------- | 2502| 201 | Permission denied. | 2503| 202 | Called by non-system application. | 2504| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types; 3. Parameter verification failed. | 2505| 14000011 | System inner fail. | 2506 2507**Example** 2508 2509```ts 2510async function example() { 2511 try { 2512 console.info('setPendingCallbackDemo'); 2513 let testFileName: string = 'testFile' + Date.now() + '.jpg'; 2514 let photoAsset = await phAccessHelper.createAsset(testFileName); 2515 let fd = await photoAsset.open('rw'); 2516 photoAsset.setPending(true, async (err) => { 2517 if (err !== undefined) { 2518 console.error(`setPending(true) failed with error: ${err.code}, ${err.message}`); 2519 return; 2520 } 2521 // write photo buffer in fd. 2522 photoAsset.setPending(false, async (err) => { 2523 if (err !== undefined) { 2524 console.error(`setPending(false) failed with error: ${err.code}, ${err.message}`); 2525 return; 2526 } 2527 await photoAsset.close(fd); 2528 }); 2529 }); 2530 } catch (err) { 2531 console.error(`setPendingCallbackDemo failed with error: ${err.code}, ${err.message}`); 2532 } 2533} 2534``` 2535 2536### setPending<sup>11+</sup> 2537 2538setPending(pendingState: boolean): Promise<void> 2539 2540Sets the pending state for this image or video asset. This API uses a promise to return the result. 2541 2542The pending state can be removed only through **setPending(false)**. You can use **photoAsset.get(photoAccessHelper.PhotoKeys.PENDING)** to check whether the asset state is pending. If the asset is in pending state, **true** is returned. Otherwise, **false** is returned. 2543 2544**NOTE**<br>**setPending** can be used only during the file creation process. Once the FD is closed, **setPending(true)** cannot be used to set the pending state for the file. 2545 2546**System API**: This is a system API. 2547 2548**Required permissions**: ohos.permission.WRITE_IMAGEVIDEO 2549 2550**System capability**: SystemCapability.FileManagement.PhotoAccessHelper.Core 2551 2552**Parameters** 2553 2554| Name | Type | Mandatory | Description | 2555| ---------- | ------- | ---- | ---------------------------------- | 2556| pendingState | boolean | Yes | Whether to set the file to pending state. The value **true** means to set the file to pending state, and the value **false** means to remove the pending state.| 2557 2558**Return value** 2559 2560| Type | Description | 2561| --------------------------------------- | ----------------- | 2562|Promise<boolean> | Promise that returns no value.| 2563 2564**Error codes** 2565 2566For details about the error codes, see [Universal Error Codes](../errorcode-universal.md) and [File Management Error Codes](../apis-core-file-kit/errorcode-filemanagement.md). 2567 2568| ID| Error Message| 2569| -------- | ---------------------------------------- | 2570| 201 | Permission denied. | 2571| 202 | Called by non-system application. | 2572| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types; 3. Parameter verification failed. | 2573| 14000011 | System inner fail. | 2574 2575**Example** 2576 2577```ts 2578async function example() { 2579 try { 2580 console.info('setPendingPromiseDemo'); 2581 let testFileName: string = 'testFile' + Date.now() + '.jpg'; 2582 let photoAsset = await phAccessHelper.createAsset(testFileName); 2583 let fd = await photoAsset.open('rw'); 2584 await photoAsset.setPending(true); 2585 // write photo buffer in fd. 2586 photoAsset.setPending(false); 2587 await photoAsset.close(fd); 2588 } catch (err) { 2589 console.error(`setPendingPromiseDemo failed with error: ${err.code}, ${err.message}`); 2590 } 2591} 2592``` 2593 2594### isEdited<sup>11+</sup> 2595 2596isEdited(callback: AsyncCallback<boolean>): void 2597 2598Checks whether this image or video asset is edited. This API uses an asynchronous callback to return the result. 2599 2600**System API**: This is a system API. 2601 2602**Required permissions**: ohos.permission.READ_IMAGEVIDEO 2603 2604**System capability**: SystemCapability.FileManagement.PhotoAccessHelper.Core 2605 2606**Parameters** 2607 2608| Name | Type | Mandatory | Description | 2609| ---------- | ------- | ---- | ---------------------------------- | 2610| callback | AsyncCallback<boolean> | Yes | Callback used to return the result. The value **true** means that the image or video asset is edited, and **false** means the opposite. The default value is **false**.| 2611 2612**Error codes** 2613 2614For details about the error codes, see [Universal Error Codes](../errorcode-universal.md) and [File Management Error Codes](../apis-core-file-kit/errorcode-filemanagement.md). 2615 2616| ID| Error Message| 2617| -------- | ---------------------------------------- | 2618| 201 | Permission denied. | 2619| 202 | Called by non-system application. | 2620| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types. | 2621| 14000011 | System inner fail. | 2622 2623**Example** 2624 2625```ts 2626import { dataSharePredicates } from '@kit.ArkData'; 2627 2628async function example() { 2629 try { 2630 console.info('isEditedCallbackDemo') 2631 let predicates: dataSharePredicates.DataSharePredicates = new dataSharePredicates.DataSharePredicates(); 2632 let fetchOptions: photoAccessHelper.FetchOptions = { 2633 fetchColumns: [], 2634 predicates: predicates 2635 }; 2636 let fetchResult: photoAccessHelper.FetchResult<photoAccessHelper.PhotoAsset> = await phAccessHelper.getAssets(fetchOptions); 2637 let photoAsset: photoAccessHelper.PhotoAsset = await fetchResult.getFirstObject(); 2638 photoAsset.isEdited((err, isEdited) => { 2639 if (err === undefined) { 2640 if (isEdited === true) { 2641 console.info('Photo is edited'); 2642 } else { 2643 console.info('Photo is not edited'); 2644 } 2645 } else { 2646 console.error(`isEdited failed with error: ${err.code}, ${err.message}`); 2647 } 2648 }); 2649 } catch (err) { 2650 console.error(`isEditedDemoCallback failed with error: ${err.code}, ${err.message}`); 2651 } 2652} 2653``` 2654 2655### isEdited<sup>11+</sup> 2656 2657isEdited(): Promise<boolean> 2658 2659Checks whether this image or video asset is edited. This API uses a promise to return the result. 2660 2661**System API**: This is a system API. 2662 2663**Required permissions**: ohos.permission.READ_IMAGEVIDEO 2664 2665**System capability**: SystemCapability.FileManagement.PhotoAccessHelper.Core 2666 2667**Return value** 2668 2669| Type | Description | 2670| --------------------------------------- | ----------------- | 2671|Promise<boolean> | Promise used to return the result. The value **true** means that the image or video asset is edited, and **false** means the opposite. The default value is **false**.| 2672 2673 2674**Error codes** 2675 2676For details about the error codes, see [Universal Error Codes](../errorcode-universal.md) and [File Management Error Codes](../apis-core-file-kit/errorcode-filemanagement.md). 2677 2678| ID| Error Message| 2679| -------- | ---------------------------------------- | 2680| 201 | Permission denied. | 2681| 202 | Called by non-system application. | 2682| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types. | 2683| 14000011 | System inner fail. | 2684 2685**Example** 2686 2687```ts 2688import { dataSharePredicates } from '@kit.ArkData'; 2689 2690async function example() { 2691 try { 2692 console.info('isEditedPromiseDemo') 2693 let predicates: dataSharePredicates.DataSharePredicates = new dataSharePredicates.DataSharePredicates(); 2694 let fetchOptions: photoAccessHelper.FetchOptions = { 2695 fetchColumns: [], 2696 predicates: predicates 2697 }; 2698 let fetchResult: photoAccessHelper.FetchResult<photoAccessHelper.PhotoAsset> = await phAccessHelper.getAssets(fetchOptions); 2699 let photoAsset: photoAccessHelper.PhotoAsset = await fetchResult.getFirstObject(); 2700 let isEdited = await photoAsset.isEdited(); 2701 if (isEdited === true) { 2702 console.info('Photo is edited'); 2703 } else { 2704 console.info('Photo is not edited'); 2705 } 2706 } catch (err) { 2707 console.error(`isEditedDemoCallback failed with error: ${err.code}, ${err.message}`); 2708 } 2709} 2710``` 2711 2712### requestEditData<sup>11+</sup> 2713 2714requestEditData(callback: AsyncCallback<string>): void 2715 2716Obtains the edit data of this image or video asset. This API uses an asynchronous callback to return the result. 2717 2718If the asset has never been edited, an empty string is returned. 2719 2720**System API**: This is a system API. 2721 2722**Required permissions**: ohos.permission.READ_IMAGEVIDEO 2723 2724**System capability**: SystemCapability.FileManagement.PhotoAccessHelper.Core 2725 2726**Parameters** 2727 2728| Name | Type | Mandatory | Description | 2729| ---------- | ------- | ---- | ---------------------------------- | 2730| callback | AsyncCallback<string> | Yes | Callback used to return the edit data obtained.| 2731 2732**Error codes** 2733 2734For details about the error codes, see [Universal Error Codes](../errorcode-universal.md) and [File Management Error Codes](../apis-core-file-kit/errorcode-filemanagement.md). 2735 2736| ID| Error Message| 2737| -------- | ---------------------------------------- | 2738| 201 | Permission denied. | 2739| 202 | Called by non-system application. | 2740| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types. | 2741| 14000011 | System inner fail. | 2742 2743**Example** 2744 2745```ts 2746import { dataSharePredicates } from '@kit.ArkData'; 2747 2748async function example() { 2749 try { 2750 console.info('requestEditDataCallbackDemo') 2751 let predicates: dataSharePredicates.DataSharePredicates = new dataSharePredicates.DataSharePredicates(); 2752 let fetchOptions: photoAccessHelper.FetchOptions = { 2753 fetchColumns: [], 2754 predicates: predicates 2755 }; 2756 let fetchResult: photoAccessHelper.FetchResult<photoAccessHelper.PhotoAsset> = await phAccessHelper.getAssets(fetchOptions); 2757 let photoAsset: photoAccessHelper.PhotoAsset = await fetchResult.getFirstObject(); 2758 photoAsset.requestEditData((err, editdata) => { 2759 if (err === undefined) { 2760 console.info('Editdata is ' + editdata); 2761 } else { 2762 console.error(`requestEditData failed with error: ${err.code}, ${err.message}`); 2763 } 2764 }); 2765 } catch (err) { 2766 console.error(`requestEditDataCallbackDemo failed with error: ${err.code}, ${err.message}`); 2767 } 2768} 2769``` 2770 2771### requestEditData<sup>11+</sup> 2772 2773requestEditData(): Promise<string> 2774 2775Obtains the edit data of this image or video asset. This API uses a promise to return the result. 2776 2777If the asset has never been edited, an empty string is returned. 2778 2779**System API**: This is a system API. 2780 2781**Required permissions**: ohos.permission.READ_IMAGEVIDEO 2782 2783**System capability**: SystemCapability.FileManagement.PhotoAccessHelper.Core 2784 2785**Return value** 2786 2787| Type | Description | 2788| --------------------------------------- | ----------------- | 2789|Promise<string> | Promise used to return the edit data obtained.| 2790 2791 2792**Error codes** 2793 2794For details about the error codes, see [Universal Error Codes](../errorcode-universal.md) and [File Management Error Codes](../apis-core-file-kit/errorcode-filemanagement.md). 2795 2796| ID| Error Message| 2797| -------- | ---------------------------------------- | 2798| 201 | Permission denied. | 2799| 202 | Called by non-system application. | 2800| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types. | 2801| 14000011 | System inner fail. | 2802 2803**Example** 2804 2805```ts 2806import { dataSharePredicates } from '@kit.ArkData'; 2807 2808async function example() { 2809 try { 2810 console.info('requestEditDataPromiseDemo') 2811 let predicates: dataSharePredicates.DataSharePredicates = new dataSharePredicates.DataSharePredicates(); 2812 let fetchOptions: photoAccessHelper.FetchOptions = { 2813 fetchColumns: [], 2814 predicates: predicates 2815 }; 2816 let fetchResult: photoAccessHelper.FetchResult<photoAccessHelper.PhotoAsset> = await phAccessHelper.getAssets(fetchOptions); 2817 let photoAsset: photoAccessHelper.PhotoAsset = await fetchResult.getFirstObject(); 2818 let editdata: string = await photoAsset.requestEditData(); 2819 console.info('Editdata is ' + editdata); 2820 } catch (err) { 2821 console.error(`requestEditDataPromiseDemo failed with error: ${err.code}, ${err.message}`); 2822 } 2823} 2824``` 2825 2826### getEditData<sup>11+</sup> 2827 2828getEditData(): Promise<MediaAssetEditData> 2829 2830Obtains the edited data of this asset. This API uses a promise to return the result. 2831 2832If the asset has never been edited, an empty string is returned. 2833 2834**System API**: This is a system API. 2835 2836**Required permissions**: ohos.permission.READ_IMAGEVIDEO 2837 2838**System capability**: SystemCapability.FileManagement.PhotoAccessHelper.Core 2839 2840**Return value** 2841 2842| Type | Description | 2843| --------------------------------------- | ----------------- | 2844|Promise<[MediaAssetEditData](#mediaasseteditdata11)> | Promise used to return the edited asset data.| 2845 2846**Error codes** 2847 2848For details about the error codes, see [Universal Error Codes](../errorcode-universal.md) and [File Management Error Codes](../apis-core-file-kit/errorcode-filemanagement.md). 2849 2850| ID| Error Message| 2851| -------- | ---------------------------------------- | 2852| 201 | Permission denied. | 2853| 202 | Called by non-system application. | 2854| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types. | 2855| 14000011 | System inner fail. | 2856 2857**Example** 2858 2859```ts 2860import { dataSharePredicates } from '@kit.ArkData'; 2861 2862async function example() { 2863 try { 2864 console.info('getEditDataDemo') 2865 let predicates: dataSharePredicates.DataSharePredicates = new dataSharePredicates.DataSharePredicates(); 2866 let fetchOptions: photoAccessHelper.FetchOptions = { 2867 fetchColumns: [], 2868 predicates: predicates 2869 }; 2870 let fetchResult: photoAccessHelper.FetchResult<photoAccessHelper.PhotoAsset> = await phAccessHelper.getAssets(fetchOptions); 2871 let photoAsset: photoAccessHelper.PhotoAsset = await fetchResult.getFirstObject(); 2872 let assetEditData: photoAccessHelper.MediaAssetEditData = await photoAsset.getEditData(); 2873 let data: string = assetEditData.data; 2874 console.info('edit data is ' + data); 2875 } catch (err) { 2876 console.error(`getEditDataDemo failed with error: ${err.code}, ${err.message}`); 2877 } 2878} 2879``` 2880 2881### requestSource<sup>11+</sup> 2882 2883requestSource(callback: AsyncCallback<number>): void 2884 2885Opens the source file to obtain the FD. This API uses an asynchronous callback to return the result. 2886 2887**System API**: This is a system API. 2888 2889**Required permissions**: ohos.permission.READ_IMAGEVIDEO 2890 2891**System capability**: SystemCapability.FileManagement.PhotoAccessHelper.Core 2892 2893**Parameters** 2894 2895| Name | Type | Mandatory | Description | 2896| ---------- | ------- | ---- | ---------------------------------- | 2897| callback | AsyncCallback<number> | Yes | Callback used to return the FD.| 2898 2899**Error codes** 2900 2901For details about the error codes, see [Universal Error Codes](../errorcode-universal.md) and [File Management Error Codes](../apis-core-file-kit/errorcode-filemanagement.md). 2902 2903| ID| Error Message| 2904| -------- | ---------------------------------------- | 2905| 201 | Permission denied. | 2906| 202 | Called by non-system application. | 2907| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types. | 2908| 14000011 | System inner fail. | 2909 2910**Example** 2911 2912```ts 2913import { dataSharePredicates } from '@kit.ArkData'; 2914 2915async function example() { 2916 try { 2917 console.info('requsetSourceCallbackDemo') 2918 let predicates: dataSharePredicates.DataSharePredicates = new dataSharePredicates.DataSharePredicates(); 2919 let fetchOptions: photoAccessHelper.FetchOptions = { 2920 fetchColumns: [], 2921 predicates: predicates 2922 }; 2923 let fetchResult: photoAccessHelper.FetchResult<photoAccessHelper.PhotoAsset> = await phAccessHelper.getAssets(fetchOptions); 2924 let photoAsset: photoAccessHelper.PhotoAsset = await fetchResult.getFirstObject(); 2925 photoAsset.requestSource((err, fd) => { 2926 if (err === undefined) { 2927 console.info('Source fd is ' + fd); 2928 } else { 2929 console.error(`requestSource failed with error: ${err.code}, ${err.message}`); 2930 } 2931 }); 2932 } catch (err) { 2933 console.error(`requsetSourceCallbackDemo failed with error: ${err.code}, ${err.message}`); 2934 } 2935} 2936``` 2937 2938### requestSource<sup>11+</sup> 2939 2940requestSource(): Promise<number> 2941 2942Opens the source file to obtain the FD. This API uses a promise to return the result. 2943 2944**System API**: This is a system API. 2945 2946**Required permissions**: ohos.permission.READ_IMAGEVIDEO 2947 2948**System capability**: SystemCapability.FileManagement.PhotoAccessHelper.Core 2949 2950**Return value** 2951 2952| Type | Description | 2953| --------------------------------------- | ----------------- | 2954|Promise<number> | Promise used to return the FD.| 2955 2956**Error codes** 2957 2958For details about the error codes, see [Universal Error Codes](../errorcode-universal.md) and [File Management Error Codes](../apis-core-file-kit/errorcode-filemanagement.md). 2959 2960| ID| Error Message| 2961| -------- | ---------------------------------------- | 2962| 201 | Permission denied. | 2963| 202 | Called by non-system application. | 2964| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types. | 2965| 14000011 | System inner fail. | 2966 2967**Example** 2968 2969```ts 2970import { dataSharePredicates } from '@kit.ArkData'; 2971 2972async function example() { 2973 try { 2974 console.info('requsetSourcePromiseDemo') 2975 let predicates: dataSharePredicates.DataSharePredicates = new dataSharePredicates.DataSharePredicates(); 2976 let fetchOptions: photoAccessHelper.FetchOptions = { 2977 fetchColumns: [], 2978 predicates: predicates 2979 }; 2980 let fetchResult: photoAccessHelper.FetchResult<photoAccessHelper.PhotoAsset> = await phAccessHelper.getAssets(fetchOptions); 2981 let photoAsset: photoAccessHelper.PhotoAsset = await fetchResult.getFirstObject(); 2982 let fd = await photoAsset.requestSource(); 2983 console.info('Source fd is ' + fd); 2984 } catch (err) { 2985 console.error(`requsetSourcePromiseDemo failed with error: ${err.code}, ${err.message}`); 2986 } 2987} 2988``` 2989 2990### commitEditedAsset<sup>11+</sup> 2991 2992commitEditedAsset(editData: string, uri: string, callback: AsyncCallback<void>) 2993 2994Commits the edited image or video asset. This API uses an asynchronous callback to return the result. 2995 2996The edited file is transferred to the media library based on the URI, which is **FileUri** of the edited file in the application sandbox directory. For details, see [File URI](../apis-core-file-kit/js-apis-file-fileuri.md). 2997 2998**NOTE**<br>The commit operation overwrites the previous edited data. 2999 3000**System API**: This is a system API. 3001 3002**Required permissions**: ohos.permission.WRITE_IMAGEVIDEO 3003 3004**System capability**: SystemCapability.FileManagement.PhotoAccessHelper.Core 3005 3006**Parameters** 3007 3008| Name | Type | Mandatory | Description | 3009| ---------- | ------- | ---- | ---------------------------------- | 3010| editData | string | Yes | New data to commit.| 3011| uri | string | Yes | URI of the committed image or video in the application sandbox.| 3012| callback | AsyncCallback<void> | Yes | Callback that returns no value.| 3013 3014**Error codes** 3015 3016For details about the error codes, see [Universal Error Codes](../errorcode-universal.md) and [File Management Error Codes](../apis-core-file-kit/errorcode-filemanagement.md). 3017 3018| ID| Error Message| 3019| -------- | ---------------------------------------- | 3020| 201 | Permission denied. | 3021| 202 | Called by non-system application. | 3022| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types; 3. Parameter verification failed. | 3023| 14000011 | System inner fail. | 3024 3025**Example** 3026 3027```ts 3028import { dataSharePredicates } from '@kit.ArkData'; 3029 3030async function example() { 3031 try { 3032 console.info('commitEditedAssetCallbackDemo') 3033 let predicates: dataSharePredicates.DataSharePredicates = new dataSharePredicates.DataSharePredicates(); 3034 let fetchOptions: photoAccessHelper.FetchOptions = { 3035 fetchColumns: [], 3036 predicates: predicates 3037 }; 3038 let fetchResult: photoAccessHelper.FetchResult<photoAccessHelper.PhotoAsset> = await phAccessHelper.getAssets(fetchOptions); 3039 let photoAsset: photoAccessHelper.PhotoAsset = await fetchResult.getFirstObject(); 3040 let editData = '123456'; 3041 let uri = 'file://com.example.temptest/data/storage/el2/base/haps/entry/files/test.jpg'; 3042 photoAsset.commitEditedAsset(editData, uri, (err) => { 3043 if (err === undefined) { 3044 console.info('commitEditedAsset is successful'); 3045 } else { 3046 console.error(`commitEditedAsset failed with error: ${err.code}, ${err.message}`); 3047 } 3048 }); 3049 } catch (err) { 3050 console.error(`commitEditedAssetCallbackDemo failed with error: ${err.code}, ${err.message}`); 3051 } 3052} 3053``` 3054 3055### commitEditedAsset<sup>11+</sup> 3056 3057commitEditedAsset(editData: string, uri: string): Promise<void> 3058 3059Commits the edited image or video asset. This API uses a promise to return the result. 3060 3061The edited file is transferred to the media library based on the URI, which is **FileUri** of the edited file in the application sandbox directory. For details, see [File URI](../apis-core-file-kit/js-apis-file-fileuri.md). 3062 3063**NOTE**<br>The commit operation overwrites the previous edited data. 3064 3065**System API**: This is a system API. 3066 3067**Required permissions**: ohos.permission.WRITE_IMAGEVIDEO 3068 3069**System capability**: SystemCapability.FileManagement.PhotoAccessHelper.Core 3070 3071**Parameters** 3072 3073| Name | Type | Mandatory | Description | 3074| ---------- | ------- | ---- | ---------------------------------- | 3075| editData | string | Yes | New data to commit.| 3076| uri | string | Yes | URI of the committed image or video in the application sandbox.| 3077 3078**Return value** 3079 3080| Type | Description | 3081| --------------------------------------- | ----------------- | 3082|Promise<void> | Promise that returns no value.| 3083 3084**Error codes** 3085 3086For details about the error codes, see [Universal Error Codes](../errorcode-universal.md) and [File Management Error Codes](../apis-core-file-kit/errorcode-filemanagement.md). 3087 3088| ID| Error Message| 3089| -------- | ---------------------------------------- | 3090| 201 | Permission denied. | 3091| 202 | Called by non-system application. | 3092| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types; 3. Parameter verification failed. | 3093| 14000011 | System inner fail. | 3094 3095**Example** 3096 3097```ts 3098import { dataSharePredicates } from '@kit.ArkData'; 3099 3100async function example() { 3101 try { 3102 console.info('commitEditedAssetPromiseDemo') 3103 let predicates: dataSharePredicates.DataSharePredicates = new dataSharePredicates.DataSharePredicates(); 3104 let fetchOptions: photoAccessHelper.FetchOptions = { 3105 fetchColumns: [], 3106 predicates: predicates 3107 }; 3108 let fetchResult: photoAccessHelper.FetchResult<photoAccessHelper.PhotoAsset> = await phAccessHelper.getAssets(fetchOptions); 3109 let photoAsset: photoAccessHelper.PhotoAsset = await fetchResult.getFirstObject(); 3110 let editData = '123456'; 3111 let uri = 'file://com.example.temptest/data/storage/el2/base/haps/entry/files/test.jpg'; 3112 await photoAsset.commitEditedAsset(editData, uri); 3113 console.info('commitEditedAsset is successful'); 3114 } catch (err) { 3115 console.error(`commitEditedAssetPromiseDemo failed with error: ${err.code}, ${err.message}`); 3116 } 3117} 3118``` 3119 3120### revertToOriginal<sup>11+</sup> 3121 3122revertToOriginal(callback: AsyncCallback<void>) 3123 3124Reverts to the state of the file before being edited. This API uses an asynchronous callback to return the result. 3125 3126**NOTE**<br>This API deletes the edited data and edited image or video asset, and the deleted data cannot be restored. Exercise caution when using this API. 3127 3128**System API**: This is a system API. 3129 3130**Required permissions**: ohos.permission.WRITE_IMAGEVIDEO 3131 3132**System capability**: SystemCapability.FileManagement.PhotoAccessHelper.Core 3133 3134**Parameters** 3135 3136| Name | Type | Mandatory | Description | 3137| ---------- | ------- | ---- | ---------------------------------- | 3138| callback | AsyncCallback<void> | Yes | Callback that returns no value.| 3139 3140**Error codes** 3141 3142For details about the error codes, see [Universal Error Codes](../errorcode-universal.md) and [File Management Error Codes](../apis-core-file-kit/errorcode-filemanagement.md). 3143 3144| ID| Error Message| 3145| -------- | ---------------------------------------- | 3146| 201 | Permission denied. | 3147| 202 | Called by non-system application. | 3148| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types. | 3149| 14000011 | System inner fail. | 3150 3151**Example** 3152 3153```ts 3154import { dataSharePredicates } from '@kit.ArkData'; 3155 3156async function example() { 3157 try { 3158 console.info('revertToOriginalCallbackDemo') 3159 let predicates: dataSharePredicates.DataSharePredicates = new dataSharePredicates.DataSharePredicates(); 3160 let fetchOptions: photoAccessHelper.FetchOptions = { 3161 fetchColumns: [], 3162 predicates: predicates 3163 }; 3164 let fetchResult: photoAccessHelper.FetchResult<photoAccessHelper.PhotoAsset> = await phAccessHelper.getAssets(fetchOptions); 3165 let photoAsset: photoAccessHelper.PhotoAsset = await fetchResult.getFirstObject(); 3166 photoAsset.revertToOriginal((err) => { 3167 if (err === undefined) { 3168 console.info('revertToOriginal is successful'); 3169 } else { 3170 console.error(`revertToOriginal failed with error: ${err.code}, ${err.message}`); 3171 } 3172 }); 3173 } catch (err) { 3174 console.error(`revertToOriginalCallbackDemo failed with error: ${err.code}, ${err.message}`); 3175 } 3176} 3177``` 3178 3179### revertToOriginal<sup>11+</sup> 3180 3181revertToOriginal(): Promise<void> 3182 3183Reverts to the state of the file before being edited. This API uses a promise to return the result. 3184 3185**NOTE**<br>This API deletes the edited data and edited image or video asset, and the deleted data cannot be restored. Exercise caution when using this API. 3186 3187**System API**: This is a system API. 3188 3189**Required permissions**: ohos.permission.WRITE_IMAGEVIDEO 3190 3191**System capability**: SystemCapability.FileManagement.PhotoAccessHelper.Core 3192 3193**Return value** 3194 3195| Type | Description | 3196| --------------------------------------- | ----------------- | 3197|Promise<string> | Promise that returns no value.| 3198 3199**Error codes** 3200 3201For details about the error codes, see [Universal Error Codes](../errorcode-universal.md) and [File Management Error Codes](../apis-core-file-kit/errorcode-filemanagement.md). 3202 3203| ID| Error Message| 3204| -------- | ---------------------------------------- | 3205| 201 | Permission denied. | 3206| 202 | Called by non-system application. | 3207| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types. | 3208| 14000011 | System inner fail. | 3209 3210**Example** 3211 3212```ts 3213import { dataSharePredicates } from '@kit.ArkData'; 3214 3215async function example() { 3216 try { 3217 console.info('revertToOriginalPromiseDemo') 3218 let predicates: dataSharePredicates.DataSharePredicates = new dataSharePredicates.DataSharePredicates(); 3219 let fetchOptions: photoAccessHelper.FetchOptions = { 3220 fetchColumns: [], 3221 predicates: predicates 3222 }; 3223 let fetchResult: photoAccessHelper.FetchResult<photoAccessHelper.PhotoAsset> = await phAccessHelper.getAssets(fetchOptions); 3224 let photoAsset: photoAccessHelper.PhotoAsset = await fetchResult.getFirstObject(); 3225 photoAsset.revertToOriginal(); 3226 console.info('revertToOriginal is successful'); 3227 } catch (err) { 3228 console.error(`revertToOriginalPromiseDemo failed with error: ${err.code}, ${err.message}`); 3229 } 3230} 3231``` 3232 3233### requestPhoto<sup>11+</sup> 3234 3235requestPhoto(callback: AsyncCallback<image.PixelMap>): string 3236 3237Obtains the quick thumbnail and quality thumbnail of this asset. This API uses an asynchronous callback to return the result. 3238 3239The size of a quick thumbnail is 128 x 128, and the size of a quality thumbnail is 256 x 256. After this API is called, the callback will be invoked twice to return a quick thumbnail and a quality thumbnail in sequence. 3240 3241**System API**: This is a system API. 3242 3243**Required permissions**: ohos.permission.READ_IMAGEVIDEO 3244 3245**System capability**: SystemCapability.FileManagement.PhotoAccessHelper.Core 3246 3247**Parameters** 3248 3249| Name | Type | Mandatory | Description | 3250| ---------- | ------- | ---- | ---------------------------------- | 3251| callback | AsyncCallback<[image.PixelMap](../apis-image-kit/js-apis-image.md#pixelmap7)> | Yes | Callback invoked twice to return the quick and quality thumbnails obtained.| 3252 3253**Return value** 3254 3255| Type | Description | 3256| --------------------------------------- | ----------------- | 3257| string | ID of the task for obtaining thumbnails.| 3258 3259**Error codes** 3260 3261For details about the error codes, see [Universal Error Codes](../errorcode-universal.md) and [File Management Error Codes](../apis-core-file-kit/errorcode-filemanagement.md). 3262 3263| ID| Error Message| 3264| -------- | ---------------------------------------- | 3265| 201 | Permission verification failed, usually the result returned by VerifyAccessToken. | 3266| 202 | Permission verification failed, application which is not a system application uses system API. | 3267| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types. | 3268| 14000011 | System inner fail. | 3269 3270**Example** 3271 3272```ts 3273import { dataSharePredicates } from '@kit.ArkData'; 3274import { image } from '@kit.ImageKit'; 3275 3276async function example() { 3277 try { 3278 console.info('requestPhotoDemo') 3279 let options: photoAccessHelper.FetchOptions = { 3280 fetchColumns: [], 3281 predicates: new dataSharePredicates.DataSharePredicates() 3282 } 3283 let fetchResult = await phAccessHelper.getAssets(options); 3284 let photoAsset = await fetchResult.getFirstObject(); 3285 let taskId: string = photoAsset.requestPhoto(async (err, pixel: image.PixelMap) => { 3286 if (err === undefined) { 3287 console.info("requestSource in, size: " + JSON.stringify((await pixel.getImageInfo()).size)) 3288 } else { 3289 console.error(`requestSource failed with error: ${err.code}, ${err.message}`); 3290 } 3291 }) 3292 console.info('requestSource taskId: ' + taskId) 3293 } catch (err) { 3294 console.error(`requestPhotoDemo failed with error: ${err.code}, ${err.message}`); 3295 } 3296} 3297``` 3298 3299### requestPhoto<sup>11+</sup> 3300 3301requestPhoto(options: RequestPhotoOptions, callback: AsyncCallback<image.PixelMap>): string 3302 3303Obtains the thumbnails of an asset based on the specified options. This API uses an asynchronous callback to return the result. 3304 3305**System API**: This is a system API. 3306 3307**Required permissions**: ohos.permission.READ_IMAGEVIDEO 3308 3309**System capability**: SystemCapability.FileManagement.PhotoAccessHelper.Core 3310 3311**Parameters** 3312 3313| Name | Type | Mandatory | Description | 3314| ---------- | ------- | ---- | ---------------------------------- | 3315| options | [RequestPhotoOptions](#requestphotooptions11) | Yes | Options for obtaining the asset thumbnail.| 3316| callback | AsyncCallback<[image.PixelMap](../apis-image-kit/js-apis-image.md#pixelmap7)> | Yes | Callback used to return the thumbnails obtained. The callback may be invoked more than once, depending on **options**.| 3317 3318**Return value** 3319 3320| Type | Description | 3321| --------------------------------------- | ----------------- | 3322| string | ID of the task for obtaining thumbnails.| 3323 3324**Error codes** 3325 3326For details about the error codes, see [Universal Error Codes](../errorcode-universal.md) and [File Management Error Codes](../apis-core-file-kit/errorcode-filemanagement.md). 3327 3328| ID| Error Message| 3329| -------- | ---------------------------------------- | 3330| 201 | Permission verification failed, usually the result returned by VerifyAccessToken. | 3331| 202 | Permission verification failed, application which is not a system application uses system API. | 3332| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types; 3. Parameter verification failed. | 3333| 14000011 | System inner fail. | 3334 3335**Example** 3336 3337```ts 3338import { dataSharePredicates } from '@kit.ArkData'; 3339import { image } from '@kit.ImageKit'; 3340 3341async function example() { 3342 try { 3343 console.info('requestPhotoDemo') 3344 let options: photoAccessHelper.FetchOptions = { 3345 fetchColumns: [], 3346 predicates: new dataSharePredicates.DataSharePredicates() 3347 } 3348 let fetchResult = await phAccessHelper.getAssets(options); 3349 let photoAsset = await fetchResult.getFirstObject(); 3350 let taskId: string = photoAsset.requestPhoto({ 3351 "size": { 3352 "width": 256, 3353 "height": 256 3354 }, 3355 "requestPhotoType": photoAccessHelper.RequestPhotoType.REQUEST_ALL_THUMBNAILS 3356 }, async (err, pixel: image.PixelMap) => { 3357 if (err === undefined) { 3358 console.info("requestSource in, size: " + JSON.stringify((await pixel.getImageInfo()).size)) 3359 } else { 3360 console.error(`requestSource failed with error: ${err.code}, ${err.message}`); 3361 } 3362 }) 3363 console.info('requestSource taskId: ' + taskId) 3364 } catch (err) { 3365 console.error(`requestPhotoDemo failed with error: ${err.code}, ${err.message}`); 3366 } 3367} 3368``` 3369 3370### cancelPhotoRequest<sup>11+</sup> 3371 3372cancelPhotoRequest(requestId: string): void 3373 3374Cancels a task for obtaining media thumbnails. 3375 3376**System API**: This is a system API. 3377 3378**Required permissions**: ohos.permission.READ_IMAGEVIDEO 3379 3380**System capability**: SystemCapability.FileManagement.PhotoAccessHelper.Core 3381 3382**Parameters** 3383 3384| Name | Type | Mandatory | Description | 3385| ---------- | ------- | ---- | ---------------------------------- | 3386| requestId | string | Yes | ID of the task to cancel.| 3387 3388**Error codes** 3389 3390For details about the error codes, see [Universal Error Codes](../errorcode-universal.md) and [File Management Error Codes](../apis-core-file-kit/errorcode-filemanagement.md). 3391 3392| ID| Error Message| 3393| -------- | ---------------------------------------- | 3394| 201 | Permission verification failed, usually the result returned by VerifyAccessToken. | 3395| 202 | Permission verification failed, application which is not a system application uses system API. | 3396| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types; 3. Parameter verification failed. | 3397| 14000011 | System inner fail. | 3398 3399**Example** 3400 3401```ts 3402import { dataSharePredicates } from '@kit.ArkData'; 3403import { image } from '@kit.ImageKit'; 3404 3405async function example() { 3406 try { 3407 console.info('cancelPhotoRequestDemo') 3408 let options: photoAccessHelper.FetchOptions = { 3409 fetchColumns: [], 3410 predicates: new dataSharePredicates.DataSharePredicates() 3411 } 3412 let fetchResult = await phAccessHelper.getAssets(options); 3413 let photoAsset = await fetchResult.getFirstObject(); 3414 let taskId: string = photoAsset.requestPhoto({ 3415 "size": { 3416 "width": 256, 3417 "height": 256 3418 }, 3419 "requestPhotoType": photoAccessHelper.RequestPhotoType.REQUEST_ALL_THUMBNAILS 3420 }, async (err, pixel: image.PixelMap) => { 3421 if (err === undefined) { 3422 console.info("requestSource in, size: " + JSON.stringify((await pixel.getImageInfo()).size)) 3423 } else { 3424 console.error(`requestSource failed with error: ${err.code}, ${err.message}`); 3425 } 3426 }) 3427 console.info('requestSource taskId: ' + taskId) 3428 photoAsset.cancelPhotoRequest(taskId); 3429 } catch (err) { 3430 console.error(`cancelPhotoRequestDemo failed with error: ${err.code}, ${err.message}`); 3431 } 3432} 3433``` 3434 3435### getAnalysisData<sup>11+</sup> 3436 3437getAnalysisData(analysisType: AnalysisType): Promise\<string> 3438 3439Obtains analysis data. This API uses a promise to return the result. 3440 3441**System API**: This is a system API. 3442 3443**Required permissions**: ohos.permission.READ\_IMAGEVIDEO 3444 3445**System capability**: SystemCapability.FileManagement.PhotoAccessHelper.Core 3446 3447**Parameters** 3448 3449| Name | Type | Mandatory| Description | 3450| :----------- | :----------- | :- | :----------- | 3451| analysisType | [AnalysisType](#analysistype11) | Yes | Smart analysis type.| 3452 3453**Error codes** 3454 3455For details about the error codes, see [Universal Error Codes](../errorcode-universal.md) and [File Management Error Codes](../apis-core-file-kit/errorcode-filemanagement.md). 3456 3457| ID | Error Message | 3458| :------- | :-------------------------------- | 3459| 201 | Permission denied. | 3460| 202 | Called by non-system application. | 3461| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types; 3. Parameter verification failed. | 3462| 14000011 | System inner fail. | 3463 3464**Example** 3465 3466```ts 3467import { dataSharePredicates } from '@kit.ArkData'; 3468 3469async function example() { 3470 try { 3471 console.info('getAnalysisDataDemo') 3472 let fetchOptions: photoAccessHelper.FetchOptions = { 3473 fetchColumns: [], 3474 predicates: new dataSharePredicates.DataSharePredicates() 3475 } 3476 let fetchResult: photoAccessHelper.FetchResult<photoAccessHelper.PhotoAsset> = 3477 await phAccessHelper.getAssets(fetchOptions); 3478 let photoAsset: photoAccessHelper.PhotoAsset = await fetchResult.getFirstObject(); 3479 if (photoAsset != undefined) { 3480 let analysisData: string = await photoAsset.getAnalysisData( 3481 photoAccessHelper.AnalysisType.ANALYSIS_OCR); 3482 console.info('get ocr result: ' + JSON.stringify(analysisData)); 3483 } 3484 fetchResult.close(); 3485 } catch (err) { 3486 console.error(`getAnalysisDataDemofailed with error: ${err.code}, ${err.message}`); 3487 } 3488} 3489``` 3490 3491### getThumbnailData<sup>18+</sup> 3492 3493getThumbnailData(type: ThumbnailType): Promise<ArrayBuffer> 3494 3495Obtains the ArrayBuffer of a file thumbnail by specifying its type. This API uses a promise to return the result. 3496 3497**Required permissions**: ohos.permission.READ_IMAGEVIDEO 3498 3499**System capability**: SystemCapability.FileManagement.PhotoAccessHelper.Core 3500 3501**Parameters** 3502 3503| Name | Type | Mandatory | Description | 3504| ---- | -------------- | ---- | ----- | 3505| type | [ThumbnailType](#thumbnailtype13) | Yes | Type of the thumbnail.| 3506 3507**Return value** 3508 3509| Type | Description | 3510| ----------------------------- | --------------------- | 3511| Promise\<ArrayBuffer> | Promise used to return the ArrayBuffer of the thumbnail.| 3512 3513**Error codes** 3514 3515For details about the error codes, see [Universal Error Codes](../errorcode-universal.md) and [File Management Error Codes](../apis-core-file-kit/errorcode-filemanagement.md). 3516 3517| ID| Error Message| 3518| -------- | ---------------------------------------- | 3519| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types; 3. Parameter verification failed. | 3520| 13900012 | Permission denied. | 3521| 13900020 | Invalid argument. | 3522| 14000011 | System inner fail. | 3523 3524**Example** 3525 3526```ts 3527import { dataSharePredicates } from '@kit.ArkData'; 3528import { BusinessError } from '@kit.BasicServicesKit'; 3529import {photoAccessHelper} from '@kit.MediaLibraryKit'; 3530const context = getContext(this); 3531let phAccessHelper = photoAccessHelper.getPhotoAccessHelper(context); 3532 3533async function example() { 3534 console.info('getThumbnailDataDemo'); 3535 let predicates: dataSharePredicates.DataSharePredicates = new dataSharePredicates.DataSharePredicates(); 3536 let fetchOption: photoAccessHelper.FetchOptions = { 3537 fetchColumns: [], 3538 predicates: predicates 3539 }; 3540 let fetchResult: photoAccessHelper.FetchResult<photoAccessHelper.PhotoAsset> = await phAccessHelper.getAssets(fetchOption); 3541 let asset = await fetchResult.getFirstObject(); 3542 console.info('asset displayName = ', asset.displayName); 3543 asset.getThumbnailData(photoAccessHelper.ThumbnailType.LCD).then((buffer: ArrayBuffer) => { 3544 console.info('getThumbnailData successful, buffer byteLength = ${buffer.byteLength}'); 3545 }).catch((err: BusinessError) => { 3546 console.error(`getThumbnailData fail with error: ${err.code}, ${err.message}`); 3547 }); 3548} 3549``` 3550 3551## Album 3552 3553Provides APIs to manage albums. 3554 3555### Properties 3556 3557**System capability**: SystemCapability.FileManagement.PhotoAccessHelper.Core 3558 3559| Name | Type | Read-Only | Optional | Description | 3560| ------------ | ------ | ---- | ---- | ------- | 3561| lpath<sup>18+</sup> | string | Yes | Yes | Virtual path of the album.<br>**System API**: This is a system API.| 3562 3563### recoverAssets<sup>(deprecated)</sup> 3564 3565recoverAssets(assets: Array<PhotoAsset>, callback: AsyncCallback<void>): void 3566 3567Recovers image or video assets from the trash. Before the operation, ensure that the image or video assets exist in the trash. This API uses an asynchronous callback to return the result. 3568 3569> **NOTE** 3570> 3571> This API is supported since API version 10 and deprecated since API version 11. Use [MediaAlbumChangeRequest.recoverAssets](#recoverassets11) instead. 3572 3573**System API**: This is a system API. 3574 3575**Required permissions**: ohos.permission.WRITE_IMAGEVIDEO 3576 3577**System capability**: SystemCapability.FileManagement.PhotoAccessHelper.Core 3578 3579**Parameters** 3580 3581| Name | Type | Mandatory| Description | 3582| -------- | ------------------------- | ---- | ---------- | 3583| assets | Array<[PhotoAsset](#photoasset)> | Yes | Array of the image or video assets to recover.| 3584| callback | AsyncCallback<void> | Yes | Callback that returns no value.| 3585 3586**Error codes** 3587 3588For details about the error codes, see [Universal Error Codes](../errorcode-universal.md) and [File Management Error Codes](../apis-core-file-kit/errorcode-filemanagement.md). 3589 3590| ID| Error Message| 3591| -------- | ---------------------------------------- | 3592| 202 | Called by non-system application. | 3593| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types; 3. Parameter verification failed. | 3594| 13900012 | Permission denied. | 3595| 13900020 | Invalid argument. | 3596| 14000011 | System inner fail. | 3597 3598**Example** 3599 3600```ts 3601import { dataSharePredicates } from '@kit.ArkData'; 3602 3603async function example() { 3604 try { 3605 console.info('recoverAssetsDemoCallback'); 3606 let predicates: dataSharePredicates.DataSharePredicates = new dataSharePredicates.DataSharePredicates(); 3607 let fetchOption: photoAccessHelper.FetchOptions = { 3608 fetchColumns: [], 3609 predicates: predicates 3610 }; 3611 let albumFetchResult: photoAccessHelper.FetchResult<photoAccessHelper.Album> = await phAccessHelper.getAlbums(photoAccessHelper.AlbumType.SYSTEM, photoAccessHelper.AlbumSubtype.TRASH); 3612 let album: photoAccessHelper.Album = await albumFetchResult.getFirstObject(); 3613 let fetchResult: photoAccessHelper.FetchResult<photoAccessHelper.PhotoAsset> = await album.getAssets(fetchOption); 3614 let asset: photoAccessHelper.PhotoAsset = await fetchResult.getFirstObject(); 3615 album.recoverAssets([asset], (err) => { 3616 if (err === undefined) { 3617 console.info('album recoverAssets successfully'); 3618 } else { 3619 console.error(`album recoverAssets failed with error: ${err.code}, ${err.message}`); 3620 } 3621 }); 3622 } catch (err) { 3623 console.error(`recoverAssetsDemoCallback failed with error: ${err.code}, ${err.message}`); 3624 } 3625} 3626``` 3627 3628### recoverAssets<sup>(deprecated)</sup> 3629 3630recoverAssets(assets: Array<PhotoAsset>): Promise<void> 3631 3632Recovers image or video assets from the trash. Before the operation, ensure that the image or video assets exist in the trash. This API uses a promise to return the result. 3633 3634> **NOTE** 3635> 3636> This API is supported since API version 10 and deprecated since API version 11. Use [MediaAlbumChangeRequest.recoverAssets](#recoverassets11) instead. 3637 3638**System API**: This is a system API. 3639 3640**Required permissions**: ohos.permission.WRITE_IMAGEVIDEO 3641 3642**System capability**: SystemCapability.FileManagement.PhotoAccessHelper.Core 3643 3644**Parameters** 3645 3646| Name | Type | Mandatory| Description | 3647| -------- | ------------------------- | ---- | ---------- | 3648| assets | Array<[PhotoAsset](#photoasset)> | Yes | Array of the image or video assets to recover.| 3649 3650**Return value** 3651 3652| Type | Description | 3653| --------------------------------------- | ----------------- | 3654|Promise<void> | Promise that returns no value.| 3655 3656**Error codes** 3657 3658For details about the error codes, see [Universal Error Codes](../errorcode-universal.md) and [File Management Error Codes](../apis-core-file-kit/errorcode-filemanagement.md). 3659 3660| ID| Error Message| 3661| -------- | ---------------------------------------- | 3662| 202 | Called by non-system application. | 3663| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types; 3. Parameter verification failed. | 3664| 13900012 | Permission denied. | 3665| 13900020 | Invalid argument. | 3666| 14000011 | System inner fail. | 3667 3668**Example** 3669 3670```ts 3671import { dataSharePredicates } from '@kit.ArkData'; 3672import { BusinessError } from '@kit.BasicServicesKit'; 3673 3674async function example() { 3675 try { 3676 console.info('recoverAssetsDemoPromise'); 3677 let predicates: dataSharePredicates.DataSharePredicates = new dataSharePredicates.DataSharePredicates(); 3678 let fetchOption: photoAccessHelper.FetchOptions = { 3679 fetchColumns: [], 3680 predicates: predicates 3681 }; 3682 let albumFetchResult: photoAccessHelper.FetchResult<photoAccessHelper.Album> = await phAccessHelper.getAlbums(photoAccessHelper.AlbumType.SYSTEM, photoAccessHelper.AlbumSubtype.TRASH); 3683 let album: photoAccessHelper.Album = await albumFetchResult.getFirstObject(); 3684 let fetchResult: photoAccessHelper.FetchResult<photoAccessHelper.PhotoAsset> = await album.getAssets(fetchOption); 3685 let asset: photoAccessHelper.PhotoAsset = await fetchResult.getFirstObject(); 3686 album.recoverAssets([asset]).then(() => { 3687 console.info('album recoverAssets successfully'); 3688 }).catch((err: BusinessError) => { 3689 console.error(`album recoverAssets failed with error: ${err.code}, ${err.message}`); 3690 }); 3691 } catch (err) { 3692 console.error(`recoverAssetsDemoPromise failed with error: ${err.code}, ${err.message}`); 3693 } 3694} 3695``` 3696 3697### deleteAssets<sup>(deprecated)</sup> 3698 3699deleteAssets(assets: Array<PhotoAsset>, callback: AsyncCallback<void>): void 3700 3701Deletes image or video assets from the trash. Before the operation, ensure that the image or video assets exist in the trash. This API uses an asynchronous callback to return the result. 3702 3703> **NOTE** 3704> 3705> This API is supported since API version 10 and deprecated since API version 11. Use [MediaAlbumChangeRequest.deleteAssets](#deleteassets11) instead. 3706 3707**NOTE**<br>This operation is irreversible. The file assets deleted cannot be restored. Exercise caution when performing this operation. 3708 3709**System API**: This is a system API. 3710 3711**Required permissions**: ohos.permission.WRITE_IMAGEVIDEO 3712 3713**System capability**: SystemCapability.FileManagement.PhotoAccessHelper.Core 3714 3715**Parameters** 3716 3717| Name | Type | Mandatory| Description | 3718| -------- | ------------------------- | ---- | ---------- | 3719| assets | Array<[PhotoAsset](#photoasset)> | Yes | Array of the image or video assets to delete.| 3720| callback | AsyncCallback<void> | Yes | Callback that returns no value.| 3721 3722**Error codes** 3723 3724For details about the error codes, see [Universal Error Codes](../errorcode-universal.md) and [File Management Error Codes](../apis-core-file-kit/errorcode-filemanagement.md). 3725 3726| ID| Error Message| 3727| -------- | ---------------------------------------- | 3728| 202 | Called by non-system application. | 3729| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types; 3. Parameter verification failed. | 3730| 13900012 | Permission denied. | 3731| 13900020 | Invalid argument. | 3732| 14000011 | System inner fail. | 3733 3734**Example** 3735 3736```ts 3737import { dataSharePredicates } from '@kit.ArkData'; 3738 3739async function example() { 3740 try { 3741 console.info('deleteAssetsDemoCallback'); 3742 let predicates: dataSharePredicates.DataSharePredicates = new dataSharePredicates.DataSharePredicates(); 3743 let fetchOption: photoAccessHelper.FetchOptions = { 3744 fetchColumns: [], 3745 predicates: predicates 3746 }; 3747 let albumFetchResult: photoAccessHelper.FetchResult<photoAccessHelper.Album> = await phAccessHelper.getAlbums(photoAccessHelper.AlbumType.SYSTEM, photoAccessHelper.AlbumSubtype.TRASH); 3748 let album: photoAccessHelper.Album = await albumFetchResult.getFirstObject(); 3749 let fetchResult: photoAccessHelper.FetchResult<photoAccessHelper.PhotoAsset> = await album.getAssets(fetchOption); 3750 let asset: photoAccessHelper.PhotoAsset = await fetchResult.getFirstObject(); 3751 album.deleteAssets([asset], (err) => { 3752 if (err === undefined) { 3753 console.info('album deleteAssets successfully'); 3754 } else { 3755 console.error(`album deleteAssets failed with error: ${err.code}, ${err.message}`); 3756 } 3757 }); 3758 } catch (err) { 3759 console.error(`deleteAssetsDemoCallback failed with error: ${err.code}, ${err.message}`); 3760 } 3761} 3762``` 3763 3764### deleteAssets<sup>(deprecated)</sup> 3765 3766deleteAssets(assets: Array<PhotoAsset>): Promise<void> 3767 3768Deletes image or video assets from the trash. Before the operation, ensure that the image or video assets exist in the trash. This API uses a promise to return the result. 3769 3770> **NOTE** 3771> 3772> This API is supported since API version 10 and deprecated since API version 11. Use [MediaAlbumChangeRequest.deleteAssets](#deleteassets11) instead. 3773 3774**NOTE**<br>This operation is irreversible. The file assets deleted cannot be restored. Exercise caution when performing this operation. 3775 3776**System API**: This is a system API. 3777 3778**Required permissions**: ohos.permission.WRITE_IMAGEVIDEO 3779 3780**System capability**: SystemCapability.FileManagement.PhotoAccessHelper.Core 3781 3782**Parameters** 3783 3784| Name | Type | Mandatory| Description | 3785| -------- | ------------------------- | ---- | ---------- | 3786| assets | Array<[PhotoAsset](#photoasset)> | Yes | Array of the image or video assets to delete.| 3787 3788**Return value** 3789 3790| Type | Description | 3791| --------------------------------------- | ----------------- | 3792|Promise<void> | Promise that returns no value.| 3793 3794**Error codes** 3795 3796For details about the error codes, see [Universal Error Codes](../errorcode-universal.md) and [File Management Error Codes](../apis-core-file-kit/errorcode-filemanagement.md). 3797 3798| ID| Error Message| 3799| -------- | ---------------------------------------- | 3800| 202 | Called by non-system application. | 3801| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types; 3. Parameter verification failed. | 3802| 13900012 | Permission denied. | 3803| 13900020 | Invalid argument. | 3804| 14000011 | System inner fail. | 3805 3806**Example** 3807 3808```ts 3809import { dataSharePredicates } from '@kit.ArkData'; 3810import { BusinessError } from '@kit.BasicServicesKit'; 3811 3812async function example() { 3813 try { 3814 console.info('deleteAssetsDemoPromise'); 3815 let predicates: dataSharePredicates.DataSharePredicates = new dataSharePredicates.DataSharePredicates(); 3816 let fetchOption: photoAccessHelper.FetchOptions = { 3817 fetchColumns: [], 3818 predicates: predicates 3819 }; 3820 let albumFetchResult: photoAccessHelper.FetchResult<photoAccessHelper.Album> = await phAccessHelper.getAlbums(photoAccessHelper.AlbumType.SYSTEM, photoAccessHelper.AlbumSubtype.TRASH); 3821 let album: photoAccessHelper.Album = await albumFetchResult.getFirstObject(); 3822 let fetchResult: photoAccessHelper.FetchResult<photoAccessHelper.PhotoAsset> = await album.getAssets(fetchOption); 3823 let asset: photoAccessHelper.PhotoAsset = await fetchResult.getFirstObject(); 3824 album.deleteAssets([asset]).then(() => { 3825 console.info('album deleteAssets successfully'); 3826 }).catch((err: BusinessError) => { 3827 console.error(`album deleteAssets failed with error: ${err.code}, ${err.message}`); 3828 }); 3829 } catch (err) { 3830 console.error(`deleteAssetsDemoPromise failed with error: ${err.code}, ${err.message}`); 3831 } 3832} 3833``` 3834 3835### setCoverUri<sup>(deprecated)</sup> 3836 3837setCoverUri(uri: string, callback: AsyncCallback<void>): void 3838 3839Sets the album cover. This API uses an asynchronous callback to return the result. 3840 3841> **NOTE** 3842> 3843> This API is supported since API version 10 and deprecated since API version 11. Use [MediaAlbumChangeRequest.setCoverUri](#setcoveruri11) instead. 3844 3845**NOTE**<br>This API can be used to set the user album cover, but not the system album cover. 3846 3847**System API**: This is a system API. 3848 3849**Required permissions**: ohos.permission.WRITE_IMAGEVIDEO 3850 3851**System capability**: SystemCapability.FileManagement.PhotoAccessHelper.Core 3852 3853**Parameters** 3854 3855| Name | Type | Mandatory| Description | 3856| -------- | ------------------------- | ---- | ---------- | 3857| uri | string | Yes | URI of the file to be set as the album cover.| 3858| callback | AsyncCallback<void> | Yes | Callback that returns no value.| 3859 3860**Error codes** 3861 3862For details about the error codes, see [Universal Error Codes](../errorcode-universal.md) and [File Management Error Codes](../apis-core-file-kit/errorcode-filemanagement.md). 3863 3864| ID| Error Message| 3865| -------- | ---------------------------------------- | 3866| 202 | Called by non-system application. | 3867| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types; 3. Parameter verification failed. | 3868| 13900012 | Permission denied. | 3869| 13900020 | Invalid argument. | 3870| 14000011 | System inner fail. | 3871 3872**Example** 3873 3874```ts 3875import { dataSharePredicates } from '@kit.ArkData'; 3876 3877async function example() { 3878 try { 3879 console.info('setCoverUriDemoCallback'); 3880 let predicates: dataSharePredicates.DataSharePredicates = new dataSharePredicates.DataSharePredicates(); 3881 let fetchOption: photoAccessHelper.FetchOptions = { 3882 fetchColumns: [], 3883 predicates: predicates 3884 }; 3885 let albumFetchResult: photoAccessHelper.FetchResult<photoAccessHelper.Album> = await phAccessHelper.getAlbums(photoAccessHelper.AlbumType.USER, photoAccessHelper.AlbumSubtype.USER_GENERIC); 3886 let album: photoAccessHelper.Album = await albumFetchResult.getFirstObject(); 3887 let fetchResult: photoAccessHelper.FetchResult<photoAccessHelper.PhotoAsset> = await album.getAssets(fetchOption); 3888 let asset: photoAccessHelper.PhotoAsset = await fetchResult.getFirstObject(); 3889 album.setCoverUri(asset.uri, (err) => { 3890 if (err === undefined) { 3891 console.info('album setCoverUri successfully'); 3892 } else { 3893 console.error(`album setCoverUri failed with error: ${err.code}, ${err.message}`); 3894 } 3895 }); 3896 } catch (err) { 3897 console.error(`setCoverUriDemoCallback failed with error: ${err.code}, ${err.message}`); 3898 } 3899} 3900``` 3901 3902### setCoverUri<sup>(deprecated)</sup> 3903 3904setCoverUri(uri: string): Promise<void> 3905 3906Sets the album cover. This API uses a promise to return the result. 3907 3908> **NOTE** 3909> 3910> This API is supported since API version 10 and deprecated since API version 11. Use [MediaAlbumChangeRequest.setCoverUri](#setcoveruri11) instead. 3911 3912**NOTE**<br>This API can be used to set the user album cover, but not the system album cover. 3913 3914**System API**: This is a system API. 3915 3916**Required permissions**: ohos.permission.WRITE_IMAGEVIDEO 3917 3918**System capability**: SystemCapability.FileManagement.PhotoAccessHelper.Core 3919 3920**Parameters** 3921 3922| Name | Type | Mandatory| Description | 3923| -------- | ------------------------- | ---- | ---------- | 3924| uri | string | Yes | URI of the file to be set as the album cover.| 3925 3926**Return value** 3927 3928| Type | Description | 3929| --------------------------------------- | ----------------- | 3930|Promise<void> | Promise that returns no value.| 3931 3932**Error codes** 3933 3934For details about the error codes, see [Universal Error Codes](../errorcode-universal.md) and [File Management Error Codes](../apis-core-file-kit/errorcode-filemanagement.md). 3935 3936| ID| Error Message| 3937| -------- | ---------------------------------------- | 3938| 202 | Called by non-system application. | 3939| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types; 3. Parameter verification failed. | 3940| 13900012 | Permission denied. | 3941| 13900020 | Invalid argument. | 3942| 14000011 | System inner fail. | 3943**Example** 3944 3945```ts 3946import { dataSharePredicates } from '@kit.ArkData'; 3947import { BusinessError } from '@kit.BasicServicesKit'; 3948 3949async function example() { 3950 try { 3951 console.info('setCoverUriDemoPromise'); 3952 let predicates: dataSharePredicates.DataSharePredicates = new dataSharePredicates.DataSharePredicates(); 3953 let fetchOption: photoAccessHelper.FetchOptions = { 3954 fetchColumns: [], 3955 predicates: predicates 3956 }; 3957 let albumFetchResult: photoAccessHelper.FetchResult<photoAccessHelper.Album> = await phAccessHelper.getAlbums(photoAccessHelper.AlbumType.USER, photoAccessHelper.AlbumSubtype.USER_GENERIC); 3958 let album: photoAccessHelper.Album = await albumFetchResult.getFirstObject(); 3959 let fetchResult: photoAccessHelper.FetchResult<photoAccessHelper.PhotoAsset> = await album.getAssets(fetchOption); 3960 let asset: photoAccessHelper.PhotoAsset = await fetchResult.getFirstObject(); 3961 album.setCoverUri(asset.uri).then(() => { 3962 console.info('album setCoverUri successfully'); 3963 }).catch((err: BusinessError) => { 3964 console.error(`album setCoverUri failed with error: ${err.code}, ${err.message}`); 3965 }); 3966 } catch (err) { 3967 console.error(`setCoverUriDemoPromise failed with error: ${err.code}, ${err.message}`); 3968 } 3969} 3970``` 3971 3972## MediaAssetEditData<sup>11+</sup> 3973 3974Represents the edited media asset data. 3975 3976**System API**: This is a system API. 3977 3978**System capability**: SystemCapability.FileManagement.PhotoAccessHelper.Core 3979 3980### Properties 3981 3982| Name | Type | Readable | Writable | Description | 3983| ------------ | ------ | ---- | ---- | ------- | 3984| compatibleFormat | string | Yes | Yes | Format of the edited data.<br>**System API**: This is a system API. | 3985| formatVersion | string | Yes | Yes | Version of the data format.<br>**System API**: This is a system API. | 3986| data | string | Yes | Yes | Content edited.<br>**System API**: This is a system API. | 3987 3988### constructor<sup>11+</sup> 3989 3990constructor(compatibleFormat: string, formatVersion: string) 3991 3992Constructor. 3993 3994**System API**: This is a system API. 3995 3996**System capability**: SystemCapability.FileManagement.PhotoAccessHelper.Core 3997 3998**Parameters** 3999 4000| Name | Type | Mandatory| Description | 4001| -------- | ------------------------- | ---- | ---------- | 4002| compatibleFormat | string | Yes | Format of the edited data.| 4003| formatVersion | string | Yes | Version of the data format.| 4004 4005**Error codes** 4006 4007For details about the error codes, see [Universal Error Codes](../errorcode-universal.md) and [File Management Error Codes](../apis-core-file-kit/errorcode-filemanagement.md). 4008 4009| ID| Error Message| 4010| -------- | ---------------------------------------- | 4011| 202 | Called by non-system application. | 4012| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types; 3. Parameter verification failed. | 4013| 14000011 | System inner fail. | 4014 4015**Example** 4016 4017```ts 4018let assetEditData: photoAccessHelper.MediaAssetEditData = new photoAccessHelper.MediaAssetEditData('system', '1.0'); 4019``` 4020 4021## MediaAssetChangeRequest<sup>11+</sup> 4022 4023Represents a media asset change request. 4024 4025**System capability**: SystemCapability.FileManagement.PhotoAccessHelper.Core 4026 4027### createAssetRequest<sup>11+</sup> 4028 4029static createAssetRequest(context: Context, displayName: string, options?: PhotoCreateOptions): MediaAssetChangeRequest 4030 4031Creates an asset change request with the specified file name. 4032 4033The file name must comply with the following specifications: 4034- The file name consists of a valid file name and an image or video file name extension. 4035- The file name cannot exceed 255 characters. 4036- The file name cannot contain any of the following characters:<br>API version 18 and later: \ / : * ? " < > | <br>API versions 10 to 17: . .. \ / : * ? " ' ` < > | { } [ ] 4037 4038**System API**: This is a system API. 4039 4040**System capability**: SystemCapability.FileManagement.PhotoAccessHelper.Core 4041 4042**Parameters** 4043 4044| Name | Type | Mandatory| Description | 4045| ------- | ------- | ---- | -------------------------- | 4046| context | [Context](../apis-ability-kit/js-apis-inner-application-context.md) | Yes | Context of the ability instance.| 4047| displayName | string | Yes | File name of the image or video to create. | 4048| options | [PhotoCreateOptions](#photocreateoptions) | No | Options for creating an image or video asset. | 4049 4050**Return value** 4051 4052| Type | Description | 4053| --------------------------------------- | ----------------- | 4054| [MediaAssetChangeRequest](#mediaassetchangerequest11) | **MediaAssetChangeRequest** created.| 4055 4056**Error codes** 4057 4058For details about the error codes, see [Universal Error Codes](../errorcode-universal.md) and [File Management Error Codes](../apis-core-file-kit/errorcode-filemanagement.md). 4059 4060| ID| Error Message| 4061| -------- | ---------------------------------------- | 4062| 202 | Called by non-system application. | 4063| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types; 3. Parameter verification failed. | 4064| 14000001 | Invalid display name. | 4065| 14000011 | System inner fail. | 4066 4067**Example** 4068 4069```ts 4070async function example() { 4071 console.info('createAssetRequestDemo'); 4072 try { 4073 let testFileName: string = 'testFile' + Date.now() + '.jpg'; 4074 let assetChangeRequest: photoAccessHelper.MediaAssetChangeRequest = photoAccessHelper.MediaAssetChangeRequest.createAssetRequest(context, testFileName); 4075 // Ensure that the asset specified by fileUri exists. 4076 let fileUri = 'file://com.example.temptest/data/storage/el2/base/haps/entry/files/test.jpg'; 4077 assetChangeRequest.addResource(photoAccessHelper.ResourceType.IMAGE_RESOURCE, fileUri); 4078 await phAccessHelper.applyChanges(assetChangeRequest); 4079 console.info('apply createAssetRequest successfully'); 4080 } catch (err) { 4081 console.error(`createAssetRequestDemo failed with error: ${err.code}, ${err.message}`); 4082 } 4083} 4084``` 4085 4086### setFavorite<sup>11+</sup> 4087 4088setFavorite(favoriteState: boolean): void 4089 4090Favorites or unfavorites this file. 4091 4092**System API**: This is a system API. 4093 4094**System capability**: SystemCapability.FileManagement.PhotoAccessHelper.Core 4095 4096**Parameters** 4097 4098| Name | Type | Mandatory | Description | 4099| ---------- | ------- | ---- | ---------------------------------- | 4100| favoriteState | boolean | Yes | Operation to perform. The value **true** means to favorite the file, and **false** means the opposite.| 4101 4102**Error codes** 4103 4104For details about the error codes, see [Universal Error Codes](../errorcode-universal.md) and [File Management Error Codes](../apis-core-file-kit/errorcode-filemanagement.md). 4105 4106| ID| Error Message| 4107| -------- | ---------------------------------------- | 4108| 202 | Called by non-system application. | 4109| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types; 3. Parameter verification failed. | 4110| 14000011 | System inner fail. | 4111 4112**Example** 4113 4114```ts 4115import { dataSharePredicates } from '@kit.ArkData'; 4116import { BusinessError } from '@kit.BasicServicesKit'; 4117 4118async function example() { 4119 console.info('setFavoriteDemo'); 4120 let predicates: dataSharePredicates.DataSharePredicates = new dataSharePredicates.DataSharePredicates(); 4121 let fetchOption: photoAccessHelper.FetchOptions = { 4122 fetchColumns: [], 4123 predicates: predicates 4124 }; 4125 let fetchResult: photoAccessHelper.FetchResult<photoAccessHelper.PhotoAsset> = await phAccessHelper.getAssets(fetchOption); 4126 let asset = await fetchResult.getFirstObject(); 4127 let assetChangeRequest: photoAccessHelper.MediaAssetChangeRequest = new photoAccessHelper.MediaAssetChangeRequest(asset); 4128 assetChangeRequest.setFavorite(true); 4129 phAccessHelper.applyChanges(assetChangeRequest).then(() => { 4130 console.info('apply setFavorite successfully'); 4131 }).catch((err: BusinessError) => { 4132 console.error(`apply setFavorite failed with error: ${err.code}, ${err.message}`); 4133 }); 4134} 4135``` 4136 4137### setHidden<sup>11+</sup> 4138 4139setHidden(hiddenState: boolean): void 4140 4141Hides this file. 4142 4143**System API**: This is a system API. 4144 4145**System capability**: SystemCapability.FileManagement.PhotoAccessHelper.Core 4146 4147**Parameters** 4148 4149| Name | Type | Mandatory | Description | 4150| ---------- | ------- | ---- | ---------------------------------- | 4151| hiddenState | boolean | Yes | Whether to hide the file. The value **true** means to hide the file; the value **false** means the opposite.| 4152 4153**Error codes** 4154 4155For details about the error codes, see [Universal Error Codes](../errorcode-universal.md) and [File Management Error Codes](../apis-core-file-kit/errorcode-filemanagement.md). 4156 4157| ID| Error Message| 4158| -------- | ---------------------------------------- | 4159| 202 | Called by non-system application. | 4160| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types; 3. Parameter verification failed. | 4161| 14000011 | System inner fail. | 4162 4163**Example** 4164 4165```ts 4166import { dataSharePredicates } from '@kit.ArkData'; 4167import { BusinessError } from '@kit.BasicServicesKit'; 4168 4169async function example() { 4170 console.info('setHiddenDemo'); 4171 let predicates: dataSharePredicates.DataSharePredicates = new dataSharePredicates.DataSharePredicates(); 4172 let fetchOption: photoAccessHelper.FetchOptions = { 4173 fetchColumns: [], 4174 predicates: predicates 4175 }; 4176 let fetchResult: photoAccessHelper.FetchResult<photoAccessHelper.PhotoAsset> = await phAccessHelper.getAssets(fetchOption); 4177 let asset = await fetchResult.getFirstObject(); 4178 let assetChangeRequest: photoAccessHelper.MediaAssetChangeRequest = new photoAccessHelper.MediaAssetChangeRequest(asset); 4179 assetChangeRequest.setHidden(true); 4180 phAccessHelper.applyChanges(assetChangeRequest).then(() => { 4181 console.info('apply setHidden successfully'); 4182 }).catch((err: BusinessError) => { 4183 console.error(`apply setHidden failed with error: ${err.code}, ${err.message}`); 4184 }); 4185} 4186``` 4187 4188### setUserComment<sup>11+</sup> 4189 4190setUserComment(userComment: string): void 4191 4192Sets the user comment information of this media asset. 4193 4194**System API**: This is a system API. 4195 4196**System capability**: SystemCapability.FileManagement.PhotoAccessHelper.Core 4197 4198**Parameters** 4199 4200| Name | Type | Mandatory | Description | 4201| ---------- | ------- | ---- | ---------------------------------- | 4202| userComment | string | Yes | Comment information to set, which cannot exceed 420 characters.| 4203 4204**Error codes** 4205 4206For details about the error codes, see [Universal Error Codes](../errorcode-universal.md) and [File Management Error Codes](../apis-core-file-kit/errorcode-filemanagement.md). 4207 4208| ID| Error Message| 4209| -------- | ---------------------------------------- | 4210| 202 | Called by non-system application. | 4211| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types; 3. Parameter verification failed. | 4212| 14000011 | System inner fail. | 4213 4214**Example** 4215 4216```ts 4217import { dataSharePredicates } from '@kit.ArkData'; 4218import { BusinessError } from '@kit.BasicServicesKit'; 4219 4220async function example() { 4221 console.info('setUserCommentDemo'); 4222 let predicates: dataSharePredicates.DataSharePredicates = new dataSharePredicates.DataSharePredicates(); 4223 let fetchOption: photoAccessHelper.FetchOptions = { 4224 fetchColumns: [], 4225 predicates: predicates 4226 }; 4227 let fetchResult: photoAccessHelper.FetchResult<photoAccessHelper.PhotoAsset> = await phAccessHelper.getAssets(fetchOption); 4228 let asset = await fetchResult.getFirstObject(); 4229 let assetChangeRequest: photoAccessHelper.MediaAssetChangeRequest = new photoAccessHelper.MediaAssetChangeRequest(asset); 4230 let userComment: string = 'test_set_user_comment'; 4231 assetChangeRequest.setUserComment(userComment); 4232 phAccessHelper.applyChanges(assetChangeRequest).then(() => { 4233 console.info('apply setUserComment successfully'); 4234 }).catch((err: BusinessError) => { 4235 console.error(`apply setUserComment failed with error: ${err.code}, ${err.message}`); 4236 }); 4237} 4238``` 4239 4240### setEditData<sup>11+</sup> 4241 4242setEditData(editData: MediaAssetEditData): void 4243 4244Saves the edited data of an asset. 4245 4246**System API**: This is a system API. 4247 4248**System capability**: SystemCapability.FileManagement.PhotoAccessHelper.Core 4249 4250**Parameters** 4251 4252| Name | Type | Mandatory | Description | 4253| ---------- | ------- | ---- | ---------------------------------- | 4254| editData | [MediaAssetEditData](#mediaasseteditdata11) | Yes | Edited data to save.| 4255 4256**Error codes** 4257 4258For details about the error codes, see [Universal Error Codes](../errorcode-universal.md) and [File Management Error Codes](../apis-core-file-kit/errorcode-filemanagement.md). 4259 4260| ID| Error Message| 4261| -------- | ---------------------------------------- | 4262| 202 | Called by non-system application. | 4263| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types; 3. Parameter verification failed. | 4264| 14000011 | System inner fail. | 4265 4266**Example** 4267 4268```ts 4269import { dataSharePredicates } from '@kit.ArkData'; 4270import { BusinessError } from '@kit.BasicServicesKit'; 4271 4272async function example() { 4273 console.info('setEditDataDemo'); 4274 let predicates: dataSharePredicates.DataSharePredicates = new dataSharePredicates.DataSharePredicates(); 4275 let fetchOption: photoAccessHelper.FetchOptions = { 4276 fetchColumns: [], 4277 predicates: predicates 4278 }; 4279 let fetchResult: photoAccessHelper.FetchResult<photoAccessHelper.PhotoAsset> = await phAccessHelper.getAssets(fetchOption); 4280 let asset = await fetchResult.getFirstObject(); 4281 let assetChangeRequest: photoAccessHelper.MediaAssetChangeRequest = new photoAccessHelper.MediaAssetChangeRequest(asset); 4282 4283 let assetEditData: photoAccessHelper.MediaAssetEditData = new photoAccessHelper.MediaAssetEditData('system', '1.0'); 4284 let fileUri = 'file://com.example.temptest/data/storage/el2/base/haps/entry/files/test.jpg'; 4285 assetChangeRequest.addResource(photoAccessHelper.ResourceType.IMAGE_RESOURCE, fileUri); 4286 assetEditData.data = '123456'; 4287 assetChangeRequest.setEditData(assetEditData); 4288 phAccessHelper.applyChanges(assetChangeRequest).then(() => { 4289 console.info('apply setEditData successfully'); 4290 }).catch((err: BusinessError) => { 4291 console.error(`apply setEditData failed with error: ${err.code}, ${err.message}`); 4292 }); 4293} 4294``` 4295 4296### addResource<sup>11+</sup> 4297 4298addResource(type: ResourceType, proxy: PhotoProxy): void 4299 4300Adds resources using **PhotoProxy** data. 4301 4302> **NOTE**<br>For the same asset change request, this API cannot be repeatedly called after resources are successfully added. 4303 4304**System API**: This is a system API available only for camera applications. 4305 4306**System capability**: SystemCapability.FileManagement.PhotoAccessHelper.Core 4307 4308**Parameters** 4309 4310| Name | Type | Mandatory| Description | 4311| ------- |---------------------------------| ---- |----------------------| 4312| type | [ResourceType](#resourcetype11) | Yes | Type of the resource to add. | 4313| proxy | [PhotoProxy](#photoproxy11) | Yes | PhotoProxy data of the resource to add.| 4314 4315**Error codes** 4316 4317For details about the error codes, see [Universal Error Codes](../errorcode-universal.md) and [File Management Error Codes](../apis-core-file-kit/errorcode-filemanagement.md). 4318 4319| ID | Error Message | 4320|----------|-----------------------------------| 4321| 202 | Called by non-system application. | 4322| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types; 3. Parameter verification failed. | 4323| 14000011 | System inner fail. | 4324| 14000016 | Operation Not Support. | 4325 4326**Example** 4327 4328```ts 4329class PhotoProxyImpl implements photoAccessHelper.PhotoProxy { 4330 // Implement PhotoProxy. 4331} 4332 4333async function example() { 4334 console.info('addResourceByPhotoProxyDemo'); 4335 try { 4336 let photoType: photoAccessHelper.PhotoType = photoAccessHelper.PhotoType.IMAGE; 4337 let extension: string = 'jpg'; 4338 let assetChangeRequest: photoAccessHelper.MediaAssetChangeRequest = photoAccessHelper.MediaAssetChangeRequest.createAssetRequest(context, photoType, extension); 4339 let photoProxy: PhotoProxyImpl = new PhotoProxyImpl(); 4340 assetChangeRequest.addResource(photoAccessHelper.ResourceType.IMAGE_RESOURCE, photoProxy); 4341 await phAccessHelper.applyChanges(assetChangeRequest); 4342 console.info('addResourceByPhotoProxy successfully'); 4343 } catch (err) { 4344 console.error(`addResourceByPhotoProxyDemo failed with error: ${err.code}, ${err.message}`); 4345 } 4346} 4347``` 4348 4349### setLocation<sup>11+</sup> 4350 4351setLocation(longitude: number, latitude: number): void 4352 4353Sets location information. 4354 4355**System API**: This is a system API. 4356 4357**System capability**: SystemCapability.FileManagement.PhotoAccessHelper.Core 4358 4359**Parameters** 4360 4361| Name | Type | Mandatory| Description | 4362| ------- |-------------| ---- |-------| 4363| longitude | number | Yes | Longitude.| 4364| latitude | number | Yes | Latitude. | 4365 4366**Error codes** 4367 4368For details about the error codes, see [Universal Error Codes](../errorcode-universal.md) and [File Management Error Codes](../apis-core-file-kit/errorcode-filemanagement.md). 4369 4370| ID| Error Message| 4371| -------- | ---------------------------------------- | 4372| 202 | Called by non-system application. | 4373| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types; 3. Parameter verification failed. | 4374| 14000011 | System inner fail. | 4375 4376**Example** 4377 4378```ts 4379import { dataSharePredicates } from '@kit.ArkData'; 4380import { BusinessError } from '@kit.BasicServicesKit'; 4381 4382async function example() { 4383 console.info('setLocationDemo'); 4384 let predicates: dataSharePredicates.DataSharePredicates = new dataSharePredicates.DataSharePredicates(); 4385 let fetchOption: photoAccessHelper.FetchOptions = { 4386 fetchColumns: [], 4387 predicates: predicates 4388 }; 4389 let fetchResult: photoAccessHelper.FetchResult<photoAccessHelper.PhotoAsset> = await phAccessHelper.getAssets(fetchOption); 4390 let asset = await fetchResult.getFirstObject(); 4391 let assetChangeRequest: photoAccessHelper.MediaAssetChangeRequest = new photoAccessHelper.MediaAssetChangeRequest(asset); 4392 assetChangeRequest.setLocation(120.52, 30.40); 4393 phAccessHelper.applyChanges(assetChangeRequest).then(() => { 4394 console.info('apply setLocation successfully'); 4395 }).catch((err: BusinessError) => { 4396 console.error(`apply setLocation failed with error: ${err.code}, ${err.message}`); 4397 }); 4398} 4399``` 4400 4401### setCameraShotKey<sup>12+</sup> 4402 4403setCameraShotKey(cameraShotKey: string): void 4404 4405Sets the Key for the Ultra Snapshot feature, which allows the camera to take photos or record videos with the screen off. 4406 4407**System API**: This is a system API. 4408 4409**System capability**: SystemCapability.FileManagement.PhotoAccessHelper.Core 4410 4411**Parameters** 4412 4413| Name | Type | Mandatory | Description | 4414| ---------- | ------- | ---- | ---------------------------------- | 4415| cameraShotKey | string | Yes | Key for the Ultra Snapshot feature.<br>This parameter is available only for the system camera, and the key value is defined by the system camera.| 4416 4417**Error codes** 4418 4419For details about the error codes, see [Universal Error Codes](../errorcode-universal.md) and [File Management Error Codes](../apis-core-file-kit/errorcode-filemanagement.md). 4420 4421| ID| Error Message| 4422| -------- | ---------------------------------------- | 4423| 202 | Called by non-system application. | 4424| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types; 3. Parameter verification failed. | 4425| 14000011 | System inner fail. | 4426 4427**Example** 4428 4429```ts 4430async function example(asset: photoAccessHelper.PhotoAsset) { 4431 console.info('setCameraShotKeyDemo'); 4432 try { 4433 let assetChangeRequest: photoAccessHelper.MediaAssetChangeRequest = new photoAccessHelper.MediaAssetChangeRequest(asset); 4434 let cameraShotKey: string = 'test_MediaAssetChangeRequest_setCameraShotKey'; 4435 assetChangeRequest.setCameraShotKey(cameraShotKey); 4436 await phAccessHelper.applyChanges(assetChangeRequest); 4437 console.info('apply setCameraShotKey successfully'); 4438 } catch (err) { 4439 console.error(`apply setCameraShotKey failed with error: ${err.code}, ${err.message}`); 4440 } 4441} 4442``` 4443 4444### setEffectMode<sup>12+</sup> 4445 4446setEffectMode(mode: MovingPhotoEffectMode): void 4447 4448Sets the effect of this moving photo. 4449 4450**System API**: This is a system API. 4451 4452**System capability**: SystemCapability.FileManagement.PhotoAccessHelper.Core 4453 4454**Parameters** 4455 4456| Name | Type | Mandatory | Description | 4457| ---------- | ------- | ---- | ---------------------------------- | 4458| mode | [MovingPhotoEffectMode](#movingphotoeffectmode12) | Yes | Effect to set.| 4459 4460**Error codes** 4461 4462For details about the error codes, see [Universal Error Codes](../errorcode-universal.md) and [File Management Error Codes](../apis-core-file-kit/errorcode-filemanagement.md). 4463 4464| ID| Error Message| 4465| -------- | ---------------------------------------- | 4466| 202 | Called by non-system application. | 4467| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types; 3. Parameter verification failed. | 4468| 14000011 | System inner fail. | 4469| 14000016 | Operation Not Support. | 4470 4471**Example** 4472 4473```ts 4474async function example(asset: photoAccessHelper.PhotoAsset) { 4475 console.info('setEffectModeDemo'); 4476 try { 4477 let assetChangeRequest: photoAccessHelper.MediaAssetChangeRequest = new photoAccessHelper.MediaAssetChangeRequest(asset); 4478 assetChangeRequest.setEffectMode(photoAccessHelper.MovingPhotoEffectMode.LONG_EXPOSURE); 4479 // Ensure that the asset specified by fileUri exists. 4480 let imageFileUri = 'file://com.example.temptest/data/storage/el2/base/haps/entry/files/long_exposure.jpg'; 4481 let videoFileUri = 'file://com.example.temptest/data/storage/el2/base/haps/entry/files/long_exposure.mp4'; 4482 assetChangeRequest.addResource(photoAccessHelper.ResourceType.IMAGE_RESOURCE, imageFileUri); 4483 assetChangeRequest.addResource(photoAccessHelper.ResourceType.VIDEO_RESOURCE, videoFileUri); 4484 await phAccessHelper.applyChanges(assetChangeRequest); 4485 console.info('apply setEffectMode successfully'); 4486 } catch (err) { 4487 console.error(`apply setEffectMode failed with error: ${err.code}, ${err.message}`); 4488 } 4489} 4490``` 4491 4492### setSupportedWatermarkType<sup>14+</sup> 4493 4494setSupportedWatermarkType(watermarkType: WatermarkType): void 4495 4496Sets the watermark type supported by photos. 4497 4498**System API**: This is a system API. 4499 4500**System capability**: SystemCapability.FileManagement.PhotoAccessHelper.Core 4501 4502**Parameters** 4503 4504| Name | Type | Mandatory | Description | 4505| ---------- | ------- | ---- | ---------------------------------- | 4506| watermarkType | [WatermarkType](#watermarktype14) | Yes | Watermark type to set. | 4507 4508**Error codes** 4509 4510For details about the error codes, see [Universal Error Codes](../errorcode-universal.md) and [File Management Error Codes](../apis-core-file-kit/errorcode-filemanagement.md). 4511 4512| ID| Error Message| 4513| -------- | ---------------------------------------- | 4514| 202 | Called by non-system application. | 4515| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types; 3. Parameter verification failed. | 4516| 14000011 | Internal system error. | 4517 4518**Example** 4519 4520```ts 4521import { dataSharePredicates } from '@kit.ArkData'; 4522import { photoAccessHelper } from '@kit.MediaLibraryKit';; 4523 4524const context = getContext(this); 4525let phAccessHelper = photoAccessHelper.getPhotoAccessHelper(context); 4526 4527async function example() { 4528 console.info('setSupportedWatermarkTypeDemo'); 4529 let predicates: dataSharePredicates.DataSharePredicates = new dataSharePredicates.DataSharePredicates(); 4530 let fetchOption: photoAccessHelper.FetchOptions = { 4531 fetchColumns: [], 4532 predicates: predicates 4533 }; 4534 try { 4535 let fetchResult: photoAccessHelper.FetchResult<photoAccessHelper.PhotoAsset> = await phAccessHelper.getAssets(fetchOption); 4536 let asset = await fetchResult.getFirstObject(); 4537 let assetChangeRequest: photoAccessHelper.MediaAssetChangeRequest = new photoAccessHelper.MediaAssetChangeRequest(asset); 4538 assetChangeRequest.setSupportedWatermarkType(photoAccessHelper.WatermarkType.BRAND_COMMON); 4539 await phAccessHelper.applyChanges(assetChangeRequest); 4540 console.info('apply setSupportedWatermarkType successfully'); 4541 } catch (err) { 4542 console.error(`apply setSupportedWatermarkType failed with error: ${err.code}, ${err.message}`); 4543 } 4544} 4545``` 4546 4547### deleteLocalAssetsPermanently<sup>18+</sup> 4548 4549static deleteLocalAssetsPermanently(context: Context, assets: Array\<PhotoAsset>): Promise<void> 4550 4551Permanently deletes photos or videos in batches. This API uses a promise to return the result. 4552 4553> **NOTE** 4554> 4555> This operation is irreversible. The file assets deleted cannot be restored. Exercise caution when performing this operation. 4556 4557**System API**: This is a system API. 4558 4559**System capability**: SystemCapability.FileManagement.PhotoAccessHelper.Core 4560 4561**Required permissions**: ohos.permission.WRITE_IMAGEVIDEO 4562 4563**Parameters** 4564 4565| Name | Type | Mandatory | Description | 4566| ---- | -------------- | ---- | ----- | 4567| context | [Context](../apis-ability-kit/js-apis-inner-application-context.md) | Yes | Context of the ability instance.| 4568| assets | Array\<[PhotoAsset](#photoasset)>| Yes | Array of images or videos to be permanently deleted.| 4569 4570**Return value** 4571 4572| Type | Description | 4573| ------------------- | ---------- | 4574| Promise<void> | Promise that returns no value.| 4575 4576**Error codes** 4577 4578For details about the error codes, see [Universal Error Codes](../errorcode-universal.md) and [File Management Error Codes](../apis-core-file-kit/errorcode-filemanagement.md). 4579 4580| ID| Error Message| 4581| -------- | ---------------------------------------- | 4582| 201 | Permission denied. | 4583| 202 | Called by non-system application. | 4584| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types; 3. Parameter verification failed. | 4585| 14000011 | Internal system error. 4586 4587**Example** 4588 4589```ts 4590import { dataSharePredicates } from '@kit.ArkData'; 4591import { BusinessError } from '@kit.BasicServicesKit'; 4592 4593struct Index { 4594 public context = getContext(this); 4595 public phAccessHelper = photoAccessHelper.getPhotoAccessHelper(this.context); 4596 4597 async function example() { 4598 console.info('deleteAssetsPermanentlyDemo'); 4599 let predicates: dataSharePredicates.DataSharePredicates = new dataSharePredicates.DataSharePredicates(); 4600 let fetchOptions: photoAccessHelper.FetchOptions = { 4601 fetchColumns: [], 4602 predicates: predicates 4603 }; 4604 try { 4605 let fetchResult: photoAccessHelper.FetchResult<photoAccessHelper.PhotoAsset> = await this.phAccessHelper.getAssets(fetchOptions); 4606 let photoAssetList: Array<photoAccessHelper.PhotoAsset> = await fetchResult.getAllObjects(); 4607 await photoAccessHelper.MediaAssetChangeRequest.deleteLocalAssetsPermanently(this.context, photoAssetList); 4608 } catch (err) { 4609 console.error(`deleteAssetsPermanentlyDemo failed with error: ${err.code}, ${err.message}`); 4610 } 4611 } 4612} 4613``` 4614 4615### setDisplayName<sup>18+</sup> 4616 4617setDisplayName(displayName: string): void 4618 4619Sets the file name (including the file name extension) of a media asset. 4620 4621**System API**: This is a system API. 4622 4623**System capability**: SystemCapability.FileManagement.PhotoAccessHelper.Core 4624 4625**Parameters** 4626 4627| Name | Type | Mandatory | Description | 4628| ---------- | ------- | ---- | ---------------------------------- | 4629| displayName | string | Yes | File name of the media asset (including the file name extension).<br>The name must meet the following requirements:<br>- The file name extension must be included.<br>- The file name (excluding the file name extension) cannot exceed 255 characters.<br>- The file name cannot contain invalid characters, such as \ / : * ?" < > \| | 4630 4631**Error codes** 4632 4633For details about the error codes, see [Universal Error Codes](../errorcode-universal.md) and [File Management Error Codes](../apis-core-file-kit/errorcode-filemanagement.md). 4634 4635| ID| Error Message| 4636| -------- | ---------------------------------------- | 4637| 202 | Called by non-system application. | 4638| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types; 3. Parameter verification failed. | 4639| 14000011 | Internal system error. | 4640 4641**Example** 4642 4643```ts 4644import { dataSharePredicates } from '@kit.ArkData'; 4645import { photoAccessHelper } from '@kit.MediaLibraryKit'; 4646 4647const context = getContext(this); 4648let phAccessHelper = photoAccessHelper.getPhotoAccessHelper(context); 4649 4650async function example() { 4651 console.info('setDisplayNameDemo'); 4652 let predicates: dataSharePredicates.DataSharePredicates = new dataSharePredicates.DataSharePredicates(); 4653 let fetchOption: photoAccessHelper.FetchOptions = { 4654 fetchColumns: [], 4655 predicates: predicates 4656 }; 4657 try { 4658 let fetchResult: photoAccessHelper.FetchResult<photoAccessHelper.PhotoAsset> = await phAccessHelper.getAssets(fetchOption); 4659 let asset = await fetchResult.getFirstObject(); 4660 let assetChangeRequest: photoAccessHelper.MediaAssetChangeRequest = new photoAccessHelper.MediaAssetChangeRequest(asset); 4661 let newDisplayName: string = 'newDisplayName.jpg'; 4662 assetChangeRequest.setDisplayName(newDisplayName); 4663 await phAccessHelper.applyChanges(assetChangeRequest); 4664 console.info('apply setDisplayName successfully'); 4665 } catch (err) { 4666 console.error(`apply setDisplayName failed with error: ${err.code}, ${err.message}`); 4667 } 4668} 4669``` 4670 4671## MediaAssetsChangeRequest<sup>11+</sup> 4672 4673Represents a request for changing multiple assets. 4674 4675**System API**: This is a system API. 4676 4677**System capability**: SystemCapability.FileManagement.PhotoAccessHelper.Core 4678 4679### constructor<sup>11+</sup> 4680 4681constructor(assets: Array<PhotoAsset>) 4682 4683Constructor. 4684 4685**System API**: This is a system API. 4686 4687**System capability**: SystemCapability.FileManagement.PhotoAccessHelper.Core 4688 4689**Parameters** 4690 4691| Name | Type | Mandatory| Description | 4692| -------- | ------------------------- | ---- | ---------- | 4693| assets | Array<[PhotoAsset](#photoasset)> | Yes | Assets to change.| 4694 4695**Error codes** 4696 4697For details about the error codes, see [Universal Error Codes](../errorcode-universal.md) and [File Management Error Codes](../apis-core-file-kit/errorcode-filemanagement.md). 4698 4699| ID| Error Message| 4700| -------- | ---------------------------------------- | 4701| 202 | Called by non-system application. | 4702| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types; 3. Parameter verification failed. | 4703| 14000011 | System inner fail. | 4704 4705**Example** 4706 4707```ts 4708import { dataSharePredicates } from '@kit.ArkData'; 4709 4710async function example() { 4711 console.info('MediaAssetsChangeRequest constructorDemo'); 4712 let predicates: dataSharePredicates.DataSharePredicates = new dataSharePredicates.DataSharePredicates(); 4713 let fetchOption: photoAccessHelper.FetchOptions = { 4714 fetchColumns: [], 4715 predicates: predicates 4716 }; 4717 let fetchResult: photoAccessHelper.FetchResult<photoAccessHelper.PhotoAsset> = await phAccessHelper.getAssets(fetchOption); 4718 let photoAssetList: Array<photoAccessHelper.PhotoAsset> = await fetchResult.getAllObjects(); 4719 let assetsChangeRequest: photoAccessHelper.MediaAssetsChangeRequest = new photoAccessHelper.MediaAssetsChangeRequest(photoAssetList); 4720} 4721``` 4722 4723### setFavorite<sup>11+</sup> 4724 4725setFavorite(favoriteState: boolean): void 4726 4727Favorites or unfavorites this file. 4728 4729**System API**: This is a system API. 4730 4731**System capability**: SystemCapability.FileManagement.PhotoAccessHelper.Core 4732 4733**Parameters** 4734 4735| Name | Type | Mandatory | Description | 4736| ---------- | ------- | ---- | ---------------------------------- | 4737| favoriteState | boolean | Yes | Operation to perform. The value **true** means to favorite the file, and **false** means the opposite.| 4738 4739**Error codes** 4740 4741For details about the error codes, see [Universal Error Codes](../errorcode-universal.md) and [File Management Error Codes](../apis-core-file-kit/errorcode-filemanagement.md). 4742 4743| ID| Error Message| 4744| -------- | ---------------------------------------- | 4745| 202 | Called by non-system application. | 4746| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types; 3. Parameter verification failed. | 4747| 14000011 | System inner fail. | 4748 4749**Example** 4750 4751```ts 4752import { dataSharePredicates } from '@kit.ArkData'; 4753import { BusinessError } from '@kit.BasicServicesKit'; 4754 4755async function example() { 4756 console.info('setFavoriteDemo'); 4757 let predicates: dataSharePredicates.DataSharePredicates = new dataSharePredicates.DataSharePredicates(); 4758 let fetchOption: photoAccessHelper.FetchOptions = { 4759 fetchColumns: [], 4760 predicates: predicates 4761 }; 4762 let fetchResult: photoAccessHelper.FetchResult<photoAccessHelper.PhotoAsset> = await phAccessHelper.getAssets(fetchOption); 4763 let photoAssetList: Array<photoAccessHelper.PhotoAsset> = await fetchResult.getAllObjects(); 4764 let assetsChangeRequest: photoAccessHelper.MediaAssetsChangeRequest = new photoAccessHelper.MediaAssetsChangeRequest(photoAssetList); 4765 assetsChangeRequest.setFavorite(true); 4766 phAccessHelper.applyChanges(assetsChangeRequest).then(() => { 4767 console.info('apply setFavorite successfully'); 4768 }).catch((err: BusinessError) => { 4769 console.error(`apply setFavorite failed with error: ${err.code}, ${err.message}`); 4770 }); 4771} 4772``` 4773 4774### setHidden<sup>11+</sup> 4775 4776setHidden(hiddenState: boolean): void 4777 4778Hides this file. 4779 4780**System API**: This is a system API. 4781 4782**System capability**: SystemCapability.FileManagement.PhotoAccessHelper.Core 4783 4784**Parameters** 4785 4786| Name | Type | Mandatory | Description | 4787| ---------- | ------- | ---- | ---------------------------------- | 4788| hiddenState | boolean | Yes | Whether to hide the file. The value **true** means to hide the file; the value **false** means the opposite.| 4789 4790**Error codes** 4791 4792For details about the error codes, see [Universal Error Codes](../errorcode-universal.md) and [File Management Error Codes](../apis-core-file-kit/errorcode-filemanagement.md). 4793 4794| ID| Error Message| 4795| -------- | ---------------------------------------- | 4796| 202 | Called by non-system application. | 4797| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types; 3. Parameter verification failed. | 4798| 14000011 | System inner fail. | 4799 4800**Example** 4801 4802```ts 4803import { dataSharePredicates } from '@kit.ArkData'; 4804import { BusinessError } from '@kit.BasicServicesKit'; 4805 4806async function example() { 4807 console.info('setHiddenDemo'); 4808 let predicates: dataSharePredicates.DataSharePredicates = new dataSharePredicates.DataSharePredicates(); 4809 let fetchOption: photoAccessHelper.FetchOptions = { 4810 fetchColumns: [], 4811 predicates: predicates 4812 }; 4813 let fetchResult: photoAccessHelper.FetchResult<photoAccessHelper.PhotoAsset> = await phAccessHelper.getAssets(fetchOption); 4814 let photoAssetList: Array<photoAccessHelper.PhotoAsset> = await fetchResult.getAllObjects(); 4815 let assetsChangeRequest: photoAccessHelper.MediaAssetsChangeRequest = new photoAccessHelper.MediaAssetsChangeRequest(photoAssetList); 4816 assetsChangeRequest.setHidden(true); 4817 phAccessHelper.applyChanges(assetsChangeRequest).then(() => { 4818 console.info('apply setHidden successfully'); 4819 }).catch((err: BusinessError) => { 4820 console.error(`apply setHidden failed with error: ${err.code}, ${err.message}`); 4821 }); 4822} 4823``` 4824 4825### setUserComment<sup>11+</sup> 4826 4827setUserComment(userComment: string): void 4828 4829Sets the user comment information of this media asset. 4830 4831**System API**: This is a system API. 4832 4833**System capability**: SystemCapability.FileManagement.PhotoAccessHelper.Core 4834 4835**Parameters** 4836 4837| Name | Type | Mandatory | Description | 4838| ---------- | ------- | ---- | ---------------------------------- | 4839| userComment | string | Yes | Comment information to set, which cannot exceed 420 characters.| 4840 4841**Error codes** 4842 4843For details about the error codes, see [Universal Error Codes](../errorcode-universal.md) and [File Management Error Codes](../apis-core-file-kit/errorcode-filemanagement.md). 4844 4845| ID| Error Message| 4846| -------- | ---------------------------------------- | 4847| 202 | Called by non-system application. | 4848| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types; 3. Parameter verification failed. | 4849| 14000011 | System inner fail. | 4850 4851**Example** 4852 4853```ts 4854import { dataSharePredicates } from '@kit.ArkData'; 4855import { BusinessError } from '@kit.BasicServicesKit'; 4856 4857async function example() { 4858 console.info('setUserCommentDemo'); 4859 let predicates: dataSharePredicates.DataSharePredicates = new dataSharePredicates.DataSharePredicates(); 4860 let fetchOption: photoAccessHelper.FetchOptions = { 4861 fetchColumns: [], 4862 predicates: predicates 4863 }; 4864 let fetchResult: photoAccessHelper.FetchResult<photoAccessHelper.PhotoAsset> = await phAccessHelper.getAssets(fetchOption); 4865 let photoAssetList: Array<photoAccessHelper.PhotoAsset> = await fetchResult.getAllObjects(); 4866 let assetsChangeRequest: photoAccessHelper.MediaAssetsChangeRequest = new photoAccessHelper.MediaAssetsChangeRequest(photoAssetList); 4867 assetsChangeRequest.setUserComment('test_set_user_comment'); 4868 phAccessHelper.applyChanges(assetsChangeRequest).then(() => { 4869 console.info('apply setUserComment successfully'); 4870 }).catch((err: BusinessError) => { 4871 console.error(`apply setUserComment failed with error: ${err.code}, ${err.message}`); 4872 }); 4873} 4874``` 4875 4876## MediaAlbumChangeRequest<sup>11+</sup> 4877 4878Provides APIs for managing the media album change request. 4879 4880**System capability**: SystemCapability.FileManagement.PhotoAccessHelper.Core 4881 4882### createAlbumRequest<sup>11+</sup> 4883 4884static createAlbumRequest(context: Context, name: string): MediaAlbumChangeRequest 4885 4886Creates a **MediaAlbumChangeRequest** instance. 4887 4888The album name must comply with the following specifications: 4889- The album name cannot exceed 255 characters. 4890- The album name cannot contain any of the following characters:<br>. .. \ / : * ? " ' ` < > | { } [ ] 4891- The album name is case-insensitive. 4892- Duplicate album names are not allowed. 4893 4894**System API**: This is a system API. 4895 4896**System capability**: SystemCapability.FileManagement.PhotoAccessHelper.Core 4897 4898**Parameters** 4899 4900| Name | Type | Mandatory| Description | 4901| ------- | ------- | ---- | -------------------------- | 4902| context | [Context](../apis-ability-kit/js-apis-inner-application-context.md) | Yes | Context of the ability instance.| 4903| name | string | Yes | Name of the album.| 4904 4905**Return value** 4906 4907| Type | Description | 4908| --------------------------------------- | ----------------- | 4909| [MediaAlbumChangeRequest](#mediaalbumchangerequest11) | **MediaAlbumChangeRequest** instance created.| 4910 4911**Error codes** 4912 4913For details about the error codes, see [Universal Error Codes](../errorcode-universal.md) and [File Management Error Codes](../apis-core-file-kit/errorcode-filemanagement.md). 4914 4915| ID| Error Message| 4916| -------- | ---------------------------------------- | 4917| 202 | Called by non-system application. | 4918| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types; 3. Parameter verification failed. | 4919| 14000011 | System inner fail. | 4920 4921**Example** 4922 4923```ts 4924async function example() { 4925 console.info('createAlbumRequestDemo'); 4926 try { 4927 let albumName: string = 'newAlbumName' + new Date().getTime(); 4928 let albumChangeRequest: photoAccessHelper.MediaAlbumChangeRequest = photoAccessHelper.MediaAlbumChangeRequest.createAlbumRequest(context, albumName); 4929 await phAccessHelper.applyChanges(albumChangeRequest); 4930 console.info('apply createAlbumRequest successfully'); 4931 } catch (err) { 4932 console.error(`createAlbumRequestDemo failed with error: ${err.code}, ${err.message}`); 4933 } 4934} 4935``` 4936 4937### deleteAlbums<sup>11+</sup> 4938 4939static deleteAlbums(context: Context, albums: Array<Album>): Promise<void> 4940 4941Deletes albums. This API uses a promise to return the result. 4942 4943Ensure that the albums to be deleted exist. Only user albums can be deleted. 4944 4945**System API**: This is a system API. 4946 4947**Required permissions**: ohos.permission.WRITE_IMAGEVIDEO 4948 4949**System capability**: SystemCapability.FileManagement.PhotoAccessHelper.Core 4950 4951**Parameters** 4952 4953| Name | Type | Mandatory| Description | 4954| ------- | ------- | ---- | -------------------------- | 4955| context | [Context](../apis-ability-kit/js-apis-inner-application-context.md) | Yes | Context of the ability instance.| 4956| albums | Array<[Album](#album)> | Yes | Albums to delete. | 4957 4958**Return value** 4959 4960| Type | Description | 4961| --------------------------------------- | ----------------- | 4962| Promise<void>| Promise that returns no value.| 4963 4964**Error codes** 4965 4966For details about the error codes, see [Universal Error Codes](../errorcode-universal.md) and [File Management Error Codes](../apis-core-file-kit/errorcode-filemanagement.md). 4967 4968| ID| Error Message| 4969| -------- | ---------------------------------------- | 4970| 201 | Permission denied. | 4971| 202 | Called by non-system application. | 4972| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types; 3. Parameter verification failed. | 4973| 14000011 | System inner fail. | 4974 4975**Example** 4976 4977```ts 4978import { dataSharePredicates } from '@kit.ArkData'; 4979 4980async function example() { 4981 console.info('deleteAlbumsDemo'); 4982 let predicates: dataSharePredicates.DataSharePredicates = new dataSharePredicates.DataSharePredicates(); 4983 let fetchOptions: photoAccessHelper.FetchOptions = { 4984 fetchColumns: [], 4985 predicates: predicates 4986 }; 4987 try { 4988 let fetchResult: photoAccessHelper.FetchResult<photoAccessHelper.Album> = await phAccessHelper.getAlbums(photoAccessHelper.AlbumType.USER, photoAccessHelper.AlbumSubtype.USER_GENERIC, fetchOptions); 4989 let album: photoAccessHelper.Album = await fetchResult.getFirstObject(); 4990 await photoAccessHelper.MediaAlbumChangeRequest.deleteAlbums(context, [album]); 4991 console.info('deleteAlbums successfully'); 4992 } catch (err) { 4993 console.error(`deleteAlbumsDemo failed with error: ${err.code}, ${err.message}`); 4994 } 4995} 4996``` 4997 4998### setCoverUri<sup>11+</sup> 4999 5000setCoverUri(coverUri: string): void 5001 5002Sets the album cover. 5003 5004**System API**: This is a system API. 5005 5006**System capability**: SystemCapability.FileManagement.PhotoAccessHelper.Core 5007 5008**Parameters** 5009 5010| Name | Type | Mandatory | Description | 5011| ---------- | ------- | ---- | ---------------------------------- | 5012| coverUri | string | Yes | URI of the file to be set as the album cover.| 5013 5014**Error codes** 5015 5016For details about the error codes, see [Universal Error Codes](../errorcode-universal.md) and [File Management Error Codes](../apis-core-file-kit/errorcode-filemanagement.md). 5017 5018| ID| Error Message| 5019| -------- | ---------------------------------------- | 5020| 202 | Called by non-system application. | 5021| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types; 3. Parameter verification failed. | 5022| 14000011 | System inner fail. | 5023 5024**Example** 5025 5026```ts 5027import { dataSharePredicates } from '@kit.ArkData'; 5028 5029async function example() { 5030 console.info('setCoverUriDemo'); 5031 let predicates: dataSharePredicates.DataSharePredicates = new dataSharePredicates.DataSharePredicates(); 5032 let fetchOptions: photoAccessHelper.FetchOptions = { 5033 fetchColumns: [], 5034 predicates: predicates 5035 }; 5036 try { 5037 let albumFetchResult: photoAccessHelper.FetchResult<photoAccessHelper.Album> = await phAccessHelper.getAlbums(photoAccessHelper.AlbumType.USER, photoAccessHelper.AlbumSubtype.USER_GENERIC); 5038 let album: photoAccessHelper.Album = await albumFetchResult.getFirstObject(); 5039 let fetchResult: photoAccessHelper.FetchResult<photoAccessHelper.PhotoAsset> = await album.getAssets(fetchOptions); 5040 let asset: photoAccessHelper.PhotoAsset = await fetchResult.getFirstObject(); 5041 5042 let albumChangeRequest: photoAccessHelper.MediaAlbumChangeRequest = new photoAccessHelper.MediaAlbumChangeRequest(album); 5043 albumChangeRequest.setCoverUri(asset.uri); 5044 await phAccessHelper.applyChanges(albumChangeRequest); 5045 console.info('setCoverUri successfully'); 5046 } catch (err) { 5047 console.error(`setCoverUriDemo failed with error: ${err.code}, ${err.message}`); 5048 } 5049} 5050``` 5051 5052### moveAssets<sup>11+</sup> 5053 5054moveAssets(assets: Array<PhotoAsset>, targetAlbum: Album): void 5055 5056Moves assets to another album. 5057 5058**System API**: This is a system API. 5059 5060**System capability**: SystemCapability.FileManagement.PhotoAccessHelper.Core 5061 5062**Parameters** 5063 5064| Name | Type | Mandatory | Description | 5065| ---------- | ------- | ---- | ---------------------------------- | 5066| assets | Array<[PhotoAsset](#photoasset)> | Yes | Assets to move.| 5067| targetAlbum | Album | Yes | Album to which the assets are to be moved.| 5068 5069**Error codes** 5070 5071For details about the error codes, see [Universal Error Codes](../errorcode-universal.md) and [File Management Error Codes](../apis-core-file-kit/errorcode-filemanagement.md). 5072 5073| ID| Error Message| 5074| -------- | ---------------------------------------- | 5075| 202 | Called by non-system application. | 5076| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types; 3. Parameter verification failed. | 5077| 14000011 | System inner fail. | 5078| 14000016 | Operation Not Support. | 5079 5080**Example** 5081 5082```ts 5083import { dataSharePredicates } from '@kit.ArkData'; 5084 5085async function example() { 5086 console.info('moveAssetsDemo'); 5087 let predicates: dataSharePredicates.DataSharePredicates = new dataSharePredicates.DataSharePredicates(); 5088 let fetchOptions: photoAccessHelper.FetchOptions = { 5089 fetchColumns: [], 5090 predicates: predicates 5091 }; 5092 try { 5093 let albumFetchResult: photoAccessHelper.FetchResult<photoAccessHelper.Album> = await phAccessHelper.getAlbums(photoAccessHelper.AlbumType.USER, photoAccessHelper.AlbumSubtype.USER_GENERIC); 5094 let album: photoAccessHelper.Album = await albumFetchResult.getFirstObject(); 5095 let fetchResult: photoAccessHelper.FetchResult<photoAccessHelper.PhotoAsset> = await album.getAssets(fetchOptions); 5096 let asset: photoAccessHelper.PhotoAsset = await fetchResult.getFirstObject(); 5097 5098 if (albumFetchResult.isAfterLast()) { 5099 console.error('lack of album to be moved into'); 5100 return; 5101 } 5102 let nextAlbum: photoAccessHelper.Album = await albumFetchResult.getNextObject(); 5103 let albumChangeRequest: photoAccessHelper.MediaAlbumChangeRequest = new photoAccessHelper.MediaAlbumChangeRequest(album); 5104 albumChangeRequest.moveAssets([asset], nextAlbum); 5105 await phAccessHelper.applyChanges(albumChangeRequest); 5106 console.info('moveAssets successfully'); 5107 } catch (err) { 5108 console.error(`moveAssetsDemo failed with error: ${err.code}, ${err.message}`); 5109 } 5110} 5111``` 5112 5113### recoverAssets<sup>11+</sup> 5114 5115recoverAssets(assets: Array<PhotoAsset>): void 5116 5117Recovers assets from the trash. 5118 5119**System API**: This is a system API. 5120 5121**System capability**: SystemCapability.FileManagement.PhotoAccessHelper.Core 5122 5123**Parameters** 5124 5125| Name | Type | Mandatory | Description | 5126| ---------- | ------- | ---- | ---------------------------------- | 5127| assets | Array<[PhotoAsset](#photoasset)> | Yes | Assets to recover.| 5128 5129**Error codes** 5130 5131For details about the error codes, see [Universal Error Codes](../errorcode-universal.md) and [File Management Error Codes](../apis-core-file-kit/errorcode-filemanagement.md). 5132 5133| ID| Error Message| 5134| -------- | ---------------------------------------- | 5135| 202 | Called by non-system application. | 5136| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types; 3. Parameter verification failed. | 5137| 14000011 | System inner fail. | 5138| 14000016 | Operation Not Support. | 5139 5140**Example** 5141 5142```ts 5143import { dataSharePredicates } from '@kit.ArkData'; 5144 5145async function example() { 5146 console.info('recoverAssetsDemo'); 5147 let predicates: dataSharePredicates.DataSharePredicates = new dataSharePredicates.DataSharePredicates(); 5148 let fetchOptions: photoAccessHelper.FetchOptions = { 5149 fetchColumns: [], 5150 predicates: predicates 5151 }; 5152 try { 5153 let albumFetchResult: photoAccessHelper.FetchResult<photoAccessHelper.Album> = await phAccessHelper.getAlbums(photoAccessHelper.AlbumType.SYSTEM, photoAccessHelper.AlbumSubtype.TRASH); 5154 let album: photoAccessHelper.Album = await albumFetchResult.getFirstObject(); 5155 let fetchResult: photoAccessHelper.FetchResult<photoAccessHelper.PhotoAsset> = await album.getAssets(fetchOptions); 5156 let asset: photoAccessHelper.PhotoAsset = await fetchResult.getFirstObject(); 5157 5158 let albumChangeRequest: photoAccessHelper.MediaAlbumChangeRequest = new photoAccessHelper.MediaAlbumChangeRequest(album); 5159 albumChangeRequest.recoverAssets([asset]); 5160 await phAccessHelper.applyChanges(albumChangeRequest); 5161 console.info('recoverAssets successfully'); 5162 } catch (err) { 5163 console.error(`recoverAssetsDemo failed with error: ${err.code}, ${err.message}`); 5164 } 5165} 5166``` 5167 5168### deleteAssets<sup>11+</sup> 5169 5170deleteAssets(assets: Array<PhotoAsset>): void 5171 5172Permanently deletes assets from the trash. 5173 5174**NOTE**<br>This operation is irreversible. The file assets deleted cannot be restored. Exercise caution when performing this operation. 5175 5176**System API**: This is a system API. 5177 5178**System capability**: SystemCapability.FileManagement.PhotoAccessHelper.Core 5179 5180**Parameters** 5181 5182| Name | Type | Mandatory | Description | 5183| ---------- | ------- | ---- | ---------------------------------- | 5184| assets | Array<[PhotoAsset](#photoasset)> | Yes | Assets to be permanently deleted.| 5185 5186**Error codes** 5187 5188For details about the error codes, see [Universal Error Codes](../errorcode-universal.md) and [File Management Error Codes](../apis-core-file-kit/errorcode-filemanagement.md). 5189 5190| ID| Error Message| 5191| -------- | ---------------------------------------- | 5192| 202 | Called by non-system application. | 5193| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types; 3. Parameter verification failed. | 5194| 14000011 | System inner fail. | 5195| 14000016 | Operation Not Support. | 5196 5197**Example** 5198 5199```ts 5200import { dataSharePredicates } from '@kit.ArkData'; 5201 5202async function example() { 5203 console.info('deleteAssetsPermanentlyDemo'); 5204 let predicates: dataSharePredicates.DataSharePredicates = new dataSharePredicates.DataSharePredicates(); 5205 let fetchOptions: photoAccessHelper.FetchOptions = { 5206 fetchColumns: [], 5207 predicates: predicates 5208 }; 5209 try { 5210 let albumFetchResult: photoAccessHelper.FetchResult<photoAccessHelper.Album> = await phAccessHelper.getAlbums(photoAccessHelper.AlbumType.SYSTEM, photoAccessHelper.AlbumSubtype.TRASH); 5211 let album: photoAccessHelper.Album = await albumFetchResult.getFirstObject(); 5212 let fetchResult: photoAccessHelper.FetchResult<photoAccessHelper.PhotoAsset> = await album.getAssets(fetchOptions); 5213 let asset: photoAccessHelper.PhotoAsset = await fetchResult.getFirstObject(); 5214 5215 let albumChangeRequest: photoAccessHelper.MediaAlbumChangeRequest = new photoAccessHelper.MediaAlbumChangeRequest(album); 5216 albumChangeRequest.deleteAssets([asset]); 5217 await phAccessHelper.applyChanges(albumChangeRequest); 5218 console.info('succeed to deleteAssets permanently'); 5219 } catch (err) { 5220 console.error(`deleteAssetsPermanentlyDemo failed with error: ${err.code}, ${err.message}`); 5221 } 5222} 5223``` 5224 5225### setDisplayLevel<sup>11+</sup> 5226 5227setDisplayLevel(displayLevel: number): void 5228 5229Sets the display level of the portrait album. 5230 5231**System API**: This is a system API. 5232 5233**System capability**: SystemCapability.FileManagement.PhotoAccessHelper.Core 5234 5235**Parameters** 5236 5237| Name | Type | Mandatory | Description | 5238| ---------- | ------- | ---- | ---------------------------------- | 5239| displayLevel | number | Yes | Display level to set.<br>The options are as follows:<br>**0**: unfavorite the portrait album.<br>**1**: set the portrait album as the first to display.<br>**2**: do not display the portrait album as the first one.<br>**3**: favorite the portrait album.| 5240 5241**Error codes** 5242 5243For details about the error codes, see [Universal Error Codes](../errorcode-universal.md) and [File Management Error Codes](../apis-core-file-kit/errorcode-filemanagement.md). 5244 5245| ID| Error Message| 5246| -------- | ---------------------------------------- | 5247| 202 | Called by non-system application. | 5248| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types; 3. Parameter verification failed. | 5249| 14000011 | System inner fail. | 5250 5251**Example** 5252 5253``` ts 5254import { dataSharePredicates } from '@kit.ArkData'; 5255 5256async function example() { 5257 try { 5258 console.info('setDisplayLevel Example') 5259 let predicates: dataSharePredicates.DataSharePredicates = new dataSharePredicates.DataSharePredicates(); 5260 predicates.equalTo('user_display_level', 2); 5261 let fetchOptions: photoAccessHelper.FetchOptions = { 5262 fetchColumns: [], 5263 predicates: predicates 5264 }; 5265 let fetchResult: photoAccessHelper.FetchResult<photoAccessHelper.Album> = await phAccessHelper.getAlbums(photoAccessHelper.AlbumType.SMART, photoAccessHelper.AlbumSubtype.PORTRAIT, fetchOptions); 5266 let album: photoAccessHelper.Album = await fetchResult.getFirstObject(); 5267 let changeRequest: photoAccessHelper.MediaAlbumChangeRequest = new photoAccessHelper.MediaAlbumChangeRequest(album); 5268 changeRequest.setDisplayLevel(1); 5269 await phAccessHelper.applyChanges(changeRequest); 5270 } catch (err) { 5271 console.error(`setDisplayLevel failed with error: ${err.code}, ${err.message}`); 5272 } 5273} 5274``` 5275 5276### setIsMe<sup>11+</sup> 5277 5278setIsMe(): void 5279 5280Sets the relationship between people in the portrait album to **Me**. 5281 5282**System API**: This is a system API. 5283 5284**System capability**: SystemCapability.FileManagement.PhotoAccessHelper.Core 5285 5286**Error codes** 5287 5288For details about the error codes, see [Universal Error Codes](../errorcode-universal.md) and [File Management Error Codes](../apis-core-file-kit/errorcode-filemanagement.md). 5289 5290| ID| Error Message| 5291| -------- | ---------------------------------------- | 5292| 202 | Called by non-system application. | 5293| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types. | 5294| 14000011 | System inner fail. | 5295 5296**Example** 5297 5298``` ts 5299import { dataSharePredicates } from '@kit.ArkData'; 5300 5301async function example() { 5302 try { 5303 console.info('setIsMe Example') 5304 let predicates: dataSharePredicates.DataSharePredicates = new dataSharePredicates.DataSharePredicates(); 5305 predicates.equalTo('user_display_level', 2); 5306 let fetchOptions: photoAccessHelper.FetchOptions = { 5307 fetchColumns: [], 5308 predicates: predicates 5309 }; 5310 let fetchResult: photoAccessHelper.FetchResult<photoAccessHelper.Album> = await phAccessHelper.getAlbums(photoAccessHelper.AlbumType.SMART, photoAccessHelper.AlbumSubtype.PORTRAIT, fetchOptions); 5311 let album: photoAccessHelper.Album = await fetchResult.getFirstObject(); 5312 let changeRequest: photoAccessHelper.MediaAlbumChangeRequest = new photoAccessHelper.MediaAlbumChangeRequest(album); 5313 changeRequest.setIsMe(); 5314 await phAccessHelper.applyChanges(changeRequest); 5315 } catch (err) { 5316 console.error(`setIsMe failed with error: ${err.code}, ${err.message}`); 5317 } 5318} 5319``` 5320 5321### dismissAssets<sup>11+</sup> 5322 5323dismissAssets(assets: Array<PhotoAsset>): void 5324 5325Removes assets from this portrait album or group photo album. 5326 5327**System API**: This is a system API. 5328 5329**System capability**: SystemCapability.FileManagement.PhotoAccessHelper.Core 5330 5331**Parameters** 5332 5333| Name | Type | Mandatory | Description | 5334| ---------- | ------- | ---- | ---------------------------------- | 5335| assets | Array<PhotoAsset> | Yes | Assets to remove.| 5336 5337**Error codes** 5338 5339For details about the error codes, see [Universal Error Codes](../errorcode-universal.md) and [File Management Error Codes](../apis-core-file-kit/errorcode-filemanagement.md). 5340 5341| ID| Error Message| 5342| -------- | ---------------------------------------- | 5343| 202 | Called by non-system application. | 5344| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types; 3. Parameter verification failed. | 5345| 14000011 | System inner fail. | 5346| 14000016 | Operation Not support. | 5347 5348**Example** 5349 5350``` ts 5351import { dataSharePredicates } from '@kit.ArkData'; 5352 5353async function example() { 5354 try { 5355 console.info('dismissAssets Example') 5356 let predicates: dataSharePredicates.DataSharePredicates = new dataSharePredicates.DataSharePredicates(); 5357 predicates.equalTo('user_display_level', 2); 5358 let fetchOptions: photoAccessHelper.FetchOptions = { 5359 fetchColumns: [], 5360 predicates: predicates 5361 }; 5362 let fetchResult: photoAccessHelper.FetchResult<photoAccessHelper.Album> = await phAccessHelper.getAlbums(photoAccessHelper.AlbumType.SMART, photoAccessHelper.AlbumSubtype.PORTRAIT, fetchOptions); 5363 let album: photoAccessHelper.Album = await fetchResult.getFirstObject(); 5364 5365 let predicatesAsset: dataSharePredicates.DataSharePredicates = new dataSharePredicates.DataSharePredicates(); 5366 let assetFetchOptions: photoAccessHelper.FetchOptions = { 5367 fetchColumns: [], 5368 predicates: predicatesAsset 5369 }; 5370 let assetFetchResult: photoAccessHelper.FetchResult<photoAccessHelper.PhotoAsset> = await phAccessHelper.getAssets(assetFetchOptions); 5371 let asset: photoAccessHelper.PhotoAsset = await assetFetchResult.getFirstObject(); 5372 5373 let changeRequest: photoAccessHelper.MediaAlbumChangeRequest = new photoAccessHelper.MediaAlbumChangeRequest(album); 5374 changeRequest.dismissAssets([asset]); 5375 await phAccessHelper.applyChanges(changeRequest); 5376 } catch (err) { 5377 console.error(`dismissAssets failed with error: ${err.code}, ${err.message}`); 5378 } 5379} 5380``` 5381 5382### mergeAlbum<sup>11+</sup> 5383 5384mergeAlbum(target: Album): void 5385 5386Merges two portrait albums. 5387 5388**System API**: This is a system API. 5389 5390**System capability**: SystemCapability.FileManagement.PhotoAccessHelper.Core 5391 5392**Parameters** 5393 5394| Name | Type | Mandatory | Description | 5395| ---------- | ------- | ---- | ---------------------------------- | 5396| target | [Album](#album) | Yes | Album generated after the merge. The album must be renamed.| 5397 5398**Error codes** 5399 5400For details about the error codes, see [Universal Error Codes](../errorcode-universal.md) and [File Management Error Codes](../apis-core-file-kit/errorcode-filemanagement.md). 5401 5402| ID| Error Message| 5403| -------- | ---------------------------------------- | 5404| 202 | Called by non-system application. | 5405| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types; 3. Parameter verification failed. | 5406| 14000011 | System inner fail. | 5407| 14000016 | Operation Not support. | 5408 5409**Example** 5410 5411``` ts 5412import { dataSharePredicates } from '@kit.ArkData'; 5413 5414async function example() { 5415 try { 5416 console.info('mergeAlbum Example') 5417 let predicates: dataSharePredicates.DataSharePredicates = new dataSharePredicates.DataSharePredicates(); 5418 predicates.equalTo('user_display_level', 2); 5419 let fetchOptions: photoAccessHelper.FetchOptions = { 5420 fetchColumns: [], 5421 predicates: predicates 5422 }; 5423 let fetchResult: photoAccessHelper.FetchResult<photoAccessHelper.Album> = await phAccessHelper.getAlbums(photoAccessHelper.AlbumType.SMART, photoAccessHelper.AlbumSubtype.PORTRAIT, fetchOptions); 5424 let album: photoAccessHelper.Album = await fetchResult.getFirstObject(); 5425 if (fetchResult.isAfterLast()) { 5426 console.error('lack of album to merge'); 5427 return; 5428 } 5429 let target: photoAccessHelper.Album = await fetchResult.getNextObject(); 5430 5431 let changeRequest: photoAccessHelper.MediaAlbumChangeRequest = new photoAccessHelper.MediaAlbumChangeRequest(album); 5432 changeRequest.mergeAlbum(target); 5433 changeRequest.setAlbumName("testName"); 5434 await phAccessHelper.applyChanges(changeRequest); 5435 } catch (err) { 5436 console.error(`mergeAlbum failed with error: ${err.code}, ${err.message}`); 5437 } 5438} 5439``` 5440 5441### placeBefore<sup>11+</sup> 5442 5443placeBefore(album: Album): void; 5444 5445Places this album before an album. 5446 5447**System API**: This is a system API. 5448 5449**System capability**: SystemCapability.FileManagement.PhotoAccessHelper.Core 5450 5451**Parameters** 5452 5453| Name | Type | Mandatory | Description | 5454| ---------- | ------- | ---- | ---------------------------------- | 5455| album | [Album](#album) | Yes | Target album. To place this album to the end, set **album** to null.| 5456 5457**Error codes** 5458 5459For details about the error codes, see [Universal Error Codes](../errorcode-universal.md) and [File Management Error Codes](../apis-core-file-kit/errorcode-filemanagement.md). 5460 5461| ID| Error Message| 5462| -------- | ---------------------------------------- | 5463| 202 | Called by non-system application. | 5464| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types; 3. Parameter verification failed. | 5465| 14000011 | System inner fail. | 5466 5467**Example** 5468 5469```ts 5470async function example() { 5471 console.info('placeBeforeDemo'); 5472 try { 5473 let albumFetchResult: photoAccessHelper.FetchResult<photoAccessHelper.Album> = await phAccessHelper.getAlbums(photoAccessHelper.AlbumType.USER, photoAccessHelper.AlbumSubtype.USER_GENERIC); 5474 let firstAlbum: photoAccessHelper.Album = await albumFetchResult.getFirstObject(); 5475 if (albumFetchResult.isAfterLast()) { 5476 console.error('lack of album to place before'); 5477 return; 5478 } 5479 let secondAlbum: photoAccessHelper.Album = await albumFetchResult.getNextObject(); 5480 let albumChangeRequest: photoAccessHelper.MediaAlbumChangeRequest = new photoAccessHelper.MediaAlbumChangeRequest(secondAlbum); 5481 albumChangeRequest.placeBefore(firstAlbum); 5482 await phAccessHelper.applyChanges(albumChangeRequest); 5483 console.info('placeBefore successfully'); 5484 } catch (err) { 5485 console.error(`placeBeforeDemo failed with error: ${err.code}, ${err.message}`); 5486 } 5487} 5488``` 5489 5490### dismiss<sup>13+</sup> 5491 5492dismiss(): void 5493 5494Removes this group photo album. 5495 5496**System API**: This is a system API. 5497 5498**System capability**: SystemCapability.FileManagement.PhotoAccessHelper.Core 5499 5500**Error codes** 5501 5502For details about the error codes, see [Universal Error Codes](../errorcode-universal.md) and [File Management Error Codes](../apis-core-file-kit/errorcode-filemanagement.md). 5503 5504| ID | Error Message | 5505| :------- | :-------------------------------- | 5506| 202 | Called by non-system application. | 5507| 401 | Parameter error. Possible causes: Incorrect parameter types. | 5508| 14000011 | System inner fail. | 5509 5510**Example** 5511 5512```ts 5513import { dataSharePredicates } from '@kit.ArkData'; 5514 5515async function example() { 5516 console.info('dismissDemo'); 5517 try { 5518 let albumFetchResult: photoAccessHelper.FetchResult<photoAccessHelper.Album> = await phAccessHelper.getAlbums(photoAccessHelper.AlbumType.SMART, photoAccessHelper.AlbumSubtype.GROUP_PHOTO); 5519 let album: photoAccessHelper.Album = await albumFetchResult.getFirstObject(); 5520 5521 let albumChangeRequest: photoAccessHelper.MediaAlbumChangeRequest = new photoAccessHelper.MediaAlbumChangeRequest(album); 5522 albumChangeRequest.dismiss(); 5523 await phAccessHelper.applyChanges(albumChangeRequest); 5524 console.info('dismiss successfully'); 5525 } catch (err) { 5526 console.error(`dismissDemo failed with error: ${err.code}, ${err.message}`); 5527 } 5528} 5529``` 5530 5531## HighlightAlbum<sup>12+</sup> 5532 5533Provides APIs for managing the **Highlights** album, which is an automatically generated collection of memorable photos or videos. 5534 5535**System API**: This is a system API. 5536 5537**System capability**: SystemCapability.FileManagement.PhotoAccessHelper.Core 5538 5539### constructor<sup>12+</sup> 5540 5541constructor(album: Album) 5542 5543A constructor used to create a **Highlights** album instance. 5544 5545**System API**: This is a system API. 5546 5547**System capability**: SystemCapability.FileManagement.PhotoAccessHelper.Core 5548 5549**Parameters** 5550 5551| Name | Type | Mandatory| Description | 5552| -------- | ------------------------- | ---- | ---------- | 5553| album | [Album](#album) | Yes | **Highlights** album to create.| 5554 5555**Error codes** 5556 5557For details about the error codes, see [Universal Error Codes](../errorcode-universal.md) and [File Management Error Codes](../apis-core-file-kit/errorcode-filemanagement.md). 5558 5559| ID| Error Message| 5560| -------- | ---------------------------------------- | 5561| 202 | Called by non-system application. | 5562| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types; 3. Parameter verification failed. | 5563| 14000011 | Internal system error. | 5564 5565**Example** 5566 5567```ts 5568import { dataSharePredicates } from '@kit.ArkData'; 5569 5570async function example() { 5571 console.info('HighlightAlbum constructorDemo'); 5572 let predicates: dataSharePredicates.DataSharePredicates = new dataSharePredicates.DataSharePredicates(); 5573 let fetchOption: photoAccessHelper.FetchOptions = { 5574 fetchColumns: [], 5575 predicates: predicates 5576 }; 5577 let albumFetchResult: photoAccessHelper.FetchResult<photoAccessHelper.Album> = await photoAccessHelper.getAlbums( 5578 photoAccessHelper.AlbumType.SMART, photoAccessHelper.AlbumSubtype.HIGHLIGHT, fetchOption); 5579 let album: photoAccessHelper.Album = await albumFetchResult.getFirstObject(); 5580 let highlightAlbum: photoAccessHelper.HighlightAlbum = new photoAccessHelper.HighlightAlbum(album); 5581 albumFetchResult.close(); 5582} 5583``` 5584 5585### getHighlightAlbumInfo<sup>12+</sup> 5586 5587getHighlightAlbumInfo(type: HighlightAlbumInfoType): Promise<string> 5588 5589Obtains specific information about the **Highlights** album. 5590 5591**System API**: This is a system API. 5592 5593**Required permissions**: ohos.permission.READ\_IMAGEVIDEO 5594 5595**System capability**: SystemCapability.FileManagement.PhotoAccessHelper.Core 5596 5597**Parameters** 5598 5599| Name | Type | Mandatory | Description | 5600| ---------- | ------- | ---- | ---------------------------------- | 5601| type | [HighlightAlbumInfoType](#highlightalbuminfotype12) | Yes | Type of the album information to obtain.| 5602 5603**Error codes** 5604 5605For details about the error codes, see [Universal Error Codes](../errorcode-universal.md) and [File Management Error Codes](../apis-core-file-kit/errorcode-filemanagement.md). 5606 5607| ID | Error Message | 5608| :------- | :-------------------------------- | 5609| 201 | Permission denied. | 5610| 202 | Called by non-system application. | 5611| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types; 3. Parameter verification failed. | 5612| 14000011 | Internal system error. | 5613 5614**Example** 5615 5616```ts 5617import { dataSharePredicates } from '@kit.ArkData'; 5618 5619async function example() { 5620 try { 5621 console.info('getHighlightAlbumInfoDemo') 5622 let fetchOptions: photoAccessHelper.FetchOptions = { 5623 fetchColumns: [], 5624 predicates: new dataSharePredicates.DataSharePredicates() 5625 } 5626 let albumFetchResult: photoAccessHelper.FetchResult<photoAccessHelper.Album> = await photoAccessHelper.getAlbums( 5627 photoAccessHelper.AlbumType.SMART, photoAccessHelper.AlbumSubtype.HIGHLIGHT, fetchOption); 5628 let album: photoAccessHelper.Album = await albumFetchResult.getFirstObject(); 5629 if (album != undefined) { 5630 let highlightAlbum: photoAccessHelper.HighlightAlbum = new photoAccessHelper.HighlightAlbum(album); 5631 let coverInfo: string = await highlightAlbum.getHighlightAlbumInfo( 5632 photoAccessHelper.HighlightAlbumInfoType.COVER_INFO); 5633 console.info('get cover info result: ' + JSON.stringify(coverInfo)); 5634 } 5635 5636 albumFetchResult.close(); 5637 } catch (err) { 5638 console.error(`getHighlightAlbumInfoDemofailed with error: ${err.code}, ${err.message}`); 5639 } 5640} 5641``` 5642 5643### getHighlightResource<sup>12+</sup> 5644 5645getHighlightResource(resourceUri: string): Promise<ArrayBuffer> 5646 5647Obtains the ArrayBuffer for caching the specified asset. 5648 5649**System API**: This is a system API. 5650 5651**Required permissions**: ohos.permission.READ\_IMAGEVIDEO 5652 5653**System capability**: SystemCapability.FileManagement.PhotoAccessHelper.Core 5654 5655**Parameters** 5656 5657| Name | Type | Mandatory | Description | 5658| ---------- | ------- | ---- | ---------------------------------- | 5659| resourceUri | string | Yes | URI of the asset to cache.| 5660 5661**Error codes** 5662 5663For details about the error codes, see [Universal Error Codes](../errorcode-universal.md) and [File Management Error Codes](../apis-core-file-kit/errorcode-filemanagement.md). 5664 5665| ID | Error Message | 5666| :------- | :-------------------------------- | 5667| 201 | Permission denied. | 5668| 202 | Called by non-system application. | 5669| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types; 3. Parameter verification failed. | 5670| 14000011 | Internal system error. | 5671 5672**Example** 5673 5674```ts 5675import { dataSharePredicates } from '@kit.ArkData'; 5676 5677async function example() { 5678 try { 5679 console.info('getHighlightResourceDemo') 5680 let fetchOptions: photoAccessHelper.FetchOptions = { 5681 fetchColumns: [], 5682 predicates: new dataSharePredicates.DataSharePredicates() 5683 } 5684 let albumFetchResult: photoAccessHelper.FetchResult<photoAccessHelper.Album> = await photoAccessHelper.getAlbums( 5685 photoAccessHelper.AlbumType.SMART, photoAccessHelper.AlbumSubtype.HIGHLIGHT, fetchOption); 5686 let album: photoAccessHelper.Album = await albumFetchResult.getFirstObject(); 5687 if (album != undefined) { 5688 let highlightAlbum: photoAccessHelper.HighlightAlbum = new photoAccessHelper.HighlightAlbum(album); 5689 let uri: string = 'file://media/highlight/cover/10/1_1/background.png?oper=highlight' 5690 let arrayBuffer: ArrayBuffer = await highlightAlbum.getHighlightResource(uri); 5691 } 5692 albumFetchResult.close(); 5693 } catch (err) { 5694 console.error(`getHighlightResourceDemofailed with error: ${err.code}, ${err.message}`); 5695 } 5696} 5697``` 5698 5699### setHighlightUserActionData<sup>12+</sup> 5700 5701setHighlightUserActionData(type: HighlightUserActionType, actionData: number): Promise<void> 5702 5703Sets the user behavior data for the **Highlights** album. 5704 5705**System API**: This is a system API. 5706 5707**Required permissions**: ohos.permission.WRITE\_IMAGEVIDEO 5708 5709**System capability**: SystemCapability.FileManagement.PhotoAccessHelper.Core 5710 5711**Parameters** 5712 5713| Name | Type | Mandatory | Description | 5714| ---------- | ------- | ---- | ---------------------------------- | 5715| type | [HighlightUserActionType](#highlightuseractiontype12) | Yes | Type of the user behavior data to set.| 5716| actionData | number | Yes | Behavior data.| 5717 5718**Error codes** 5719 5720For details about the error codes, see [Universal Error Codes](../errorcode-universal.md) and [File Management Error Codes](../apis-core-file-kit/errorcode-filemanagement.md). 5721 5722| ID | Error Message | 5723| :------- | :-------------------------------- | 5724| 201 | Permission denied. | 5725| 202 | Called by non-system application. | 5726| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types; 3. Parameter verification failed. | 5727| 14000011 | Internal system error. | 5728 5729**Example** 5730 5731```ts 5732import { dataSharePredicates } from '@kit.ArkData'; 5733 5734async function example() { 5735 try { 5736 console.info('setHighlightUserActionDataDemo') 5737 let fetchOptions: photoAccessHelper.FetchOptions = { 5738 fetchColumns: [], 5739 predicates: new dataSharePredicates.DataSharePredicates() 5740 } 5741 let albumFetchResult: photoAccessHelper.FetchResult<photoAccessHelper.Album> = await photoAccessHelper.getAlbums( 5742 photoAccessHelper.AlbumType.SMART, photoAccessHelper.AlbumSubtype.HIGHLIGHT, fetchOption); 5743 let album: photoAccessHelper.Album = await albumFetchResult.getFirstObject(); 5744 if (album != undefined) { 5745 let highlightAlbum: photoAccessHelper.HighlightAlbum = new photoAccessHelper.HighlightAlbum(album); 5746 highlightAlbum.setHighlightUserActionData(photoAccessHelper.HighlightUserActionType.INSERTED_PIC_COUNT, 1); 5747 } 5748 albumFetchResult.close(); 5749 } catch (err) { 5750 console.error(`setHighlightUserActionDataDemofailed with error: ${err.code}, ${err.message}`); 5751 } 5752} 5753``` 5754 5755### setSubTitle<sup>18+</sup> 5756 5757setSubTitle(title: string): void 5758 5759Sets the subtitle for this **Highlights** album instance. 5760 5761The subtitle must meet the following requirements: 5762 5763- The subtitle cannot exceed 255 characters. 5764- The subtitle cannot contain any of the following characters:<br> . \ / : * ? " ' ` < > | { } [ ] 5765- The subtitle is case-insensitive. 5766 5767**System API**: This is a system API. 5768 5769**Required permissions**: ohos.permission.WRITE\_IMAGEVIDEO 5770 5771**System capability**: SystemCapability.FileManagement.PhotoAccessHelper.Core 5772 5773**Parameters** 5774 5775| Name | Type | Mandatory | Description | 5776| ---------- | ------- | ---- | ---------------------------------- | 5777| title | string | Yes | Subtitle to set.| 5778 5779**Error codes** 5780 5781For details about the error codes, see [Universal Error Codes](../errorcode-universal.md) and [File Management Error Codes](../apis-core-file-kit/errorcode-filemanagement.md). 5782 5783| ID | Error Message | 5784| :------- | :-------------------------------- | 5785| 201 | Permission denied. | 5786| 202 | Called by non-system application. | 5787| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types; 3. Parameter verification failed. | 5788| 14000011 | Internal system error. It is recommended to retry and check the logs. Possible causes: 1. Database corrupted; 2. The file system is abnormal; 3. The IPC request timed out. | 5789 5790**Example** 5791 5792```ts 5793import { dataSharePredicates } from '@kit.ArkData'; 5794 5795async function example() { 5796 try { 5797 console.info('setSubTitle'); 5798 let helper: photoAccessHelper.PhotoAccessHelper = photoAccessHelper.getPhotoAccessHelper(getContext(this)); 5799 let albumFetchOption: photoAccessHelper.FetchOptions = { 5800 fetchColumns: [], 5801 predicates: new dataSharePredicates.DataSharePredicates() 5802 }; 5803 let albumFetchResult: photoAccessHelper.FetchResult<photoAccessHelper.Album> = 5804 await helper.getAlbums(photoAccessHelper.AlbumType.SMART, photoAccessHelper.AlbumSubtype.HIGHLIGHT, albumFetchOption); 5805 if (albumFetchResult.getCount() === 0) { 5806 console.error('No album'); 5807 return; 5808 } 5809 let highlightAlbum: photoAccessHelper.Album = await albumFetchResult.getFirstObject(); 5810 albumFetchResult.close(); 5811 let changeHighlightAlbumRequest: photoAccessHelper.HighlightAlbum = new photoAccessHelper.HighlightAlbum(highlightAlbum); 5812 changeHighlightAlbumRequest.setSubTitle("testName"); 5813 console.info('setSubTitle success'); 5814 } catch (err) { 5815 console.error(`setSubTitle with error: ${err}`); 5816 } 5817} 5818``` 5819 5820### deleteHighlightAlbums<sup>18+</sup> 5821 5822static deleteHighlightAlbums(context: Context, albums: Array<Album>): Promise<number> 5823 5824Deletes highlight albums. 5825 5826**System API**: This is a system API. 5827 5828**Required permissions**: ohos.permission.WRITE\_IMAGEVIDEO 5829 5830**System capability**: SystemCapability.FileManagement.PhotoAccessHelper.Core 5831 5832**Parameters** 5833 5834| Name | Type | Mandatory | Description | 5835| ---------- | ------- | ---- | ---------------------------------- | 5836| context | [Context](../apis-ability-kit/js-apis-inner-application-context.md) | Yes | Context of the ability instance.| 5837| albums | Array<[Album](#album)> | Yes | Array of highlight albums to delete.| 5838 5839**Return value** 5840 5841| Type | Description | 5842| :------------------ | :---------------------------------- | 5843| Promise<number> | Promise used to return the operation result. The value **0** means that the operation is successful, and **-1** means the opposite.| 5844 5845**Error codes** 5846 5847For details about the error codes, see [Universal Error Codes](../errorcode-universal.md) and [File Management Error Codes](../apis-core-file-kit/errorcode-filemanagement.md). 5848 5849| ID | Error Message | 5850| :------- | :-------------------------------- | 5851| 201 | Permission denied. | 5852| 202 | Called by non-system application. | 5853| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types; 3. Parameter verification failed. | 5854| 14000011 | Internal system error. It is recommended to retry and check the logs. Possible causes: 1. Database corrupted; 2. The file system is abnormal; 3. The IPC request timed out. | 5855 5856**Example** 5857 5858```ts 5859import { dataSharePredicates } from '@kit.ArkData'; 5860 5861async function example() { 5862 try { 5863 console.info('deleteHighlightAlbums'); 5864 let helper: photoAccessHelper.PhotoAccessHelper = photoAccessHelper.getPhotoAccessHelper(getContext(this)); 5865 let albumFetchOption: photoAccessHelper.FetchOptions = { 5866 fetchColumns: [], 5867 predicates: new dataSharePredicates.DataSharePredicates() 5868 }; 5869 let albumFetchResult: photoAccessHelper.FetchResult<photoAccessHelper.Album> = 5870 await helper.getAlbums(photoAccessHelper.AlbumType.SMART, photoAccessHelper.AlbumSubtype.HIGHLIGHT, albumFetchOption); 5871 if (albumFetchResult.getCount() === 0) { 5872 console.error('No album'); 5873 return; 5874 } 5875 let highlightAlbum: photoAccessHelper.Album = await albumFetchResult.getFirstObject(); 5876 albumFetchResult.close(); 5877 let result = await photoAccessHelper.HighlightAlbum.deleteHighlightAlbums(getContext(this), [highlightAlbum]); 5878 console.info('deleteHighlightAlbums success'); 5879 } catch (err) { 5880 console.error(`deleteHighlightAlbums with error: ${err}`); 5881 } 5882} 5883``` 5884 5885## MediaAnalysisAlbumChangeRequest<sup>18+</sup> 5886 5887Provides APIs for managing the analysis album change request. 5888 5889**System capability**: SystemCapability.FileManagement.PhotoAccessHelper.Core 5890 5891### constructor<sup>18+</sup> 5892 5893constructor(album: Album) 5894 5895A constructor used to create an **Analysis** album instance. 5896 5897**System API**: This is a system API. 5898 5899**System capability**: SystemCapability.FileManagement.PhotoAccessHelper.Core 5900 5901**Parameters** 5902 5903| Name | Type | Mandatory | Description | 5904| ---------- | ------- | ---- | ---------------------------------- | 5905| album | [Album](#album) | Yes | **Analysis** album to create.| 5906 5907**Error codes** 5908 5909For details about the error codes, see [Universal Error Codes](../errorcode-universal.md) and [File Management Error Codes](../apis-core-file-kit/errorcode-filemanagement.md). 5910 5911| ID| Error Message| 5912| -------- | ---------------------------------------- | 5913| 202 | Called by non-system application. | 5914| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types; 3. Parameter verification failed. | 5915 5916**Example** 5917 5918```ts 5919import { dataSharePredicates } from '@kit.ArkData'; 5920 5921async function example() { 5922 console.info('MediaAnalysisAlbumChangeRequest constructorDemo'); 5923 let helper: photoAccessHelper.PhotoAccessHelper = photoAccessHelper.getPhotoAccessHelper(getContext(this)); 5924 let albumFetchOption: photoAccessHelper.FetchOptions = { 5925 fetchColumns: [], 5926 predicates: new dataSharePredicates.DataSharePredicates() 5927 }; 5928 let albumFetchResult: photoAccessHelper.FetchResult<photoAccessHelper.Album> = 5929 await helper.getAlbums(photoAccessHelper.AlbumType.SMART, photoAccessHelper.AlbumSubtype.HIGHLIGHT, albumFetchOption); 5930 if (albumFetchResult.getCount() === 0) { 5931 console.error('No album'); 5932 return; 5933 } 5934 let highlightAlbum: photoAccessHelper.Album = await albumFetchResult.getFirstObject(); 5935 albumFetchResult.close(); 5936 let changeRequest: photoAccessHelper.MediaAnalysisAlbumChangeRequest = 5937 new photoAccessHelper.MediaAnalysisAlbumChangeRequest(highlightAlbum); 5938} 5939``` 5940 5941### setOrderPosition<sup>18+</sup> 5942 5943setOrderPosition(assets: Array<PhotoAsset>, position: Array<number>): void 5944 5945Sets the sequence of assets in the **Analysis** album. 5946 5947**System API**: This is a system API. 5948 5949**Required permissions**: ohos.permission.WRITE\_IMAGEVIDEO 5950 5951**System capability**: SystemCapability.FileManagement.PhotoAccessHelper.Core 5952 5953**Parameters** 5954 5955| Name | Type | Mandatory | Description | 5956| ---------- | ------- | ---- | ---------------------------------- | 5957| assets | Array<[PhotoAsset](#photoasset)> | Yes | Assets in the album for which the sequence needs to be set.| 5958| position | Array<number> | Yes | Sequence of assets in the album.| 5959 5960**Error codes** 5961 5962For details about the error codes, see [Universal Error Codes](../errorcode-universal.md) and [File Management Error Codes](../apis-core-file-kit/errorcode-filemanagement.md). 5963 5964| ID | Error Message | 5965| :------- | :-------------------------------- | 5966| 201 | Permission denied. | 5967| 202 | Called by non-system application. | 5968| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types; 3. Parameter verification failed. | 5969| 14000011 | Internal system error. It is recommended to retry and check the logs. Possible causes: 1. Database corrupted; 2. The file system is abnormal; 3. The IPC request timed out. | 5970 5971**Example** 5972 5973```ts 5974import { dataSharePredicates } from '@kit.ArkData'; 5975 5976async function example() { 5977 try { 5978 console.info('setOrderPosition'); 5979 let helper: photoAccessHelper.PhotoAccessHelper = photoAccessHelper.getPhotoAccessHelper(getContext(this)); 5980 let albumFetchOption: photoAccessHelper.FetchOptions = { 5981 fetchColumns: [], 5982 predicates: new dataSharePredicates.DataSharePredicates() 5983 }; 5984 let albumFetchResult: photoAccessHelper.FetchResult<photoAccessHelper.Album> = 5985 await helper.getAlbums(photoAccessHelper.AlbumType.SMART, photoAccessHelper.AlbumSubtype.HIGHLIGHT, albumFetchOption); 5986 if (albumFetchResult.getCount() === 0) { 5987 console.error('No album'); 5988 return; 5989 } 5990 let highlightAlbum: photoAccessHelper.Album = await albumFetchResult.getFirstObject(); 5991 albumFetchResult.close(); 5992 let predicates: dataSharePredicates.DataSharePredicates = new dataSharePredicates.DataSharePredicates(); 5993 const fetchOption: photoAccessHelper.FetchOptions = { 5994 fetchColumns: [], 5995 predicates: predicates 5996 }; 5997 let fetchResult: photoAccessHelper.FetchResult<photoAccessHelper.PhotoAsset> = 5998 await highlightAlbum.getAssets(fetchOption); 5999 let assets: photoAccessHelper.PhotoAsset[] = await fetchResult.getAllObjects(); 6000 let indexes: number[] = []; 6001 for (let i = 0; i < assets.length; i++) { 6002 indexes.push(i); 6003 } 6004 let changeRequest: photoAccessHelper.MediaAnalysisAlbumChangeRequest = 6005 new photoAccessHelper.MediaAnalysisAlbumChangeRequest(highlightAlbum); 6006 changeRequest.setOrderPosition(assets, indexes); 6007 await helper.applyChanges(changeRequest); 6008 console.info(`setOrderPosition ${indexes}`); 6009 } catch (err) { 6010 console.error(`setOrderPosition error: ${err}`); 6011 } 6012} 6013``` 6014 6015## AnalysisAlbum<sup>18+</sup> 6016 6017**Analysis** album to create. 6018 6019**System capability**: SystemCapability.FileManagement.PhotoAccessHelper.Core 6020 6021### constructor<sup>18+</sup> 6022 6023constructor(album: Album) 6024 6025A constructor used to create an **Analysis** album instance. 6026 6027**System API**: This is a system API. 6028 6029**System capability**: SystemCapability.FileManagement.PhotoAccessHelper.Core 6030 6031**Parameters** 6032 6033| Name | Type | Mandatory | Description | 6034| ---------- | ------- | ---- | ---------------------------------- | 6035| album | [Album](#album) | Yes | **Analysis** album to create.| 6036 6037**Error codes** 6038 6039For details about the error codes, see [Universal Error Codes](../errorcode-universal.md) and [File Management Error Codes](../apis-core-file-kit/errorcode-filemanagement.md). 6040 6041| ID| Error Message| 6042| -------- | ---------------------------------------- | 6043| 202 | Called by non-system application. | 6044| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types; 3. Parameter verification failed. | 6045 6046**Example** 6047 6048```ts 6049import { dataSharePredicates } from '@kit.ArkData'; 6050 6051async function example() { 6052 console.info('AnalysisAlbum constructorDemo'); 6053 let helper: photoAccessHelper.PhotoAccessHelper = photoAccessHelper.getPhotoAccessHelper(getContext(this)); 6054 let albumFetchOption: photoAccessHelper.FetchOptions = { 6055 fetchColumns: [], 6056 predicates: new dataSharePredicates.DataSharePredicates() 6057 }; 6058 let albumFetchResult: photoAccessHelper.FetchResult<photoAccessHelper.Album> = 6059 await helper.getAlbums(photoAccessHelper.AlbumType.SMART, photoAccessHelper.AlbumSubtype.HIGHLIGHT, albumFetchOption); 6060 if (albumFetchResult.getCount() === 0) { 6061 console.error('No album'); 6062 return; 6063 } 6064 let highlightAlbum: photoAccessHelper.Album = await albumFetchResult.getFirstObject(); 6065 albumFetchResult.close(); 6066 let analysisAlbum: photoAccessHelper.AnalysisAlbum = new photoAccessHelper.AnalysisAlbum(highlightAlbum); 6067} 6068``` 6069 6070### getOrderPosition<sup>18+</sup> 6071 6072getOrderPosition(assets: Array<PhotoAsset>): Promise<Array<number>> 6073 6074Obtains the sequence of assets in the **Analysis** album. 6075 6076**System API**: This is a system API. 6077 6078**Required permissions**: ohos.permission.READ\_IMAGEVIDEO 6079 6080**System capability**: SystemCapability.FileManagement.PhotoAccessHelper.Core 6081 6082**Parameters** 6083 6084| Name | Type | Mandatory | Description | 6085| ---------- | ------- | ---- | ---------------------------------- | 6086| assets | Array<[PhotoAsset](#photoasset)> | Yes | Assets in the album whose sequence needs to be obtained.| 6087 6088**Return value** 6089 6090| Type | Description | 6091| :------------------ | :---------------------------------- | 6092| Promise<Array<number>> | Sequence number of an asset in the album.| 6093 6094**Error codes** 6095 6096For details about the error codes, see [Universal Error Codes](../errorcode-universal.md) and [File Management Error Codes](../apis-core-file-kit/errorcode-filemanagement.md). 6097 6098| ID | Error Message | 6099| :------- | :-------------------------------- | 6100| 201 | Permission denied. | 6101| 202 | Called by non-system application. | 6102| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types; 3. Parameter verification failed. | 6103| 14000011 | Internal system error. It is recommended to retry and check the logs. Possible causes: 1. Database corrupted; 2. The file system is abnormal; 3. The IPC request timed out. | 6104 6105**Example** 6106 6107```ts 6108import { dataSharePredicates } from '@kit.ArkData'; 6109 6110async function example() { 6111 try { 6112 console.info('getOrderPosition'); 6113 let helper: photoAccessHelper.PhotoAccessHelper = photoAccessHelper.getPhotoAccessHelper(getContext(this)); 6114 let albumFetchOption: photoAccessHelper.FetchOptions = { 6115 fetchColumns: [], 6116 predicates: new dataSharePredicates.DataSharePredicates() 6117 }; 6118 let albumFetchResult: photoAccessHelper.FetchResult<photoAccessHelper.Album> = 6119 await helper.getAlbums(photoAccessHelper.AlbumType.SMART, photoAccessHelper.AlbumSubtype.HIGHLIGHT, albumFetchOption); 6120 if (albumFetchResult.getCount() === 0) { 6121 console.error('No album'); 6122 return; 6123 } 6124 let highlightAlbum: photoAccessHelper.Album = await albumFetchResult.getFirstObject(); 6125 albumFetchResult.close(); 6126 let predicates: dataSharePredicates.DataSharePredicates = new dataSharePredicates.DataSharePredicates(); 6127 let analysisAlbum: photoAccessHelper.AnalysisAlbum = new photoAccessHelper.AnalysisAlbum(highlightAlbum); 6128 const fetchOption: photoAccessHelper.FetchOptions = { 6129 fetchColumns: [], 6130 predicates: predicates 6131 }; 6132 let fetchResult: photoAccessHelper.FetchResult<photoAccessHelper.PhotoAsset> = 6133 await highlightAlbum.getAssets(fetchOption); 6134 let assets: photoAccessHelper.PhotoAsset[] = await fetchResult.getAllObjects(); 6135 let positions: number[] = await analysisAlbum.getOrderPosition(assets); 6136 console.info(`getOrderPosition ${positions}`); 6137 } catch (err) { 6138 console.error(`getOrderPosition error: ${err}`); 6139 } 6140} 6141``` 6142 6143## CloudEnhancement<sup>13+</sup> 6144 6145Provides APIs for cloud enhancement management, including managing the tasks of generating AI-powered cloud enhancement photos and obtaining the association between the original photos and AI cloud enhancement photos. 6146 6147**System API**: This is a system API. 6148 6149**System capability**: SystemCapability.FileManagement.PhotoAccessHelper.Core 6150 6151### getCloudEnhancementInstance<sup>13+</sup> 6152 6153static getCloudEnhancementInstance(context: Context): CloudEnhancement 6154 6155Obtains a cloud enhancement instance. 6156 6157**System API**: This is a system API. 6158 6159**System capability**: SystemCapability.FileManagement.PhotoAccessHelper.Core 6160 6161**Parameters** 6162 6163| Name | Type | Mandatory| Description | 6164| -------- | ------------------------- | ---- | ---------- | 6165| context | [Context](../apis-ability-kit/js-apis-inner-application-context.md) | Yes | Context of the ability instance.| 6166 6167**Error codes** 6168 6169For details about the error codes, see [Universal Error Codes](../errorcode-universal.md) and [File Management Error Codes](../apis-core-file-kit/errorcode-filemanagement.md). 6170 6171| ID| Error Message| 6172| -------- | ---------------------------------------- | 6173| 202 | Called by non-system application. | 6174| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types; 3. Parameter verification failed. | 6175| 14000011 | Internal system error. | 6176 6177**Example** 6178 6179```ts 6180import { dataSharePredicates } from '@kit.ArkData'; 6181 6182async function example() { 6183 console.info('getCloudEnhancementInstanceDemo'); 6184 let photoPredicates: dataSharePredicates.DataSharePredicates = new dataSharePredicates.DataSharePredicates(); 6185 let photoFetchOptions: photoAccessHelper.FetchOptions = { 6186 fetchColumns: [], 6187 predicates: photoPredicates 6188 }; 6189 let phAccessHelper = photoAccessHelper.getPhotoAccessHelper(context); 6190 try { 6191 let fetchResult = await phAccessHelper.getAssets(photoFetchOptions); 6192 let asset = await fetchResult.getLastObject(); 6193 let cloudEnhancementInstance: photoAccessHelper.CloudEnhancement 6194 = photoAccessHelper.CloudEnhancement.getCloudEnhancementInstance(context); 6195 let hasCloudWatermark = true; 6196 await cloudEnhancementInstance.submitCloudEnhancementTasks([asset], hasCloudWatermark); 6197 } catch (err) { 6198 console.error(`getCloudEnhancementInstanceDemo failed with error: ${err.code}, ${err.message}`); 6199 } 6200} 6201``` 6202 6203### submitCloudEnhancementTasks<sup>13+</sup> 6204 6205submitCloudEnhancementTasks(photoAssets: Array<PhotoAsset>, hasCloudWatermark: boolean): Promise<void> 6206 6207Submits cloud enhancement tasks. 6208 6209**System API**: This is a system API. 6210 6211**System capability**: SystemCapability.FileManagement.PhotoAccessHelper.Core 6212 6213**Required permissions**: ohos.permission.WRITE_IMAGEVIDEO 6214 6215**Parameters** 6216 6217| Name | Type | Mandatory| Description | 6218| -------- | ------------------------- | ---- | ---------- | 6219| photoAssets | Array<[PhotoAsset](#photoasset)> | Yes | [PhotoAsset](#photoasset) to enhance.| 6220| hasCloudWatermark | boolean | Yes | Whether to add a cloud enhancement watermark to the enhanced images.| 6221 6222**Error codes** 6223 6224For details about the error codes, see [Universal Error Codes](../errorcode-universal.md) and [File Management Error Codes](../apis-core-file-kit/errorcode-filemanagement.md). 6225 6226| ID| Error Message| 6227| -------- | ---------------------------------------- | 6228| 201 | Permission denied. | 6229| 202 | Called by non-system application. | 6230| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types; 3. Parameter verification failed. | 6231| 14000011 | Internal system error. | 6232 6233**Example** 6234 6235```ts 6236import { dataSharePredicates } from '@kit.ArkData'; 6237 6238async function example() { 6239 console.info('submitCloudEnhancementTasksDemo'); 6240 let photoPredicates: dataSharePredicates.DataSharePredicates = new dataSharePredicates.DataSharePredicates(); 6241 let photoFetchOptions: photoAccessHelper.FetchOptions = { 6242 fetchColumns: [], 6243 predicates: photoPredicates 6244 }; 6245 let phAccessHelper = photoAccessHelper.getPhotoAccessHelper(context); 6246 try { 6247 let fetchResult = await phAccessHelper.getAssets(photoFetchOptions); 6248 let asset = await fetchResult.getLastObject(); 6249 let cloudEnhancementInstance: photoAccessHelper.CloudEnhancement 6250 = photoAccessHelper.CloudEnhancement.getCloudEnhancementInstance(context); 6251 let hasCloudWatermark = true; 6252 await cloudEnhancementInstance.submitCloudEnhancementTasks([asset], hasCloudWatermark); 6253 } catch (err) { 6254 console.error(`submitCloudEnhancementTasksDemo failed with error: ${err.code}, ${err.message}`); 6255 } 6256} 6257``` 6258 6259### submitCloudEnhancementTasks<sup>18+</sup> 6260 6261submitCloudEnhancementTasks(photoAssets: Array<PhotoAsset>, hasCloudWatermark: boolean, triggerMode?: number): Promise<void> 6262 6263Submits cloud enhancement tasks. 6264 6265**System API**: This is a system API. 6266 6267**System capability**: SystemCapability.FileManagement.PhotoAccessHelper.Core 6268 6269**Required permissions**: ohos.permission.WRITE_IMAGEVIDEO 6270 6271**Parameters** 6272 6273| Name | Type | Mandatory| Description | 6274| -------- | ------------------------- | ---- | ---------- | 6275| photoAssets | Array<[PhotoAsset](#photoasset)> | Yes | [PhotoAsset](#photoasset) to enhance.| 6276| hasCloudWatermark | boolean | Yes | Whether to add a cloud watermark to the enhanced image. The value **true** means to add the watermark, and **false** means the opposite.| 6277| triggerMode | number | No | Trigger mode of the cloud enhancement task.<br>**- 0**: manually triggered.<br>**- 1**: automatically triggered.<br>The default value is **0**.| 6278 6279**Error codes** 6280 6281For details about the error codes, see [Universal Error Codes](../errorcode-universal.md) and [File Management Error Codes](../apis-core-file-kit/errorcode-filemanagement.md). 6282 6283| ID| Error Message| 6284| -------- | ---------------------------------------- | 6285| 201 | Permission denied. | 6286| 202 | Called by non-system application. | 6287| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types; 3. Parameter verification failed. | 6288| 14000011 | Internal system error. | 6289 6290**Example** 6291 6292```ts 6293import { dataSharePredicates } from '@kit.ArkData'; 6294 6295async function example() { 6296 console.info('submitCloudEnhancementTasksDemo'); 6297 let photoPredicates: dataSharePredicates.DataSharePredicates = new dataSharePredicates.DataSharePredicates(); 6298 let photoFetchOptions: photoAccessHelper.FetchOptions = { 6299 fetchColumns: [], 6300 predicates: photoPredicates 6301 }; 6302 let phAccessHelper = photoAccessHelper.getPhotoAccessHelper(context); 6303 try { 6304 let fetchResult = await phAccessHelper.getAssets(photoFetchOptions); 6305 let asset = await fetchResult.getLastObject(); 6306 let cloudEnhancementInstance: photoAccessHelper.CloudEnhancement 6307 = photoAccessHelper.CloudEnhancement.getCloudEnhancementInstance(context); 6308 let hasCloudWatermark = true; 6309 let triggerAuto = 1; 6310 await cloudEnhancementInstance.submitCloudEnhancementTasks([asset], hasCloudWatermark, triggerAuto); 6311 } catch (err) { 6312 console.error(`submitCloudEnhancementTasksDemo failed with error: ${err.code}, ${err.message}`); 6313 } 6314} 6315``` 6316 6317### prioritizeCloudEnhancementTask<sup>13+</sup> 6318 6319prioritizeCloudEnhancementTask(photoAsset: PhotoAsset): Promise<void> 6320 6321Prioritizes a cloud enhancement task. 6322 6323**System API**: This is a system API. 6324 6325**System capability**: SystemCapability.FileManagement.PhotoAccessHelper.Core 6326 6327**Required permissions**: ohos.permission.WRITE_IMAGEVIDEO 6328 6329**Parameters** 6330 6331| Name | Type | Mandatory| Description | 6332| -------- | ------------------------- | ---- | ---------- | 6333| photoAsset | [PhotoAsset](#photoasset) | Yes | [PhotoAsset](#photoasset) whose cloud enhancement priority needs to be escalated.| 6334 6335**Error codes** 6336 6337For details about the error codes, see [Universal Error Codes](../errorcode-universal.md) and [File Management Error Codes](../apis-core-file-kit/errorcode-filemanagement.md). 6338 6339| ID| Error Message| 6340| -------- | ---------------------------------------- | 6341| 201 | Permission denied. | 6342| 202 | Called by non-system application. | 6343| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types; 3. Parameter verification failed. | 6344| 14000011 | Internal system error. | 6345 6346**Example** 6347 6348```ts 6349import { dataSharePredicates } from '@kit.ArkData'; 6350 6351async function example() { 6352 console.info('prioritizeCloudEnhancementTaskDemo'); 6353 let photoPredicates: dataSharePredicates.DataSharePredicates = new dataSharePredicates.DataSharePredicates(); 6354 // Obtain the cloud enhancement tasks in progress. 6355 photoPredicates.equalTo(photoAccessHelper.PhotoKeys.CE_AVAILABLE, 2); 6356 let photoFetchOptions: photoAccessHelper.FetchOptions = { 6357 fetchColumns: [], 6358 predicates: photoPredicates 6359 }; 6360 let phAccessHelper = photoAccessHelper.getPhotoAccessHelper(context); 6361 try { 6362 let fetchResult = await phAccessHelper.getAssets(photoFetchOptions); 6363 let asset = await fetchResult.getLastObject(); 6364 let cloudEnhancementInstance: photoAccessHelper.CloudEnhancement 6365 = photoAccessHelper.CloudEnhancement.getCloudEnhancementInstance(context); 6366 let hasCloudWatermark = true; 6367 await cloudEnhancementInstance.prioritizeCloudEnhancementTask(asset); 6368 } catch (err) { 6369 console.error(`prioritizeCloudEnhancementTaskDemo failed with error: ${err.code}, ${err.message}`); 6370 } 6371} 6372``` 6373 6374### cancelCloudEnhancementTasks<sup>13+</sup> 6375 6376cancelCloudEnhancementTasks(photoAssets: Array<PhotoAsset>): Promise<void> 6377 6378Cancels cloud enhancement tasks. 6379 6380**System API**: This is a system API. 6381 6382**System capability**: SystemCapability.FileManagement.PhotoAccessHelper.Core 6383 6384**Required permissions**: ohos.permission.WRITE_IMAGEVIDEO 6385 6386**Parameters** 6387 6388| Name | Type | Mandatory| Description | 6389| -------- | ------------------------- | ---- | ---------- | 6390| photoAssets | Array<[PhotoAsset](#photoasset)> | Yes | Array of [PhotoAssets](#photoasset) whose cloud enhancement tasks are to be canceled.| 6391 6392**Error codes** 6393 6394For details about the error codes, see [Universal Error Codes](../errorcode-universal.md) and [File Management Error Codes](../apis-core-file-kit/errorcode-filemanagement.md). 6395 6396| ID| Error Message| 6397| -------- | ---------------------------------------- | 6398| 201 | Permission denied. | 6399| 202 | Called by non-system application. | 6400| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types; 3. Parameter verification failed. | 6401| 14000011 | Internal system error. | 6402 6403**Example** 6404 6405```ts 6406import { dataSharePredicates } from '@kit.ArkData'; 6407 6408async function example() { 6409 console.info('cancelCloudEnhancementTasksDemo'); 6410 let photoPredicates: dataSharePredicates.DataSharePredicates = new dataSharePredicates.DataSharePredicates(); 6411 // Obtain the cloud enhancement tasks in progress. 6412 photoPredicates.equalTo(photoAccessHelper.PhotoKeys.CE_AVAILABLE, 2); 6413 let photoFetchOptions: photoAccessHelper.FetchOptions = { 6414 fetchColumns: [], 6415 predicates: photoPredicates 6416 }; 6417 let phAccessHelper = photoAccessHelper.getPhotoAccessHelper(context); 6418 try { 6419 let fetchResult = await phAccessHelper.getAssets(photoFetchOptions); 6420 let asset = await fetchResult.getLastObject(); 6421 let cloudEnhancementInstance: photoAccessHelper.CloudEnhancement 6422 = photoAccessHelper.CloudEnhancement.getCloudEnhancementInstance(context); 6423 await cloudEnhancementInstance.cancelCloudEnhancementTasks([asset]); 6424 } catch (err) { 6425 console.error(`cancelCloudEnhancementTasksDemo failed with error: ${err.code}, ${err.message}`); 6426 } 6427} 6428``` 6429 6430### cancelAllCloudEnhancementTasks<sup>13+</sup> 6431 6432cancelAllCloudEnhancementTasks(): Promise<void> 6433 6434Cancels all cloud enhancement tasks. 6435 6436**System API**: This is a system API. 6437 6438**System capability**: SystemCapability.FileManagement.PhotoAccessHelper.Core 6439 6440**Required permissions**: ohos.permission.WRITE_IMAGEVIDEO 6441 6442**Error codes** 6443 6444For details about the error codes, see [Universal Error Codes](../errorcode-universal.md) and [File Management Error Codes](../apis-core-file-kit/errorcode-filemanagement.md). 6445 6446| ID| Error Message| 6447| -------- | ---------------------------------------- | 6448| 201 | Permission denied. | 6449| 202 | Called by non-system application. | 6450| 14000011 | Internal system error. | 6451 6452**Example** 6453 6454```ts 6455import { dataSharePredicates } from '@kit.ArkData'; 6456 6457async function example() { 6458 console.info('cancelAllCloudEnhancementTasksDemo'); 6459 try { 6460 let cloudEnhancementInstance: photoAccessHelper.CloudEnhancement 6461 = photoAccessHelper.CloudEnhancement.getCloudEnhancementInstance(context); 6462 await cloudEnhancementInstance.cancelCloudEnhancementTasks(); 6463 } catch (err) { 6464 console.error(`cancelAllCloudEnhancementTasksDemo failed with error: ${err.code}, ${err.message}`); 6465 } 6466} 6467``` 6468 6469### queryCloudEnhancementTaskState<sup>13+</sup> 6470 6471queryCloudEnhancementTaskState(photoAsset: PhotoAsset): Promise<CloudEnhancementTaskState> 6472 6473Queries information about a cloud enhancement task. 6474 6475**System API**: This is a system API. 6476 6477**System capability**: SystemCapability.FileManagement.PhotoAccessHelper.Core 6478 6479**Required permissions**: ohos.permission.READ_IMAGEVIDEO 6480 6481**Parameters** 6482 6483| Name | Type | Mandatory| Description | 6484| -------- | ------------------------- | ---- | ---------- | 6485| photoAsset | [PhotoAsset](#photoasset) | Yes | [PhotoAsset](#photoasset) whose cloud enhancement task information is to be queried.| 6486 6487**Error codes** 6488 6489For details about the error codes, see [Universal Error Codes](../errorcode-universal.md) and [File Management Error Codes](../apis-core-file-kit/errorcode-filemanagement.md). 6490 6491| ID| Error Message| 6492| -------- | ---------------------------------------- | 6493| 201 | Permission denied. | 6494| 202 | Called by non-system application. | 6495| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types; 3. Parameter verification failed. | 6496| 14000011 | Internal system error. | 6497 6498**Example** 6499 6500```ts 6501import { dataSharePredicates } from '@kit.ArkData'; 6502 6503async function example() { 6504 console.info('queryCloudEnhancementTaskStateDemo'); 6505 let photoPredicates: dataSharePredicates.DataSharePredicates = new dataSharePredicates.DataSharePredicates(); 6506 // Obtain the cloud enhancement tasks in progress. 6507 photoPredicates.equalTo(photoAccessHelper.PhotoKeys.CE_AVAILABLE, 2); 6508 let photoFetchOptions: photoAccessHelper.FetchOptions = { 6509 fetchColumns: [], 6510 predicates: photoPredicates 6511 }; 6512 let phAccessHelper = photoAccessHelper.getPhotoAccessHelper(context); 6513 try { 6514 let fetchResult = await phAccessHelper.getAssets(photoFetchOptions); 6515 let asset = await fetchResult.getLastObject(); 6516 let cloudEnhancementInstance: photoAccessHelper.CloudEnhancement 6517 = photoAccessHelper.CloudEnhancement.getCloudEnhancementInstance(context); 6518 const cloudEnhancementTaskState: photoAccessHelper.CloudEnhancementTaskState 6519 = await cloudEnhancementInstance.queryCloudEnhancementTaskState(asset); 6520 let taskStage = cloudEnhancementTaskState.taskStage; 6521 if (taskStage == photoAccessHelper.CloudEnhancementTaskStage.TASK_STAGE_EXCEPTION) { 6522 console.log("task has exception"); 6523 } else if (taskStage == photoAccessHelper.CloudEnhancementTaskStage.TASK_STAGE_PREPARING) { 6524 console.log("task is preparing"); 6525 } else if (taskStage == photoAccessHelper.CloudEnhancementTaskStage.TASK_STAGE_UPLOADING) { 6526 let transferredFileSize = cloudEnhancementTaskState.transferredFileSize; 6527 let totalFileSize = cloudEnhancementTaskState.totalFileSize; 6528 let message = `task is uploading, transferredFileSize: ${transferredFileSize}, totalFileSize: ${totalFileSize}`; 6529 console.log(message); 6530 } else if (taskStage == photoAccessHelper.CloudEnhancementTaskStage.TASK_STAGE_EXECUTING) { 6531 let expectedDuration = cloudEnhancementTaskState.expectedDuration; 6532 let message = `task is executing, expectedDuration: ${expectedDuration}`; 6533 console.log(message); 6534 } else if (taskStage == photoAccessHelper.CloudEnhancementTaskStage.TASK_STAGE_DOWNLOADING) { 6535 let transferredFileSize = cloudEnhancementTaskState.transferredFileSize; 6536 let totalFileSize = cloudEnhancementTaskState.totalFileSize; 6537 let message = `task is downloading, transferredFileSize: ${transferredFileSize}, totalFileSize: ${totalFileSize}`; 6538 console.log(message); 6539 } else if (taskStage == photoAccessHelper.CloudEnhancementTaskStage.TASK_STAGE_FAILED) { 6540 let errCode = cloudEnhancementTaskState.statusCode; 6541 let message = `task is failed, errCode: ${errCode}`; 6542 console.log(message); 6543 } else if (taskStage == photoAccessHelper.CloudEnhancementTaskStage.TASK_STAGE_COMPLETED) { 6544 console.log("task is completed"); 6545 } 6546 } catch (err) { 6547 console.error(`queryCloudEnhancementTaskStateDemo failed with error: ${err.code}, ${err.message}`); 6548 } 6549} 6550``` 6551 6552### syncCloudEnhancementTaskStatus<sup>13+</sup> 6553 6554syncCloudEnhancementTaskStatus(): Promise<void> 6555 6556Synchronizes the cloud enhancement task status. 6557 6558**System API**: This is a system API. 6559 6560**System capability**: SystemCapability.FileManagement.PhotoAccessHelper.Core 6561 6562**Required permissions**: ohos.permission.READ_IMAGEVIDEO 6563 6564**Error codes** 6565 6566For details about the error codes, see [Universal Error Codes](../errorcode-universal.md) and [File Management Error Codes](../apis-core-file-kit/errorcode-filemanagement.md). 6567 6568| ID| Error Message| 6569| -------- | ---------------------------------------- | 6570| 201 | Permission denied. | 6571| 202 | Called by non-system application. | 6572| 14000011 | Internal system error. | 6573 6574**Example** 6575 6576```ts 6577import { dataSharePredicates } from '@kit.ArkData'; 6578 6579async function example() { 6580 console.info('syncCloudEnhancementTaskStatusDemo'); 6581 try { 6582 let cloudEnhancementInstance: photoAccessHelper.CloudEnhancement 6583 = photoAccessHelper.CloudEnhancement.getCloudEnhancementInstance(context); 6584 await cloudEnhancementInstance.syncCloudEnhancementTaskStatus(); 6585 } catch (err) { 6586 console.error(`syncCloudEnhancementTaskStatusDemo failed with error: ${err.code}, ${err.message}`); 6587 } 6588} 6589``` 6590 6591### getCloudEnhancementPair<sup>13+</sup> 6592 6593getCloudEnhancementPair(asset: PhotoAsset): Promise<PhotoAsset> 6594 6595Obtains the photo after cloud enhancement. 6596 6597**System API**: This is a system API. 6598 6599**System capability**: SystemCapability.FileManagement.PhotoAccessHelper.Core 6600 6601**Required permissions**: ohos.permission.READ_IMAGEVIDEO 6602 6603**Parameters** 6604 6605| Name | Type | Mandatory| Description | 6606| -------- | ------------------------- | ---- | ---------- | 6607| photoAsset | [PhotoAsset](#photoasset) | Yes | [PhotoAsset](#photoasset) whose cloud enhancement photo is to be obtained.| 6608 6609**Error codes** 6610 6611For details about the error codes, see [Universal Error Codes](../errorcode-universal.md) and [File Management Error Codes](../apis-core-file-kit/errorcode-filemanagement.md). 6612 6613| ID| Error Message| 6614| -------- | ---------------------------------------- | 6615| 201 | Permission denied. | 6616| 202 | Called by non-system application. | 6617| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types; 3. Parameter verification failed. | 6618| 14000011 | Internal system error. | 6619 6620**Example** 6621 6622```ts 6623import { dataSharePredicates } from '@kit.ArkData'; 6624 6625async function example() { 6626 console.info('getCloudEnhancementPairDemo'); 6627 let photoPredicates: dataSharePredicates.DataSharePredicates = new dataSharePredicates.DataSharePredicates(); 6628 // Query the completed cloud enhancement tasks. 6629 photoPredicates.equalTo(photoAccessHelper.PhotoKeys.CE_AVAILABLE, 5); 6630 let photoFetchOptions: photoAccessHelper.FetchOptions = { 6631 fetchColumns: [], 6632 predicates: photoPredicates 6633 }; 6634 let phAccessHelper = photoAccessHelper.getPhotoAccessHelper(context); 6635 try { 6636 let fetchResult = await phAccessHelper.getAssets(photoFetchOptions); 6637 let asset = await fetchResult.getLastObject(); 6638 let cloudEnhancementInstance: photoAccessHelper.CloudEnhancement 6639 = photoAccessHelper.CloudEnhancement.getCloudEnhancementInstance(context); 6640 let photoAsset: photoAccessHelper.PhotoAsset 6641 = await cloudEnhancementInstance.getCloudEnhancementPair(asset); 6642 } catch (err) { 6643 console.error(`getCloudEnhancementPairDemo failed with error: ${err.code}, ${err.message}`); 6644 } 6645} 6646``` 6647 6648### setVideoEnhancementAttr<sup>13+</sup> 6649 6650setVideoEnhancementAttr(videoEnhancementType: VideoEnhancementType, photoId: string): Promise<void> 6651 6652Sets the attributes for deferred video enhancement. 6653 6654**System API**: This is a system API. 6655 6656**Required permissions**: ohos.permission.WRITE\_IMAGEVIDEO 6657 6658**System capability**: SystemCapability.FileManagement.PhotoAccessHelper.Core 6659 6660**Parameters** 6661 6662| Name | Type | Mandatory | Description | 6663| ---------- | ------- | ---- | ---------------------------------- | 6664| videoEnhancementType | [VideoEnhancementType](#videoenhancementtype13) | Yes | Type of video enhancement.| 6665| photoId | string | Yes | Photo ID of the image.| 6666 6667**Error codes** 6668 6669For details about the error codes, see [Universal Error Codes](../errorcode-universal.md) and [File Management Error Codes](../apis-core-file-kit/errorcode-filemanagement.md). 6670 6671| ID | Error Message | 6672| :------- | :-------------------------------- | 6673| 202 | Called by non-system application. | 6674| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types; 3. Parameter verification failed. | 6675| 14000011 | Internal system error. | 6676| 14000016 | Operation Not Support. | 6677 6678**Example** 6679 6680```ts 6681async function example(asset: photoAccessHelper.PhotoAsset) { 6682 try { 6683 let assetChangeRequest: photoAccessHelper.MediaAssetChangeRequest = new photoAccessHelper.MediaAssetChangeRequest(asset); 6684 let photoId = "202410011800"; 6685 assetChangeRequest.setVideoEnhancementAttr(photoAccessHelper.VideoEnhancementType.QUALITY_ENHANCEMENT_LOCAL, photoId); 6686 await phAccessHelper.applyChanges(assetChangeRequest); 6687 } catch (err) { 6688 console.error(`setVideoEnhancementAttr fail with error: ${err.code}, ${err.message}`); 6689 } 6690} 6691``` 6692 6693### getFaceId<sup>13+</sup> 6694 6695getFaceId(): Promise\<string> 6696 6697Obtains the face identifier on the cover of a portrait album or group photo album. 6698 6699**System API**: This is a system API. 6700 6701**Required permissions**: ohos.permission.READ\_IMAGEVIDEO 6702 6703**System capability**: SystemCapability.FileManagement.PhotoAccessHelper.Core 6704 6705**Return value** 6706 6707| Type | Description | 6708| :------------------ | :---------------------------------- | 6709| Promise<string> | Promise used to return **tag_id** of the portrait album, **group_tag** of the group photo album, or an empty string if no face identifier is found.| 6710 6711**Error codes** 6712 6713For details about the error codes, see [Universal Error Codes](../errorcode-universal.md) and [File Management Error Codes](../apis-core-file-kit/errorcode-filemanagement.md). 6714 6715| ID| Error Message | 6716| :------- | :----------------------------------------------------------- | 6717| 201 | Permission denied. | 6718| 202 | Called by non-system application. | 6719| 14000011 | Internal system error | 6720 6721**Example** 6722 6723```ts 6724import { dataSharePredicates } from '@kit.ArkData'; 6725 6726async function example() { 6727 try { 6728 console.info('getFaceIdDemo'); 6729 let predicates: dataSharePredicates.DataSharePredicates = new dataSharePredicates.DataSharePredicates(); 6730 predicates.equalTo("user_display_level", 1); 6731 let fetchOptions: photoAccessHelper.FetchOptions = { 6732 fetchColumns: [], 6733 predicates: predicates 6734 }; 6735 let fetchResult = 6736 await phAccessHelper.getAlbums(photoAccessHelper.AlbumType.SMART, photoAccessHelper.AlbumSubtype.PORTRAIT, 6737 fetchOptions); 6738 let album = await fetchResult?.getFirstObject(); 6739 let faceId = await album?.getFaceId(); 6740 console.info(`getFaceId successfully, faceId: ${faceId}`); 6741 fetchResult.close(); 6742 } catch (err) { 6743 console.error(`getFaceId failed with err: ${err.code}, ${err.message}`); 6744 } 6745} 6746``` 6747 6748## CloudMediaAssetManager<sup>14+</sup> 6749 6750A class used for cloud media asset management. It is used to manage download tasks for media assets stored in the cloud and delete local data and files pertaining to these cloud-based assets. 6751 6752**System API**: This is a system API. 6753 6754**System capability**: SystemCapability.FileManagement.PhotoAccessHelper.Core 6755 6756### getCloudMediaAssetManagerInstance<sup>14+</sup> 6757 6758static getCloudMediaAssetManagerInstance(context: Context): CloudMediaAssetManager 6759 6760Obtains a CloudMediaAssetManager instance. 6761 6762**System API**: This is a system API. 6763 6764**System capability**: SystemCapability.FileManagement.PhotoAccessHelper.Core 6765 6766**Parameters** 6767 6768| Name | Type | Mandatory| Description | 6769| -------- | ------------------------- | ---- | ---------- | 6770| context | [Context](../apis-ability-kit/js-apis-inner-application-context.md) | Yes | Context of the ability instance.| 6771 6772**Return value** 6773 6774| Type | Description | 6775| --------------------------------------- | ----------------- | 6776| [CloudMediaAssetManager](#cloudmediaassetmanager14) | CloudMediaAssetManager instance.| 6777 6778**Error codes** 6779 6780For details about the error codes, see [Universal Error Codes](../errorcode-universal.md) and [File Management Error Codes](../apis-core-file-kit/errorcode-filemanagement.md). 6781 6782| ID| Error Message| 6783| -------- | ---------------------------------------- | 6784| 202 | Called by non-system application. | 6785| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types; 3. Parameter verification failed. | 6786| 14000011 | Internal system error. It is recommended to retry and check the logs. Possible causes: 1. Database corrupted; 2. The file system is abnormal; 3. The IPC request timed out. | 6787 6788**Example** 6789 6790```ts 6791import { photoAccessHelper } from '@kit.MediaLibraryKit'; 6792const context = getContext(this); 6793async function example() { 6794 console.info('getCloudMediaAssetManagerInstanceDemo'); 6795 try { 6796 let cloudMediaAssetManagerInstance: photoAccessHelper.CloudMediaAssetManager 6797 = photoAccessHelper.CloudMediaAssetManager.getCloudMediaAssetManagerInstance(context); 6798 await cloudMediaAssetManagerInstance.pauseDownloadCloudMedia(); 6799 } catch (err) { 6800 console.error(`getCloudMediaAssetManagerInstanceDemo failed with error: ${err.code}, ${err.message}`); 6801 } 6802} 6803``` 6804 6805### startDownloadCloudMedia<sup>14+</sup> 6806 6807startDownloadCloudMedia(downloadType: CloudMediaDownloadType): Promise<void> 6808 6809Starts or resumes a task to download cloud media assets. 6810 6811**System API**: This is a system API. 6812 6813**System capability**: SystemCapability.FileManagement.PhotoAccessHelper.Core 6814 6815**Parameters** 6816 6817| Name | Type | Mandatory| Description | 6818| -------- | ------------------------- | ---- | ---------- | 6819| downloadType | [CloudMediaDownloadType](#cloudmediadownloadtype14) | Yes | Type of the download task.| 6820 6821**Return value** 6822 6823| Type | Description | 6824| --------------------------------------- | ----------------- | 6825| Promise<void>| Promise that returns no value.| 6826 6827**Error codes** 6828 6829For details about the error codes, see [Universal Error Codes](../errorcode-universal.md) and [File Management Error Codes](../apis-core-file-kit/errorcode-filemanagement.md). 6830 6831| ID| Error Message| 6832| -------- | ---------------------------------------- | 6833| 201 | Permission denied. | 6834| 202 | Called by non-system application. | 6835| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types; 3. Parameter verification failed. | 6836| 14000011 | Internal system error. It is recommended to retry and check the logs. Possible causes: 1. Database corrupted; 2. The file system is abnormal; 3. The IPC request timed out. | 6837 6838**Example** 6839 6840```ts 6841import { photoAccessHelper } from '@kit.MediaLibraryKit'; 6842const context = getContext(this); 6843async function example() { 6844 console.info('startDownloadCloudMediaDemo'); 6845 try { 6846 let cloudMediaAssetManagerInstance: photoAccessHelper.CloudMediaAssetManager 6847 = photoAccessHelper.CloudMediaAssetManager.getCloudMediaAssetManagerInstance(context); 6848 await cloudMediaAssetManagerInstance.startDownloadCloudMedia(photoAccessHelper.CloudMediaDownloadType.DOWNLOAD_FORCE); 6849 } catch (err) { 6850 console.error(`startDownloadCloudMediaDemo failed with error: ${err.code}, ${err.message}`); 6851 } 6852} 6853``` 6854 6855### pauseDownloadCloudMedia<sup>14+</sup> 6856 6857pauseDownloadCloudMedia(): Promise<void> 6858 6859Suspends a task that downloads cloud media assets. 6860 6861**System API**: This is a system API. 6862 6863**System capability**: SystemCapability.FileManagement.PhotoAccessHelper.Core 6864 6865**Return value** 6866 6867| Type | Description | 6868| --------------------------------------- | ----------------- | 6869| Promise<void>| Promise that returns no value.| 6870 6871**Error codes** 6872 6873For details about the error codes, see [Universal Error Codes](../errorcode-universal.md) and [File Management Error Codes](../apis-core-file-kit/errorcode-filemanagement.md). 6874 6875| ID| Error Message| 6876| -------- | ---------------------------------------- | 6877| 201 | Permission denied. | 6878| 202 | Called by non-system application. | 6879| 14000011 | Internal system error. It is recommended to retry and check the logs. Possible causes: 1. Database corrupted; 2. The file system is abnormal; 3. The IPC request timed out. | 6880 6881**Example** 6882 6883```ts 6884import { photoAccessHelper } from '@kit.MediaLibraryKit'; 6885const context = getContext(this); 6886async function example() { 6887 console.info('pauseDownloadCloudMediaDemo'); 6888 try { 6889 let cloudMediaAssetManagerInstance: photoAccessHelper.CloudMediaAssetManager 6890 = photoAccessHelper.CloudMediaAssetManager.getCloudMediaAssetManagerInstance(context); 6891 await cloudMediaAssetManagerInstance.pauseDownloadCloudMedia(); 6892 } catch (err) { 6893 console.error(`pauseDownloadCloudMediaDemo failed with error: ${err.code}, ${err.message}`); 6894 } 6895} 6896``` 6897 6898### cancelDownloadCloudMedia<sup>14+</sup> 6899 6900cancelDownloadCloudMedia(): Promise<void> 6901 6902Cancels a task that downloads cloud media assets. 6903 6904**System API**: This is a system API. 6905 6906**System capability**: SystemCapability.FileManagement.PhotoAccessHelper.Core 6907 6908**Return value** 6909 6910| Type | Description | 6911| --------------------------------------- | ----------------- | 6912| Promise<void>| Promise that returns no value.| 6913 6914**Error codes** 6915 6916For details about the error codes, see [Universal Error Codes](../errorcode-universal.md) and [File Management Error Codes](../apis-core-file-kit/errorcode-filemanagement.md). 6917 6918| ID| Error Message| 6919| -------- | ---------------------------------------- | 6920| 201 | Permission denied. | 6921| 202 | Called by non-system application. | 6922| 14000011 | Internal system error. It is recommended to retry and check the logs. Possible causes: 1. Database corrupted; 2. The file system is abnormal; 3. The IPC request timed out. | 6923 6924**Example** 6925 6926```ts 6927import { photoAccessHelper } from '@kit.MediaLibraryKit'; 6928const context = getContext(this); 6929async function example() { 6930 console.info('cancelDownloadCloudMediaDemo'); 6931 try { 6932 let cloudMediaAssetManagerInstance: photoAccessHelper.CloudMediaAssetManager 6933 = photoAccessHelper.CloudMediaAssetManager.getCloudMediaAssetManagerInstance(context); 6934 await cloudMediaAssetManagerInstance.cancelDownloadCloudMedia(); 6935 } catch (err) { 6936 console.error(`cancelDownloadCloudMediaDemo failed with error: ${err.code}, ${err.message}`); 6937 } 6938} 6939``` 6940 6941### retainCloudMediaAsset<sup>14+</sup> 6942 6943retainCloudMediaAsset(retainType: CloudMediaRetainType): Promise<void> 6944 6945Deletes local metadata and files of cloud media assets. 6946 6947**System API**: This is a system API. 6948 6949**System capability**: SystemCapability.FileManagement.PhotoAccessHelper.Core 6950 6951**Parameters** 6952 6953| Name | Type | Mandatory| Description | 6954| -------- | ------------------------- | ---- | ---------- | 6955| retainType | [CloudMediaRetainType](#cloudmediaretaintype14) | Yes | Mode for deleting cloud media assets.| 6956 6957**Return value** 6958 6959| Type | Description | 6960| --------------------------------------- | ----------------- | 6961| Promise<void>| Promise that returns no value.| 6962 6963**Error codes** 6964 6965For details about the error codes, see [Universal Error Codes](../errorcode-universal.md) and [File Management Error Codes](../apis-core-file-kit/errorcode-filemanagement.md). 6966 6967| ID| Error Message| 6968| -------- | ---------------------------------------- | 6969| 201 | Permission denied. | 6970| 202 | Called by non-system application. | 6971| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types; 3. Parameter verification failed. | 6972| 14000011 | Internal system error. It is recommended to retry and check the logs. Possible causes: 1. Database corrupted; 2. The file system is abnormal; 3. The IPC request timed out. | 6973 6974**Example** 6975 6976```ts 6977import { photoAccessHelper } from '@kit.MediaLibraryKit'; 6978const context = getContext(this); 6979async function example() { 6980 console.info('retainCloudMediaAssetDemo'); 6981 try { 6982 let cloudMediaAssetManagerInstance: photoAccessHelper.CloudMediaAssetManager 6983 = photoAccessHelper.CloudMediaAssetManager.getCloudMediaAssetManagerInstance(context); 6984 await cloudMediaAssetManagerInstance.retainCloudMediaAsset(photoAccessHelper.CloudMediaRetainType.RETAIN_FORCE); 6985 } catch (err) { 6986 console.error(`retainCloudMediaAssetDemo failed with error: ${err.code}, ${err.message}`); 6987 } 6988} 6989``` 6990 6991### getCloudMediaAssetStatus<sup>14+</sup> 6992 6993getCloudMediaAssetStatus(): Promise<CloudMediaAssetStatus> 6994 6995Obtains the status of a task that downloads cloud media assets. 6996 6997**System API**: This is a system API. 6998 6999**System capability**: SystemCapability.FileManagement.PhotoAccessHelper.Core 7000 7001**Return value** 7002 7003| Type | Description | 7004| --------------------------------------- | ----------------- | 7005|Promise<[CloudMediaAssetStatus](#cloudmediaassetstatus14)> | Promise used to return the task status.| 7006 7007**Error codes** 7008 7009For details about the error codes, see [Universal Error Codes](../errorcode-universal.md) and [File Management Error Codes](../apis-core-file-kit/errorcode-filemanagement.md). 7010 7011| ID| Error Message| 7012| -------- | ---------------------------------------- | 7013| 201 | Permission denied. | 7014| 202 | Called by non-system application. | 7015| 14000011 | Internal system error. It is recommended to retry and check the logs. Possible causes: 1. Database corrupted; 2. The file system is abnormal; 3. The IPC request timed out. | 7016 7017**Example** 7018 7019```ts 7020import { photoAccessHelper } from '@kit.MediaLibraryKit'; 7021const context = getContext(this); 7022async function example() { 7023 console.info('getCloudMediaAssetStatusDemo'); 7024 try { 7025 let cloudMediaAssetManagerInstance: photoAccessHelper.CloudMediaAssetManager 7026 = photoAccessHelper.CloudMediaAssetManager.getCloudMediaAssetManagerInstance(context); 7027 const cloudMediaAssetStatus: photoAccessHelper.CloudMediaAssetStatus = await cloudMediaAssetManagerInstance.getCloudMediaAssetStatus(); 7028 let taskStatus = cloudMediaAssetStatus.taskStatus; 7029 let taskInfo = cloudMediaAssetStatus.taskInfo; 7030 let errorCode = cloudMediaAssetStatus.errorCode; 7031 let message = `taskStatus: ${taskStatus}, taskInfo: ${taskInfo}, errorCode: ${errorCode}`; 7032 console.log(message); 7033 } catch (err) { 7034 console.error(`getCloudMediaAssetStatusDemo failed with error: ${err.code}, ${err.message}`); 7035 } 7036} 7037``` 7038 7039## PhotoSubtype 7040 7041Enumerates the [PhotoAsset](#photoasset) types. 7042 7043**System capability**: SystemCapability.FileManagement.PhotoAccessHelper.Core 7044 7045| Name | Value| Description| 7046| ----- | ---- | ---- | 7047| SCREENSHOT | 1 | Screenshot and screen recording file.<br>**System API**: This is a system API.| 7048 7049## AlbumType 7050 7051Enumerates the album types. 7052 7053**System capability**: SystemCapability.FileManagement.PhotoAccessHelper.Core 7054 7055| Name | Value | Description | 7056| ------------------- | ---- | ------------------------- | 7057| SMART<sup>11+</sup> | 4096 | Smart analysis album.<br>**System API**: This is a system API.| 7058 7059## AlbumSubtype 7060 7061Enumerate the album subtypes. 7062 7063**System capability**: SystemCapability.FileManagement.PhotoAccessHelper.Core 7064 7065| Name | Value | Description | 7066| --------------------------------- | ---------- | ------------------------------- | 7067| HIDDEN | 1027 | Hidden album. <br>**System API**: This is a system API. | 7068| TRASH | 1028 | Trash. <br>**System API**: This is a system API. | 7069| SCREENSHOT | 1029 | Album for screenshots and screen recording files. <br>**System API**: This is a system API. | 7070| CAMERA | 1030 | Album for photos and videos taken by the camera. <br>**System API**: This is a system API.| 7071| SOURCE\_GENERIC<sup>11+</sup> | 2049 | Source album. <br>**System API**: This is a system API. | 7072| CLASSIFY<sup>11+</sup> | 4097 | Classified album. <br>**System API**: This is a system API. | 7073| GEOGRAPHY\_LOCATION<sup>11+</sup> | 4099 | Geographic location album. <br>**System API**: This is a system API. | 7074| GEOGRAPHY\_CITY<sup>11+</sup> | 4100 | City album. <br>**System API**: This is a system API. | 7075| SHOOTING\_MODE<sup>11+</sup> | 4101 | Shooting mode album. <br>**System API**: This is a system API. | 7076| PORTRAIT<sup>11+</sup> | 4102 | Portrait album. <br>**System API**: This is a system API. | 7077| GROUP_PHOTO<sup>13+</sup> | 4103 | Group photo album. <br>**System API**: This is a system API. | 7078| HIGHLIGHT<sup>12+</sup> | 4104 | Highlights album. <br>**System API**: This is a system API. | 7079| HIGHLIGHT_SUGGESTIONS<sup>12+</sup> | 4105 | Highlights suggestion album. <br>**System API**: This is a system API. | 7080| CLOUD_ENHANCEMENT<sup>13+</sup> | 1032 | AI-powered cloud enhanced album. <br>**System API**: This is a system API. | 7081 7082## RequestPhotoType<sup>11+</sup> 7083 7084Enumerates the types of the operation for obtaining image or video thumbnails. 7085 7086**System API**: This is a system API. 7087 7088**System capability**: SystemCapability.FileManagement.PhotoAccessHelper.Core 7089 7090| Name | Value| Description| 7091| ----- | ---- | ---- | 7092| REQUEST_ALL_THUMBNAILS | 0 | Obtain both the quick thumbnail and the quality thumbnail.| 7093| REQUEST_FAST_THUMBNAIL | 1 | Obtain only the quick thumbnail.| 7094| REQUEST_QUALITY_THUMBNAIL | 2 | Obtain only the quality thumbnail.| 7095 7096## PhotoKeys 7097 7098Defines the key information about an image or video file. 7099 7100**System capability**: SystemCapability.FileManagement.PhotoAccessHelper.Core 7101 7102| Name | Value | Description | 7103| ------------- | ------------------- | ---------------------------------------------------------- | 7104| DATE_TRASHED | 'date_trashed' | Date when the file was deleted. The value is the number of seconds elapsed since the Epoch time. <br>**System API**: This is a system API. | 7105| HIDDEN | 'hidden' | Whether the file is hidden. <br>**System API**: This is a system API. | 7106| CAMERA_SHOT_KEY | 'camera_shot_key' | Key for the Ultra Snapshot feature, which allows the camera to take photos or record videos with the screen off. (This parameter is available only for the system camera, and the key value is defined by the system camera.) <br>**System API**: This is a system API. | 7107| USER_COMMENT<sup>10+</sup> | 'user_comment' | User comment information. <br>**System API**: This is a system API. | 7108| DATE_YEAR<sup>11+</sup> | 'date_year' | Year when the file was created. <br>**System API**: This is a system API. | 7109| DATE_MONTH<sup>11+</sup> | 'date_month' | Month when the file was created. <br>**System API**: This is a system API. | 7110| DATE_DAY<sup>11+</sup> | 'date_day' | Date when the file was created. <br>**System API**: This is a system API. | 7111| PENDING<sup>11+</sup> | 'pending' | Pending state. <br>**System API**: This is a system API. | 7112| DATE_TRASHED_MS<sup>12+</sup> | 'date_trashed_ms' | Date when the file was deleted. The value is the number of milliseconds elapsed since the Epoch time. **System API**: This is a system API.<br>**NOTE**: The photos queried cannot be sorted based on this field.| 7113| MOVING_PHOTO_EFFECT_MODE<sup>12+</sup> | 'moving_photo_effect_mode' | Effect of the moving photo. <br>**System API**: This is a system API.| 7114| CE_AVAILABLE<sup>13+</sup> | 'ce_available' | Cloud enhancement identifier. <br>**System API**: This is a system API.| 7115| SUPPORTED_WATERMARK_TYPE<sup>14+</sup> | 'supported_watermark_type' | Editable watermark identifier. <br>**System API**: This is a system API.| 7116| IS_CE_AUTO<sup>18+</sup> | 'is_auto' | Specifies whether automatic cloud enhancement is supported. <br>**System API**: This is a system API.| 7117 7118## AlbumKeys 7119 7120Enumerates the album keys. 7121 7122**System capability**: SystemCapability.FileManagement.PhotoAccessHelper.Core 7123 7124| Name | Value | Description | 7125| --------------------------------- | -------------------- | ----------------------------------------------------- | 7126| ALBUM_LPATH<sup>18+</sup> | 'lpath' | Virtual path of the album.<br>**System API**: This is a system API. | 7127 7128## HiddenPhotosDisplayMode<sup>11+</sup> 7129 7130Enumerates the display modes of hidden files in the system. 7131 7132**System API**: This is a system API. 7133 7134**System capability**: SystemCapability.FileManagement.PhotoAccessHelper.Core 7135 7136| Name | Value | Description | 7137| ------------- | ------------------- | ---------------------------------------------------------- | 7138| ASSETS_MODE | 0 | Display all hidden files in the system. | 7139| ALBUMS_MODE | 1 | Display hidden files by album (display all albums that contain hidden files in the system, excluding the preset hidden album and the albums in the trash). | 7140 7141## PhotoCreateOptions 7142 7143Options for creating an image or video asset. 7144 7145**System API**: This is a system API. 7146 7147**System capability**: SystemCapability.FileManagement.PhotoAccessHelper.Core 7148 7149| Name | Type | Mandatory| Description | 7150| ---------------------- | ------------------- | ---- | ------------------------------------------------ | 7151| subtype | [PhotoSubtype](#photosubtype) | No | Subtype of the image or video. | 7152| cameraShotKey | string | No | Key for the Ultra Snapshot feature, which allows the camera to take photos or record videos with the screen off. (This parameter is available only for the system camera, and the key value is defined by the system camera.) | 7153 7154## RequestPhotoOptions<sup>11+</sup> 7155 7156Defines the options for obtaining the thumbnail of an image or video. 7157 7158**System API**: This is a system API. 7159 7160**System capability**: SystemCapability.FileManagement.PhotoAccessHelper.Core 7161 7162| Name | Type | Mandatory| Description | 7163| ---------------------- | ------------------- | ---- | ------------------------------------------------ | 7164| size | [image.Size](../apis-image-kit/js-apis-image.md#size) | No | Size of the thumbnail to obtain. | 7165| requestPhotoType | [RequestPhotoType](#requestphototype11) | No | Operation to perform. | 7166 7167## RequestOptions<sup>11+</sup> 7168 7169Represents request options. 7170 7171**System capability**: SystemCapability.FileManagement.PhotoAccessHelper.Core 7172 7173| Name | Type | Readable| Writable| Description | 7174| ---------------------- |---------------------------------| ---- |---- | ------------------------------------------------ | 7175| sourceMode | [SourceMode](#sourcemode11) | Yes | Yes | Type of the asset file requested, which can be the original file or edited file. <br>**System API**: This is a system API.| 7176 7177## PhotoProxy<sup>11+</sup> 7178 7179Photo proxy object, which is used by the camera application to write image data. 7180 7181**System API**: This is a system API. 7182 7183**System capability**: SystemCapability.FileManagement.PhotoAccessHelper.Core 7184 7185## MediaChangeRequest<sup>11+</sup> 7186 7187Media change request, which is the parent class of the asset change request and album change request. 7188 7189> **NOTE**<br>The media change request takes effect only after [applyChanges](js-apis-photoAccessHelper.md#applychanges11) is called. 7190 7191**System capability**: SystemCapability.FileManagement.PhotoAccessHelper.Core 7192 7193## FormInfo<sup>11+</sup> 7194 7195Defines the Gallery widget information. 7196 7197**System API**: This is a system API. 7198 7199**System capability**: SystemCapability.FileManagement.PhotoAccessHelper.Core 7200 7201| Name | Type | Mandatory| Description | 7202| ---------------------- | ------------------- | ---- | ------------------------------------------------ | 7203|formId |string |Yes| Widget ID, which is provided when a widget is created in Gallery.| 7204|uri |string |Yes| URI of the image bound to the widget. When a widget is created, **uri** can be empty or the URI of an image. When a widget is removed, **uri** is not verified and can be empty. | 7205 7206## GalleryFormInfo<sup>18+</sup> 7207 7208Defines the Gallery widget information. 7209 7210**System API**: This is a system API. 7211 7212**System capability**: SystemCapability.FileManagement.PhotoAccessHelper.Core 7213 7214| Name | Type | Mandatory| Description | 7215| ---------------------- | ------------------- | ---- | ------------------------------------------------ | 7216|formId |string |Yes| Widget ID, which is provided when a widget is created in Gallery.| 7217|assetUris |Array<string> |Yes| URIs of the images or albums bound to the widget. This parameter is mandatory when a widget is created or updated and is optional when a widget is removed. | 7218 7219## ResourceType<sup>11+</sup> 7220 7221Enumerates the types of the resources to write. 7222 7223**System capability**: SystemCapability.FileManagement.PhotoAccessHelper.Core 7224 7225| Name | Value| Description| 7226| ----- | ---- | ---- | 7227| PHOTO_PROXY | 3 | Photo proxy. <br>**System API**: This is a system API.| 7228| PRIVATE_MOVING_PHOTO_RESOURCE<sup>13+</sup> | 4 | Private moving photo. <br>**System API**: This is a system API.| 7229| PRIVATE_MOVING_PHOTO_METADATA<sup>18+</sup> | 5 | Metadata resource of the private moving photo. <br>**System API**: This is a system API.| 7230 7231## DefaultChangeUri 7232 7233Enumerates the **DefaultChangeUri** subtypes. 7234 7235**System capability**: SystemCapability.FileManagement.PhotoAccessHelper.Core 7236 7237| Name | Value | Description | 7238| ----------------- | ----------------------- | ------------------------------------------------------------ | 7239| DEFAULT_HIDDEN_ALBUM_URI<sup>11+</sup> | 'file://media/HiddenAlbum' | URI of an album in the hidden albums that are displayed by album, that is, the URI of an album with hidden files. Such albums do not include the preset hidden album and the albums in the trash. This URI is used to subscribe to the change notifications of the hidden albums displayed by album. <br>**System API**: This is a system API.| 7240 7241## SourceMode<sup>11+</sup> 7242 7243Enumerates the types of the file to read. 7244 7245**System API**: This is a system API. 7246 7247**System capability**: SystemCapability.FileManagement.PhotoAccessHelper.Core 7248 7249| Name | Value| Description| 7250| ----- | ---- | ---- | 7251| ORIGINAL_MODE | 0 | Original file.| 7252| EDITED_MODE | 1 | Edited file.| 7253## AuthorizationMode<sup>12+</sup> 7254 7255Enumerates the authorization modes. 7256 7257**System API**: This is a system API. 7258 7259**System capability**: SystemCapability.FileManagement.PhotoAccessHelper.Core 7260 7261| Name | Value| Description| 7262| ----- | ---- | ---- | 7263| SHORT_TIME_AUTHORIZATION| 0 | Temporary authorization.| 7264 7265## AnalysisType<sup>11+</sup> 7266 7267Enumerates the smart analysis types. 7268 7269**System capability**: SystemCapability.FileManagement.PhotoAccessHelper.Core 7270 7271| Name | Value | Description | 7272| :---------------------------- | :- | :------- | 7273| ANALYSIS\_AESTHETICS\_SCORE | 0 | Aesthetics score. <br>**System API**: This is a system API. | 7274| ANALYSIS\_LABEL | 1 | Label. <br>**System API**: This is a system API. | 7275| ANALYSIS\_OCR | 2 | Optical character recognition (OCR) analysis. <br>**System API**: This is a system API. | 7276| ANALYSIS\_FACE | 3 | Facial detection analysis. <br>**System API**: This is a system API. | 7277| ANALYSIS\_OBJECT | 4 | Object detection analysis. <br>**System API**: This is a system API. | 7278| ANALYSIS\_RECOMMENDATION | 5 | Recommendation analysis. <br>**System API**: This is a system API. | 7279| ANALYSIS\_SEGMENTATION | 6 | Segmentation analysis. <br>**System API**: This is a system API. | 7280| ANALYSIS\_COMPOSITION | 7 | Aesthetic composition analysis. <br>**System API**: This is a system API. | 7281| ANALYSIS\_SALIENCY | 8 | Salience analysis. <br>**System API**: This is a system API. | 7282| ANALYSIS\_DETAIL\_ADDRESS | 9 | Detailed address analysis. <br>**System API**: This is a system API. | 7283| ANALYSIS\_HUMAN\_FACE\_TAG<sup>12+</sup> | 10 | Face clustering analysis. <br>**System API**: This is a system API. | 7284| ANALYSIS\_HEAD\_POSITION<sup>12+</sup> | 11 | Analysis of the position of a person's or pet's head. <br>**System API**: This is a system API. | 7285| ANALYSIS\_BONE\_POSE<sup>12+</sup> | 12 | Analysis of the position of skeletal elements (bones) in a human body. <br>**System API**: This is a system API. | 7286| ANALYSIS\_VIDEO\_LABEL<sup>12+</sup> | 13 | Video label analysis. <br>**System API**: This is a system API. | 7287 7288## HighlightAlbumInfoType<sup>12+</sup> 7289 7290Enumerates the types of the highlights album information. 7291 7292**System API**: This is a system API. 7293 7294**System capability**: SystemCapability.FileManagement.PhotoAccessHelper.Core 7295 7296| Name | Value | Description | 7297| :------------ | :- | :------- | 7298| COVER\_INFO | 0 | Cover information. | 7299| PLAY\_INFO | 1 | Music information. | 7300 7301## HighlightUserActionType<sup>12+</sup> 7302 7303Enumerates the user behavior types of the highlights album. 7304 7305**System API**: This is a system API. 7306 7307**System capability**: SystemCapability.FileManagement.PhotoAccessHelper.Core 7308 7309| Name | Value | Description | 7310| :---------------------------- | :- | :------- | 7311| INSERTED\_PIC\_COUNT | 0 | Number of inserted pictures. | 7312| REMOVED\_PIC\_COUNT | 1 | Number of removed pictures. | 7313| SHARED\_SCREENSHOT\_COUNT | 2 | Number of times that a full-length image in a highlights album is shared. | 7314| SHARED\_COVER\_COUNT | 3 | Number of times that a highlights cover is shared. | 7315| RENAMED\_COUNT | 4 | Number of times that a highlights album is renamed. | 7316| CHANGED\_COVER\_COUNT | 5 | Number of times that a cover is changed. | 7317| RENDER\_VIEWED\_TIMES | 100 | Number of times that the pictures in a highlights album are played. | 7318| RENDER\_VIEWED\_DURATION | 101 | Time used to play the pictures in a highlights album. | 7319| ART\_LAYOUT\_VIEWED\_TIMES | 102 | Number of times that a highlights album is viewed. | 7320| ART\_LAYOUT\_VIEWED\_DURATION | 103 | Time used to view a highlights album. | 7321 7322## MovingPhotoEffectMode<sup>12+</sup> 7323 7324Enumerates the effects of a moving photo. 7325 7326**System API**: This is a system API. 7327 7328**System capability**: SystemCapability.FileManagement.PhotoAccessHelper.Core 7329 7330| Name | Value | Description | 7331| :---------------------------- | :- | :------- | 7332| DEFAULT | 0 | Default effect.| 7333| BOUNCE\_PLAY | 1 | Back-and-forth motion.| 7334| LOOP\_PLAY | 2 | Continuously repeated animation.| 7335| LONG\_EXPOSURE | 3 | Long exposure. | 7336| MULTI\_EXPOSURE | 4 | Multiple exposures. | 7337| CINEMA\_GRAPH<sup>13+</sup> | 5 | Cinemagraph. | 7338| IMAGE\_ONLY<sup>13+</sup> | 10 | Image only. | 7339 7340## PhotoPermissionType<sup>12+</sup> 7341 7342Enumerates the types of permissions for accessing media assets. 7343 7344The permissions include temporary read permission and persistent read permission. The temporary read permission will be removed when the application is dead, while the persistent read permission will not. 7345 7346For the same media asset and application, the persistent read permission overwrites the temporary read permission. The temporary read permission does not overwrite the persistent read permission. 7347 7348**System API**: This is a system API. 7349 7350**System capability**: SystemCapability.FileManagement.PhotoAccessHelper.Core 7351 7352| Name | Value| Description| 7353| ----- | ---- | ---- | 7354| TEMPORARY_READ_IMAGEVIDEO | 0 | Temporary read permission.| 7355| PERSISTENT_READ_IMAGEVIDEO | 1 | Persistent read permission.| 7356 7357## HideSensitiveType<sup>12+</sup> 7358 7359Enumerates the types of media resource information to be hidden from an application. 7360 7361**System API**: This is a system API. 7362 7363**System capability**: SystemCapability.FileManagement.PhotoAccessHelper.Core 7364 7365| Name | Value| Description| 7366| ----- | ---- | ---- | 7367| HIDE_LOCATION_AND_SHOOTING_PARAM | 0 | Geographical location and shooting parameters.| 7368| HIDE_LOCATION_ONLY | 1 | Geographical location information.| 7369| HIDE_SHOOTING_PARAM_ONLY | 2 | Shooting parameters.| 7370| NO_HIDE_SENSITIVE_TYPE | 3 | Do not hide any information.| 7371 7372## CloudEnhancementTaskStage<sup>13+</sup> 7373 7374Enumerates the cloud enhancement task states, which are returned by [CloudEnhancementTaskState](#cloudenhancement13). 7375 7376**System API**: This is a system API. 7377 7378**System capability**: SystemCapability.FileManagement.PhotoAccessHelper.Core 7379 7380| Name | Value| Description| 7381| ----- | ---- | ---- | 7382| TASK_STAGE_EXCEPTION | -1 | The cloud enhancement task is abnormal.| 7383| TASK_STAGE_PREPARING | 0 | The cloud enhancement task is being prepared.| 7384| TASK_STAGE_UPLOADING | 1 | The cloud enhancement task is uploading data.| 7385| TASK_STAGE_EXECUTING | 2 | The cloud enhancement task is being executed.| 7386| TASK_STAGE_DOWNLOADING | 3 | The cloud enhancement task is downloading data.| 7387| TASK_STAGE_FAILED | 4 | The cloud enhancement task failed.| 7388| TASK_STAGE_COMPLETED | 5 | The cloud enhancement task is complete.| 7389 7390## CloudEnhancementState<sup>13+</sup> 7391 7392Enumerates the cloud enhancement states. 7393 7394**System API**: This is a system API. 7395 7396**System capability**: SystemCapability.FileManagement.PhotoAccessHelper.Core 7397 7398| Name | Value| Description| 7399| ----- | ---- | ---- | 7400| UNAVAILABLE | 0 | Cloud enhancement is unavailable.| 7401| AVAILABLE | 1 | Cloud enhancement is available.| 7402| EXECUTING | 2 | Cloud enhancement is being executed.| 7403| COMPLETED | 3 | Cloud enhancement has been completed.| 7404 7405## CloudEnhancementTaskState<sup>13+</sup> 7406 7407Represents the cloud enhancement task information, which includes the cloud enhancement task state and other information related to certain states. 7408 7409**System API**: This is a system API. 7410 7411**System capability**: SystemCapability.FileManagement.PhotoAccessHelper.Core 7412 7413| Name | Type | Mandatory| Description | 7414| ---------------------- | ------------------- | ---- | ------------------------------------------------ | 7415|taskStage |[CloudEnhancementTaskStage](#cloudenhancementtaskstage13) |Yes| Cloud enhancement task state.| 7416|transferredFileSize |number |No| Size of the file transferred. This parameter is mandatory when **taskStage** is **CloudEnhancementTaskStage.TASK_STAGE_UPLOADING** or **CloudEnhancementTaskStage.TASK_STAGE_DOWNLOADING**. | 7417|totalFileSize |number |No| Total file size. This parameter is mandatory when **taskStage** is **CloudEnhancementTaskStage.TASK_STAGE_UPLOADING** or **CloudEnhancementTaskStage.TASK_STAGE_DOWNLOADING**. | 7418|expectedDuration |number |No| Queuing time. This parameter is mandatory when **taskStage** is **CloudEnhancementTaskStage.TASK_STAGE_EXECUTING**. | 7419|statusCode |number |No| Status code. This parameter is mandatory when **taskStage** is **CloudEnhancementTaskStage.TASK_STAGE_FAILED**. | 7420 7421## VideoEnhancementType<sup>13+</sup> 7422 7423Enumerates the types of segmented video enhancement. 7424 7425**System API**: This is a system API. 7426 7427**System capability**: SystemCapability.FileManagement.PhotoAccessHelper.Core 7428 7429| Name | Value| Description| 7430| ----- | ---- | ---- | 7431| QUALITY_ENHANCEMENT_LOCAL | 0 | Apply enhancement on the device.| 7432| QUALITY_ENHANCEMENT_CLOUD | 1 | Apply enhancement on the cloud.| 7433| QUALITY_ENHANCEMENT_LOCAL_AND_CLOUD | 2 | Apply enhancement on both the device and cloud.| 7434 7435## ThumbnailType<sup>13+</sup> 7436 7437Enumerates thumbnail types. 7438 7439**System API**: This is a system API. 7440 7441**System capability**: SystemCapability.FileManagement.PhotoAccessHelper.Core 7442 7443| Name | Value | Description | 7444| :---------------------------- | :- | :------- | 7445| LCD | 1 | LCD thumbnail. | 7446| THM | 2 | THM thumbnail. | 7447 7448## WatermarkType<sup>14+</sup> 7449 7450Enumerates the watermark editable flags. 7451 7452**System API**: This is a system API. 7453 7454**System capability**: SystemCapability.FileManagement.PhotoAccessHelper.Core 7455 7456| Name | Value| Description| 7457| ----- | ---- | ---- | 7458| DEFAULT | 0 | Watermarks are not editable.| 7459| BRAND_COMMON | 1 | Brand and common watermarks are editable.| 7460| COMMON | 2 | Common watermarks are editable.| 7461| BRAND | 3 | Brand watermarks are editable.| 7462 7463## CloudMediaDownloadType<sup>14+</sup> 7464 7465Enumerates the types of download tasks. 7466 7467**System API**: This is a system API. 7468 7469**System capability**: SystemCapability.FileManagement.PhotoAccessHelper.Core 7470 7471| Name | Value| Description| 7472| ----- | ---- | ---- | 7473| DOWNLOAD_FORCE | 0 | High-priority download, without the need for the device to switch to screen-off charging mode.| 7474| DOWNLOAD_GENTLE | 1 | Low-priority download, demanding that device be in screen-off charging mode.| 7475 7476## CloudMediaRetainType<sup>14+</sup> 7477 7478Enumerates the modes used for deleting cloud media assets. 7479 7480**System API**: This is a system API. 7481 7482**System capability**: SystemCapability.FileManagement.PhotoAccessHelper.Core 7483 7484| Name | Value| Description| 7485| ----- | ---- | ---- | 7486| RETAIN_FORCE | 0 | Deletes the local metadata and thumbnail of the original files from the cloud.| 7487 7488## CloudMediaAssetTaskStatus<sup>14+</sup> 7489 7490Enumerates the statuses of tasks used for downloading cloud media assets. 7491 7492**System API**: This is a system API. 7493 7494**System capability**: SystemCapability.FileManagement.PhotoAccessHelper.Core 7495 7496| Name | Value| Description| 7497| ----- | ---- | ---- | 7498| DOWNLOADING | 0 | The task is in progress.| 7499| PAUSED | 1 | The task is paused.| 7500| IDLE | 2 | There is no download task.| 7501 7502## CloudMediaTaskPauseCause<sup>14+</sup> 7503 7504Enumerates the reasons why a cloud media asset download task is paused. 7505 7506**System API**: This is a system API. 7507 7508**System capability**: SystemCapability.FileManagement.PhotoAccessHelper.Core 7509 7510| Name | Value| Description| 7511| ----- | ---- | ---- | 7512| NO_PAUSE | 0 | Downloading is proceeding normally without any pauses.| 7513| TEMPERATURE_LIMIT | 1 | The device temperature is excessively high.| 7514| ROM_LIMIT | 2 | The local disk space is insufficient.| 7515| NETWORK_FLOW_LIMIT | 3 | Network traffic is restricted, and Wi-Fi is not available.| 7516| WIFI_UNAVAILABLE | 4 | The network is abnormal.| 7517| POWER_LIMIT | 5 | Power usage is restricted.| 7518| BACKGROUND_TASK_UNAVAILABLE | 6 | The device is not in charging screen-off mode.| 7519| FREQUENT_USER_REQUESTS | 7 | The user is making requests too frequently.| 7520| CLOUD_ERROR | 8 | There is an error with the cloud service.| 7521| USER_PAUSED | 9 | The download has been paused by the user.| 7522 7523## CloudMediaAssetStatus<sup>14+</sup> 7524 7525Describes the details of a cloud media asset download task. It is the return value of the API used by applications to obtain the cloud asset download task status. 7526 7527**System API**: This is a system API. 7528 7529**System capability**: SystemCapability.FileManagement.PhotoAccessHelper.Core 7530 7531| Name | Type | Mandatory| Description | 7532| ---------------------- | ------------------- | ---- | ------------------------------------------------ | 7533|taskStatus |[CloudMediaAssetTaskStatus](#cloudmediaassettaskstatus14) |Yes| Status of the download task.| 7534|taskInfo |string |Yes| Total number of and size (measured in bytes) of the assets that have been downloaded, and the total number and size (also measured in bytes) of the assets remaining to be downloaded. | 7535|errorCode |[CloudMediaTaskPauseCause](#cloudmediataskpausecause14) |Yes| Reason why the download task is suspended.| 7536