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 used to return the image or video created.| 41 42**Error codes** 43 44For details about the error codes, see [Universal Error Codes](../errorcode-universal.md) and [File Management Error Codes](../apis-core-file-kit/errorcode-filemanagement.md). 45 46| ID| Error Message| 47| -------- | ---------------------------------------- | 48| 202 | Called by non-system application. | 49| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types; 3. Parameter verification failed. | 50| 13900012 | Permission denied. | 51| 13900020 | Invalid argument. | 52| 14000001 | Invalid display name. | 53| 14000011 | System inner fail. | 54 55**Example** 56 57```ts 58async function example() { 59 console.info('createAssetDemo'); 60 let testFileName: string = 'testFile' + Date.now() + '.jpg'; 61 phAccessHelper.createAsset(testFileName, (err, photoAsset) => { 62 if (photoAsset !== undefined) { 63 console.info('createAsset file displayName' + photoAsset.displayName); 64 console.info('createAsset successfully'); 65 } else { 66 console.error(`createAsset failed, error: ${err.code}, ${err.message}`); 67 } 68 }); 69} 70``` 71 72### createAsset 73 74createAsset(displayName: string): Promise<PhotoAsset> 75 76Creates an image or video asset with the specified file name. This API uses a promise to return the result. 77 78The file name must comply with the following specifications: 79- The file name consists of a valid file name and an image or video file name extension. 80- The file name cannot exceed 255 characters. 81- The file name cannot contain any of the following characters:<br>. .. \ / : * ? " ' ` < > | { } [ ] 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 used 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 used 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 albums. | 520| options | [FetchOptions](js-apis-photoAccessHelper.md#fetchoptions) | Yes | Options for retrieving the hidden albums. | 521| callback | AsyncCallback<[FetchResult](js-apis-photoAccessHelper.md#fetchresult)<[Album](#album)>> | Yes | Callback used 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 albums. | 578| callback | AsyncCallback<[FetchResult](js-apis-photoAccessHelper.md#fetchresult)<[Album](#album)>> | Yes | Callback used 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 albums. | 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 used 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 videos). 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. If the URIs fail to be generated, a batch creation error code will be returned.<br>The error code **-3006** means that there are invalid characters; **-2004** means that the image type does not match the file name extension; **-203** means that the file operation is abnormal.| 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** 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 the enum.| 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** means the operation is successful; 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 application. 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 | string | 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. If the URIs fail to be generated, a batch creation error code will be returned.<br>The error code **-3006** means that there are invalid characters; **-2004** means that the image type does not match the file name extension; **-203** means that the file operation is abnormal.| 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## PhotoAsset 1554 1555Provides APIs for encapsulating file asset attributes. 1556 1557### open<sup>(deprecated)</sup> 1558 1559open(mode: string, callback: AsyncCallback<number>): void 1560 1561Opens this file asset. This API uses an asynchronous callback to return the result. 1562 1563> **NOTE** 1564> 1565> 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. 1566 1567> **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. 1568 1569**System API**: This is a system API. 1570 1571**Required permissions**: ohos.permission.READ_IMAGEVIDEO or ohos.permission.WRITE_IMAGEVIDEO 1572 1573**System capability**: SystemCapability.FileManagement.PhotoAccessHelper.Core 1574 1575**Parameters** 1576 1577| Name | Type | Mandatory | Description | 1578| -------- | --------------------------- | ---- | ----------------------------------- | 1579| mode | string | Yes | Mode for opening the file, which can be **'r'** (read-only), **'w'** (write-only), or **'rw'** (read/write).| 1580| callback | AsyncCallback<number> | Yes | Callback used to return the file descriptor (FD) of the file opened. | 1581 1582**Error codes** 1583 1584For details about the error codes, see [Universal Error Codes](../errorcode-universal.md) and [File Management Error Codes](../apis-core-file-kit/errorcode-filemanagement.md). 1585 1586| ID| Error Message| 1587| -------- | ---------------------------------------- | 1588| 202 | Called by non-system application. | 1589| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types; 3. Parameter verification failed. | 1590| 13900012 | Permission denied. | 1591| 13900020 | Invalid argument. | 1592| 14000011 | System inner fail. | 1593 1594**Example** 1595 1596```ts 1597async function example() { 1598 console.info('Open demo'); 1599 let testFileName: string = 'testFile' + Date.now() + '.jpg'; 1600 let photoAsset: photoAccessHelper.PhotoAsset = await phAccessHelper.createAsset(testFileName); 1601 photoAsset.open('rw', (err, fd) => { 1602 if (fd !== undefined) { 1603 console.info('File fd' + fd); 1604 photoAsset.close(fd); 1605 } else { 1606 console.error(`Open file err: ${err.code}, ${err.message}`); 1607 } 1608 }); 1609} 1610``` 1611 1612### open<sup>(deprecated)</sup> 1613 1614open(mode: string): Promise<number> 1615 1616Opens this file asset. This API uses a promise to return the result. 1617 1618> **NOTE** 1619> 1620> 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. 1621 1622> **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. 1623 1624**System API**: This is a system API. 1625 1626**Required permissions**: ohos.permission.READ_IMAGEVIDEO or ohos.permission.WRITE_IMAGEVIDEO 1627 1628**System capability**: SystemCapability.FileManagement.PhotoAccessHelper.Core 1629 1630**Parameters** 1631 1632| Name | Type | Mandatory | Description | 1633| ---- | ------ | ---- | ----------------------------------- | 1634| mode | string | Yes | Mode for opening the file, which can be **'r'** (read-only), **'w'** (write-only), or **'rw'** (read/write).| 1635 1636**Return value** 1637 1638| Type | Description | 1639| --------------------- | ------------- | 1640| Promise<number> | Promise used to return the FD of the file opened.| 1641 1642**Error codes** 1643 1644For details about the error codes, see [Universal Error Codes](../errorcode-universal.md) and [File Management Error Codes](../apis-core-file-kit/errorcode-filemanagement.md). 1645 1646| ID| Error Message| 1647| -------- | ---------------------------------------- | 1648| 202 | Called by non-system application. | 1649| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types; 3. Parameter verification failed. | 1650| 13900012 | Permission denied. | 1651| 13900020 | Invalid argument. | 1652| 14000011 | System inner fail. | 1653 1654**Example** 1655 1656```ts 1657async function example() { 1658 console.info('Open demo'); 1659 try { 1660 let testFileName: string = 'testFile' + Date.now() + '.jpg'; 1661 let photoAsset: photoAccessHelper.PhotoAsset = await phAccessHelper.createAsset(testFileName); 1662 let fd: number = await photoAsset.open('rw'); 1663 if (fd !== undefined) { 1664 console.info('File fd' + fd); 1665 photoAsset.close(fd); 1666 } else { 1667 console.error('Open file fail'); 1668 } 1669 } catch (err) { 1670 console.error(`Open demo err: ${err.code}, ${err.message}`); 1671 } 1672} 1673``` 1674 1675### setFavorite<sup>(deprecated)</sup> 1676 1677setFavorite(favoriteState: boolean, callback: AsyncCallback<void>): void 1678 1679Favorites or unfavorites this file. This API uses an asynchronous callback to return the result. 1680 1681> **NOTE** 1682> 1683> This API is supported since API version 10 and deprecated since API version 11. Use [MediaAssetChangeRequest.setFavorite](#setfavorite11) instead. 1684 1685**System API**: This is a system API. 1686 1687**Required permissions**: ohos.permission.WRITE_IMAGEVIDEO 1688 1689**System capability**: SystemCapability.FileManagement.PhotoAccessHelper.Core 1690 1691**Parameters** 1692 1693| Name | Type | Mandatory | Description | 1694| ---------- | ------------------------- | ---- | ---------------------------------- | 1695| favoriteState | boolean | Yes | Operation to perform. The value **true** means to favorite the file asset, and **false** means the opposite.| 1696| callback | AsyncCallback<void> | Yes | Callback that returns no value. | 1697 1698**Error codes** 1699 1700For details about the error codes, see [Universal Error Codes](../errorcode-universal.md) and [File Management Error Codes](../apis-core-file-kit/errorcode-filemanagement.md). 1701 1702| ID| Error Message| 1703| -------- | ---------------------------------------- | 1704| 202 | Called by non-system application. | 1705| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types; 3. Parameter verification failed. | 1706| 13900012 | Permission denied. | 1707| 13900020 | Invalid argument. | 1708| 14000011 | System inner fail. | 1709 1710**Example** 1711 1712```ts 1713import { dataSharePredicates } from '@kit.ArkData'; 1714 1715async function example() { 1716 console.info('setFavoriteDemo'); 1717 let predicates: dataSharePredicates.DataSharePredicates = new dataSharePredicates.DataSharePredicates(); 1718 let fetchOption: photoAccessHelper.FetchOptions = { 1719 fetchColumns: [], 1720 predicates: predicates 1721 }; 1722 let fetchResult: photoAccessHelper.FetchResult<photoAccessHelper.PhotoAsset> = await phAccessHelper.getAssets(fetchOption); 1723 let asset = await fetchResult.getFirstObject(); 1724 asset.setFavorite(true, (err) => { 1725 if (err === undefined) { 1726 console.info('favorite successfully'); 1727 } else { 1728 console.error(`favorite failed with error: ${err.code}, ${err.message}`); 1729 } 1730 }); 1731} 1732``` 1733 1734### setFavorite<sup>(deprecated)</sup> 1735 1736setFavorite(favoriteState: boolean): Promise<void> 1737 1738Favorites or unfavorites this file asset. This API uses a promise to return the result. 1739 1740> **NOTE** 1741> 1742> This API is supported since API version 10 and deprecated since API version 11. Use [MediaAssetChangeRequest.setFavorite](#setfavorite11) instead. 1743 1744**System API**: This is a system API. 1745 1746**Required permissions**: ohos.permission.WRITE_IMAGEVIDEO 1747 1748**System capability**: SystemCapability.FileManagement.PhotoAccessHelper.Core 1749 1750**Parameters** 1751 1752| Name | Type | Mandatory | Description | 1753| ---------- | ------- | ---- | ---------------------------------- | 1754| favoriteState | boolean | Yes | Operation to perform. The value **true** means to favorite the file asset, and **false** means the opposite.| 1755 1756**Return value** 1757 1758| Type | Description | 1759| ------------------- | ---------- | 1760| Promise<void> | Promise that returns no value.| 1761 1762**Error codes** 1763 1764For details about the error codes, see [Universal Error Codes](../errorcode-universal.md) and [File Management Error Codes](../apis-core-file-kit/errorcode-filemanagement.md). 1765 1766| ID| Error Message| 1767| -------- | ---------------------------------------- | 1768| 202 | Called by non-system application. | 1769| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types; 3. Parameter verification failed. | 1770| 13900012 | Permission denied. | 1771| 13900020 | Invalid argument. | 1772| 14000011 | System inner fail. | 1773 1774**Example** 1775 1776```ts 1777import { dataSharePredicates } from '@kit.ArkData'; 1778import { BusinessError } from '@kit.BasicServicesKit'; 1779 1780async function example() { 1781 console.info('setFavoriteDemo'); 1782 let predicates: dataSharePredicates.DataSharePredicates = new dataSharePredicates.DataSharePredicates(); 1783 let fetchOption: photoAccessHelper.FetchOptions = { 1784 fetchColumns: [], 1785 predicates: predicates 1786 }; 1787 let fetchResult: photoAccessHelper.FetchResult<photoAccessHelper.PhotoAsset> = await phAccessHelper.getAssets(fetchOption); 1788 let asset = await fetchResult.getFirstObject(); 1789 asset.setFavorite(true).then(() => { 1790 console.info('setFavorite successfully'); 1791 }).catch((err: BusinessError) => { 1792 console.error(`setFavorite failed with error: ${err.code}, ${err.message}`); 1793 }); 1794} 1795``` 1796 1797### setHidden<sup>(deprecated)</sup> 1798 1799setHidden(hiddenState: boolean, callback: AsyncCallback<void>): void 1800 1801Sets this file to hidden state. This API uses an asynchronous callback to return the result. 1802 1803Private 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. 1804 1805> **NOTE** 1806> 1807> This API is supported since API version 10 and deprecated since API version 11. Use [MediaAssetChangeRequest.setHidden](#sethidden11) instead. 1808 1809**System API**: This is a system API. 1810 1811**Required permissions**: ohos.permission.WRITE_IMAGEVIDEO 1812 1813**System capability**: SystemCapability.FileManagement.PhotoAccessHelper.Core 1814 1815**Parameters** 1816 1817| Name | Type | Mandatory | Description | 1818| ---------- | ------------------------- | ---- | ---------------------------------- | 1819| 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.| 1820| callback | AsyncCallback<void> | Yes | Callback that returns no value. | 1821 1822**Error codes** 1823 1824For details about the error codes, see [Universal Error Codes](../errorcode-universal.md) and [File Management Error Codes](../apis-core-file-kit/errorcode-filemanagement.md). 1825 1826| ID| Error Message| 1827| -------- | ---------------------------------------- | 1828| 202 | Called by non-system application. | 1829| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types; 3. Parameter verification failed. | 1830| 13900012 | Permission denied. | 1831| 13900020 | Invalid argument. | 1832| 14000011 | System inner fail. | 1833 1834**Example** 1835 1836```ts 1837import { dataSharePredicates } from '@kit.ArkData'; 1838 1839async function example() { 1840 console.info('setHiddenDemo'); 1841 let predicates: dataSharePredicates.DataSharePredicates = new dataSharePredicates.DataSharePredicates(); 1842 let fetchOption: photoAccessHelper.FetchOptions = { 1843 fetchColumns: [], 1844 predicates: predicates 1845 }; 1846 let fetchResult: photoAccessHelper.FetchResult<photoAccessHelper.PhotoAsset> = await phAccessHelper.getAssets(fetchOption); 1847 let asset = await fetchResult.getFirstObject(); 1848 asset.setHidden(true, (err) => { 1849 if (err === undefined) { 1850 console.info('setHidden successfully'); 1851 } else { 1852 console.error(`setHidden failed with error: ${err.code}, ${err.message}`); 1853 } 1854 }); 1855} 1856``` 1857 1858### setHidden<sup>(deprecated)</sup> 1859 1860setHidden(hiddenState: boolean): Promise<void> 1861 1862Sets this file asset to hidden state. This API uses a promise to return the result. 1863 1864Private 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. 1865 1866> **NOTE** 1867> 1868> This API is supported since API version 10 and deprecated since API version 11. Use [MediaAssetChangeRequest.setHidden](#sethidden11) instead. 1869 1870**System API**: This is a system API. 1871 1872**Required permissions**: ohos.permission.WRITE_IMAGEVIDEO 1873 1874**System capability**: SystemCapability.FileManagement.PhotoAccessHelper.Core 1875 1876**Parameters** 1877 1878| Name | Type | Mandatory | Description | 1879| ---------- | ------- | ---- | ---------------------------------- | 1880| 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.| 1881 1882**Return value** 1883 1884| Type | Description | 1885| ------------------- | ---------- | 1886| Promise<void> | Promise that returns no value.| 1887 1888**Error codes** 1889 1890For details about the error codes, see [Universal Error Codes](../errorcode-universal.md) and [File Management Error Codes](../apis-core-file-kit/errorcode-filemanagement.md). 1891 1892| ID| Error Message| 1893| -------- | ---------------------------------------- | 1894| 202 | Called by non-system application. | 1895| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types; 3. Parameter verification failed. | 1896| 13900012 | Permission denied. | 1897| 13900020 | Invalid argument. | 1898| 14000011 | System inner fail. | 1899 1900**Example** 1901 1902```ts 1903import { dataSharePredicates } from '@kit.ArkData'; 1904import { BusinessError } from '@kit.BasicServicesKit'; 1905 1906async function example() { 1907 // Restore a file from a hidden album. Before the operation, ensure that the file exists in the hidden album. 1908 console.info('setHiddenDemo'); 1909 let predicates: dataSharePredicates.DataSharePredicates = new dataSharePredicates.DataSharePredicates(); 1910 let fetchOption: photoAccessHelper.FetchOptions = { 1911 fetchColumns: [], 1912 predicates: predicates 1913 }; 1914 let albumList: photoAccessHelper.FetchResult<photoAccessHelper.Album> = await phAccessHelper.getAlbums(photoAccessHelper.AlbumType.SYSTEM, photoAccessHelper.AlbumSubtype.HIDDEN); 1915 let album = await albumList.getFirstObject(); 1916 let fetchResult: photoAccessHelper.FetchResult<photoAccessHelper.PhotoAsset> = await album.getAssets(fetchOption); 1917 let asset = await fetchResult.getFirstObject(); 1918 asset.setHidden(false).then(() => { 1919 console.info('setHidden successfully'); 1920 }).catch((err: BusinessError) => { 1921 console.error(`setHidden failed with error: ${err.code}, ${err.message}`); 1922 }); 1923} 1924``` 1925 1926### getExif 1927 1928getExif(): Promise<string> 1929 1930Obtains the exchangeable image file format (EXIF) data from a JPG image. This API uses a promise to return the result. 1931 1932The 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). 1933 1934> **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**. 1935 1936**System API**: This is a system API. 1937 1938**Required permissions**: ohos.permission.READ_IMAGEVIDEO 1939 1940**System capability**: SystemCapability.FileManagement.PhotoAccessHelper.Core 1941 1942**Return value** 1943 1944| Type | Description | 1945| --------------------------------------- | ----------------- | 1946| Promise<string> | Promise used to return the EXIF data, in JSON strings.| 1947 1948**Error codes** 1949 1950For details about the error codes, see [Universal Error Codes](../errorcode-universal.md) and [File Management Error Codes](../apis-core-file-kit/errorcode-filemanagement.md). 1951 1952| ID| Error Message| 1953| -------- | ---------------------------------------- | 1954| 202 | Called by non-system application. | 1955| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types. | 1956| 13900012 | Permission denied. | 1957| 13900020 | Invalid argument. | 1958| 14000011 | System inner fail. | 1959 1960**Example** 1961 1962```ts 1963import { dataSharePredicates } from '@kit.ArkData'; 1964 1965async function example() { 1966 try { 1967 console.info('getExifDemo'); 1968 let predicates: dataSharePredicates.DataSharePredicates = new dataSharePredicates.DataSharePredicates(); 1969 let fetchOptions: photoAccessHelper.FetchOptions = { 1970 fetchColumns: [ 'all_exif', photoAccessHelper.PhotoKeys.USER_COMMENT], 1971 predicates: predicates 1972 }; 1973 let fetchResult: photoAccessHelper.FetchResult<photoAccessHelper.PhotoAsset> = await phAccessHelper.getAssets(fetchOptions); 1974 let photoAsset: photoAccessHelper.PhotoAsset = await fetchResult.getFirstObject(); 1975 let exifMessage = await photoAsset.getExif(); 1976 let userCommentKey = 'UserComment'; 1977 let userComment = JSON.stringify(JSON.parse(exifMessage), [userCommentKey]); 1978 console.info('getExifDemo userComment: ' + JSON.stringify(userComment)); 1979 fetchResult.close(); 1980 } catch (err) { 1981 console.error(`getExifDemoCallback failed with error: ${err.code}, ${err.message}`); 1982 } 1983} 1984``` 1985 1986### getExif 1987 1988getExif(callback: AsyncCallback<string>): void 1989 1990Obtains the exchangeable image file format (EXIF) data from a JPG image. This API uses an asynchronous callback to return the result. 1991 1992The 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). 1993 1994> **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**. 1995 1996**System API**: This is a system API. 1997 1998**Required permissions**: ohos.permission.READ_IMAGEVIDEO 1999 2000**System capability**: SystemCapability.FileManagement.PhotoAccessHelper.Core 2001 2002**Parameters** 2003 2004| Name | Type | Mandatory| Description | 2005| -------- | ------------------------- | ---- | ---------- | 2006| callback | AsyncCallback<string> | Yes | Callback used to return the EXIF data, in JSON strings.| 2007 2008**Error codes** 2009 2010For details about the error codes, see [Universal Error Codes](../errorcode-universal.md) and [File Management Error Codes](../apis-core-file-kit/errorcode-filemanagement.md). 2011 2012| ID| Error Message| 2013| -------- | ---------------------------------------- | 2014| 202 | Called by non-system application. | 2015| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types. | 2016| 13900012 | Permission denied. | 2017| 13900020 | Invalid argument. | 2018| 14000011 | System inner fail. | 2019 2020**Example** 2021 2022```ts 2023import { dataSharePredicates } from '@kit.ArkData'; 2024 2025async function example() { 2026 try { 2027 console.info('getExifDemo'); 2028 let predicates: dataSharePredicates.DataSharePredicates = new dataSharePredicates.DataSharePredicates(); 2029 predicates.isNotNull('all_exif') 2030 let fetchOptions: photoAccessHelper.FetchOptions = { 2031 fetchColumns: ['all_exif', photoAccessHelper.PhotoKeys.USER_COMMENT], 2032 predicates: predicates 2033 }; 2034 let fetchResult: photoAccessHelper.FetchResult<photoAccessHelper.PhotoAsset> = await phAccessHelper.getAssets(fetchOptions); 2035 let photoAsset: photoAccessHelper.PhotoAsset = await fetchResult.getFirstObject(); 2036 console.info('getExifDemo photoAsset displayName: ' + JSON.stringify(photoAsset.displayName)); 2037 let userCommentKey = 'UserComment'; 2038 photoAsset.getExif((err, exifMessage) => { 2039 if (exifMessage !== undefined) { 2040 let userComment = JSON.stringify(JSON.parse(exifMessage), [userCommentKey]); 2041 console.info('getExifDemo userComment: ' + JSON.stringify(userComment)); 2042 } else { 2043 console.error(`getExif failed, error: ${err.code}, ${err.message}`); 2044 } 2045 }); 2046 fetchResult.close(); 2047 } catch (err) { 2048 console.error(`getExifDemoCallback failed with error: ${err.code}, ${err.message}`); 2049 } 2050} 2051``` 2052 2053### setUserComment<sup>(deprecated)</sup> 2054 2055setUserComment(userComment: string): Promise<void> 2056 2057Sets user comment information of an image or video. This API uses a promise to return the result. 2058 2059> **NOTE** 2060> 2061> This API is supported since API version 10 and deprecated since API version 11. Use [MediaAssetChangeRequest.setUserComment](#setusercomment11) instead. 2062 2063**NOTE**<br>This API can be used to modify the comment information of only images or videos. 2064 2065**System API**: This is a system API. 2066 2067**Required permissions**: ohos.permission.WRITE_IMAGEVIDEO 2068 2069**System capability**: SystemCapability.FileManagement.PhotoAccessHelper.Core 2070 2071**Parameters** 2072 2073| Name | Type | Mandatory| Description | 2074| -------- | ------------------------- | ---- | ---------- | 2075| userComment | string | Yes | User comment information to set, which cannot exceed 420 characters.| 2076 2077**Return value** 2078 2079| Type | Description | 2080| --------------------------------------- | ----------------- | 2081|Promise<void> | Promise that returns no value.| 2082 2083**Error codes** 2084 2085For details about the error codes, see [Universal Error Codes](../errorcode-universal.md) and [File Management Error Codes](../apis-core-file-kit/errorcode-filemanagement.md). 2086 2087| ID| Error Message| 2088| -------- | ---------------------------------------- | 2089| 202 | Called by non-system application. | 2090| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types; 3. Parameter verification failed. | 2091| 13900012 | Permission denied. | 2092| 13900020 | Invalid argument. | 2093| 14000011 | System inner fail. | 2094 2095**Example** 2096 2097```ts 2098import { dataSharePredicates } from '@kit.ArkData'; 2099 2100async function example() { 2101 try { 2102 console.info('setUserCommentDemo') 2103 let predicates: dataSharePredicates.DataSharePredicates = new dataSharePredicates.DataSharePredicates(); 2104 let fetchOptions: photoAccessHelper.FetchOptions = { 2105 fetchColumns: [], 2106 predicates: predicates 2107 }; 2108 let fetchResult: photoAccessHelper.FetchResult<photoAccessHelper.PhotoAsset> = await phAccessHelper.getAssets(fetchOptions); 2109 let photoAsset: photoAccessHelper.PhotoAsset = await fetchResult.getFirstObject(); 2110 let userComment = 'test_set_user_comment'; 2111 await photoAsset.setUserComment(userComment); 2112 } catch (err) { 2113 console.error(`setUserCommentDemoPromise failed with error: ${err.code}, ${err.message}`); 2114 } 2115} 2116``` 2117 2118### setUserComment<sup>(deprecated)</sup> 2119 2120setUserComment(userComment: string, callback: AsyncCallback<void>): void 2121 2122Sets user comment information of an image or video. This API uses an asynchronous callback to return the result. 2123 2124> **NOTE** 2125> 2126> This API is supported since API version 10 and deprecated since API version 11. Use [MediaAssetChangeRequest.setUserComment](#setusercomment11) instead. 2127 2128**NOTE**<br>This API can be used to modify the comment information of only images or videos. 2129 2130**System API**: This is a system API. 2131 2132**Required permissions**: ohos.permission.WRITE_IMAGEVIDEO 2133 2134**System capability**: SystemCapability.FileManagement.PhotoAccessHelper.Core 2135 2136**Parameters** 2137 2138| Name | Type | Mandatory| Description | 2139| -------- | ------------------------- | ---- | ---------- | 2140| userComment | string | Yes | User comment information to set, which cannot exceed 420 characters.| 2141| callback | AsyncCallback<void> | Yes | Callback that returns no value.| 2142 2143**Error codes** 2144 2145For details about the error codes, see [Universal Error Codes](../errorcode-universal.md) and [File Management Error Codes](../apis-core-file-kit/errorcode-filemanagement.md). 2146 2147| ID| Error Message| 2148| -------- | ---------------------------------------- | 2149| 202 | Called by non-system application. | 2150| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types; 3. Parameter verification failed. | 2151| 13900012 | Permission denied. | 2152| 13900020 | Invalid argument. | 2153| 14000011 | System inner fail. | 2154 2155**Example** 2156 2157```ts 2158import { dataSharePredicates } from '@kit.ArkData'; 2159 2160async function example() { 2161 try { 2162 console.info('setUserCommentDemo') 2163 let predicates: dataSharePredicates.DataSharePredicates = new dataSharePredicates.DataSharePredicates(); 2164 let fetchOptions: photoAccessHelper.FetchOptions = { 2165 fetchColumns: [], 2166 predicates: predicates 2167 }; 2168 let fetchResult: photoAccessHelper.FetchResult<photoAccessHelper.PhotoAsset> = await phAccessHelper.getAssets(fetchOptions); 2169 let photoAsset: photoAccessHelper.PhotoAsset = await fetchResult.getFirstObject(); 2170 let userComment = 'test_set_user_comment'; 2171 photoAsset.setUserComment(userComment, (err) => { 2172 if (err === undefined) { 2173 console.info('setUserComment successfully'); 2174 } else { 2175 console.error(`setUserComment failed with error: ${err.code}, ${err.message}`); 2176 } 2177 }); 2178 } catch (err) { 2179 console.error(`setUserCommentDemoCallback failed with error: ${err.code}, ${err.message}`); 2180 } 2181} 2182``` 2183 2184### setPending<sup>11+</sup> 2185 2186setPending(pendingState: boolean, callback: AsyncCallback<void>): void 2187 2188Sets the pending state for this image or video asset. This API uses an asynchronous callback to return the result. 2189 2190The 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. 2191 2192**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. 2193 2194**System API**: This is a system API. 2195 2196**Required permissions**: ohos.permission.WRITE_IMAGEVIDEO 2197 2198**System capability**: SystemCapability.FileManagement.PhotoAccessHelper.Core 2199 2200**Parameters** 2201 2202| Name | Type | Mandatory | Description | 2203| ---------- | ------- | ---- | ---------------------------------- | 2204| 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.| 2205| callback | AsyncCallback<void> | Yes | Callback that returns no value.| 2206 2207**Error codes** 2208 2209For details about the error codes, see [Universal Error Codes](../errorcode-universal.md) and [File Management Error Codes](../apis-core-file-kit/errorcode-filemanagement.md). 2210 2211| ID| Error Message| 2212| -------- | ---------------------------------------- | 2213| 201 | Permission denied. | 2214| 202 | Called by non-system application. | 2215| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types; 3. Parameter verification failed. | 2216| 14000011 | System inner fail. | 2217 2218**Example** 2219 2220```ts 2221async function example() { 2222 try { 2223 console.info('setPendingCallbackDemo'); 2224 let testFileName: string = 'testFile' + Date.now() + '.jpg'; 2225 let photoAsset = await phAccessHelper.createAsset(testFileName); 2226 let fd = await photoAsset.open('rw'); 2227 photoAsset.setPending(true, async (err) => { 2228 if (err !== undefined) { 2229 console.error(`setPending(true) failed with error: ${err.code}, ${err.message}`); 2230 return; 2231 } 2232 // write photo buffer in fd. 2233 photoAsset.setPending(false, async (err) => { 2234 if (err !== undefined) { 2235 console.error(`setPending(false) failed with error: ${err.code}, ${err.message}`); 2236 return; 2237 } 2238 await photoAsset.close(fd); 2239 }); 2240 }); 2241 } catch (err) { 2242 console.error(`setPendingCallbackDemo failed with error: ${err.code}, ${err.message}`); 2243 } 2244} 2245``` 2246 2247### setPending<sup>11+</sup> 2248 2249setPending(pendingState: boolean): Promise<void> 2250 2251Sets the pending state for this image or video asset. This API uses a promise to return the result. 2252 2253The 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. 2254 2255**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. 2256 2257**System API**: This is a system API. 2258 2259**Required permissions**: ohos.permission.WRITE_IMAGEVIDEO 2260 2261**System capability**: SystemCapability.FileManagement.PhotoAccessHelper.Core 2262 2263**Parameters** 2264 2265| Name | Type | Mandatory | Description | 2266| ---------- | ------- | ---- | ---------------------------------- | 2267| 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.| 2268 2269**Return value** 2270 2271| Type | Description | 2272| --------------------------------------- | ----------------- | 2273|Promise<boolean> | Promise that returns no value.| 2274 2275**Error codes** 2276 2277For details about the error codes, see [Universal Error Codes](../errorcode-universal.md) and [File Management Error Codes](../apis-core-file-kit/errorcode-filemanagement.md). 2278 2279| ID| Error Message| 2280| -------- | ---------------------------------------- | 2281| 201 | Permission denied. | 2282| 202 | Called by non-system application. | 2283| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types; 3. Parameter verification failed. | 2284| 14000011 | System inner fail. | 2285 2286**Example** 2287 2288```ts 2289async function example() { 2290 try { 2291 console.info('setPendingPromiseDemo'); 2292 let testFileName: string = 'testFile' + Date.now() + '.jpg'; 2293 let photoAsset = await phAccessHelper.createAsset(testFileName); 2294 let fd = await photoAsset.open('rw'); 2295 await photoAsset.setPending(true); 2296 // write photo buffer in fd. 2297 photoAsset.setPending(false); 2298 await photoAsset.close(fd); 2299 } catch (err) { 2300 console.error(`setPendingPromiseDemo failed with error: ${err.code}, ${err.message}`); 2301 } 2302} 2303``` 2304 2305### isEdited<sup>11+</sup> 2306 2307isEdited(callback: AsyncCallback<boolean>): void 2308 2309Checks whether this image or video asset is edited. This API uses an asynchronous callback to return the result. 2310 2311**System API**: This is a system API. 2312 2313**Required permissions**: ohos.permission.READ_IMAGEVIDEO 2314 2315**System capability**: SystemCapability.FileManagement.PhotoAccessHelper.Core 2316 2317**Parameters** 2318 2319| Name | Type | Mandatory | Description | 2320| ---------- | ------- | ---- | ---------------------------------- | 2321| callback | AsyncCallback<boolean> | Yes | Callback used to return the result.| 2322 2323**Error codes** 2324 2325For details about the error codes, see [Universal Error Codes](../errorcode-universal.md) and [File Management Error Codes](../apis-core-file-kit/errorcode-filemanagement.md). 2326 2327| ID| Error Message| 2328| -------- | ---------------------------------------- | 2329| 201 | Permission denied. | 2330| 202 | Called by non-system application. | 2331| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types. | 2332| 14000011 | System inner fail. | 2333 2334**Example** 2335 2336```ts 2337import { dataSharePredicates } from '@kit.ArkData'; 2338 2339async function example() { 2340 try { 2341 console.info('isEditedCallbackDemo') 2342 let predicates: dataSharePredicates.DataSharePredicates = new dataSharePredicates.DataSharePredicates(); 2343 let fetchOptions: photoAccessHelper.FetchOptions = { 2344 fetchColumns: [], 2345 predicates: predicates 2346 }; 2347 let fetchResult: photoAccessHelper.FetchResult<photoAccessHelper.PhotoAsset> = await phAccessHelper.getAssets(fetchOptions); 2348 let photoAsset: photoAccessHelper.PhotoAsset = await fetchResult.getFirstObject(); 2349 photoAsset.isEdited((err, isEdited) => { 2350 if (err === undefined) { 2351 if (isEdited === true) { 2352 console.info('Photo is edited'); 2353 } else { 2354 console.info('Photo is not edited'); 2355 } 2356 } else { 2357 console.error(`isEdited failed with error: ${err.code}, ${err.message}`); 2358 } 2359 }); 2360 } catch (err) { 2361 console.error(`isEditedDemoCallback failed with error: ${err.code}, ${err.message}`); 2362 } 2363} 2364``` 2365 2366### isEdited<sup>11+</sup> 2367 2368isEdited(): Promise<boolean> 2369 2370Checks whether this image or video asset is edited. This API uses a promise to return the result. 2371 2372**System API**: This is a system API. 2373 2374**Required permissions**: ohos.permission.READ_IMAGEVIDEO 2375 2376**System capability**: SystemCapability.FileManagement.PhotoAccessHelper.Core 2377 2378**Return value** 2379 2380| Type | Description | 2381| --------------------------------------- | ----------------- | 2382|Promise<boolean> | Promise used to return the result.| 2383 2384 2385**Error codes** 2386 2387For details about the error codes, see [Universal Error Codes](../errorcode-universal.md) and [File Management Error Codes](../apis-core-file-kit/errorcode-filemanagement.md). 2388 2389| ID| Error Message| 2390| -------- | ---------------------------------------- | 2391| 201 | Permission denied. | 2392| 202 | Called by non-system application. | 2393| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types. | 2394| 14000011 | System inner fail. | 2395 2396**Example** 2397 2398```ts 2399import { dataSharePredicates } from '@kit.ArkData'; 2400 2401async function example() { 2402 try { 2403 console.info('isEditedPromiseDemo') 2404 let predicates: dataSharePredicates.DataSharePredicates = new dataSharePredicates.DataSharePredicates(); 2405 let fetchOptions: photoAccessHelper.FetchOptions = { 2406 fetchColumns: [], 2407 predicates: predicates 2408 }; 2409 let fetchResult: photoAccessHelper.FetchResult<photoAccessHelper.PhotoAsset> = await phAccessHelper.getAssets(fetchOptions); 2410 let photoAsset: photoAccessHelper.PhotoAsset = await fetchResult.getFirstObject(); 2411 let isEdited = await photoAsset.isEdited(); 2412 if (isEdited === true) { 2413 console.info('Photo is edited'); 2414 } else { 2415 console.info('Photo is not edited'); 2416 } 2417 } catch (err) { 2418 console.error(`isEditedDemoCallback failed with error: ${err.code}, ${err.message}`); 2419 } 2420} 2421``` 2422 2423### requestEditData<sup>11+</sup> 2424 2425requestEditData(callback: AsyncCallback<string>): void 2426 2427Obtains the edit data of this image or video asset. This API uses an asynchronous callback to return the result. 2428 2429If the asset has never been edited, an empty string is returned. 2430 2431**System API**: This is a system API. 2432 2433**Required permissions**: ohos.permission.READ_IMAGEVIDEO 2434 2435**System capability**: SystemCapability.FileManagement.PhotoAccessHelper.Core 2436 2437**Parameters** 2438 2439| Name | Type | Mandatory | Description | 2440| ---------- | ------- | ---- | ---------------------------------- | 2441| callback | AsyncCallback<string> | Yes | Callback used to return the edit data obtained.| 2442 2443**Error codes** 2444 2445For details about the error codes, see [Universal Error Codes](../errorcode-universal.md) and [File Management Error Codes](../apis-core-file-kit/errorcode-filemanagement.md). 2446 2447| ID| Error Message| 2448| -------- | ---------------------------------------- | 2449| 201 | Permission denied. | 2450| 202 | Called by non-system application. | 2451| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types. | 2452| 14000011 | System inner fail. | 2453 2454**Example** 2455 2456```ts 2457import { dataSharePredicates } from '@kit.ArkData'; 2458 2459async function example() { 2460 try { 2461 console.info('requestEditDataCallbackDemo') 2462 let predicates: dataSharePredicates.DataSharePredicates = new dataSharePredicates.DataSharePredicates(); 2463 let fetchOptions: photoAccessHelper.FetchOptions = { 2464 fetchColumns: [], 2465 predicates: predicates 2466 }; 2467 let fetchResult: photoAccessHelper.FetchResult<photoAccessHelper.PhotoAsset> = await phAccessHelper.getAssets(fetchOptions); 2468 let photoAsset: photoAccessHelper.PhotoAsset = await fetchResult.getFirstObject(); 2469 photoAsset.requestEditData((err, editdata) => { 2470 if (err === undefined) { 2471 console.info('Editdata is ' + editdata); 2472 } else { 2473 console.error(`requestEditData failed with error: ${err.code}, ${err.message}`); 2474 } 2475 }); 2476 } catch (err) { 2477 console.error(`requestEditDataCallbackDemo failed with error: ${err.code}, ${err.message}`); 2478 } 2479} 2480``` 2481 2482### requestEditData<sup>11+</sup> 2483 2484requestEditData(): Promise<string> 2485 2486Obtains the edit data of this image or video asset. This API uses a promise to return the result. 2487 2488If the asset has never been edited, an empty string is returned. 2489 2490**System API**: This is a system API. 2491 2492**Required permissions**: ohos.permission.READ_IMAGEVIDEO 2493 2494**System capability**: SystemCapability.FileManagement.PhotoAccessHelper.Core 2495 2496**Return value** 2497 2498| Type | Description | 2499| --------------------------------------- | ----------------- | 2500|Promise<string> | Promise used to return the edit data obtained.| 2501 2502 2503**Error codes** 2504 2505For details about the error codes, see [Universal Error Codes](../errorcode-universal.md) and [File Management Error Codes](../apis-core-file-kit/errorcode-filemanagement.md). 2506 2507| ID| Error Message| 2508| -------- | ---------------------------------------- | 2509| 201 | Permission denied. | 2510| 202 | Called by non-system application. | 2511| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types. | 2512| 14000011 | System inner fail. | 2513 2514**Example** 2515 2516```ts 2517import { dataSharePredicates } from '@kit.ArkData'; 2518 2519async function example() { 2520 try { 2521 console.info('requestEditDataPromiseDemo') 2522 let predicates: dataSharePredicates.DataSharePredicates = new dataSharePredicates.DataSharePredicates(); 2523 let fetchOptions: photoAccessHelper.FetchOptions = { 2524 fetchColumns: [], 2525 predicates: predicates 2526 }; 2527 let fetchResult: photoAccessHelper.FetchResult<photoAccessHelper.PhotoAsset> = await phAccessHelper.getAssets(fetchOptions); 2528 let photoAsset: photoAccessHelper.PhotoAsset = await fetchResult.getFirstObject(); 2529 let editdata: string = await photoAsset.requestEditData(); 2530 console.info('Editdata is ' + editdata); 2531 } catch (err) { 2532 console.error(`requestEditDataPromiseDemo failed with error: ${err.code}, ${err.message}`); 2533 } 2534} 2535``` 2536 2537### getEditData<sup>11+</sup> 2538 2539getEditData(): Promise<MediaAssetEditData> 2540 2541Obtains the edited data of this asset. This API uses a promise to return the result. 2542 2543If the asset has never been edited, an empty string is returned. 2544 2545**System API**: This is a system API. 2546 2547**Required permissions**: ohos.permission.READ_IMAGEVIDEO 2548 2549**System capability**: SystemCapability.FileManagement.PhotoAccessHelper.Core 2550 2551**Return value** 2552 2553| Type | Description | 2554| --------------------------------------- | ----------------- | 2555|Promise<[MediaAssetEditData](#mediaasseteditdata11)> | Promise used to return the edited asset data.| 2556 2557**Error codes** 2558 2559For details about the error codes, see [Universal Error Codes](../errorcode-universal.md) and [File Management Error Codes](../apis-core-file-kit/errorcode-filemanagement.md). 2560 2561| ID| Error Message| 2562| -------- | ---------------------------------------- | 2563| 201 | Permission denied. | 2564| 202 | Called by non-system application. | 2565| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types. | 2566| 14000011 | System inner fail. | 2567 2568**Example** 2569 2570```ts 2571import { dataSharePredicates } from '@kit.ArkData'; 2572 2573async function example() { 2574 try { 2575 console.info('getEditDataDemo') 2576 let predicates: dataSharePredicates.DataSharePredicates = new dataSharePredicates.DataSharePredicates(); 2577 let fetchOptions: photoAccessHelper.FetchOptions = { 2578 fetchColumns: [], 2579 predicates: predicates 2580 }; 2581 let fetchResult: photoAccessHelper.FetchResult<photoAccessHelper.PhotoAsset> = await phAccessHelper.getAssets(fetchOptions); 2582 let photoAsset: photoAccessHelper.PhotoAsset = await fetchResult.getFirstObject(); 2583 let assetEditData: photoAccessHelper.MediaAssetEditData = await photoAsset.getEditData(); 2584 let data: string = assetEditData.data; 2585 console.info('edit data is ' + data); 2586 } catch (err) { 2587 console.error(`getEditDataDemo failed with error: ${err.code}, ${err.message}`); 2588 } 2589} 2590``` 2591 2592### requestSource<sup>11+</sup> 2593 2594requestSource(callback: AsyncCallback<number>): void 2595 2596Opens the source file to obtain the FD. This API uses an asynchronous callback to return the result. 2597 2598**System API**: This is a system API. 2599 2600**Required permissions**: ohos.permission.READ_IMAGEVIDEO 2601 2602**System capability**: SystemCapability.FileManagement.PhotoAccessHelper.Core 2603 2604**Parameters** 2605 2606| Name | Type | Mandatory | Description | 2607| ---------- | ------- | ---- | ---------------------------------- | 2608| callback | AsyncCallback<number> | Yes | Callback used to return the FD.| 2609 2610**Error codes** 2611 2612For details about the error codes, see [Universal Error Codes](../errorcode-universal.md) and [File Management Error Codes](../apis-core-file-kit/errorcode-filemanagement.md). 2613 2614| ID| Error Message| 2615| -------- | ---------------------------------------- | 2616| 201 | Permission denied. | 2617| 202 | Called by non-system application. | 2618| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types. | 2619| 14000011 | System inner fail. | 2620 2621**Example** 2622 2623```ts 2624import { dataSharePredicates } from '@kit.ArkData'; 2625 2626async function example() { 2627 try { 2628 console.info('requsetSourceCallbackDemo') 2629 let predicates: dataSharePredicates.DataSharePredicates = new dataSharePredicates.DataSharePredicates(); 2630 let fetchOptions: photoAccessHelper.FetchOptions = { 2631 fetchColumns: [], 2632 predicates: predicates 2633 }; 2634 let fetchResult: photoAccessHelper.FetchResult<photoAccessHelper.PhotoAsset> = await phAccessHelper.getAssets(fetchOptions); 2635 let photoAsset: photoAccessHelper.PhotoAsset = await fetchResult.getFirstObject(); 2636 photoAsset.requestSource((err, fd) => { 2637 if (err === undefined) { 2638 console.info('Source fd is ' + fd); 2639 } else { 2640 console.error(`requestSource failed with error: ${err.code}, ${err.message}`); 2641 } 2642 }); 2643 } catch (err) { 2644 console.error(`requsetSourceCallbackDemo failed with error: ${err.code}, ${err.message}`); 2645 } 2646} 2647``` 2648 2649### requestSource<sup>11+</sup> 2650 2651requestSource(): Promise<number> 2652 2653Opens the source file to obtain the FD. This API uses a promise to return the result. 2654 2655**System API**: This is a system API. 2656 2657**Required permissions**: ohos.permission.READ_IMAGEVIDEO 2658 2659**System capability**: SystemCapability.FileManagement.PhotoAccessHelper.Core 2660 2661**Return value** 2662 2663| Type | Description | 2664| --------------------------------------- | ----------------- | 2665|Promise<number> | Promise used to return the FD.| 2666 2667**Error codes** 2668 2669For details about the error codes, see [Universal Error Codes](../errorcode-universal.md) and [File Management Error Codes](../apis-core-file-kit/errorcode-filemanagement.md). 2670 2671| ID| Error Message| 2672| -------- | ---------------------------------------- | 2673| 201 | Permission denied. | 2674| 202 | Called by non-system application. | 2675| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types. | 2676| 14000011 | System inner fail. | 2677 2678**Example** 2679 2680```ts 2681import { dataSharePredicates } from '@kit.ArkData'; 2682 2683async function example() { 2684 try { 2685 console.info('requsetSourcePromiseDemo') 2686 let predicates: dataSharePredicates.DataSharePredicates = new dataSharePredicates.DataSharePredicates(); 2687 let fetchOptions: photoAccessHelper.FetchOptions = { 2688 fetchColumns: [], 2689 predicates: predicates 2690 }; 2691 let fetchResult: photoAccessHelper.FetchResult<photoAccessHelper.PhotoAsset> = await phAccessHelper.getAssets(fetchOptions); 2692 let photoAsset: photoAccessHelper.PhotoAsset = await fetchResult.getFirstObject(); 2693 let fd = await photoAsset.requestSource(); 2694 console.info('Source fd is ' + fd); 2695 } catch (err) { 2696 console.error(`requsetSourcePromiseDemo failed with error: ${err.code}, ${err.message}`); 2697 } 2698} 2699``` 2700 2701### commitEditedAsset<sup>11+</sup> 2702 2703commitEditedAsset(editData: string, uri: string, callback: AsyncCallback<void>) 2704 2705Commits the edited image or video asset. This API uses an asynchronous callback to return the result. 2706 2707The 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). 2708 2709**NOTE**<br>The commit operation overwrites the previous edited data. 2710 2711**System API**: This is a system API. 2712 2713**Required permissions**: ohos.permission.WRITE_IMAGEVIDEO 2714 2715**System capability**: SystemCapability.FileManagement.PhotoAccessHelper.Core 2716 2717**Parameters** 2718 2719| Name | Type | Mandatory | Description | 2720| ---------- | ------- | ---- | ---------------------------------- | 2721| editData | string | Yes | New data to commit.| 2722| uri | string | Yes | URI of the committed image or video in the application sandbox.| 2723| callback | AsyncCallback<void> | Yes | Callback that returns no value.| 2724 2725**Error codes** 2726 2727For details about the error codes, see [Universal Error Codes](../errorcode-universal.md) and [File Management Error Codes](../apis-core-file-kit/errorcode-filemanagement.md). 2728 2729| ID| Error Message| 2730| -------- | ---------------------------------------- | 2731| 201 | Permission denied. | 2732| 202 | Called by non-system application. | 2733| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types; 3. Parameter verification failed. | 2734| 14000011 | System inner fail. | 2735 2736**Example** 2737 2738```ts 2739import { dataSharePredicates } from '@kit.ArkData'; 2740 2741async function example() { 2742 try { 2743 console.info('commitEditedAssetCallbackDemo') 2744 let predicates: dataSharePredicates.DataSharePredicates = new dataSharePredicates.DataSharePredicates(); 2745 let fetchOptions: photoAccessHelper.FetchOptions = { 2746 fetchColumns: [], 2747 predicates: predicates 2748 }; 2749 let fetchResult: photoAccessHelper.FetchResult<photoAccessHelper.PhotoAsset> = await phAccessHelper.getAssets(fetchOptions); 2750 let photoAsset: photoAccessHelper.PhotoAsset = await fetchResult.getFirstObject(); 2751 let editData = '123456'; 2752 let uri = 'file://com.example.temptest/data/storage/el2/base/haps/entry/files/test.jpg'; 2753 photoAsset.commitEditedAsset(editData, uri, (err) => { 2754 if (err === undefined) { 2755 console.info('commitEditedAsset is successful'); 2756 } else { 2757 console.error(`commitEditedAsset failed with error: ${err.code}, ${err.message}`); 2758 } 2759 }); 2760 } catch (err) { 2761 console.error(`commitEditedAssetCallbackDemo failed with error: ${err.code}, ${err.message}`); 2762 } 2763} 2764``` 2765 2766### commitEditedAsset<sup>11+</sup> 2767 2768commitEditedAsset(editData: string, uri: string): Promise<void> 2769 2770Commits the edited image or video asset. This API uses a promise to return the result. 2771 2772The 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). 2773 2774**NOTE**<br>The commit operation overwrites the previous edited data. 2775 2776**System API**: This is a system API. 2777 2778**Required permissions**: ohos.permission.WRITE_IMAGEVIDEO 2779 2780**System capability**: SystemCapability.FileManagement.PhotoAccessHelper.Core 2781 2782**Parameters** 2783 2784| Name | Type | Mandatory | Description | 2785| ---------- | ------- | ---- | ---------------------------------- | 2786| editData | string | Yes | New data to commit.| 2787| uri | string | Yes | URI of the committed image or video in the application sandbox.| 2788 2789**Return value** 2790 2791| Type | Description | 2792| --------------------------------------- | ----------------- | 2793|Promise<void> | Promise that returns no value.| 2794 2795**Error codes** 2796 2797For details about the error codes, see [Universal Error Codes](../errorcode-universal.md) and [File Management Error Codes](../apis-core-file-kit/errorcode-filemanagement.md). 2798 2799| ID| Error Message| 2800| -------- | ---------------------------------------- | 2801| 201 | Permission denied. | 2802| 202 | Called by non-system application. | 2803| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types; 3. Parameter verification failed. | 2804| 14000011 | System inner fail. | 2805 2806**Example** 2807 2808```ts 2809import { dataSharePredicates } from '@kit.ArkData'; 2810 2811async function example() { 2812 try { 2813 console.info('commitEditedAssetPromiseDemo') 2814 let predicates: dataSharePredicates.DataSharePredicates = new dataSharePredicates.DataSharePredicates(); 2815 let fetchOptions: photoAccessHelper.FetchOptions = { 2816 fetchColumns: [], 2817 predicates: predicates 2818 }; 2819 let fetchResult: photoAccessHelper.FetchResult<photoAccessHelper.PhotoAsset> = await phAccessHelper.getAssets(fetchOptions); 2820 let photoAsset: photoAccessHelper.PhotoAsset = await fetchResult.getFirstObject(); 2821 let editData = '123456'; 2822 let uri = 'file://com.example.temptest/data/storage/el2/base/haps/entry/files/test.jpg'; 2823 await photoAsset.commitEditedAsset(editData, uri); 2824 console.info('commitEditedAsset is successful'); 2825 } catch (err) { 2826 console.error(`commitEditedAssetPromiseDemo failed with error: ${err.code}, ${err.message}`); 2827 } 2828} 2829``` 2830 2831### revertToOriginal<sup>11+</sup> 2832 2833revertToOriginal(callback: AsyncCallback<void>) 2834 2835Reverts to the state of the file before being edited. This API uses an asynchronous callback to return the result. 2836 2837**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. 2838 2839**System API**: This is a system API. 2840 2841**Required permissions**: ohos.permission.WRITE_IMAGEVIDEO 2842 2843**System capability**: SystemCapability.FileManagement.PhotoAccessHelper.Core 2844 2845**Parameters** 2846 2847| Name | Type | Mandatory | Description | 2848| ---------- | ------- | ---- | ---------------------------------- | 2849| callback | AsyncCallback<void> | Yes | Callback that returns no value.| 2850 2851**Error codes** 2852 2853For details about the error codes, see [Universal Error Codes](../errorcode-universal.md) and [File Management Error Codes](../apis-core-file-kit/errorcode-filemanagement.md). 2854 2855| ID| Error Message| 2856| -------- | ---------------------------------------- | 2857| 201 | Permission denied. | 2858| 202 | Called by non-system application. | 2859| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types. | 2860| 14000011 | System inner fail. | 2861 2862**Example** 2863 2864```ts 2865import { dataSharePredicates } from '@kit.ArkData'; 2866 2867async function example() { 2868 try { 2869 console.info('revertToOriginalCallbackDemo') 2870 let predicates: dataSharePredicates.DataSharePredicates = new dataSharePredicates.DataSharePredicates(); 2871 let fetchOptions: photoAccessHelper.FetchOptions = { 2872 fetchColumns: [], 2873 predicates: predicates 2874 }; 2875 let fetchResult: photoAccessHelper.FetchResult<photoAccessHelper.PhotoAsset> = await phAccessHelper.getAssets(fetchOptions); 2876 let photoAsset: photoAccessHelper.PhotoAsset = await fetchResult.getFirstObject(); 2877 photoAsset.revertToOriginal((err) => { 2878 if (err === undefined) { 2879 console.info('revertToOriginal is successful'); 2880 } else { 2881 console.error(`revertToOriginal failed with error: ${err.code}, ${err.message}`); 2882 } 2883 }); 2884 } catch (err) { 2885 console.error(`revertToOriginalCallbackDemo failed with error: ${err.code}, ${err.message}`); 2886 } 2887} 2888``` 2889 2890### revertToOriginal<sup>11+</sup> 2891 2892revertToOriginal(): Promise<void> 2893 2894Reverts to the state of the file before being edited. This API uses a promise to return the result. 2895 2896**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. 2897 2898**System API**: This is a system API. 2899 2900**Required permissions**: ohos.permission.WRITE_IMAGEVIDEO 2901 2902**System capability**: SystemCapability.FileManagement.PhotoAccessHelper.Core 2903 2904**Return value** 2905 2906| Type | Description | 2907| --------------------------------------- | ----------------- | 2908|Promise<string> | Promise that returns no value.| 2909 2910**Error codes** 2911 2912For details about the error codes, see [Universal Error Codes](../errorcode-universal.md) and [File Management Error Codes](../apis-core-file-kit/errorcode-filemanagement.md). 2913 2914| ID| Error Message| 2915| -------- | ---------------------------------------- | 2916| 201 | Permission denied. | 2917| 202 | Called by non-system application. | 2918| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types. | 2919| 14000011 | System inner fail. | 2920 2921**Example** 2922 2923```ts 2924import { dataSharePredicates } from '@kit.ArkData'; 2925 2926async function example() { 2927 try { 2928 console.info('revertToOriginalPromiseDemo') 2929 let predicates: dataSharePredicates.DataSharePredicates = new dataSharePredicates.DataSharePredicates(); 2930 let fetchOptions: photoAccessHelper.FetchOptions = { 2931 fetchColumns: [], 2932 predicates: predicates 2933 }; 2934 let fetchResult: photoAccessHelper.FetchResult<photoAccessHelper.PhotoAsset> = await phAccessHelper.getAssets(fetchOptions); 2935 let photoAsset: photoAccessHelper.PhotoAsset = await fetchResult.getFirstObject(); 2936 photoAsset.revertToOriginal(); 2937 console.info('revertToOriginal is successful'); 2938 } catch (err) { 2939 console.error(`revertToOriginalPromiseDemo failed with error: ${err.code}, ${err.message}`); 2940 } 2941} 2942``` 2943 2944### requestPhoto<sup>11+</sup> 2945 2946requestPhoto(callback: AsyncCallback<image.PixelMap>): string 2947 2948Obtains the quick thumbnail and quality thumbnail of this asset. This API uses an asynchronous callback to return the result. 2949 2950The 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. 2951 2952**System API**: This is a system API. 2953 2954**Required permissions**: ohos.permission.READ_IMAGEVIDEO 2955 2956**System capability**: SystemCapability.FileManagement.PhotoAccessHelper.Core 2957 2958**Parameters** 2959 2960| Name | Type | Mandatory | Description | 2961| ---------- | ------- | ---- | ---------------------------------- | 2962| callback | AsyncCallback<[image.PixelMap](../apis-image-kit/js-apis-image.md#pixelmap7)> | Yes | Callback invoked twice to return the quick and quality thumbnails obtained.| 2963 2964**Return value** 2965 2966| Type | Description | 2967| --------------------------------------- | ----------------- | 2968| string | ID of the task for obtaining thumbnails.| 2969 2970**Error codes** 2971 2972For details about the error codes, see [Universal Error Codes](../errorcode-universal.md) and [File Management Error Codes](../apis-core-file-kit/errorcode-filemanagement.md). 2973 2974| ID| Error Message| 2975| -------- | ---------------------------------------- | 2976| 201 | Permission verification failed, usually the result returned by VerifyAccessToken. | 2977| 202 | Permission verification failed, application which is not a system application uses system API. | 2978| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types. | 2979| 14000011 | System inner fail. | 2980 2981**Example** 2982 2983```ts 2984import { dataSharePredicates } from '@kit.ArkData'; 2985import { image } from '@kit.ImageKit'; 2986 2987async function example() { 2988 try { 2989 console.info('requestPhotoDemo') 2990 let options: photoAccessHelper.FetchOptions = { 2991 fetchColumns: [], 2992 predicates: new dataSharePredicates.DataSharePredicates() 2993 } 2994 let fetchResult = await phAccessHelper.getAssets(options); 2995 let photoAsset = await fetchResult.getFirstObject(); 2996 let taskId: string = photoAsset.requestPhoto(async (err, pixel: image.PixelMap) => { 2997 if (err === undefined) { 2998 console.info("requestSource in, size: " + JSON.stringify((await pixel.getImageInfo()).size)) 2999 } else { 3000 console.error(`requestSource failed with error: ${err.code}, ${err.message}`); 3001 } 3002 }) 3003 console.info('requestSource taskId: ' + taskId) 3004 } catch (err) { 3005 console.error(`requestPhotoDemo failed with error: ${err.code}, ${err.message}`); 3006 } 3007} 3008``` 3009 3010### requestPhoto<sup>11+</sup> 3011 3012requestPhoto(options: RequestPhotoOptions, callback: AsyncCallback<image.PixelMap>): string 3013 3014Obtains the thumbnails of an asset based on the specified options. This API uses an asynchronous callback to return the result. 3015 3016**System API**: This is a system API. 3017 3018**Required permissions**: ohos.permission.READ_IMAGEVIDEO 3019 3020**System capability**: SystemCapability.FileManagement.PhotoAccessHelper.Core 3021 3022**Parameters** 3023 3024| Name | Type | Mandatory | Description | 3025| ---------- | ------- | ---- | ---------------------------------- | 3026| options | [RequestPhotoOptions](#requestphotooptions11) | Yes | Options for obtaining the asset thumbnail.| 3027| callback | AsyncCallback<[image.PixelMap](../apis-image-kit/js-apis-image.md#pixelmap7)> | Yes | Callback used to return the thumbnails obtained. The callback may be invoked more than once, depending on **options**.| 3028 3029**Return value** 3030 3031| Type | Description | 3032| --------------------------------------- | ----------------- | 3033| string | ID of the task for obtaining thumbnails.| 3034 3035**Error codes** 3036 3037For details about the error codes, see [Universal Error Codes](../errorcode-universal.md) and [File Management Error Codes](../apis-core-file-kit/errorcode-filemanagement.md). 3038 3039| ID| Error Message| 3040| -------- | ---------------------------------------- | 3041| 201 | Permission verification failed, usually the result returned by VerifyAccessToken. | 3042| 202 | Permission verification failed, application which is not a system application uses system API. | 3043| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types; 3. Parameter verification failed. | 3044| 14000011 | System inner fail. | 3045 3046**Example** 3047 3048```ts 3049import { dataSharePredicates } from '@kit.ArkData'; 3050import { image } from '@kit.ImageKit'; 3051 3052async function example() { 3053 try { 3054 console.info('requestPhotoDemo') 3055 let options: photoAccessHelper.FetchOptions = { 3056 fetchColumns: [], 3057 predicates: new dataSharePredicates.DataSharePredicates() 3058 } 3059 let fetchResult = await phAccessHelper.getAssets(options); 3060 let photoAsset = await fetchResult.getFirstObject(); 3061 let taskId: string = photoAsset.requestPhoto({ 3062 "size": { 3063 "width": 256, 3064 "height": 256 3065 }, 3066 "requestPhotoType": photoAccessHelper.RequestPhotoType.REQUEST_ALL_THUMBNAILS 3067 }, async (err, pixel: image.PixelMap) => { 3068 if (err === undefined) { 3069 console.info("requestSource in, size: " + JSON.stringify((await pixel.getImageInfo()).size)) 3070 } else { 3071 console.error(`requestSource failed with error: ${err.code}, ${err.message}`); 3072 } 3073 }) 3074 console.info('requestSource taskId: ' + taskId) 3075 } catch (err) { 3076 console.error(`requestPhotoDemo failed with error: ${err.code}, ${err.message}`); 3077 } 3078} 3079``` 3080 3081### cancelPhotoRequest<sup>11+</sup> 3082 3083cancelPhotoRequest(requestId: string): void 3084 3085Cancels a task for obtaining media thumbnails. 3086 3087**System API**: This is a system API. 3088 3089**Required permissions**: ohos.permission.READ_IMAGEVIDEO 3090 3091**System capability**: SystemCapability.FileManagement.PhotoAccessHelper.Core 3092 3093**Parameters** 3094 3095| Name | Type | Mandatory | Description | 3096| ---------- | ------- | ---- | ---------------------------------- | 3097| requestId | string | Yes | ID of the task to cancel.| 3098 3099**Error codes** 3100 3101For details about the error codes, see [Universal Error Codes](../errorcode-universal.md) and [File Management Error Codes](../apis-core-file-kit/errorcode-filemanagement.md). 3102 3103| ID| Error Message| 3104| -------- | ---------------------------------------- | 3105| 201 | Permission verification failed, usually the result returned by VerifyAccessToken. | 3106| 202 | Permission verification failed, application which is not a system application uses system API. | 3107| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types; 3. Parameter verification failed. | 3108| 14000011 | System inner fail. | 3109 3110**Example** 3111 3112```ts 3113import { dataSharePredicates } from '@kit.ArkData'; 3114import { image } from '@kit.ImageKit'; 3115 3116async function example() { 3117 try { 3118 console.info('cancelPhotoRequestDemo') 3119 let options: photoAccessHelper.FetchOptions = { 3120 fetchColumns: [], 3121 predicates: new dataSharePredicates.DataSharePredicates() 3122 } 3123 let fetchResult = await phAccessHelper.getAssets(options); 3124 let photoAsset = await fetchResult.getFirstObject(); 3125 let taskId: string = photoAsset.requestPhoto({ 3126 "size": { 3127 "width": 256, 3128 "height": 256 3129 }, 3130 "requestPhotoType": photoAccessHelper.RequestPhotoType.REQUEST_ALL_THUMBNAILS 3131 }, async (err, pixel: image.PixelMap) => { 3132 if (err === undefined) { 3133 console.info("requestSource in, size: " + JSON.stringify((await pixel.getImageInfo()).size)) 3134 } else { 3135 console.error(`requestSource failed with error: ${err.code}, ${err.message}`); 3136 } 3137 }) 3138 console.info('requestSource taskId: ' + taskId) 3139 photoAsset.cancelPhotoRequest(taskId); 3140 } catch (err) { 3141 console.error(`cancelPhotoRequestDemo failed with error: ${err.code}, ${err.message}`); 3142 } 3143} 3144``` 3145 3146### getAnalysisData<sup>11+</sup> 3147 3148getAnalysisData(analysisType: AnalysisType): Promise\<string> 3149 3150Obtains analysis data. This API uses a promise to return the result. 3151 3152**System API**: This is a system API. 3153 3154**Required permissions**: ohos.permission.READ\_IMAGEVIDEO 3155 3156**System capability**: SystemCapability.FileManagement.PhotoAccessHelper.Core 3157 3158**Parameters** 3159 3160| Name | Type | Mandatory| Description | 3161| :----------- | :----------- | :- | :----------- | 3162| analysisType | [AnalysisType](#analysistype11) | Yes | Smart analysis type.| 3163 3164**Error codes** 3165 3166For details about the error codes, see [Universal Error Codes](../errorcode-universal.md) and [File Management Error Codes](../apis-core-file-kit/errorcode-filemanagement.md). 3167 3168| ID | Error Message | 3169| :------- | :-------------------------------- | 3170| 201 | Permission denied. | 3171| 202 | Called by non-system application. | 3172| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types; 3. Parameter verification failed. | 3173| 14000011 | System inner fail. | 3174 3175**Example** 3176 3177```ts 3178import { dataSharePredicates } from '@kit.ArkData'; 3179 3180async function example() { 3181 try { 3182 console.info('getAnalysisDataDemo') 3183 let fetchOptions: photoAccessHelper.FetchOptions = { 3184 fetchColumns: [], 3185 predicates: new dataSharePredicates.DataSharePredicates() 3186 } 3187 let fetchResult: photoAccessHelper.FetchResult<photoAccessHelper.PhotoAsset> = 3188 await phAccessHelper.getAssets(fetchOptions); 3189 let photoAsset: photoAccessHelper.PhotoAsset = await fetchResult.getFirstObject(); 3190 if (photoAsset != undefined) { 3191 let analysisData: string = await photoAsset.getAnalysisData( 3192 photoAccessHelper.AnalysisType.ANALYSIS_OCR); 3193 console.info('get ocr result: ' + JSON.stringify(analysisData)); 3194 } 3195 fetchResult.close(); 3196 } catch (err) { 3197 console.error(`getAnalysisDataDemofailed with error: ${err.code}, ${err.message}`); 3198 } 3199} 3200``` 3201 3202## Album 3203 3204Provides APIs to manage albums. 3205 3206### recoverAssets<sup>(deprecated)</sup> 3207 3208recoverAssets(assets: Array<PhotoAsset>, callback: AsyncCallback<void>): void 3209 3210Recovers 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. 3211 3212> **NOTE** 3213> 3214> This API is supported since API version 10 and deprecated since API version 11. Use [MediaAlbumChangeRequest.recoverAssets](#recoverassets11) instead. 3215 3216**System API**: This is a system API. 3217 3218**Required permissions**: ohos.permission.WRITE_IMAGEVIDEO 3219 3220**System capability**: SystemCapability.FileManagement.PhotoAccessHelper.Core 3221 3222**Parameters** 3223 3224| Name | Type | Mandatory| Description | 3225| -------- | ------------------------- | ---- | ---------- | 3226| assets | Array<[PhotoAsset](#photoasset)> | Yes | Array of the image or video assets to recover.| 3227| callback | AsyncCallback<void> | Yes | Callback that returns no value.| 3228 3229**Error codes** 3230 3231For details about the error codes, see [Universal Error Codes](../errorcode-universal.md) and [File Management Error Codes](../apis-core-file-kit/errorcode-filemanagement.md). 3232 3233| ID| Error Message| 3234| -------- | ---------------------------------------- | 3235| 202 | Called by non-system application. | 3236| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types; 3. Parameter verification failed. | 3237| 13900012 | Permission denied. | 3238| 13900020 | Invalid argument. | 3239| 14000011 | System inner fail. | 3240 3241**Example** 3242 3243```ts 3244import { dataSharePredicates } from '@kit.ArkData'; 3245 3246async function example() { 3247 try { 3248 console.info('recoverAssetsDemoCallback'); 3249 let predicates: dataSharePredicates.DataSharePredicates = new dataSharePredicates.DataSharePredicates(); 3250 let fetchOption: photoAccessHelper.FetchOptions = { 3251 fetchColumns: [], 3252 predicates: predicates 3253 }; 3254 let albumFetchResult: photoAccessHelper.FetchResult<photoAccessHelper.Album> = await phAccessHelper.getAlbums(photoAccessHelper.AlbumType.SYSTEM, photoAccessHelper.AlbumSubtype.TRASH); 3255 let album: photoAccessHelper.Album = await albumFetchResult.getFirstObject(); 3256 let fetchResult: photoAccessHelper.FetchResult<photoAccessHelper.PhotoAsset> = await album.getAssets(fetchOption); 3257 let asset: photoAccessHelper.PhotoAsset = await fetchResult.getFirstObject(); 3258 album.recoverAssets([asset], (err) => { 3259 if (err === undefined) { 3260 console.info('album recoverAssets successfully'); 3261 } else { 3262 console.error(`album recoverAssets failed with error: ${err.code}, ${err.message}`); 3263 } 3264 }); 3265 } catch (err) { 3266 console.error(`recoverAssetsDemoCallback failed with error: ${err.code}, ${err.message}`); 3267 } 3268} 3269``` 3270 3271### recoverAssets<sup>(deprecated)</sup> 3272 3273recoverAssets(assets: Array<PhotoAsset>): Promise<void> 3274 3275Recovers 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. 3276 3277> **NOTE** 3278> 3279> This API is supported since API version 10 and deprecated since API version 11. Use [MediaAlbumChangeRequest.recoverAssets](#recoverassets11) instead. 3280 3281**System API**: This is a system API. 3282 3283**Required permissions**: ohos.permission.WRITE_IMAGEVIDEO 3284 3285**System capability**: SystemCapability.FileManagement.PhotoAccessHelper.Core 3286 3287**Parameters** 3288 3289| Name | Type | Mandatory| Description | 3290| -------- | ------------------------- | ---- | ---------- | 3291| assets | Array<[PhotoAsset](#photoasset)> | Yes | Array of the image or video assets to recover.| 3292 3293**Return value** 3294 3295| Type | Description | 3296| --------------------------------------- | ----------------- | 3297|Promise<void> | Promise that returns no value.| 3298 3299**Error codes** 3300 3301For details about the error codes, see [Universal Error Codes](../errorcode-universal.md) and [File Management Error Codes](../apis-core-file-kit/errorcode-filemanagement.md). 3302 3303| ID| Error Message| 3304| -------- | ---------------------------------------- | 3305| 202 | Called by non-system application. | 3306| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types; 3. Parameter verification failed. | 3307| 13900012 | Permission denied. | 3308| 13900020 | Invalid argument. | 3309| 14000011 | System inner fail. | 3310 3311**Example** 3312 3313```ts 3314import { dataSharePredicates } from '@kit.ArkData'; 3315import { BusinessError } from '@kit.BasicServicesKit'; 3316 3317async function example() { 3318 try { 3319 console.info('recoverAssetsDemoPromise'); 3320 let predicates: dataSharePredicates.DataSharePredicates = new dataSharePredicates.DataSharePredicates(); 3321 let fetchOption: photoAccessHelper.FetchOptions = { 3322 fetchColumns: [], 3323 predicates: predicates 3324 }; 3325 let albumFetchResult: photoAccessHelper.FetchResult<photoAccessHelper.Album> = await phAccessHelper.getAlbums(photoAccessHelper.AlbumType.SYSTEM, photoAccessHelper.AlbumSubtype.TRASH); 3326 let album: photoAccessHelper.Album = await albumFetchResult.getFirstObject(); 3327 let fetchResult: photoAccessHelper.FetchResult<photoAccessHelper.PhotoAsset> = await album.getAssets(fetchOption); 3328 let asset: photoAccessHelper.PhotoAsset = await fetchResult.getFirstObject(); 3329 album.recoverAssets([asset]).then(() => { 3330 console.info('album recoverAssets successfully'); 3331 }).catch((err: BusinessError) => { 3332 console.error(`album recoverAssets failed with error: ${err.code}, ${err.message}`); 3333 }); 3334 } catch (err) { 3335 console.error(`recoverAssetsDemoPromise failed with error: ${err.code}, ${err.message}`); 3336 } 3337} 3338``` 3339 3340### deleteAssets<sup>(deprecated)</sup> 3341 3342deleteAssets(assets: Array<PhotoAsset>, callback: AsyncCallback<void>): void 3343 3344Deletes 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. 3345 3346> **NOTE** 3347> 3348> This API is supported since API version 10 and deprecated since API version 11. Use [MediaAlbumChangeRequest.deleteAssets](#deleteassets11) instead. 3349 3350**NOTE**<br>This operation is irreversible. The file assets deleted cannot be restored. Exercise caution when performing this operation. 3351 3352**System API**: This is a system API. 3353 3354**Required permissions**: ohos.permission.WRITE_IMAGEVIDEO 3355 3356**System capability**: SystemCapability.FileManagement.PhotoAccessHelper.Core 3357 3358**Parameters** 3359 3360| Name | Type | Mandatory| Description | 3361| -------- | ------------------------- | ---- | ---------- | 3362| assets | Array<[PhotoAsset](#photoasset)> | Yes | Array of the image or video assets to delete.| 3363| callback | AsyncCallback<void> | Yes | Callback that returns no value.| 3364 3365**Error codes** 3366 3367For details about the error codes, see [Universal Error Codes](../errorcode-universal.md) and [File Management Error Codes](../apis-core-file-kit/errorcode-filemanagement.md). 3368 3369| ID| Error Message| 3370| -------- | ---------------------------------------- | 3371| 202 | Called by non-system application. | 3372| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types; 3. Parameter verification failed. | 3373| 13900012 | Permission denied. | 3374| 13900020 | Invalid argument. | 3375| 14000011 | System inner fail. | 3376 3377**Example** 3378 3379```ts 3380import { dataSharePredicates } from '@kit.ArkData'; 3381 3382async function example() { 3383 try { 3384 console.info('deleteAssetsDemoCallback'); 3385 let predicates: dataSharePredicates.DataSharePredicates = new dataSharePredicates.DataSharePredicates(); 3386 let fetchOption: photoAccessHelper.FetchOptions = { 3387 fetchColumns: [], 3388 predicates: predicates 3389 }; 3390 let albumFetchResult: photoAccessHelper.FetchResult<photoAccessHelper.Album> = await phAccessHelper.getAlbums(photoAccessHelper.AlbumType.SYSTEM, photoAccessHelper.AlbumSubtype.TRASH); 3391 let album: photoAccessHelper.Album = await albumFetchResult.getFirstObject(); 3392 let fetchResult: photoAccessHelper.FetchResult<photoAccessHelper.PhotoAsset> = await album.getAssets(fetchOption); 3393 let asset: photoAccessHelper.PhotoAsset = await fetchResult.getFirstObject(); 3394 album.deleteAssets([asset], (err) => { 3395 if (err === undefined) { 3396 console.info('album deleteAssets successfully'); 3397 } else { 3398 console.error(`album deleteAssets failed with error: ${err.code}, ${err.message}`); 3399 } 3400 }); 3401 } catch (err) { 3402 console.error(`deleteAssetsDemoCallback failed with error: ${err.code}, ${err.message}`); 3403 } 3404} 3405``` 3406 3407### deleteAssets<sup>(deprecated)</sup> 3408 3409deleteAssets(assets: Array<PhotoAsset>): Promise<void> 3410 3411Deletes 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. 3412 3413> **NOTE** 3414> 3415> This API is supported since API version 10 and deprecated since API version 11. Use [MediaAlbumChangeRequest.deleteAssets](#deleteassets11) instead. 3416 3417**NOTE**<br>This operation is irreversible. The file assets deleted cannot be restored. Exercise caution when performing this operation. 3418 3419**System API**: This is a system API. 3420 3421**Required permissions**: ohos.permission.WRITE_IMAGEVIDEO 3422 3423**System capability**: SystemCapability.FileManagement.PhotoAccessHelper.Core 3424 3425**Parameters** 3426 3427| Name | Type | Mandatory| Description | 3428| -------- | ------------------------- | ---- | ---------- | 3429| assets | Array<[PhotoAsset](#photoasset)> | Yes | Array of the image or video assets to delete.| 3430 3431**Return value** 3432 3433| Type | Description | 3434| --------------------------------------- | ----------------- | 3435|Promise<void> | Promise that returns no value.| 3436 3437**Error codes** 3438 3439For details about the error codes, see [Universal Error Codes](../errorcode-universal.md) and [File Management Error Codes](../apis-core-file-kit/errorcode-filemanagement.md). 3440 3441| ID| Error Message| 3442| -------- | ---------------------------------------- | 3443| 202 | Called by non-system application. | 3444| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types; 3. Parameter verification failed. | 3445| 13900012 | Permission denied. | 3446| 13900020 | Invalid argument. | 3447| 14000011 | System inner fail. | 3448 3449**Example** 3450 3451```ts 3452import { dataSharePredicates } from '@kit.ArkData'; 3453import { BusinessError } from '@kit.BasicServicesKit'; 3454 3455async function example() { 3456 try { 3457 console.info('deleteAssetsDemoPromise'); 3458 let predicates: dataSharePredicates.DataSharePredicates = new dataSharePredicates.DataSharePredicates(); 3459 let fetchOption: photoAccessHelper.FetchOptions = { 3460 fetchColumns: [], 3461 predicates: predicates 3462 }; 3463 let albumFetchResult: photoAccessHelper.FetchResult<photoAccessHelper.Album> = await phAccessHelper.getAlbums(photoAccessHelper.AlbumType.SYSTEM, photoAccessHelper.AlbumSubtype.TRASH); 3464 let album: photoAccessHelper.Album = await albumFetchResult.getFirstObject(); 3465 let fetchResult: photoAccessHelper.FetchResult<photoAccessHelper.PhotoAsset> = await album.getAssets(fetchOption); 3466 let asset: photoAccessHelper.PhotoAsset = await fetchResult.getFirstObject(); 3467 album.deleteAssets([asset]).then(() => { 3468 console.info('album deleteAssets successfully'); 3469 }).catch((err: BusinessError) => { 3470 console.error(`album deleteAssets failed with error: ${err.code}, ${err.message}`); 3471 }); 3472 } catch (err) { 3473 console.error(`deleteAssetsDemoPromise failed with error: ${err.code}, ${err.message}`); 3474 } 3475} 3476``` 3477 3478### setCoverUri<sup>(deprecated)</sup> 3479 3480setCoverUri(uri: string, callback: AsyncCallback<void>): void 3481 3482Sets the album cover. This API uses an asynchronous callback to return the result. 3483 3484> **NOTE** 3485> 3486> This API is supported since API version 10 and deprecated since API version 11. Use [MediaAlbumChangeRequest.setCoverUri](#setcoveruri11) instead. 3487 3488**NOTE**<br>This API can be used to set the user album cover, but not the system album cover. 3489 3490**System API**: This is a system API. 3491 3492**Required permissions**: ohos.permission.WRITE_IMAGEVIDEO 3493 3494**System capability**: SystemCapability.FileManagement.PhotoAccessHelper.Core 3495 3496**Parameters** 3497 3498| Name | Type | Mandatory| Description | 3499| -------- | ------------------------- | ---- | ---------- | 3500| uri | string | Yes | URI of the file to be set as the album cover.| 3501| callback | AsyncCallback<void> | Yes | Callback that returns no value.| 3502 3503**Error codes** 3504 3505For details about the error codes, see [Universal Error Codes](../errorcode-universal.md) and [File Management Error Codes](../apis-core-file-kit/errorcode-filemanagement.md). 3506 3507| ID| Error Message| 3508| -------- | ---------------------------------------- | 3509| 202 | Called by non-system application. | 3510| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types; 3. Parameter verification failed. | 3511| 13900012 | Permission denied. | 3512| 13900020 | Invalid argument. | 3513| 14000011 | System inner fail. | 3514 3515**Example** 3516 3517```ts 3518import { dataSharePredicates } from '@kit.ArkData'; 3519 3520async function example() { 3521 try { 3522 console.info('setCoverUriDemoCallback'); 3523 let predicates: dataSharePredicates.DataSharePredicates = new dataSharePredicates.DataSharePredicates(); 3524 let fetchOption: photoAccessHelper.FetchOptions = { 3525 fetchColumns: [], 3526 predicates: predicates 3527 }; 3528 let albumFetchResult: photoAccessHelper.FetchResult<photoAccessHelper.Album> = await phAccessHelper.getAlbums(photoAccessHelper.AlbumType.USER, photoAccessHelper.AlbumSubtype.USER_GENERIC); 3529 let album: photoAccessHelper.Album = await albumFetchResult.getFirstObject(); 3530 let fetchResult: photoAccessHelper.FetchResult<photoAccessHelper.PhotoAsset> = await album.getAssets(fetchOption); 3531 let asset: photoAccessHelper.PhotoAsset = await fetchResult.getFirstObject(); 3532 album.setCoverUri(asset.uri, (err) => { 3533 if (err === undefined) { 3534 console.info('album setCoverUri successfully'); 3535 } else { 3536 console.error(`album setCoverUri failed with error: ${err.code}, ${err.message}`); 3537 } 3538 }); 3539 } catch (err) { 3540 console.error(`setCoverUriDemoCallback failed with error: ${err.code}, ${err.message}`); 3541 } 3542} 3543``` 3544 3545### setCoverUri<sup>(deprecated)</sup> 3546 3547setCoverUri(uri: string): Promise<void> 3548 3549Sets the album cover. This API uses a promise to return the result. 3550 3551> **NOTE** 3552> 3553> This API is supported since API version 10 and deprecated since API version 11. Use [MediaAlbumChangeRequest.setCoverUri](#setcoveruri11) instead. 3554 3555**NOTE**<br>This API can be used to set the user album cover, but not the system album cover. 3556 3557**System API**: This is a system API. 3558 3559**Required permissions**: ohos.permission.WRITE_IMAGEVIDEO 3560 3561**System capability**: SystemCapability.FileManagement.PhotoAccessHelper.Core 3562 3563**Parameters** 3564 3565| Name | Type | Mandatory| Description | 3566| -------- | ------------------------- | ---- | ---------- | 3567| uri | string | Yes | URI of the file to be set as the album cover.| 3568 3569**Return value** 3570 3571| Type | Description | 3572| --------------------------------------- | ----------------- | 3573|Promise<void> | Promise that returns no value.| 3574 3575**Error codes** 3576 3577For details about the error codes, see [Universal Error Codes](../errorcode-universal.md) and [File Management Error Codes](../apis-core-file-kit/errorcode-filemanagement.md). 3578 3579| ID| Error Message| 3580| -------- | ---------------------------------------- | 3581| 202 | Called by non-system application. | 3582| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types; 3. Parameter verification failed. | 3583| 13900012 | Permission denied. | 3584| 13900020 | Invalid argument. | 3585| 14000011 | System inner fail. | 3586**Example** 3587 3588```ts 3589import { dataSharePredicates } from '@kit.ArkData'; 3590import { BusinessError } from '@kit.BasicServicesKit'; 3591 3592async function example() { 3593 try { 3594 console.info('setCoverUriDemoPromise'); 3595 let predicates: dataSharePredicates.DataSharePredicates = new dataSharePredicates.DataSharePredicates(); 3596 let fetchOption: photoAccessHelper.FetchOptions = { 3597 fetchColumns: [], 3598 predicates: predicates 3599 }; 3600 let albumFetchResult: photoAccessHelper.FetchResult<photoAccessHelper.Album> = await phAccessHelper.getAlbums(photoAccessHelper.AlbumType.USER, photoAccessHelper.AlbumSubtype.USER_GENERIC); 3601 let album: photoAccessHelper.Album = await albumFetchResult.getFirstObject(); 3602 let fetchResult: photoAccessHelper.FetchResult<photoAccessHelper.PhotoAsset> = await album.getAssets(fetchOption); 3603 let asset: photoAccessHelper.PhotoAsset = await fetchResult.getFirstObject(); 3604 album.setCoverUri(asset.uri).then(() => { 3605 console.info('album setCoverUri successfully'); 3606 }).catch((err: BusinessError) => { 3607 console.error(`album setCoverUri failed with error: ${err.code}, ${err.message}`); 3608 }); 3609 } catch (err) { 3610 console.error(`setCoverUriDemoPromise failed with error: ${err.code}, ${err.message}`); 3611 } 3612} 3613``` 3614 3615## MediaAssetEditData<sup>11+</sup> 3616 3617Represents the edited media asset data. 3618 3619**System API**: This is a system API. 3620 3621**System capability**: SystemCapability.FileManagement.PhotoAccessHelper.Core 3622 3623### Properties 3624 3625| Name | Type | Readable | Writable | Description | 3626| ------------ | ------ | ---- | ---- | ------- | 3627| compatibleFormat | string | Yes | Yes | Format of the edited data.<br>**System API**: This is a system API. | 3628| formatVersion | string | Yes | Yes | Version of the data format.<br>**System API**: This is a system API. | 3629| data | string | Yes | Yes | Content edited.<br>**System API**: This is a system API. | 3630 3631### constructor<sup>11+</sup> 3632 3633constructor(compatibleFormat: string, formatVersion: string) 3634 3635Constructor. 3636 3637**System API**: This is a system API. 3638 3639**System capability**: SystemCapability.FileManagement.PhotoAccessHelper.Core 3640 3641**Parameters** 3642 3643| Name | Type | Mandatory| Description | 3644| -------- | ------------------------- | ---- | ---------- | 3645| compatibleFormat | string | Yes | Format of the edited data.| 3646| formatVersion | string | Yes | Version of the data format.| 3647 3648**Error codes** 3649 3650For details about the error codes, see [Universal Error Codes](../errorcode-universal.md) and [File Management Error Codes](../apis-core-file-kit/errorcode-filemanagement.md). 3651 3652| ID| Error Message| 3653| -------- | ---------------------------------------- | 3654| 202 | Called by non-system application. | 3655| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types; 3. Parameter verification failed. | 3656| 14000011 | System inner fail. | 3657 3658**Example** 3659 3660```ts 3661let assetEditData: photoAccessHelper.MediaAssetEditData = new photoAccessHelper.MediaAssetEditData('system', '1.0'); 3662``` 3663 3664## MediaAssetChangeRequest<sup>11+</sup> 3665 3666Represents a media asset change request. 3667 3668**System capability**: SystemCapability.FileManagement.PhotoAccessHelper.Core 3669 3670### createAssetRequest<sup>11+</sup> 3671 3672static createAssetRequest(context: Context, displayName: string, options?: PhotoCreateOptions): MediaAssetChangeRequest 3673 3674Creates an asset change request with the specified file name. 3675 3676The file name must comply with the following specifications: 3677- The file name consists of a valid file name and an image or video file name extension. 3678- The file name cannot exceed 255 characters. 3679- The file name cannot contain any of the following characters:<br>. .. \ / : * ? " ' ` < > | { } [ ] 3680 3681**System API**: This is a system API. 3682 3683**System capability**: SystemCapability.FileManagement.PhotoAccessHelper.Core 3684 3685**Parameters** 3686 3687| Name | Type | Mandatory| Description | 3688| ------- | ------- | ---- | -------------------------- | 3689| context | [Context](../apis-ability-kit/js-apis-inner-application-context.md) | Yes | Context of the ability instance.| 3690| displayName | string | Yes | File name of the image or video to create. | 3691| options | [PhotoCreateOptions](#photocreateoptions) | No | Options for creating an image or video asset. | 3692 3693**Return value** 3694 3695| Type | Description | 3696| --------------------------------------- | ----------------- | 3697| [MediaAssetChangeRequest](#mediaassetchangerequest11) | **MediaAssetChangeRequest** created.| 3698 3699**Error codes** 3700 3701For details about the error codes, see [Universal Error Codes](../errorcode-universal.md) and [File Management Error Codes](../apis-core-file-kit/errorcode-filemanagement.md). 3702 3703| ID| Error Message| 3704| -------- | ---------------------------------------- | 3705| 202 | Called by non-system application. | 3706| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types; 3. Parameter verification failed. | 3707| 14000001 | Invalid display name. | 3708| 14000011 | System inner fail. | 3709 3710**Example** 3711 3712```ts 3713async function example() { 3714 console.info('createAssetRequestDemo'); 3715 try { 3716 let testFileName: string = 'testFile' + Date.now() + '.jpg'; 3717 let assetChangeRequest: photoAccessHelper.MediaAssetChangeRequest = photoAccessHelper.MediaAssetChangeRequest.createAssetRequest(context, testFileName); 3718 // Ensure that the asset specified by fileUri exists. 3719 let fileUri = 'file://com.example.temptest/data/storage/el2/base/haps/entry/files/test.jpg'; 3720 assetChangeRequest.addResource(photoAccessHelper.ResourceType.IMAGE_RESOURCE, fileUri); 3721 await phAccessHelper.applyChanges(assetChangeRequest); 3722 console.info('apply createAssetRequest successfully'); 3723 } catch (err) { 3724 console.error(`createAssetRequestDemo failed with error: ${err.code}, ${err.message}`); 3725 } 3726} 3727``` 3728 3729### setFavorite<sup>11+</sup> 3730 3731setFavorite(favoriteState: boolean): void 3732 3733Favorites or unfavorites this file. 3734 3735**System API**: This is a system API. 3736 3737**System capability**: SystemCapability.FileManagement.PhotoAccessHelper.Core 3738 3739**Parameters** 3740 3741| Name | Type | Mandatory | Description | 3742| ---------- | ------- | ---- | ---------------------------------- | 3743| favoriteState | boolean | Yes | Operation to perform. The value **true** means to favorite the file, and **false** means the opposite.| 3744 3745**Error codes** 3746 3747For details about the error codes, see [Universal Error Codes](../errorcode-universal.md) and [File Management Error Codes](../apis-core-file-kit/errorcode-filemanagement.md). 3748 3749| ID| Error Message| 3750| -------- | ---------------------------------------- | 3751| 202 | Called by non-system application. | 3752| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types; 3. Parameter verification failed. | 3753| 14000011 | System inner fail. | 3754 3755**Example** 3756 3757```ts 3758import { dataSharePredicates } from '@kit.ArkData'; 3759import { BusinessError } from '@kit.BasicServicesKit'; 3760 3761async function example() { 3762 console.info('setFavoriteDemo'); 3763 let predicates: dataSharePredicates.DataSharePredicates = new dataSharePredicates.DataSharePredicates(); 3764 let fetchOption: photoAccessHelper.FetchOptions = { 3765 fetchColumns: [], 3766 predicates: predicates 3767 }; 3768 let fetchResult: photoAccessHelper.FetchResult<photoAccessHelper.PhotoAsset> = await phAccessHelper.getAssets(fetchOption); 3769 let asset = await fetchResult.getFirstObject(); 3770 let assetChangeRequest: photoAccessHelper.MediaAssetChangeRequest = new photoAccessHelper.MediaAssetChangeRequest(asset); 3771 assetChangeRequest.setFavorite(true); 3772 phAccessHelper.applyChanges(assetChangeRequest).then(() => { 3773 console.info('apply setFavorite successfully'); 3774 }).catch((err: BusinessError) => { 3775 console.error(`apply setFavorite failed with error: ${err.code}, ${err.message}`); 3776 }); 3777} 3778``` 3779 3780### setHidden<sup>11+</sup> 3781 3782setHidden(hiddenState: boolean): void 3783 3784Hides this file. 3785 3786**System API**: This is a system API. 3787 3788**System capability**: SystemCapability.FileManagement.PhotoAccessHelper.Core 3789 3790**Parameters** 3791 3792| Name | Type | Mandatory | Description | 3793| ---------- | ------- | ---- | ---------------------------------- | 3794| hiddenState | boolean | Yes | Whether to hide the file. The value **true** means to hide the file; the value **false** means the opposite.| 3795 3796**Error codes** 3797 3798For details about the error codes, see [Universal Error Codes](../errorcode-universal.md) and [File Management Error Codes](../apis-core-file-kit/errorcode-filemanagement.md). 3799 3800| ID| Error Message| 3801| -------- | ---------------------------------------- | 3802| 202 | Called by non-system application. | 3803| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types; 3. Parameter verification failed. | 3804| 14000011 | System inner fail. | 3805 3806**Example** 3807 3808```ts 3809import { dataSharePredicates } from '@kit.ArkData'; 3810import { BusinessError } from '@kit.BasicServicesKit'; 3811 3812async function example() { 3813 console.info('setHiddenDemo'); 3814 let predicates: dataSharePredicates.DataSharePredicates = new dataSharePredicates.DataSharePredicates(); 3815 let fetchOption: photoAccessHelper.FetchOptions = { 3816 fetchColumns: [], 3817 predicates: predicates 3818 }; 3819 let fetchResult: photoAccessHelper.FetchResult<photoAccessHelper.PhotoAsset> = await phAccessHelper.getAssets(fetchOption); 3820 let asset = await fetchResult.getFirstObject(); 3821 let assetChangeRequest: photoAccessHelper.MediaAssetChangeRequest = new photoAccessHelper.MediaAssetChangeRequest(asset); 3822 assetChangeRequest.setHidden(true); 3823 phAccessHelper.applyChanges(assetChangeRequest).then(() => { 3824 console.info('apply setHidden successfully'); 3825 }).catch((err: BusinessError) => { 3826 console.error(`apply setHidden failed with error: ${err.code}, ${err.message}`); 3827 }); 3828} 3829``` 3830 3831### setUserComment<sup>11+</sup> 3832 3833setUserComment(userComment: string): void 3834 3835Sets the user comment information of this media asset. 3836 3837**System API**: This is a system API. 3838 3839**System capability**: SystemCapability.FileManagement.PhotoAccessHelper.Core 3840 3841**Parameters** 3842 3843| Name | Type | Mandatory | Description | 3844| ---------- | ------- | ---- | ---------------------------------- | 3845| userComment | string | Yes | Comment information to set, which cannot exceed 420 characters.| 3846 3847**Error codes** 3848 3849For details about the error codes, see [Universal Error Codes](../errorcode-universal.md) and [File Management Error Codes](../apis-core-file-kit/errorcode-filemanagement.md). 3850 3851| ID| Error Message| 3852| -------- | ---------------------------------------- | 3853| 202 | Called by non-system application. | 3854| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types; 3. Parameter verification failed. | 3855| 14000011 | System inner fail. | 3856 3857**Example** 3858 3859```ts 3860import { dataSharePredicates } from '@kit.ArkData'; 3861import { BusinessError } from '@kit.BasicServicesKit'; 3862 3863async function example() { 3864 console.info('setUserCommentDemo'); 3865 let predicates: dataSharePredicates.DataSharePredicates = new dataSharePredicates.DataSharePredicates(); 3866 let fetchOption: photoAccessHelper.FetchOptions = { 3867 fetchColumns: [], 3868 predicates: predicates 3869 }; 3870 let fetchResult: photoAccessHelper.FetchResult<photoAccessHelper.PhotoAsset> = await phAccessHelper.getAssets(fetchOption); 3871 let asset = await fetchResult.getFirstObject(); 3872 let assetChangeRequest: photoAccessHelper.MediaAssetChangeRequest = new photoAccessHelper.MediaAssetChangeRequest(asset); 3873 let userComment: string = 'test_set_user_comment'; 3874 assetChangeRequest.setUserComment(userComment); 3875 phAccessHelper.applyChanges(assetChangeRequest).then(() => { 3876 console.info('apply setUserComment successfully'); 3877 }).catch((err: BusinessError) => { 3878 console.error(`apply setUserComment failed with error: ${err.code}, ${err.message}`); 3879 }); 3880} 3881``` 3882 3883### setEditData<sup>11+</sup> 3884 3885setEditData(editData: MediaAssetEditData): void 3886 3887Saves the edited data of an asset. 3888 3889**System API**: This is a system API. 3890 3891**System capability**: SystemCapability.FileManagement.PhotoAccessHelper.Core 3892 3893**Parameters** 3894 3895| Name | Type | Mandatory | Description | 3896| ---------- | ------- | ---- | ---------------------------------- | 3897| editData | [MediaAssetEditData](#mediaasseteditdata11) | Yes | Edited data to save.| 3898 3899**Error codes** 3900 3901For details about the error codes, see [Universal Error Codes](../errorcode-universal.md) and [File Management Error Codes](../apis-core-file-kit/errorcode-filemanagement.md). 3902 3903| ID| Error Message| 3904| -------- | ---------------------------------------- | 3905| 202 | Called by non-system application. | 3906| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types; 3. Parameter verification failed. | 3907| 14000011 | System inner fail. | 3908 3909**Example** 3910 3911```ts 3912import { dataSharePredicates } from '@kit.ArkData'; 3913import { BusinessError } from '@kit.BasicServicesKit'; 3914 3915async function example() { 3916 console.info('setEditDataDemo'); 3917 let predicates: dataSharePredicates.DataSharePredicates = new dataSharePredicates.DataSharePredicates(); 3918 let fetchOption: photoAccessHelper.FetchOptions = { 3919 fetchColumns: [], 3920 predicates: predicates 3921 }; 3922 let fetchResult: photoAccessHelper.FetchResult<photoAccessHelper.PhotoAsset> = await phAccessHelper.getAssets(fetchOption); 3923 let asset = await fetchResult.getFirstObject(); 3924 let assetChangeRequest: photoAccessHelper.MediaAssetChangeRequest = new photoAccessHelper.MediaAssetChangeRequest(asset); 3925 3926 let assetEditData: photoAccessHelper.MediaAssetEditData = new photoAccessHelper.MediaAssetEditData('system', '1.0'); 3927 let fileUri = 'file://com.example.temptest/data/storage/el2/base/haps/entry/files/test.jpg'; 3928 assetChangeRequest.addResource(photoAccessHelper.ResourceType.IMAGE_RESOURCE, fileUri); 3929 assetEditData.data = '123456'; 3930 assetChangeRequest.setEditData(assetEditData); 3931 phAccessHelper.applyChanges(assetChangeRequest).then(() => { 3932 console.info('apply setEditData successfully'); 3933 }).catch((err: BusinessError) => { 3934 console.error(`apply setEditData failed with error: ${err.code}, ${err.message}`); 3935 }); 3936} 3937``` 3938 3939### addResource<sup>11+</sup> 3940 3941addResource(type: ResourceType, proxy: PhotoProxy): void 3942 3943Adds resources using **PhotoProxy** data. 3944 3945> **NOTE**<br>For the same asset change request, this API cannot be repeatedly called after resources are successfully added. 3946 3947**System API**: This is a system API available only for camera applications. 3948 3949**System capability**: SystemCapability.FileManagement.PhotoAccessHelper.Core 3950 3951**Parameters** 3952 3953| Name | Type | Mandatory| Description | 3954| ------- |---------------------------------| ---- |----------------------| 3955| type | [ResourceType](#resourcetype11) | Yes | Type of the resource to add. | 3956| proxy | [PhotoProxy](#photoproxy11) | Yes | PhotoProxy data of the resource to add.| 3957 3958**Error codes** 3959 3960For details about the error codes, see [Universal Error Codes](../errorcode-universal.md) and [File Management Error Codes](../apis-core-file-kit/errorcode-filemanagement.md). 3961 3962| ID | Error Message | 3963|----------|-----------------------------------| 3964| 202 | Called by non-system application. | 3965| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types; 3. Parameter verification failed. | 3966| 14000011 | System inner fail. | 3967| 14000016 | Operation Not Support. | 3968 3969**Example** 3970 3971```ts 3972class PhotoProxyImpl implements photoAccessHelper.PhotoProxy { 3973 // Implement PhotoProxy. 3974} 3975 3976async function example() { 3977 console.info('addResourceByPhotoProxyDemo'); 3978 try { 3979 let photoType: photoAccessHelper.PhotoType = photoAccessHelper.PhotoType.IMAGE; 3980 let extension: string = 'jpg'; 3981 let assetChangeRequest: photoAccessHelper.MediaAssetChangeRequest = photoAccessHelper.MediaAssetChangeRequest.createAssetRequest(context, photoType, extension); 3982 let photoProxy: PhotoProxyImpl = new PhotoProxyImpl(); 3983 assetChangeRequest.addResource(photoAccessHelper.ResourceType.IMAGE_RESOURCE, photoProxy); 3984 await phAccessHelper.applyChanges(assetChangeRequest); 3985 console.info('addResourceByPhotoProxy successfully'); 3986 } catch (err) { 3987 console.error(`addResourceByPhotoProxyDemo failed with error: ${err.code}, ${err.message}`); 3988 } 3989} 3990``` 3991 3992### setLocation<sup>11+</sup> 3993 3994setLocation(longitude: number, latitude: number): void 3995 3996Sets location information. 3997 3998**System API**: This is a system API. 3999 4000**System capability**: SystemCapability.FileManagement.PhotoAccessHelper.Core 4001 4002**Parameters** 4003 4004| Name | Type | Mandatory| Description | 4005| ------- |-------------| ---- |-------| 4006| longitude | number | Yes | Longitude.| 4007| latitude | number | Yes | Latitude. | 4008 4009**Error codes** 4010 4011For details about the error codes, see [Universal Error Codes](../errorcode-universal.md) and [File Management Error Codes](../apis-core-file-kit/errorcode-filemanagement.md). 4012 4013| ID| Error Message| 4014| -------- | ---------------------------------------- | 4015| 202 | Called by non-system application. | 4016| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types; 3. Parameter verification failed. | 4017| 14000011 | System inner fail. | 4018 4019**Example** 4020 4021```ts 4022import { dataSharePredicates } from '@kit.ArkData'; 4023import { BusinessError } from '@kit.BasicServicesKit'; 4024 4025async function example() { 4026 console.info('setLocationDemo'); 4027 let predicates: dataSharePredicates.DataSharePredicates = new dataSharePredicates.DataSharePredicates(); 4028 let fetchOption: photoAccessHelper.FetchOptions = { 4029 fetchColumns: [], 4030 predicates: predicates 4031 }; 4032 let fetchResult: photoAccessHelper.FetchResult<photoAccessHelper.PhotoAsset> = await phAccessHelper.getAssets(fetchOption); 4033 let asset = await fetchResult.getFirstObject(); 4034 let assetChangeRequest: photoAccessHelper.MediaAssetChangeRequest = new photoAccessHelper.MediaAssetChangeRequest(asset); 4035 assetChangeRequest.setLocation(120.52, 30.40); 4036 phAccessHelper.applyChanges(assetChangeRequest).then(() => { 4037 console.info('apply setLocation successfully'); 4038 }).catch((err: BusinessError) => { 4039 console.error(`apply setLocation failed with error: ${err.code}, ${err.message}`); 4040 }); 4041} 4042``` 4043 4044### setCameraShotKey<sup>12+</sup> 4045 4046setCameraShotKey(cameraShotKey: string): void 4047 4048Sets the Key for the Ultra Snapshot feature, which allows the camera to take photos or record videos with the screen off. 4049 4050**System API**: This is a system API. 4051 4052**System capability**: SystemCapability.FileManagement.PhotoAccessHelper.Core 4053 4054**Parameters** 4055 4056| Name | Type | Mandatory | Description | 4057| ---------- | ------- | ---- | ---------------------------------- | 4058| 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.| 4059 4060**Error codes** 4061 4062For details about the error codes, see [Universal Error Codes](../errorcode-universal.md) and [File Management Error Codes](../apis-core-file-kit/errorcode-filemanagement.md). 4063 4064| ID| Error Message| 4065| -------- | ---------------------------------------- | 4066| 202 | Called by non-system application. | 4067| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types; 3. Parameter verification failed. | 4068| 14000011 | System inner fail. | 4069 4070**Example** 4071 4072```ts 4073async function example(asset: photoAccessHelper.PhotoAsset) { 4074 console.info('setCameraShotKeyDemo'); 4075 try { 4076 let assetChangeRequest: photoAccessHelper.MediaAssetChangeRequest = new photoAccessHelper.MediaAssetChangeRequest(asset); 4077 let cameraShotKey: string = 'test_MediaAssetChangeRequest_setCameraShotKey'; 4078 assetChangeRequest.setCameraShotKey(cameraShotKey); 4079 await phAccessHelper.applyChanges(assetChangeRequest); 4080 console.info('apply setCameraShotKey successfully'); 4081 } catch (err) { 4082 console.error(`apply setCameraShotKey failed with error: ${err.code}, ${err.message}`); 4083 } 4084} 4085``` 4086 4087### setEffectMode<sup>12+</sup> 4088 4089setEffectMode(mode: MovingPhotoEffectMode): void 4090 4091Sets the effect of this moving photo. 4092 4093**System API**: This is a system API. 4094 4095**System capability**: SystemCapability.FileManagement.PhotoAccessHelper.Core 4096 4097**Parameters** 4098 4099| Name | Type | Mandatory | Description | 4100| ---------- | ------- | ---- | ---------------------------------- | 4101| mode | [MovingPhotoEffectMode](#movingphotoeffectmode12) | Yes | Effect to set.| 4102 4103**Error codes** 4104 4105For details about the error codes, see [Universal Error Codes](../errorcode-universal.md) and [File Management Error Codes](../apis-core-file-kit/errorcode-filemanagement.md). 4106 4107| ID| Error Message| 4108| -------- | ---------------------------------------- | 4109| 202 | Called by non-system application. | 4110| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types; 3. Parameter verification failed. | 4111| 14000011 | System inner fail. | 4112| 14000016 | Operation Not Support. | 4113 4114**Example** 4115 4116```ts 4117async function example(asset: photoAccessHelper.PhotoAsset) { 4118 console.info('setEffectModeDemo'); 4119 try { 4120 let assetChangeRequest: photoAccessHelper.MediaAssetChangeRequest = new photoAccessHelper.MediaAssetChangeRequest(asset); 4121 assetChangeRequest.setEffectMode(photoAccessHelper.MovingPhotoEffectMode.LONG_EXPOSURE); 4122 // Ensure that the asset specified by fileUri exists. 4123 let imageFileUri = 'file://com.example.temptest/data/storage/el2/base/haps/entry/files/long_exposure.jpg'; 4124 let videoFileUri = 'file://com.example.temptest/data/storage/el2/base/haps/entry/files/long_exposure.mp4'; 4125 assetChangeRequest.addResource(photoAccessHelper.ResourceType.IMAGE_RESOURCE, imageFileUri); 4126 assetChangeRequest.addResource(photoAccessHelper.ResourceType.VIDEO_RESOURCE, videoFileUri); 4127 await phAccessHelper.applyChanges(assetChangeRequest); 4128 console.info('apply setEffectMode successfully'); 4129 } catch (err) { 4130 console.error(`apply setEffectMode failed with error: ${err.code}, ${err.message}`); 4131 } 4132} 4133``` 4134 4135### setSupportedWatermarkType<sup>14+</sup> 4136 4137setSupportedWatermarkType(watermarkType: WatermarkType): void 4138 4139Sets the watermark type supported by photos. 4140 4141**System API**: This is a system API. 4142 4143**System capability**: SystemCapability.FileManagement.PhotoAccessHelper.Core 4144 4145**Parameters** 4146 4147| Name | Type | Mandatory | Description | 4148| ---------- | ------- | ---- | ---------------------------------- | 4149| watermarkType | [WatermarkType](#watermarktype14) | Yes | Watermark type to set. | 4150 4151**Error codes** 4152 4153For details about the error codes, see [Universal Error Codes](../errorcode-universal.md) and [File Management Error Codes](../apis-core-file-kit/errorcode-filemanagement.md). 4154 4155| ID| Error Message| 4156| -------- | ---------------------------------------- | 4157| 202 | Called by non-system application. | 4158| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types; 3. Parameter verification failed. | 4159| 14000011 | Internal system error. | 4160 4161**Example** 4162 4163```ts 4164import { dataSharePredicates } from '@kit.ArkData'; 4165import photoAccessHelper from '@ohos.file.photoAccessHelper'; 4166 4167const context = getContext(this); 4168let phAccessHelper = photoAccessHelper.getPhotoAccessHelper(context); 4169 4170async function example() { 4171 console.info('setSupportedWatermarkTypeDemo'); 4172 let predicates: dataSharePredicates.DataSharePredicates = new dataSharePredicates.DataSharePredicates(); 4173 let fetchOption: photoAccessHelper.FetchOptions = { 4174 fetchColumns: [], 4175 predicates: predicates 4176 }; 4177 try { 4178 let fetchResult: photoAccessHelper.FetchResult<photoAccessHelper.PhotoAsset> = await phAccessHelper.getAssets(fetchOption); 4179 let asset = await fetchResult.getFirstObject(); 4180 let assetChangeRequest: photoAccessHelper.MediaAssetChangeRequest = new photoAccessHelper.MediaAssetChangeRequest(asset); 4181 assetChangeRequest.setSupportedWatermarkType(photoAccessHelper.WatermarkType.BRAND_COMMON); 4182 await phAccessHelper.applyChanges(assetChangeRequest); 4183 console.info('apply setSupportedWatermarkType successfully'); 4184 } catch (err) { 4185 console.error(`apply setSupportedWatermarkType failed with error: ${err.code}, ${err.message}`); 4186 } 4187} 4188``` 4189 4190## MediaAssetsChangeRequest<sup>11+</sup> 4191 4192Represents a request for changing multiple assets. 4193 4194**System API**: This is a system API. 4195 4196**System capability**: SystemCapability.FileManagement.PhotoAccessHelper.Core 4197 4198### constructor<sup>11+</sup> 4199 4200constructor(assets: Array<PhotoAsset>) 4201 4202Constructor. 4203 4204**System API**: This is a system API. 4205 4206**System capability**: SystemCapability.FileManagement.PhotoAccessHelper.Core 4207 4208**Parameters** 4209 4210| Name | Type | Mandatory| Description | 4211| -------- | ------------------------- | ---- | ---------- | 4212| assets | Array<[PhotoAsset](#photoasset)> | Yes | Assets to change.| 4213 4214**Error codes** 4215 4216For details about the error codes, see [Universal Error Codes](../errorcode-universal.md) and [File Management Error Codes](../apis-core-file-kit/errorcode-filemanagement.md). 4217 4218| ID| Error Message| 4219| -------- | ---------------------------------------- | 4220| 202 | Called by non-system application. | 4221| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types; 3. Parameter verification failed. | 4222| 14000011 | System inner fail. | 4223 4224**Example** 4225 4226```ts 4227import { dataSharePredicates } from '@kit.ArkData'; 4228 4229async function example() { 4230 console.info('MediaAssetsChangeRequest constructorDemo'); 4231 let predicates: dataSharePredicates.DataSharePredicates = new dataSharePredicates.DataSharePredicates(); 4232 let fetchOption: photoAccessHelper.FetchOptions = { 4233 fetchColumns: [], 4234 predicates: predicates 4235 }; 4236 let fetchResult: photoAccessHelper.FetchResult<photoAccessHelper.PhotoAsset> = await phAccessHelper.getAssets(fetchOption); 4237 let photoAssetList: Array<photoAccessHelper.PhotoAsset> = await fetchResult.getAllObjects(); 4238 let assetsChangeRequest: photoAccessHelper.MediaAssetsChangeRequest = new photoAccessHelper.MediaAssetsChangeRequest(photoAssetList); 4239} 4240``` 4241 4242### setFavorite<sup>11+</sup> 4243 4244setFavorite(favoriteState: boolean): void 4245 4246Favorites or unfavorites this file. 4247 4248**System API**: This is a system API. 4249 4250**System capability**: SystemCapability.FileManagement.PhotoAccessHelper.Core 4251 4252**Parameters** 4253 4254| Name | Type | Mandatory | Description | 4255| ---------- | ------- | ---- | ---------------------------------- | 4256| favoriteState | boolean | Yes | Operation to perform. The value **true** means to favorite the file, and **false** means the opposite.| 4257 4258**Error codes** 4259 4260For details about the error codes, see [Universal Error Codes](../errorcode-universal.md) and [File Management Error Codes](../apis-core-file-kit/errorcode-filemanagement.md). 4261 4262| ID| Error Message| 4263| -------- | ---------------------------------------- | 4264| 202 | Called by non-system application. | 4265| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types; 3. Parameter verification failed. | 4266| 14000011 | System inner fail. | 4267 4268**Example** 4269 4270```ts 4271import { dataSharePredicates } from '@kit.ArkData'; 4272import { BusinessError } from '@kit.BasicServicesKit'; 4273 4274async function example() { 4275 console.info('setFavoriteDemo'); 4276 let predicates: dataSharePredicates.DataSharePredicates = new dataSharePredicates.DataSharePredicates(); 4277 let fetchOption: photoAccessHelper.FetchOptions = { 4278 fetchColumns: [], 4279 predicates: predicates 4280 }; 4281 let fetchResult: photoAccessHelper.FetchResult<photoAccessHelper.PhotoAsset> = await phAccessHelper.getAssets(fetchOption); 4282 let photoAssetList: Array<photoAccessHelper.PhotoAsset> = await fetchResult.getAllObjects(); 4283 let assetsChangeRequest: photoAccessHelper.MediaAssetsChangeRequest = new photoAccessHelper.MediaAssetsChangeRequest(photoAssetList); 4284 assetsChangeRequest.setFavorite(true); 4285 phAccessHelper.applyChanges(assetsChangeRequest).then(() => { 4286 console.info('apply setFavorite successfully'); 4287 }).catch((err: BusinessError) => { 4288 console.error(`apply setFavorite failed with error: ${err.code}, ${err.message}`); 4289 }); 4290} 4291``` 4292 4293### setHidden<sup>11+</sup> 4294 4295setHidden(hiddenState: boolean): void 4296 4297Hides this file. 4298 4299**System API**: This is a system API. 4300 4301**System capability**: SystemCapability.FileManagement.PhotoAccessHelper.Core 4302 4303**Parameters** 4304 4305| Name | Type | Mandatory | Description | 4306| ---------- | ------- | ---- | ---------------------------------- | 4307| hiddenState | boolean | Yes | Whether to hide the file. The value **true** means to hide the file; the value **false** means the opposite.| 4308 4309**Error codes** 4310 4311For details about the error codes, see [Universal Error Codes](../errorcode-universal.md) and [File Management Error Codes](../apis-core-file-kit/errorcode-filemanagement.md). 4312 4313| ID| Error Message| 4314| -------- | ---------------------------------------- | 4315| 202 | Called by non-system application. | 4316| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types; 3. Parameter verification failed. | 4317| 14000011 | System inner fail. | 4318 4319**Example** 4320 4321```ts 4322import { dataSharePredicates } from '@kit.ArkData'; 4323import { BusinessError } from '@kit.BasicServicesKit'; 4324 4325async function example() { 4326 console.info('setHiddenDemo'); 4327 let predicates: dataSharePredicates.DataSharePredicates = new dataSharePredicates.DataSharePredicates(); 4328 let fetchOption: photoAccessHelper.FetchOptions = { 4329 fetchColumns: [], 4330 predicates: predicates 4331 }; 4332 let fetchResult: photoAccessHelper.FetchResult<photoAccessHelper.PhotoAsset> = await phAccessHelper.getAssets(fetchOption); 4333 let photoAssetList: Array<photoAccessHelper.PhotoAsset> = await fetchResult.getAllObjects(); 4334 let assetsChangeRequest: photoAccessHelper.MediaAssetsChangeRequest = new photoAccessHelper.MediaAssetsChangeRequest(photoAssetList); 4335 assetsChangeRequest.setHidden(true); 4336 phAccessHelper.applyChanges(assetsChangeRequest).then(() => { 4337 console.info('apply setHidden successfully'); 4338 }).catch((err: BusinessError) => { 4339 console.error(`apply setHidden failed with error: ${err.code}, ${err.message}`); 4340 }); 4341} 4342``` 4343 4344### setUserComment<sup>11+</sup> 4345 4346setUserComment(userComment: string): void 4347 4348Sets the user comment information of this media asset. 4349 4350**System API**: This is a system API. 4351 4352**System capability**: SystemCapability.FileManagement.PhotoAccessHelper.Core 4353 4354**Parameters** 4355 4356| Name | Type | Mandatory | Description | 4357| ---------- | ------- | ---- | ---------------------------------- | 4358| userComment | string | Yes | Comment information to set, which cannot exceed 420 characters.| 4359 4360**Error codes** 4361 4362For details about the error codes, see [Universal Error Codes](../errorcode-universal.md) and [File Management Error Codes](../apis-core-file-kit/errorcode-filemanagement.md). 4363 4364| ID| Error Message| 4365| -------- | ---------------------------------------- | 4366| 202 | Called by non-system application. | 4367| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types; 3. Parameter verification failed. | 4368| 14000011 | System inner fail. | 4369 4370**Example** 4371 4372```ts 4373import { dataSharePredicates } from '@kit.ArkData'; 4374import { BusinessError } from '@kit.BasicServicesKit'; 4375 4376async function example() { 4377 console.info('setUserCommentDemo'); 4378 let predicates: dataSharePredicates.DataSharePredicates = new dataSharePredicates.DataSharePredicates(); 4379 let fetchOption: photoAccessHelper.FetchOptions = { 4380 fetchColumns: [], 4381 predicates: predicates 4382 }; 4383 let fetchResult: photoAccessHelper.FetchResult<photoAccessHelper.PhotoAsset> = await phAccessHelper.getAssets(fetchOption); 4384 let photoAssetList: Array<photoAccessHelper.PhotoAsset> = await fetchResult.getAllObjects(); 4385 let assetsChangeRequest: photoAccessHelper.MediaAssetsChangeRequest = new photoAccessHelper.MediaAssetsChangeRequest(photoAssetList); 4386 assetsChangeRequest.setUserComment('test_set_user_comment'); 4387 phAccessHelper.applyChanges(assetsChangeRequest).then(() => { 4388 console.info('apply setUserComment successfully'); 4389 }).catch((err: BusinessError) => { 4390 console.error(`apply setUserComment failed with error: ${err.code}, ${err.message}`); 4391 }); 4392} 4393``` 4394 4395## MediaAlbumChangeRequest<sup>11+</sup> 4396 4397Provides APIs for managing the media album change request. 4398 4399**System capability**: SystemCapability.FileManagement.PhotoAccessHelper.Core 4400 4401### createAlbumRequest<sup>11+</sup> 4402 4403static createAlbumRequest(context: Context, name: string): MediaAlbumChangeRequest 4404 4405Creates a **MediaAlbumChangeRequest** instance. 4406 4407The album name must comply with the following specifications: 4408- The album name cannot exceed 255 characters. 4409- The album name cannot contain any of the following characters:<br>. .. \ / : * ? " ' ` < > | { } [ ] 4410- The album name is case-insensitive. 4411- Duplicate album names are not allowed. 4412 4413**System API**: This is a system API. 4414 4415**System capability**: SystemCapability.FileManagement.PhotoAccessHelper.Core 4416 4417**Parameters** 4418 4419| Name | Type | Mandatory| Description | 4420| ------- | ------- | ---- | -------------------------- | 4421| context | [Context](../apis-ability-kit/js-apis-inner-application-context.md) | Yes | Context of the ability instance.| 4422| name | string | Yes | Name of the album.| 4423 4424**Return value** 4425 4426| Type | Description | 4427| --------------------------------------- | ----------------- | 4428| [MediaAlbumChangeRequest](#mediaalbumchangerequest11) | **MediaAlbumChangeRequest** instance created.| 4429 4430**Error codes** 4431 4432For details about the error codes, see [Universal Error Codes](../errorcode-universal.md) and [File Management Error Codes](../apis-core-file-kit/errorcode-filemanagement.md). 4433 4434| ID| Error Message| 4435| -------- | ---------------------------------------- | 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 4443async function example() { 4444 console.info('createAlbumRequestDemo'); 4445 try { 4446 let albumName: string = 'newAlbumName' + new Date().getTime(); 4447 let albumChangeRequest: photoAccessHelper.MediaAlbumChangeRequest = photoAccessHelper.MediaAlbumChangeRequest.createAlbumRequest(context, albumName); 4448 await phAccessHelper.applyChanges(albumChangeRequest); 4449 console.info('apply createAlbumRequest successfully'); 4450 } catch (err) { 4451 console.error(`createAlbumRequestDemo failed with error: ${err.code}, ${err.message}`); 4452 } 4453} 4454``` 4455 4456### deleteAlbums<sup>11+</sup> 4457 4458static deleteAlbums(context: Context, albums: Array<Album>): Promise<void> 4459 4460Deletes albums. This API uses a promise to return the result. 4461 4462Ensure that the albums to be deleted exist. Only user albums can be deleted. 4463 4464**System API**: This is a system API. 4465 4466**Required permissions**: ohos.permission.WRITE_IMAGEVIDEO 4467 4468**System capability**: SystemCapability.FileManagement.PhotoAccessHelper.Core 4469 4470**Parameters** 4471 4472| Name | Type | Mandatory| Description | 4473| ------- | ------- | ---- | -------------------------- | 4474| context | [Context](../apis-ability-kit/js-apis-inner-application-context.md) | Yes | Context of the ability instance.| 4475| albums | Array<[Album](#album)> | Yes | Albums to delete. | 4476 4477**Return value** 4478 4479| Type | Description | 4480| --------------------------------------- | ----------------- | 4481| Promise<void>| Promise that returns no value.| 4482 4483**Error codes** 4484 4485For details about the error codes, see [Universal Error Codes](../errorcode-universal.md) and [File Management Error Codes](../apis-core-file-kit/errorcode-filemanagement.md). 4486 4487| ID| Error Message| 4488| -------- | ---------------------------------------- | 4489| 201 | Permission denied. | 4490| 202 | Called by non-system application. | 4491| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types; 3. Parameter verification failed. | 4492| 14000011 | System inner fail. | 4493 4494**Example** 4495 4496```ts 4497import { dataSharePredicates } from '@kit.ArkData'; 4498 4499async function example() { 4500 console.info('deleteAlbumsDemo'); 4501 let predicates: dataSharePredicates.DataSharePredicates = new dataSharePredicates.DataSharePredicates(); 4502 let fetchOptions: photoAccessHelper.FetchOptions = { 4503 fetchColumns: [], 4504 predicates: predicates 4505 }; 4506 try { 4507 let fetchResult: photoAccessHelper.FetchResult<photoAccessHelper.Album> = await phAccessHelper.getAlbums(photoAccessHelper.AlbumType.USER, photoAccessHelper.AlbumSubtype.USER_GENERIC, fetchOptions); 4508 let album: photoAccessHelper.Album = await fetchResult.getFirstObject(); 4509 await photoAccessHelper.MediaAlbumChangeRequest.deleteAlbums(context, [album]); 4510 console.info('deleteAlbums successfully'); 4511 } catch (err) { 4512 console.error(`deleteAlbumsDemo failed with error: ${err.code}, ${err.message}`); 4513 } 4514} 4515``` 4516 4517### setCoverUri<sup>11+</sup> 4518 4519setCoverUri(coverUri: string): void 4520 4521Sets the album cover. 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| coverUri | string | Yes | URI of the file to be set as the album cover.| 4532 4533**Error codes** 4534 4535For details about the error codes, see [Universal Error Codes](../errorcode-universal.md) and [File Management Error Codes](../apis-core-file-kit/errorcode-filemanagement.md). 4536 4537| ID| Error Message| 4538| -------- | ---------------------------------------- | 4539| 202 | Called by non-system application. | 4540| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types; 3. Parameter verification failed. | 4541| 14000011 | System inner fail. | 4542 4543**Example** 4544 4545```ts 4546import { dataSharePredicates } from '@kit.ArkData'; 4547 4548async function example() { 4549 console.info('setCoverUriDemo'); 4550 let predicates: dataSharePredicates.DataSharePredicates = new dataSharePredicates.DataSharePredicates(); 4551 let fetchOptions: photoAccessHelper.FetchOptions = { 4552 fetchColumns: [], 4553 predicates: predicates 4554 }; 4555 try { 4556 let albumFetchResult: photoAccessHelper.FetchResult<photoAccessHelper.Album> = await phAccessHelper.getAlbums(photoAccessHelper.AlbumType.USER, photoAccessHelper.AlbumSubtype.USER_GENERIC); 4557 let album: photoAccessHelper.Album = await albumFetchResult.getFirstObject(); 4558 let fetchResult: photoAccessHelper.FetchResult<photoAccessHelper.PhotoAsset> = await album.getAssets(fetchOptions); 4559 let asset: photoAccessHelper.PhotoAsset = await fetchResult.getFirstObject(); 4560 4561 let albumChangeRequest: photoAccessHelper.MediaAlbumChangeRequest = new photoAccessHelper.MediaAlbumChangeRequest(album); 4562 albumChangeRequest.setCoverUri(asset.uri); 4563 await phAccessHelper.applyChanges(albumChangeRequest); 4564 console.info('setCoverUri successfully'); 4565 } catch (err) { 4566 console.error(`setCoverUriDemo failed with error: ${err.code}, ${err.message}`); 4567 } 4568} 4569``` 4570 4571### moveAssets<sup>11+</sup> 4572 4573moveAssets(assets: Array<PhotoAsset>, targetAlbum: Album): void 4574 4575Moves assets to another album. 4576 4577**System API**: This is a system API. 4578 4579**System capability**: SystemCapability.FileManagement.PhotoAccessHelper.Core 4580 4581**Parameters** 4582 4583| Name | Type | Mandatory | Description | 4584| ---------- | ------- | ---- | ---------------------------------- | 4585| assets | Array<[PhotoAsset](#photoasset)> | Yes | Assets to move.| 4586| targetAlbum | Album | Yes | Album to which the assets are to be moved.| 4587 4588**Error codes** 4589 4590For details about the error codes, see [Universal Error Codes](../errorcode-universal.md) and [File Management Error Codes](../apis-core-file-kit/errorcode-filemanagement.md). 4591 4592| ID| Error Message| 4593| -------- | ---------------------------------------- | 4594| 202 | Called by non-system application. | 4595| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types; 3. Parameter verification failed. | 4596| 14000011 | System inner fail. | 4597| 14000016 | Operation Not Support. | 4598 4599**Example** 4600 4601```ts 4602import { dataSharePredicates } from '@kit.ArkData'; 4603 4604async function example() { 4605 console.info('moveAssetsDemo'); 4606 let predicates: dataSharePredicates.DataSharePredicates = new dataSharePredicates.DataSharePredicates(); 4607 let fetchOptions: photoAccessHelper.FetchOptions = { 4608 fetchColumns: [], 4609 predicates: predicates 4610 }; 4611 try { 4612 let albumFetchResult: photoAccessHelper.FetchResult<photoAccessHelper.Album> = await phAccessHelper.getAlbums(photoAccessHelper.AlbumType.USER, photoAccessHelper.AlbumSubtype.USER_GENERIC); 4613 let album: photoAccessHelper.Album = await albumFetchResult.getFirstObject(); 4614 let fetchResult: photoAccessHelper.FetchResult<photoAccessHelper.PhotoAsset> = await album.getAssets(fetchOptions); 4615 let asset: photoAccessHelper.PhotoAsset = await fetchResult.getFirstObject(); 4616 4617 if (albumFetchResult.isAfterLast()) { 4618 console.error('lack of album to be moved into'); 4619 return; 4620 } 4621 let nextAlbum: photoAccessHelper.Album = await albumFetchResult.getNextObject(); 4622 let albumChangeRequest: photoAccessHelper.MediaAlbumChangeRequest = new photoAccessHelper.MediaAlbumChangeRequest(album); 4623 albumChangeRequest.moveAssets([asset], nextAlbum); 4624 await phAccessHelper.applyChanges(albumChangeRequest); 4625 console.info('moveAssets successfully'); 4626 } catch (err) { 4627 console.error(`moveAssetsDemo failed with error: ${err.code}, ${err.message}`); 4628 } 4629} 4630``` 4631 4632### recoverAssets<sup>11+</sup> 4633 4634recoverAssets(assets: Array<PhotoAsset>): void 4635 4636Recovers assets from the trash. 4637 4638**System API**: This is a system API. 4639 4640**System capability**: SystemCapability.FileManagement.PhotoAccessHelper.Core 4641 4642**Parameters** 4643 4644| Name | Type | Mandatory | Description | 4645| ---------- | ------- | ---- | ---------------------------------- | 4646| assets | Array<[PhotoAsset](#photoasset)> | Yes | Assets to recover.| 4647 4648**Error codes** 4649 4650For details about the error codes, see [Universal Error Codes](../errorcode-universal.md) and [File Management Error Codes](../apis-core-file-kit/errorcode-filemanagement.md). 4651 4652| ID| Error Message| 4653| -------- | ---------------------------------------- | 4654| 202 | Called by non-system application. | 4655| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types; 3. Parameter verification failed. | 4656| 14000011 | System inner fail. | 4657| 14000016 | Operation Not Support. | 4658 4659**Example** 4660 4661```ts 4662import { dataSharePredicates } from '@kit.ArkData'; 4663 4664async function example() { 4665 console.info('recoverAssetsDemo'); 4666 let predicates: dataSharePredicates.DataSharePredicates = new dataSharePredicates.DataSharePredicates(); 4667 let fetchOptions: photoAccessHelper.FetchOptions = { 4668 fetchColumns: [], 4669 predicates: predicates 4670 }; 4671 try { 4672 let albumFetchResult: photoAccessHelper.FetchResult<photoAccessHelper.Album> = await phAccessHelper.getAlbums(photoAccessHelper.AlbumType.SYSTEM, photoAccessHelper.AlbumSubtype.TRASH); 4673 let album: photoAccessHelper.Album = await albumFetchResult.getFirstObject(); 4674 let fetchResult: photoAccessHelper.FetchResult<photoAccessHelper.PhotoAsset> = await album.getAssets(fetchOptions); 4675 let asset: photoAccessHelper.PhotoAsset = await fetchResult.getFirstObject(); 4676 4677 let albumChangeRequest: photoAccessHelper.MediaAlbumChangeRequest = new photoAccessHelper.MediaAlbumChangeRequest(album); 4678 albumChangeRequest.recoverAssets([asset]); 4679 await phAccessHelper.applyChanges(albumChangeRequest); 4680 console.info('recoverAssets successfully'); 4681 } catch (err) { 4682 console.error(`recoverAssetsDemo failed with error: ${err.code}, ${err.message}`); 4683 } 4684} 4685``` 4686 4687### deleteAssets<sup>11+</sup> 4688 4689deleteAssets(assets: Array<PhotoAsset>): void 4690 4691Permanently deletes assets from the trash. 4692 4693**NOTE**<br>This operation is irreversible. The file assets deleted cannot be restored. Exercise caution when performing this operation. 4694 4695**System API**: This is a system API. 4696 4697**System capability**: SystemCapability.FileManagement.PhotoAccessHelper.Core 4698 4699**Parameters** 4700 4701| Name | Type | Mandatory | Description | 4702| ---------- | ------- | ---- | ---------------------------------- | 4703| assets | Array<[PhotoAsset](#photoasset)> | Yes | Assets to be permanently deleted.| 4704 4705**Error codes** 4706 4707For details about the error codes, see [Universal Error Codes](../errorcode-universal.md) and [File Management Error Codes](../apis-core-file-kit/errorcode-filemanagement.md). 4708 4709| ID| Error Message| 4710| -------- | ---------------------------------------- | 4711| 202 | Called by non-system application. | 4712| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types; 3. Parameter verification failed. | 4713| 14000011 | System inner fail. | 4714| 14000016 | Operation Not Support. | 4715 4716**Example** 4717 4718```ts 4719import { dataSharePredicates } from '@kit.ArkData'; 4720 4721async function example() { 4722 console.info('deleteAssetsPermanentlyDemo'); 4723 let predicates: dataSharePredicates.DataSharePredicates = new dataSharePredicates.DataSharePredicates(); 4724 let fetchOptions: photoAccessHelper.FetchOptions = { 4725 fetchColumns: [], 4726 predicates: predicates 4727 }; 4728 try { 4729 let albumFetchResult: photoAccessHelper.FetchResult<photoAccessHelper.Album> = await phAccessHelper.getAlbums(photoAccessHelper.AlbumType.SYSTEM, photoAccessHelper.AlbumSubtype.TRASH); 4730 let album: photoAccessHelper.Album = await albumFetchResult.getFirstObject(); 4731 let fetchResult: photoAccessHelper.FetchResult<photoAccessHelper.PhotoAsset> = await album.getAssets(fetchOptions); 4732 let asset: photoAccessHelper.PhotoAsset = await fetchResult.getFirstObject(); 4733 4734 let albumChangeRequest: photoAccessHelper.MediaAlbumChangeRequest = new photoAccessHelper.MediaAlbumChangeRequest(album); 4735 albumChangeRequest.deleteAssets([asset]); 4736 await phAccessHelper.applyChanges(albumChangeRequest); 4737 console.info('succeed to deleteAssets permanently'); 4738 } catch (err) { 4739 console.error(`deleteAssetsPermanentlyDemo failed with error: ${err.code}, ${err.message}`); 4740 } 4741} 4742``` 4743 4744### setDisplayLevel<sup>11+</sup> 4745 4746setDisplayLevel(displayLevel: number): void 4747 4748Sets the display level of the portrait album. 4749 4750**System API**: This is a system API. 4751 4752**System capability**: SystemCapability.FileManagement.PhotoAccessHelper.Core 4753 4754**Parameters** 4755 4756| Name | Type | Mandatory | Description | 4757| ---------- | ------- | ---- | ---------------------------------- | 4758| 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.| 4759 4760**Error codes** 4761 4762For details about the error codes, see [Universal Error Codes](../errorcode-universal.md) and [File Management Error Codes](../apis-core-file-kit/errorcode-filemanagement.md). 4763 4764| ID| Error Message| 4765| -------- | ---------------------------------------- | 4766| 202 | Called by non-system application. | 4767| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types; 3. Parameter verification failed. | 4768| 14000011 | System inner fail. | 4769 4770**Example** 4771 4772``` ts 4773import { dataSharePredicates } from '@kit.ArkData'; 4774 4775async function example() { 4776 try { 4777 console.info('setDisplayLevel Example') 4778 let predicates: dataSharePredicates.DataSharePredicates = new dataSharePredicates.DataSharePredicates(); 4779 predicates.equalTo('user_display_level', 2); 4780 let fetchOptions: photoAccessHelper.FetchOptions = { 4781 fetchColumns: [], 4782 predicates: predicates 4783 }; 4784 let fetchResult: photoAccessHelper.FetchResult<photoAccessHelper.Album> = await phAccessHelper.getAlbums(photoAccessHelper.AlbumType.SMART, photoAccessHelper.AlbumSubtype.PORTRAIT, fetchOptions); 4785 let album: photoAccessHelper.Album = await fetchResult.getFirstObject(); 4786 let changeRequest: photoAccessHelper.MediaAlbumChangeRequest = new photoAccessHelper.MediaAlbumChangeRequest(album); 4787 changeRequest.setDisplayLevel(1); 4788 await phAccessHelper.applyChanges(changeRequest); 4789 } catch (err) { 4790 console.error(`setDisplayLevel failed with error: ${err.code}, ${err.message}`); 4791 } 4792} 4793``` 4794 4795### setIsMe<sup>11+</sup> 4796 4797setIsMe(): void 4798 4799Sets the relationship between people in the portrait album to **Me**. 4800 4801**System API**: This is a system API. 4802 4803**System capability**: SystemCapability.FileManagement.PhotoAccessHelper.Core 4804 4805**Error codes** 4806 4807For details about the error codes, see [Universal Error Codes](../errorcode-universal.md) and [File Management Error Codes](../apis-core-file-kit/errorcode-filemanagement.md). 4808 4809| ID| Error Message| 4810| -------- | ---------------------------------------- | 4811| 202 | Called by non-system application. | 4812| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types. | 4813| 14000011 | System inner fail. | 4814 4815**Example** 4816 4817``` ts 4818import { dataSharePredicates } from '@kit.ArkData'; 4819 4820async function example() { 4821 try { 4822 console.info('setIsMe Example') 4823 let predicates: dataSharePredicates.DataSharePredicates = new dataSharePredicates.DataSharePredicates(); 4824 predicates.equalTo('user_display_level', 2); 4825 let fetchOptions: photoAccessHelper.FetchOptions = { 4826 fetchColumns: [], 4827 predicates: predicates 4828 }; 4829 let fetchResult: photoAccessHelper.FetchResult<photoAccessHelper.Album> = await phAccessHelper.getAlbums(photoAccessHelper.AlbumType.SMART, photoAccessHelper.AlbumSubtype.PORTRAIT, fetchOptions); 4830 let album: photoAccessHelper.Album = await fetchResult.getFirstObject(); 4831 let changeRequest: photoAccessHelper.MediaAlbumChangeRequest = new photoAccessHelper.MediaAlbumChangeRequest(album); 4832 changeRequest.setIsMe(); 4833 await phAccessHelper.applyChanges(changeRequest); 4834 } catch (err) { 4835 console.error(`setIsMe failed with error: ${err.code}, ${err.message}`); 4836 } 4837} 4838``` 4839 4840### dismissAssets<sup>11+</sup> 4841 4842dismissAssets(assets: Array<PhotoAsset>): void 4843 4844Removes assets from this portrait album or group photo album. 4845 4846**System API**: This is a system API. 4847 4848**System capability**: SystemCapability.FileManagement.PhotoAccessHelper.Core 4849 4850**Parameters** 4851 4852| Name | Type | Mandatory | Description | 4853| ---------- | ------- | ---- | ---------------------------------- | 4854| assets | Array<PhotoAsset> | Yes | Assets to remove.| 4855 4856**Error codes** 4857 4858For details about the error codes, see [Universal Error Codes](../errorcode-universal.md) and [File Management Error Codes](../apis-core-file-kit/errorcode-filemanagement.md). 4859 4860| ID| Error Message| 4861| -------- | ---------------------------------------- | 4862| 202 | Called by non-system application. | 4863| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types; 3. Parameter verification failed. | 4864| 14000011 | System inner fail. | 4865| 14000016 | Operation Not support. | 4866 4867**Example** 4868 4869``` ts 4870import { dataSharePredicates } from '@kit.ArkData'; 4871 4872async function example() { 4873 try { 4874 console.info('dismissAssets Example') 4875 let predicates: dataSharePredicates.DataSharePredicates = new dataSharePredicates.DataSharePredicates(); 4876 predicates.equalTo('user_display_level', 2); 4877 let fetchOptions: photoAccessHelper.FetchOptions = { 4878 fetchColumns: [], 4879 predicates: predicates 4880 }; 4881 let fetchResult: photoAccessHelper.FetchResult<photoAccessHelper.Album> = await phAccessHelper.getAlbums(photoAccessHelper.AlbumType.SMART, photoAccessHelper.AlbumSubtype.PORTRAIT, fetchOptions); 4882 let album: photoAccessHelper.Album = await fetchResult.getFirstObject(); 4883 4884 let predicatesAsset: dataSharePredicates.DataSharePredicates = new dataSharePredicates.DataSharePredicates(); 4885 let assetFetchOptions: photoAccessHelper.FetchOptions = { 4886 fetchColumns: [], 4887 predicates: predicatesAsset 4888 }; 4889 let assetFetchResult: photoAccessHelper.FetchResult<photoAccessHelper.PhotoAsset> = await phAccessHelper.getAssets(assetFetchOptions); 4890 let asset: photoAccessHelper.PhotoAsset = await assetFetchResult.getFirstObject(); 4891 4892 let changeRequest: photoAccessHelper.MediaAlbumChangeRequest = new photoAccessHelper.MediaAlbumChangeRequest(album); 4893 changeRequest.dismissAssets([asset]); 4894 await phAccessHelper.applyChanges(changeRequest); 4895 } catch (err) { 4896 console.error(`dismissAssets failed with error: ${err.code}, ${err.message}`); 4897 } 4898} 4899``` 4900 4901### mergeAlbum<sup>11+</sup> 4902 4903mergeAlbum(target: Album): void 4904 4905Merges two portrait albums. 4906 4907**System API**: This is a system API. 4908 4909**System capability**: SystemCapability.FileManagement.PhotoAccessHelper.Core 4910 4911**Parameters** 4912 4913| Name | Type | Mandatory | Description | 4914| ---------- | ------- | ---- | ---------------------------------- | 4915| target | [Album](#album) | Yes | Album generated after the merge. The album must be renamed.| 4916 4917**Error codes** 4918 4919For details about the error codes, see [Universal Error Codes](../errorcode-universal.md) and [File Management Error Codes](../apis-core-file-kit/errorcode-filemanagement.md). 4920 4921| ID| Error Message| 4922| -------- | ---------------------------------------- | 4923| 202 | Called by non-system application. | 4924| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types; 3. Parameter verification failed. | 4925| 14000011 | System inner fail. | 4926| 14000016 | Operation Not support. | 4927 4928**Example** 4929 4930``` ts 4931import { dataSharePredicates } from '@kit.ArkData'; 4932 4933async function example() { 4934 try { 4935 console.info('mergeAlbum Example') 4936 let predicates: dataSharePredicates.DataSharePredicates = new dataSharePredicates.DataSharePredicates(); 4937 predicates.equalTo('user_display_level', 2); 4938 let fetchOptions: photoAccessHelper.FetchOptions = { 4939 fetchColumns: [], 4940 predicates: predicates 4941 }; 4942 let fetchResult: photoAccessHelper.FetchResult<photoAccessHelper.Album> = await phAccessHelper.getAlbums(photoAccessHelper.AlbumType.SMART, photoAccessHelper.AlbumSubtype.PORTRAIT, fetchOptions); 4943 let album: photoAccessHelper.Album = await fetchResult.getFirstObject(); 4944 if (fetchResult.isAfterLast()) { 4945 console.error('lack of album to merge'); 4946 return; 4947 } 4948 let target: photoAccessHelper.Album = await fetchResult.getNextObject(); 4949 4950 let changeRequest: photoAccessHelper.MediaAlbumChangeRequest = new photoAccessHelper.MediaAlbumChangeRequest(album); 4951 changeRequest.mergeAlbum(target); 4952 changeRequest.setAlbumName("testName"); 4953 await phAccessHelper.applyChanges(changeRequest); 4954 } catch (err) { 4955 console.error(`mergeAlbum failed with error: ${err.code}, ${err.message}`); 4956 } 4957} 4958``` 4959 4960### placeBefore<sup>11+</sup> 4961 4962placeBefore(album: Album): void; 4963 4964Places this album before an album. 4965 4966**System API**: This is a system API. 4967 4968**System capability**: SystemCapability.FileManagement.PhotoAccessHelper.Core 4969 4970**Parameters** 4971 4972| Name | Type | Mandatory | Description | 4973| ---------- | ------- | ---- | ---------------------------------- | 4974| album | [Album](#album) | Yes | Target album. To place this album to the end, set **album** to null.| 4975 4976**Error codes** 4977 4978For details about the error codes, see [Universal Error Codes](../errorcode-universal.md) and [File Management Error Codes](../apis-core-file-kit/errorcode-filemanagement.md). 4979 4980| ID| Error Message| 4981| -------- | ---------------------------------------- | 4982| 202 | Called by non-system application. | 4983| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types; 3. Parameter verification failed. | 4984| 14000011 | System inner fail. | 4985 4986**Example** 4987 4988```ts 4989async function example() { 4990 console.info('placeBeforeDemo'); 4991 try { 4992 let albumFetchResult: photoAccessHelper.FetchResult<photoAccessHelper.Album> = await phAccessHelper.getAlbums(photoAccessHelper.AlbumType.USER, photoAccessHelper.AlbumSubtype.USER_GENERIC); 4993 let firstAlbum: photoAccessHelper.Album = await albumFetchResult.getFirstObject(); 4994 if (albumFetchResult.isAfterLast()) { 4995 console.error('lack of album to place before'); 4996 return; 4997 } 4998 let secondAlbum: photoAccessHelper.Album = await albumFetchResult.getNextObject(); 4999 let albumChangeRequest: photoAccessHelper.MediaAlbumChangeRequest = new photoAccessHelper.MediaAlbumChangeRequest(secondAlbum); 5000 albumChangeRequest.placeBefore(firstAlbum); 5001 await phAccessHelper.applyChanges(albumChangeRequest); 5002 console.info('placeBefore successfully'); 5003 } catch (err) { 5004 console.error(`placeBeforeDemo failed with error: ${err.code}, ${err.message}`); 5005 } 5006} 5007``` 5008 5009### dismiss<sup>13+</sup> 5010 5011dismiss(): void 5012 5013Removes this group photo album. 5014 5015**System API**: This is a system API. 5016 5017**System capability**: SystemCapability.FileManagement.PhotoAccessHelper.Core 5018 5019**Error codes** 5020 5021For details about the error codes, see [Universal Error Codes](../errorcode-universal.md) and [File Management Error Codes](../apis-core-file-kit/errorcode-filemanagement.md). 5022 5023| ID | Error Message | 5024| :------- | :-------------------------------- | 5025| 202 | Called by non-system application. | 5026| 401 | Parameter error. Possible causes: Incorrect parameter types. | 5027| 14000011 | System inner fail. | 5028 5029**Example** 5030 5031```ts 5032import { dataSharePredicates } from '@kit.ArkData'; 5033 5034async function example() { 5035 console.info('dismissDemo'); 5036 try { 5037 let albumFetchResult: photoAccessHelper.FetchResult<photoAccessHelper.Album> = await phAccessHelper.getAlbums(photoAccessHelper.AlbumType.SMART, photoAccessHelper.AlbumSubtype.GROUP_PHOTO); 5038 let album: photoAccessHelper.Album = await albumFetchResult.getFirstObject(); 5039 5040 let albumChangeRequest: photoAccessHelper.MediaAlbumChangeRequest = new photoAccessHelper.MediaAlbumChangeRequest(album); 5041 albumChangeRequest.dismiss(); 5042 await phAccessHelper.applyChanges(albumChangeRequest); 5043 console.info('dismiss successfully'); 5044 } catch (err) { 5045 console.error(`dismissDemo failed with error: ${err.code}, ${err.message}`); 5046 } 5047} 5048``` 5049 5050## HighlightAlbum<sup>12+</sup> 5051 5052Provides APIs for managing the **Highlights** album, which is an automatically generated collection of memorable photos or videos. 5053 5054**System API**: This is a system API. 5055 5056**System capability**: SystemCapability.FileManagement.PhotoAccessHelper.Core 5057 5058### constructor<sup>12+</sup> 5059 5060constructor(album: Album) 5061 5062A constructor used to create a **Highlights** album instance. 5063 5064**System API**: This is a system API. 5065 5066**System capability**: SystemCapability.FileManagement.PhotoAccessHelper.Core 5067 5068**Parameters** 5069 5070| Name | Type | Mandatory| Description | 5071| -------- | ------------------------- | ---- | ---------- | 5072| album | [Album](#album) | Yes | **Highlights** album to create.| 5073 5074**Error codes** 5075 5076For details about the error codes, see [Universal Error Codes](../errorcode-universal.md) and [File Management Error Codes](../apis-core-file-kit/errorcode-filemanagement.md). 5077 5078| ID| Error Message| 5079| -------- | ---------------------------------------- | 5080| 202 | Called by non-system application. | 5081| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types; 3. Parameter verification failed. | 5082| 14000011 | Internal system error. | 5083 5084**Example** 5085 5086```ts 5087import { dataSharePredicates } from '@kit.ArkData'; 5088 5089async function example() { 5090 console.info('HighlightAlbum constructorDemo'); 5091 let predicates: dataSharePredicates.DataSharePredicates = new dataSharePredicates.DataSharePredicates(); 5092 let fetchOption: photoAccessHelper.FetchOptions = { 5093 fetchColumns: [], 5094 predicates: predicates 5095 }; 5096 let albumFetchResult: photoAccessHelper.FetchResult<photoAccessHelper.Album> = await photoAccessHelper.getAlbums( 5097 photoAccessHelper.AlbumType.SMART, photoAccessHelper.AlbumSubtype.HIGHLIGHT, fetchOption); 5098 let album: photoAccessHelper.Album = await albumFetchResult.getFirstObject(); 5099 let highlightAlbum: photoAccessHelper.HighlightAlbum = new photoAccessHelper.HighlightAlbum(album); 5100 albumFetchResult.close(); 5101} 5102``` 5103 5104### getHighlightAlbumInfo<sup>12+</sup> 5105 5106getHighlightAlbumInfo(type: HighlightAlbumInfoType): Promise<string> 5107 5108Obtains specific information about the **Highlights** album. 5109 5110**System API**: This is a system API. 5111 5112**Required permissions**: ohos.permission.READ\_IMAGEVIDEO 5113 5114**System capability**: SystemCapability.FileManagement.PhotoAccessHelper.Core 5115 5116**Parameters** 5117 5118| Name | Type | Mandatory | Description | 5119| ---------- | ------- | ---- | ---------------------------------- | 5120| type | [HighlightAlbumInfoType](#highlightalbuminfotype12) | Yes | Type of the album information to obtain.| 5121 5122**Error codes** 5123 5124For details about the error codes, see [Universal Error Codes](../errorcode-universal.md) and [File Management Error Codes](../apis-core-file-kit/errorcode-filemanagement.md). 5125 5126| ID | Error Message | 5127| :------- | :-------------------------------- | 5128| 201 | Permission denied. | 5129| 202 | Called by non-system application. | 5130| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types; 3. Parameter verification failed. | 5131| 14000011 | Internal system error. | 5132 5133**Example** 5134 5135```ts 5136import { dataSharePredicates } from '@kit.ArkData'; 5137 5138async function example() { 5139 try { 5140 console.info('getHighlightAlbumInfoDemo') 5141 let fetchOptions: photoAccessHelper.FetchOptions = { 5142 fetchColumns: [], 5143 predicates: new dataSharePredicates.DataSharePredicates() 5144 } 5145 let albumFetchResult: photoAccessHelper.FetchResult<photoAccessHelper.Album> = await photoAccessHelper.getAlbums( 5146 photoAccessHelper.AlbumType.SMART, photoAccessHelper.AlbumSubtype.HIGHLIGHT, fetchOption); 5147 let album: photoAccessHelper.Album = await albumFetchResult.getFirstObject(); 5148 if (album != undefined) { 5149 let highlightAlbum: photoAccessHelper.HighlightAlbum = new photoAccessHelper.HighlightAlbum(album); 5150 let coverInfo: string = await highlightAlbum.getHighlightAlbumInfo( 5151 photoAccessHelper.HighlightAlbumInfoType.COVER_INFO); 5152 console.info('get cover info result: ' + JSON.stringify(coverInfo)); 5153 } 5154 5155 albumFetchResult.close(); 5156 } catch (err) { 5157 console.error(`getHighlightAlbumInfoDemofailed with error: ${err.code}, ${err.message}`); 5158 } 5159} 5160``` 5161 5162### getHighlightResource<sup>12+</sup> 5163 5164getHighlightResource(resourceUri: string): Promise<ArrayBuffer> 5165 5166Obtains the ArrayBuffer for caching the specified asset. 5167 5168**System API**: This is a system API. 5169 5170**Required permissions**: ohos.permission.READ\_IMAGEVIDEO 5171 5172**System capability**: SystemCapability.FileManagement.PhotoAccessHelper.Core 5173 5174**Parameters** 5175 5176| Name | Type | Mandatory | Description | 5177| ---------- | ------- | ---- | ---------------------------------- | 5178| resourceUri | string | Yes | URI of the asset to cache.| 5179 5180**Error codes** 5181 5182For details about the error codes, see [Universal Error Codes](../errorcode-universal.md) and [File Management Error Codes](../apis-core-file-kit/errorcode-filemanagement.md). 5183 5184| ID | Error Message | 5185| :------- | :-------------------------------- | 5186| 201 | Permission denied. | 5187| 202 | Called by non-system application. | 5188| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types; 3. Parameter verification failed. | 5189| 14000011 | Internal system error. | 5190 5191**Example** 5192 5193```ts 5194import { dataSharePredicates } from '@kit.ArkData'; 5195 5196async function example() { 5197 try { 5198 console.info('getHighlightResourceDemo') 5199 let fetchOptions: photoAccessHelper.FetchOptions = { 5200 fetchColumns: [], 5201 predicates: new dataSharePredicates.DataSharePredicates() 5202 } 5203 let albumFetchResult: photoAccessHelper.FetchResult<photoAccessHelper.Album> = await photoAccessHelper.getAlbums( 5204 photoAccessHelper.AlbumType.SMART, photoAccessHelper.AlbumSubtype.HIGHLIGHT, fetchOption); 5205 let album: photoAccessHelper.Album = await albumFetchResult.getFirstObject(); 5206 if (album != undefined) { 5207 let highlightAlbum: photoAccessHelper.HighlightAlbum = new photoAccessHelper.HighlightAlbum(album); 5208 let uri: string = 'file://media/highlight/cover/10/1_1/background.png?oper=highlight' 5209 let arrayBuffer: ArrayBuffer = await highlightAlbum.getHighlightResource(uri); 5210 } 5211 albumFetchResult.close(); 5212 } catch (err) { 5213 console.error(`getHighlightResourceDemofailed with error: ${err.code}, ${err.message}`); 5214 } 5215} 5216``` 5217 5218### setHighlightUserActionData<sup>12+</sup> 5219 5220setHighlightUserActionData(type: HighlightUserActionType, actionData: number): Promise<void> 5221 5222Sets the user behavior data for the **Highlights** album. 5223 5224**System API**: This is a system API. 5225 5226**Required permissions**: ohos.permission.WRITE\_IMAGEVIDEO 5227 5228**System capability**: SystemCapability.FileManagement.PhotoAccessHelper.Core 5229 5230**Parameters** 5231 5232| Name | Type | Mandatory | Description | 5233| ---------- | ------- | ---- | ---------------------------------- | 5234| type | [HighlightUserActionType](#highlightuseractiontype12) | Yes | Type of the user behavior data to set.| 5235| actionData | number | Yes | Behavior data.| 5236 5237**Error codes** 5238 5239For details about the error codes, see [Universal Error Codes](../errorcode-universal.md) and [File Management Error Codes](../apis-core-file-kit/errorcode-filemanagement.md). 5240 5241| ID | Error Message | 5242| :------- | :-------------------------------- | 5243| 201 | Permission denied. | 5244| 202 | Called by non-system application. | 5245| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types; 3. Parameter verification failed. | 5246| 14000011 | Internal system error. | 5247 5248**Example** 5249 5250```ts 5251import { dataSharePredicates } from '@kit.ArkData'; 5252 5253async function example() { 5254 try { 5255 console.info('setHighlightUserActionDataDemo') 5256 let fetchOptions: photoAccessHelper.FetchOptions = { 5257 fetchColumns: [], 5258 predicates: new dataSharePredicates.DataSharePredicates() 5259 } 5260 let albumFetchResult: photoAccessHelper.FetchResult<photoAccessHelper.Album> = await photoAccessHelper.getAlbums( 5261 photoAccessHelper.AlbumType.SMART, photoAccessHelper.AlbumSubtype.HIGHLIGHT, fetchOption); 5262 let album: photoAccessHelper.Album = await albumFetchResult.getFirstObject(); 5263 if (album != undefined) { 5264 let highlightAlbum: photoAccessHelper.HighlightAlbum = new photoAccessHelper.HighlightAlbum(album); 5265 highlightAlbum.setHighlightUserActionData(photoAccessHelper.HighlightUserActionType.INSERTED_PIC_COUNT, 1); 5266 } 5267 albumFetchResult.close(); 5268 } catch (err) { 5269 console.error(`setHighlightUserActionDataDemofailed with error: ${err.code}, ${err.message}`); 5270 } 5271} 5272``` 5273 5274## CloudEnhancement<sup>13+</sup> 5275 5276Provides APIs for cloud enhancement management, including managing the tasks of generating AI-powered cloud enhancement photos and obtaining the association between the original photos and AI cloud enhancement photos. 5277 5278**System API**: This is a system API. 5279 5280**System capability**: SystemCapability.FileManagement.PhotoAccessHelper.Core 5281 5282### getCloudEnhancementInstance<sup>13+</sup> 5283 5284static getCloudEnhancementInstance(context: Context): CloudEnhancement 5285 5286Obtains a cloud enhancement instance. 5287 5288**System API**: This is a system API. 5289 5290**System capability**: SystemCapability.FileManagement.PhotoAccessHelper.Core 5291 5292**Parameters** 5293 5294| Name | Type | Mandatory| Description | 5295| -------- | ------------------------- | ---- | ---------- | 5296| context | [Context](../apis-ability-kit/js-apis-inner-application-context.md) | Yes | Context of the ability instance.| 5297 5298**Error codes** 5299 5300For details about the error codes, see [Universal Error Codes](../errorcode-universal.md) and [File Management Error Codes](../apis-core-file-kit/errorcode-filemanagement.md). 5301 5302| ID| Error Message| 5303| -------- | ---------------------------------------- | 5304| 202 | Called by non-system application. | 5305| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types; 3. Parameter verification failed. | 5306| 14000011 | Internal system error. | 5307 5308**Example** 5309 5310```ts 5311import { dataSharePredicates } from '@kit.ArkData'; 5312 5313async function example() { 5314 console.info('getCloudEnhancementInstanceDemo'); 5315 let photoPredicates: dataSharePredicates.DataSharePredicates = new dataSharePredicates.DataSharePredicates(); 5316 let photoFetchOptions: photoAccessHelper.FetchOptions = { 5317 fetchColumns: [], 5318 predicates: photoPredicates 5319 }; 5320 let phAccessHelper = photoAccessHelper.getPhotoAccessHelper(context); 5321 try { 5322 let fetchResult = await phAccessHelper.getAssets(photoFetchOptions); 5323 let asset = await fetchResult.getLastObject(); 5324 let cloudEnhancementInstance: photoAccessHelper.CloudEnhancement 5325 = photoAccessHelper.CloudEnhancement.getCloudEnhancementInstance(context); 5326 let hasCloudWatermark = true; 5327 await cloudEnhancementInstance.submitCloudEnhancementTasks([asset], hasCloudWatermark); 5328 } catch (err) { 5329 console.error(`getCloudEnhancementInstanceDemo failed with error: ${err.code}, ${err.message}`); 5330 } 5331} 5332``` 5333 5334### submitCloudEnhancementTasks<sup>13+</sup> 5335 5336submitCloudEnhancementTasks(photoAssets: Array<PhotoAsset>, hasCloudWatermark: boolean): Promise<void> 5337 5338Submits cloud enhancement tasks. 5339 5340**System API**: This is a system API. 5341 5342**System capability**: SystemCapability.FileManagement.PhotoAccessHelper.Core 5343 5344**Parameters** 5345 5346| Name | Type | Mandatory| Description | 5347| -------- | ------------------------- | ---- | ---------- | 5348| photoAssets | Array<[PhotoAsset](#photoasset)> | Yes | [PhotoAsset](#photoasset) to enhance.| 5349| hasCloudWatermark | boolean | Yes | Whether to add a cloud enhancement watermark to the enhanced images.| 5350 5351**Error codes** 5352 5353For details about the error codes, see [Universal Error Codes](../errorcode-universal.md) and [File Management Error Codes](../apis-core-file-kit/errorcode-filemanagement.md). 5354 5355| ID| Error Message| 5356| -------- | ---------------------------------------- | 5357| 201 | Permission denied. | 5358| 202 | Called by non-system application. | 5359| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types; 3. Parameter verification failed. | 5360| 14000011 | Internal system error. | 5361 5362**Example** 5363 5364```ts 5365import { dataSharePredicates } from '@kit.ArkData'; 5366 5367async function example() { 5368 console.info('submitCloudEnhancementTasksDemo'); 5369 let photoPredicates: dataSharePredicates.DataSharePredicates = new dataSharePredicates.DataSharePredicates(); 5370 let photoFetchOptions: photoAccessHelper.FetchOptions = { 5371 fetchColumns: [], 5372 predicates: photoPredicates 5373 }; 5374 let phAccessHelper = photoAccessHelper.getPhotoAccessHelper(context); 5375 try { 5376 let fetchResult = await phAccessHelper.getAssets(photoFetchOptions); 5377 let asset = await fetchResult.getLastObject(); 5378 let cloudEnhancementInstance: photoAccessHelper.CloudEnhancement 5379 = photoAccessHelper.CloudEnhancement.getCloudEnhancementInstance(context); 5380 let hasCloudWatermark = true; 5381 await cloudEnhancementInstance.submitCloudEnhancementTasks([asset], hasCloudWatermark); 5382 } catch (err) { 5383 console.error(`submitCloudEnhancementTasksDemo failed with error: ${err.code}, ${err.message}`); 5384 } 5385} 5386``` 5387 5388### prioritizeCloudEnhancementTask<sup>13+</sup> 5389 5390prioritizeCloudEnhancementTask(photoAsset: PhotoAsset): Promise<void> 5391 5392Prioritizes a cloud enhancement task. 5393 5394**System API**: This is a system API. 5395 5396**System capability**: SystemCapability.FileManagement.PhotoAccessHelper.Core 5397 5398**Parameters** 5399 5400| Name | Type | Mandatory| Description | 5401| -------- | ------------------------- | ---- | ---------- | 5402| photoAsset | [PhotoAsset](#photoasset) | Yes | [PhotoAsset](#photoasset) whose cloud enhancement priority needs to be escalated.| 5403 5404**Error codes** 5405 5406For details about the error codes, see [Universal Error Codes](../errorcode-universal.md) and [File Management Error Codes](../apis-core-file-kit/errorcode-filemanagement.md). 5407 5408| ID| Error Message| 5409| -------- | ---------------------------------------- | 5410| 201 | Permission denied. | 5411| 202 | Called by non-system application. | 5412| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types; 3. Parameter verification failed. | 5413| 14000011 | Internal system error. | 5414 5415**Example** 5416 5417```ts 5418import { dataSharePredicates } from '@kit.ArkData'; 5419 5420async function example() { 5421 console.info('prioritizeCloudEnhancementTaskDemo'); 5422 let photoPredicates: dataSharePredicates.DataSharePredicates = new dataSharePredicates.DataSharePredicates(); 5423 // Obtain the cloud enhancement tasks in progress. 5424 photoPredicates.equalTo(photoAccessHelper.PhotoKeys.CE_AVAILABLE, 2); 5425 let photoFetchOptions: photoAccessHelper.FetchOptions = { 5426 fetchColumns: [], 5427 predicates: photoPredicates 5428 }; 5429 let phAccessHelper = photoAccessHelper.getPhotoAccessHelper(context); 5430 try { 5431 let fetchResult = await phAccessHelper.getAssets(photoFetchOptions); 5432 let asset = await fetchResult.getLastObject(); 5433 let cloudEnhancementInstance: photoAccessHelper.CloudEnhancement 5434 = photoAccessHelper.CloudEnhancement.getCloudEnhancementInstance(context); 5435 let hasCloudWatermark = true; 5436 await cloudEnhancementInstance.prioritizeCloudEnhancementTask(asset); 5437 } catch (err) { 5438 console.error(`prioritizeCloudEnhancementTaskDemo failed with error: ${err.code}, ${err.message}`); 5439 } 5440} 5441``` 5442 5443### cancelCloudEnhancementTasks<sup>13+</sup> 5444 5445cancelCloudEnhancementTasks(photoAssets: Array<PhotoAsset>): Promise<void> 5446 5447Cancels cloud enhancement tasks. 5448 5449**System API**: This is a system API. 5450 5451**System capability**: SystemCapability.FileManagement.PhotoAccessHelper.Core 5452 5453**Parameters** 5454 5455| Name | Type | Mandatory| Description | 5456| -------- | ------------------------- | ---- | ---------- | 5457| photoAssets | Array<[PhotoAsset](#photoasset)> | Yes | Array of [PhotoAssets](#photoasset) whose cloud enhancement tasks are to be canceled.| 5458 5459**Error codes** 5460 5461For details about the error codes, see [Universal Error Codes](../errorcode-universal.md) and [File Management Error Codes](../apis-core-file-kit/errorcode-filemanagement.md). 5462 5463| ID| Error Message| 5464| -------- | ---------------------------------------- | 5465| 201 | Permission denied. | 5466| 202 | Called by non-system application. | 5467| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types; 3. Parameter verification failed. | 5468| 14000011 | Internal system error. | 5469 5470**Example** 5471 5472```ts 5473import { dataSharePredicates } from '@kit.ArkData'; 5474 5475async function example() { 5476 console.info('cancelCloudEnhancementTasksDemo'); 5477 let photoPredicates: dataSharePredicates.DataSharePredicates = new dataSharePredicates.DataSharePredicates(); 5478 // Obtain the cloud enhancement tasks in progress. 5479 photoPredicates.equalTo(photoAccessHelper.PhotoKeys.CE_AVAILABLE, 2); 5480 let photoFetchOptions: photoAccessHelper.FetchOptions = { 5481 fetchColumns: [], 5482 predicates: photoPredicates 5483 }; 5484 let phAccessHelper = photoAccessHelper.getPhotoAccessHelper(context); 5485 try { 5486 let fetchResult = await phAccessHelper.getAssets(photoFetchOptions); 5487 let asset = await fetchResult.getLastObject(); 5488 let cloudEnhancementInstance: photoAccessHelper.CloudEnhancement 5489 = photoAccessHelper.CloudEnhancement.getCloudEnhancementInstance(context); 5490 await cloudEnhancementInstance.cancelCloudEnhancementTasks([asset]); 5491 } catch (err) { 5492 console.error(`cancelCloudEnhancementTasksDemo failed with error: ${err.code}, ${err.message}`); 5493 } 5494} 5495``` 5496 5497### cancelAllCloudEnhancementTasks<sup>13+</sup> 5498 5499cancelAllCloudEnhancementTasks(): Promise<void> 5500 5501Cancels all cloud enhancement tasks. 5502 5503**System API**: This is a system API. 5504 5505**System capability**: SystemCapability.FileManagement.PhotoAccessHelper.Core 5506 5507**Error codes** 5508 5509For details about the error codes, see [Universal Error Codes](../errorcode-universal.md) and [File Management Error Codes](../apis-core-file-kit/errorcode-filemanagement.md). 5510 5511| ID| Error Message| 5512| -------- | ---------------------------------------- | 5513| 201 | Permission denied. | 5514| 202 | Called by non-system application. | 5515| 14000011 | Internal system error. | 5516 5517**Example** 5518 5519```ts 5520import { dataSharePredicates } from '@kit.ArkData'; 5521 5522async function example() { 5523 console.info('cancelAllCloudEnhancementTasksDemo'); 5524 try { 5525 let cloudEnhancementInstance: photoAccessHelper.CloudEnhancement 5526 = photoAccessHelper.CloudEnhancement.getCloudEnhancementInstance(context); 5527 await cloudEnhancementInstance.cancelCloudEnhancementTasks(); 5528 } catch (err) { 5529 console.error(`cancelAllCloudEnhancementTasksDemo failed with error: ${err.code}, ${err.message}`); 5530 } 5531} 5532``` 5533 5534### queryCloudEnhancementTaskState<sup>13+</sup> 5535 5536queryCloudEnhancementTaskState(photoAsset: PhotoAsset): Promise<CloudEnhancementTaskState> 5537 5538Queries information about a cloud enhancement task. 5539 5540**System API**: This is a system API. 5541 5542**System capability**: SystemCapability.FileManagement.PhotoAccessHelper.Core 5543 5544**Parameters** 5545 5546| Name | Type | Mandatory| Description | 5547| -------- | ------------------------- | ---- | ---------- | 5548| photoAsset | [PhotoAsset](#photoasset) | Yes | [PhotoAsset](#photoasset) whose cloud enhancement task information is to be queried.| 5549 5550**Error codes** 5551 5552For details about the error codes, see [Universal Error Codes](../errorcode-universal.md) and [File Management Error Codes](../apis-core-file-kit/errorcode-filemanagement.md). 5553 5554| ID| Error Message| 5555| -------- | ---------------------------------------- | 5556| 201 | Permission denied. | 5557| 202 | Called by non-system application. | 5558| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types; 3. Parameter verification failed. | 5559| 14000011 | Internal system error. | 5560 5561**Example** 5562 5563```ts 5564import { dataSharePredicates } from '@kit.ArkData'; 5565 5566async function example() { 5567 console.info('queryCloudEnhancementTaskStateDemo'); 5568 let photoPredicates: dataSharePredicates.DataSharePredicates = new dataSharePredicates.DataSharePredicates(); 5569 // Obtain the cloud enhancement tasks in progress. 5570 photoPredicates.equalTo(photoAccessHelper.PhotoKeys.CE_AVAILABLE, 2); 5571 let photoFetchOptions: photoAccessHelper.FetchOptions = { 5572 fetchColumns: [], 5573 predicates: photoPredicates 5574 }; 5575 let phAccessHelper = photoAccessHelper.getPhotoAccessHelper(context); 5576 try { 5577 let fetchResult = await phAccessHelper.getAssets(photoFetchOptions); 5578 let asset = await fetchResult.getLastObject(); 5579 let cloudEnhancementInstance: photoAccessHelper.CloudEnhancement 5580 = photoAccessHelper.CloudEnhancement.getCloudEnhancementInstance(context); 5581 const cloudEnhancementTaskState: photoAccessHelper.CloudEnhancementTaskState 5582 = await cloudEnhancementInstance.queryCloudEnhancementTaskState(asset); 5583 let taskStage = cloudEnhancementTaskState.taskStage; 5584 if (taskStage == photoAccessHelper.CloudEnhancementTaskStage.TASK_STAGE_EXCEPTION) { 5585 console.log("task has exception"); 5586 } else if (taskStage == photoAccessHelper.CloudEnhancementTaskStage.TASK_STAGE_PREPARING) { 5587 console.log("task is preparing"); 5588 } else if (taskStage == photoAccessHelper.CloudEnhancementTaskStage.TASK_STAGE_UPLOADING) { 5589 let transferredFileSize = cloudEnhancementTaskState.transferredFileSize; 5590 let totalFileSize = cloudEnhancementTaskState.totalFileSize; 5591 let message = `task is uploading, transferredFileSize: ${transferredFileSize}, totalFileSize: ${totalFileSize}`; 5592 console.log(message); 5593 } else if (taskStage == photoAccessHelper.CloudEnhancementTaskStage.TASK_STAGE_EXECUTING) { 5594 let expectedDuration = cloudEnhancementTaskState.expectedDuration; 5595 let message = `task is executing, expectedDuration: ${expectedDuration}`; 5596 console.log(message); 5597 } else if (taskStage == photoAccessHelper.CloudEnhancementTaskStage.TASK_STAGE_DOWNLOADING) { 5598 let transferredFileSize = cloudEnhancementTaskState.transferredFileSize; 5599 let totalFileSize = cloudEnhancementTaskState.totalFileSize; 5600 let message = `task is downloading, transferredFileSize: ${transferredFileSize}, totalFileSize: ${totalFileSize}`; 5601 console.log(message); 5602 } else if (taskStage == photoAccessHelper.CloudEnhancementTaskStage.TASK_STAGE_FAILED) { 5603 let errCode = cloudEnhancementTaskState.statusCode; 5604 let message = `task is failed, errCode: ${errCode}`; 5605 console.log(message); 5606 } else if (taskStage == photoAccessHelper.CloudEnhancementTaskStage.TASK_STAGE_COMPLETED) { 5607 console.log("task is completed"); 5608 } 5609 } catch (err) { 5610 console.error(`queryCloudEnhancementTaskStateDemo failed with error: ${err.code}, ${err.message}`); 5611 } 5612} 5613``` 5614 5615### syncCloudEnhancementTaskStatus<sup>13+</sup> 5616 5617syncCloudEnhancementTaskStatus(): Promise<void> 5618 5619Synchronizes the cloud enhancement task status. 5620 5621**System API**: This is a system API. 5622 5623**System capability**: SystemCapability.FileManagement.PhotoAccessHelper.Core 5624 5625**Error codes** 5626 5627For details about the error codes, see [Universal Error Codes](../errorcode-universal.md) and [File Management Error Codes](../apis-core-file-kit/errorcode-filemanagement.md). 5628 5629| ID| Error Message| 5630| -------- | ---------------------------------------- | 5631| 201 | Permission denied. | 5632| 202 | Called by non-system application. | 5633| 14000011 | Internal system error. | 5634 5635**Example** 5636 5637```ts 5638import { dataSharePredicates } from '@kit.ArkData'; 5639 5640async function example() { 5641 console.info('syncCloudEnhancementTaskStatusDemo'); 5642 try { 5643 let cloudEnhancementInstance: photoAccessHelper.CloudEnhancement 5644 = photoAccessHelper.CloudEnhancement.getCloudEnhancementInstance(context); 5645 await cloudEnhancementInstance.syncCloudEnhancementTaskStatus(); 5646 } catch (err) { 5647 console.error(`syncCloudEnhancementTaskStatusDemo failed with error: ${err.code}, ${err.message}`); 5648 } 5649} 5650``` 5651 5652### getCloudEnhancementPair<sup>13+</sup> 5653 5654getCloudEnhancementPair(asset: PhotoAsset): Promise<PhotoAsset> 5655 5656Obtains the photo after cloud enhancement. 5657 5658**System API**: This is a system API. 5659 5660**System capability**: SystemCapability.FileManagement.PhotoAccessHelper.Core 5661 5662**Parameters** 5663 5664| Name | Type | Mandatory| Description | 5665| -------- | ------------------------- | ---- | ---------- | 5666| photoAsset | [PhotoAsset](#photoasset) | Yes | [PhotoAsset](#photoasset) whose cloud enhancement photo is to be obtained.| 5667 5668**Error codes** 5669 5670For details about the error codes, see [Universal Error Codes](../errorcode-universal.md) and [File Management Error Codes](../apis-core-file-kit/errorcode-filemanagement.md). 5671 5672| ID| Error Message| 5673| -------- | ---------------------------------------- | 5674| 201 | Permission denied. | 5675| 202 | Called by non-system application. | 5676| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types; 3. Parameter verification failed. | 5677| 14000011 | Internal system error. | 5678 5679**Example** 5680 5681```ts 5682import { dataSharePredicates } from '@kit.ArkData'; 5683 5684async function example() { 5685 console.info('getCloudEnhancementPairDemo'); 5686 let photoPredicates: dataSharePredicates.DataSharePredicates = new dataSharePredicates.DataSharePredicates(); 5687 // Query the completed cloud enhancement tasks. 5688 photoPredicates.equalTo(photoAccessHelper.PhotoKeys.CE_AVAILABLE, 5); 5689 let photoFetchOptions: photoAccessHelper.FetchOptions = { 5690 fetchColumns: [], 5691 predicates: photoPredicates 5692 }; 5693 let phAccessHelper = photoAccessHelper.getPhotoAccessHelper(context); 5694 try { 5695 let fetchResult = await phAccessHelper.getAssets(photoFetchOptions); 5696 let asset = await fetchResult.getLastObject(); 5697 let cloudEnhancementInstance: photoAccessHelper.CloudEnhancement 5698 = photoAccessHelper.CloudEnhancement.getCloudEnhancementInstance(context); 5699 let photoAsset: photoAccessHelper.PhotoAsset 5700 = await cloudEnhancementInstance.getCloudEnhancementPair(asset); 5701 } catch (err) { 5702 console.error(`getCloudEnhancementPairDemo failed with error: ${err.code}, ${err.message}`); 5703 } 5704} 5705``` 5706 5707### setVideoEnhancementAttr<sup>13+</sup> 5708 5709setVideoEnhancementAttr(videoEnhancementType: VideoEnhancementType, photoId: string): Promise<void> 5710 5711Sets the attributes for deferred video enhancement. 5712 5713**System API**: This is a system API. 5714 5715**Required permissions**: ohos.permission.WRITE\_IMAGEVIDEO 5716 5717**System capability**: SystemCapability.FileManagement.PhotoAccessHelper.Core 5718 5719**Parameters** 5720 5721| Name | Type | Mandatory | Description | 5722| ---------- | ------- | ---- | ---------------------------------- | 5723| videoEnhancementType | [VideoEnhancementType](#videoenhancementtype13) | Yes | Type of video enhancement.| 5724| photoId | string | Yes | Photo ID of the image.| 5725 5726**Error codes** 5727 5728For details about the error codes, see [Universal Error Codes](../errorcode-universal.md) and [File Management Error Codes](../apis-core-file-kit/errorcode-filemanagement.md). 5729 5730| ID | Error Message | 5731| :------- | :-------------------------------- | 5732| 202 | Called by non-system application. | 5733| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types; 3. Parameter verification failed. | 5734| 14000011 | Internal system error. | 5735| 14000016 | Operation Not Support. | 5736 5737**Example** 5738 5739```ts 5740async function example(asset: photoAccessHelper.PhotoAsset) { 5741 try { 5742 let assetChangeRequest: photoAccessHelper.MediaAssetChangeRequest = new photoAccessHelper.MediaAssetChangeRequest(asset); 5743 let photoId = "202410011800"; 5744 assetChangeRequest.setVideoEnhancementAttr(photoAccessHelper.VideoEnhancementType.QUALITY_ENHANCEMENT_LOCAL, photoId); 5745 await phAccessHelper.applyChanges(assetChangeRequest); 5746 } catch (err) { 5747 console.error(`setVideoEnhancementAttr fail with error: ${err.code}, ${err.message}`); 5748 } 5749} 5750``` 5751 5752### getFaceId<sup>13+</sup> 5753 5754getFaceId(): Promise\<string> 5755 5756Obtains the face identifier on the cover of a portrait album or group photo album. 5757 5758**System API**: This is a system API. 5759 5760**Required permissions**: ohos.permission.READ\_IMAGEVIDEO 5761 5762**System capability**: SystemCapability.FileManagement.PhotoAccessHelper.Core 5763 5764**Return value** 5765 5766| Type | Description | 5767| :------------------ | :---------------------------------- | 5768| Promise<string> | Promise used to return **tag_id** of the portrait album, **group_tag** of the group photo album, or an empty string if no face identifier is found.| 5769 5770**Error codes** 5771 5772For details about the error codes, see [Universal Error Codes](../errorcode-universal.md) and [File Management Error Codes](../apis-core-file-kit/errorcode-filemanagement.md). 5773 5774| ID| Error Message | 5775| :------- | :----------------------------------------------------------- | 5776| 201 | Permission denied. | 5777| 202 | Called by non-system application. | 5778| 14000011 | Internal system error | 5779 5780**Example** 5781 5782```ts 5783import { dataSharePredicates } from '@kit.ArkData'; 5784 5785async function example() { 5786 try { 5787 console.info('getFaceIdDemo'); 5788 let predicates: dataSharePredicates.DataSharePredicates = new dataSharePredicates.DataSharePredicates(); 5789 predicates.equalTo("user_display_level", 1); 5790 let fetchOptions: photoAccessHelper.FetchOptions = { 5791 fetchColumns: [], 5792 predicates: predicates 5793 }; 5794 let fetchResult = 5795 await phAccessHelper.getAlbums(photoAccessHelper.AlbumType.SMART, photoAccessHelper.AlbumSubtype.PORTRAIT, 5796 fetchOptions); 5797 let album = await fetchResult?.getFirstObject(); 5798 let faceId = await album?.getFaceId(); 5799 console.info(`getFaceId successfully, faceId: ${faceId}`); 5800 fetchResult.close(); 5801 } catch (err) { 5802 console.error(`getFaceId failed with err: ${err.code}, ${err.message}`); 5803 } 5804} 5805``` 5806 5807## CloudMediaAssetManager<sup>14+</sup> 5808 5809A class used for cloud media asset management. It is used to manage download tasks for media assets stored in the cloud and delete local data and files pertaining to these cloud-based assets. 5810 5811**System API**: This is a system API. 5812 5813**System capability**: SystemCapability.FileManagement.PhotoAccessHelper.Core 5814 5815### getCloudMediaAssetManagerInstance<sup>14+</sup> 5816 5817static getCloudMediaAssetManagerInstance(context: Context): CloudMediaAssetManager 5818 5819Obtains a CloudMediaAssetManager instance. 5820 5821**System API**: This is a system API. 5822 5823**System capability**: SystemCapability.FileManagement.PhotoAccessHelper.Core 5824 5825**Parameters** 5826 5827| Name | Type | Mandatory| Description | 5828| -------- | ------------------------- | ---- | ---------- | 5829| context | [Context](../apis-ability-kit/js-apis-inner-application-context.md) | Yes | Context of the ability instance.| 5830 5831**Return value** 5832 5833| Type | Description | 5834| --------------------------------------- | ----------------- | 5835| [CloudMediaAssetManager](#cloudmediaassetmanager14) | CloudMediaAssetManager instance.| 5836 5837**Error codes** 5838 5839For details about the error codes, see [Universal Error Codes](../errorcode-universal.md) and [File Management Error Codes](../apis-core-file-kit/errorcode-filemanagement.md). 5840 5841| ID| Error Message| 5842| -------- | ---------------------------------------- | 5843| 202 | Called by non-system application. | 5844| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types; 3. Parameter verification failed. | 5845| 14000011 | Internal system error. It is recommended to retry and check the logs. Possible causes: 1. Database corrupted; 2. The file system is abnormal; 3. The IPC request timed out. | 5846 5847**Example** 5848 5849```ts 5850import photoAccessHelper from '@ohos.file.photoAccessHelper' 5851const context = getContext(this); 5852async function example() { 5853 console.info('getCloudMediaAssetManagerInstanceDemo'); 5854 try { 5855 let cloudMediaAssetManagerInstance: photoAccessHelper.CloudMediaAssetManager 5856 = photoAccessHelper.CloudMediaAssetManager.getCloudMediaAssetManagerInstance(context); 5857 await cloudMediaAssetManagerInstance.pauseDownloadCloudMedia(); 5858 } catch (err) { 5859 console.error(`getCloudMediaAssetManagerInstanceDemo failed with error: ${err.code}, ${err.message}`); 5860 } 5861} 5862``` 5863 5864### startDownloadCloudMedia<sup>14+</sup> 5865 5866startDownloadCloudMedia(downloadType: CloudMediaDownloadType): Promise<void> 5867 5868Starts or resumes a task to download cloud media assets. 5869 5870**System API**: This is a system API. 5871 5872**System capability**: SystemCapability.FileManagement.PhotoAccessHelper.Core 5873 5874**Parameters** 5875 5876| Name | Type | Mandatory| Description | 5877| -------- | ------------------------- | ---- | ---------- | 5878| downloadType | [CloudMediaDownloadType](#cloudmediadownloadtype14) | Yes | Type of the download task.| 5879 5880**Return value** 5881 5882| Type | Description | 5883| --------------------------------------- | ----------------- | 5884| Promise<void>| Promise that returns no value.| 5885 5886**Error codes** 5887 5888For details about the error codes, see [Universal Error Codes](../errorcode-universal.md) and [File Management Error Codes](../apis-core-file-kit/errorcode-filemanagement.md). 5889 5890| ID| Error Message| 5891| -------- | ---------------------------------------- | 5892| 201 | Permission denied. | 5893| 202 | Called by non-system application. | 5894| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types; 3. Parameter verification failed. | 5895| 14000011 | Internal system error. It is recommended to retry and check the logs. Possible causes: 1. Database corrupted; 2. The file system is abnormal; 3. The IPC request timed out. | 5896 5897**Example** 5898 5899```ts 5900import photoAccessHelper from '@ohos.file.photoAccessHelper' 5901const context = getContext(this); 5902async function example() { 5903 console.info('startDownloadCloudMediaDemo'); 5904 try { 5905 let cloudMediaAssetManagerInstance: photoAccessHelper.CloudMediaAssetManager 5906 = photoAccessHelper.CloudMediaAssetManager.getCloudMediaAssetManagerInstance(context); 5907 await cloudMediaAssetManagerInstance.startDownloadCloudMedia(photoAccessHelper.CloudMediaDownloadType.DOWNLOAD_FORCE); 5908 } catch (err) { 5909 console.error(`startDownloadCloudMediaDemo failed with error: ${err.code}, ${err.message}`); 5910 } 5911} 5912``` 5913 5914### pauseDownloadCloudMedia<sup>14+</sup> 5915 5916pauseDownloadCloudMedia(): Promise<void> 5917 5918Suspends a task that downloads cloud media assets. 5919 5920**System API**: This is a system API. 5921 5922**System capability**: SystemCapability.FileManagement.PhotoAccessHelper.Core 5923 5924**Return value** 5925 5926| Type | Description | 5927| --------------------------------------- | ----------------- | 5928| Promise<void>| Promise that returns no value.| 5929 5930**Error codes** 5931 5932For details about the error codes, see [Universal Error Codes](../errorcode-universal.md) and [File Management Error Codes](../apis-core-file-kit/errorcode-filemanagement.md). 5933 5934| ID| Error Message| 5935| -------- | ---------------------------------------- | 5936| 201 | Permission denied. | 5937| 202 | Called by non-system application. | 5938| 14000011 | Internal system error. It is recommended to retry and check the logs. Possible causes: 1. Database corrupted; 2. The file system is abnormal; 3. The IPC request timed out. | 5939 5940**Example** 5941 5942```ts 5943import photoAccessHelper from '@ohos.file.photoAccessHelper' 5944const context = getContext(this); 5945async function example() { 5946 console.info('pauseDownloadCloudMediaDemo'); 5947 try { 5948 let cloudMediaAssetManagerInstance: photoAccessHelper.CloudMediaAssetManager 5949 = photoAccessHelper.CloudMediaAssetManager.getCloudMediaAssetManagerInstance(context); 5950 await cloudMediaAssetManagerInstance.pauseDownloadCloudMedia(); 5951 } catch (err) { 5952 console.error(`pauseDownloadCloudMediaDemo failed with error: ${err.code}, ${err.message}`); 5953 } 5954} 5955``` 5956 5957### cancelDownloadCloudMedia<sup>14+</sup> 5958 5959cancelDownloadCloudMedia(): Promise<void> 5960 5961Cancels a task that downloads cloud media assets. 5962 5963**System API**: This is a system API. 5964 5965**System capability**: SystemCapability.FileManagement.PhotoAccessHelper.Core 5966 5967**Return value** 5968 5969| Type | Description | 5970| --------------------------------------- | ----------------- | 5971| Promise<void>| Promise that returns no value.| 5972 5973**Error codes** 5974 5975For details about the error codes, see [Universal Error Codes](../errorcode-universal.md) and [File Management Error Codes](../apis-core-file-kit/errorcode-filemanagement.md). 5976 5977| ID| Error Message| 5978| -------- | ---------------------------------------- | 5979| 201 | Permission denied. | 5980| 202 | Called by non-system application. | 5981| 14000011 | Internal system error. It is recommended to retry and check the logs. Possible causes: 1. Database corrupted; 2. The file system is abnormal; 3. The IPC request timed out. | 5982 5983**Example** 5984 5985```ts 5986import photoAccessHelper from '@ohos.file.photoAccessHelper' 5987const context = getContext(this); 5988async function example() { 5989 console.info('cancelDownloadCloudMediaDemo'); 5990 try { 5991 let cloudMediaAssetManagerInstance: photoAccessHelper.CloudMediaAssetManager 5992 = photoAccessHelper.CloudMediaAssetManager.getCloudMediaAssetManagerInstance(context); 5993 await cloudMediaAssetManagerInstance.cancelDownloadCloudMedia(); 5994 } catch (err) { 5995 console.error(`cancelDownloadCloudMediaDemo failed with error: ${err.code}, ${err.message}`); 5996 } 5997} 5998``` 5999 6000### retainCloudMediaAsset<sup>14+</sup> 6001 6002retainCloudMediaAsset(retainType: CloudMediaRetainType): Promise<void> 6003 6004Deletes local metadata and files of cloud media assets. 6005 6006**System API**: This is a system API. 6007 6008**System capability**: SystemCapability.FileManagement.PhotoAccessHelper.Core 6009 6010**Parameters** 6011 6012| Name | Type | Mandatory| Description | 6013| -------- | ------------------------- | ---- | ---------- | 6014| retainType | [CloudMediaRetainType](#cloudmediaretaintype14) | Yes | Mode for deleting cloud media assets.| 6015 6016**Return value** 6017 6018| Type | Description | 6019| --------------------------------------- | ----------------- | 6020| Promise<void>| Promise that returns no value.| 6021 6022**Error codes** 6023 6024For details about the error codes, see [Universal Error Codes](../errorcode-universal.md) and [File Management Error Codes](../apis-core-file-kit/errorcode-filemanagement.md). 6025 6026| ID| Error Message| 6027| -------- | ---------------------------------------- | 6028| 201 | Permission denied. | 6029| 202 | Called by non-system application. | 6030| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types; 3. Parameter verification failed. | 6031| 14000011 | Internal system error. It is recommended to retry and check the logs. Possible causes: 1. Database corrupted; 2. The file system is abnormal; 3. The IPC request timed out. | 6032 6033**Example** 6034 6035```ts 6036import photoAccessHelper from '@ohos.file.photoAccessHelper' 6037const context = getContext(this); 6038async function example() { 6039 console.info('retainCloudMediaAssetDemo'); 6040 try { 6041 let cloudMediaAssetManagerInstance: photoAccessHelper.CloudMediaAssetManager 6042 = photoAccessHelper.CloudMediaAssetManager.getCloudMediaAssetManagerInstance(context); 6043 await cloudMediaAssetManagerInstance.retainCloudMediaAsset(photoAccessHelper.CloudMediaRetainType.RETAIN_FORCE); 6044 } catch (err) { 6045 console.error(`retainCloudMediaAssetDemo failed with error: ${err.code}, ${err.message}`); 6046 } 6047} 6048``` 6049 6050### getCloudMediaAssetStatus<sup>14+</sup> 6051 6052getCloudMediaAssetStatus(): Promise<CloudMediaAssetStatus> 6053 6054Obtains the status of a task that downloads cloud media assets. 6055 6056**System API**: This is a system API. 6057 6058**System capability**: SystemCapability.FileManagement.PhotoAccessHelper.Core 6059 6060**Return value** 6061 6062| Type | Description | 6063| --------------------------------------- | ----------------- | 6064|Promise<[CloudMediaAssetStatus](#cloudmediaassetstatus14)> | Promise used to return the task status.| 6065 6066**Error codes** 6067 6068For details about the error codes, see [Universal Error Codes](../errorcode-universal.md) and [File Management Error Codes](../apis-core-file-kit/errorcode-filemanagement.md). 6069 6070| ID| Error Message| 6071| -------- | ---------------------------------------- | 6072| 201 | Permission denied. | 6073| 202 | Called by non-system application. | 6074| 14000011 | Internal system error. It is recommended to retry and check the logs. Possible causes: 1. Database corrupted; 2. The file system is abnormal; 3. The IPC request timed out. | 6075 6076**Example** 6077 6078```ts 6079import photoAccessHelper from '@ohos.file.photoAccessHelper' 6080const context = getContext(this); 6081async function example() { 6082 console.info('getCloudMediaAssetStatusDemo'); 6083 try { 6084 let cloudMediaAssetManagerInstance: photoAccessHelper.CloudMediaAssetManager 6085 = photoAccessHelper.CloudMediaAssetManager.getCloudMediaAssetManagerInstance(context); 6086 const cloudMediaAssetStatus: photoAccessHelper.CloudMediaAssetStatus = await cloudMediaAssetManagerInstance.getCloudMediaAssetStatus(); 6087 let taskStatus = cloudMediaAssetStatus.taskStatus; 6088 let taskInfo = cloudMediaAssetStatus.taskInfo; 6089 let errorCode = cloudMediaAssetStatus.errorCode; 6090 let message = `taskStatus: ${taskStatus}, taskInfo: ${taskInfo}, errorCode: ${errorCode}`; 6091 console.log(message); 6092 } catch (err) { 6093 console.error(`getCloudMediaAssetStatusDemo failed with error: ${err.code}, ${err.message}`); 6094 } 6095} 6096``` 6097 6098## PhotoSubtype 6099 6100Enumerates the [PhotoAsset](#photoasset) types. 6101 6102**System capability**: SystemCapability.FileManagement.PhotoAccessHelper.Core 6103 6104| Name | Value| Description| 6105| ----- | ---- | ---- | 6106| SCREENSHOT | 1 | Screenshot and screen recording file.<br>**System API**: This is a system API.| 6107 6108## PositionType 6109 6110Enumerates the file locations. 6111 6112**System API**: This is a system API. 6113 6114**System capability**: SystemCapability.FileManagement.PhotoAccessHelper.Core 6115 6116| Name | Value| Description| 6117| ----- | ---- | ---- | 6118| LOCAL | 1 << 0 | Stored only on a local device.| 6119| CLOUD | 1 << 1 | Stored only on the cloud.| 6120 6121## AlbumType 6122 6123Enumerates the album types. 6124 6125**System capability**: SystemCapability.FileManagement.PhotoAccessHelper.Core 6126 6127| Name | Value | Description | 6128| ------------------- | ---- | ------------------------- | 6129| SMART<sup>11+</sup> | 4096 | Smart analysis album.<br>**System API**: This is a system API.| 6130 6131## AlbumSubtype 6132 6133Enumerate the album subtypes. 6134 6135**System capability**: SystemCapability.FileManagement.PhotoAccessHelper.Core 6136 6137| Name | Value | Description | 6138| --------------------------------- | ---------- | ------------------------------- | 6139| HIDDEN | 1027 | Hidden album. <br>**System API**: This is a system API. | 6140| TRASH | 1028 | Trash. <br>**System API**: This is a system API. | 6141| SCREENSHOT | 1029 | Album for screenshots and screen recording files. <br>**System API**: This is a system API. | 6142| CAMERA | 1030 | Album for photos and videos taken by the camera. <br>**System API**: This is a system API.| 6143| SOURCE\_GENERIC<sup>11+</sup> | 2049 | Source album. <br>**System API**: This is a system API. | 6144| CLASSIFY<sup>11+</sup> | 4097 | Classified album. <br>**System API**: This is a system API. | 6145| GEOGRAPHY\_LOCATION<sup>11+</sup> | 4099 | Geographic location album. <br>**System API**: This is a system API. | 6146| GEOGRAPHY\_CITY<sup>11+</sup> | 4100 | City album. <br>**System API**: This is a system API. | 6147| SHOOTING\_MODE<sup>11+</sup> | 4101 | Shooting mode album. <br>**System API**: This is a system API. | 6148| PORTRAIT<sup>11+</sup> | 4102 | Portrait album. <br>**System API**: This is a system API. | 6149| GROUP_PHOTO<sup>13+</sup> | 4103 | Group photo album. <br>**System API**: This is a system API. | 6150| HIGHLIGHT<sup>12+</sup> | 4104 | Highlights album. <br>**System API**: This is a system API. | 6151| HIGHLIGHT_SUGGESTIONS<sup>12+</sup> | 4105 | Highlights suggestion album. <br>**System API**: This is a system API. | 6152| CLOUD_ENHANCEMENT<sup>13+</sup> | 1032 | AI-powered cloud enhanced album. <br>**System API**: This is a system API. | 6153 6154## RequestPhotoType<sup>11+</sup> 6155 6156Enumerates the types of the operation for obtaining image or video thumbnails. 6157 6158**System API**: This is a system API. 6159 6160**System capability**: SystemCapability.FileManagement.PhotoAccessHelper.Core 6161 6162| Name | Value| Description| 6163| ----- | ---- | ---- | 6164| REQUEST_ALL_THUMBNAILS | 0 | Obtain both the quick thumbnail and the quality thumbnail.| 6165| REQUEST_FAST_THUMBNAIL | 1 | Obtain only the quick thumbnail.| 6166| REQUEST_QUALITY_THUMBNAIL | 2 | Obtain only the quality thumbnail.| 6167 6168## PhotoKeys 6169 6170Defines the key information about an image or video file. 6171 6172**System capability**: SystemCapability.FileManagement.PhotoAccessHelper.Core 6173 6174| Name | Value | Description | 6175| ------------- | ------------------- | ---------------------------------------------------------- | 6176| POSITION | 'position' | File location type. <br>**System API**: This is a system API. | 6177| 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. | 6178| HIDDEN | 'hidden' | Whether the file is hidden. <br>**System API**: This is a system API. | 6179| 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. | 6180| USER_COMMENT<sup>10+</sup> | 'user_comment' | User comment information. <br>**System API**: This is a system API. | 6181| DATE_YEAR<sup>11+</sup> | 'date_year' | Year when the file was created. <br>**System API**: This is a system API. | 6182| DATE_MONTH<sup>11+</sup> | 'date_month' | Month when the file was created. <br>**System API**: This is a system API. | 6183| DATE_DAY<sup>11+</sup> | 'date_day' | Date when the file was created. <br>**System API**: This is a system API. | 6184| PENDING<sup>11+</sup> | 'pending' | Pending state. <br>**System API**: This is a system API. | 6185| 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.| 6186| MOVING_PHOTO_EFFECT_MODE<sup>12+</sup> | 'moving_photo_effect_mode' | Effect of the moving photo. <br>**System API**: This is a system API.| 6187| CE_AVAILABLE<sup>13+</sup> | 'ce_available' | Cloud enhancement identifier. <br>**System API**: This is a system API.| 6188| SUPPORTED_WATERMARK_TYPE<sup>14+</sup> | 'supported_watermark_type' | Editable watermark identifier. <br>**System API**: This is a system API.| 6189 6190## HiddenPhotosDisplayMode<sup>11+</sup> 6191 6192Enumerates the display modes of hidden files in the system. 6193 6194**System API**: This is a system API. 6195 6196**System capability**: SystemCapability.FileManagement.PhotoAccessHelper.Core 6197 6198| Name | Value | Description | 6199| ------------- | ------------------- | ---------------------------------------------------------- | 6200| ASSETS_MODE | 0 | Display all hidden files in the system. | 6201| 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). | 6202 6203## PhotoCreateOptions 6204 6205Options for creating an image or video asset. 6206 6207**System API**: This is a system API. 6208 6209**System capability**: SystemCapability.FileManagement.PhotoAccessHelper.Core 6210 6211| Name | Type | Mandatory| Description | 6212| ---------------------- | ------------------- | ---- | ------------------------------------------------ | 6213| subtype | [PhotoSubtype](#photosubtype) | No | Subtype of the image or video. | 6214| 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.) | 6215 6216## RequestPhotoOptions<sup>11+</sup> 6217 6218Defines the options for obtaining the thumbnail of an image or video. 6219 6220**System API**: This is a system API. 6221 6222**System capability**: SystemCapability.FileManagement.PhotoAccessHelper.Core 6223 6224| Name | Type | Mandatory| Description | 6225| ---------------------- | ------------------- | ---- | ------------------------------------------------ | 6226| size | [image.Size](../apis-image-kit/js-apis-image.md#size) | No | Size of the thumbnail to obtain. | 6227| requestPhotoType | [RequestPhotoType](#requestphototype11) | No | Operation to perform. | 6228 6229## RequestOptions<sup>11+</sup> 6230 6231Represents request options. 6232 6233**System capability**: SystemCapability.FileManagement.PhotoAccessHelper.Core 6234 6235| Name | Type | Readable| Writable| Description | 6236| ---------------------- |---------------------------------| ---- |---- | ------------------------------------------------ | 6237| 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.| 6238 6239## PhotoProxy<sup>11+</sup> 6240 6241Photo proxy object, which is used by the camera application to write image data. 6242 6243**System API**: This is a system API. 6244 6245**System capability**: SystemCapability.FileManagement.PhotoAccessHelper.Core 6246 6247## MediaChangeRequest<sup>11+</sup> 6248 6249Media change request, which is the parent class of the asset change request and album change request. 6250 6251> **NOTE**<br>The media change request takes effect only after [applyChanges](js-apis-photoAccessHelper.md#applychanges11) is called. 6252 6253**System capability**: SystemCapability.FileManagement.PhotoAccessHelper.Core 6254 6255## FormInfo<sup>11+</sup> 6256 6257Defines the Gallery widget information. 6258 6259**System API**: This is a system API. 6260 6261**System capability**: SystemCapability.FileManagement.PhotoAccessHelper.Core 6262 6263| Name | Type | Mandatory| Description | 6264| ---------------------- | ------------------- | ---- | ------------------------------------------------ | 6265|formId |string |Yes| Widget ID, which is provided when a widget is created in Gallery.| 6266|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. | 6267 6268## ResourceType<sup>11+</sup> 6269 6270Enumerates the types of the resources to write. 6271 6272**System capability**: SystemCapability.FileManagement.PhotoAccessHelper.Core 6273 6274| Name | Value| Description| 6275| ----- | ---- | ---- | 6276| PHOTO_PROXY | 3 | Photo proxy. <br>**System API**: This is a system API.| 6277| PRIVATE_MOVING_PHOTO_RESOURCE<sup>13+</sup> | 4 | Private moving photo. <br>**System API**: This is a system API.| 6278 6279## DefaultChangeUri 6280 6281Enumerates the **DefaultChangeUri** subtypes. 6282 6283**System capability**: SystemCapability.FileManagement.PhotoAccessHelper.Core 6284 6285| Name | Value | Description | 6286| ----------------- | ----------------------- | ------------------------------------------------------------ | 6287| 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.| 6288 6289## SourceMode<sup>11+</sup> 6290 6291Enumerates the types of the file to read. 6292 6293**System API**: This is a system API. 6294 6295**System capability**: SystemCapability.FileManagement.PhotoAccessHelper.Core 6296 6297| Name | Value| Description| 6298| ----- | ---- | ---- | 6299| ORIGINAL_MODE | 0 | Original file.| 6300| EDITED_MODE | 1 | Edited file.| 6301## AuthorizationMode<sup>12+</sup> 6302 6303Enumerates the authorization modes. 6304 6305**System API**: This is a system API. 6306 6307**System capability**: SystemCapability.FileManagement.PhotoAccessHelper.Core 6308 6309| Name | Value| Description| 6310| ----- | ---- | ---- | 6311| SHORT_TIME_AUTHORIZATION| 0 | Temporary authorization.| 6312 6313## AnalysisType<sup>11+</sup> 6314 6315Enumerates the smart analysis types. 6316 6317**System capability**: SystemCapability.FileManagement.PhotoAccessHelper.Core 6318 6319| Name | Value | Description | 6320| :---------------------------- | :- | :------- | 6321| ANALYSIS\_AESTHETICS\_SCORE | 0 | Aesthetics score. <br>**System API**: This is a system API. | 6322| ANALYSIS\_LABEL | 1 | Label. <br>**System API**: This is a system API. | 6323| ANALYSIS\_OCR | 2 | Optical character recognition (OCR) analysis. <br>**System API**: This is a system API. | 6324| ANALYSIS\_FACE | 3 | Facial detection analysis. <br>**System API**: This is a system API. | 6325| ANALYSIS\_OBJECT | 4 | Object detection analysis. <br>**System API**: This is a system API. | 6326| ANALYSIS\_RECOMMENDATION | 5 | Recommendation analysis. <br>**System API**: This is a system API. | 6327| ANALYSIS\_SEGMENTATION | 6 | Segmentation analysis. <br>**System API**: This is a system API. | 6328| ANALYSIS\_COMPOSITION | 7 | Aesthetic composition analysis. <br>**System API**: This is a system API. | 6329| ANALYSIS\_SALIENCY | 8 | Salience analysis. <br>**System API**: This is a system API. | 6330| ANALYSIS\_DETAIL\_ADDRESS | 9 | Detailed address analysis. <br>**System API**: This is a system API. | 6331| ANALYSIS\_HUMAN\_FACE\_TAG<sup>12+</sup> | 10 | Face clustering analysis. <br>**System API**: This is a system API. | 6332| 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. | 6333| 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. | 6334| ANALYSIS\_VIDEO\_LABEL<sup>12+</sup> | 13 | Video label analysis. <br>**System API**: This is a system API. | 6335 6336## HighlightAlbumInfoType<sup>12+</sup> 6337 6338Enumerates the types of the highlights album information. 6339 6340**System API**: This is a system API. 6341 6342**System capability**: SystemCapability.FileManagement.PhotoAccessHelper.Core 6343 6344| Name | Value | Description | 6345| :------------ | :- | :------- | 6346| COVER\_INFO | 0 | Cover information. | 6347| PLAY\_INFO | 1 | Music information. | 6348 6349## HighlightUserActionType<sup>12+</sup> 6350 6351Enumerates the user behavior types of the highlights album. 6352 6353**System API**: This is a system API. 6354 6355**System capability**: SystemCapability.FileManagement.PhotoAccessHelper.Core 6356 6357| Name | Value | Description | 6358| :---------------------------- | :- | :------- | 6359| INSERTED\_PIC\_COUNT | 0 | Number of inserted pictures. | 6360| REMOVED\_PIC\_COUNT | 1 | Number of removed pictures. | 6361| SHARED\_SCREENSHOT\_COUNT | 2 | Number of times that a full-length image in a highlights album is shared. | 6362| SHARED\_COVER\_COUNT | 3 | Number of times that a highlights cover is shared. | 6363| RENAMED\_COUNT | 4 | Number of times that a highlights album is renamed. | 6364| CHANGED\_COVER\_COUNT | 5 | Number of times that a cover is changed. | 6365| RENDER\_VIEWED\_TIMES | 100 | Number of times that the pictures in a highlights album are played. | 6366| RENDER\_VIEWED\_DURATION | 101 | Time used to play the pictures in a highlights album. | 6367| ART\_LAYOUT\_VIEWED\_TIMES | 102 | Number of times that a highlights album is viewed. | 6368| ART\_LAYOUT\_VIEWED\_DURATION | 103 | Time used to view a highlights album. | 6369 6370## MovingPhotoEffectMode<sup>12+</sup> 6371 6372Enumerates the effects of a moving photo. 6373 6374**System API**: This is a system API. 6375 6376**System capability**: SystemCapability.FileManagement.PhotoAccessHelper.Core 6377 6378| Name | Value | Description | 6379| :---------------------------- | :- | :------- | 6380| DEFAULT | 0 | Default effect.| 6381| BOUNCE\_PLAY | 1 | Back-and-forth motion.| 6382| LOOP\_PLAY | 2 | Continuously repeated animation.| 6383| LONG\_EXPOSURE | 3 | Long exposure. | 6384| MULTI\_EXPOSURE | 4 | Multiple exposures. | 6385| CINEMA\_GRAPH<sup>13+</sup> | 5 | Cinemagraph. | 6386| IMAGE\_ONLY<sup>13+</sup> | 10 | Image only. | 6387 6388## PhotoPermissionType<sup>12+</sup> 6389 6390Enumerates the types of permissions for accessing media assets. 6391 6392The permissions include temporary read permission and persistent read permission. The temporary read permission will be removed when the application is dead, while the persistent read permission will not. 6393 6394For 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. 6395 6396**System API**: This is a system API. 6397 6398**System capability**: SystemCapability.FileManagement.PhotoAccessHelper.Core 6399 6400| Name | Value| Description| 6401| ----- | ---- | ---- | 6402| TEMPORARY_READ_IMAGEVIDEO | 0 | Temporary read permission.| 6403| PERSISTENT_READ_IMAGEVIDEO | 1 | Persistent read permission.| 6404 6405## HideSensitiveType<sup>12+</sup> 6406 6407Enumerates the types of media resource information to be hidden from an application. 6408 6409**System API**: This is a system API. 6410 6411**System capability**: SystemCapability.FileManagement.PhotoAccessHelper.Core 6412 6413| Name | Value| Description| 6414| ----- | ---- | ---- | 6415| HIDE_LOCATION_AND_SHOOTING_PARAM | 0 | Geographical location and shooting parameters.| 6416| HIDE_LOCATION_ONLY | 1 | Geographical location information.| 6417| HIDE_SHOOTING_PARAM_ONLY | 2 | Shooting parameters.| 6418| NO_HIDE_SENSITIVE_TYPE | 3 | Do not hide any information.| 6419 6420## CloudEnhancementTaskStage<sup>13+</sup> 6421 6422Enumerates the cloud enhancement task states, which are returned by [CloudEnhancementTaskState](#cloudenhancement13). 6423 6424**System API**: This is a system API. 6425 6426**System capability**: SystemCapability.FileManagement.PhotoAccessHelper.Core 6427 6428| Name | Value| Description| 6429| ----- | ---- | ---- | 6430| TASK_STAGE_EXCEPTION | -1 | The cloud enhancement task is abnormal.| 6431| TASK_STAGE_PREPARING | 0 | The cloud enhancement task is being prepared.| 6432| TASK_STAGE_UPLOADING | 1 | The cloud enhancement task is uploading data.| 6433| TASK_STAGE_EXECUTING | 2 | The cloud enhancement task is being executed.| 6434| TASK_STAGE_DOWNLOADING | 3 | The cloud enhancement task is downloading data.| 6435| TASK_STAGE_FAILED | 4 | The cloud enhancement task failed.| 6436| TASK_STAGE_COMPLETED | 5 | The cloud enhancement task is complete.| 6437 6438## CloudEnhancementState<sup>13+</sup> 6439 6440Enumerates the cloud enhancement states. 6441 6442**System API**: This is a system API. 6443 6444**System capability**: SystemCapability.FileManagement.PhotoAccessHelper.Core 6445 6446| Name | Value| Description| 6447| ----- | ---- | ---- | 6448| UNAVAILABLE | 0 | Cloud enhancement is unavailable.| 6449| AVAILABLE | 1 | Cloud enhancement is available.| 6450| EXECUTING | 2 | Cloud enhancement is being executed.| 6451| COMPLETED | 3 | Cloud enhancement has been completed.| 6452 6453## CloudEnhancementTaskState<sup>13+</sup> 6454 6455Represents the cloud enhancement task information, which includes the cloud enhancement task state and other information related to certain states. 6456 6457**System API**: This is a system API. 6458 6459**System capability**: SystemCapability.FileManagement.PhotoAccessHelper.Core 6460 6461| Name | Type | Mandatory| Description | 6462| ---------------------- | ------------------- | ---- | ------------------------------------------------ | 6463|taskStage |[CloudEnhancementTaskStage](#cloudenhancementtaskstage13) |Yes| Cloud enhancement task state.| 6464|transferredFileSize |number |No| Size of the file transferred. This parameter is mandatory when **taskStage** is **CloudEnhancementTaskStage.TASK_STAGE_UPLOADING** or **CloudEnhancementTaskStage.TASK_STAGE_DOWNLOADING**. | 6465|totalFileSize |number |No| Total file size. This parameter is mandatory when **taskStage** is **CloudEnhancementTaskStage.TASK_STAGE_UPLOADING** or **CloudEnhancementTaskStage.TASK_STAGE_DOWNLOADING**. | 6466|expectedDuration |number |No| Queuing time. This parameter is mandatory when **taskStage** is **CloudEnhancementTaskStage.TASK_STAGE_EXECUTING**. | 6467|statusCode |number |No| Status code. This parameter is mandatory when **taskStage** is **CloudEnhancementTaskStage.TASK_STAGE_FAILED**. | 6468 6469## VideoEnhancementType<sup>13+</sup> 6470 6471Enumerates the types of segmented video enhancement. 6472 6473**System API**: This is a system API. 6474 6475**System capability**: SystemCapability.FileManagement.PhotoAccessHelper.Core 6476 6477| Name | Value| Description| 6478| ----- | ---- | ---- | 6479| QUALITY_ENHANCEMENT_LOCAL | 0 | Apply enhancement on the device.| 6480| QUALITY_ENHANCEMENT_CLOUD | 1 | Apply enhancement on the cloud.| 6481| QUALITY_ENHANCEMENT_LOCAL_AND_CLOUD | 2 | Apply enhancement on both the device and cloud.| 6482 6483## ThumbnailType<sup>13+</sup> 6484 6485Enumerates thumbnail types. 6486 6487**System API**: This is a system API. 6488 6489**System capability**: SystemCapability.FileManagement.PhotoAccessHelper.Core 6490 6491| Name | Value | Description | 6492| :---------------------------- | :- | :------- | 6493| LCD | 1 | LCD thumbnail. | 6494| THM | 2 | THM thumbnail. | 6495 6496## WatermarkType<sup>14+</sup> 6497 6498Enumerates the watermark editable flags. 6499 6500**System API**: This is a system API. 6501 6502**System capability**: SystemCapability.FileManagement.PhotoAccessHelper.Core 6503 6504| Name | Value| Description| 6505| ----- | ---- | ---- | 6506| DEFAULT | 0 | Watermarks are not editable.| 6507| BRAND_COMMON | 1 | Brand and common watermarks are editable.| 6508| COMMON | 2 | Common watermarks are editable.| 6509| BRAND | 3 | Brand watermarks are editable.| 6510 6511## CloudMediaDownloadType<sup>14+</sup> 6512 6513Enumerates the types of download tasks. 6514 6515**System API**: This is a system API. 6516 6517**System capability**: SystemCapability.FileManagement.PhotoAccessHelper.Core 6518 6519| Name | Value| Description| 6520| ----- | ---- | ---- | 6521| DOWNLOAD_FORCE | 0 | High-priority download, without the need for the device to switch to screen-off charging mode.| 6522| DOWNLOAD_GENTLE | 1 | Low-priority download, demanding that device be in screen-off charging mode.| 6523 6524## CloudMediaRetainType<sup>14+</sup> 6525 6526Enumerates the modes used for deleting cloud media assets. 6527 6528**System API**: This is a system API. 6529 6530**System capability**: SystemCapability.FileManagement.PhotoAccessHelper.Core 6531 6532| Name | Value| Description| 6533| ----- | ---- | ---- | 6534| RETAIN_FORCE | 0 | Deletes the local metadata and thumbnail of the original files from the cloud.| 6535 6536## CloudMediaAssetTaskStatus<sup>14+</sup> 6537 6538Enumerates the statuses of tasks used for downloading cloud media assets. 6539 6540**System API**: This is a system API. 6541 6542**System capability**: SystemCapability.FileManagement.PhotoAccessHelper.Core 6543 6544| Name | Value| Description| 6545| ----- | ---- | ---- | 6546| DOWNLOADING | 0 | The task is in progress.| 6547| PAUSED | 1 | The task is paused.| 6548| IDLE | 2 | There is no download task.| 6549 6550## CloudMediaTaskPauseCause<sup>14+</sup> 6551 6552Enumerates the reasons why a cloud media asset download task is paused. 6553 6554**System API**: This is a system API. 6555 6556**System capability**: SystemCapability.FileManagement.PhotoAccessHelper.Core 6557 6558| Name | Value| Description| 6559| ----- | ---- | ---- | 6560| NO_PAUSE | 0 | Downloading is proceeding normally without any pauses.| 6561| TEMPERATURE_LIMIT | 1 | The device temperature is excessively high.| 6562| ROM_LIMIT | 2 | The local disk space is insufficient.| 6563| NETWORK_FLOW_LIMIT | 3 | Network traffic is restricted, and Wi-Fi is not available.| 6564| WIFI_UNAVAILABLE | 4 | The network is abnormal.| 6565| POWER_LIMIT | 5 | Power usage is restricted.| 6566| BACKGROUND_TASK_UNAVAILABLE | 6 | The device is not in charging screen-off mode.| 6567| FREQUENT_USER_REQUESTS | 7 | The user is making requests too frequently.| 6568| CLOUD_ERROR | 8 | There is an error with the cloud service.| 6569| USER_PAUSED | 9 | The download has been paused by the user.| 6570 6571## CloudMediaAssetStatus<sup>14+</sup> 6572 6573Describes the details of a cloud media asset download task. It is the return value of the API used by applications to obtain the cloud asset download task status. 6574 6575**System API**: This is a system API. 6576 6577**System capability**: SystemCapability.FileManagement.PhotoAccessHelper.Core 6578 6579| Name | Type | Mandatory| Description | 6580| ---------------------- | ------------------- | ---- | ------------------------------------------------ | 6581|taskStatus |[CloudMediaAssetTaskStatus](#cloudmediaassettaskstatus14) |Yes| Status of the download task.| 6582|taskInfo |string |Yes| Total number of and size (measured in bytes) of the assets that have been downloaded, and the total number and size (also measured in bytes) of the assets remaining to be downloaded. | 6583|errorCode |[CloudMediaTaskPauseCause](#cloudmediataskpausecause14) |Yes| Reason why the download task is suspended.| 6584