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> . .. \ / : * ? " ' ` < > | { } [ ] 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 invoked 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> . .. \ / : * ? " ' ` < > | { } [ ] 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### createAsset 131 132createAsset(displayName: string, options: PhotoCreateOptions, callback: AsyncCallback<PhotoAsset>): void 133 134Creates an image or video asset with the specified file name and options. This API uses an asynchronous callback to return the result. 135 136The file name must comply with the following specifications: 137- The file name consists of a valid file name and an image or video file name extension. 138- The file name cannot exceed 255 characters. 139- The file name cannot contain any of the following characters:<br> . .. \ / : * ? " ' ` < > | { } [ ] 140 141**System API**: This is a system API. 142 143**System capability**: SystemCapability.FileManagement.PhotoAccessHelper.Core 144 145**Required permissions**: ohos.permission.WRITE_IMAGEVIDEO 146 147**Parameters** 148 149| Name | Type | Mandatory| Description | 150| -------- | ------------------------ | ---- | ------------------------- | 151| displayName | string | Yes | File name of the image or video to create. | 152| options | [PhotoCreateOptions](#photocreateoptions) | Yes | Options for creating an image or video asset. | 153| callback | AsyncCallback<[PhotoAsset](#photoasset)> | Yes | Callback invoked to return the image or video created.| 154 155**Error codes** 156 157For details about the error codes, see [Universal Error Codes](../errorcode-universal.md) and [File Management Error Codes](../apis-core-file-kit/errorcode-filemanagement.md). 158 159| ID| Error Message| 160| -------- | ---------------------------------------- | 161| 202 | Called by non-system application. | 162| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types; 3. Parameter verification failed. | 163| 13900012 | Permission denied. | 164| 13900020 | Invalid argument. | 165| 14000001 | Invalid display name. | 166| 14000011 | System inner fail. | 167 168**Example** 169 170```ts 171async function example() { 172 console.info('createAssetDemo'); 173 let testFileName: string = 'testFile' + Date.now() + '.jpg'; 174 let createOption: photoAccessHelper.PhotoCreateOptions = { 175 subtype: photoAccessHelper.PhotoSubtype.DEFAULT 176 } 177 phAccessHelper.createAsset(testFileName, createOption, (err, photoAsset) => { 178 if (photoAsset !== undefined) { 179 console.info('createAsset file displayName' + photoAsset.displayName); 180 console.info('createAsset successfully'); 181 } else { 182 console.error(`createAsset failed, error: ${err.code}, ${err.message}`); 183 } 184 }); 185} 186``` 187 188### createAsset 189 190createAsset(displayName: string, options: PhotoCreateOptions): Promise<PhotoAsset> 191 192Creates an image or video asset with the specified file name and options. This API uses a promise to return the result. 193 194The file name must comply with the following specifications: 195- The file name consists of a valid file name and an image or video file name extension. 196- The file name cannot exceed 255 characters. 197- The file name cannot contain any of the following characters:<br> . .. \ / : * ? " ' ` < > | { } [ ] 198 199**System API**: This is a system API. 200 201**System capability**: SystemCapability.FileManagement.PhotoAccessHelper.Core 202 203**Required permissions**: ohos.permission.WRITE_IMAGEVIDEO 204 205**Parameters** 206 207| Name | Type | Mandatory| Description | 208| -------- | ------------------------ | ---- | ------------------------- | 209| displayName | string | Yes | File name of the image or video to create. | 210| options | [PhotoCreateOptions](#photocreateoptions) | Yes | Options for creating an image or video asset. | 211 212**Return value** 213 214| Type | Description | 215| --------------------------- | -------------- | 216| Promise<[PhotoAsset](#photoasset)> | Promise used to return the created image and video asset.| 217 218**Error codes** 219 220For details about the error codes, see [Universal Error Codes](../errorcode-universal.md) and [File Management Error Codes](../apis-core-file-kit/errorcode-filemanagement.md). 221 222| ID| Error Message| 223| -------- | ---------------------------------------- | 224| 202 | Called by non-system application. | 225| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types; 3. Parameter verification failed. | 226| 13900012 | Permission denied. | 227| 13900020 | Invalid argument. | 228| 14000001 | Invalid display name. | 229| 14000011 | System inner fail. | 230 231**Example** 232 233```ts 234async function example() { 235 console.info('createAssetDemo'); 236 try { 237 let testFileName:string = 'testFile' + Date.now() + '.jpg'; 238 let createOption: photoAccessHelper.PhotoCreateOptions = { 239 subtype: photoAccessHelper.PhotoSubtype.DEFAULT 240 } 241 let photoAsset: photoAccessHelper.PhotoAsset = await phAccessHelper.createAsset(testFileName, createOption); 242 console.info('createAsset file displayName' + photoAsset.displayName); 243 console.info('createAsset successfully'); 244 } catch (err) { 245 console.error(`createAsset failed, error: ${err.code}, ${err.message}`); 246 } 247} 248``` 249 250### createAlbum<sup>(deprecated)</sup> 251 252createAlbum(name: string, callback: AsyncCallback<Album>): void 253 254Creates an album. This API uses an asynchronous callback to return the result. 255 256The album name must meet the following requirements: 257- The album name cannot exceed 255 characters. 258- The album name cannot contain any of the following characters:<br> . .. \ / : * ? " ' ` < > | { } [ ] 259- The album name is case-insensitive. 260- Duplicate album names are not allowed. 261 262> **NOTE** 263> 264> This API is supported since API version 10 and deprecated since API version 11. Use [MediaAlbumChangeRequest.createAlbumRequest](#createalbumrequest11) instead. 265 266**System API**: This is a system API. 267 268**System capability**: SystemCapability.FileManagement.PhotoAccessHelper.Core 269 270**Required permissions**: ohos.permission.WRITE_IMAGEVIDEO 271 272**Parameters** 273 274| Name | Type | Mandatory| Description | 275| -------- | ------------------------ | ---- | ------------------------- | 276| name | string | Yes | Name of the album to create. | 277| callback | AsyncCallback<[Album](#album)> | Yes | Callback invoked to return the created album instance.| 278 279**Error codes** 280 281For details about the error codes, see [Universal Error Codes](../errorcode-universal.md) and [File Management Error Codes](../apis-core-file-kit/errorcode-filemanagement.md). 282 283| ID| Error Message| 284| -------- | ---------------------------------------- | 285| 202 | Called by non-system application. | 286| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types; 3. Parameter verification failed. | 287| 13900012 | Permission denied. | 288| 13900015 | File exists. | 289| 13900020 | Invalid argument. | 290| 14000011 | System inner fail. | 291 292**Example** 293 294```ts 295async function example() { 296 console.info('createAlbumDemo'); 297 let albumName: string = 'newAlbumName' + new Date().getTime(); 298 phAccessHelper.createAlbum(albumName, (err, album) => { 299 if (err) { 300 console.error(`createAlbumCallback failed with err: ${err.code}, ${err.message}`); 301 return; 302 } 303 console.info('createAlbumCallback successfully, album: ' + album.albumName + ' album uri: ' + album.albumUri); 304 }); 305} 306``` 307 308### createAlbum<sup>(deprecated)</sup> 309 310createAlbum(name: string): Promise<Album> 311 312Creates an album. This API uses a promise to return the result. 313 314The album name must meet the following requirements: 315- The album name cannot exceed 255 characters. 316- The album name cannot contain any of the following characters:<br> . .. \ / : * ? " ' ` < > | { } [ ] 317- The album name is case-insensitive. 318- Duplicate album names are not allowed. 319 320> **NOTE** 321> 322> This API is supported since API version 10 and deprecated since API version 11. Use [MediaAlbumChangeRequest.createAlbumRequest](#createalbumrequest11) instead. 323 324**System API**: This is a system API. 325 326**System capability**: SystemCapability.FileManagement.PhotoAccessHelper.Core 327 328**Required permissions**: ohos.permission.WRITE_IMAGEVIDEO 329 330**Parameters** 331 332| Name | Type | Mandatory| Description | 333| -------- | ------------------------ | ---- | ------------------------- | 334| name | string | Yes | Name of the album to create. | 335 336**Return value** 337 338| Type | Description | 339| --------------------------- | -------------- | 340| Promise<[Album](#album)> | Promise used to return the created album instance.| 341 342**Error codes** 343 344For details about the error codes, see [Universal Error Codes](../errorcode-universal.md) and [File Management Error Codes](../apis-core-file-kit/errorcode-filemanagement.md). 345 346| ID| Error Message| 347| -------- | ---------------------------------------- | 348| 202 | Called by non-system application. | 349| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types; 3. Parameter verification failed. | 350| 13900012 | Permission denied. | 351| 13900015 | File exists. | 352| 13900020 | Invalid argument. | 353| 14000011 | System inner fail. | 354 355**Example** 356 357```ts 358import { BusinessError } from '@kit.BasicServicesKit'; 359 360async function example() { 361 console.info('createAlbumDemo'); 362 let albumName: string = 'newAlbumName' + new Date().getTime(); 363 phAccessHelper.createAlbum(albumName).then((album) => { 364 console.info('createAlbumPromise successfully, album: ' + album.albumName + ' album uri: ' + album.albumUri); 365 }).catch((err: BusinessError) => { 366 console.error(`createAlbumPromise failed with err: ${err.code}, ${err.message}`); 367 }); 368} 369``` 370 371### deleteAlbums<sup>(deprecated)</sup> 372 373deleteAlbums(albums: Array<Album>, callback: AsyncCallback<void>): void 374 375Deletes albums. This API uses an asynchronous callback to return the result. 376 377Ensure that the albums to be deleted exist. Only user albums can be deleted. 378 379> **NOTE** 380> 381> This API is supported since API version 10 and deprecated since API version 11. Use [MediaAlbumChangeRequest.deleteAlbums](#deletealbums11) instead. 382 383**System API**: This is a system API. 384 385**System capability**: SystemCapability.FileManagement.PhotoAccessHelper.Core 386 387**Required permissions**: ohos.permission.WRITE_IMAGEVIDEO 388 389**Parameters** 390 391| Name | Type | Mandatory| Description | 392| -------- | ------------------------ | ---- | ------------------------- | 393| albums | Array<[Album](#album)> | Yes | Albums to delete. | 394| callback | AsyncCallback<void> | Yes | Callback that returns no value.| 395 396**Error codes** 397 398For details about the error codes, see [Universal Error Codes](../errorcode-universal.md) and [File Management Error Codes](../apis-core-file-kit/errorcode-filemanagement.md). 399 400| ID| Error Message| 401| -------- | ---------------------------------------- | 402| 202 | Called by non-system application. | 403| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types; 3. Parameter verification failed. | 404| 13900012 | Permission denied. | 405| 13900020 | Invalid argument. | 406| 14000011 | System inner fail. | 407 408**Example** 409 410```ts 411import { dataSharePredicates } from '@kit.ArkData'; 412 413async function example() { 414 // Delete the album named newAlbumName. 415 console.info('deleteAlbumsDemo'); 416 let predicates: dataSharePredicates.DataSharePredicates = new dataSharePredicates.DataSharePredicates(); 417 predicates.equalTo('album_name', 'newAlbumName'); 418 let fetchOptions: photoAccessHelper.FetchOptions = { 419 fetchColumns: [], 420 predicates: predicates 421 }; 422 let fetchResult: photoAccessHelper.FetchResult<photoAccessHelper.Album> = await phAccessHelper.getAlbums(photoAccessHelper.AlbumType.USER, photoAccessHelper.AlbumSubtype.USER_GENERIC, fetchOptions); 423 let album: photoAccessHelper.Album = await fetchResult.getFirstObject(); 424 phAccessHelper.deleteAlbums([album], (err) => { 425 if (err) { 426 console.error(`deletePhotoAlbumsCallback failed with err: ${err.code}, ${err.message}`); 427 return; 428 } 429 console.info('deletePhotoAlbumsCallback successfully'); 430 }); 431 fetchResult.close(); 432} 433``` 434 435### deleteAlbums<sup>(deprecated)</sup> 436 437deleteAlbums(albums: Array<Album>): Promise<void> 438 439Deletes albums. This API uses a promise to return the result. 440 441Ensure that the albums to be deleted exist. Only user albums can be deleted. 442 443> **NOTE** 444> 445> This API is supported since API version 10 and deprecated since API version 11. Use [MediaAlbumChangeRequest.deleteAlbums](#deletealbums11) instead. 446 447**System API**: This is a system API. 448 449**System capability**: SystemCapability.FileManagement.PhotoAccessHelper.Core 450 451**Required permissions**: ohos.permission.WRITE_IMAGEVIDEO 452 453**Parameters** 454 455| Name | Type | Mandatory| Description | 456| -------- | ------------------------ | ---- | ------------------------- | 457| albums | Array<[Album](#album)> | Yes | Albums to delete. | 458 459**Return value** 460 461| Type | Description | 462| --------------------------- | -------------- | 463| Promise<void> | Promise that returns no value.| 464 465**Error codes** 466 467For details about the error codes, see [Universal Error Codes](../errorcode-universal.md) and [File Management Error Codes](../apis-core-file-kit/errorcode-filemanagement.md). 468 469| ID| Error Message| 470| -------- | ---------------------------------------- | 471| 202 | Called by non-system application. | 472| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types; 3. Parameter verification failed. | 473| 13900012 | Permission denied. | 474| 13900020 | Invalid argument. | 475| 14000011 | System inner fail. | 476 477**Example** 478 479```ts 480import { dataSharePredicates } from '@kit.ArkData'; 481import { BusinessError } from '@kit.BasicServicesKit'; 482 483async function example() { 484 // Delete the album named newAlbumName. 485 console.info('deleteAlbumsDemo'); 486 let predicates: dataSharePredicates.DataSharePredicates = new dataSharePredicates.DataSharePredicates(); 487 predicates.equalTo('album_name', 'newAlbumName'); 488 let fetchOptions: photoAccessHelper.FetchOptions = { 489 fetchColumns: [], 490 predicates: predicates 491 }; 492 let fetchResult: photoAccessHelper.FetchResult<photoAccessHelper.Album> = await phAccessHelper.getAlbums(photoAccessHelper.AlbumType.USER, photoAccessHelper.AlbumSubtype.USER_GENERIC, fetchOptions); 493 let album: photoAccessHelper.Album = await fetchResult.getFirstObject(); 494 phAccessHelper.deleteAlbums([album]).then(() => { 495 console.info('deletePhotoAlbumsPromise successfully'); 496 }).catch((err: BusinessError) => { 497 console.error(`deletePhotoAlbumsPromise failed with err: ${err.code}, ${err.message}`); 498 }); 499 fetchResult.close(); 500} 501``` 502 503### getHiddenAlbums<sup>11+</sup> 504 505getHiddenAlbums(mode: HiddenPhotosDisplayMode, options: FetchOptions, callback: AsyncCallback<FetchResult<Album>>): void 506 507Obtains hidden albums based on the specified display mode and retrieval options. This API uses an asynchronous callback to return the result. 508 509**System API**: This is a system API. 510 511**Required permissions**: ohos.permission.READ_IMAGEVIDEO and ohos.permission.MANAGE_PRIVATE_PHOTOS 512 513**System capability**: SystemCapability.FileManagement.PhotoAccessHelper.Core 514 515**Parameters** 516 517| Name | Type | Mandatory| Description | 518| -------- | ------------------------ | ---- | ------------------------- | 519| mode | [HiddenPhotosDisplayMode](#hiddenphotosdisplaymode11) | Yes | Display mode of hidden files. | 520| options | [FetchOptions](js-apis-photoAccessHelper.md#fetchoptions) | Yes | Options for retrieving the hidden files. | 521| callback | AsyncCallback<[FetchResult](js-apis-photoAccessHelper.md#fetchresult)<[Album](#album)>> | Yes | Callback invoked to return the result.| 522 523**Error codes** 524 525For details about the error codes, see [Universal Error Codes](../errorcode-universal.md) and [File Management Error Codes](../apis-core-file-kit/errorcode-filemanagement.md). 526 527| ID| Error Message| 528| -------- | ---------------------------------------- | 529| 201 | Permission verification failed, usually the result returned by VerifyAccessToken. | 530| 202 | Permission verification failed, application which is not a system application uses system API. | 531| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types; 3. Parameter verification failed. | 532| 14000011 | System inner fail. | 533 534**Example** 535 536```ts 537import { dataSharePredicates } from '@kit.ArkData'; 538 539// Obtain the album newAlbumName that contains hidden files. 540async function getHiddenAlbumsView() { 541 console.info('getHiddenAlbumsViewDemo'); 542 let predicates: dataSharePredicates.DataSharePredicates = new dataSharePredicates.DataSharePredicates(); 543 predicates.equalTo('album_name', 'newAlbumName'); 544 let fetchOptions: photoAccessHelper.FetchOptions = { 545 fetchColumns: [], 546 predicates: predicates 547 }; 548 phAccessHelper.getHiddenAlbums(photoAccessHelper.HiddenPhotosDisplayMode.ALBUMS_MODE, fetchOptions, 549 async (err, fetchResult) => { 550 if (fetchResult === undefined) { 551 console.error('getHiddenAlbumsViewCallback fetchResult is undefined'); 552 return; 553 } 554 let album = await fetchResult.getFirstObject(); 555 console.info('getHiddenAlbumsViewCallback successfully, album name: ' + album.albumName); 556 fetchResult.close(); 557 }); 558} 559``` 560 561### getHiddenAlbums<sup>11+</sup> 562 563getHiddenAlbums(mode: HiddenPhotosDisplayMode, callback: AsyncCallback<FetchResult<Album>>): void 564 565Obtains hidden albums based on the specified display mode. This API uses an asynchronous callback to return the result. 566 567**System API**: This is a system API. 568 569**Required permissions**: ohos.permission.READ_IMAGEVIDEO and ohos.permission.MANAGE_PRIVATE_PHOTOS 570 571**System capability**: SystemCapability.FileManagement.PhotoAccessHelper.Core 572 573**Parameters** 574 575| Name | Type | Mandatory| Description | 576| -------- | ------------------------ | ---- | ------------------------- | 577| mode | [HiddenPhotosDisplayMode](#hiddenphotosdisplaymode11) | Yes | Display mode of hidden files. | 578| callback | AsyncCallback<[FetchResult](js-apis-photoAccessHelper.md#fetchresult)<[Album](#album)>> | Yes | Callback invoked to return the result.| 579 580**Error codes** 581 582For details about the error codes, see [Universal Error Codes](../errorcode-universal.md) and [File Management Error Codes](../apis-core-file-kit/errorcode-filemanagement.md). 583 584| ID| Error Message| 585| -------- | ---------------------------------------- | 586| 201 | Permission verification failed, usually the result returned by VerifyAccessToken. | 587| 202 | Permission verification failed, application which is not a system application uses system API. | 588| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types; 3. Parameter verification failed. | 589| 14000011 | System inner fail. | 590 591**Example** 592 593```ts 594import { dataSharePredicates } from '@kit.ArkData'; 595 596// Obtain the preset hidden album. 597async function getSysHiddenAlbum() { 598 console.info('getSysHiddenAlbumDemo'); 599 phAccessHelper.getHiddenAlbums(photoAccessHelper.HiddenPhotosDisplayMode.ASSETS_MODE, async (err, fetchResult) => { 600 if (fetchResult === undefined) { 601 console.error('getSysHiddenAlbumCallback fetchResult is undefined'); 602 return; 603 } 604 let hiddenAlbum: photoAccessHelper.Album = await fetchResult.getFirstObject(); 605 console.info('getSysHiddenAlbumCallback successfully, albumUri: ' + hiddenAlbum.albumUri); 606 fetchResult.close(); 607 }); 608} 609 610// 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. 611async function getHiddenAlbumsView() { 612 console.info('getHiddenAlbumsViewDemo'); 613 phAccessHelper.getHiddenAlbums(photoAccessHelper.HiddenPhotosDisplayMode.ALBUMS_MODE, async (err, fetchResult) => { 614 if (fetchResult === undefined) { 615 console.error('getHiddenAlbumsViewCallback fetchResult is undefined'); 616 return; 617 } 618 let albums: Array<photoAccessHelper.Album> = await fetchResult.getAllObjects(); 619 console.info('getHiddenAlbumsViewCallback successfully, albums size: ' + albums.length); 620 621 let predicates: dataSharePredicates.DataSharePredicates = new dataSharePredicates.DataSharePredicates(); 622 let fetchOption: photoAccessHelper.FetchOptions = { 623 fetchColumns: [], 624 predicates: predicates 625 }; 626 for (let i = 0; i < albums.length; i++) { 627 // Obtain hidden files in the album. 628 albums[i].getAssets(fetchOption, (err, assetFetchResult) => { 629 console.info('album get hidden assets successfully, getCount: ' + assetFetchResult.getCount()); 630 }); 631 } 632 fetchResult.close(); 633 }); 634} 635``` 636 637### getHiddenAlbums<sup>11+</sup> 638 639getHiddenAlbums(mode: HiddenPhotosDisplayMode, options?: FetchOptions): Promise<FetchResult<Album>> 640 641Obtains hidden albums based on the specified display mode and retrieval options. This API uses a promise to return the result. 642 643**System API**: This is a system API. 644 645**Required permissions**: ohos.permission.READ_IMAGEVIDEO and ohos.permission.MANAGE_PRIVATE_PHOTOS 646 647**System capability**: SystemCapability.FileManagement.PhotoAccessHelper.Core 648 649**Parameters** 650 651| Name | Type | Mandatory| Description | 652| -------- | ------------------------ | ---- | ------------------------- | 653| mode | [HiddenPhotosDisplayMode](#hiddenphotosdisplaymode11) | Yes | Display mode of hidden files. | 654| 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. | 655 656**Return value** 657 658| Type | Description | 659| --------------------------- | -------------- | 660| Promise<[FetchResult](js-apis-photoAccessHelper.md#fetchresult)<[Album](#album)>> | Promise used to return the result. 661 662**Error codes** 663 664For details about the error codes, see [Universal Error Codes](../errorcode-universal.md) and [File Management Error Codes](../apis-core-file-kit/errorcode-filemanagement.md). 665 666| ID| Error Message| 667| -------- | ---------------------------------------- | 668| 201 | Permission verification failed, usually the result returned by VerifyAccessToken. | 669| 202 | Permission verification failed, application which is not a system application uses system API. | 670| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types; 3. Parameter verification failed. | 671| 14000011 | System inner fail. | 672 673**Example** 674 675```ts 676import { dataSharePredicates } from '@kit.ArkData'; 677import { BusinessError } from '@kit.BasicServicesKit'; 678 679// Obtain the preset hidden album. 680async function getSysHiddenAlbum() { 681 console.info('getSysHiddenAlbumDemo'); 682 phAccessHelper.getHiddenAlbums(photoAccessHelper.HiddenPhotosDisplayMode.ASSETS_MODE) 683 .then( async (fetchResult) => { 684 if (fetchResult === undefined) { 685 console.error('getSysHiddenAlbumPromise fetchResult is undefined'); 686 return; 687 } 688 let hiddenAlbum: photoAccessHelper.Album = await fetchResult.getFirstObject(); 689 console.info('getAlbumsPromise successfully, albumUri: ' + hiddenAlbum.albumUri); 690 fetchResult.close(); 691 }).catch((err: BusinessError) => { 692 console.error(`getSysHiddenAlbumPromise failed with err: ${err.code}, ${err.message}`); 693 }); 694} 695 696// 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. 697async function getHiddenAlbumsView() { 698 console.info('getHiddenAlbumsViewDemo'); 699 phAccessHelper.getHiddenAlbums(photoAccessHelper.HiddenPhotosDisplayMode.ALBUMS_MODE).then( async (fetchResult) => { 700 if (fetchResult === undefined) { 701 console.error('getHiddenAlbumsViewPromise fetchResult is undefined'); 702 return; 703 } 704 let albums: Array<photoAccessHelper.Album> = await fetchResult.getAllObjects(); 705 console.info('getHiddenAlbumsViewPromise successfully, albums size: ' + albums.length); 706 707 let predicates: dataSharePredicates.DataSharePredicates = new dataSharePredicates.DataSharePredicates(); 708 let fetchOption: photoAccessHelper.FetchOptions = { 709 fetchColumns: [], 710 predicates: predicates 711 }; 712 for (let i = 0; i < albums.length; i++) { 713 // Obtain hidden files in the album. 714 albums[i].getAssets(fetchOption).then((assetFetchResult) => { 715 console.info('album get hidden assets successfully, getCount: ' + assetFetchResult.getCount()); 716 }).catch((err: BusinessError) => { 717 console.error(`album get hidden assets failed with error: ${err.code}, ${err.message}`); 718 }); 719 } 720 fetchResult.close(); 721 }).catch((err: BusinessError) => { 722 console.error(`getHiddenAlbumsViewPromise failed with err: ${err.code}, ${err.message}`); 723 }); 724} 725``` 726 727### deleteAssets<sup>(deprecated)</sup> 728 729deleteAssets(uriList: Array<string>, callback: AsyncCallback<void>): void 730 731Deletes media assets. This API uses an asynchronous callback to return the result. The deleted assets are moved to the trash. 732 733> **NOTE** 734> 735> This API is supported since API version 10 and deprecated since API version 11. Use [MediaAssetChangeRequest.deleteAssets](js-apis-photoAccessHelper.md#deleteassets11) instead. 736 737**System API**: This is a system API. 738 739**Required permissions**: ohos.permission.WRITE_IMAGEVIDEO 740 741**System capability**: SystemCapability.FileManagement.PhotoAccessHelper.Core 742 743**Parameters** 744 745| Name | Type | Mandatory| Description | 746| -------- | ------------------------- | ---- | ---------- | 747| uriList | Array<string> | Yes | URIs of the media files to delete.| 748| callback | AsyncCallback<void> | Yes | Callback that returns no value.| 749 750**Error codes** 751 752For details about the error codes, see [Universal Error Codes](../errorcode-universal.md) and [File Management Error Codes](../apis-core-file-kit/errorcode-filemanagement.md). 753 754| ID| Error Message| 755| -------- | ---------------------------------------- | 756| 202 | Called by non-system application. | 757| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types; 3. Parameter verification failed. | 758| 13900012 | Permission denied. | 759| 13900020 | Invalid argument. | 760| 14000002 | Invalid uri. | 761| 14000011 | System inner fail. | 762 763**Example** 764 765```ts 766import { dataSharePredicates } from '@kit.ArkData'; 767 768async function example() { 769 console.info('deleteAssetDemo'); 770 let predicates: dataSharePredicates.DataSharePredicates = new dataSharePredicates.DataSharePredicates(); 771 let fetchOptions: photoAccessHelper.FetchOptions = { 772 fetchColumns: [], 773 predicates: predicates 774 }; 775 try { 776 let fetchResult: photoAccessHelper.FetchResult<photoAccessHelper.PhotoAsset> = await phAccessHelper.getAssets(fetchOptions); 777 let asset: photoAccessHelper.PhotoAsset = await fetchResult.getFirstObject(); 778 if (asset === undefined) { 779 console.error('asset not exist'); 780 return; 781 } 782 phAccessHelper.deleteAssets([asset.uri], (err) => { 783 if (err === undefined) { 784 console.info('deleteAssets successfully'); 785 } else { 786 console.error(`deleteAssets failed with error: ${err.code}, ${err.message}`); 787 } 788 }); 789 } catch (err) { 790 console.error(`fetch failed, error: ${err.code}, ${err.message}`); 791 } 792} 793``` 794 795### deleteAssets<sup>(deprecated)</sup> 796 797deleteAssets(uriList: Array<string>): Promise<void> 798 799Deletes media assets. This API uses a promise to return the result. The deleted assets are moved to the trash. 800 801> **NOTE** 802> 803> This API is supported since API version 10 and deprecated since API version 11. Use [MediaAssetChangeRequest.deleteAssets](js-apis-photoAccessHelper.md#deleteassets11) instead. 804 805**System API**: This is a system API. 806 807**Required permissions**: ohos.permission.WRITE_IMAGEVIDEO 808 809**System capability**: SystemCapability.FileManagement.PhotoAccessHelper.Core 810 811**Parameters** 812 813| Name | Type | Mandatory| Description | 814| -------- | ------------------------- | ---- | ---------- | 815| uriList | Array<string> | Yes | URIs of the media files to delete.| 816 817**Return value** 818 819| Type | Description | 820| --------------------------------------- | ----------------- | 821| Promise<void>| Promise that returns no value.| 822 823**Error codes** 824 825For details about the error codes, see [Universal Error Codes](../errorcode-universal.md) and [File Management Error Codes](../apis-core-file-kit/errorcode-filemanagement.md). 826 827| ID| Error Message| 828| -------- | ---------------------------------------- | 829| 202 | Called by non-system application. | 830| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types; 3. Parameter verification failed. | 831| 13900012 | Permission denied. | 832| 13900020 | Invalid argument. | 833| 14000002 | Invalid uri. | 834| 14000011 | System inner fail. | 835 836**Example** 837 838```ts 839import { dataSharePredicates } from '@kit.ArkData'; 840 841async function example() { 842 console.info('deleteDemo'); 843 let predicates: dataSharePredicates.DataSharePredicates = new dataSharePredicates.DataSharePredicates(); 844 let fetchOptions: photoAccessHelper.FetchOptions = { 845 fetchColumns: [], 846 predicates: predicates 847 }; 848 try { 849 let fetchResult: photoAccessHelper.FetchResult<photoAccessHelper.PhotoAsset> = await phAccessHelper.getAssets(fetchOptions); 850 let asset: photoAccessHelper.PhotoAsset = await fetchResult.getFirstObject(); 851 if (asset === undefined) { 852 console.error('asset not exist'); 853 return; 854 } 855 await phAccessHelper.deleteAssets([asset.uri]); 856 console.info('deleteAssets successfully'); 857 } catch (err) { 858 console.error(`deleteAssets failed with error: ${err.code}, ${err.message}`); 859 } 860} 861``` 862 863### getPhotoIndex 864 865getPhotoIndex(photoUri: string, albumUri: string, options: FetchOptions, callback: AsyncCallback<number>): void 866 867Obtains the index of an image or video in an album. This API uses an asynchronous callback to return the result. 868 869**System API**: This is a system API. 870 871**Required permissions**: ohos.permission.READ_IMAGEVIDEO 872 873**System capability**: SystemCapability.FileManagement.PhotoAccessHelper.Core 874 875**Parameters** 876 877| Name | Type | Mandatory| Description | 878| -------- | ------------------------- | ---- | ---------- | 879| photoUri | string | Yes | URI of the media asset whose index is to be obtained.| 880| 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. | 881| 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. | 882| callback | AsyncCallback<number>| Yes | Callback invoked to return the index obtained.| 883 884**Error codes** 885 886For details about the error codes, see [Universal Error Codes](../errorcode-universal.md) and [File Management Error Codes](../apis-core-file-kit/errorcode-filemanagement.md). 887 888| ID| Error Message| 889| -------- | ---------------------------------------- | 890| 202 | Called by non-system application. | 891| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types; 3. Parameter verification failed. | 892| 13900012 | Permission denied. | 893| 13900020 | Invalid argument. | 894| 14000011 | System inner fail. | 895 896**Example** 897 898```ts 899import { dataSharePredicates } from '@kit.ArkData'; 900 901async function example() { 902 try { 903 console.info('getPhotoIndexDemo'); 904 let predicatesForGetAsset: dataSharePredicates.DataSharePredicates = new dataSharePredicates.DataSharePredicates(); 905 let fetchOp: photoAccessHelper.FetchOptions = { 906 fetchColumns: [], 907 predicates: predicatesForGetAsset 908 }; 909 // Obtain the uri of the album 910 let albumFetchResult: photoAccessHelper.FetchResult<photoAccessHelper.Album> = await phAccessHelper.getAlbums(photoAccessHelper.AlbumType.SYSTEM, photoAccessHelper.AlbumSubtype.FAVORITE, fetchOp); 911 let album: photoAccessHelper.Album = await albumFetchResult.getFirstObject(); 912 let predicates: dataSharePredicates.DataSharePredicates = new dataSharePredicates.DataSharePredicates(); 913 predicates.orderByAsc(photoAccessHelper.PhotoKeys.DATE_MODIFIED); 914 let fetchOptions: photoAccessHelper.FetchOptions = { 915 fetchColumns: [photoAccessHelper.PhotoKeys.DATE_MODIFIED], 916 predicates: predicates 917 }; 918 let photoFetchResult: photoAccessHelper.FetchResult<photoAccessHelper.PhotoAsset> = await album.getAssets(fetchOptions); 919 let expectIndex = 1; 920 // Obtain the uri of the second file 921 let photoAsset: photoAccessHelper.PhotoAsset = await photoFetchResult.getObjectByPosition(expectIndex); 922 923 phAccessHelper.getPhotoIndex(photoAsset.uri, album.albumUri, fetchOptions, (err, index) => { 924 if (err === undefined) { 925 console.info(`getPhotoIndex successfully and index is : ${index}`); 926 } else { 927 console.error(`getPhotoIndex failed; error: ${err.code}, ${err.message}`); 928 } 929 }); 930 } catch (error) { 931 console.error(`getPhotoIndex failed; error: ${error.code}, ${error.message}`); 932 } 933} 934``` 935 936### getPhotoIndex 937 938getPhotoIndex(photoUri: string, albumUri: string, options: FetchOptions): Promise<number> 939 940Obtains the index of an image or video in an album. This API uses a promise to return the result. 941 942**System API**: This is a system API. 943 944**Required permissions**: ohos.permission.READ_IMAGEVIDEO 945 946**System capability**: SystemCapability.FileManagement.PhotoAccessHelper.Core 947 948**Parameters** 949 950| Name | Type | Mandatory| Description | 951| -------- | ------------------------- | ---- | ---------- | 952| photoUri | string | Yes | URI of the media asset whose index is to be obtained.| 953| 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. | 954| 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. | 955 956**Return value** 957 958| Type | Description | 959| --------------------------------------- | ----------------- | 960| Promise<number>| Promise used to return the index obtained.| 961 962**Error codes** 963 964For details about the error codes, see [Universal Error Codes](../errorcode-universal.md) and [File Management Error Codes](../apis-core-file-kit/errorcode-filemanagement.md). 965 966| ID| Error Message| 967| -------- | ---------------------------------------- | 968| 202 | Called by non-system application. | 969| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types; 3. Parameter verification failed. | 970| 13900012 | Permission denied. | 971| 13900020 | Invalid argument. | 972| 14000011 | System inner fail. | 973 974**Example** 975 976```ts 977import { dataSharePredicates } from '@kit.ArkData'; 978import { BusinessError } from '@kit.BasicServicesKit'; 979 980async function example() { 981 try { 982 console.info('getPhotoIndexDemo'); 983 let predicatesForGetAsset: dataSharePredicates.DataSharePredicates = new dataSharePredicates.DataSharePredicates(); 984 let fetchOp: photoAccessHelper.FetchOptions = { 985 fetchColumns: [], 986 predicates: predicatesForGetAsset 987 }; 988 // Obtain the uri of the album 989 let albumFetchResult: photoAccessHelper.FetchResult<photoAccessHelper.Album> = await phAccessHelper.getAlbums(photoAccessHelper.AlbumType.SYSTEM, photoAccessHelper.AlbumSubtype.FAVORITE, fetchOp); 990 let album: photoAccessHelper.Album = await albumFetchResult.getFirstObject(); 991 let predicates: dataSharePredicates.DataSharePredicates = new dataSharePredicates.DataSharePredicates(); 992 predicates.orderByAsc(photoAccessHelper.PhotoKeys.DATE_MODIFIED); 993 let fetchOptions: photoAccessHelper.FetchOptions = { 994 fetchColumns: [photoAccessHelper.PhotoKeys.DATE_MODIFIED], 995 predicates: predicates 996 }; 997 let photoFetchResult: photoAccessHelper.FetchResult<photoAccessHelper.PhotoAsset> = await album.getAssets(fetchOptions); 998 let expectIndex = 1; 999 // Obtain the uri of the second file 1000 let photoAsset: photoAccessHelper.PhotoAsset = await photoFetchResult.getObjectByPosition(expectIndex); 1001 phAccessHelper.getPhotoIndex(photoAsset.uri, album.albumUri, fetchOptions).then((index) => { 1002 console.info(`getPhotoIndex successfully and index is : ${index}`); 1003 }).catch((err: BusinessError) => { 1004 console.error(`getPhotoIndex failed; error: ${err.code}, ${err.message}`); 1005 }); 1006 } catch (error) { 1007 console.error(`getPhotoIndex failed; error: ${error.code}, ${error.message}`); 1008 } 1009} 1010``` 1011 1012### saveFormInfo<sup>11+</sup> 1013 1014saveFormInfo(info:FormInfo, callback: AsyncCallback<void>):void 1015 1016Saves a Gallery widget. This API uses an asynchronous callback to return the result. 1017 1018**System API**: This is a system API. 1019 1020**Required permissions**: ohos.permission.WRITE_IMAGEVIDEO 1021 1022**System capability**: SystemCapability.FileManagement.PhotoAccessHelper.Core 1023 1024**Parameters** 1025 1026| Name | Type | Mandatory| Description | 1027| -------- | ------------------------ | ---- | ------------------------- | 1028| 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. | 1029| callback | AsyncCallback<void> | Yes | Callback that returns no value.| 1030 1031**Error codes** 1032 1033For details about the error codes, see [Universal Error Codes](../errorcode-universal.md) and [File Management Error Codes](../apis-core-file-kit/errorcode-filemanagement.md). 1034 1035| ID| Error Message| 1036| -------- | ---------------------------------------- | 1037| 201 | Permission verification failed, usually the result returned by VerifyAccessToken. | 1038| 202 | Permission verification failed, application which is not a system application uses system API. | 1039| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types; 3. Parameter verification failed. | 1040| 14000011 | System inner fail. | 1041 1042 1043**Example** 1044 1045```ts 1046import { dataSharePredicates } from '@kit.ArkData'; 1047import { BusinessError } from '@kit.BasicServicesKit'; 1048 1049async function example() { 1050 console.info('saveFormInfoDemo'); 1051 let predicates: dataSharePredicates.DataSharePredicates = new dataSharePredicates.DataSharePredicates(); 1052 let fetchOptions: photoAccessHelper.FetchOptions = { 1053 fetchColumns: [], 1054 predicates: predicates 1055 }; 1056 let fetchResult: photoAccessHelper.FetchResult<photoAccessHelper.PhotoAsset> = await phAccessHelper.getAssets(fetchOptions); 1057 let photoAsset: photoAccessHelper.PhotoAsset = await fetchResult.getFirstObject(); 1058 1059 let info: photoAccessHelper.FormInfo = { 1060 // 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. 1061 formId : "20230116123", 1062 uri: photoAsset.uri, 1063 } 1064 1065 phAccessHelper.saveFormInfo(info, async (err: BusinessError) => { 1066 if (err == undefined) { 1067 console.info('saveFormInfo success'); 1068 } else { 1069 console.error(`saveFormInfo fail with error: ${err.code}, ${err.message}`); 1070 } 1071 }); 1072} 1073``` 1074 1075### saveFormInfo<sup>11+</sup> 1076 1077saveFormInfo(info:FormInfo):Promise<void> 1078 1079Saves a Gallery widget. This API uses a promise to return the result. 1080 1081**System API**: This is a system API. 1082 1083**Required permissions**: ohos.permission.WRITE_IMAGEVIDEO 1084 1085**System capability**: SystemCapability.FileManagement.PhotoAccessHelper.Core 1086 1087**Parameters** 1088 1089| Name | Type | Mandatory| Description | 1090| -------- | ------------------------ | ---- | ------------------------- | 1091| 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. | 1092 1093**Return value** 1094 1095| Type | Description | 1096| --------------------------------------- | ----------------- | 1097| Promise<void>| Promise that returns no value.| 1098 1099**Error codes** 1100 1101For details about the error codes, see [Universal Error Codes](../errorcode-universal.md) and [File Management Error Codes](../apis-core-file-kit/errorcode-filemanagement.md). 1102 1103| ID| Error Message| 1104| -------- | ---------------------------------------- | 1105| 201 | Permission verification failed, usually the result returned by VerifyAccessToken. | 1106| 202 | Permission verification failed, application which is not a system application uses system API. | 1107| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types; 3. Parameter verification failed. | 1108| 14000011 | System inner fail. | 1109 1110**Example** 1111 1112```ts 1113import { dataSharePredicates } from '@kit.ArkData'; 1114import { BusinessError } from '@kit.BasicServicesKit'; 1115 1116async function example() { 1117 console.info('saveFormInfoDemo'); 1118 let predicates: dataSharePredicates.DataSharePredicates = new dataSharePredicates.DataSharePredicates(); 1119 let fetchOptions: photoAccessHelper.FetchOptions = { 1120 fetchColumns: [], 1121 predicates: predicates 1122 }; 1123 let fetchResult: photoAccessHelper.FetchResult<photoAccessHelper.PhotoAsset> = await phAccessHelper.getAssets(fetchOptions); 1124 let photoAsset: photoAccessHelper.PhotoAsset = await fetchResult.getFirstObject(); 1125 1126 let info: photoAccessHelper.FormInfo = { 1127 // 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. 1128 formId: "20230116123", 1129 uri: photoAsset.uri, 1130 } 1131 1132 phAccessHelper.saveFormInfo(info).then(() => { 1133 console.info('saveFormInfo successfully'); 1134 }).catch((err: BusinessError) => { 1135 console.error(`saveFormInfo failed with error: ${err.code}, ${err.message}`); 1136 }); 1137} 1138``` 1139 1140### removeFormInfo<sup>11+</sup> 1141 1142removeFormInfo(info:FormInfo, callback: AsyncCallback<void>):void 1143 1144Removes a Gallery widget. This API uses an asynchronous callback to return the result. 1145 1146**System API**: This is a system API. 1147 1148**Required permissions**: ohos.permission.WRITE_IMAGEVIDEO 1149 1150**System capability**: SystemCapability.FileManagement.PhotoAccessHelper.Core 1151 1152**Parameters** 1153 1154| Name | Type | Mandatory| Description | 1155| -------- | ------------------------ | ---- | ------------------------- | 1156| 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. | 1157| callback | AsyncCallback<void> | Yes | Callback that returns no value.| 1158 1159**Error codes** 1160 1161For details about the error codes, see [Universal Error Codes](../errorcode-universal.md) and [File Management Error Codes](../apis-core-file-kit/errorcode-filemanagement.md). 1162 1163| ID| Error Message| 1164| -------- | ---------------------------------------- | 1165| 201 | Permission verification failed, usually the result returned by VerifyAccessToken. | 1166| 202 | Permission verification failed, application which is not a system application uses system API. | 1167| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types; 3. Parameter verification failed. | 1168| 14000011 | System inner fail. | 1169 1170**Example** 1171 1172```ts 1173import { BusinessError } from '@kit.BasicServicesKit'; 1174 1175async function example() { 1176 console.info('removeFormInfoDemo'); 1177 let info: photoAccessHelper.FormInfo = { 1178 // formId is a string consisting of only digits. When removing a widget, leave uri empty. 1179 formId: "20230116123", 1180 uri: "", 1181 } 1182 1183 phAccessHelper.removeFormInfo(info, async (err: BusinessError) => { 1184 if (err == undefined) { 1185 console.info('removeFormInfo success'); 1186 } else { 1187 console.error(`removeFormInfo fail with error: ${err.code}, ${err.message}`); 1188 } 1189 }); 1190} 1191``` 1192 1193### removeFormInfo<sup>11+</sup> 1194 1195removeFormInfo(info:FormInfo):Promise<void> 1196 1197Removes a Gallery widget. This API uses a promise to return the result. 1198 1199**System API**: This is a system API. 1200 1201**Required permissions**: ohos.permission.WRITE_IMAGEVIDEO 1202 1203**System capability**: SystemCapability.FileManagement.PhotoAccessHelper.Core 1204 1205**Parameters** 1206 1207| Name | Type | Mandatory| Description | 1208| -------- | ------------------------ | ---- | ------------------------- | 1209| 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. | 1210 1211**Return value** 1212 1213| Type | Description | 1214| --------------------------------------- | ----------------- | 1215| Promise<void>| Promise that returns no value.| 1216 1217**Error codes** 1218 1219For details about the error codes, see [Universal Error Codes](../errorcode-universal.md) and [File Management Error Codes](../apis-core-file-kit/errorcode-filemanagement.md). 1220 1221| ID| Error Message| 1222| -------- | ---------------------------------------- | 1223| 201 | Permission verification failed, usually the result returned by VerifyAccessToken. | 1224| 202 | Permission verification failed, application which is not a system application uses system API. | 1225| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types; 3. Parameter verification failed. | 1226| 14000011 | System inner fail. | 1227 1228**Example** 1229 1230```ts 1231import { BusinessError } from '@kit.BasicServicesKit'; 1232 1233async function example() { 1234 console.info('removeFormInfoDemo'); 1235 let info: photoAccessHelper.FormInfo = { 1236 // formId is a string consisting of only digits. When removing a widget, leave uri empty. 1237 formId: "20230116123", 1238 uri: "", 1239 } 1240 1241 phAccessHelper.removeFormInfo(info).then(() => { 1242 console.info('removeFormInfo successfully'); 1243 }).catch((err: BusinessError) => { 1244 console.error(`removeFormInfo failed with error: ${err.code}, ${err.message}`); 1245 }); 1246} 1247``` 1248 1249### createAssetsForApp<sup>12+</sup> 1250 1251createAssetsForApp(bundleName: string, appName: string, appId: string, photoCreationConfigs: Array<PhotoCreationConfig>): Promise<Array<string>> 1252 1253Creates media assets for an application. The returned URIs has been granted with the permission for writing the media assets (images or vides). 1254 1255**System API**: This is a system API. 1256 1257**Required permissions**: ohos.permission.WRITE_IMAGEVIDEO 1258 1259**System capability**: SystemCapability.FileManagement.PhotoAccessHelper.Core 1260 1261**Parameters** 1262 1263| Name | Type | Mandatory| Description | 1264| -------- |----------------------------------------------------------------------| ---- | ------------------------- | 1265| bundleName | string | Yes| Bundle name of the target application.| 1266| appName | string | Yes| Name of the target application.| 1267| appId | string | Yes| ID of the target application.| 1268| photoCreationConfigs | Array<[PhotoCreationConfig](./js-apis-photoAccessHelper.md#photocreationconfig12)> | Yes| Configuration for creating (saving) the media assets in the media library.| 1269 1270**Return value** 1271 1272| Type | Description | 1273| --------------------------------------- | ----------------- | 1274| 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.| 1275 1276**Error codes** 1277 1278For details about the error codes, see [Universal Error Codes](../errorcode-universal.md) and [File Management Error Codes](../apis-core-file-kit/errorcode-filemanagement.md). 1279 1280| ID| Error Message| 1281| -------- | ---------------------------------------- | 1282| 201 | Permission denied. | 1283| 202 | Called by non-system application. | 1284| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameters types; 3. Parameter verification failed. | 1285| 14000011 | Internal system error. | 1286 1287**Example** 1288 1289```ts 1290async function example() { 1291 console.info('createAssetsForAppDemo.'); 1292 1293 try { 1294 let bundleName: string = 'testBundleName'; 1295 let appName: string = 'testAppName'; 1296 let appId: string = 'testAppId'; 1297 let photoCreationConfigs: Array<photoAccessHelper.PhotoCreationConfig> = [ 1298 { 1299 title: 'test', 1300 fileNameExtension: 'jpg', 1301 photoType: photoAccessHelper.PhotoType.IMAGE, 1302 subtype: photoAccessHelper.PhotoSubtype.DEFAULT, 1303 } 1304 ]; 1305 let desFileUris: Array<string> = await phAccessHelper.createAssetsForApp(bundleName, appName, appId, photoCreationConfigs); 1306 console.info('createAssetsForApp success, data is ' + desFileUris); 1307 } catch (err) { 1308 console.error(`createAssetsForApp failed with error: ${err.code}, ${err.message}`); 1309 } 1310} 1311``` 1312 1313### grantPhotoUriPermission<sup>12+</sup> 1314 1315grantPhotoUriPermission(appid: string, uri: string, photoPermissionType: PhotoPermissionType, hideSensitiveType: HideSensitiveType): Promise<number> 1316 1317Grants an application the permission to access a URI. This API uses a promise to return the result. 1318 1319**System API**: This is a system API. 1320 1321**System capability**: SystemCapability.FileManagement.PhotoAccessHelper.Core 1322 1323**Required permissions**: ohos.permission.WRITE_IMAGEVIDEO 1324 1325**Parameters** 1326 1327| Name | Type | Mandatory| Description | 1328| -------- |----------------------------------------------------------------------| ---- | ------------------------- | 1329| appid | string | Yes| ID of the target application.| 1330| uri | string | Yes| URI of the media asset.| 1331| photoPermissionType | [PhotoPermissionType](#photopermissiontype12) | Yes| Type of the permission to be granted. For details, see the enum.| 1332| hideSensitiveType | [HideSensitiveType](#hidesensitivetype12) | Yes| Type of the information to hide. This parameter is reserved. Currently, any enumerated value of **HideSensitiveType** can be passed in.| 1333 1334**Return value** 1335 1336| Type | Description | 1337| --------------------------------------- | ----------------- | 1338| Promise<number> | Promise used to return the result. The value **0** indicates 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.| 1339 1340**Error codes** 1341 1342For details about the error codes, see [Universal Error Codes](../errorcode-universal.md) and [File Management Error Codes](../apis-core-file-kit/errorcode-filemanagement.md). 1343 1344| ID| Error Message| 1345| -------- | ---------------------------------------- | 1346| 201 | Permission denied. | 1347| 202 | Called by non-system application. | 1348| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameters types; 3. Parameter verification failed. | 1349| 14000011 | Internal system error. | 1350 1351**Example** 1352 1353```ts 1354async function example() { 1355 console.info('grantPhotoUriPermissionDemo'); 1356 1357 try { 1358 let result = await phAccessHelper.grantPhotoUriPermission('com.example.myapplication01', 1359 'file://media/Photo/1/IMG_datetime_0001/displayName.jpg', 1360 photoAccessHelper.PhotoPermissionType.TEMPORARY_READ_IMAGEVIDEO, 1361 photoAccessHelper.HideSensitiveType.HIDE_LOCATION_AND_SHOTING_PARM); 1362 1363 console.info('grantPhotoUriPermission success, result=' + result); 1364 } catch (err) { 1365 console.error('grantPhotoUriPermission failed, error=' + err); 1366 } 1367} 1368``` 1369 1370### grantPhotoUrisPermission<sup>12+</sup> 1371 1372grantPhotoUrisPermission(appid: string, uriList: Array<string>, photoPermissionType: PhotoPermissionType, hideSensitiveType: HideSensitiveType): Promise<number> 1373 1374Grants an application the permission to access multiple URIs. This API uses a promise to return the result. 1375 1376**System API**: This is a system API. 1377 1378**System capability**: SystemCapability.FileManagement.PhotoAccessHelper.Core 1379 1380**Required permissions**: ohos.permission.WRITE_IMAGEVIDEO 1381 1382**Parameters** 1383 1384| Name | Type | Mandatory| Description | 1385| -------- |----------------------------------------------------------------------| ---- | ------------------------- | 1386| appid | string | Yes| ID of the target application.| 1387| uriList | Array<string> | Yes| A list of URIs, which cannot exceed 1000.| 1388| photoPermissionType | [PhotoPermissionType](#photopermissiontype12) | Yes| Type of the permission to be granted. For details, see **PhotoPermissionType**.| 1389| hideSensitiveType | [HideSensitiveType](#hidesensitivetype12) | Yes| Type of the information to hide. This parameter is reserved. Currently, any enumerated value of **HideSensitiveType** can be passed in.| 1390 1391**Return value** 1392 1393| Type | Description | 1394| --------------------------------------- | ----------------- | 1395| Promise<number> | Promise used to return the result. The value **0** indicates means the operation is successful; and the value **-1** means the opposite.| 1396 1397**Error codes** 1398 1399For details about the error codes, see [Universal Error Codes](../errorcode-universal.md) and [File Management Error Codes](../apis-core-file-kit/errorcode-filemanagement.md). 1400 1401| ID| Error Message| 1402| -------- | ---------------------------------------- | 1403| 201 | Permission denied. | 1404| 202 | Called by non-system application. | 1405| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameters types; 3. Parameter verification failed. | 1406| 14000011 | Internal system error. | 1407 1408**Example** 1409 1410```ts 1411async function example() { 1412 console.info('grantPhotoUrisPermissionDemo'); 1413 1414 try { 1415 // URIs of the media assets. 1416 let uris: Array<string> = [ 1417 'file://media/Photo/11/IMG_datetime_0001/displayName1.jpg', 1418 'file://media/Photo/22/IMG_datetime_0002/displayName2.jpg']; 1419 let result = await phAccessHelper.grantPhotoUrisPermission('com.example.myapplication01', uris, 1420 photoAccessHelper.PhotoPermissionType.TEMPORARY_READ_IMAGEVIDEO, 1421 photoAccessHelper.HideSensitiveType.HIDE_LOCATION_AND_SHOTING_PARM); 1422 1423 console.info('grantPhotoUrisPermission success, result=' + result); 1424 } catch (err) { 1425 console.error('grantPhotoUrisPermission failed, error=' + err); 1426 } 1427} 1428``` 1429 1430### cancelPhotoUriPermission<sup>12+</sup> 1431 1432cancelPhotoUriPermission(appid: string, uri: string, photoPermissionType: PhotoPermissionType): Promise<number> 1433 1434Cancels the permission for accessing an URI from an appliction. This API uses a promise to return the result. 1435 1436**System API**: This is a system API. 1437 1438**System capability**: SystemCapability.FileManagement.PhotoAccessHelper.Core 1439 1440**Required permissions**: ohos.permission.WRITE_IMAGEVIDEO 1441 1442**Parameters** 1443 1444| Name | Type | Mandatory| Description | 1445| -------- |----------------------------------------------------------------------| ---- | ------------------------- | 1446| appid | string | Yes| ID of the target application.| 1447| uri | sring | Yes| URI of the media asset.| 1448| photoPermissionType | [PhotoPermissionType](#photopermissiontype12) | Yes| Permission type.| 1449 1450**Return value** 1451 1452| Type | Description | 1453| --------------------------------------- | ----------------- | 1454| Promise<number> | Promise used to return the result. The value **0** means the operation is successful; the value **-1** means the opposite.| 1455 1456**Error codes** 1457 1458For details about the error codes, see [Universal Error Codes](../errorcode-universal.md) and [File Management Error Codes](../apis-core-file-kit/errorcode-filemanagement.md). 1459 1460| ID| Error Message| 1461| -------- | ---------------------------------------- | 1462| 201 | Permission denied. | 1463| 202 | Called by non-system application. | 1464| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameters types; 3. Parameter verification failed. | 1465| 14000011 | Internal system error. | 1466 1467**Example** 1468 1469```ts 1470async function example() { 1471 console.info('cancelPhotoUriPermissionDemo'); 1472 1473 try { 1474 let result = await phAccessHelper.cancelPhotoUriPermission('com.example.myapplication01', 1475 'file://media/Photo/11/IMG_datetime_0001/displayName.jpg', 1476 photoAccessHelper.PhotoPermissionType.TEMPORARY_READ_IMAGEVIDEO); 1477 1478 console.info('cancelPhotoUriPermission success, result=' + result); 1479 } catch (err) { 1480 console.error('cancelPhotoUriPermission failed, error=' + err); 1481 } 1482} 1483``` 1484 1485### createAssetsForAppWithMode<sup>12+</sup> 1486 1487createAssetsForAppWithMode(boundleName: string, appName: string, appId: string, tokenId: number, authorizationMode: AuthorizationMode, photoCreationConfigs:Array\<PhotoCreationConfig>): Promise\<Array\<string>> 1488 1489Creates assets with a temporary permission. This API uses a promise to return the result. 1490 1491**System API**: This is a system API. 1492 1493**System capability**: SystemCapability.FileManagement.PhotoAccessHelper.Core 1494 1495**Required permissions**: ohos.permission.WRITE_IMAGEVIDEO 1496 1497**Parameters** 1498 1499| Name | Type | Mandatory| Description | 1500| -------- |----------------------------------------------------------------------| ---- | ------------------------- | 1501| boundleName| string | Yes| Bundle name of the target application.| 1502| appName| string | Yes| Name of the target application.| 1503| appId| string | Yes| ID of the target application.| 1504| tokenId| number| Yes| Unique identifier for the temporary authorization.| 1505| 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.| 1506| PhotoCreationConfig| Array\<[PhotoCreationConfig](js-apis-photoAccessHelper.md#photocreationconfig12)> | Yes| Configuration for creating (saving) the media assets in the media library.| 1507 1508**Return value** 1509 1510| Type | Description | 1511| --------------------------------------- | ----------------- | 1512| 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.| 1513 1514**Error codes** 1515 1516For details about the error codes, see [Universal Error Codes](../errorcode-universal.md) and [File Management Error Codes](../apis-core-file-kit/errorcode-filemanagement.md). 1517 1518| ID| Error Message| 1519| -------- | ---------------------------------------- | 1520| 201 | Permission denied. | 1521| 202 | Called by non-system application. | 1522| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameters types; 3. Parameter verification failed. | 1523| 14000011 | Internal system error. | 1524 1525**Example** 1526 1527```ts 1528async function example() { 1529 console.info('createAssetsForAppWithModeDemo.'); 1530 1531 try { 1532 let photoCreationConfigs: Array<photoAccessHelper.PhotoCreationConfig> = [ 1533 { 1534 title: '123456', 1535 fileNameExtension: 'jpg', 1536 photoType: photoAccessHelper.PhotoType.IMAGE, 1537 subtype: photoAccessHelper.PhotoSubtype.DEFAULT, 1538 } 1539 ]; 1540 let bundleName: string = 'testBundleName'; 1541 let appName: string = 'testAppName'; 1542 let appId: string = 'testAppId'; 1543 let tokenId: number = 537197950; 1544 let authorizationMode: photoAccessHelper.AuthorizationMode = photoAccessHelper.AuthorizationMode.SHORT_TIME_AUTHORIZATION; 1545 let result: Array<string> = await phAccessHelper.createAssetsForAppWithMode(bundleName, appName, appId, tokenId, authorizationMode, photoCreationConfigs); 1546 console.info(`result: ${JSON.stringify(result)}`); 1547 console.info('Photo createAssetsForAppWithMode success.'); 1548 } catch (err) { 1549 console.error(`createAssetsForAppWithMode failed with error: ${err.code}, ${err.message}`); 1550 } 1551} 1552``` 1553 1554## PhotoAsset 1555 1556Provides APIs for encapsulating file asset attributes. 1557 1558### open<sup>(deprecated)</sup> 1559 1560open(mode: string, callback: AsyncCallback<number>): void 1561 1562Opens this file asset. This API uses an asynchronous callback to return the result. 1563 1564> **NOTE** 1565> 1566> 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. 1567 1568> **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. 1569 1570**System API**: This is a system API. 1571 1572**Required permissions**: ohos.permission.READ_IMAGEVIDEO or ohos.permission.WRITE_IMAGEVIDEO 1573 1574**System capability**: SystemCapability.FileManagement.PhotoAccessHelper.Core 1575 1576**Parameters** 1577 1578| Name | Type | Mandatory | Description | 1579| -------- | --------------------------- | ---- | ----------------------------------- | 1580| mode | string | Yes | Mode for opening the file, which can be **'r'** (read-only), **'w'** (write-only), or **'rw'** (read/write).| 1581| callback | AsyncCallback<number> | Yes | Callback invoked to return the file descriptor (FD) of the file opened. | 1582 1583**Error codes** 1584 1585For details about the error codes, see [Universal Error Codes](../errorcode-universal.md) and [File Management Error Codes](../apis-core-file-kit/errorcode-filemanagement.md). 1586 1587| ID| Error Message| 1588| -------- | ---------------------------------------- | 1589| 202 | Called by non-system application. | 1590| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types; 3. Parameter verification failed. | 1591| 13900012 | Permission denied. | 1592| 13900020 | Invalid argument. | 1593| 14000011 | System inner fail. | 1594 1595**Example** 1596 1597```ts 1598async function example() { 1599 console.info('Open demo'); 1600 let testFileName: string = 'testFile' + Date.now() + '.jpg'; 1601 let photoAsset: photoAccessHelper.PhotoAsset = await phAccessHelper.createAsset(testFileName); 1602 photoAsset.open('rw', (err, fd) => { 1603 if (fd !== undefined) { 1604 console.info('File fd' + fd); 1605 photoAsset.close(fd); 1606 } else { 1607 console.error(`Open file err: ${err.code}, ${err.message}`); 1608 } 1609 }); 1610} 1611``` 1612 1613### open<sup>(deprecated)</sup> 1614 1615open(mode: string): Promise<number> 1616 1617Opens this file asset. This API uses a promise to return the result. 1618 1619> **NOTE** 1620> 1621> 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. 1622 1623> **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. 1624 1625**System API**: This is a system API. 1626 1627**Required permissions**: ohos.permission.READ_IMAGEVIDEO or ohos.permission.WRITE_IMAGEVIDEO 1628 1629**System capability**: SystemCapability.FileManagement.PhotoAccessHelper.Core 1630 1631**Parameters** 1632 1633| Name | Type | Mandatory | Description | 1634| ---- | ------ | ---- | ----------------------------------- | 1635| mode | string | Yes | Mode for opening the file, which can be **'r'** (read-only), **'w'** (write-only), or **'rw'** (read/write).| 1636 1637**Return value** 1638 1639| Type | Description | 1640| --------------------- | ------------- | 1641| Promise<number> | Promise used to return the FD of the file opened.| 1642 1643**Error codes** 1644 1645For details about the error codes, see [Universal Error Codes](../errorcode-universal.md) and [File Management Error Codes](../apis-core-file-kit/errorcode-filemanagement.md). 1646 1647| ID| Error Message| 1648| -------- | ---------------------------------------- | 1649| 202 | Called by non-system application. | 1650| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types; 3. Parameter verification failed. | 1651| 13900012 | Permission denied. | 1652| 13900020 | Invalid argument. | 1653| 14000011 | System inner fail. | 1654 1655**Example** 1656 1657```ts 1658async function example() { 1659 console.info('Open demo'); 1660 try { 1661 let testFileName: string = 'testFile' + Date.now() + '.jpg'; 1662 let photoAsset: photoAccessHelper.PhotoAsset = await phAccessHelper.createAsset(testFileName); 1663 let fd: number = await photoAsset.open('rw'); 1664 if (fd !== undefined) { 1665 console.info('File fd' + fd); 1666 photoAsset.close(fd); 1667 } else { 1668 console.error('Open file fail'); 1669 } 1670 } catch (err) { 1671 console.error(`Open demo err: ${err.code}, ${err.message}`); 1672 } 1673} 1674``` 1675 1676### setFavorite<sup>(deprecated)</sup> 1677 1678setFavorite(favoriteState: boolean, callback: AsyncCallback<void>): void 1679 1680Favorites or unfavorites this file. This API uses an asynchronous callback to return the result. 1681 1682> **NOTE** 1683> 1684> This API is supported since API version 10 and deprecated since API version 11. Use [MediaAssetChangeRequest.setFavorite](#setfavorite11) instead. 1685 1686**System API**: This is a system API. 1687 1688**Required permissions**: ohos.permission.WRITE_IMAGEVIDEO 1689 1690**System capability**: SystemCapability.FileManagement.PhotoAccessHelper.Core 1691 1692**Parameters** 1693 1694| Name | Type | Mandatory | Description | 1695| ---------- | ------------------------- | ---- | ---------------------------------- | 1696| favoriteState | boolean | Yes | Operation to perform. The value **true** means to favorite the file asset, and **false** means the opposite.| 1697| callback | AsyncCallback<void> | Yes | Callback that returns no value. | 1698 1699**Error codes** 1700 1701For details about the error codes, see [Universal Error Codes](../errorcode-universal.md) and [File Management Error Codes](../apis-core-file-kit/errorcode-filemanagement.md). 1702 1703| ID| Error Message| 1704| -------- | ---------------------------------------- | 1705| 202 | Called by non-system application. | 1706| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types; 3. Parameter verification failed. | 1707| 13900012 | Permission denied. | 1708| 13900020 | Invalid argument. | 1709| 14000011 | System inner fail. | 1710 1711**Example** 1712 1713```ts 1714import { dataSharePredicates } from '@kit.ArkData'; 1715 1716async function example() { 1717 console.info('setFavoriteDemo'); 1718 let predicates: dataSharePredicates.DataSharePredicates = new dataSharePredicates.DataSharePredicates(); 1719 let fetchOption: photoAccessHelper.FetchOptions = { 1720 fetchColumns: [], 1721 predicates: predicates 1722 }; 1723 let fetchResult: photoAccessHelper.FetchResult<photoAccessHelper.PhotoAsset> = await phAccessHelper.getAssets(fetchOption); 1724 let asset = await fetchResult.getFirstObject(); 1725 asset.setFavorite(true, (err) => { 1726 if (err === undefined) { 1727 console.info('favorite successfully'); 1728 } else { 1729 console.error(`favorite failed with error: ${err.code}, ${err.message}`); 1730 } 1731 }); 1732} 1733``` 1734 1735### setFavorite<sup>(deprecated)</sup> 1736 1737setFavorite(favoriteState: boolean): Promise<void> 1738 1739Favorites or unfavorites this file asset. This API uses a promise to return the result. 1740 1741> **NOTE** 1742> 1743> This API is supported since API version 10 and deprecated since API version 11. Use [MediaAssetChangeRequest.setFavorite](#setfavorite11) instead. 1744 1745**System API**: This is a system API. 1746 1747**Required permissions**: ohos.permission.WRITE_IMAGEVIDEO 1748 1749**System capability**: SystemCapability.FileManagement.PhotoAccessHelper.Core 1750 1751**Parameters** 1752 1753| Name | Type | Mandatory | Description | 1754| ---------- | ------- | ---- | ---------------------------------- | 1755| favoriteState | boolean | Yes | Operation to perform. The value **true** means to favorite the file asset, and **false** means the opposite.| 1756 1757**Return value** 1758 1759| Type | Description | 1760| ------------------- | ---------- | 1761| Promise<void> | Promise that returns no value.| 1762 1763**Error codes** 1764 1765For details about the error codes, see [Universal Error Codes](../errorcode-universal.md) and [File Management Error Codes](../apis-core-file-kit/errorcode-filemanagement.md). 1766 1767| ID| Error Message| 1768| -------- | ---------------------------------------- | 1769| 202 | Called by non-system application. | 1770| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types; 3. Parameter verification failed. | 1771| 13900012 | Permission denied. | 1772| 13900020 | Invalid argument. | 1773| 14000011 | System inner fail. | 1774 1775**Example** 1776 1777```ts 1778import { dataSharePredicates } from '@kit.ArkData'; 1779import { BusinessError } from '@kit.BasicServicesKit'; 1780 1781async function example() { 1782 console.info('setFavoriteDemo'); 1783 let predicates: dataSharePredicates.DataSharePredicates = new dataSharePredicates.DataSharePredicates(); 1784 let fetchOption: photoAccessHelper.FetchOptions = { 1785 fetchColumns: [], 1786 predicates: predicates 1787 }; 1788 let fetchResult: photoAccessHelper.FetchResult<photoAccessHelper.PhotoAsset> = await phAccessHelper.getAssets(fetchOption); 1789 let asset = await fetchResult.getFirstObject(); 1790 asset.setFavorite(true).then(() => { 1791 console.info('setFavorite successfully'); 1792 }).catch((err: BusinessError) => { 1793 console.error(`setFavorite failed with error: ${err.code}, ${err.message}`); 1794 }); 1795} 1796``` 1797 1798### setHidden<sup>(deprecated)</sup> 1799 1800setHidden(hiddenState: boolean, callback: AsyncCallback<void>): void 1801 1802Sets this file to hidden state. This API uses an asynchronous callback to return the result. 1803 1804Private 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. 1805 1806> **NOTE** 1807> 1808> This API is supported since API version 10 and deprecated since API version 11. Use [MediaAssetChangeRequest.setHidden](#sethidden11) instead. 1809 1810**System API**: This is a system API. 1811 1812**Required permissions**: ohos.permission.WRITE_IMAGEVIDEO 1813 1814**System capability**: SystemCapability.FileManagement.PhotoAccessHelper.Core 1815 1816**Parameters** 1817 1818| Name | Type | Mandatory | Description | 1819| ---------- | ------------------------- | ---- | ---------------------------------- | 1820| 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.| 1821| callback | AsyncCallback<void> | Yes | Callback that returns no value. | 1822 1823**Error codes** 1824 1825For details about the error codes, see [Universal Error Codes](../errorcode-universal.md) and [File Management Error Codes](../apis-core-file-kit/errorcode-filemanagement.md). 1826 1827| ID| Error Message| 1828| -------- | ---------------------------------------- | 1829| 202 | Called by non-system application. | 1830| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types; 3. Parameter verification failed. | 1831| 13900012 | Permission denied. | 1832| 13900020 | Invalid argument. | 1833| 14000011 | System inner fail. | 1834 1835**Example** 1836 1837```ts 1838import { dataSharePredicates } from '@kit.ArkData'; 1839 1840async function example() { 1841 console.info('setHiddenDemo'); 1842 let predicates: dataSharePredicates.DataSharePredicates = new dataSharePredicates.DataSharePredicates(); 1843 let fetchOption: photoAccessHelper.FetchOptions = { 1844 fetchColumns: [], 1845 predicates: predicates 1846 }; 1847 let fetchResult: photoAccessHelper.FetchResult<photoAccessHelper.PhotoAsset> = await phAccessHelper.getAssets(fetchOption); 1848 let asset = await fetchResult.getFirstObject(); 1849 asset.setHidden(true, (err) => { 1850 if (err === undefined) { 1851 console.info('setHidden successfully'); 1852 } else { 1853 console.error(`setHidden failed with error: ${err.code}, ${err.message}`); 1854 } 1855 }); 1856} 1857``` 1858 1859### setHidden<sup>(deprecated)</sup> 1860 1861setHidden(hiddenState: boolean): Promise<void> 1862 1863Sets this file asset to hidden state. This API uses a promise to return the result. 1864 1865Private 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. 1866 1867> **NOTE** 1868> 1869> This API is supported since API version 10 and deprecated since API version 11. Use [MediaAssetChangeRequest.setHidden](#sethidden11) instead. 1870 1871**System API**: This is a system API. 1872 1873**Required permissions**: ohos.permission.WRITE_IMAGEVIDEO 1874 1875**System capability**: SystemCapability.FileManagement.PhotoAccessHelper.Core 1876 1877**Parameters** 1878 1879| Name | Type | Mandatory | Description | 1880| ---------- | ------- | ---- | ---------------------------------- | 1881| 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.| 1882 1883**Return value** 1884 1885| Type | Description | 1886| ------------------- | ---------- | 1887| Promise<void> | Promise that returns no value.| 1888 1889**Error codes** 1890 1891For details about the error codes, see [Universal Error Codes](../errorcode-universal.md) and [File Management Error Codes](../apis-core-file-kit/errorcode-filemanagement.md). 1892 1893| ID| Error Message| 1894| -------- | ---------------------------------------- | 1895| 202 | Called by non-system application. | 1896| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types; 3. Parameter verification failed. | 1897| 13900012 | Permission denied. | 1898| 13900020 | Invalid argument. | 1899| 14000011 | System inner fail. | 1900 1901**Example** 1902 1903```ts 1904import { dataSharePredicates } from '@kit.ArkData'; 1905import { BusinessError } from '@kit.BasicServicesKit'; 1906 1907async function example() { 1908 // Restore a file from a hidden album. Before the operation, ensure that the file exists in the hidden album. 1909 console.info('setHiddenDemo'); 1910 let predicates: dataSharePredicates.DataSharePredicates = new dataSharePredicates.DataSharePredicates(); 1911 let fetchOption: photoAccessHelper.FetchOptions = { 1912 fetchColumns: [], 1913 predicates: predicates 1914 }; 1915 let albumList: photoAccessHelper.FetchResult<photoAccessHelper.Album> = await phAccessHelper.getAlbums(photoAccessHelper.AlbumType.SYSTEM, photoAccessHelper.AlbumSubtype.HIDDEN); 1916 let album = await albumList.getFirstObject(); 1917 let fetchResult: photoAccessHelper.FetchResult<photoAccessHelper.PhotoAsset> = await album.getAssets(fetchOption); 1918 let asset = await fetchResult.getFirstObject(); 1919 asset.setHidden(false).then(() => { 1920 console.info('setHidden successfully'); 1921 }).catch((err: BusinessError) => { 1922 console.error(`setHidden failed with error: ${err.code}, ${err.message}`); 1923 }); 1924} 1925``` 1926 1927### getExif 1928 1929getExif(): Promise<string> 1930 1931Obtains the exchangeable image file format (EXIF) data from a JPG image. This API uses a promise to return the result. 1932 1933The 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). 1934 1935> **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**. 1936 1937**System API**: This is a system API. 1938 1939**Required permissions**: ohos.permission.READ_IMAGEVIDEO 1940 1941**System capability**: SystemCapability.FileManagement.PhotoAccessHelper.Core 1942 1943**Return value** 1944 1945| Type | Description | 1946| --------------------------------------- | ----------------- | 1947| Promise<string> | Promise used to return the EXIF data, in JSON strings.| 1948 1949**Error codes** 1950 1951For details about the error codes, see [Universal Error Codes](../errorcode-universal.md) and [File Management Error Codes](../apis-core-file-kit/errorcode-filemanagement.md). 1952 1953| ID| Error Message| 1954| -------- | ---------------------------------------- | 1955| 202 | Called by non-system application. | 1956| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types. | 1957| 13900012 | Permission denied. | 1958| 13900020 | Invalid argument. | 1959| 14000011 | System inner fail. | 1960 1961**Example** 1962 1963```ts 1964import { dataSharePredicates } from '@kit.ArkData'; 1965 1966async function example() { 1967 try { 1968 console.info('getExifDemo'); 1969 let predicates: dataSharePredicates.DataSharePredicates = new dataSharePredicates.DataSharePredicates(); 1970 let fetchOptions: photoAccessHelper.FetchOptions = { 1971 fetchColumns: [ 'all_exif', photoAccessHelper.PhotoKeys.USER_COMMENT], 1972 predicates: predicates 1973 }; 1974 let fetchResult: photoAccessHelper.FetchResult<photoAccessHelper.PhotoAsset> = await phAccessHelper.getAssets(fetchOptions); 1975 let photoAsset: photoAccessHelper.PhotoAsset = await fetchResult.getFirstObject(); 1976 let exifMessage = await photoAsset.getExif(); 1977 let userCommentKey = 'UserComment'; 1978 let userComment = JSON.stringify(JSON.parse(exifMessage), [userCommentKey]); 1979 console.info('getExifDemo userComment: ' + JSON.stringify(userComment)); 1980 fetchResult.close(); 1981 } catch (err) { 1982 console.error(`getExifDemoCallback failed with error: ${err.code}, ${err.message}`); 1983 } 1984} 1985``` 1986 1987### getExif 1988 1989getExif(callback: AsyncCallback<string>): void 1990 1991Obtains the exchangeable image file format (EXIF) data from a JPG image. This API uses an asynchronous callback to return the result. 1992 1993The 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). 1994 1995> **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**. 1996 1997**System API**: This is a system API. 1998 1999**Required permissions**: ohos.permission.READ_IMAGEVIDEO 2000 2001**System capability**: SystemCapability.FileManagement.PhotoAccessHelper.Core 2002 2003**Parameters** 2004 2005| Name | Type | Mandatory| Description | 2006| -------- | ------------------------- | ---- | ---------- | 2007| callback | AsyncCallback<string> | Yes | Callback invoked to return the EXIF data, in JSON strings.| 2008 2009**Error codes** 2010 2011For details about the error codes, see [Universal Error Codes](../errorcode-universal.md) and [File Management Error Codes](../apis-core-file-kit/errorcode-filemanagement.md). 2012 2013| ID| Error Message| 2014| -------- | ---------------------------------------- | 2015| 202 | Called by non-system application. | 2016| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types. | 2017| 13900012 | Permission denied. | 2018| 13900020 | Invalid argument. | 2019| 14000011 | System inner fail. | 2020 2021**Example** 2022 2023```ts 2024import { dataSharePredicates } from '@kit.ArkData'; 2025 2026async function example() { 2027 try { 2028 console.info('getExifDemo'); 2029 let predicates: dataSharePredicates.DataSharePredicates = new dataSharePredicates.DataSharePredicates(); 2030 predicates.isNotNull('all_exif') 2031 let fetchOptions: photoAccessHelper.FetchOptions = { 2032 fetchColumns: ['all_exif', photoAccessHelper.PhotoKeys.USER_COMMENT], 2033 predicates: predicates 2034 }; 2035 let fetchResult: photoAccessHelper.FetchResult<photoAccessHelper.PhotoAsset> = await phAccessHelper.getAssets(fetchOptions); 2036 let photoAsset: photoAccessHelper.PhotoAsset = await fetchResult.getFirstObject(); 2037 console.info('getExifDemo photoAsset displayName: ' + JSON.stringify(photoAsset.displayName)); 2038 let userCommentKey = 'UserComment'; 2039 photoAsset.getExif((err, exifMessage) => { 2040 if (exifMessage !== undefined) { 2041 let userComment = JSON.stringify(JSON.parse(exifMessage), [userCommentKey]); 2042 console.info('getExifDemo userComment: ' + JSON.stringify(userComment)); 2043 } else { 2044 console.error(`getExif failed, error: ${err.code}, ${err.message}`); 2045 } 2046 }); 2047 fetchResult.close(); 2048 } catch (err) { 2049 console.error(`getExifDemoCallback failed with error: ${err.code}, ${err.message}`); 2050 } 2051} 2052``` 2053 2054### setUserComment<sup>(deprecated)</sup> 2055 2056setUserComment(userComment: string): Promise<void> 2057 2058Sets user comment information of an image or video. This API uses a promise to return the result. 2059 2060> **NOTE** 2061> 2062> This API is supported since API version 10 and deprecated since API version 11. Use [MediaAssetChangeRequest.setUserComment](#setusercomment11) instead. 2063 2064**NOTE**<br>This API can be used to modify the comment information of only images or videos. 2065 2066**System API**: This is a system API. 2067 2068**Required permissions**: ohos.permission.WRITE_IMAGEVIDEO 2069 2070**System capability**: SystemCapability.FileManagement.PhotoAccessHelper.Core 2071 2072**Parameters** 2073 2074| Name | Type | Mandatory| Description | 2075| -------- | ------------------------- | ---- | ---------- | 2076| userComment | string | Yes | User comment information to set, which cannot exceed 420 characters.| 2077 2078**Return value** 2079 2080| Type | Description | 2081| --------------------------------------- | ----------------- | 2082|Promise<void> | Promise that returns no value.| 2083 2084**Error codes** 2085 2086For details about the error codes, see [Universal Error Codes](../errorcode-universal.md) and [File Management Error Codes](../apis-core-file-kit/errorcode-filemanagement.md). 2087 2088| ID| Error Message| 2089| -------- | ---------------------------------------- | 2090| 202 | Called by non-system application. | 2091| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types; 3. Parameter verification failed. | 2092| 13900012 | Permission denied. | 2093| 13900020 | Invalid argument. | 2094| 14000011 | System inner fail. | 2095 2096**Example** 2097 2098```ts 2099import { dataSharePredicates } from '@kit.ArkData'; 2100 2101async function example() { 2102 try { 2103 console.info('setUserCommentDemo') 2104 let predicates: dataSharePredicates.DataSharePredicates = new dataSharePredicates.DataSharePredicates(); 2105 let fetchOptions: photoAccessHelper.FetchOptions = { 2106 fetchColumns: [], 2107 predicates: predicates 2108 }; 2109 let fetchResult: photoAccessHelper.FetchResult<photoAccessHelper.PhotoAsset> = await phAccessHelper.getAssets(fetchOptions); 2110 let photoAsset: photoAccessHelper.PhotoAsset = await fetchResult.getFirstObject(); 2111 let userComment = 'test_set_user_comment'; 2112 await photoAsset.setUserComment(userComment); 2113 } catch (err) { 2114 console.error(`setUserCommentDemoPromise failed with error: ${err.code}, ${err.message}`); 2115 } 2116} 2117``` 2118 2119### setUserComment<sup>(deprecated)</sup> 2120 2121setUserComment(userComment: string, callback: AsyncCallback<void>): void 2122 2123Sets user comment information of an image or video. This API uses an asynchronous callback to return the result. 2124 2125> **NOTE** 2126> 2127> This API is supported since API version 10 and deprecated since API version 11. Use [MediaAssetChangeRequest.setUserComment](#setusercomment11) instead. 2128 2129**NOTE**<br>This API can be used to modify the comment information of only images or videos. 2130 2131**System API**: This is a system API. 2132 2133**Required permissions**: ohos.permission.WRITE_IMAGEVIDEO 2134 2135**System capability**: SystemCapability.FileManagement.PhotoAccessHelper.Core 2136 2137**Parameters** 2138 2139| Name | Type | Mandatory| Description | 2140| -------- | ------------------------- | ---- | ---------- | 2141| userComment | string | Yes | User comment information to set, which cannot exceed 420 characters.| 2142| callback | AsyncCallback<void> | Yes | Callback that returns no value.| 2143 2144**Error codes** 2145 2146For details about the error codes, see [Universal Error Codes](../errorcode-universal.md) and [File Management Error Codes](../apis-core-file-kit/errorcode-filemanagement.md). 2147 2148| ID| Error Message| 2149| -------- | ---------------------------------------- | 2150| 202 | Called by non-system application. | 2151| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types; 3. Parameter verification failed. | 2152| 13900012 | Permission denied. | 2153| 13900020 | Invalid argument. | 2154| 14000011 | System inner fail. | 2155 2156**Example** 2157 2158```ts 2159import { dataSharePredicates } from '@kit.ArkData'; 2160 2161async function example() { 2162 try { 2163 console.info('setUserCommentDemo') 2164 let predicates: dataSharePredicates.DataSharePredicates = new dataSharePredicates.DataSharePredicates(); 2165 let fetchOptions: photoAccessHelper.FetchOptions = { 2166 fetchColumns: [], 2167 predicates: predicates 2168 }; 2169 let fetchResult: photoAccessHelper.FetchResult<photoAccessHelper.PhotoAsset> = await phAccessHelper.getAssets(fetchOptions); 2170 let photoAsset: photoAccessHelper.PhotoAsset = await fetchResult.getFirstObject(); 2171 let userComment = 'test_set_user_comment'; 2172 photoAsset.setUserComment(userComment, (err) => { 2173 if (err === undefined) { 2174 console.info('setUserComment successfully'); 2175 } else { 2176 console.error(`setUserComment failed with error: ${err.code}, ${err.message}`); 2177 } 2178 }); 2179 } catch (err) { 2180 console.error(`setUserCommentDemoCallback failed with error: ${err.code}, ${err.message}`); 2181 } 2182} 2183``` 2184 2185### setPending<sup>11+</sup> 2186 2187setPending(pendingState: boolean, callback: AsyncCallback<void>): void 2188 2189Sets the pending state for this image or video asset. This API uses an asynchronous callback to return the result. 2190 2191The 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. 2192 2193**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. 2194 2195**System API**: This is a system API. 2196 2197**Required permissions**: ohos.permission.WRITE_IMAGEVIDEO 2198 2199**System capability**: SystemCapability.FileManagement.PhotoAccessHelper.Core 2200 2201**Parameters** 2202 2203| Name | Type | Mandatory | Description | 2204| ---------- | ------- | ---- | ---------------------------------- | 2205| 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.| 2206| callback | AsyncCallback<void> | Yes | Callback that returns no value.| 2207 2208**Error codes** 2209 2210For details about the error codes, see [Universal Error Codes](../errorcode-universal.md) and [File Management Error Codes](../apis-core-file-kit/errorcode-filemanagement.md). 2211 2212| ID| Error Message| 2213| -------- | ---------------------------------------- | 2214| 201 | Permission denied. | 2215| 202 | Called by non-system application. | 2216| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types; 3. Parameter verification failed. | 2217| 14000011 | System inner fail. | 2218 2219**Example** 2220 2221```ts 2222async function example() { 2223 try { 2224 console.info('setPendingCallbackDemo'); 2225 let testFileName: string = 'testFile' + Date.now() + '.jpg'; 2226 let photoAsset = await phAccessHelper.createAsset(testFileName); 2227 let fd = await photoAsset.open('rw'); 2228 photoAsset.setPending(true, async (err) => { 2229 if (err !== undefined) { 2230 console.error(`setPending(true) failed with error: ${err.code}, ${err.message}`); 2231 return; 2232 } 2233 // write photo buffer in fd 2234 photoAsset.setPending(false, async (err) => { 2235 if (err !== undefined) { 2236 console.error(`setPending(false) failed with error: ${err.code}, ${err.message}`); 2237 return; 2238 } 2239 await photoAsset.close(fd); 2240 }); 2241 }); 2242 } catch (err) { 2243 console.error(`setPendingCallbackDemo failed with error: ${err.code}, ${err.message}`); 2244 } 2245} 2246``` 2247 2248### setPending<sup>11+</sup> 2249 2250setPending(pendingState: boolean): Promise<void> 2251 2252Sets the pending state for this image or video asset. This API uses a promise to return the result. 2253 2254The 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. 2255 2256**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. 2257 2258**System API**: This is a system API. 2259 2260**Required permissions**: ohos.permission.WRITE_IMAGEVIDEO 2261 2262**System capability**: SystemCapability.FileManagement.PhotoAccessHelper.Core 2263 2264**Parameters** 2265 2266| Name | Type | Mandatory | Description | 2267| ---------- | ------- | ---- | ---------------------------------- | 2268| 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.| 2269 2270**Return value** 2271 2272| Type | Description | 2273| --------------------------------------- | ----------------- | 2274|Promise<boolean> | Promise that returns no value.| 2275 2276**Error codes** 2277 2278For details about the error codes, see [Universal Error Codes](../errorcode-universal.md) and [File Management Error Codes](../apis-core-file-kit/errorcode-filemanagement.md). 2279 2280| ID| Error Message| 2281| -------- | ---------------------------------------- | 2282| 201 | Permission denied. | 2283| 202 | Called by non-system application. | 2284| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types; 3. Parameter verification failed. | 2285| 14000011 | System inner fail. | 2286 2287**Example** 2288 2289```ts 2290async function example() { 2291 try { 2292 console.info('setPendingPromiseDemo'); 2293 let testFileName: string = 'testFile' + Date.now() + '.jpg'; 2294 let photoAsset = await phAccessHelper.createAsset(testFileName); 2295 let fd = await photoAsset.open('rw'); 2296 await photoAsset.setPending(true); 2297 // write photo buffer in fd 2298 photoAsset.setPending(false); 2299 await photoAsset.close(fd); 2300 } catch (err) { 2301 console.error(`setPendingPromiseDemo failed with error: ${err.code}, ${err.message}`); 2302 } 2303} 2304``` 2305 2306### isEdited<sup>11+</sup> 2307 2308isEdited(callback: AsyncCallback<boolean>): void 2309 2310Checks whether this image or video asset is edited. This API uses an asynchronous callback to return the result. 2311 2312**System API**: This is a system API. 2313 2314**Required permissions**: ohos.permission.READ_IMAGEVIDEO 2315 2316**System capability**: SystemCapability.FileManagement.PhotoAccessHelper.Core 2317 2318**Parameters** 2319 2320| Name | Type | Mandatory | Description | 2321| ---------- | ------- | ---- | ---------------------------------- | 2322| callback | AsyncCallback<boolean> | Yes | Callback invoked to return the result.| 2323 2324**Error codes** 2325 2326For details about the error codes, see [Universal Error Codes](../errorcode-universal.md) and [File Management Error Codes](../apis-core-file-kit/errorcode-filemanagement.md). 2327 2328| ID| Error Message| 2329| -------- | ---------------------------------------- | 2330| 201 | Permission denied. | 2331| 202 | Called by non-system application. | 2332| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types. | 2333| 14000011 | System inner fail. | 2334 2335**Example** 2336 2337```ts 2338import { dataSharePredicates } from '@kit.ArkData'; 2339 2340async function example() { 2341 try { 2342 console.info('isEditedCallbackDemo') 2343 let predicates: dataSharePredicates.DataSharePredicates = new dataSharePredicates.DataSharePredicates(); 2344 let fetchOptions: photoAccessHelper.FetchOptions = { 2345 fetchColumns: [], 2346 predicates: predicates 2347 }; 2348 let fetchResult: photoAccessHelper.FetchResult<photoAccessHelper.PhotoAsset> = await phAccessHelper.getAssets(fetchOptions); 2349 let photoAsset: photoAccessHelper.PhotoAsset = await fetchResult.getFirstObject(); 2350 photoAsset.isEdited((err, isEdited) => { 2351 if (err === undefined) { 2352 if (isEdited === true) { 2353 console.info('Photo is edited'); 2354 } else { 2355 console.info('Photo is not edited'); 2356 } 2357 } else { 2358 console.error(`isEdited failed with error: ${err.code}, ${err.message}`); 2359 } 2360 }); 2361 } catch (err) { 2362 console.error(`isEditedDemoCallback failed with error: ${err.code}, ${err.message}`); 2363 } 2364} 2365``` 2366 2367### isEdited<sup>11+</sup> 2368 2369isEdited(): Promise<boolean> 2370 2371Checks whether this image or video asset is edited. This API uses a promise to return the result. 2372 2373**System API**: This is a system API. 2374 2375**Required permissions**: ohos.permission.READ_IMAGEVIDEO 2376 2377**System capability**: SystemCapability.FileManagement.PhotoAccessHelper.Core 2378 2379**Return value** 2380 2381| Type | Description | 2382| --------------------------------------- | ----------------- | 2383|Promise<boolean> | Promise used to return the result.| 2384 2385 2386**Error codes** 2387 2388For details about the error codes, see [Universal Error Codes](../errorcode-universal.md) and [File Management Error Codes](../apis-core-file-kit/errorcode-filemanagement.md). 2389 2390| ID| Error Message| 2391| -------- | ---------------------------------------- | 2392| 201 | Permission denied. | 2393| 202 | Called by non-system application. | 2394| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types. | 2395| 14000011 | System inner fail. | 2396 2397**Example** 2398 2399```ts 2400import { dataSharePredicates } from '@kit.ArkData'; 2401 2402async function example() { 2403 try { 2404 console.info('isEditedPromiseDemo') 2405 let predicates: dataSharePredicates.DataSharePredicates = new dataSharePredicates.DataSharePredicates(); 2406 let fetchOptions: photoAccessHelper.FetchOptions = { 2407 fetchColumns: [], 2408 predicates: predicates 2409 }; 2410 let fetchResult: photoAccessHelper.FetchResult<photoAccessHelper.PhotoAsset> = await phAccessHelper.getAssets(fetchOptions); 2411 let photoAsset: photoAccessHelper.PhotoAsset = await fetchResult.getFirstObject(); 2412 let isEdited = await photoAsset.isEdited(); 2413 if (isEdited === true) { 2414 console.info('Photo is edited'); 2415 } else { 2416 console.info('Photo is not edited'); 2417 } 2418 } catch (err) { 2419 console.error(`isEditedDemoCallback failed with error: ${err.code}, ${err.message}`); 2420 } 2421} 2422``` 2423 2424### requestEditData<sup>11+</sup> 2425 2426requestEditData(callback: AsyncCallback<string>): void 2427 2428Obtains the edit data of this image or video asset. This API uses an asynchronous callback to return the result. 2429 2430If the asset has never been edited, an empty string is returned. 2431 2432**System API**: This is a system API. 2433 2434**Required permissions**: ohos.permission.READ_IMAGEVIDEO 2435 2436**System capability**: SystemCapability.FileManagement.PhotoAccessHelper.Core 2437 2438**Parameters** 2439 2440| Name | Type | Mandatory | Description | 2441| ---------- | ------- | ---- | ---------------------------------- | 2442| callback | AsyncCallback<string> | Yes | Callback invoked to return the edit data obtained.| 2443 2444**Error codes** 2445 2446For details about the error codes, see [Universal Error Codes](../errorcode-universal.md) and [File Management Error Codes](../apis-core-file-kit/errorcode-filemanagement.md). 2447 2448| ID| Error Message| 2449| -------- | ---------------------------------------- | 2450| 201 | Permission denied. | 2451| 202 | Called by non-system application. | 2452| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types. | 2453| 14000011 | System inner fail. | 2454 2455**Example** 2456 2457```ts 2458import { dataSharePredicates } from '@kit.ArkData'; 2459 2460async function example() { 2461 try { 2462 console.info('requestEditDataCallbackDemo') 2463 let predicates: dataSharePredicates.DataSharePredicates = new dataSharePredicates.DataSharePredicates(); 2464 let fetchOptions: photoAccessHelper.FetchOptions = { 2465 fetchColumns: [], 2466 predicates: predicates 2467 }; 2468 let fetchResult: photoAccessHelper.FetchResult<photoAccessHelper.PhotoAsset> = await phAccessHelper.getAssets(fetchOptions); 2469 let photoAsset: photoAccessHelper.PhotoAsset = await fetchResult.getFirstObject(); 2470 photoAsset.requestEditData((err, editdata) => { 2471 if (err === undefined) { 2472 console.info('Editdata is ' + editdata); 2473 } else { 2474 console.error(`requestEditData failed with error: ${err.code}, ${err.message}`); 2475 } 2476 }); 2477 } catch (err) { 2478 console.error(`requestEditDataCallbackDemo failed with error: ${err.code}, ${err.message}`); 2479 } 2480} 2481``` 2482 2483### requestEditData<sup>11+</sup> 2484 2485requestEditData(): Promise<string> 2486 2487Obtains the edit data of this image or video asset. This API uses a promise to return the result. 2488 2489If the asset has never been edited, an empty string is returned. 2490 2491**System API**: This is a system API. 2492 2493**Required permissions**: ohos.permission.READ_IMAGEVIDEO 2494 2495**System capability**: SystemCapability.FileManagement.PhotoAccessHelper.Core 2496 2497**Return value** 2498 2499| Type | Description | 2500| --------------------------------------- | ----------------- | 2501|Promise<string> | Promise used to return the edit data obtained.| 2502 2503 2504**Error codes** 2505 2506For details about the error codes, see [Universal Error Codes](../errorcode-universal.md) and [File Management Error Codes](../apis-core-file-kit/errorcode-filemanagement.md). 2507 2508| ID| Error Message| 2509| -------- | ---------------------------------------- | 2510| 201 | Permission denied. | 2511| 202 | Called by non-system application. | 2512| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types. | 2513| 14000011 | System inner fail. | 2514 2515**Example** 2516 2517```ts 2518import { dataSharePredicates } from '@kit.ArkData'; 2519 2520async function example() { 2521 try { 2522 console.info('requestEditDataPromiseDemo') 2523 let predicates: dataSharePredicates.DataSharePredicates = new dataSharePredicates.DataSharePredicates(); 2524 let fetchOptions: photoAccessHelper.FetchOptions = { 2525 fetchColumns: [], 2526 predicates: predicates 2527 }; 2528 let fetchResult: photoAccessHelper.FetchResult<photoAccessHelper.PhotoAsset> = await phAccessHelper.getAssets(fetchOptions); 2529 let photoAsset: photoAccessHelper.PhotoAsset = await fetchResult.getFirstObject(); 2530 let editdata: string = await photoAsset.requestEditData(); 2531 console.info('Editdata is ' + editdata); 2532 } catch (err) { 2533 console.error(`requestEditDataPromiseDemo failed with error: ${err.code}, ${err.message}`); 2534 } 2535} 2536``` 2537 2538### getEditData<sup>11+</sup> 2539 2540getEditData(): Promise<MediaAssetEditData> 2541 2542Obtains the edited data of this asset. This API uses a promise to return the result. 2543 2544If the asset has never been edited, an empty string is returned. 2545 2546**System API**: This is a system API. 2547 2548**Required permissions**: ohos.permission.READ_IMAGEVIDEO 2549 2550**System capability**: SystemCapability.FileManagement.PhotoAccessHelper.Core 2551 2552**Return value** 2553 2554| Type | Description | 2555| --------------------------------------- | ----------------- | 2556|Promise<[MediaAssetEditData](#mediaasseteditdata11)> | Promise used to return the edited asset data.| 2557 2558**Error codes** 2559 2560For details about the error codes, see [Universal Error Codes](../errorcode-universal.md) and [File Management Error Codes](../apis-core-file-kit/errorcode-filemanagement.md). 2561 2562| ID| Error Message| 2563| -------- | ---------------------------------------- | 2564| 201 | Permission denied. | 2565| 202 | Called by non-system application. | 2566| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types. | 2567| 14000011 | System inner fail. | 2568 2569**Example** 2570 2571```ts 2572import { dataSharePredicates } from '@kit.ArkData'; 2573 2574async function example() { 2575 try { 2576 console.info('getEditDataDemo') 2577 let predicates: dataSharePredicates.DataSharePredicates = new dataSharePredicates.DataSharePredicates(); 2578 let fetchOptions: photoAccessHelper.FetchOptions = { 2579 fetchColumns: [], 2580 predicates: predicates 2581 }; 2582 let fetchResult: photoAccessHelper.FetchResult<photoAccessHelper.PhotoAsset> = await phAccessHelper.getAssets(fetchOptions); 2583 let photoAsset: photoAccessHelper.PhotoAsset = await fetchResult.getFirstObject(); 2584 let assetEditData: photoAccessHelper.MediaAssetEditData = await photoAsset.getEditData(); 2585 let data: string = assetEditData.data; 2586 console.info('edit data is ' + data); 2587 } catch (err) { 2588 console.error(`getEditDataDemo failed with error: ${err.code}, ${err.message}`); 2589 } 2590} 2591``` 2592 2593### requestSource<sup>11+</sup> 2594 2595requestSource(callback: AsyncCallback<number>): void 2596 2597Opens the source file to obtain the FD. This API uses an asynchronous callback to return the result. 2598 2599**System API**: This is a system API. 2600 2601**Required permissions**: ohos.permission.READ_IMAGEVIDEO 2602 2603**System capability**: SystemCapability.FileManagement.PhotoAccessHelper.Core 2604 2605**Parameters** 2606 2607| Name | Type | Mandatory | Description | 2608| ---------- | ------- | ---- | ---------------------------------- | 2609| callback | AsyncCallback<number> | Yes | Callback invoked to return the FD.| 2610 2611**Error codes** 2612 2613For details about the error codes, see [Universal Error Codes](../errorcode-universal.md) and [File Management Error Codes](../apis-core-file-kit/errorcode-filemanagement.md). 2614 2615| ID| Error Message| 2616| -------- | ---------------------------------------- | 2617| 201 | Permission denied. | 2618| 202 | Called by non-system application. | 2619| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types. | 2620| 14000011 | System inner fail. | 2621 2622**Example** 2623 2624```ts 2625import { dataSharePredicates } from '@kit.ArkData'; 2626 2627async function example() { 2628 try { 2629 console.info('requsetSourceCallbackDemo') 2630 let predicates: dataSharePredicates.DataSharePredicates = new dataSharePredicates.DataSharePredicates(); 2631 let fetchOptions: photoAccessHelper.FetchOptions = { 2632 fetchColumns: [], 2633 predicates: predicates 2634 }; 2635 let fetchResult: photoAccessHelper.FetchResult<photoAccessHelper.PhotoAsset> = await phAccessHelper.getAssets(fetchOptions); 2636 let photoAsset: photoAccessHelper.PhotoAsset = await fetchResult.getFirstObject(); 2637 photoAsset.requestSource((err, fd) => { 2638 if (err === undefined) { 2639 console.info('Source fd is ' + fd); 2640 } else { 2641 console.error(`requestSource failed with error: ${err.code}, ${err.message}`); 2642 } 2643 }); 2644 } catch (err) { 2645 console.error(`requsetSourceCallbackDemo failed with error: ${err.code}, ${err.message}`); 2646 } 2647} 2648``` 2649 2650### requestSource<sup>11+</sup> 2651 2652requestSource(): Promise<number> 2653 2654Opens the source file to obtain the FD. This API uses a promise to return the result. 2655 2656**System API**: This is a system API. 2657 2658**Required permissions**: ohos.permission.READ_IMAGEVIDEO 2659 2660**System capability**: SystemCapability.FileManagement.PhotoAccessHelper.Core 2661 2662**Return value** 2663 2664| Type | Description | 2665| --------------------------------------- | ----------------- | 2666|Promise<number> | Promise used to return the FD.| 2667 2668**Error codes** 2669 2670For details about the error codes, see [Universal Error Codes](../errorcode-universal.md) and [File Management Error Codes](../apis-core-file-kit/errorcode-filemanagement.md). 2671 2672| ID| Error Message| 2673| -------- | ---------------------------------------- | 2674| 201 | Permission denied. | 2675| 202 | Called by non-system application. | 2676| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types. | 2677| 14000011 | System inner fail. | 2678 2679**Example** 2680 2681```ts 2682import { dataSharePredicates } from '@kit.ArkData'; 2683 2684async function example() { 2685 try { 2686 console.info('requsetSourcePromiseDemo') 2687 let predicates: dataSharePredicates.DataSharePredicates = new dataSharePredicates.DataSharePredicates(); 2688 let fetchOptions: photoAccessHelper.FetchOptions = { 2689 fetchColumns: [], 2690 predicates: predicates 2691 }; 2692 let fetchResult: photoAccessHelper.FetchResult<photoAccessHelper.PhotoAsset> = await phAccessHelper.getAssets(fetchOptions); 2693 let photoAsset: photoAccessHelper.PhotoAsset = await fetchResult.getFirstObject(); 2694 let fd = await photoAsset.requestSource(); 2695 console.info('Source fd is ' + fd); 2696 } catch (err) { 2697 console.error(`requsetSourcePromiseDemo failed with error: ${err.code}, ${err.message}`); 2698 } 2699} 2700``` 2701 2702### commitEditedAsset<sup>11+</sup> 2703 2704commitEditedAsset(editData: string, uri: string, callback: AsyncCallback<void>) 2705 2706Commits the edited image or video asset. This API uses an asynchronous callback to return the result. 2707 2708The 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). 2709 2710**NOTE**<br>The commit operation overwrites the previous edited data. 2711 2712**System API**: This is a system API. 2713 2714**Required permissions**: ohos.permission.WRITE_IMAGEVIDEO 2715 2716**System capability**: SystemCapability.FileManagement.PhotoAccessHelper.Core 2717 2718**Parameters** 2719 2720| Name | Type | Mandatory | Description | 2721| ---------- | ------- | ---- | ---------------------------------- | 2722| editData | string | Yes | New data to commit.| 2723| uri | string | Yes | URI of the committed image or video in the application sandbox.| 2724| callback | AsyncCallback<void> | Yes | Callback that returns no value.| 2725 2726**Error codes** 2727 2728For details about the error codes, see [Universal Error Codes](../errorcode-universal.md) and [File Management Error Codes](../apis-core-file-kit/errorcode-filemanagement.md). 2729 2730| ID| Error Message| 2731| -------- | ---------------------------------------- | 2732| 201 | Permission denied. | 2733| 202 | Called by non-system application. | 2734| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types; 3. Parameter verification failed. | 2735| 14000011 | System inner fail. | 2736 2737**Example** 2738 2739```ts 2740import { dataSharePredicates } from '@kit.ArkData'; 2741 2742async function example() { 2743 try { 2744 console.info('commitEditedAssetCallbackDemo') 2745 let predicates: dataSharePredicates.DataSharePredicates = new dataSharePredicates.DataSharePredicates(); 2746 let fetchOptions: photoAccessHelper.FetchOptions = { 2747 fetchColumns: [], 2748 predicates: predicates 2749 }; 2750 let fetchResult: photoAccessHelper.FetchResult<photoAccessHelper.PhotoAsset> = await phAccessHelper.getAssets(fetchOptions); 2751 let photoAsset: photoAccessHelper.PhotoAsset = await fetchResult.getFirstObject(); 2752 let editData = '123456'; 2753 let uri = 'file://com.example.temptest/data/storage/el2/base/haps/entry/files/test.jpg'; 2754 photoAsset.commitEditedAsset(editData, uri, (err) => { 2755 if (err === undefined) { 2756 console.info('commitEditedAsset is successful'); 2757 } else { 2758 console.error(`commitEditedAsset failed with error: ${err.code}, ${err.message}`); 2759 } 2760 }); 2761 } catch (err) { 2762 console.error(`commitEditedAssetCallbackDemo failed with error: ${err.code}, ${err.message}`); 2763 } 2764} 2765``` 2766 2767### commitEditedAsset<sup>11+</sup> 2768 2769commitEditedAsset(editData: string, uri: string): Promise<void> 2770 2771Commits the edited image or video asset. This API uses a promise to return the result. 2772 2773The 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). 2774 2775**NOTE**<br>The commit operation overwrites the previous edited data. 2776 2777**System API**: This is a system API. 2778 2779**Required permissions**: ohos.permission.WRITE_IMAGEVIDEO 2780 2781**System capability**: SystemCapability.FileManagement.PhotoAccessHelper.Core 2782 2783**Parameters** 2784 2785| Name | Type | Mandatory | Description | 2786| ---------- | ------- | ---- | ---------------------------------- | 2787| editData | string | Yes | New data to commit.| 2788| uri | string | Yes | URI of the committed image or video in the application sandbox.| 2789 2790**Return value** 2791 2792| Type | Description | 2793| --------------------------------------- | ----------------- | 2794|Promise<void> | Promise that returns no value.| 2795 2796**Error codes** 2797 2798For details about the error codes, see [Universal Error Codes](../errorcode-universal.md) and [File Management Error Codes](../apis-core-file-kit/errorcode-filemanagement.md). 2799 2800| ID| Error Message| 2801| -------- | ---------------------------------------- | 2802| 201 | Permission denied. | 2803| 202 | Called by non-system application. | 2804| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types; 3. Parameter verification failed. | 2805| 14000011 | System inner fail. | 2806 2807**Example** 2808 2809```ts 2810import { dataSharePredicates } from '@kit.ArkData'; 2811 2812async function example() { 2813 try { 2814 console.info('commitEditedAssetPromiseDemo') 2815 let predicates: dataSharePredicates.DataSharePredicates = new dataSharePredicates.DataSharePredicates(); 2816 let fetchOptions: photoAccessHelper.FetchOptions = { 2817 fetchColumns: [], 2818 predicates: predicates 2819 }; 2820 let fetchResult: photoAccessHelper.FetchResult<photoAccessHelper.PhotoAsset> = await phAccessHelper.getAssets(fetchOptions); 2821 let photoAsset: photoAccessHelper.PhotoAsset = await fetchResult.getFirstObject(); 2822 let editData = '123456'; 2823 let uri = 'file://com.example.temptest/data/storage/el2/base/haps/entry/files/test.jpg'; 2824 await photoAsset.commitEditedAsset(editData, uri); 2825 console.info('commitEditedAsset is successful'); 2826 } catch (err) { 2827 console.error(`commitEditedAssetPromiseDemo failed with error: ${err.code}, ${err.message}`); 2828 } 2829} 2830``` 2831 2832### revertToOriginal<sup>11+</sup> 2833 2834revertToOriginal(callback: AsyncCallback<void>) 2835 2836Reverts to the state of the file before being edited. This API uses an asynchronous callback to return the result. 2837 2838**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. 2839 2840**System API**: This is a system API. 2841 2842**Required permissions**: ohos.permission.WRITE_IMAGEVIDEO 2843 2844**System capability**: SystemCapability.FileManagement.PhotoAccessHelper.Core 2845 2846**Parameters** 2847 2848| Name | Type | Mandatory | Description | 2849| ---------- | ------- | ---- | ---------------------------------- | 2850| callback | AsyncCallback<void> | Yes | Callback that returns no value.| 2851 2852**Error codes** 2853 2854For details about the error codes, see [Universal Error Codes](../errorcode-universal.md) and [File Management Error Codes](../apis-core-file-kit/errorcode-filemanagement.md). 2855 2856| ID| Error Message| 2857| -------- | ---------------------------------------- | 2858| 201 | Permission denied. | 2859| 202 | Called by non-system application. | 2860| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types. | 2861| 14000011 | System inner fail. | 2862 2863**Example** 2864 2865```ts 2866import { dataSharePredicates } from '@kit.ArkData'; 2867 2868async function example() { 2869 try { 2870 console.info('revertToOriginalCallbackDemo') 2871 let predicates: dataSharePredicates.DataSharePredicates = new dataSharePredicates.DataSharePredicates(); 2872 let fetchOptions: photoAccessHelper.FetchOptions = { 2873 fetchColumns: [], 2874 predicates: predicates 2875 }; 2876 let fetchResult: photoAccessHelper.FetchResult<photoAccessHelper.PhotoAsset> = await phAccessHelper.getAssets(fetchOptions); 2877 let photoAsset: photoAccessHelper.PhotoAsset = await fetchResult.getFirstObject(); 2878 photoAsset.revertToOriginal((err) => { 2879 if (err === undefined) { 2880 console.info('revertToOriginal is successful'); 2881 } else { 2882 console.error(`revertToOriginal failed with error: ${err.code}, ${err.message}`); 2883 } 2884 }); 2885 } catch (err) { 2886 console.error(`revertToOriginalCallbackDemo failed with error: ${err.code}, ${err.message}`); 2887 } 2888} 2889``` 2890 2891### revertToOriginal<sup>11+</sup> 2892 2893revertToOriginal(): Promise<void> 2894 2895Reverts to the state of the file before being edited. This API uses a promise to return the result. 2896 2897**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. 2898 2899**System API**: This is a system API. 2900 2901**Required permissions**: ohos.permission.WRITE_IMAGEVIDEO 2902 2903**System capability**: SystemCapability.FileManagement.PhotoAccessHelper.Core 2904 2905**Return value** 2906 2907| Type | Description | 2908| --------------------------------------- | ----------------- | 2909|Promise<string> | Promise that returns no value.| 2910 2911**Error codes** 2912 2913For details about the error codes, see [Universal Error Codes](../errorcode-universal.md) and [File Management Error Codes](../apis-core-file-kit/errorcode-filemanagement.md). 2914 2915| ID| Error Message| 2916| -------- | ---------------------------------------- | 2917| 201 | Permission denied. | 2918| 202 | Called by non-system application. | 2919| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types. | 2920| 14000011 | System inner fail. | 2921 2922**Example** 2923 2924```ts 2925import { dataSharePredicates } from '@kit.ArkData'; 2926 2927async function example() { 2928 try { 2929 console.info('revertToOriginalPromiseDemo') 2930 let predicates: dataSharePredicates.DataSharePredicates = new dataSharePredicates.DataSharePredicates(); 2931 let fetchOptions: photoAccessHelper.FetchOptions = { 2932 fetchColumns: [], 2933 predicates: predicates 2934 }; 2935 let fetchResult: photoAccessHelper.FetchResult<photoAccessHelper.PhotoAsset> = await phAccessHelper.getAssets(fetchOptions); 2936 let photoAsset: photoAccessHelper.PhotoAsset = await fetchResult.getFirstObject(); 2937 photoAsset.revertToOriginal(); 2938 console.info('revertToOriginal is successful'); 2939 } catch (err) { 2940 console.error(`revertToOriginalPromiseDemo failed with error: ${err.code}, ${err.message}`); 2941 } 2942} 2943``` 2944 2945### requestPhoto<sup>11+</sup> 2946 2947requestPhoto(callback: AsyncCallback<image.PixelMap>): string 2948 2949Obtains the quick thumbnail and quality thumbnail of this asset. This API uses an asynchronous callback to return the result. 2950 2951The 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. 2952 2953**System API**: This is a system API. 2954 2955**Required permissions**: ohos.permission.READ_IMAGEVIDEO 2956 2957**System capability**: SystemCapability.FileManagement.PhotoAccessHelper.Core 2958 2959**Parameters** 2960 2961| Name | Type | Mandatory | Description | 2962| ---------- | ------- | ---- | ---------------------------------- | 2963| callback | AsyncCallback<[image.PixelMap](../apis-image-kit/js-apis-image.md#pixelmap7)> | Yes | Callback invoked twice to return the quick and quality thumbnails obtained.| 2964 2965**Return value** 2966 2967| Type | Description | 2968| --------------------------------------- | ----------------- | 2969| string | ID of the task for obtaining thumbnails.| 2970 2971**Error codes** 2972 2973For details about the error codes, see [Universal Error Codes](../errorcode-universal.md) and [File Management Error Codes](../apis-core-file-kit/errorcode-filemanagement.md). 2974 2975| ID| Error Message| 2976| -------- | ---------------------------------------- | 2977| 201 | Permission verification failed, usually the result returned by VerifyAccessToken. | 2978| 202 | Permission verification failed, application which is not a system application uses system API. | 2979| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types. | 2980| 14000011 | System inner fail. | 2981 2982**Example** 2983 2984```ts 2985import { dataSharePredicates } from '@kit.ArkData'; 2986import { image } from '@kit.ImageKit'; 2987 2988async function example() { 2989 try { 2990 console.info('requestPhotoDemo') 2991 let options: photoAccessHelper.FetchOptions = { 2992 fetchColumns: [], 2993 predicates: new dataSharePredicates.DataSharePredicates() 2994 } 2995 let fetchResult = await phAccessHelper.getAssets(options); 2996 let photoAsset = await fetchResult.getFirstObject(); 2997 let taskId: string = photoAsset.requestPhoto(async (err, pixel: image.PixelMap) => { 2998 if (err === undefined) { 2999 console.info("requestSource in, size: " + JSON.stringify((await pixel.getImageInfo()).size)) 3000 } else { 3001 console.error(`requestSource failed with error: ${err.code}, ${err.message}`); 3002 } 3003 }) 3004 console.info('requestSource taskId: ' + taskId) 3005 } catch (err) { 3006 console.error(`requestPhotoDemo failed with error: ${err.code}, ${err.message}`); 3007 } 3008} 3009``` 3010 3011### requestPhoto<sup>11+</sup> 3012 3013requestPhoto(options: RequestPhotoOptions, callback: AsyncCallback<image.PixelMap>): string 3014 3015Obtains the thumbnails of an asset based on the specified options. This API uses an asynchronous callback to return the result. 3016 3017**System API**: This is a system API. 3018 3019**Required permissions**: ohos.permission.READ_IMAGEVIDEO 3020 3021**System capability**: SystemCapability.FileManagement.PhotoAccessHelper.Core 3022 3023**Parameters** 3024 3025| Name | Type | Mandatory | Description | 3026| ---------- | ------- | ---- | ---------------------------------- | 3027| options | [RequestPhotoOptions](#requestphotooptions11) | Yes | Options for obtaining the asset thumbnail.| 3028| callback | AsyncCallback<[image.PixelMap](../apis-image-kit/js-apis-image.md#pixelmap7)> | Yes | Callback invoked to return the thumbnails obtained. The callback may be invoked more than once, depending on **options**.| 3029 3030**Return value** 3031 3032| Type | Description | 3033| --------------------------------------- | ----------------- | 3034| string | ID of the task for obtaining thumbnails.| 3035 3036**Error codes** 3037 3038For details about the error codes, see [Universal Error Codes](../errorcode-universal.md) and [File Management Error Codes](../apis-core-file-kit/errorcode-filemanagement.md). 3039 3040| ID| Error Message| 3041| -------- | ---------------------------------------- | 3042| 201 | Permission verification failed, usually the result returned by VerifyAccessToken. | 3043| 202 | Permission verification failed, application which is not a system application uses system API. | 3044| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types; 3. Parameter verification failed. | 3045| 14000011 | System inner fail. | 3046 3047**Example** 3048 3049```ts 3050import { dataSharePredicates } from '@kit.ArkData'; 3051import { image } from '@kit.ImageKit'; 3052 3053async function example() { 3054 try { 3055 console.info('requestPhotoDemo') 3056 let options: photoAccessHelper.FetchOptions = { 3057 fetchColumns: [], 3058 predicates: new dataSharePredicates.DataSharePredicates() 3059 } 3060 let fetchResult = await phAccessHelper.getAssets(options); 3061 let photoAsset = await fetchResult.getFirstObject(); 3062 let taskId: string = photoAsset.requestPhoto({ 3063 "size": { 3064 "width": 256, 3065 "height": 256 3066 }, 3067 "requestPhotoType": photoAccessHelper.RequestPhotoType.REQUEST_ALL_THUMBNAILS 3068 }, async (err, pixel: image.PixelMap) => { 3069 if (err === undefined) { 3070 console.info("requestSource in, size: " + JSON.stringify((await pixel.getImageInfo()).size)) 3071 } else { 3072 console.error(`requestSource failed with error: ${err.code}, ${err.message}`); 3073 } 3074 }) 3075 console.info('requestSource taskId: ' + taskId) 3076 } catch (err) { 3077 console.error(`requestPhotoDemo failed with error: ${err.code}, ${err.message}`); 3078 } 3079} 3080``` 3081 3082### cancelPhotoRequest<sup>11+</sup> 3083 3084cancelPhotoRequest(requestId: string): void 3085 3086Cancels a task for obtaining media thumbnails. 3087 3088**System API**: This is a system API. 3089 3090**Required permissions**: ohos.permission.READ_IMAGEVIDEO 3091 3092**System capability**: SystemCapability.FileManagement.PhotoAccessHelper.Core 3093 3094**Parameters** 3095 3096| Name | Type | Mandatory | Description | 3097| ---------- | ------- | ---- | ---------------------------------- | 3098| requestId | string | Yes | ID of the task to cancel.| 3099 3100**Error codes** 3101 3102For details about the error codes, see [Universal Error Codes](../errorcode-universal.md) and [File Management Error Codes](../apis-core-file-kit/errorcode-filemanagement.md). 3103 3104| ID| Error Message| 3105| -------- | ---------------------------------------- | 3106| 201 | Permission verification failed, usually the result returned by VerifyAccessToken. | 3107| 202 | Permission verification failed, application which is not a system application uses system API. | 3108| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types; 3. Parameter verification failed. | 3109| 14000011 | System inner fail. | 3110 3111**Example** 3112 3113```ts 3114import { dataSharePredicates } from '@kit.ArkData'; 3115import { image } from '@kit.ImageKit'; 3116 3117async function example() { 3118 try { 3119 console.info('cancelPhotoRequestDemo') 3120 let options: photoAccessHelper.FetchOptions = { 3121 fetchColumns: [], 3122 predicates: new dataSharePredicates.DataSharePredicates() 3123 } 3124 let fetchResult = await phAccessHelper.getAssets(options); 3125 let photoAsset = await fetchResult.getFirstObject(); 3126 let taskId: string = photoAsset.requestPhoto({ 3127 "size": { 3128 "width": 256, 3129 "height": 256 3130 }, 3131 "requestPhotoType": photoAccessHelper.RequestPhotoType.REQUEST_ALL_THUMBNAILS 3132 }, async (err, pixel: image.PixelMap) => { 3133 if (err === undefined) { 3134 console.info("requestSource in, size: " + JSON.stringify((await pixel.getImageInfo()).size)) 3135 } else { 3136 console.error(`requestSource failed with error: ${err.code}, ${err.message}`); 3137 } 3138 }) 3139 console.info('requestSource taskId: ' + taskId) 3140 photoAsset.cancelPhotoRequest(taskId); 3141 } catch (err) { 3142 console.error(`cancelPhotoRequestDemo failed with error: ${err.code}, ${err.message}`); 3143 } 3144} 3145``` 3146 3147### getAnalysisData<sup>11+</sup> 3148 3149getAnalysisData(analysisType: AnalysisType): Promise\<string> 3150 3151Obtains analysis data. This API uses a promise to return the result. 3152 3153**System API**: This is a system API. 3154 3155**Required permissions**: ohos.permission.READ\_IMAGEVIDEO 3156 3157**System capability**: SystemCapability.FileManagement.PhotoAccessHelper.Core 3158 3159**Parameters** 3160 3161| Name | Type | Mandatory| Description | 3162| :----------- | :----------- | :- | :----------- | 3163| analysisType | [AnalysisType](#analysistype11) | Yes | Smart analysis type.| 3164 3165**Error codes** 3166 3167For details about the error codes, see [Universal Error Codes](../errorcode-universal.md) and [File Management Error Codes](../apis-core-file-kit/errorcode-filemanagement.md). 3168 3169| ID | Error Message | 3170| :------- | :-------------------------------- | 3171| 201 | Permission denied. | 3172| 202 | Called by non-system application. | 3173| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types; 3. Parameter verification failed. | 3174| 14000011 | System inner fail. | 3175 3176**Example** 3177 3178```ts 3179import { dataSharePredicates } from '@kit.ArkData'; 3180 3181async function example() { 3182 try { 3183 console.info('getAnalysisDataDemo') 3184 let fetchOptions: photoAccessHelper.FetchOptions = { 3185 fetchColumns: [], 3186 predicates: new dataSharePredicates.DataSharePredicates() 3187 } 3188 let fetchResult: photoAccessHelper.FetchResult<photoAccessHelper.PhotoAsset> = 3189 await phAccessHelper.getAssets(fetchOptions); 3190 let photoAsset: photoAccessHelper.PhotoAsset = await fetchResult.getFirstObject(); 3191 if (photoAsset != undefined) { 3192 let analysisData: string = await photoAsset.getAnalysisData( 3193 photoAccessHelper.AnalysisType.ANALYSIS_OCR); 3194 console.info('get ocr result: ' + JSON.stringify(analysisData)); 3195 } 3196 fetchResult.close(); 3197 } catch (err) { 3198 console.error(`getAnalysisDataDemofailed with error: ${err.code}, ${err.message}`); 3199 } 3200} 3201``` 3202 3203## Album 3204 3205Provides APIs to manage albums. 3206 3207### recoverAssets<sup>(deprecated)</sup> 3208 3209recoverAssets(assets: Array<PhotoAsset>, callback: AsyncCallback<void>): void 3210 3211Recovers 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. 3212 3213> **NOTE** 3214> 3215> This API is supported since API version 10 and deprecated since API version 11. Use [MediaAlbumChangeRequest.recoverAssets](#recoverassets11) instead. 3216 3217**System API**: This is a system API. 3218 3219**Required permissions**: ohos.permission.WRITE_IMAGEVIDEO 3220 3221**System capability**: SystemCapability.FileManagement.PhotoAccessHelper.Core 3222 3223**Parameters** 3224 3225| Name | Type | Mandatory| Description | 3226| -------- | ------------------------- | ---- | ---------- | 3227| assets | Array<[PhotoAsset](#photoasset)> | Yes | Array of the image or video assets to recover.| 3228| callback | AsyncCallback<void> | Yes | Callback that returns no value.| 3229 3230**Error codes** 3231 3232For details about the error codes, see [Universal Error Codes](../errorcode-universal.md) and [File Management Error Codes](../apis-core-file-kit/errorcode-filemanagement.md). 3233 3234| ID| Error Message| 3235| -------- | ---------------------------------------- | 3236| 202 | Called by non-system application. | 3237| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types; 3. Parameter verification failed. | 3238| 13900012 | Permission denied. | 3239| 13900020 | Invalid argument. | 3240| 14000011 | System inner fail. | 3241 3242**Example** 3243 3244```ts 3245import { dataSharePredicates } from '@kit.ArkData'; 3246 3247async function example() { 3248 try { 3249 console.info('recoverAssetsDemoCallback'); 3250 let predicates: dataSharePredicates.DataSharePredicates = new dataSharePredicates.DataSharePredicates(); 3251 let fetchOption: photoAccessHelper.FetchOptions = { 3252 fetchColumns: [], 3253 predicates: predicates 3254 }; 3255 let albumFetchResult: photoAccessHelper.FetchResult<photoAccessHelper.Album> = await phAccessHelper.getAlbums(photoAccessHelper.AlbumType.SYSTEM, photoAccessHelper.AlbumSubtype.TRASH); 3256 let album: photoAccessHelper.Album = await albumFetchResult.getFirstObject(); 3257 let fetchResult: photoAccessHelper.FetchResult<photoAccessHelper.PhotoAsset> = await album.getAssets(fetchOption); 3258 let asset: photoAccessHelper.PhotoAsset = await fetchResult.getFirstObject(); 3259 album.recoverAssets([asset], (err) => { 3260 if (err === undefined) { 3261 console.info('album recoverAssets successfully'); 3262 } else { 3263 console.error(`album recoverAssets failed with error: ${err.code}, ${err.message}`); 3264 } 3265 }); 3266 } catch (err) { 3267 console.error(`recoverAssetsDemoCallback failed with error: ${err.code}, ${err.message}`); 3268 } 3269} 3270``` 3271 3272### recoverAssets<sup>(deprecated)</sup> 3273 3274recoverAssets(assets: Array<PhotoAsset>): Promise<void> 3275 3276Recovers 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. 3277 3278> **NOTE** 3279> 3280> This API is supported since API version 10 and deprecated since API version 11. Use [MediaAlbumChangeRequest.recoverAssets](#recoverassets11) instead. 3281 3282**System API**: This is a system API. 3283 3284**Required permissions**: ohos.permission.WRITE_IMAGEVIDEO 3285 3286**System capability**: SystemCapability.FileManagement.PhotoAccessHelper.Core 3287 3288**Parameters** 3289 3290| Name | Type | Mandatory| Description | 3291| -------- | ------------------------- | ---- | ---------- | 3292| assets | Array<[PhotoAsset](#photoasset)> | Yes | Array of the image or video assets to recover.| 3293 3294**Return value** 3295 3296| Type | Description | 3297| --------------------------------------- | ----------------- | 3298|Promise<void> | Promise that returns no value.| 3299 3300**Error codes** 3301 3302For details about the error codes, see [Universal Error Codes](../errorcode-universal.md) and [File Management Error Codes](../apis-core-file-kit/errorcode-filemanagement.md). 3303 3304| ID| Error Message| 3305| -------- | ---------------------------------------- | 3306| 202 | Called by non-system application. | 3307| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types; 3. Parameter verification failed. | 3308| 13900012 | Permission denied. | 3309| 13900020 | Invalid argument. | 3310| 14000011 | System inner fail. | 3311 3312**Example** 3313 3314```ts 3315import { dataSharePredicates } from '@kit.ArkData'; 3316import { BusinessError } from '@kit.BasicServicesKit'; 3317 3318async function example() { 3319 try { 3320 console.info('recoverAssetsDemoPromise'); 3321 let predicates: dataSharePredicates.DataSharePredicates = new dataSharePredicates.DataSharePredicates(); 3322 let fetchOption: photoAccessHelper.FetchOptions = { 3323 fetchColumns: [], 3324 predicates: predicates 3325 }; 3326 let albumFetchResult: photoAccessHelper.FetchResult<photoAccessHelper.Album> = await phAccessHelper.getAlbums(photoAccessHelper.AlbumType.SYSTEM, photoAccessHelper.AlbumSubtype.TRASH); 3327 let album: photoAccessHelper.Album = await albumFetchResult.getFirstObject(); 3328 let fetchResult: photoAccessHelper.FetchResult<photoAccessHelper.PhotoAsset> = await album.getAssets(fetchOption); 3329 let asset: photoAccessHelper.PhotoAsset = await fetchResult.getFirstObject(); 3330 album.recoverAssets([asset]).then(() => { 3331 console.info('album recoverAssets successfully'); 3332 }).catch((err: BusinessError) => { 3333 console.error(`album recoverAssets failed with error: ${err.code}, ${err.message}`); 3334 }); 3335 } catch (err) { 3336 console.error(`recoverAssetsDemoPromise failed with error: ${err.code}, ${err.message}`); 3337 } 3338} 3339``` 3340 3341### deleteAssets<sup>(deprecated)</sup> 3342 3343deleteAssets(assets: Array<PhotoAsset>, callback: AsyncCallback<void>): void 3344 3345Deletes 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. 3346 3347> **NOTE** 3348> 3349> This API is supported since API version 10 and deprecated since API version 11. Use [MediaAlbumChangeRequest.deleteAssets](#deleteassets11) instead. 3350 3351**NOTE**<br>This operation is irreversible. The file assets deleted cannot be restored. Exercise caution when performing this operation. 3352 3353**System API**: This is a system API. 3354 3355**Required permissions**: ohos.permission.WRITE_IMAGEVIDEO 3356 3357**System capability**: SystemCapability.FileManagement.PhotoAccessHelper.Core 3358 3359**Parameters** 3360 3361| Name | Type | Mandatory| Description | 3362| -------- | ------------------------- | ---- | ---------- | 3363| assets | Array<[PhotoAsset](#photoasset)> | Yes | Array of the image or video assets to delete.| 3364| callback | AsyncCallback<void> | Yes | Callback that returns no value.| 3365 3366**Error codes** 3367 3368For details about the error codes, see [Universal Error Codes](../errorcode-universal.md) and [File Management Error Codes](../apis-core-file-kit/errorcode-filemanagement.md). 3369 3370| ID| Error Message| 3371| -------- | ---------------------------------------- | 3372| 202 | Called by non-system application. | 3373| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types; 3. Parameter verification failed. | 3374| 13900012 | Permission denied. | 3375| 13900020 | Invalid argument. | 3376| 14000011 | System inner fail. | 3377 3378**Example** 3379 3380```ts 3381import { dataSharePredicates } from '@kit.ArkData'; 3382 3383async function example() { 3384 try { 3385 console.info('deleteAssetsDemoCallback'); 3386 let predicates: dataSharePredicates.DataSharePredicates = new dataSharePredicates.DataSharePredicates(); 3387 let fetchOption: photoAccessHelper.FetchOptions = { 3388 fetchColumns: [], 3389 predicates: predicates 3390 }; 3391 let albumFetchResult: photoAccessHelper.FetchResult<photoAccessHelper.Album> = await phAccessHelper.getAlbums(photoAccessHelper.AlbumType.SYSTEM, photoAccessHelper.AlbumSubtype.TRASH); 3392 let album: photoAccessHelper.Album = await albumFetchResult.getFirstObject(); 3393 let fetchResult: photoAccessHelper.FetchResult<photoAccessHelper.PhotoAsset> = await album.getAssets(fetchOption); 3394 let asset: photoAccessHelper.PhotoAsset = await fetchResult.getFirstObject(); 3395 album.deleteAssets([asset], (err) => { 3396 if (err === undefined) { 3397 console.info('album deleteAssets successfully'); 3398 } else { 3399 console.error(`album deleteAssets failed with error: ${err.code}, ${err.message}`); 3400 } 3401 }); 3402 } catch (err) { 3403 console.error(`deleteAssetsDemoCallback failed with error: ${err.code}, ${err.message}`); 3404 } 3405} 3406``` 3407 3408### deleteAssets<sup>(deprecated)</sup> 3409 3410deleteAssets(assets: Array<PhotoAsset>): Promise<void> 3411 3412Deletes 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. 3413 3414> **NOTE** 3415> 3416> This API is supported since API version 10 and deprecated since API version 11. Use [MediaAlbumChangeRequest.deleteAssets](#deleteassets11) instead. 3417 3418**NOTE**<br>This operation is irreversible. The file assets deleted cannot be restored. Exercise caution when performing this operation. 3419 3420**System API**: This is a system API. 3421 3422**Required permissions**: ohos.permission.WRITE_IMAGEVIDEO 3423 3424**System capability**: SystemCapability.FileManagement.PhotoAccessHelper.Core 3425 3426**Parameters** 3427 3428| Name | Type | Mandatory| Description | 3429| -------- | ------------------------- | ---- | ---------- | 3430| assets | Array<[PhotoAsset](#photoasset)> | Yes | Array of the image or video assets to delete.| 3431 3432**Return value** 3433 3434| Type | Description | 3435| --------------------------------------- | ----------------- | 3436|Promise<void> | Promise that returns no value.| 3437 3438**Error codes** 3439 3440For details about the error codes, see [Universal Error Codes](../errorcode-universal.md) and [File Management Error Codes](../apis-core-file-kit/errorcode-filemanagement.md). 3441 3442| ID| Error Message| 3443| -------- | ---------------------------------------- | 3444| 202 | Called by non-system application. | 3445| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types; 3. Parameter verification failed. | 3446| 13900012 | Permission denied. | 3447| 13900020 | Invalid argument. | 3448| 14000011 | System inner fail. | 3449 3450**Example** 3451 3452```ts 3453import { dataSharePredicates } from '@kit.ArkData'; 3454import { BusinessError } from '@kit.BasicServicesKit'; 3455 3456async function example() { 3457 try { 3458 console.info('deleteAssetsDemoPromise'); 3459 let predicates: dataSharePredicates.DataSharePredicates = new dataSharePredicates.DataSharePredicates(); 3460 let fetchOption: photoAccessHelper.FetchOptions = { 3461 fetchColumns: [], 3462 predicates: predicates 3463 }; 3464 let albumFetchResult: photoAccessHelper.FetchResult<photoAccessHelper.Album> = await phAccessHelper.getAlbums(photoAccessHelper.AlbumType.SYSTEM, photoAccessHelper.AlbumSubtype.TRASH); 3465 let album: photoAccessHelper.Album = await albumFetchResult.getFirstObject(); 3466 let fetchResult: photoAccessHelper.FetchResult<photoAccessHelper.PhotoAsset> = await album.getAssets(fetchOption); 3467 let asset: photoAccessHelper.PhotoAsset = await fetchResult.getFirstObject(); 3468 album.deleteAssets([asset]).then(() => { 3469 console.info('album deleteAssets successfully'); 3470 }).catch((err: BusinessError) => { 3471 console.error(`album deleteAssets failed with error: ${err.code}, ${err.message}`); 3472 }); 3473 } catch (err) { 3474 console.error(`deleteAssetsDemoPromise failed with error: ${err.code}, ${err.message}`); 3475 } 3476} 3477``` 3478 3479### setCoverUri<sup>(deprecated)</sup> 3480 3481setCoverUri(uri: string, callback: AsyncCallback<void>): void 3482 3483Sets the album cover. This API uses an asynchronous callback to return the result. 3484 3485> **NOTE** 3486> 3487> This API is supported since API version 10 and deprecated since API version 11. Use [MediaAlbumChangeRequest.setCoverUri](#setcoveruri11) instead. 3488 3489**NOTE**<br>This API can be used to set the user album cover, but not the system album cover. 3490 3491**System API**: This is a system API. 3492 3493**Required permissions**: ohos.permission.WRITE_IMAGEVIDEO 3494 3495**System capability**: SystemCapability.FileManagement.PhotoAccessHelper.Core 3496 3497**Parameters** 3498 3499| Name | Type | Mandatory| Description | 3500| -------- | ------------------------- | ---- | ---------- | 3501| uri | string | Yes | URI of the file to be set as the album cover.| 3502| callback | AsyncCallback<void> | Yes | Callback that returns no value.| 3503 3504**Error codes** 3505 3506For details about the error codes, see [Universal Error Codes](../errorcode-universal.md) and [File Management Error Codes](../apis-core-file-kit/errorcode-filemanagement.md). 3507 3508| ID| Error Message| 3509| -------- | ---------------------------------------- | 3510| 202 | Called by non-system application. | 3511| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types; 3. Parameter verification failed. | 3512| 13900012 | Permission denied. | 3513| 13900020 | Invalid argument. | 3514| 14000011 | System inner fail. | 3515 3516**Example** 3517 3518```ts 3519import { dataSharePredicates } from '@kit.ArkData'; 3520 3521async function example() { 3522 try { 3523 console.info('setCoverUriDemoCallback'); 3524 let predicates: dataSharePredicates.DataSharePredicates = new dataSharePredicates.DataSharePredicates(); 3525 let fetchOption: photoAccessHelper.FetchOptions = { 3526 fetchColumns: [], 3527 predicates: predicates 3528 }; 3529 let albumFetchResult: photoAccessHelper.FetchResult<photoAccessHelper.Album> = await phAccessHelper.getAlbums(photoAccessHelper.AlbumType.USER, photoAccessHelper.AlbumSubtype.USER_GENERIC); 3530 let album: photoAccessHelper.Album = await albumFetchResult.getFirstObject(); 3531 let fetchResult: photoAccessHelper.FetchResult<photoAccessHelper.PhotoAsset> = await album.getAssets(fetchOption); 3532 let asset: photoAccessHelper.PhotoAsset = await fetchResult.getFirstObject(); 3533 album.setCoverUri(asset.uri, (err) => { 3534 if (err === undefined) { 3535 console.info('album setCoverUri successfully'); 3536 } else { 3537 console.error(`album setCoverUri failed with error: ${err.code}, ${err.message}`); 3538 } 3539 }); 3540 } catch (err) { 3541 console.error(`setCoverUriDemoCallback failed with error: ${err.code}, ${err.message}`); 3542 } 3543} 3544``` 3545 3546### setCoverUri<sup>(deprecated)</sup> 3547 3548setCoverUri(uri: string): Promise<void> 3549 3550Sets the album cover. This API uses a promise to return the result. 3551 3552> **NOTE** 3553> 3554> This API is supported since API version 10 and deprecated since API version 11. Use [MediaAlbumChangeRequest.setCoverUri](#setcoveruri11) instead. 3555 3556**NOTE**<br>This API can be used to set the user album cover, but not the system album cover. 3557 3558**System API**: This is a system API. 3559 3560**Required permissions**: ohos.permission.WRITE_IMAGEVIDEO 3561 3562**System capability**: SystemCapability.FileManagement.PhotoAccessHelper.Core 3563 3564**Parameters** 3565 3566| Name | Type | Mandatory| Description | 3567| -------- | ------------------------- | ---- | ---------- | 3568| uri | string | Yes | URI of the file to be set as the album cover.| 3569 3570**Return value** 3571 3572| Type | Description | 3573| --------------------------------------- | ----------------- | 3574|Promise<void> | Promise that returns no value.| 3575 3576**Error codes** 3577 3578For details about the error codes, see [Universal Error Codes](../errorcode-universal.md) and [File Management Error Codes](../apis-core-file-kit/errorcode-filemanagement.md). 3579 3580| ID| Error Message| 3581| -------- | ---------------------------------------- | 3582| 202 | Called by non-system application. | 3583| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types; 3. Parameter verification failed. | 3584| 13900012 | Permission denied. | 3585| 13900020 | Invalid argument. | 3586| 14000011 | System inner fail. | 3587**Example** 3588 3589```ts 3590import { dataSharePredicates } from '@kit.ArkData'; 3591import { BusinessError } from '@kit.BasicServicesKit'; 3592 3593async function example() { 3594 try { 3595 console.info('setCoverUriDemoPromise'); 3596 let predicates: dataSharePredicates.DataSharePredicates = new dataSharePredicates.DataSharePredicates(); 3597 let fetchOption: photoAccessHelper.FetchOptions = { 3598 fetchColumns: [], 3599 predicates: predicates 3600 }; 3601 let albumFetchResult: photoAccessHelper.FetchResult<photoAccessHelper.Album> = await phAccessHelper.getAlbums(photoAccessHelper.AlbumType.USER, photoAccessHelper.AlbumSubtype.USER_GENERIC); 3602 let album: photoAccessHelper.Album = await albumFetchResult.getFirstObject(); 3603 let fetchResult: photoAccessHelper.FetchResult<photoAccessHelper.PhotoAsset> = await album.getAssets(fetchOption); 3604 let asset: photoAccessHelper.PhotoAsset = await fetchResult.getFirstObject(); 3605 album.setCoverUri(asset.uri).then(() => { 3606 console.info('album setCoverUri successfully'); 3607 }).catch((err: BusinessError) => { 3608 console.error(`album setCoverUri failed with error: ${err.code}, ${err.message}`); 3609 }); 3610 } catch (err) { 3611 console.error(`setCoverUriDemoPromise failed with error: ${err.code}, ${err.message}`); 3612 } 3613} 3614``` 3615 3616## MediaAssetEditData<sup>11+</sup> 3617 3618Represents the edited media asset data. 3619 3620**System API**: This is a system API. 3621 3622**System capability**: SystemCapability.FileManagement.PhotoAccessHelper.Core 3623 3624### Attributes 3625 3626| Name | Type | Readable | Writable | Description | 3627| ------------ | ------ | ---- | ---- | ------- | 3628| compatibleFormat | string | Yes | Yes | Format of the edited data. **System API**: This is a system API. | 3629| formatVersion | string | Yes | Yes | Version of the data format. **System API**: This is a system API. | 3630| data | string | Yes | Yes | Content edited. **System API**: This is a system API. | 3631 3632### constructor<sup>11+</sup> 3633 3634constructor(compatibleFormat: string, formatVersion: string) 3635 3636Constructor. 3637 3638**System API**: This is a system API. 3639 3640**System capability**: SystemCapability.FileManagement.PhotoAccessHelper.Core 3641 3642**Parameters** 3643 3644| Name | Type | Mandatory| Description | 3645| -------- | ------------------------- | ---- | ---------- | 3646| compatibleFormat | string | Yes | Format of the edited data.| 3647| formatVersion | string | Yes | Version of the data format.| 3648 3649**Error codes** 3650 3651For details about the error codes, see [Universal Error Codes](../errorcode-universal.md) and [File Management Error Codes](../apis-core-file-kit/errorcode-filemanagement.md). 3652 3653| ID| Error Message| 3654| -------- | ---------------------------------------- | 3655| 202 | Called by non-system application. | 3656| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types; 3. Parameter verification failed. | 3657| 14000011 | System inner fail. | 3658 3659**Example** 3660 3661```ts 3662let assetEditData: photoAccessHelper.MediaAssetEditData = new photoAccessHelper.MediaAssetEditData('system', '1.0'); 3663``` 3664 3665## MediaAssetChangeRequest<sup>11+</sup> 3666 3667Represents a media asset change request. 3668 3669**System capability**: SystemCapability.FileManagement.PhotoAccessHelper.Core 3670 3671### createAssetRequest<sup>11+</sup> 3672 3673static createAssetRequest(context: Context, displayName: string, options?: PhotoCreateOptions): MediaAssetChangeRequest 3674 3675Creates an asset change request with the specified file name. 3676 3677The file name must comply with the following specifications: 3678- The file name consists of a valid file name and an image or video file name extension. 3679- The file name cannot exceed 255 characters. 3680- The file name cannot contain any of the following characters:<br> . .. \ / : * ? " ' ` < > | { } [ ] 3681 3682**System API**: This is a system API. 3683 3684**System capability**: SystemCapability.FileManagement.PhotoAccessHelper.Core 3685 3686**Parameters** 3687 3688| Name | Type | Mandatory| Description | 3689| ------- | ------- | ---- | -------------------------- | 3690| context | [Context](../apis-ability-kit/js-apis-inner-application-context.md) | Yes | Context of the ability instance.| 3691| displayName | string | Yes | File name of the image or video to create. | 3692| options | [PhotoCreateOptions](#photocreateoptions) | No | Options for creating an image or video asset. | 3693 3694**Return value** 3695 3696| Type | Description | 3697| --------------------------------------- | ----------------- | 3698| [MediaAssetChangeRequest](#mediaassetchangerequest11) | **MediaAssetChangeRequest** created.| 3699 3700**Error codes** 3701 3702For details about the error codes, see [Universal Error Codes](../errorcode-universal.md) and [File Management Error Codes](../apis-core-file-kit/errorcode-filemanagement.md). 3703 3704| ID| Error Message| 3705| -------- | ---------------------------------------- | 3706| 202 | Called by non-system application. | 3707| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types; 3. Parameter verification failed. | 3708| 14000001 | Invalid display name. | 3709| 14000011 | System inner fail. | 3710 3711**Example** 3712 3713```ts 3714async function example() { 3715 console.info('createAssetRequestDemo'); 3716 try { 3717 let testFileName: string = 'testFile' + Date.now() + '.jpg'; 3718 let assetChangeRequest: photoAccessHelper.MediaAssetChangeRequest = photoAccessHelper.MediaAssetChangeRequest.createAssetRequest(context, testFileName); 3719 // Ensure that the asset specified by fileUri exists. 3720 let fileUri = 'file://com.example.temptest/data/storage/el2/base/haps/entry/files/test.jpg'; 3721 assetChangeRequest.addResource(photoAccessHelper.ResourceType.IMAGE_RESOURCE, fileUri); 3722 await phAccessHelper.applyChanges(assetChangeRequest); 3723 console.info('apply createAssetRequest successfully'); 3724 } catch (err) { 3725 console.error(`createAssetRequestDemo failed with error: ${err.code}, ${err.message}`); 3726 } 3727} 3728``` 3729 3730### setFavorite<sup>11+</sup> 3731 3732setFavorite(favoriteState: boolean): void 3733 3734Favorites or unfavorites this file. 3735 3736**System API**: This is a system API. 3737 3738**System capability**: SystemCapability.FileManagement.PhotoAccessHelper.Core 3739 3740**Parameters** 3741 3742| Name | Type | Mandatory | Description | 3743| ---------- | ------- | ---- | ---------------------------------- | 3744| favoriteState | boolean | Yes | Operation to perform. The value **true** means to favorite the file, and **false** means the opposite.| 3745 3746**Error codes** 3747 3748For details about the error codes, see [Universal Error Codes](../errorcode-universal.md) and [File Management Error Codes](../apis-core-file-kit/errorcode-filemanagement.md). 3749 3750| ID| Error Message| 3751| -------- | ---------------------------------------- | 3752| 202 | Called by non-system application. | 3753| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types; 3. Parameter verification failed. | 3754| 14000011 | System inner fail. | 3755 3756**Example** 3757 3758```ts 3759import { dataSharePredicates } from '@kit.ArkData'; 3760import { BusinessError } from '@kit.BasicServicesKit'; 3761 3762async function example() { 3763 console.info('setFavoriteDemo'); 3764 let predicates: dataSharePredicates.DataSharePredicates = new dataSharePredicates.DataSharePredicates(); 3765 let fetchOption: photoAccessHelper.FetchOptions = { 3766 fetchColumns: [], 3767 predicates: predicates 3768 }; 3769 let fetchResult: photoAccessHelper.FetchResult<photoAccessHelper.PhotoAsset> = await phAccessHelper.getAssets(fetchOption); 3770 let asset = await fetchResult.getFirstObject(); 3771 let assetChangeRequest: photoAccessHelper.MediaAssetChangeRequest = new photoAccessHelper.MediaAssetChangeRequest(asset); 3772 assetChangeRequest.setFavorite(true); 3773 phAccessHelper.applyChanges(assetChangeRequest).then(() => { 3774 console.info('apply setFavorite successfully'); 3775 }).catch((err: BusinessError) => { 3776 console.error(`apply setFavorite failed with error: ${err.code}, ${err.message}`); 3777 }); 3778} 3779``` 3780 3781### setHidden<sup>11+</sup> 3782 3783setHidden(hiddenState: boolean): void 3784 3785Hides this file. 3786 3787**System API**: This is a system API. 3788 3789**System capability**: SystemCapability.FileManagement.PhotoAccessHelper.Core 3790 3791**Parameters** 3792 3793| Name | Type | Mandatory | Description | 3794| ---------- | ------- | ---- | ---------------------------------- | 3795| hiddenState | boolean | Yes | Whether to hide the file. The value **true** means to hide the file; the value **false** means the opposite.| 3796 3797**Error codes** 3798 3799For details about the error codes, see [Universal Error Codes](../errorcode-universal.md) and [File Management Error Codes](../apis-core-file-kit/errorcode-filemanagement.md). 3800 3801| ID| Error Message| 3802| -------- | ---------------------------------------- | 3803| 202 | Called by non-system application. | 3804| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types; 3. Parameter verification failed. | 3805| 14000011 | System inner fail. | 3806 3807**Example** 3808 3809```ts 3810import { dataSharePredicates } from '@kit.ArkData'; 3811import { BusinessError } from '@kit.BasicServicesKit'; 3812 3813async function example() { 3814 console.info('setHiddenDemo'); 3815 let predicates: dataSharePredicates.DataSharePredicates = new dataSharePredicates.DataSharePredicates(); 3816 let fetchOption: photoAccessHelper.FetchOptions = { 3817 fetchColumns: [], 3818 predicates: predicates 3819 }; 3820 let fetchResult: photoAccessHelper.FetchResult<photoAccessHelper.PhotoAsset> = await phAccessHelper.getAssets(fetchOption); 3821 let asset = await fetchResult.getFirstObject(); 3822 let assetChangeRequest: photoAccessHelper.MediaAssetChangeRequest = new photoAccessHelper.MediaAssetChangeRequest(asset); 3823 assetChangeRequest.setHidden(true); 3824 phAccessHelper.applyChanges(assetChangeRequest).then(() => { 3825 console.info('apply setHidden successfully'); 3826 }).catch((err: BusinessError) => { 3827 console.error(`apply setHidden failed with error: ${err.code}, ${err.message}`); 3828 }); 3829} 3830``` 3831 3832### setUserComment<sup>11+</sup> 3833 3834setUserComment(userComment: string): void 3835 3836Sets the user comment information of this media asset. 3837 3838**System API**: This is a system API. 3839 3840**System capability**: SystemCapability.FileManagement.PhotoAccessHelper.Core 3841 3842**Parameters** 3843 3844| Name | Type | Mandatory | Description | 3845| ---------- | ------- | ---- | ---------------------------------- | 3846| userComment | string | Yes | Comment information to set, which cannot exceed 420 characters.| 3847 3848**Error codes** 3849 3850For details about the error codes, see [Universal Error Codes](../errorcode-universal.md) and [File Management Error Codes](../apis-core-file-kit/errorcode-filemanagement.md). 3851 3852| ID| Error Message| 3853| -------- | ---------------------------------------- | 3854| 202 | Called by non-system application. | 3855| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types; 3. Parameter verification failed. | 3856| 14000011 | System inner fail. | 3857 3858**Example** 3859 3860```ts 3861import { dataSharePredicates } from '@kit.ArkData'; 3862import { BusinessError } from '@kit.BasicServicesKit'; 3863 3864async function example() { 3865 console.info('setUserCommentDemo'); 3866 let predicates: dataSharePredicates.DataSharePredicates = new dataSharePredicates.DataSharePredicates(); 3867 let fetchOption: photoAccessHelper.FetchOptions = { 3868 fetchColumns: [], 3869 predicates: predicates 3870 }; 3871 let fetchResult: photoAccessHelper.FetchResult<photoAccessHelper.PhotoAsset> = await phAccessHelper.getAssets(fetchOption); 3872 let asset = await fetchResult.getFirstObject(); 3873 let assetChangeRequest: photoAccessHelper.MediaAssetChangeRequest = new photoAccessHelper.MediaAssetChangeRequest(asset); 3874 let userComment: string = 'test_set_user_comment'; 3875 assetChangeRequest.setUserComment(userComment); 3876 phAccessHelper.applyChanges(assetChangeRequest).then(() => { 3877 console.info('apply setUserComment successfully'); 3878 }).catch((err: BusinessError) => { 3879 console.error(`apply setUserComment failed with error: ${err.code}, ${err.message}`); 3880 }); 3881} 3882``` 3883 3884### setEditData<sup>11+</sup> 3885 3886setEditData(editData: MediaAssetEditData): void 3887 3888Saves the edited data of an asset. 3889 3890**System API**: This is a system API. 3891 3892**System capability**: SystemCapability.FileManagement.PhotoAccessHelper.Core 3893 3894**Parameters** 3895 3896| Name | Type | Mandatory | Description | 3897| ---------- | ------- | ---- | ---------------------------------- | 3898| editData | [MediaAssetEditData](#mediaasseteditdata11) | Yes | Edited data to save.| 3899 3900**Error codes** 3901 3902For details about the error codes, see [Universal Error Codes](../errorcode-universal.md) and [File Management Error Codes](../apis-core-file-kit/errorcode-filemanagement.md). 3903 3904| ID| Error Message| 3905| -------- | ---------------------------------------- | 3906| 202 | Called by non-system application. | 3907| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types; 3. Parameter verification failed. | 3908| 14000011 | System inner fail. | 3909 3910**Example** 3911 3912```ts 3913import { dataSharePredicates } from '@kit.ArkData'; 3914import { BusinessError } from '@kit.BasicServicesKit'; 3915 3916async function example() { 3917 console.info('setEditDataDemo'); 3918 let predicates: dataSharePredicates.DataSharePredicates = new dataSharePredicates.DataSharePredicates(); 3919 let fetchOption: photoAccessHelper.FetchOptions = { 3920 fetchColumns: [], 3921 predicates: predicates 3922 }; 3923 let fetchResult: photoAccessHelper.FetchResult<photoAccessHelper.PhotoAsset> = await phAccessHelper.getAssets(fetchOption); 3924 let asset = await fetchResult.getFirstObject(); 3925 let assetChangeRequest: photoAccessHelper.MediaAssetChangeRequest = new photoAccessHelper.MediaAssetChangeRequest(asset); 3926 3927 let assetEditData: photoAccessHelper.MediaAssetEditData = new photoAccessHelper.MediaAssetEditData('system', '1.0'); 3928 let fileUri = 'file://com.example.temptest/data/storage/el2/base/haps/entry/files/test.jpg'; 3929 assetChangeRequest.addResource(photoAccessHelper.ResourceType.IMAGE_RESOURCE, fileUri); 3930 assetEditData.data = '123456'; 3931 assetChangeRequest.setEditData(assetEditData); 3932 phAccessHelper.applyChanges(assetChangeRequest).then(() => { 3933 console.info('apply setEditData successfully'); 3934 }).catch((err: BusinessError) => { 3935 console.error(`apply setEditData failed with error: ${err.code}, ${err.message}`); 3936 }); 3937} 3938``` 3939 3940### addResource<sup>11+</sup> 3941 3942addResource(type: ResourceType, proxy: PhotoProxy): void 3943 3944Adds resources using **PhotoProxy** data. 3945 3946> **NOTE**<br>For the same asset change request, this API cannot be repeatedly called after resources are successfully added. 3947 3948**System API**: This is a system API available only for camera applications. 3949 3950**System capability**: SystemCapability.FileManagement.PhotoAccessHelper.Core 3951 3952**Parameters** 3953 3954| Name | Type | Mandatory| Description | 3955| ------- |---------------------------------| ---- |----------------------| 3956| type | [ResourceType](#resourcetype11) | Yes | Type of the resource to add. | 3957| proxy | [PhotoProxy](#photoproxy11) | Yes | PhotoProxy data of the resource to add.| 3958 3959**Error codes** 3960 3961For details about the error codes, see [Universal Error Codes](../errorcode-universal.md) and [File Management Error Codes](../apis-core-file-kit/errorcode-filemanagement.md). 3962 3963| ID | Error Message | 3964|----------|-----------------------------------| 3965| 202 | Called by non-system application. | 3966| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types; 3. Parameter verification failed. | 3967| 14000011 | System inner fail. | 3968| 14000016 | Operation Not Support. | 3969 3970**Example** 3971 3972```ts 3973class PhotoProxyImpl implements photoAccessHelper.PhotoProxy { 3974 // Implement PhotoProxy. 3975} 3976 3977async function example() { 3978 console.info('addResourceByPhotoProxyDemo'); 3979 try { 3980 let photoType: photoAccessHelper.PhotoType = photoAccessHelper.PhotoType.IMAGE; 3981 let extension: string = 'jpg'; 3982 let assetChangeRequest: photoAccessHelper.MediaAssetChangeRequest = photoAccessHelper.MediaAssetChangeRequest.createAssetRequest(context, photoType, extension); 3983 let photoProxy: PhotoProxyImpl = new PhotoProxyImpl(); 3984 assetChangeRequest.addResource(photoAccessHelper.ResourceType.IMAGE_RESOURCE, photoProxy); 3985 await phAccessHelper.applyChanges(assetChangeRequest); 3986 console.info('addResourceByPhotoProxy successfully'); 3987 } catch (err) { 3988 console.error(`addResourceByPhotoProxyDemo failed with error: ${err.code}, ${err.message}`); 3989 } 3990} 3991``` 3992 3993### setLocation<sup>11+</sup> 3994 3995setLocation(longitude: number, latitude: number): void 3996 3997Sets location information. 3998 3999**System API**: This is a system API. 4000 4001**System capability**: SystemCapability.FileManagement.PhotoAccessHelper.Core 4002 4003**Parameters** 4004 4005| Name | Type | Mandatory| Description | 4006| ------- |-------------| ---- |-------| 4007| longitude | number | Yes | Longitude.| 4008| latitude | number | Yes | Latitude. | 4009 4010**Error codes** 4011 4012For details about the error codes, see [Universal Error Codes](../errorcode-universal.md) and [File Management Error Codes](../apis-core-file-kit/errorcode-filemanagement.md). 4013 4014| ID| Error Message| 4015| -------- | ---------------------------------------- | 4016| 202 | Called by non-system application. | 4017| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types; 3. Parameter verification failed. | 4018| 14000011 | System inner fail. | 4019 4020**Example** 4021 4022```ts 4023import { dataSharePredicates } from '@kit.ArkData'; 4024import { BusinessError } from '@kit.BasicServicesKit'; 4025 4026async function example() { 4027 console.info('setLocationDemo'); 4028 let predicates: dataSharePredicates.DataSharePredicates = new dataSharePredicates.DataSharePredicates(); 4029 let fetchOption: photoAccessHelper.FetchOptions = { 4030 fetchColumns: [], 4031 predicates: predicates 4032 }; 4033 let fetchResult: photoAccessHelper.FetchResult<photoAccessHelper.PhotoAsset> = await phAccessHelper.getAssets(fetchOption); 4034 let asset = await fetchResult.getFirstObject(); 4035 let assetChangeRequest: photoAccessHelper.MediaAssetChangeRequest = new photoAccessHelper.MediaAssetChangeRequest(asset); 4036 assetChangeRequest.setLocation(120.52, 30.40); 4037 phAccessHelper.applyChanges(assetChangeRequest).then(() => { 4038 console.info('apply setLocation successfully'); 4039 }).catch((err: BusinessError) => { 4040 console.error(`apply setLocation failed with error: ${err.code}, ${err.message}`); 4041 }); 4042} 4043``` 4044 4045### setCameraShotKey<sup>12+</sup> 4046 4047setCameraShotKey(cameraShotKey: string): void 4048 4049Sets the Key for the Ultra Snapshot feature, which allows the camera to take photos or record videos with the screen off. 4050 4051**System API**: This is a system API. 4052 4053**System capability**: SystemCapability.FileManagement.PhotoAccessHelper.Core 4054 4055**Parameters** 4056 4057| Name | Type | Mandatory | Description | 4058| ---------- | ------- | ---- | ---------------------------------- | 4059| 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.| 4060 4061**Error codes** 4062 4063For details about the error codes, see [Universal Error Codes](../errorcode-universal.md) and [File Management Error Codes](../apis-core-file-kit/errorcode-filemanagement.md). 4064 4065| ID| Error Message| 4066| -------- | ---------------------------------------- | 4067| 202 | Called by non-system application. | 4068| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types; 3. Parameter verification failed. | 4069| 14000011 | System inner fail. | 4070 4071**Example** 4072 4073```ts 4074async function example(asset: photoAccessHelper.PhotoAsset) { 4075 console.info('setCameraShotKeyDemo'); 4076 try { 4077 let assetChangeRequest: photoAccessHelper.MediaAssetChangeRequest = new photoAccessHelper.MediaAssetChangeRequest(asset); 4078 let cameraShotKey: string = 'test_MediaAssetChangeRequest_setCameraShotKey'; 4079 assetChangeRequest.setCameraShotKey(cameraShotKey); 4080 await phAccessHelper.applyChanges(assetChangeRequest); 4081 console.info('apply setCameraShotKey successfully'); 4082 } catch (err) { 4083 console.error(`apply setCameraShotKey failed with error: ${err.code}, ${err.message}`); 4084 } 4085} 4086``` 4087 4088### setEffectMode<sup>12+</sup> 4089 4090setEffectMode(mode: MovingPhotoEffectMode): void 4091 4092Sets the effect of this moving photo. 4093 4094**System API**: This is a system API. 4095 4096**System capability**: SystemCapability.FileManagement.PhotoAccessHelper.Core 4097 4098**Parameters** 4099 4100| Name | Type | Mandatory | Description | 4101| ---------- | ------- | ---- | ---------------------------------- | 4102| mode | [MovingPhotoEffectMode](#movingphotoeffectmode12) | Yes | Effect to set.| 4103 4104**Error codes** 4105 4106For details about the error codes, see [Universal Error Codes](../errorcode-universal.md) and [File Management Error Codes](../apis-core-file-kit/errorcode-filemanagement.md). 4107 4108| ID| Error Message| 4109| -------- | ---------------------------------------- | 4110| 202 | Called by non-system application. | 4111| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types; 3. Parameter verification failed. | 4112| 14000011 | System inner fail. | 4113| 14000016 | Operation Not Support. | 4114 4115**Example** 4116 4117```ts 4118async function example(asset: photoAccessHelper.PhotoAsset) { 4119 console.info('setEffectModeDemo'); 4120 try { 4121 let assetChangeRequest: photoAccessHelper.MediaAssetChangeRequest = new photoAccessHelper.MediaAssetChangeRequest(asset); 4122 assetChangeRequest.setEffectMode(photoAccessHelper.MovingPhotoEffectMode.LONG_EXPOSURE); 4123 // Ensure that the asset specified by fileUri exists. 4124 let imageFileUri = 'file://com.example.temptest/data/storage/el2/base/haps/entry/files/long_exposure.jpg'; 4125 let videoFileUri = 'file://com.example.temptest/data/storage/el2/base/haps/entry/files/long_exposure.mp4'; 4126 assetChangeRequest.addResource(photoAccessHelper.ResourceType.IMAGE_RESOURCE, imageFileUri); 4127 assetChangeRequest.addResource(photoAccessHelper.ResourceType.VIDEO_RESOURCE, videoFileUri); 4128 await phAccessHelper.applyChanges(assetChangeRequest); 4129 console.info('apply setEffectMode successfully'); 4130 } catch (err) { 4131 console.error(`apply setEffectMode failed with error: ${err.code}, ${err.message}`); 4132 } 4133} 4134``` 4135 4136## MediaAssetsChangeRequest<sup>11+</sup> 4137 4138Represents a request for changing multiple assets. 4139 4140**System API**: This is a system API. 4141 4142**System capability**: SystemCapability.FileManagement.PhotoAccessHelper.Core 4143 4144### constructor<sup>11+</sup> 4145 4146constructor(assets: Array<PhotoAsset>) 4147 4148Constructor. 4149 4150**System API**: This is a system API. 4151 4152**System capability**: SystemCapability.FileManagement.PhotoAccessHelper.Core 4153 4154**Parameters** 4155 4156| Name | Type | Mandatory| Description | 4157| -------- | ------------------------- | ---- | ---------- | 4158| assets | Array<[PhotoAsset](#photoasset)> | Yes | Assets to change.| 4159 4160**Error codes** 4161 4162For details about the error codes, see [Universal Error Codes](../errorcode-universal.md) and [File Management Error Codes](../apis-core-file-kit/errorcode-filemanagement.md). 4163 4164| ID| Error Message| 4165| -------- | ---------------------------------------- | 4166| 202 | Called by non-system application. | 4167| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types; 3. Parameter verification failed. | 4168| 14000011 | System inner fail. | 4169 4170**Example** 4171 4172```ts 4173import { dataSharePredicates } from '@kit.ArkData'; 4174 4175async function example() { 4176 console.info('MediaAssetsChangeRequest constructorDemo'); 4177 let predicates: dataSharePredicates.DataSharePredicates = new dataSharePredicates.DataSharePredicates(); 4178 let fetchOption: photoAccessHelper.FetchOptions = { 4179 fetchColumns: [], 4180 predicates: predicates 4181 }; 4182 let fetchResult: photoAccessHelper.FetchResult<photoAccessHelper.PhotoAsset> = await phAccessHelper.getAssets(fetchOption); 4183 let photoAssetList: Array<photoAccessHelper.PhotoAsset> = await fetchResult.getAllObjects(); 4184 let assetsChangeRequest: photoAccessHelper.MediaAssetsChangeRequest = new photoAccessHelper.MediaAssetsChangeRequest(photoAssetList); 4185} 4186``` 4187 4188### setFavorite<sup>11+</sup> 4189 4190setFavorite(favoriteState: boolean): void 4191 4192Favorites or unfavorites this file. 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| favoriteState | boolean | Yes | Operation to perform. The value **true** means to favorite the file, and **false** means the opposite.| 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('setFavoriteDemo'); 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 photoAssetList: Array<photoAccessHelper.PhotoAsset> = await fetchResult.getAllObjects(); 4229 let assetsChangeRequest: photoAccessHelper.MediaAssetsChangeRequest = new photoAccessHelper.MediaAssetsChangeRequest(photoAssetList); 4230 assetsChangeRequest.setFavorite(true); 4231 phAccessHelper.applyChanges(assetsChangeRequest).then(() => { 4232 console.info('apply setFavorite successfully'); 4233 }).catch((err: BusinessError) => { 4234 console.error(`apply setFavorite failed with error: ${err.code}, ${err.message}`); 4235 }); 4236} 4237``` 4238 4239### setHidden<sup>11+</sup> 4240 4241setHidden(hiddenState: boolean): void 4242 4243Hides this file. 4244 4245**System API**: This is a system API. 4246 4247**System capability**: SystemCapability.FileManagement.PhotoAccessHelper.Core 4248 4249**Parameters** 4250 4251| Name | Type | Mandatory | Description | 4252| ---------- | ------- | ---- | ---------------------------------- | 4253| hiddenState | boolean | Yes | Whether to hide the file. The value **true** means to hide the file; the value **false** means the opposite.| 4254 4255**Error codes** 4256 4257For details about the error codes, see [Universal Error Codes](../errorcode-universal.md) and [File Management Error Codes](../apis-core-file-kit/errorcode-filemanagement.md). 4258 4259| ID| Error Message| 4260| -------- | ---------------------------------------- | 4261| 202 | Called by non-system application. | 4262| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types; 3. Parameter verification failed. | 4263| 14000011 | System inner fail. | 4264 4265**Example** 4266 4267```ts 4268import { dataSharePredicates } from '@kit.ArkData'; 4269import { BusinessError } from '@kit.BasicServicesKit'; 4270 4271async function example() { 4272 console.info('setHiddenDemo'); 4273 let predicates: dataSharePredicates.DataSharePredicates = new dataSharePredicates.DataSharePredicates(); 4274 let fetchOption: photoAccessHelper.FetchOptions = { 4275 fetchColumns: [], 4276 predicates: predicates 4277 }; 4278 let fetchResult: photoAccessHelper.FetchResult<photoAccessHelper.PhotoAsset> = await phAccessHelper.getAssets(fetchOption); 4279 let photoAssetList: Array<photoAccessHelper.PhotoAsset> = await fetchResult.getAllObjects(); 4280 let assetsChangeRequest: photoAccessHelper.MediaAssetsChangeRequest = new photoAccessHelper.MediaAssetsChangeRequest(photoAssetList); 4281 assetsChangeRequest.setHidden(true); 4282 phAccessHelper.applyChanges(assetsChangeRequest).then(() => { 4283 console.info('apply setHidden successfully'); 4284 }).catch((err: BusinessError) => { 4285 console.error(`apply setHidden failed with error: ${err.code}, ${err.message}`); 4286 }); 4287} 4288``` 4289 4290### setUserComment<sup>11+</sup> 4291 4292setUserComment(userComment: string): void 4293 4294Sets the user comment information of this media asset. 4295 4296**System API**: This is a system API. 4297 4298**System capability**: SystemCapability.FileManagement.PhotoAccessHelper.Core 4299 4300**Parameters** 4301 4302| Name | Type | Mandatory | Description | 4303| ---------- | ------- | ---- | ---------------------------------- | 4304| userComment | string | Yes | Comment information to set, which cannot exceed 420 characters.| 4305 4306**Error codes** 4307 4308For details about the error codes, see [Universal Error Codes](../errorcode-universal.md) and [File Management Error Codes](../apis-core-file-kit/errorcode-filemanagement.md). 4309 4310| ID| Error Message| 4311| -------- | ---------------------------------------- | 4312| 202 | Called by non-system application. | 4313| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types; 3. Parameter verification failed. | 4314| 14000011 | System inner fail. | 4315 4316**Example** 4317 4318```ts 4319import { dataSharePredicates } from '@kit.ArkData'; 4320import { BusinessError } from '@kit.BasicServicesKit'; 4321 4322async function example() { 4323 console.info('setUserCommentDemo'); 4324 let predicates: dataSharePredicates.DataSharePredicates = new dataSharePredicates.DataSharePredicates(); 4325 let fetchOption: photoAccessHelper.FetchOptions = { 4326 fetchColumns: [], 4327 predicates: predicates 4328 }; 4329 let fetchResult: photoAccessHelper.FetchResult<photoAccessHelper.PhotoAsset> = await phAccessHelper.getAssets(fetchOption); 4330 let photoAssetList: Array<photoAccessHelper.PhotoAsset> = await fetchResult.getAllObjects(); 4331 let assetsChangeRequest: photoAccessHelper.MediaAssetsChangeRequest = new photoAccessHelper.MediaAssetsChangeRequest(photoAssetList); 4332 assetsChangeRequest.setUserComment('test_set_user_comment'); 4333 phAccessHelper.applyChanges(assetsChangeRequest).then(() => { 4334 console.info('apply setUserComment successfully'); 4335 }).catch((err: BusinessError) => { 4336 console.error(`apply setUserComment failed with error: ${err.code}, ${err.message}`); 4337 }); 4338} 4339``` 4340 4341## MediaAlbumChangeRequest<sup>11+</sup> 4342 4343Provides APIs for managing the media album change request. 4344 4345**System capability**: SystemCapability.FileManagement.PhotoAccessHelper.Core 4346 4347### createAlbumRequest<sup>11+</sup> 4348 4349static createAlbumRequest(context: Context, name: string): MediaAlbumChangeRequest 4350 4351Creates a **MediaAlbumChangeRequest** instance. 4352 4353The album name must comply with the following specifications: 4354- The album name cannot exceed 255 characters. 4355- The album name cannot contain any of the following characters:<br> . .. \ / : * ? " ' ` < > | { } [ ] 4356- The album name is case-insensitive. 4357- Duplicate album names are not allowed. 4358 4359**System API**: This is a system API. 4360 4361**System capability**: SystemCapability.FileManagement.PhotoAccessHelper.Core 4362 4363**Parameters** 4364 4365| Name | Type | Mandatory| Description | 4366| ------- | ------- | ---- | -------------------------- | 4367| context | [Context](../apis-ability-kit/js-apis-inner-application-context.md) | Yes | Context of the ability instance.| 4368| name | string | Yes | Name of the album.| 4369 4370**Return value** 4371 4372| Type | Description | 4373| --------------------------------------- | ----------------- | 4374| [MediaAlbumChangeRequest](#mediaalbumchangerequest11) | **MediaAlbumChangeRequest** instance created.| 4375 4376**Error codes** 4377 4378For details about the error codes, see [Universal Error Codes](../errorcode-universal.md) and [File Management Error Codes](../apis-core-file-kit/errorcode-filemanagement.md). 4379 4380| ID| Error Message| 4381| -------- | ---------------------------------------- | 4382| 202 | Called by non-system application. | 4383| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types; 3. Parameter verification failed. | 4384| 14000011 | System inner fail. | 4385 4386**Example** 4387 4388```ts 4389async function example() { 4390 console.info('createAlbumRequestDemo'); 4391 try { 4392 let albumName: string = 'newAlbumName' + new Date().getTime(); 4393 let albumChangeRequest: photoAccessHelper.MediaAlbumChangeRequest = photoAccessHelper.MediaAlbumChangeRequest.createAlbumRequest(context, albumName); 4394 await phAccessHelper.applyChanges(albumChangeRequest); 4395 console.info('apply createAlbumRequest successfully'); 4396 } catch (err) { 4397 console.error(`createAlbumRequestDemo failed with error: ${err.code}, ${err.message}`); 4398 } 4399} 4400``` 4401 4402### deleteAlbums<sup>11+</sup> 4403 4404static deleteAlbums(context: Context, albums: Array<Album>): Promise<void> 4405 4406Deletes albums. This API uses a promise to return the result. 4407 4408Ensure that the albums to be deleted exist. Only user albums can be deleted. 4409 4410**System API**: This is a system API. 4411 4412**Required permissions**: ohos.permission.WRITE_IMAGEVIDEO 4413 4414**System capability**: SystemCapability.FileManagement.PhotoAccessHelper.Core 4415 4416**Parameters** 4417 4418| Name | Type | Mandatory| Description | 4419| ------- | ------- | ---- | -------------------------- | 4420| context | [Context](../apis-ability-kit/js-apis-inner-application-context.md) | Yes | Context of the ability instance.| 4421| albums | Array<[Album](#album)> | Yes | Albums to delete. | 4422 4423**Return value** 4424 4425| Type | Description | 4426| --------------------------------------- | ----------------- | 4427| Promise<void>| Promise that returns no value.| 4428 4429**Error codes** 4430 4431For details about the error codes, see [Universal Error Codes](../errorcode-universal.md) and [File Management Error Codes](../apis-core-file-kit/errorcode-filemanagement.md). 4432 4433| ID| Error Message| 4434| -------- | ---------------------------------------- | 4435| 201 | Permission denied. | 4436| 202 | Called by non-system application. | 4437| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types; 3. Parameter verification failed. | 4438| 14000011 | System inner fail. | 4439 4440**Example** 4441 4442```ts 4443import { dataSharePredicates } from '@kit.ArkData'; 4444 4445async function example() { 4446 console.info('deleteAlbumsDemo'); 4447 let predicates: dataSharePredicates.DataSharePredicates = new dataSharePredicates.DataSharePredicates(); 4448 let fetchOptions: photoAccessHelper.FetchOptions = { 4449 fetchColumns: [], 4450 predicates: predicates 4451 }; 4452 try { 4453 let fetchResult: photoAccessHelper.FetchResult<photoAccessHelper.Album> = await phAccessHelper.getAlbums(photoAccessHelper.AlbumType.USER, photoAccessHelper.AlbumSubtype.USER_GENERIC, fetchOptions); 4454 let album: photoAccessHelper.Album = await fetchResult.getFirstObject(); 4455 await photoAccessHelper.MediaAlbumChangeRequest.deleteAlbums(context, [album]); 4456 console.info('deleteAlbums successfully'); 4457 } catch (err) { 4458 console.error(`deleteAlbumsDemo failed with error: ${err.code}, ${err.message}`); 4459 } 4460} 4461``` 4462 4463### setCoverUri<sup>11+</sup> 4464 4465setCoverUri(coverUri: string): void 4466 4467Sets the album cover. 4468 4469**System API**: This is a system API. 4470 4471**System capability**: SystemCapability.FileManagement.PhotoAccessHelper.Core 4472 4473**Parameters** 4474 4475| Name | Type | Mandatory | Description | 4476| ---------- | ------- | ---- | ---------------------------------- | 4477| coverUri | string | Yes | URI of the file to be set as the album cover.| 4478 4479**Error codes** 4480 4481For details about the error codes, see [Universal Error Codes](../errorcode-universal.md) and [File Management Error Codes](../apis-core-file-kit/errorcode-filemanagement.md). 4482 4483| ID| Error Message| 4484| -------- | ---------------------------------------- | 4485| 202 | Called by non-system application. | 4486| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types; 3. Parameter verification failed. | 4487| 14000011 | System inner fail. | 4488 4489**Example** 4490 4491```ts 4492import { dataSharePredicates } from '@kit.ArkData'; 4493 4494async function example() { 4495 console.info('setCoverUriDemo'); 4496 let predicates: dataSharePredicates.DataSharePredicates = new dataSharePredicates.DataSharePredicates(); 4497 let fetchOptions: photoAccessHelper.FetchOptions = { 4498 fetchColumns: [], 4499 predicates: predicates 4500 }; 4501 try { 4502 let albumFetchResult: photoAccessHelper.FetchResult<photoAccessHelper.Album> = await phAccessHelper.getAlbums(photoAccessHelper.AlbumType.USER, photoAccessHelper.AlbumSubtype.USER_GENERIC); 4503 let album: photoAccessHelper.Album = await albumFetchResult.getFirstObject(); 4504 let fetchResult: photoAccessHelper.FetchResult<photoAccessHelper.PhotoAsset> = await album.getAssets(fetchOptions); 4505 let asset: photoAccessHelper.PhotoAsset = await fetchResult.getFirstObject(); 4506 4507 let albumChangeRequest: photoAccessHelper.MediaAlbumChangeRequest = new photoAccessHelper.MediaAlbumChangeRequest(album); 4508 albumChangeRequest.setCoverUri(asset.uri); 4509 await phAccessHelper.applyChanges(albumChangeRequest); 4510 console.info('setCoverUri successfully'); 4511 } catch (err) { 4512 console.error(`setCoverUriDemo failed with error: ${err.code}, ${err.message}`); 4513 } 4514} 4515``` 4516 4517### moveAssets<sup>11+</sup> 4518 4519moveAssets(assets: Array<PhotoAsset>, targetAlbum: Album): void 4520 4521Moves assets to another album. 4522 4523**System API**: This is a system API. 4524 4525**System capability**: SystemCapability.FileManagement.PhotoAccessHelper.Core 4526 4527**Parameters** 4528 4529| Name | Type | Mandatory | Description | 4530| ---------- | ------- | ---- | ---------------------------------- | 4531| assets | Array<[PhotoAsset](#photoasset)> | Yes | Assets to move.| 4532| targetAlbum | Album | Yes | Album to which the assets are to be moved.| 4533 4534**Error codes** 4535 4536For details about the error codes, see [Universal Error Codes](../errorcode-universal.md) and [File Management Error Codes](../apis-core-file-kit/errorcode-filemanagement.md). 4537 4538| ID| Error Message| 4539| -------- | ---------------------------------------- | 4540| 202 | Called by non-system application. | 4541| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types; 3. Parameter verification failed. | 4542| 14000011 | System inner fail. | 4543| 14000016 | Operation Not Support. | 4544 4545**Example** 4546 4547```ts 4548import { dataSharePredicates } from '@kit.ArkData'; 4549 4550async function example() { 4551 console.info('moveAssetsDemo'); 4552 let predicates: dataSharePredicates.DataSharePredicates = new dataSharePredicates.DataSharePredicates(); 4553 let fetchOptions: photoAccessHelper.FetchOptions = { 4554 fetchColumns: [], 4555 predicates: predicates 4556 }; 4557 try { 4558 let albumFetchResult: photoAccessHelper.FetchResult<photoAccessHelper.Album> = await phAccessHelper.getAlbums(photoAccessHelper.AlbumType.USER, photoAccessHelper.AlbumSubtype.USER_GENERIC); 4559 let album: photoAccessHelper.Album = await albumFetchResult.getFirstObject(); 4560 let fetchResult: photoAccessHelper.FetchResult<photoAccessHelper.PhotoAsset> = await album.getAssets(fetchOptions); 4561 let asset: photoAccessHelper.PhotoAsset = await fetchResult.getFirstObject(); 4562 4563 if (albumFetchResult.isAfterLast()) { 4564 console.error('lack of album to be moved into'); 4565 return; 4566 } 4567 let nextAlbum: photoAccessHelper.Album = await albumFetchResult.getNextObject(); 4568 let albumChangeRequest: photoAccessHelper.MediaAlbumChangeRequest = new photoAccessHelper.MediaAlbumChangeRequest(album); 4569 albumChangeRequest.moveAssets([asset], nextAlbum); 4570 await phAccessHelper.applyChanges(albumChangeRequest); 4571 console.info('moveAssets successfully'); 4572 } catch (err) { 4573 console.error(`moveAssetsDemo failed with error: ${err.code}, ${err.message}`); 4574 } 4575} 4576``` 4577 4578### recoverAssets<sup>11+</sup> 4579 4580recoverAssets(assets: Array<PhotoAsset>): void 4581 4582Recovers assets from the trash. 4583 4584**System API**: This is a system API. 4585 4586**System capability**: SystemCapability.FileManagement.PhotoAccessHelper.Core 4587 4588**Parameters** 4589 4590| Name | Type | Mandatory | Description | 4591| ---------- | ------- | ---- | ---------------------------------- | 4592| assets | Array<[PhotoAsset](#photoasset)> | Yes | Assets to recover.| 4593 4594**Error codes** 4595 4596For details about the error codes, see [Universal Error Codes](../errorcode-universal.md) and [File Management Error Codes](../apis-core-file-kit/errorcode-filemanagement.md). 4597 4598| ID| Error Message| 4599| -------- | ---------------------------------------- | 4600| 202 | Called by non-system application. | 4601| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types; 3. Parameter verification failed. | 4602| 14000011 | System inner fail. | 4603| 14000016 | Operation Not Support. | 4604 4605**Example** 4606 4607```ts 4608import { dataSharePredicates } from '@kit.ArkData'; 4609 4610async function example() { 4611 console.info('recoverAssetsDemo'); 4612 let predicates: dataSharePredicates.DataSharePredicates = new dataSharePredicates.DataSharePredicates(); 4613 let fetchOptions: photoAccessHelper.FetchOptions = { 4614 fetchColumns: [], 4615 predicates: predicates 4616 }; 4617 try { 4618 let albumFetchResult: photoAccessHelper.FetchResult<photoAccessHelper.Album> = await phAccessHelper.getAlbums(photoAccessHelper.AlbumType.SYSTEM, photoAccessHelper.AlbumSubtype.TRASH); 4619 let album: photoAccessHelper.Album = await albumFetchResult.getFirstObject(); 4620 let fetchResult: photoAccessHelper.FetchResult<photoAccessHelper.PhotoAsset> = await album.getAssets(fetchOptions); 4621 let asset: photoAccessHelper.PhotoAsset = await fetchResult.getFirstObject(); 4622 4623 let albumChangeRequest: photoAccessHelper.MediaAlbumChangeRequest = new photoAccessHelper.MediaAlbumChangeRequest(album); 4624 albumChangeRequest.recoverAssets([asset]); 4625 await phAccessHelper.applyChanges(albumChangeRequest); 4626 console.info('recoverAssets successfully'); 4627 } catch (err) { 4628 console.error(`recoverAssetsDemo failed with error: ${err.code}, ${err.message}`); 4629 } 4630} 4631``` 4632 4633### deleteAssets<sup>11+</sup> 4634 4635deleteAssets(assets: Array<PhotoAsset>): void 4636 4637Permanently deletes assets from the trash. 4638 4639**NOTE**<br>This operation is irreversible. The file assets deleted cannot be restored. Exercise caution when performing this operation. 4640 4641**System API**: This is a system API. 4642 4643**System capability**: SystemCapability.FileManagement.PhotoAccessHelper.Core 4644 4645**Parameters** 4646 4647| Name | Type | Mandatory | Description | 4648| ---------- | ------- | ---- | ---------------------------------- | 4649| assets | Array<[PhotoAsset](#photoasset)> | Yes | Assets to be permanently deleted.| 4650 4651**Error codes** 4652 4653For details about the error codes, see [Universal Error Codes](../errorcode-universal.md) and [File Management Error Codes](../apis-core-file-kit/errorcode-filemanagement.md). 4654 4655| ID| Error Message| 4656| -------- | ---------------------------------------- | 4657| 202 | Called by non-system application. | 4658| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types; 3. Parameter verification failed. | 4659| 14000011 | System inner fail. | 4660| 14000016 | Operation Not Support. | 4661 4662**Example** 4663 4664```ts 4665import { dataSharePredicates } from '@kit.ArkData'; 4666 4667async function example() { 4668 console.info('deleteAssetsPermanentlyDemo'); 4669 let predicates: dataSharePredicates.DataSharePredicates = new dataSharePredicates.DataSharePredicates(); 4670 let fetchOptions: photoAccessHelper.FetchOptions = { 4671 fetchColumns: [], 4672 predicates: predicates 4673 }; 4674 try { 4675 let albumFetchResult: photoAccessHelper.FetchResult<photoAccessHelper.Album> = await phAccessHelper.getAlbums(photoAccessHelper.AlbumType.SYSTEM, photoAccessHelper.AlbumSubtype.TRASH); 4676 let album: photoAccessHelper.Album = await albumFetchResult.getFirstObject(); 4677 let fetchResult: photoAccessHelper.FetchResult<photoAccessHelper.PhotoAsset> = await album.getAssets(fetchOptions); 4678 let asset: photoAccessHelper.PhotoAsset = await fetchResult.getFirstObject(); 4679 4680 let albumChangeRequest: photoAccessHelper.MediaAlbumChangeRequest = new photoAccessHelper.MediaAlbumChangeRequest(album); 4681 albumChangeRequest.deleteAssets([asset]); 4682 await phAccessHelper.applyChanges(albumChangeRequest); 4683 console.info('succeed to deleteAssets permanently'); 4684 } catch (err) { 4685 console.error(`deleteAssetsPermanentlyDemo failed with error: ${err.code}, ${err.message}`); 4686 } 4687} 4688``` 4689 4690### setDisplayLevel<sup>11+</sup> 4691 4692setDisplayLevel(displayLevel: number): void 4693 4694Sets the display level of the portrait album. 4695 4696**System API**: This is a system API. 4697 4698**System capability**: SystemCapability.FileManagement.PhotoAccessHelper.Core 4699 4700**Parameters** 4701 4702| Name | Type | Mandatory | Description | 4703| ---------- | ------- | ---- | ---------------------------------- | 4704| 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.| 4705 4706**Error codes** 4707 4708For details about the error codes, see [Universal Error Codes](../errorcode-universal.md) and [File Management Error Codes](../apis-core-file-kit/errorcode-filemanagement.md). 4709 4710| ID| Error Message| 4711| -------- | ---------------------------------------- | 4712| 202 | Called by non-system application. | 4713| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types; 3. Parameter verification failed. | 4714| 14000011 | System inner fail. | 4715 4716**Example** 4717 4718``` ts 4719import { dataSharePredicates } from '@kit.ArkData'; 4720 4721async function example() { 4722 try { 4723 console.info('setDisplayLevel Example') 4724 let predicates: dataSharePredicates.DataSharePredicates = new dataSharePredicates.DataSharePredicates(); 4725 predicates.equalTo('user_display_level', 2); 4726 let fetchOptions: photoAccessHelper.FetchOptions = { 4727 fetchColumns: [], 4728 predicates: predicates 4729 }; 4730 let fetchResult: photoAccessHelper.FetchResult<photoAccessHelper.Album> = await phAccessHelper.getAlbums(photoAccessHelper.AlbumType.SMART, photoAccessHelper.AlbumSubtype.PORTRAIT, fetchOptions); 4731 let album: photoAccessHelper.Album = await fetchResult.getFirstObject(); 4732 let changeRequest: photoAccessHelper.MediaAlbumChangeRequest = new photoAccessHelper.MediaAlbumChangeRequest(album); 4733 changeRequest.setDisplayLevel(1); 4734 await phAccessHelper.applyChanges(changeRequest); 4735 } catch (err) { 4736 console.error(`setDisplayLevel failed with error: ${err.code}, ${err.message}`); 4737 } 4738} 4739``` 4740 4741### setIsMe<sup>11+</sup> 4742 4743setIsMe(): void 4744 4745Sets the relationship between people in the portrait album to **Me**. 4746 4747**System API**: This is a system API. 4748 4749**System capability**: SystemCapability.FileManagement.PhotoAccessHelper.Core 4750 4751**Error codes** 4752 4753For details about the error codes, see [Universal Error Codes](../errorcode-universal.md) and [File Management Error Codes](../apis-core-file-kit/errorcode-filemanagement.md). 4754 4755| ID| Error Message| 4756| -------- | ---------------------------------------- | 4757| 202 | Called by non-system application. | 4758| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types. | 4759| 14000011 | System inner fail. | 4760 4761**Example** 4762 4763``` ts 4764import { dataSharePredicates } from '@kit.ArkData'; 4765 4766async function example() { 4767 try { 4768 console.info('setIsMe Example') 4769 let predicates: dataSharePredicates.DataSharePredicates = new dataSharePredicates.DataSharePredicates(); 4770 predicates.equalTo('user_display_level', 2); 4771 let fetchOptions: photoAccessHelper.FetchOptions = { 4772 fetchColumns: [], 4773 predicates: predicates 4774 }; 4775 let fetchResult: photoAccessHelper.FetchResult<photoAccessHelper.Album> = await phAccessHelper.getAlbums(photoAccessHelper.AlbumType.SMART, photoAccessHelper.AlbumSubtype.PORTRAIT, fetchOptions); 4776 let album: photoAccessHelper.Album = await fetchResult.getFirstObject(); 4777 let changeRequest: photoAccessHelper.MediaAlbumChangeRequest = new photoAccessHelper.MediaAlbumChangeRequest(album); 4778 changeRequest.setIsMe(); 4779 await phAccessHelper.applyChanges(changeRequest); 4780 } catch (err) { 4781 console.error(`setIsMe failed with error: ${err.code}, ${err.message}`); 4782 } 4783} 4784``` 4785 4786### dismissAssets<sup>11+</sup> 4787 4788dismissAssets(assets: Array<PhotoAsset>): void 4789 4790Removes assets from this portrait album. 4791 4792**System API**: This is a system API. 4793 4794**System capability**: SystemCapability.FileManagement.PhotoAccessHelper.Core 4795 4796**Parameters** 4797 4798| Name | Type | Mandatory | Description | 4799| ---------- | ------- | ---- | ---------------------------------- | 4800| assets | Array<PhotoAsset> | Yes | Assets to remove.| 4801 4802**Error codes** 4803 4804For details about the error codes, see [Universal Error Codes](../errorcode-universal.md) and [File Management Error Codes](../apis-core-file-kit/errorcode-filemanagement.md). 4805 4806| ID| Error Message| 4807| -------- | ---------------------------------------- | 4808| 202 | Called by non-system application. | 4809| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types; 3. Parameter verification failed. | 4810| 14000011 | System inner fail. | 4811| 14000016 | Operation Not support. | 4812 4813**Example** 4814 4815``` ts 4816import { dataSharePredicates } from '@kit.ArkData'; 4817 4818async function example() { 4819 try { 4820 console.info('dismissAssets Example') 4821 let predicates: dataSharePredicates.DataSharePredicates = new dataSharePredicates.DataSharePredicates(); 4822 predicates.equalTo('user_display_level', 2); 4823 let fetchOptions: photoAccessHelper.FetchOptions = { 4824 fetchColumns: [], 4825 predicates: predicates 4826 }; 4827 let fetchResult: photoAccessHelper.FetchResult<photoAccessHelper.Album> = await phAccessHelper.getAlbums(photoAccessHelper.AlbumType.SMART, photoAccessHelper.AlbumSubtype.PORTRAIT, fetchOptions); 4828 let album: photoAccessHelper.Album = await fetchResult.getFirstObject(); 4829 4830 let predicatesAsset: dataSharePredicates.DataSharePredicates = new dataSharePredicates.DataSharePredicates(); 4831 let assetFetchOptions: photoAccessHelper.FetchOptions = { 4832 fetchColumns: [], 4833 predicates: predicatesAsset 4834 }; 4835 let assetFetchResult: photoAccessHelper.FetchResult<photoAccessHelper.PhotoAsset> = await phAccessHelper.getAssets(assetFetchOptions); 4836 let asset: photoAccessHelper.PhotoAsset = await assetFetchResult.getFirstObject(); 4837 4838 let changeRequest: photoAccessHelper.MediaAlbumChangeRequest = new photoAccessHelper.MediaAlbumChangeRequest(album); 4839 changeRequest.dismissAssets([asset]); 4840 await phAccessHelper.applyChanges(changeRequest); 4841 } catch (err) { 4842 console.error(`dismissAssets failed with error: ${err.code}, ${err.message}`); 4843 } 4844} 4845``` 4846 4847### mergeAlbum<sup>11+</sup> 4848 4849mergeAlbum(target: Album): void 4850 4851Merges two portrait albums. 4852 4853**System API**: This is a system API. 4854 4855**System capability**: SystemCapability.FileManagement.PhotoAccessHelper.Core 4856 4857**Parameters** 4858 4859| Name | Type | Mandatory | Description | 4860| ---------- | ------- | ---- | ---------------------------------- | 4861| target | [Album](#album) | Yes | Album generated after the merge. The album must be renamed.| 4862 4863**Error codes** 4864 4865For details about the error codes, see [Universal Error Codes](../errorcode-universal.md) and [File Management Error Codes](../apis-core-file-kit/errorcode-filemanagement.md). 4866 4867| ID| Error Message| 4868| -------- | ---------------------------------------- | 4869| 202 | Called by non-system application. | 4870| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types; 3. Parameter verification failed. | 4871| 14000011 | System inner fail. | 4872| 14000016 | Operation Not support. | 4873 4874**Example** 4875 4876``` ts 4877import { dataSharePredicates } from '@kit.ArkData'; 4878 4879async function example() { 4880 try { 4881 console.info('mergeAlbum Example') 4882 let predicates: dataSharePredicates.DataSharePredicates = new dataSharePredicates.DataSharePredicates(); 4883 predicates.equalTo('user_display_level', 2); 4884 let fetchOptions: photoAccessHelper.FetchOptions = { 4885 fetchColumns: [], 4886 predicates: predicates 4887 }; 4888 let fetchResult: photoAccessHelper.FetchResult<photoAccessHelper.Album> = await phAccessHelper.getAlbums(photoAccessHelper.AlbumType.SMART, photoAccessHelper.AlbumSubtype.PORTRAIT, fetchOptions); 4889 let album: photoAccessHelper.Album = await fetchResult.getFirstObject(); 4890 if (fetchResult.isAfterLast()) { 4891 console.error('lack of album to merge'); 4892 return; 4893 } 4894 let target: photoAccessHelper.Album = await fetchResult.getNextObject(); 4895 4896 let changeRequest: photoAccessHelper.MediaAlbumChangeRequest = new photoAccessHelper.MediaAlbumChangeRequest(album); 4897 changeRequest.mergeAlbum(target); 4898 changeRequest.setAlbumName("testName"); 4899 await phAccessHelper.applyChanges(changeRequest); 4900 } catch (err) { 4901 console.error(`mergeAlbum failed with error: ${err.code}, ${err.message}`); 4902 } 4903} 4904``` 4905 4906### placeBefore<sup>11+</sup> 4907 4908placeBefore(album: Album): void; 4909 4910Places this album before an album. 4911 4912**System API**: This is a system API. 4913 4914**System capability**: SystemCapability.FileManagement.PhotoAccessHelper.Core 4915 4916**Parameters** 4917 4918| Name | Type | Mandatory | Description | 4919| ---------- | ------- | ---- | ---------------------------------- | 4920| album | [Album](#album) | Yes | Target album. To place this album to the end, set **album** to null.| 4921 4922**Error codes** 4923 4924For details about the error codes, see [Universal Error Codes](../errorcode-universal.md) and [File Management Error Codes](../apis-core-file-kit/errorcode-filemanagement.md). 4925 4926| ID| Error Message| 4927| -------- | ---------------------------------------- | 4928| 202 | Called by non-system application. | 4929| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types; 3. Parameter verification failed. | 4930| 14000011 | System inner fail. | 4931 4932**Example** 4933 4934```ts 4935async function example() { 4936 console.info('placeBeforeDemo'); 4937 try { 4938 let albumFetchResult: photoAccessHelper.FetchResult<photoAccessHelper.Album> = await phAccessHelper.getAlbums(photoAccessHelper.AlbumType.USER, photoAccessHelper.AlbumSubtype.USER_GENERIC); 4939 let firstAlbum: photoAccessHelper.Album = await albumFetchResult.getFirstObject(); 4940 if (albumFetchResult.isAfterLast()) { 4941 console.error('lack of album to place before'); 4942 return; 4943 } 4944 let secondAlbum: photoAccessHelper.Album = await albumFetchResult.getNextObject(); 4945 let albumChangeRequest: photoAccessHelper.MediaAlbumChangeRequest = new photoAccessHelper.MediaAlbumChangeRequest(secondAlbum); 4946 albumChangeRequest.placeBefore(firstAlbum); 4947 await phAccessHelper.applyChanges(albumChangeRequest); 4948 console.info('placeBefore successfully'); 4949 } catch (err) { 4950 console.error(`placeBeforeDemo failed with error: ${err.code}, ${err.message}`); 4951 } 4952} 4953``` 4954 4955 4956 4957 4958 4959 4960 4961 4962 4963 4964 4965 4966 4967## HighlightAlbum<sup>12+</sup> 4968 4969Provides APIs for managing the **Highlights** album, which is an automatically generated collection of memorable photos or videos. 4970 4971**System API**: This is a system API. 4972 4973**System capability**: SystemCapability.FileManagement.PhotoAccessHelper.Core 4974 4975### constructor<sup>12+</sup> 4976 4977constructor(album: Album) 4978 4979A constructor used to create a **Highlights** album instance. 4980 4981**System API**: This is a system API. 4982 4983**System capability**: SystemCapability.FileManagement.PhotoAccessHelper.Core 4984 4985**Parameters** 4986 4987| Name | Type | Mandatory| Description | 4988| -------- | ------------------------- | ---- | ---------- | 4989| album | [Album](#album) | Yes | **Highlights** album to create.| 4990 4991**Error codes** 4992 4993For details about the error codes, see [Universal Error Codes](../errorcode-universal.md) and [File Management Error Codes](../apis-core-file-kit/errorcode-filemanagement.md). 4994 4995| ID| Error Message| 4996| -------- | ---------------------------------------- | 4997| 202 | Called by non-system application. | 4998| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types; 3. Parameter verification failed. | 4999| 14000011 | Internal system error. | 5000 5001**Example** 5002 5003```ts 5004import { dataSharePredicates } from '@kit.ArkData'; 5005 5006async function example() { 5007 console.info('HighlightAlbum constructorDemo'); 5008 let predicates: dataSharePredicates.DataSharePredicates = new dataSharePredicates.DataSharePredicates(); 5009 let fetchOption: photoAccessHelper.FetchOptions = { 5010 fetchColumns: [], 5011 predicates: predicates 5012 }; 5013 let albumFetchResult: photoAccessHelper.FetchResult<photoAccessHelper.Album> = await photoAccessHelper.getAlbums( 5014 photoAccessHelper.AlbumType.SMART, photoAccessHelper.AlbumSubtype.HIGHLIGHT, fetchOption); 5015 let album: photoAccessHelper.Album = await albumFetchResult.getFirstObject(); 5016 let highlightAlbum: photoAccessHelper.HighlightAlbum = new photoAccessHelper.HighlightAlbum(album); 5017 albumFetchResult.close(); 5018} 5019``` 5020 5021### getHighlightAlbumInfo<sup>12+</sup> 5022 5023getHighlightAlbumInfo(type: HighlightAlbumInfoType): Promise<string> 5024 5025Obtains specific information about the **Highlights** album. 5026 5027**System API**: This is a system API. 5028 5029**Required permissions**: ohos.permission.READ\_IMAGEVIDEO 5030 5031**System capability**: SystemCapability.FileManagement.PhotoAccessHelper.Core 5032 5033**Parameters** 5034 5035| Name | Type | Mandatory | Description | 5036| ---------- | ------- | ---- | ---------------------------------- | 5037| type | [HighlightAlbumInfoType](#highlightalbuminfotype12) | Yes | Type of the album information to obtain.| 5038 5039**Error codes** 5040 5041For details about the error codes, see [Universal Error Codes](../errorcode-universal.md) and [File Management Error Codes](../apis-core-file-kit/errorcode-filemanagement.md). 5042 5043| ID | Error Message | 5044| :------- | :-------------------------------- | 5045| 201 | Permission denied. | 5046| 202 | Called by non-system application. | 5047| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types; 3. Parameter verification failed. | 5048| 14000011 | Internal system error. | 5049 5050**Example** 5051 5052```ts 5053import { dataSharePredicates } from '@kit.ArkData'; 5054 5055async function example() { 5056 try { 5057 console.info('getHighlightAlbumInfoDemo') 5058 let fetchOptions: photoAccessHelper.FetchOptions = { 5059 fetchColumns: [], 5060 predicates: new dataSharePredicates.DataSharePredicates() 5061 } 5062 let albumFetchResult: photoAccessHelper.FetchResult<photoAccessHelper.Album> = await photoAccessHelper.getAlbums( 5063 photoAccessHelper.AlbumType.SMART, photoAccessHelper.AlbumSubtype.HIGHLIGHT, fetchOption); 5064 let album: photoAccessHelper.Album = await albumFetchResult.getFirstObject(); 5065 if (album != undefined) { 5066 let highlightAlbum: photoAccessHelper.HighlightAlbum = new photoAccessHelper.HighlightAlbum(album); 5067 let coverInfo: string = await highlightAlbum.getHighlightAlbumInfo( 5068 photoAccessHelper.HighlightAlbumInfoType.COVER_INFO); 5069 console.info('get cover info result: ' + JSON.stringify(coverInfo)); 5070 } 5071 5072 albumFetchResult.close(); 5073 } catch (err) { 5074 console.error(`getHighlightAlbumInfoDemofailed with error: ${err.code}, ${err.message}`); 5075 } 5076} 5077``` 5078 5079### getHighlightResource<sup>12+</sup> 5080 5081getHighlightResource(resourceUri: string): Promise<ArrayBuffer> 5082 5083Obtains the ArrayBuffer for caching the specified asset. 5084 5085**System API**: This is a system API. 5086 5087**Required permissions**: ohos.permission.READ\_IMAGEVIDEO 5088 5089**System capability**: SystemCapability.FileManagement.PhotoAccessHelper.Core 5090 5091**Parameters** 5092 5093| Name | Type | Mandatory | Description | 5094| ---------- | ------- | ---- | ---------------------------------- | 5095| resourceUri | string | Yes | URI of the asset to cache.| 5096 5097**Error codes** 5098 5099For details about the error codes, see [Universal Error Codes](../errorcode-universal.md) and [File Management Error Codes](../apis-core-file-kit/errorcode-filemanagement.md). 5100 5101| ID | Error Message | 5102| :------- | :-------------------------------- | 5103| 201 | Permission denied. | 5104| 202 | Called by non-system application. | 5105| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types; 3. Parameter verification failed. | 5106| 14000011 | Internal system error. | 5107 5108**Example** 5109 5110```ts 5111import { dataSharePredicates } from '@kit.ArkData'; 5112 5113async function example() { 5114 try { 5115 console.info('getHighlightResourceDemo') 5116 let fetchOptions: photoAccessHelper.FetchOptions = { 5117 fetchColumns: [], 5118 predicates: new dataSharePredicates.DataSharePredicates() 5119 } 5120 let albumFetchResult: photoAccessHelper.FetchResult<photoAccessHelper.Album> = await photoAccessHelper.getAlbums( 5121 photoAccessHelper.AlbumType.SMART, photoAccessHelper.AlbumSubtype.HIGHLIGHT, fetchOption); 5122 let album: photoAccessHelper.Album = await albumFetchResult.getFirstObject(); 5123 if (album != undefined) { 5124 let highlightAlbum: photoAccessHelper.HighlightAlbum = new photoAccessHelper.HighlightAlbum(album); 5125 let uri: string = 'file://media/highlight/cover/10/1_1/background.png?oper=highlight' 5126 let arrayBuffer: ArrayBuffer = await highlightAlbum.getHighlightResource(uri); 5127 } 5128 albumFetchResult.close(); 5129 } catch (err) { 5130 console.error(`getHighlightResourceDemofailed with error: ${err.code}, ${err.message}`); 5131 } 5132} 5133``` 5134 5135### setHighlightUserActionData<sup>12+</sup> 5136 5137setHighlightUserActionData(type: HighlightUserActionType, actionData: number): Promise<void> 5138 5139Sets the user behavior data for the **Highlights** album. 5140 5141**System API**: This is a system API. 5142 5143**Required permissions**: ohos.permission.WRITE\_IMAGEVIDEO 5144 5145**System capability**: SystemCapability.FileManagement.PhotoAccessHelper.Core 5146 5147**Parameters** 5148 5149| Name | Type | Mandatory | Description | 5150| ---------- | ------- | ---- | ---------------------------------- | 5151| type | [HighlightUserActionType](#highlightuseractiontype12) | Yes | Type of the user behavior data to set.| 5152| actionData | number | Yes | Behavior data.| 5153 5154**Error codes** 5155 5156For details about the error codes, see [Universal Error Codes](../errorcode-universal.md) and [File Management Error Codes](../apis-core-file-kit/errorcode-filemanagement.md). 5157 5158| ID | Error Message | 5159| :------- | :-------------------------------- | 5160| 201 | Permission denied. | 5161| 202 | Called by non-system application. | 5162| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types; 3. Parameter verification failed. | 5163| 14000011 | Internal system error. | 5164 5165**Example** 5166 5167```ts 5168import { dataSharePredicates } from '@kit.ArkData'; 5169 5170async function example() { 5171 try { 5172 console.info('setHighlightUserActionDataDemo') 5173 let fetchOptions: photoAccessHelper.FetchOptions = { 5174 fetchColumns: [], 5175 predicates: new dataSharePredicates.DataSharePredicates() 5176 } 5177 let albumFetchResult: photoAccessHelper.FetchResult<photoAccessHelper.Album> = await photoAccessHelper.getAlbums( 5178 photoAccessHelper.AlbumType.SMART, photoAccessHelper.AlbumSubtype.HIGHLIGHT, fetchOption); 5179 let album: photoAccessHelper.Album = await albumFetchResult.getFirstObject(); 5180 if (album != undefined) { 5181 let highlightAlbum: photoAccessHelper.HighlightAlbum = new photoAccessHelper.HighlightAlbum(album); 5182 highlightAlbum.setHighlightUserActionData(photoAccessHelper.HighlightUserActionType.INSERTED_PIC_COUNT, 1); 5183 } 5184 albumFetchResult.close(); 5185 } catch (err) { 5186 console.error(`setHighlightUserActionDataDemofailed with error: ${err.code}, ${err.message}`); 5187 } 5188} 5189``` 5190 5191## PhotoSubtype 5192 5193Enumerates the [PhotoAsset](#photoasset) types. 5194 5195**System capability**: SystemCapability.FileManagement.PhotoAccessHelper.Core 5196 5197| Name | Value| Description| 5198| ----- | ---- | ---- | 5199| SCREENSHOT | 1 | Screenshot and screen recording file. **System API**: This is a system API.| 5200 5201## PositionType 5202 5203Enumerates the file locations. 5204 5205**System API**: This is a system API. 5206 5207**System capability**: SystemCapability.FileManagement.PhotoAccessHelper.Core 5208 5209| Name | Value| Description| 5210| ----- | ---- | ---- | 5211| LOCAL | 1 << 0 | Stored only on a local device.| 5212| CLOUD | 1 << 1 | Stored only on the cloud.| 5213 5214## AlbumType 5215 5216Enumerates the album types. 5217 5218**System capability**: SystemCapability.FileManagement.PhotoAccessHelper.Core 5219 5220| Name | Value | Description | 5221| ------------------- | ---- | ------------------------- | 5222| SMART<sup>11+</sup> | 4096 | Smart analysis album. **System API**: This is a system API.| 5223 5224## AlbumSubtype 5225 5226Enumerate the album subtypes. 5227 5228**System capability**: SystemCapability.FileManagement.PhotoAccessHelper.Core 5229 5230| Name | Value | Description | 5231| --------------------------------- | ---------- | ------------------------------- | 5232| HIDDEN | 1027 | Hidden album. **System API**: This is a system API. | 5233| TRASH | 1028 | Trash. **System API**: This is a system API. | 5234| SCREENSHOT | 1029 | Album for screenshots and screen recording files. **System API**: This is a system API. | 5235| CAMERA | 1030 | Album for photos and videos taken by the camera. **System API**: This is a system API.| 5236| SOURCE\_GENERIC<sup>11+</sup> | 2049 | Source album. **System API**: This is a system API. | 5237| CLASSIFY<sup>11+</sup> | 4097 | Classified album. **System API**: This is a system API. | 5238| GEOGRAPHY\_LOCATION<sup>11+</sup> | 4099 | Geographic location album. **System API**: This is a system API. | 5239| GEOGRAPHY\_CITY<sup>11+</sup> | 4100 | City album. **System API**: This is a system API. | 5240| SHOOTING\_MODE<sup>11+</sup> | 4101 | Shooting mode album. **System API**: This is a system API. | 5241| PORTRAIT<sup>11+</sup> | 4102 | Portrait album. **System API**: This is a system API. | 5242| GROUP_PHOTO<sup>12+</sup> | 4103 | Group photo album. **System API**: This is a system API. | 5243| HIGHLIGHT<sup>12+</sup> | 4104 | Highlights album. **System API**: This is a system API. | 5244| HIGHLIGHT_SUGGESTIONS<sup>12+</sup> | 4105 | Highlights suggestion album. **System API**: This is a system API. | 5245 5246## RequestPhotoType<sup>11+</sup> 5247 5248Enumerates the types of the operation for obtaining image or video thumbnails. 5249 5250**System API**: This is a system API. 5251 5252**System capability**: SystemCapability.FileManagement.PhotoAccessHelper.Core 5253 5254| Name | Value| Description| 5255| ----- | ---- | ---- | 5256| REQUEST_ALL_THUMBNAILS | 0 | Obtain both the quick thumbnail and the quality thumbnail.| 5257| REQUEST_FAST_THUMBNAIL | 1 | Obtain only the quick thumbnail.| 5258| REQUEST_QUALITY_THUMBNAIL | 2 | Obtain only the quality thumbnail.| 5259 5260## PhotoKeys 5261 5262Defines the key information about an image or video file. 5263 5264**System capability**: SystemCapability.FileManagement.PhotoAccessHelper.Core 5265 5266| Name | Value | Description | 5267| ------------- | ------------------- | ---------------------------------------------------------- | 5268| POSITION | 'position' | File location type. <br>**System API**: This is a system API. | 5269| 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. | 5270| HIDDEN | 'hidden' | Whether the file is hidden. <br>**System API**: This is a system API. | 5271| 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. | 5272| USER_COMMENT<sup>10+</sup> | 'user_comment' | User comment information. <br>**System API**: This is a system API. | 5273| DATE_YEAR<sup>11+</sup> | 'date_year' | Year when the file was created. <br>**System API**: This is a system API. | 5274| DATE_MONTH<sup>11+</sup> | 'date_month' | Month when the file was created. <br>**System API**: This is a system API. | 5275| DATE_DAY<sup>11+</sup> | 'date_day' | Date when the file was created. <br>**System API**: This is a system API. | 5276| PENDING<sup>11+</sup> | 'pending' | Pending state. <br>**System API**: This is a system API. | 5277| 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.| 5278| MOVING_PHOTO_EFFECT_MODE<sup>12+</sup> | 'moving_photo_effect_mode' | Effect of the moving photo. <br>**System API**: This is a system API.| 5279 5280## HiddenPhotosDisplayMode<sup>11+</sup> 5281 5282Enumerates the display modes of hidden files in the system. 5283 5284**System API**: This is a system API. 5285 5286**System capability**: SystemCapability.FileManagement.PhotoAccessHelper.Core 5287 5288| Name | Value | Description | 5289| ------------- | ------------------- | ---------------------------------------------------------- | 5290| ASSETS_MODE | 0 | Display all hidden files in the system. | 5291| 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). | 5292 5293## PhotoCreateOptions 5294 5295Options for creating an image or video asset. 5296 5297**System API**: This is a system API. 5298 5299**System capability**: SystemCapability.FileManagement.PhotoAccessHelper.Core 5300 5301| Name | Type | Mandatory| Description | 5302| ---------------------- | ------------------- | ---- | ------------------------------------------------ | 5303| subtype | [PhotoSubtype](#photosubtype) | No | Subtype of the image or video. | 5304| 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.) | 5305 5306## RequestPhotoOptions<sup>11+</sup> 5307 5308Defines the options for obtaining the thumbnail of an image or video. 5309 5310**System API**: This is a system API. 5311 5312**System capability**: SystemCapability.FileManagement.PhotoAccessHelper.Core 5313 5314| Name | Type | Mandatory| Description | 5315| ---------------------- | ------------------- | ---- | ------------------------------------------------ | 5316| size | [image.Size](../apis-image-kit/js-apis-image.md#size) | No | Size of the thumbnail to obtain. | 5317| requestPhotoType | [RequestPhotoType](#requestphototype11) | No | Operation to perform. | 5318 5319## RequestOptions<sup>11+</sup> 5320 5321Represents request options. 5322 5323**System capability**: SystemCapability.FileManagement.PhotoAccessHelper.Core 5324 5325| Name | Type | Readable| Writable| Description | 5326| ---------------------- |---------------------------------| ---- |---- | ------------------------------------------------ | 5327| 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.| 5328 5329## PhotoProxy<sup>11+</sup> 5330 5331Photo proxy object, which is used by the camera application to write image data. 5332 5333**System API**: This is a system API. 5334 5335**System capability**: SystemCapability.FileManagement.PhotoAccessHelper.Core 5336 5337## MediaChangeRequest<sup>11+</sup> 5338 5339Media change request, which is the parent class of the asset change request and album change request. 5340 5341> **NOTE**<br>The media change request takes effect only after [applyChanges](js-apis-photoAccessHelper.md#applychanges11) is called. 5342 5343**System capability**: SystemCapability.FileManagement.PhotoAccessHelper.Core 5344 5345## FormInfo<sup>11+</sup> 5346 5347Defines the Gallery widget information. 5348 5349**System API**: This is a system API. 5350 5351**System capability**: SystemCapability.FileManagement.PhotoAccessHelper.Core 5352 5353| Name | Type | Mandatory| Description | 5354| ---------------------- | ------------------- | ---- | ------------------------------------------------ | 5355|formId |string |Yes| Widget ID, which is provided when a widget is created in Gallery.| 5356|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. | 5357 5358## ResourceType<sup>11+</sup> 5359 5360Enumerates the types of the resources to write. 5361 5362**System capability**: SystemCapability.FileManagement.PhotoAccessHelper.Core 5363 5364| Name | Value| Description| 5365| ----- | ---- | ---- | 5366| PHOTO_PROXY | 3 | Photo proxy. <br>**System API**: This is a system API.| 5367| PRIVATE_MOVING_PHOTO_RESOURCE<sup>12+</sup> | 4 | Private moving photo. <br>**System API**: This is a system API.| 5368 5369## DefaultChangeUri 5370 5371Enumerates the **DefaultChangeUri** subtypes. 5372 5373**System capability**: SystemCapability.FileManagement.PhotoAccessHelper.Core 5374 5375| Name | Value | Description | 5376| ----------------- | ----------------------- | ------------------------------------------------------------ | 5377| 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.| 5378 5379## SourceMode<sup>11+</sup> 5380 5381Enumerates the types of the file to read. 5382 5383**System API**: This is a system API. 5384 5385**System capability**: SystemCapability.FileManagement.PhotoAccessHelper.Core 5386 5387| Name | Value| Description| 5388| ----- | ---- | ---- | 5389| ORIGINAL_MODE | 0 | Original file.| 5390| EDITED_MODE | 1 | Edited file.| 5391## AuthorizationMode<sup>12+</sup> 5392 5393Enumerates the authorization modes. 5394 5395**System API**: This is a system API. 5396 5397**System capability**: SystemCapability.FileManagement.PhotoAccessHelper.Core 5398 5399| Name | Value| Description| 5400| ----- | ---- | ---- | 5401| SHORT_TIME_AUTHORIZATION| 0 | Temporary authorization.| 5402 5403## AnalysisType<sup>11+</sup> 5404 5405Enumerates the smart analysis types. 5406 5407**System capability**: SystemCapability.FileManagement.PhotoAccessHelper.Core 5408 5409| Name | Value | Description | 5410| :---------------------------- | :- | :------- | 5411| ANALYSIS\_AESTHETICS\_SCORE | 0 | Aesthetics score. <br>**System API**: This is a system API. | 5412| ANALYSIS\_LABEL | 1 | Label. <br>**System API**: This is a system API. | 5413| ANALYSIS\_OCR | 2 | Optical character recognition (OCR) analysis. <br>**System API**: This is a system API. | 5414| ANALYSIS\_FACE | 3 | Facial detection analysis. <br>**System API**: This is a system API. | 5415| ANALYSIS\_OBJECT | 4 | Object detection analysis. <br>**System API**: This is a system API. | 5416| ANALYSIS\_RECOMMENDATION | 5 | Recommendation analysis. <br>**System API**: This is a system API. | 5417| ANALYSIS\_SEGMENTATION | 6 | Segmentation analysis. <br>**System API**: This is a system API. | 5418| ANALYSIS\_COMPOSITION | 7 | Aesthetic composition analysis. <br>**System API**: This is a system API. | 5419| ANALYSIS\_SALIENCY | 8 | Salience analysis. <br>**System API**: This is a system API. | 5420| ANALYSIS\_DETAIL\_ADDRESS | 9 | Detailed address analysis. <br>**System API**: This is a system API. | 5421| ANALYSIS\_HUMAN\_FACE\_TAG<sup>12+</sup> | 10 | Face clustering analysis. <br>**System API**: This is a system API. | 5422| 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. | 5423| 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. | 5424| ANALYSIS\_VIDEO\_LABEL<sup>12+</sup> | 13 | Video label analysis. <br>**System API**: This is a system API. | 5425 5426## HighlightAlbumInfoType<sup>12+</sup> 5427 5428Enumerates the types of the highlights album information. 5429 5430**System API**: This is a system API. 5431 5432**System capability**: SystemCapability.FileManagement.PhotoAccessHelper.Core 5433 5434| Name | Value | Description | 5435| :------------ | :- | :------- | 5436| COVER\_INFO | 0 | Cover information. | 5437| PLAY\_INFO | 1 | Music information. | 5438 5439## HighlightUserActionType<sup>12+</sup> 5440 5441Enumerates the user behavior types of the highlights album. 5442 5443**System API**: This is a system API. 5444 5445**System capability**: SystemCapability.FileManagement.PhotoAccessHelper.Core 5446 5447| Name | Value | Description | 5448| :---------------------------- | :- | :------- | 5449| INSERTED\_PIC\_COUNT | 0 | Number of inserted pictures. | 5450| REMOVED\_PIC\_COUNT | 1 | Number of removed pictures. | 5451| SHARED\_SCREENSHOT\_COUNT | 2 | Number of times that a full-length image in a highlights album is shared. | 5452| SHARED\_COVER\_COUNT | 3 | Number of times that a highlights cover is shared. | 5453| RENAMED\_COUNT | 4 | Number of times that a highlights album is renamed. | 5454| CHANGED\_COVER\_COUNT | 5 | Number of times that a cover is changed. | 5455| RENDER\_VIEWED\_TIMES | 100 | Number of times that the pictures in a highlights album are played. | 5456| RENDER\_VIEWED\_DURATION | 101 | Time used to play the pictures in a highlights album. | 5457| ART\_LAYOUT\_VIEWED\_TIMES | 102 | Number of times that a highlights album is viewed. | 5458| ART\_LAYOUT\_VIEWED\_DURATION | 103 | Time used to view a highlights album. | 5459 5460## MovingPhotoEffectMode<sup>12+</sup> 5461 5462Enumerates the effects of a moving photo. 5463 5464**System API**: This is a system API. 5465 5466**System capability**: SystemCapability.FileManagement.PhotoAccessHelper.Core 5467 5468| Name | Value | Description | 5469| :---------------------------- | :- | :------- | 5470| DEFAULT | 0 | Default effect.| 5471| BOUNCE\_PLAY | 1 | Back-and-forth motion.| 5472| LOOP\_PLAY | 2 | Continuously repeated animation.| 5473| LONG\_EXPOSURE | 3 | Long exposure. | 5474| MULTI\_EXPOSURE | 4 | Multiple exposures. | 5475| CINEMA\_GRAPH | 5 | Cinemagraph. | 5476| IMAGE\_ONLY | 10 | Image only. | 5477 5478## PhotoPermissionType<sup>12+</sup> 5479 5480Enumerates the types of permissions for accessing media assets. 5481 5482The permissions include temporary read permission and persistent read permission. The temporary read permission will be removed when the application exits, while the persisten read permission will not. 5483 5484For 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. 5485 5486**System API**: This is a system API. 5487 5488**System capability**: SystemCapability.FileManagement.PhotoAccessHelper.Core 5489 5490| Name | Value| Description| 5491| ----- | ---- | ---- | 5492| TEMPORARY_READ_IMAGEVIDEO | 0 | Temporary read permission.| 5493| PERSISTENT_READ_IMAGEVIDEO | 1 | Persistent read permission.| 5494 5495## HideSensitiveType<sup>12+</sup> 5496 5497Enumerates the types of media resource information to be hidden from an application. 5498 5499**System API**: This is a system API. 5500 5501**System capability**: SystemCapability.FileManagement.PhotoAccessHelper.Core 5502 5503| Name | Value| Description| 5504| ----- | ---- | ---- | 5505| HIDE_LOCATION_AND_SHOOTING_PARAM | 0 | Geographical location and shooting parameters.| 5506| HIDE_LOCATION_ONLY | 1 | Geographical location information.| 5507| HIDE_SHOOTING_PARAM_ONLY | 2 | Shooting parameters.| 5508| NO_HIDE_SENSITIVE_TYPE | 3 | Do not hide any information.| 5509