1# @ohos.file.photoAccessHelper (Album Management) 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 9## Modules to Import 10 11```ts 12import { photoAccessHelper } from '@kit.MediaLibraryKit'; 13``` 14 15## photoAccessHelper.getPhotoAccessHelper 16 17getPhotoAccessHelper(context: Context): PhotoAccessHelper 18 19Obtains a **PhotoAccessHelper** instance for accessing and modifying media files in the album. 20 21**Model restriction**: This API can be used only in the stage model. 22 23**Atomic service API**: This API can be used in atomic services since API version 11. 24 25**System capability**: SystemCapability.FileManagement.PhotoAccessHelper.Core 26 27**Parameters** 28 29| Name | Type | Mandatory| Description | 30| ------- | ------- | ---- | -------------------------- | 31| context | [Context](../apis-ability-kit/js-apis-inner-application-context.md) | Yes | Context of the ability instance.| 32 33**Return value** 34 35| Type | Description | 36| ----------------------------- | :---- | 37| [PhotoAccessHelper](#photoaccesshelper) | **PhotoAccessHelper** instance obtained.| 38 39**Error codes** 40 41For details about the error codes, see [Universal Error Codes](../errorcode-universal.md). 42 43| ID| Error Message| 44| -------- | ---------------------------------------- | 45| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types; 3. Parameter verification failed. | 46 47**Example** 48 49```ts 50// The phAccessHelper instance obtained is a global object. It is used by default in subsequent operations. If the code snippet is not added, an error will be reported indicating that phAccessHelper is not defined. 51let context = getContext(this); 52let phAccessHelper = photoAccessHelper.getPhotoAccessHelper(context); 53``` 54 55## PhotoAccessHelper 56 57### getAssets 58 59getAssets(options: FetchOptions, callback: AsyncCallback<FetchResult<PhotoAsset>>): void 60 61Obtains image and video assets. This API uses an asynchronous callback to return the result. 62 63**System capability**: SystemCapability.FileManagement.PhotoAccessHelper.Core 64 65**Required permissions**: ohos.permission.READ_IMAGEVIDEO 66 67When you call this API in Picker mode, you do not need to request the ohos.permission.READ_IMAGEVIDEO permission. For details, see [Obtaining an Image or Video by URI](../../media/medialibrary/photoAccessHelper-photoviewpicker.md#obtaining-an-image-or-video-by-uri). 68 69**Parameters** 70 71| Name | Type | Mandatory| Description | 72| -------- | ------------------------ | ---- | ------------------------- | 73| options | [FetchOptions](#fetchoptions) | Yes | Options for fetching the image and video assets. | 74| callback | AsyncCallback<[FetchResult](#fetchresult)<[PhotoAsset](#photoasset)>> | Yes | Callback used to return the image and video assets obtained.| 75 76**Error codes** 77 78For details about the error codes, see [Universal Error Codes](../errorcode-universal.md) and [File Management Error Codes](../apis-core-file-kit/errorcode-filemanagement.md). 79 80| ID| Error Message| 81| -------- | ---------------------------------------- | 82| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types; 3. Parameter verification failed. | 83| 13900012 | Permission denied. | 84| 13900020 | Invalid argument. | 85| 14000011 | System inner fail. | 86 87**Example** 88 89```ts 90import { dataSharePredicates } from '@kit.ArkData'; 91 92async function example() { 93 console.info('getAssets'); 94 let predicates: dataSharePredicates.DataSharePredicates = new dataSharePredicates.DataSharePredicates(); 95 let fetchOptions: photoAccessHelper.FetchOptions = { 96 fetchColumns: [], 97 predicates: predicates 98 }; 99 100 phAccessHelper.getAssets(fetchOptions, async (err, fetchResult) => { 101 if (fetchResult !== undefined) { 102 console.info('fetchResult success'); 103 let photoAsset: photoAccessHelper.PhotoAsset = await fetchResult.getFirstObject(); 104 if (photoAsset !== undefined) { 105 console.info('photoAsset.displayName : ' + photoAsset.displayName); 106 } 107 } else { 108 console.error(`fetchResult fail with error: ${err.code}, ${err.message}`); 109 } 110 }); 111} 112``` 113 114### getAssets 115 116getAssets(options: FetchOptions): Promise<FetchResult<PhotoAsset>> 117 118Obtains image and video assets. This API uses a promise to return the result. 119 120**System capability**: SystemCapability.FileManagement.PhotoAccessHelper.Core 121 122**Required permissions**: ohos.permission.READ_IMAGEVIDEO 123 124When you call this API in Picker mode, you do not need to request the ohos.permission.READ_IMAGEVIDEO permission. For details, see [Obtaining an Image or Video by URI](../../media/medialibrary/photoAccessHelper-photoviewpicker.md#obtaining-an-image-or-video-by-uri). 125 126**Parameters** 127 128| Name | Type | Mandatory| Description | 129| ------- | ------------------- | ---- | ---------------- | 130| options | [FetchOptions](#fetchoptions) | Yes | Options for fetching the image and video assets. | 131 132**Return value** 133 134| Type | Description | 135| --------------------------- | -------------- | 136| Promise<[FetchResult](#fetchresult)<[PhotoAsset](#photoasset)>> | Promise used to return the image and video assets obtained.| 137 138**Error codes** 139 140For details about the error codes, see [Universal Error Codes](../errorcode-universal.md) and [File Management Error Codes](../apis-core-file-kit/errorcode-filemanagement.md). 141 142| ID| Error Message| 143| -------- | ---------------------------------------- | 144| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types; 3. Parameter verification failed. | 145| 13900012 | Permission denied. | 146| 13900020 | Invalid argument. | 147| 14000011 | System inner fail. | 148 149**Example** 150 151```ts 152import { dataSharePredicates } from '@kit.ArkData'; 153 154async function example() { 155 console.info('getAssets'); 156 let predicates: dataSharePredicates.DataSharePredicates = new dataSharePredicates.DataSharePredicates(); 157 let fetchOptions: photoAccessHelper.FetchOptions = { 158 fetchColumns: [], 159 predicates: predicates 160 }; 161 try { 162 let fetchResult: photoAccessHelper.FetchResult<photoAccessHelper.PhotoAsset> = await phAccessHelper.getAssets(fetchOptions); 163 if (fetchResult !== undefined) { 164 console.info('fetchResult success'); 165 let photoAsset: photoAccessHelper.PhotoAsset = await fetchResult.getFirstObject(); 166 if (photoAsset !== undefined) { 167 console.info('photoAsset.displayName :' + photoAsset.displayName); 168 } 169 } 170 } catch (err) { 171 console.error(`getAssets failed, error: ${err.code}, ${err.message}`); 172 } 173} 174``` 175 176### getBurstAssets<sup>12+</sup> 177 178getBurstAssets(burstKey: string, options: FetchOptions): Promise<FetchResult<PhotoAsset>> 179 180Obtains burst assets. This API uses a promise to return the result. 181 182**System capability**: SystemCapability.FileManagement.PhotoAccessHelper.Core 183 184**Required permissions**: ohos.permission.READ_IMAGEVIDEO 185 186**Parameters** 187 188| Name | Type | Mandatory| Description | 189| ------- | ------------------- | ---- | ---------------- | 190| burstKey | string | Yes | UUID of a set of burst photos (**BURST_KEY** of [PhotoKeys](#photokeys)). | 191| options | [FetchOptions](#fetchoptions) | Yes | Options for fetching the burst photos. | 192 193**Return value** 194 195| Type | Description | 196| --------------------------- | -------------- | 197| Promise<[FetchResult](#fetchresult)<[PhotoAsset](#photoasset)>> | Promise used to return the result.| 198 199**Error codes** 200 201For details about the error codes, see [Universal Error Codes](../errorcode-universal.md) and [File Management Error Codes](../apis-core-file-kit/errorcode-filemanagement.md). 202 203| ID| Error Message| 204| -------- | ---------------------------------------- | 205| 201 | Permission denied. | 206| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types; 3. Parameter verification failed. | 207| 14000011 | Internal system error. | 208 209**Example** 210 211```ts 212import { photoAccessHelper } from '@kit.MediaLibraryKit'; 213import { dataSharePredicates } from '@kit.ArkData'; 214 215async function example() { 216 console.info('getBurstAssets'); 217 let predicates: dataSharePredicates.DataSharePredicates = new dataSharePredicates.DataSharePredicates(); 218 let fetchOptions: photoAccessHelper.FetchOptions = { 219 fetchColumns: [], 220 predicates: predicates 221 }; 222 // burstKey is a 36-bit UUID, which can be obtained from photoAccessHelper.PhotoKeys. 223 let burstKey: string = "e719d696-09fa-44f8-ec3f215aa62a"; 224 try { 225 let fetchResult: photoAccessHelper.FetchResult<photoAccessHelper.PhotoAsset> = await 226 phAccessHelper.getBurstAssets(burstKey, fetchOptions); 227 if (fetchResult !== undefined) { 228 console.info('fetchResult success'); 229 let photoAsset: photoAccessHelper.PhotoAsset = await fetchResult.getFirstObject(); 230 if (photoAsset !== undefined) { 231 console.info('photoAsset.displayName :' + photoAsset.displayName); 232 } 233 } 234 } catch (err) { 235 console.error(`getBurstAssets failed, error: ${err.code}, ${err.message}`); 236 } 237} 238``` 239 240### createAsset 241 242createAsset(photoType: PhotoType, extension: string, options: CreateOptions, callback: AsyncCallback<string>): void 243 244Creates an image or video asset with the specified file type, file name extension, and options. This API uses an asynchronous callback to return the result. 245 246If the caller does not have the ohos.permission.WRITE_IMAGEVIDEO permission, you can create a media asset by using a security component. For details, see [Creating a Media Asset Using a Security Component](../../media/medialibrary/photoAccessHelper-savebutton.md). 247 248**Atomic service API**: This API can be used in atomic services since API version 11. 249 250**System capability**: SystemCapability.FileManagement.PhotoAccessHelper.Core 251 252**Required permissions**: ohos.permission.WRITE_IMAGEVIDEO 253 254**Parameters** 255 256| Name | Type | Mandatory| Description | 257| -------- | ------------------------ | ---- | ------------------------- | 258| photoType | [PhotoType](#phototype) | Yes | Type of the file to create, which can be **IMAGE** or **VIDEO**. | 259| extension | string | Yes | File name extension, for example, **'jpg'**. | 260| options | [CreateOptions](#createoptions) | Yes | Options for creating the image or video asset, for example, **{title: 'testPhoto'}**. | 261| callback | AsyncCallback<string> | Yes | Callback used to return the URI of the created image or video asset.| 262 263**Error codes** 264 265For details about the error codes, see [Universal Error Codes](../errorcode-universal.md) and [File Management Error Codes](../apis-core-file-kit/errorcode-filemanagement.md). 266 267| ID| Error Message| 268| -------- | ---------------------------------------- | 269| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types; 3. Parameter verification failed. | 270| 13900012 | Permission denied. | 271| 13900020 | Invalid argument. | 272| 14000011 | System inner fail. | 273 274**Example** 275 276```ts 277async function example() { 278 console.info('createAssetDemo'); 279 let photoType: photoAccessHelper.PhotoType = photoAccessHelper.PhotoType.IMAGE; 280 let extension:string = 'jpg'; 281 let options: photoAccessHelper.CreateOptions = { 282 title: 'testPhoto' 283 } 284 phAccessHelper.createAsset(photoType, extension, options, (err, uri) => { 285 if (uri !== undefined) { 286 console.info('createAsset uri' + uri); 287 console.info('createAsset successfully'); 288 } else { 289 console.error(`createAsset failed, error: ${err.code}, ${err.message}`); 290 } 291 }); 292} 293``` 294 295### createAsset 296 297createAsset(photoType: PhotoType, extension: string, callback: AsyncCallback<string>): void 298 299Creates an image or video asset with the specified file type and file name extension. This API uses an asynchronous callback to return the result. 300 301If the caller does not have the ohos.permission.WRITE_IMAGEVIDEO permission, you can create a media asset by using a security component. For details, see [Creating a Media Asset Using a Security Component](../../media/medialibrary/photoAccessHelper-savebutton.md). 302 303**Atomic service API**: This API can be used in atomic services since API version 11. 304 305**System capability**: SystemCapability.FileManagement.PhotoAccessHelper.Core 306 307**Required permissions**: ohos.permission.WRITE_IMAGEVIDEO 308 309**Parameters** 310 311| Name | Type | Mandatory| Description | 312| -------- | ------------------------ | ---- | ------------------------- | 313| photoType | [PhotoType](#phototype) | Yes | Type of the file to create, which can be **IMAGE** or **VIDEO**. | 314| extension | string | Yes | File name extension, for example, **'jpg'**. | 315| callback | AsyncCallback<string> | Yes | Callback used to return the URI of the created image or video asset.| 316 317**Error codes** 318 319For details about the error codes, see [Universal Error Codes](../errorcode-universal.md) and [File Management Error Codes](../apis-core-file-kit/errorcode-filemanagement.md). 320 321| ID| Error Message| 322| -------- | ---------------------------------------- | 323| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types; 3. Parameter verification failed. | 324| 13900012 | Permission denied. | 325| 13900020 | Invalid argument. | 326| 14000011 | System inner fail. | 327 328**Example** 329 330```ts 331async function example() { 332 console.info('createAssetDemo'); 333 let photoType: photoAccessHelper.PhotoType = photoAccessHelper.PhotoType.IMAGE; 334 let extension: string = 'jpg'; 335 phAccessHelper.createAsset(photoType, extension, (err, uri) => { 336 if (uri !== undefined) { 337 console.info('createAsset uri' + uri); 338 console.info('createAsset successfully'); 339 } else { 340 console.error(`createAsset failed, error: ${err.code}, ${err.message}`); 341 } 342 }); 343} 344``` 345 346### createAsset 347 348createAsset(photoType: PhotoType, extension: string, options?: CreateOptions): Promise<string> 349 350Creates an image or video asset with the specified file type, file name extension, and options. This API uses a promise to return the result. 351 352If the caller does not have the ohos.permission.WRITE_IMAGEVIDEO permission, you can create a media asset by using a security component. For details, see [Creating a Media Asset Using a Security Component](../../media/medialibrary/photoAccessHelper-savebutton.md). 353 354**Atomic service API**: This API can be used in atomic services since API version 11. 355 356**System capability**: SystemCapability.FileManagement.PhotoAccessHelper.Core 357 358**Required permissions**: ohos.permission.WRITE_IMAGEVIDEO 359 360**Parameters** 361 362| Name | Type | Mandatory| Description | 363| -------- | ------------------------ | ---- | ------------------------- | 364| photoType | [PhotoType](#phototype) | Yes | Type of the file to create, which can be **IMAGE** or **VIDEO**. | 365| extension | string | Yes | File name extension, for example, **'jpg'**. | 366| options | [CreateOptions](#createoptions) | No | Options for creating the image or video asset, for example, **{title: 'testPhoto'}**. | 367 368**Return value** 369 370| Type | Description | 371| --------------------------- | -------------- | 372| Promise<string> | Promise used to return the URI of the created image or video asset.| 373 374**Error codes** 375 376For details about the error codes, see [Universal Error Codes](../errorcode-universal.md) and [File Management Error Codes](../apis-core-file-kit/errorcode-filemanagement.md). 377 378| ID| Error Message| 379| -------- | ---------------------------------------- | 380| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types; 3. Parameter verification failed. | 381| 13900012 | Permission denied. | 382| 13900020 | Invalid argument. | 383| 14000011 | System inner fail. | 384 385**Example** 386 387```ts 388async function example() { 389 console.info('createAssetDemo'); 390 try { 391 let photoType: photoAccessHelper.PhotoType = photoAccessHelper.PhotoType.IMAGE; 392 let extension: string = 'jpg'; 393 let options: photoAccessHelper.CreateOptions = { 394 title: 'testPhoto' 395 } 396 let uri: string = await phAccessHelper.createAsset(photoType, extension, options); 397 console.info('createAsset uri' + uri); 398 console.info('createAsset successfully'); 399 } catch (err) { 400 console.error(`createAsset failed, error: ${err.code}, ${err.message}`); 401 } 402} 403``` 404 405### getAlbums 406 407getAlbums(type: AlbumType, subtype: AlbumSubtype, options: FetchOptions, callback: AsyncCallback<FetchResult<Album>>): void 408 409Obtains albums based on the specified options and album type. This API uses an asynchronous callback to return the result. 410 411Before the operation, ensure that the albums to obtain exist. 412 413**System capability**: SystemCapability.FileManagement.PhotoAccessHelper.Core 414 415**Required permissions**: ohos.permission.READ_IMAGEVIDEO 416 417**Parameters** 418 419| Name | Type | Mandatory| Description | 420| -------- | ------------------------ | ---- | ------------------------- | 421| type | [AlbumType](#albumtype) | Yes | Type of the album. | 422| subtype | [AlbumSubtype](#albumsubtype) | Yes | Subtype of the album. | 423| options | [FetchOptions](#fetchoptions) | Yes | Options for fetching the albums. | 424| callback | AsyncCallback<[FetchResult](#fetchresult)<[Album](#album)>> | Yes | Callback used to return the result.| 425 426**Error codes** 427 428For details about the error codes, see [Universal Error Codes](../errorcode-universal.md) and [File Management Error Codes](../apis-core-file-kit/errorcode-filemanagement.md). 429 430| ID| Error Message| 431| -------- | ---------------------------------------- | 432| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types; 3. Parameter verification failed. | 433| 13900012 | Permission denied. | 434| 13900020 | Invalid argument. | 435| 14000011 | System inner fail. | 436 437**Example** 438 439```ts 440import { dataSharePredicates } from '@kit.ArkData'; 441 442async function example() { 443 // Obtain the album named newAlbumName. 444 console.info('getAlbumsDemo'); 445 let predicates: dataSharePredicates.DataSharePredicates = new dataSharePredicates.DataSharePredicates(); 446 predicates.equalTo('album_name', 'newAlbumName'); 447 let fetchOptions: photoAccessHelper.FetchOptions = { 448 fetchColumns: [], 449 predicates: predicates 450 }; 451 phAccessHelper.getAlbums(photoAccessHelper.AlbumType.USER, photoAccessHelper.AlbumSubtype.USER_GENERIC, fetchOptions, async (err, fetchResult) => { 452 if (err) { 453 console.error(`getAlbumsCallback failed with err: ${err.code}, ${err.message}`); 454 return; 455 } 456 if (fetchResult === undefined) { 457 console.error('getAlbumsCallback fetchResult is undefined'); 458 return; 459 } 460 let album = await fetchResult.getFirstObject(); 461 console.info('getAlbumsCallback successfully, albumName: ' + album.albumName); 462 fetchResult.close(); 463 }); 464} 465``` 466 467### getAlbums 468 469getAlbums(type: AlbumType, subtype: AlbumSubtype, callback: AsyncCallback<FetchResult<Album>>): void 470 471Obtains albums by type. This API uses an asynchronous callback to return the result. 472 473Before the operation, ensure that the albums to obtain exist. 474 475**System capability**: SystemCapability.FileManagement.PhotoAccessHelper.Core 476 477**Required permissions**: ohos.permission.READ_IMAGEVIDEO 478 479**Parameters** 480 481| Name | Type | Mandatory| Description | 482| -------- | ------------------------ | ---- | ------------------------- | 483| type | [AlbumType](#albumtype) | Yes | Type of the album. | 484| subtype | [AlbumSubtype](#albumsubtype) | Yes | Subtype of the album. | 485| callback | AsyncCallback<[FetchResult](#fetchresult)<[Album](#album)>> | Yes | Callback used to return the result.| 486 487**Error codes** 488 489For details about the error codes, see [Universal Error Codes](../errorcode-universal.md) and [File Management Error Codes](../apis-core-file-kit/errorcode-filemanagement.md). 490 491| ID| Error Message| 492| -------- | ---------------------------------------- | 493| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types; 3. Parameter verification failed. | 494| 13900012 | Permission denied. | 495| 13900020 | Invalid argument. | 496| 14000011 | System inner fail. | 497 498**Example** 499 500```ts 501async function example() { 502 // Obtain the system album VIDEO, which is preset by default. 503 console.info('getAlbumsDemo'); 504 phAccessHelper.getAlbums(photoAccessHelper.AlbumType.SYSTEM, photoAccessHelper.AlbumSubtype.VIDEO, async (err, fetchResult) => { 505 if (err) { 506 console.error(`getAlbumsCallback failed with err: ${err.code}, ${err.message}`); 507 return; 508 } 509 if (fetchResult === undefined) { 510 console.error('getAlbumsCallback fetchResult is undefined'); 511 return; 512 } 513 let album: photoAccessHelper.Album = await fetchResult.getFirstObject(); 514 console.info('getAlbumsCallback successfully, albumUri: ' + album.albumUri); 515 fetchResult.close(); 516 }); 517} 518``` 519 520### getAlbums 521 522getAlbums(type: AlbumType, subtype: AlbumSubtype, options?: FetchOptions): Promise<FetchResult<Album>> 523 524Obtains albums based on the specified options and album type. This API uses a promise to return the result. 525 526Before the operation, ensure that the albums to obtain exist. 527 528**System capability**: SystemCapability.FileManagement.PhotoAccessHelper.Core 529 530**Required permissions**: ohos.permission.READ_IMAGEVIDEO 531 532**Parameters** 533 534| Name | Type | Mandatory| Description | 535| -------- | ------------------------ | ---- | ------------------------- | 536| type | [AlbumType](#albumtype) | Yes | Type of the album. | 537| subtype | [AlbumSubtype](#albumsubtype) | Yes | Subtype of the album. | 538| options | [FetchOptions](#fetchoptions) | No | Options for fetching the albums. If this parameter is not specified, the albums are obtained based on the album type by default. | 539 540**Return value** 541 542| Type | Description | 543| --------------------------- | -------------- | 544| Promise<[FetchResult](#fetchresult)<[Album](#album)>> | Promise used to return the result.| 545 546**Error codes** 547 548For details about the error codes, see [Universal Error Codes](../errorcode-universal.md) and [File Management Error Codes](../apis-core-file-kit/errorcode-filemanagement.md). 549 550| ID| Error Message| 551| -------- | ---------------------------------------- | 552| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types; 3. Parameter verification failed. | 553| 13900012 | Permission denied. | 554| 13900020 | Invalid argument. | 555| 14000011 | System inner fail. | 556 557**Example** 558 559```ts 560import { dataSharePredicates } from '@kit.ArkData'; 561import { BusinessError } from '@kit.BasicServicesKit'; 562 563async function example() { 564 // Obtain the album named newAlbumName. 565 console.info('getAlbumsDemo'); 566 let predicates: dataSharePredicates.DataSharePredicates = new dataSharePredicates.DataSharePredicates(); 567 predicates.equalTo('album_name', 'newAlbumName'); 568 let fetchOptions: photoAccessHelper.FetchOptions = { 569 fetchColumns: [], 570 predicates: predicates 571 }; 572 phAccessHelper.getAlbums(photoAccessHelper.AlbumType.USER, photoAccessHelper.AlbumSubtype.USER_GENERIC, fetchOptions).then( async (fetchResult) => { 573 if (fetchResult === undefined) { 574 console.error('getAlbumsPromise fetchResult is undefined'); 575 return; 576 } 577 let album: photoAccessHelper.Album = await fetchResult.getFirstObject(); 578 console.info('getAlbumsPromise successfully, albumName: ' + album.albumName); 579 fetchResult.close(); 580 }).catch((err: BusinessError) => { 581 console.error(`getAlbumsPromise failed with err: ${err.code}, ${err.message}`); 582 }); 583} 584``` 585 586### registerChange 587 588registerChange(uri: string, forChildUris: boolean, callback: Callback<ChangeData>) : void 589 590Registers listening for the specified URI. This API uses a callback to return the result. 591 592**System capability**: SystemCapability.FileManagement.PhotoAccessHelper.Core 593 594**Parameters** 595 596| Name | Type | Mandatory| Description | 597| --------- | ------------------------------------------- | ---- | ------------------------------------------------------------ | 598| uri | string | Yes | URI of the photo asset, URI of the album, or [DefaultChangeUri](#defaultchangeuri).| 599| forChildUris | boolean | Yes | Whether to perform fuzzy listening.<br>If **uri** is the URI of an album, the value **true** means to listen for the changes of the files in the album; the value **false** means to listen for the changes of the album only.<br>If **uri** is the URI of a photoAsset, there is no difference between **true** and false for **forChildUris**.<br>If **uri** is **DefaultChangeUri**, **forChildUris** must be set to **true**. If **forChildUris** is false, the URI cannot be found and no message can be received.| 600| callback | Callback<[ChangeData](#changedata)> | Yes | Callback used to return the [ChangeData](#changedata). <br>**NOTE**<br>Multiple callback listeners can be registered for a URI. You can use [unRegisterChange](#unregisterchange) to unregister all listeners for the URI or a specified callback listener.| 601 602**Error codes** 603 604For details about the error codes, see [Universal Error Codes](../errorcode-universal.md) and [File Management Error Codes](../apis-core-file-kit/errorcode-filemanagement.md). 605 606| ID| Error Message| 607| -------- | ---------------------------------------- | 608| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types; 3. Parameter verification failed. | 609| 13900012 | Permission denied. | 610| 13900020 | Invalid argument. | 611 612**Example** 613 614```ts 615import { dataSharePredicates } from '@kit.ArkData'; 616 617async function example() { 618 console.info('registerChangeDemo'); 619 let predicates: dataSharePredicates.DataSharePredicates = new dataSharePredicates.DataSharePredicates(); 620 let fetchOptions: photoAccessHelper.FetchOptions = { 621 fetchColumns: [], 622 predicates: predicates 623 }; 624 let fetchResult: photoAccessHelper.FetchResult<photoAccessHelper.PhotoAsset> = await phAccessHelper.getAssets(fetchOptions); 625 let photoAsset: photoAccessHelper.PhotoAsset = await fetchResult.getFirstObject(); 626 if (photoAsset !== undefined) { 627 console.info('photoAsset.displayName : ' + photoAsset.displayName); 628 } 629 let onCallback1 = (changeData: photoAccessHelper.ChangeData) => { 630 console.info('onCallback1 success, changData: ' + JSON.stringify(changeData)); 631 //file had changed, do something. 632 } 633 let onCallback2 = (changeData: photoAccessHelper.ChangeData) => { 634 console.info('onCallback2 success, changData: ' + JSON.stringify(changeData)); 635 //file had changed, do something. 636 } 637 // Register onCallback1. 638 phAccessHelper.registerChange(photoAsset.uri, false, onCallback1); 639 // Register onCallback2. 640 phAccessHelper.registerChange(photoAsset.uri, false, onCallback2); 641 642 await photoAccessHelper.MediaAssetChangeRequest.deleteAssets(context, [photoAsset]); 643} 644``` 645 646### unRegisterChange 647 648unRegisterChange(uri: string, callback?: Callback<ChangeData>): void 649 650Unregisters listening for the specified URI. Multiple callbacks can be registered for a URI for listening. You can use this API to unregister the listening of the specified callbacks or all callbacks. 651 652**System capability**: SystemCapability.FileManagement.PhotoAccessHelper.Core 653 654**Parameters** 655 656| Name | Type | Mandatory| Description | 657| -------- | ------------------------------------------- | ---- | ------------------------------------------------------------ | 658| uri | string | Yes | URI of the photo asset, URI of the album, or [DefaultChangeUri](#defaultchangeuri).| 659| callback | Callback<[ChangeData](#changedata)> | No | Callback to unregister. If this parameter is not specified, all the callbacks for listening for the URI will be canceled. <br>**NOTE**: The specified callback unregistered will not be invoked when the data changes.| 660 661**Error codes** 662 663For details about the error codes, see [Universal Error Codes](../errorcode-universal.md) and [File Management Error Codes](../apis-core-file-kit/errorcode-filemanagement.md). 664 665| ID| Error Message| 666| -------- | ---------------------------------------- | 667| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types; 3. Parameter verification failed. | 668| 13900012 | Permission denied. | 669| 13900020 | Invalid argument. | 670 671**Example** 672 673```ts 674import { dataSharePredicates } from '@kit.ArkData'; 675 676async function example() { 677 console.info('offDemo'); 678 let predicates: dataSharePredicates.DataSharePredicates = new dataSharePredicates.DataSharePredicates(); 679 let fetchOptions: photoAccessHelper.FetchOptions = { 680 fetchColumns: [], 681 predicates: predicates 682 }; 683 let fetchResult: photoAccessHelper.FetchResult<photoAccessHelper.PhotoAsset> = await phAccessHelper.getAssets(fetchOptions); 684 let photoAsset: photoAccessHelper.PhotoAsset = await fetchResult.getFirstObject(); 685 if (photoAsset !== undefined) { 686 console.info('photoAsset.displayName : ' + photoAsset.displayName); 687 } 688 let onCallback1 = (changeData: photoAccessHelper.ChangeData) => { 689 console.info('onCallback1 on'); 690 } 691 let onCallback2 = (changeData: photoAccessHelper.ChangeData) => { 692 console.info('onCallback2 on'); 693 } 694 // Register onCallback1. 695 phAccessHelper.registerChange(photoAsset.uri, false, onCallback1); 696 // Register onCallback2. 697 phAccessHelper.registerChange(photoAsset.uri, false, onCallback2); 698 // Unregister the listening of onCallback1. 699 phAccessHelper.unRegisterChange(photoAsset.uri, onCallback1); 700 await photoAccessHelper.MediaAssetChangeRequest.deleteAssets(context, [photoAsset]); 701} 702``` 703 704### createDeleteRequest<sup>(deprecated)</sup> 705 706createDeleteRequest(uriList: Array<string>, callback: AsyncCallback<void>): void 707 708Creates a dialog box for deleting media files. This API uses an asynchronous callback to return the result. The deleted media files are moved to the trash. 709 710> **NOTE** 711> 712> This API is supported since API version 10 and deprecated since API version 11. Use [MediaAssetChangeRequest.deleteAssets](#deleteassets11-1) instead. 713 714**Required permissions**: ohos.permission.WRITE_IMAGEVIDEO 715 716**System capability**: SystemCapability.FileManagement.PhotoAccessHelper.Core 717 718**Parameters** 719 720| Name | Type | Mandatory| Description | 721| -------- | ------------------------- | ---- | ---------- | 722| uriList | Array<string> | Yes | URIs of the media files to delete. A maximum of 300 media files can be deleted.| 723| callback | AsyncCallback<void> | Yes | Callback that returns no value.| 724 725**Error codes** 726 727For details about the error codes, see [Universal Error Codes](../errorcode-universal.md) and [File Management Error Codes](../apis-core-file-kit/errorcode-filemanagement.md). 728 729| ID| Error Message| 730| -------- | ---------------------------------------- | 731| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types; 3. Parameter verification failed. | 732| 13900012 | Permission denied. | 733| 13900020 | Invalid argument. | 734| 14000011 | System inner fail. | 735 736**Example** 737 738```ts 739import { dataSharePredicates } from '@kit.ArkData'; 740 741async function example() { 742 console.info('createDeleteRequestDemo'); 743 let predicates: dataSharePredicates.DataSharePredicates = new dataSharePredicates.DataSharePredicates(); 744 let fetchOptions: photoAccessHelper.FetchOptions = { 745 fetchColumns: [], 746 predicates: predicates 747 }; 748 try { 749 let fetchResult: photoAccessHelper.FetchResult<photoAccessHelper.PhotoAsset> = await phAccessHelper.getAssets(fetchOptions); 750 let asset: photoAccessHelper.PhotoAsset = await fetchResult.getFirstObject(); 751 if (asset === undefined) { 752 console.error('asset not exist'); 753 return; 754 } 755 phAccessHelper.createDeleteRequest([asset.uri], (err) => { 756 if (err === undefined) { 757 console.info('createDeleteRequest successfully'); 758 } else { 759 console.error(`createDeleteRequest failed with error: ${err.code}, ${err.message}`); 760 } 761 }); 762 } catch (err) { 763 console.error(`fetch failed, error: ${err.code}, ${err.message}`); 764 } 765} 766``` 767 768### createDeleteRequest<sup>(deprecated)</sup> 769 770createDeleteRequest(uriList: Array<string>): Promise<void> 771 772Creates a dialog box for deleting media files. This API uses a promise to return the result. The deleted media files are moved to the trash. 773 774> **NOTE** 775> 776> This API is supported since API version 10 and deprecated since API version 11. Use [MediaAssetChangeRequest.deleteAssets](#deleteassets11-1) instead. 777 778**Required permissions**: ohos.permission.WRITE_IMAGEVIDEO 779 780**System capability**: SystemCapability.FileManagement.PhotoAccessHelper.Core 781 782**Parameters** 783 784| Name | Type | Mandatory| Description | 785| -------- | ------------------------- | ---- | ---------- | 786| uriList | Array<string> | Yes | URIs of the media files to delete. A maximum of 300 media files can be deleted.| 787 788**Return value** 789 790| Type | Description | 791| --------------------------------------- | ----------------- | 792| Promise<void>| Promise that returns no value.| 793 794**Error codes** 795 796For details about the error codes, see [Universal Error Codes](../errorcode-universal.md) and [File Management Error Codes](../apis-core-file-kit/errorcode-filemanagement.md). 797 798| ID| Error Message| 799| -------- | ---------------------------------------- | 800| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types; 3. Parameter verification failed. | 801| 13900012 | Permission denied. | 802| 13900020 | Invalid argument. | 803| 14000011 | System inner fail. | 804 805**Example** 806 807```ts 808import { dataSharePredicates } from '@kit.ArkData'; 809 810async function example() { 811 console.info('createDeleteRequestDemo'); 812 let predicates: dataSharePredicates.DataSharePredicates = new dataSharePredicates.DataSharePredicates(); 813 let fetchOptions: photoAccessHelper.FetchOptions = { 814 fetchColumns: [], 815 predicates: predicates 816 }; 817 try { 818 let fetchResult: photoAccessHelper.FetchResult<photoAccessHelper.PhotoAsset> = await phAccessHelper.getAssets(fetchOptions); 819 let asset: photoAccessHelper.PhotoAsset = await fetchResult.getFirstObject(); 820 if (asset === undefined) { 821 console.error('asset not exist'); 822 return; 823 } 824 await phAccessHelper.createDeleteRequest([asset.uri]); 825 console.info('createDeleteRequest successfully'); 826 } catch (err) { 827 console.error(`createDeleteRequest failed with error: ${err.code}, ${err.message}`); 828 } 829} 830``` 831 832### applyChanges<sup>11+</sup> 833 834applyChanges(mediaChangeRequest: MediaChangeRequest): Promise<void> 835 836Applies media changes. This API uses a promise to return the result. 837 838**Required permissions**: ohos.permission.WRITE_IMAGEVIDEO 839 840When you create a media asset by using a security component, you do not need to request the ohos.permission.WRITE_IMAGEVIDEO permission to call this API. For details, see [Creating a Media Asset Using a Security Component](../../media/medialibrary/photoAccessHelper-savebutton.md). 841 842**Atomic service API**: This API can be used in atomic services since API version 11. 843 844**System capability**: SystemCapability.FileManagement.PhotoAccessHelper.Core 845 846**Parameters** 847 848| Name | Type | Mandatory| Description | 849| -------- | ------------------------ | ---- | ------------------------- | 850| mediaChangeRequest | [MediaChangeRequest](#mediachangerequest11) | Yes | Request for asset changes or album changes.| 851 852**Return value** 853 854| Type | Description | 855| --------------------------------------- | ----------------- | 856| Promise<void>| Promise that returns no value.| 857 858**Error codes** 859 860For details about the error codes, see [Universal Error Codes](../errorcode-universal.md) and [File Management Error Codes](../apis-core-file-kit/errorcode-filemanagement.md). 861 862| ID| Error Message| 863| -------- | ---------------------------------------- | 864| 201 | Permission denied. | 865| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types; 3. Parameter verification failed. | 866| 14000011 | System inner fail. | 867 868**Example** 869 870This API depends on the [MediaChangeRequest](#mediachangerequest11) object. For details about the sample code, see the examples of [MediaAssetChangeRequest](#mediaassetchangerequest11) and [MediaAlbumChangeRequest](#mediaalbumchangerequest11). 871 872### release 873 874release(callback: AsyncCallback<void>): void 875 876Releases this **PhotoAccessHelper** instance. This API uses an asynchronous callback to return the result. 877Call this API when the APIs of the **PhotoAccessHelper** instance are no longer used. 878 879**System capability**: SystemCapability.FileManagement.PhotoAccessHelper.Core 880 881**Parameters** 882 883| Name | Type | Mandatory| Description | 884| -------- | ------------------------- | ---- | -------------------- | 885| callback | AsyncCallback<void> | Yes | Callback used to return the result.| 886 887**Error codes** 888 889For details about the error codes, see [Universal Error Codes](../errorcode-universal.md) and [File Management Error Codes](../apis-core-file-kit/errorcode-filemanagement.md). 890 891| ID| Error Message| 892| -------- | ---------------------------------------- | 893| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types. | 894| 13900020 | Invalid argument. | 895| 14000011 | System inner fail. | 896 897**Example** 898 899```ts 900async function example() { 901 console.info('releaseDemo'); 902 phAccessHelper.release((err) => { 903 if (err !== undefined) { 904 console.error(`release failed. error: ${err.code}, ${err.message}`); 905 } else { 906 console.info('release ok.'); 907 } 908 }); 909} 910``` 911 912### release 913 914release(): Promise<void> 915 916Releases this **PhotoAccessHelper** instance. This API uses a promise to return the result. 917Call this API when the APIs of the **PhotoAccessHelper** instance are no longer used. 918 919**System capability**: SystemCapability.FileManagement.PhotoAccessHelper.Core 920 921**Return value** 922 923| Type | Description | 924| ------------------- | --------------------------------- | 925| Promise<void> | Promise that returns no value.| 926 927**Error codes** 928 929For details about the error codes, see [Universal Error Codes](../errorcode-universal.md) and [File Management Error Codes](../apis-core-file-kit/errorcode-filemanagement.md). 930 931| ID| Error Message| 932| -------- | ---------------------------------------- | 933| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types. | 934| 13900020 | Invalid argument. | 935| 14000011 | System inner fail. | 936 937**Example** 938 939```ts 940async function example() { 941 console.info('releaseDemo'); 942 try { 943 await phAccessHelper.release(); 944 console.info('release ok.'); 945 } catch (err) { 946 console.error(`release failed. error: ${err.code}, ${err.message}`); 947 } 948} 949``` 950 951### showAssetsCreationDialog<sup>12+</sup> 952 953showAssetsCreationDialog(srcFileUris: Array<string>, photoCreationConfigs: Array<PhotoCreationConfig>): Promise<Array<string>> 954 955Shows the dialog box for the user to confirm whether to save the photos or videos. If the user agrees to save the images or videos, a list of URIs granted with the save permission is returned. The list takes effect permanently, and the application can write the images or videos based on the URIs. If the user refuses to save the images or videos, an empty list is returned. To display the application name in the dialog box, the API relies on the configuration of **label** and **icon** under **abilities** in the **module.json5** file. If they are not configured, no application name is displayed in the dialog box. 956 957**Atomic service API**: This API can be used in atomic services since API version 12. 958 959**System capability**: SystemCapability.FileManagement.PhotoAccessHelper.Core 960 961**Parameters** 962 963| Name | Type | Mandatory| Description | 964| -------- |----------------------------------------------------------------------| ---- | ------------------------- | 965| srcFileUris | Array<string> | Yes| [URIs](../../file-management/user-file-uri-intro.md#media-file-uri) of the images or videos to be saved to the media library.<br>**NOTE**<br>- Only image and video URIs are supported.<br>- URIs cannot be manually constructed. You must call APIs to obtain them. For details, see [Obtaining a Media File URI](../../file-management/user-file-uri-intro.md#obtaining-a-media-file-uri). | 966| photoCreationConfigs | Array<[PhotoCreationConfig](#photocreationconfig12)> | Yes| Configuration for saving the images or videos, including the names of the files to be saved. The value must be consistent with that of **srcFileUris**.| 967 968**Return value** 969 970| Type | Description | 971| --------------------------------------- | ----------------- | 972| Promise<Array<string>> | Promise used to return a URI list. The URIs are granted with the permission for 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.| 973 974**Error codes** 975 976For details about the error codes, see [Universal Error Codes](../errorcode-universal.md) and [File Management Error Codes](../apis-core-file-kit/errorcode-filemanagement.md). 977 978| ID| Error Message| 979| -------- | ---------------------------------------- | 980| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types; 3. Parameter verification failed. | 981| 14000011 | Internal system error. | 982 983**Example** 984 985```ts 986import { dataSharePredicates } from '@kit.ArkData'; 987import { photoAccessHelper } from '@kit.MediaLibraryKit'; 988 989async function example() { 990 console.info('ShowAssetsCreationDialogDemo.'); 991 992 try { 993 // Obtain the sandbox URIs of the images or videos to be saved to the media library. 994 let srcFileUris: Array<string> = [ 995 'file://fileUriDemo1' // The URI here is an example only. 996 ]; 997 let photoCreationConfigs: Array<photoAccessHelper.PhotoCreationConfig> = [ 998 { 999 title: 'test2', // Optional. 1000 fileNameExtension: 'jpg', 1001 photoType: photoAccessHelper.PhotoType.IMAGE, 1002 subtype: photoAccessHelper.PhotoSubtype.DEFAULT, // This parameter is optional. 1003 } 1004 ]; 1005 let desFileUris: Array<string> = await phAccessHelper.showAssetsCreationDialog(srcFileUris, photoCreationConfigs); 1006 console.info('showAssetsCreationDialog success, data is ' + desFileUris); 1007 } catch (err) { 1008 console.error('showAssetsCreationDialog failed, errCode is ' + err.code + ', errMsg is ' + err.message); 1009 } 1010} 1011``` 1012 1013### createAssetWithShortTermPermission<sup>12+</sup> 1014 1015createAssetWithShortTermPermission(photoCreationConfig: PhotoCreationConfig): Promise<string> 1016 1017Creates an asset with a temporary permission of the given period. When this API is called by an application for the first time, a dialog box will be displayed for the user to confirm whether to save the asset. If the user agrees to save the asset, the asset instance will be created and the file URI granted with the save permission will be returned. The application can write the asset based on the URI 1018within 5 minutes after the user agrees to save the asset. If the same application calls this API again within the 5 minutes, the authorized URI can be automatically returned without the need to display the conformation dialog box. 1019 1020**System capability**: SystemCapability.FileManagement.PhotoAccessHelper.Core 1021 1022**Required permissions**: ohos.permission.SHORT_TERM_WRITE_IMAGEVIDEO 1023 1024**Parameters** 1025 1026| Name | Type | Mandatory| Description | 1027| -------- |----------------------------------------------------------------------| ---- | ------------------------- | 1028| photoCreationConfig | [PhotoCreationConfig](#photocreationconfig12); | Yes| Configuration for saving a media asset (image or video) to the media library, including the file name.| 1029 1030**Return value** 1031 1032| Type | Description | 1033| --------------------------------------- | ----------------- | 1034| Promise<string> | Promise used to return the URI of the asset saved. The URIs are granted with the permission for 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.| 1035 1036**Error codes** 1037 1038For details about the error codes, see [Universal Error Codes](../errorcode-universal.md) and [File Management Error Codes](../apis-core-file-kit/errorcode-filemanagement.md). 1039 1040| ID| Error Message| 1041| -------- | ---------------------------------------- | 1042| 201 | Permission denied | 1043| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types; 3. Parameter verification failed. | 1044| 14000011 | Internal system error | 1045 1046**Example** 1047 1048```ts 1049import { fileIo } from '@kit.CoreFileKit'; 1050 1051async function example() { 1052 console.info('createAssetWithShortTermPermissionDemo.'); 1053 1054 try { 1055 let photoCreationConfig: photoAccessHelper.PhotoCreationConfig = { 1056 title: '123456', 1057 fileNameExtension: 'jpg', 1058 photoType: photoAccessHelper.PhotoType.IMAGE, 1059 subtype: photoAccessHelper.PhotoSubtype.DEFAULT, 1060 }; 1061 1062 let resultUri: string = await phAccessHelper.createAssetWithShortTermPermission(photoCreationConfig); 1063 let resultFile: fileIo.File = fileIo.openSync(resultUri, fileIo.OpenMode.READ_WRITE); 1064 // Use the actual URI and file size. 1065 let srcFile: fileIo.File = fileIo.openSync("file://test.jpg", fileIo.OpenMode.READ_ONLY); 1066 let bufSize: number = 2000000; 1067 let readSize: number = 0; 1068 let buf = new ArrayBuffer(bufSize); 1069 let readLen = fileIo.readSync(srcFile.fd, buf, { 1070 offset: readSize, 1071 length: bufSize 1072 }); 1073 if (readLen > 0) { 1074 readSize += readLen; 1075 fileIo.writeSync(resultFile.fd, buf, { length: readLen }); 1076 } 1077 fileIo.closeSync(srcFile); 1078 fileIo.closeSync(resultFile); 1079 } catch (err) { 1080 console.error('createAssetWithShortTermPermission failed, errCode is ' + err.code + ', errMsg is ' + err.message); 1081 } 1082 1083} 1084``` 1085 1086### requestPhotoUrisReadPermission<sup>14+</sup> 1087 1088requestPhotoUrisReadPermission(srcFileUris: Array<string>): Promise<Array<string>> 1089 1090<!--RP1--><!--RP1End-->Grants the save permission for URIs. This API uses a promise to return the result. 1091 1092**Atomic service API**: This API can be used in atomic services since API version 14. 1093 1094**System capability**: SystemCapability.FileManagement.PhotoAccessHelper.Core 1095 1096**Parameters** 1097 1098| Name | Type | Mandatory| Description | 1099| -------- |----------------------------------------------------------------------| ---- | ------------------------- | 1100| srcFileUris | Array<string> | Yes| [URIs](../../file-management/user-file-uri-intro.md#media-file-uri) of the images or videos to be granted with the permission.<br>**NOTE**: Only image and video URIs are supported.| 1101 1102**Return value** 1103 1104| Type | Description | 1105| --------------------------------------- | ----------------- | 1106| Promise<Array<string>> | Promise used to return the URIs granted with the save permission.| 1107 1108**Error codes** 1109 1110For details about the error codes, see [Universal Error Codes](../errorcode-universal.md) and [File Management Error Codes](../apis-core-file-kit/errorcode-filemanagement.md). 1111 1112| ID| Error Message| 1113| -------- | ---------------------------------------- | 1114| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types; 3. Parameter verification failed. | 1115| 14000011 | Internal system error | 1116 1117**Example** 1118 1119```ts 1120import { dataSharePredicates } from '@kit.ArkData'; 1121import { photoAccessHelper } from '@kit.MediaLibraryKit'; 1122 1123async function example() { 1124 console.info('requestPhotoUrisReadPermissionDemo.'); 1125 1126 try { 1127 let phAccessHelper: photoAccessHelper.PhotoAccessHelper = photoAccessHelper.getPhotoAccessHelper(context); 1128 // Obtain the URIs of the images or videos to be granted with the permission. 1129 let srcFileUris: Array<string> = [ 1130 'file://fileUriDemo1' // The URI here is an example only. 1131 ]; 1132 let desFileUris: Array<string> = await phAccessHelper.requestPhotoUrisReadPermission(srcFileUris); 1133 console.info('requestPhotoUrisReadPermission success, data is ' + desFileUris); 1134 } catch (err) { 1135 console.error('requestPhotoUrisReadPermission failed, errCode is ' + err.code + ', errMsg is ' + err.message); 1136 } 1137} 1138``` 1139 1140## PhotoAsset 1141 1142Provides APIs for encapsulating file asset attributes. 1143 1144### Properties 1145 1146**System capability**: SystemCapability.FileManagement.PhotoAccessHelper.Core 1147 1148| Name | Type | Readable| Writable| Description | 1149| ------------------------- | ------------------------ | ---- | ---- | ------------------------------------------------------ | 1150| uri | string | Yes | No | Media asset URI, for example, **file://media/Photo/1/IMG_datetime_0001/displayName.jpg**. For details, see [Media File URI](../../file-management/user-file-uri-intro.md#media-file-uri).<br>**Atomic service API**: This API can be used in atomic services since API version 12. | 1151| photoType | [PhotoType](#phototype) | Yes | No | Type of the file. | 1152| displayName | string | Yes | No | File name, including the file name extension, to display. | 1153 1154### get 1155 1156get(member: string): MemberType 1157 1158Obtains a **PhotoAsset** member parameter. 1159 1160**System capability**: SystemCapability.FileManagement.PhotoAccessHelper.Core 1161 1162**Parameters** 1163 1164| Name | Type | Mandatory | Description | 1165| -------- | ------------------------- | ---- | ----- | 1166| member | string | Yes | Name of the member parameter to obtain. Except **'uri'**, **'media_type'**, **'subtype'**, and **'display_name'**, you need to pass in [PhotoKeys](#photokeys) in **fetchColumns** in **get()**. For example, to obtain the title attribute, set **fetchColumns: ['title']**.| 1167 1168**Return value** 1169 1170| Type | Description | 1171| ------------------- | --------------------------------- | 1172| [MemberType](#membertype) | **PhotoAsset** member parameter obtained.| 1173 1174**Error codes** 1175 1176For details about the error codes, see [Universal Error Codes](../errorcode-universal.md) and [File Management Error Codes](../apis-core-file-kit/errorcode-filemanagement.md). 1177 1178| ID| Error Message| 1179| -------- | ---------------------------------------- | 1180| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types; 3. Parameter verification failed. | 1181| 13900020 | Invalid argument. | 1182| 14000014 | Member is not a valid PhotoKey. | 1183 1184**Example** 1185 1186```ts 1187import { dataSharePredicates } from '@kit.ArkData'; 1188 1189async function example() { 1190 console.info('photoAssetGetDemo'); 1191 try { 1192 let predicates: dataSharePredicates.DataSharePredicates = new dataSharePredicates.DataSharePredicates(); 1193 let fetchOption: photoAccessHelper.FetchOptions = { 1194 fetchColumns: ['title'], 1195 predicates: predicates 1196 }; 1197 let fetchResult: photoAccessHelper.FetchResult<photoAccessHelper.PhotoAsset> = await phAccessHelper.getAssets(fetchOption); 1198 let photoAsset: photoAccessHelper.PhotoAsset = await fetchResult.getFirstObject(); 1199 let title: photoAccessHelper.PhotoKeys = photoAccessHelper.PhotoKeys.TITLE; 1200 let photoAssetTitle: photoAccessHelper.MemberType = photoAsset.get(title.toString()); 1201 console.info('photoAsset Get photoAssetTitle = ', photoAssetTitle); 1202 } catch (err) { 1203 console.error(`release failed. error: ${err.code}, ${err.message}`); 1204 } 1205} 1206``` 1207 1208### set 1209 1210set(member: string, value: string): void 1211 1212Sets a **PhotoAsset** member parameter. 1213 1214**System capability**: SystemCapability.FileManagement.PhotoAccessHelper.Core 1215 1216**Parameters** 1217 1218| Name | Type | Mandatory | Description | 1219| -------- | ------------------------- | ---- | ----- | 1220| member | string | Yes | Name of the member parameter to set. For example, **[PhotoKeys](#photokeys).TITLE**.| 1221| value | string | Yes | Member parameter to set. Only the value of **[PhotoKeys](#photokeys).TITLE** can be modified.| 1222 1223**Error codes** 1224 1225For details about the error codes, see [Universal Error Codes](../errorcode-universal.md) and [File Management Error Codes](../apis-core-file-kit/errorcode-filemanagement.md). 1226 1227| ID| Error Message| 1228| -------- | ---------------------------------------- | 1229| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types; 3. Parameter verification failed. | 1230| 13900020 | Invalid argument. | 1231| 14000014 | Member is not a valid PhotoKey. | 1232 1233**Example** 1234 1235```ts 1236import { dataSharePredicates } from '@kit.ArkData'; 1237 1238async function example() { 1239 console.info('photoAssetSetDemo'); 1240 try { 1241 let predicates: dataSharePredicates.DataSharePredicates = new dataSharePredicates.DataSharePredicates(); 1242 let fetchOption: photoAccessHelper.FetchOptions = { 1243 fetchColumns: ['title'], 1244 predicates: predicates 1245 }; 1246 let fetchResult: photoAccessHelper.FetchResult<photoAccessHelper.PhotoAsset> = await phAccessHelper.getAssets(fetchOption); 1247 let photoAsset: photoAccessHelper.PhotoAsset = await fetchResult.getFirstObject(); 1248 let title: string = photoAccessHelper.PhotoKeys.TITLE.toString(); 1249 photoAsset.set(title, 'newTitle'); 1250 } catch (err) { 1251 console.error(`release failed. error: ${err.code}, ${err.message}`); 1252 } 1253} 1254``` 1255 1256### commitModify 1257 1258commitModify(callback: AsyncCallback<void>): void 1259 1260Commits the modification on the file metadata to the database. This API uses an asynchronous callback to return the result. 1261 1262**Required permissions**: ohos.permission.WRITE_IMAGEVIDEO 1263 1264**Atomic service API**: This API can be used in atomic services since API version 11. 1265 1266**System capability**: SystemCapability.FileManagement.PhotoAccessHelper.Core 1267 1268**Parameters** 1269 1270| Name | Type | Mandatory | Description | 1271| -------- | ------------------------- | ---- | ----- | 1272| callback | AsyncCallback<void> | Yes | Callback that returns no value.| 1273 1274**Error codes** 1275 1276For details about the error codes, see [Universal Error Codes](../errorcode-universal.md) and [File Management Error Codes](../apis-core-file-kit/errorcode-filemanagement.md). 1277 1278| ID| Error Message| 1279| -------- | ---------------------------------------- | 1280| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types. | 1281| 13900012 | Permission denied. | 1282| 13900020 | Invalid argument. | 1283| 14000001 | Invalid display name. | 1284| 14000011 | System inner fail. | 1285 1286**Example** 1287 1288```ts 1289import { dataSharePredicates } from '@kit.ArkData'; 1290 1291async function example() { 1292 console.info('commitModifyDemo'); 1293 let predicates: dataSharePredicates.DataSharePredicates = new dataSharePredicates.DataSharePredicates(); 1294 let fetchOption: photoAccessHelper.FetchOptions = { 1295 fetchColumns: ['title'], 1296 predicates: predicates 1297 }; 1298 let fetchResult: photoAccessHelper.FetchResult<photoAccessHelper.PhotoAsset> = await phAccessHelper.getAssets(fetchOption); 1299 let photoAsset: photoAccessHelper.PhotoAsset = await fetchResult.getFirstObject(); 1300 let title: string = photoAccessHelper.PhotoKeys.TITLE.toString(); 1301 let photoAssetTitle: photoAccessHelper.MemberType = photoAsset.get(title); 1302 console.info('photoAsset get photoAssetTitle = ', photoAssetTitle); 1303 photoAsset.set(title, 'newTitle2'); 1304 photoAsset.commitModify((err) => { 1305 if (err === undefined) { 1306 let newPhotoAssetTitle: photoAccessHelper.MemberType = photoAsset.get(title); 1307 console.info('photoAsset get newPhotoAssetTitle = ', newPhotoAssetTitle); 1308 } else { 1309 console.error(`commitModify failed, error: ${err.code}, ${err.message}`); 1310 } 1311 }); 1312} 1313``` 1314 1315### commitModify 1316 1317commitModify(): Promise<void> 1318 1319Commits the modification on the file metadata to the database. This API uses a promise to return the result. 1320 1321**Required permissions**: ohos.permission.WRITE_IMAGEVIDEO 1322 1323**Atomic service API**: This API can be used in atomic services since API version 11. 1324 1325**System capability**: SystemCapability.FileManagement.PhotoAccessHelper.Core 1326 1327**Return value** 1328 1329| Type | Description | 1330| ------------------- | ---------- | 1331| Promise<void> | Promise that returns no value.| 1332 1333**Error codes** 1334 1335For details about the error codes, see [Universal Error Codes](../errorcode-universal.md) and [File Management Error Codes](../apis-core-file-kit/errorcode-filemanagement.md). 1336 1337| ID| Error Message| 1338| -------- | ---------------------------------------- | 1339| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types. | 1340| 13900012 | Permission denied. | 1341| 13900020 | Invalid argument. | 1342| 14000001 | Invalid display name. | 1343| 14000011 | System inner fail. | 1344 1345**Example** 1346 1347```ts 1348import { dataSharePredicates } from '@kit.ArkData'; 1349 1350async function example() { 1351 console.info('commitModifyDemo'); 1352 let predicates: dataSharePredicates.DataSharePredicates = new dataSharePredicates.DataSharePredicates(); 1353 let fetchOption: photoAccessHelper.FetchOptions = { 1354 fetchColumns: ['title'], 1355 predicates: predicates 1356 }; 1357 let fetchResult: photoAccessHelper.FetchResult<photoAccessHelper.PhotoAsset> = await phAccessHelper.getAssets(fetchOption); 1358 let photoAsset: photoAccessHelper.PhotoAsset = await fetchResult.getFirstObject(); 1359 let title: string = photoAccessHelper.PhotoKeys.TITLE.toString(); 1360 let photoAssetTitle: photoAccessHelper.MemberType = photoAsset.get(title); 1361 console.info('photoAsset get photoAssetTitle = ', photoAssetTitle); 1362 photoAsset.set(title, 'newTitle3'); 1363 try { 1364 await photoAsset.commitModify(); 1365 let newPhotoAssetTitle: photoAccessHelper.MemberType = photoAsset.get(title); 1366 console.info('photoAsset get newPhotoAssetTitle = ', newPhotoAssetTitle); 1367 } catch (err) { 1368 console.error(`release failed. error: ${err.code}, ${err.message}`); 1369 } 1370} 1371``` 1372 1373### getReadOnlyFd<sup>(deprecated)</sup> 1374 1375getReadOnlyFd(callback: AsyncCallback<number>): void 1376 1377Opens this file in read-only mode. This API uses an asynchronous callback to return the result. 1378 1379> **NOTE** 1380> 1381> - 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. 1382 1383> - The returned FD must be closed when it is not required. 1384 1385**Required permissions**: ohos.permission.READ_IMAGEVIDEO 1386 1387**System capability**: SystemCapability.FileManagement.PhotoAccessHelper.Core 1388 1389**Parameters** 1390 1391| Name | Type | Mandatory | Description | 1392| -------- | --------------------------- | ---- | ----------------------------------- | 1393| callback | AsyncCallback<number> | Yes | Callback used to return the file descriptor (FD) of the file opened. | 1394 1395**Error codes** 1396 1397For details about the error codes, see [Universal Error Codes](../errorcode-universal.md) and [File Management Error Codes](../apis-core-file-kit/errorcode-filemanagement.md). 1398 1399| ID| Error Message| 1400| -------- | ---------------------------------------- | 1401| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types. | 1402| 13900012 | Permission denied. | 1403| 13900020 | Invalid argument. | 1404| 14000011 | System inner fail. | 1405 1406**Example** 1407 1408```ts 1409async function example() { 1410 console.info('getReadOnlyFdDemo'); 1411 // Ensure that there are images and video files in the device. 1412 let predicates: dataSharePredicates.DataSharePredicates = new dataSharePredicates.DataSharePredicates(); 1413 let fetchOptions: photoAccessHelper.FetchOptions = { 1414 fetchColumns: [], 1415 predicates: predicates 1416 }; 1417 let assetResult: photoAccessHelper.FetchResult<photoAccessHelper.PhotoAsset> = await phAccessHelper.getAssets(fetchOptions); 1418 let photoAsset: photoAccessHelper.PhotoAsset = await assetResult.getFirstObject(); 1419 photoAsset.getReadOnlyFd((err, fd) => { 1420 if (fd !== undefined) { 1421 console.info('File fd' + fd); 1422 photoAsset.close(fd); 1423 } else { 1424 console.error(`getReadOnlyFd err: ${err.code}, ${err.message}`); 1425 } 1426 }); 1427} 1428``` 1429 1430### getReadOnlyFd<sup>(deprecated)</sup> 1431 1432getReadOnlyFd(): Promise<number> 1433 1434Opens this file in read-only mode. This API uses a promise to return the result. 1435 1436> **NOTE** 1437> 1438> - 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. 1439 1440> - The returned FD must be closed when it is not required. 1441 1442**Required permissions**: ohos.permission.READ_IMAGEVIDEO 1443 1444**System capability**: SystemCapability.FileManagement.PhotoAccessHelper.Core 1445 1446**Return value** 1447 1448| Type | Description | 1449| --------------------- | ------------- | 1450| Promise<number> | Promise used to return the FD of the file opened.| 1451 1452**Error codes** 1453 1454For details about the error codes, see [Universal Error Codes](../errorcode-universal.md) and [File Management Error Codes](../apis-core-file-kit/errorcode-filemanagement.md). 1455 1456| ID| Error Message| 1457| -------- | ---------------------------------------- | 1458| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types. | 1459| 13900012 | Permission denied. | 1460| 13900020 | Invalid argument. | 1461| 14000011 | System inner fail. | 1462 1463**Example** 1464 1465```ts 1466async function example() { 1467 console.info('getReadOnlyFdDemo'); 1468 try { 1469 // Ensure that there are images and video files in the device. 1470 let predicates: dataSharePredicates.DataSharePredicates = new dataSharePredicates.DataSharePredicates(); 1471 let fetchOptions: photoAccessHelper.FetchOptions = { 1472 fetchColumns: [], 1473 predicates: predicates 1474 }; 1475 let assetResult: photoAccessHelper.FetchResult<photoAccessHelper.PhotoAsset> = await phAccessHelper.getAssets(fetchOptions); 1476 let photoAsset: photoAccessHelper.PhotoAsset = await assetResult.getFirstObject(); 1477 let fd: number = await photoAsset.getReadOnlyFd(); 1478 if (fd !== undefined) { 1479 console.info('File fd' + fd); 1480 photoAsset.close(fd); 1481 } else { 1482 console.error('getReadOnlyFd fail'); 1483 } 1484 } catch (err) { 1485 console.error(`getReadOnlyFd demo err: ${err.code}, ${err.message}`); 1486 } 1487} 1488``` 1489 1490### close<sup>(deprecated)</sup> 1491 1492close(fd: number, callback: AsyncCallback<void>): void 1493 1494Closes a file. This API uses an asynchronous callback to return the result. 1495 1496> **NOTE** 1497> 1498> 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, and the corresponding **close** API is also deprecated. 1499 1500**System capability**: SystemCapability.FileManagement.PhotoAccessHelper.Core 1501 1502**Parameters** 1503 1504| Name | Type | Mandatory | Description | 1505| -------- | ------------------------- | ---- | ----- | 1506| fd | number | Yes | FD of the file to close.| 1507| callback | AsyncCallback<void> | Yes | Callback that returns no value.| 1508 1509**Error codes** 1510 1511For details about the error codes, see [Universal Error Codes](../errorcode-universal.md) and [File Management Error Codes](../apis-core-file-kit/errorcode-filemanagement.md). 1512 1513| ID| Error Message| 1514| -------- | ---------------------------------------- | 1515| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types; 3. Parameter verification failed. | 1516| 13900020 | Invalid argument. | 1517| 14000011 | System inner fail. | 1518 1519**Example** 1520 1521```ts 1522import { dataSharePredicates } from '@kit.ArkData'; 1523 1524async function example() { 1525 console.info('closeDemo'); 1526 try { 1527 let predicates: dataSharePredicates.DataSharePredicates = new dataSharePredicates.DataSharePredicates(); 1528 let fetchOption: photoAccessHelper.FetchOptions = { 1529 fetchColumns: [], 1530 predicates: predicates 1531 }; 1532 let fetchResult: photoAccessHelper.FetchResult<photoAccessHelper.PhotoAsset> = await phAccessHelper.getAssets(fetchOption); 1533 let photoAsset: photoAccessHelper.PhotoAsset = await fetchResult.getFirstObject(); 1534 let fd: number = await photoAsset.open('rw'); 1535 console.info('file fd', fd); 1536 photoAsset.close(fd, (err) => { 1537 if (err === undefined) { 1538 console.info('asset close succeed.'); 1539 } else { 1540 console.error(`close failed, error: ${err.code}, ${err.message}`); 1541 } 1542 }); 1543 } catch (err) { 1544 console.error(`close failed, error: ${err.code}, ${err.message}`); 1545 } 1546} 1547``` 1548 1549### close<sup>(deprecated)</sup> 1550 1551close(fd: number): Promise<void> 1552 1553Closes a file. This API uses a promise to return the result. 1554 1555> **NOTE** 1556> 1557> 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, and the corresponding **close** API is also deprecated. 1558 1559**System capability**: SystemCapability.FileManagement.PhotoAccessHelper.Core 1560 1561**Parameters** 1562 1563| Name | Type | Mandatory | Description | 1564| ---- | ------ | ---- | ----- | 1565| fd | number | Yes | FD of the file to close.| 1566 1567**Return value** 1568 1569| Type | Description | 1570| ------------------- | ---------- | 1571| Promise<void> | Promise that returns no value.| 1572 1573**Error codes** 1574 1575For details about the error codes, see [Universal Error Codes](../errorcode-universal.md) and [File Management Error Codes](../apis-core-file-kit/errorcode-filemanagement.md). 1576 1577| ID| Error Message| 1578| -------- | ---------------------------------------- | 1579| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types; 3. Parameter verification failed. | 1580| 13900020 | Invalid argument. | 1581| 14000011 | System inner fail. | 1582 1583**Example** 1584 1585```ts 1586import { dataSharePredicates } from '@kit.ArkData'; 1587 1588async function example() { 1589 console.info('closeDemo'); 1590 try { 1591 let predicates: dataSharePredicates.DataSharePredicates = new dataSharePredicates.DataSharePredicates(); 1592 let fetchOption: photoAccessHelper.FetchOptions = { 1593 fetchColumns: [], 1594 predicates: predicates 1595 }; 1596 let fetchResult: photoAccessHelper.FetchResult<photoAccessHelper.PhotoAsset> = await phAccessHelper.getAssets(fetchOption); 1597 let asset: photoAccessHelper.PhotoAsset = await fetchResult.getFirstObject(); 1598 let fd = await asset.open('rw'); 1599 console.info('file fd', fd); 1600 await asset.close(fd); 1601 console.info('asset close succeed.'); 1602 } catch (err) { 1603 console.error(`close failed, error: ${err.code}, ${err.message}`); 1604 } 1605} 1606``` 1607 1608### getThumbnail 1609 1610getThumbnail(callback: AsyncCallback<image.PixelMap>): void 1611 1612Obtains the thumbnail of this file. This API uses an asynchronous callback to return the result. 1613 1614**Required permissions**: ohos.permission.READ_IMAGEVIDEO 1615 1616**System capability**: SystemCapability.FileManagement.PhotoAccessHelper.Core 1617 1618**Parameters** 1619 1620| Name | Type | Mandatory | Description | 1621| -------- | ----------------------------------- | ---- | ---------------- | 1622| callback | AsyncCallback<[image.PixelMap](../apis-image-kit/js-apis-image.md#pixelmap7)> | Yes | Callback used to return the PixelMap of the thumbnail.| 1623 1624**Error codes** 1625 1626For details about the error codes, see [Universal Error Codes](../errorcode-universal.md) and [File Management Error Codes](../apis-core-file-kit/errorcode-filemanagement.md). 1627 1628| ID| Error Message| 1629| -------- | ---------------------------------------- | 1630| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types. | 1631| 13900012 | Permission denied. | 1632| 13900020 | Invalid argument. | 1633| 14000011 | System inner fail. | 1634 1635**Example** 1636 1637```ts 1638import { dataSharePredicates } from '@kit.ArkData'; 1639 1640async function example() { 1641 console.info('getThumbnailDemo'); 1642 let predicates: dataSharePredicates.DataSharePredicates = new dataSharePredicates.DataSharePredicates(); 1643 let fetchOption: photoAccessHelper.FetchOptions = { 1644 fetchColumns: [], 1645 predicates: predicates 1646 }; 1647 let fetchResult: photoAccessHelper.FetchResult<photoAccessHelper.PhotoAsset> = await phAccessHelper.getAssets(fetchOption); 1648 let asset: photoAccessHelper.PhotoAsset = await fetchResult.getFirstObject(); 1649 console.info('asset displayName = ', asset.displayName); 1650 asset.getThumbnail((err, pixelMap) => { 1651 if (err === undefined) { 1652 console.info('getThumbnail successful ' + pixelMap); 1653 } else { 1654 console.error(`getThumbnail fail with error: ${err.code}, ${err.message}`); 1655 } 1656 }); 1657} 1658``` 1659 1660### getThumbnail 1661 1662getThumbnail(size: image.Size, callback: AsyncCallback<image.PixelMap>): void 1663 1664Obtains the file thumbnail of the given size. This API uses an asynchronous callback to return the result. 1665 1666**Required permissions**: ohos.permission.READ_IMAGEVIDEO 1667 1668**System capability**: SystemCapability.FileManagement.PhotoAccessHelper.Core 1669 1670**Parameters** 1671 1672| Name | Type | Mandatory | Description | 1673| -------- | ----------------------------------- | ---- | ---------------- | 1674| size | [image.Size](../apis-image-kit/js-apis-image.md#size) | Yes | Size of the thumbnail. | 1675| callback | AsyncCallback<[image.PixelMap](../apis-image-kit/js-apis-image.md#pixelmap7)> | Yes | Callback used to return the PixelMap of the thumbnail.| 1676 1677**Error codes** 1678 1679For details about the error codes, see [Universal Error Codes](../errorcode-universal.md) and [File Management Error Codes](../apis-core-file-kit/errorcode-filemanagement.md). 1680 1681| ID| Error Message| 1682| -------- | ---------------------------------------- | 1683| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types; 3. Parameter verification failed. | 1684| 13900012 | Permission denied. | 1685| 13900020 | Invalid argument. | 1686| 14000011 | System inner fail. | 1687 1688**Example** 1689 1690```ts 1691import { dataSharePredicates } from '@kit.ArkData'; 1692import { image } from '@kit.ImageKit'; 1693 1694async function example() { 1695 console.info('getThumbnailDemo'); 1696 let predicates: dataSharePredicates.DataSharePredicates = new dataSharePredicates.DataSharePredicates(); 1697 let fetchOption: photoAccessHelper.FetchOptions = { 1698 fetchColumns: [], 1699 predicates: predicates 1700 }; 1701 let size: image.Size = { width: 720, height: 720 }; 1702 let fetchResult: photoAccessHelper.FetchResult<photoAccessHelper.PhotoAsset> = await phAccessHelper.getAssets(fetchOption); 1703 let asset = await fetchResult.getFirstObject(); 1704 console.info('asset displayName = ', asset.displayName); 1705 asset.getThumbnail(size, (err, pixelMap) => { 1706 if (err === undefined) { 1707 console.info('getThumbnail successful ' + pixelMap); 1708 } else { 1709 console.error(`getThumbnail fail with error: ${err.code}, ${err.message}`); 1710 } 1711 }); 1712} 1713``` 1714 1715### getThumbnail 1716 1717getThumbnail(size?: image.Size): Promise<image.PixelMap> 1718 1719Obtains the file thumbnail of the given size. This API uses a promise to return the result. 1720 1721**Required permissions**: ohos.permission.READ_IMAGEVIDEO 1722 1723**System capability**: SystemCapability.FileManagement.PhotoAccessHelper.Core 1724 1725**Parameters** 1726 1727| Name | Type | Mandatory | Description | 1728| ---- | -------------- | ---- | ----- | 1729| size | [image.Size](../apis-image-kit/js-apis-image.md#size) | No | Size of the thumbnail.| 1730 1731**Return value** 1732 1733| Type | Description | 1734| ----------------------------- | --------------------- | 1735| Promise<[image.PixelMap](../apis-image-kit/js-apis-image.md#pixelmap7)> | Promise used to return the PixelMap of the thumbnail.| 1736 1737**Error codes** 1738 1739For details about the error codes, see [Universal Error Codes](../errorcode-universal.md) and [File Management Error Codes](../apis-core-file-kit/errorcode-filemanagement.md). 1740 1741| ID| Error Message| 1742| -------- | ---------------------------------------- | 1743| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types; 3. Parameter verification failed. | 1744| 13900012 | Permission denied. | 1745| 13900020 | Invalid argument. | 1746| 14000011 | System inner fail. | 1747 1748**Example** 1749 1750```ts 1751import { dataSharePredicates } from '@kit.ArkData'; 1752import { image } from '@kit.ImageKit'; 1753import { BusinessError } from '@kit.BasicServicesKit'; 1754 1755async function example() { 1756 console.info('getThumbnailDemo'); 1757 let predicates: dataSharePredicates.DataSharePredicates = new dataSharePredicates.DataSharePredicates(); 1758 let fetchOption: photoAccessHelper.FetchOptions = { 1759 fetchColumns: [], 1760 predicates: predicates 1761 }; 1762 let size: image.Size = { width: 720, height: 720 }; 1763 let fetchResult: photoAccessHelper.FetchResult<photoAccessHelper.PhotoAsset> = await phAccessHelper.getAssets(fetchOption); 1764 let asset = await fetchResult.getFirstObject(); 1765 console.info('asset displayName = ', asset.displayName); 1766 asset.getThumbnail(size).then((pixelMap) => { 1767 console.info('getThumbnail successful ' + pixelMap); 1768 }).catch((err: BusinessError) => { 1769 console.error(`getThumbnail fail with error: ${err.code}, ${err.message}`); 1770 }); 1771} 1772``` 1773 1774### clone<sup>14+</sup> 1775 1776clone(title: string): Promise<PhotoAsset> 1777 1778Clones a media asset. The file name can be set, but the file type cannot be changed. 1779 1780**Required permissions**: ohos.permission.WRITE\_IMAGEVIDEO 1781 1782**System capability**: SystemCapability.FileManagement.PhotoAccessHelper.Core 1783 1784**Parameters** 1785 1786| Name | Type | Mandatory | Description | 1787| ---------- | ------- | ---- | ---------------------------------- | 1788| title| string | Yes | Title of the cloned asset. The title must meet the following requirements:<br>- It does not contain a file name extension.<br>- The file name, which is in the format of title+file name extension, does not exceed 255 characters.<br>- The title does not contain any of the following characters:\ / : * ? " ' ` < > \| { } [ ] | 1789 1790**Return value** 1791 1792| Type | Description | 1793| ------------------- | ----------------------- | 1794| Promise<PhotoAsset> | Promise used to return the [PhotoAsset](#photoasset) cloned.| 1795 1796**Error codes** 1797 1798For details about the error codes, see [Universal Error Codes](../errorcode-universal.md) and [File Management Error Codes](../apis-core-file-kit/errorcode-filemanagement.md). 1799 1800| ID | Error Message | 1801| :------- | :-------------------------------- | 1802| 201 | Permission denied. | 1803| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types; 3. Parameter verification failed. | 1804| 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. | 1805 1806**Example** 1807 1808```ts 1809import { dataSharePredicates } from '@kit.ArkData'; 1810import { systemDateTime } from '@kit.BasicServicesKit'; 1811 1812async function example() { 1813 let predicates: dataSharePredicates.DataSharePredicates = new dataSharePredicates.DataSharePredicates(); 1814 let fetchOptions: photoAccessHelper.FetchOptions = { 1815 fetchColumns: [], 1816 predicates: predicates 1817 }; 1818 try { 1819 let fetchResult: photoAccessHelper.FetchResult<photoAccessHelper.PhotoAsset> = await phAccessHelper.getAssets(fetchOptions); 1820 let photoAsset: photoAccessHelper.PhotoAsset = await fetchResult.getFirstObject(); 1821 let title: string = systemDateTime.getTime().toString(); 1822 let newAsset: photoAccessHelper.PhotoAsset = await photoAsset.clone(title); 1823 console.info('get new asset successfully'); 1824 } catch (error) { 1825 console.error(`failed to get new asset. message = ${error.code}, ${error.message}`); 1826 } 1827} 1828``` 1829 1830## PhotoViewPicker 1831 1832Provides APIs for the user to select images and videos. Before using the APIs of **PhotoViewPicker**, you need to create a **PhotoViewPicker** instance. 1833 1834**Atomic service API**: This API can be used in atomic services since API version 11. 1835 1836**System capability**: SystemCapability.FileManagement.PhotoAccessHelper.Core 1837 1838**Example** 1839 1840```ts 1841let photoPicker = new photoAccessHelper.PhotoViewPicker(); 1842``` 1843 1844### select 1845 1846select(option?: PhotoSelectOptions) : Promise<PhotoSelectResult> 1847 1848Starts a **photoPicker** page for the user to select one or more images or videos. This API uses a promise to return the result. You can pass in **PhotoSelectOptions** to specify the media file type and the maximum number of files to select. 1849 1850**NOTE**<br>The **photoUris** in the **PhotoSelectResult** object returned by this API has permanent authorization and can be used only by calling [photoAccessHelper.getAssets()](#getassets). For details, see [Using a Media File URI](../../file-management/user-file-uri-intro.md#using-a-media-file-uri). 1851 1852**Atomic service API**: This API can be used in atomic services since API version 11. 1853 1854**System capability**: SystemCapability.FileManagement.PhotoAccessHelper.Core 1855 1856**Parameters** 1857 1858| Name | Type | Mandatory| Description | 1859| ------- | ------- | ---- | -------------------------- | 1860| option | [PhotoSelectOptions](#photoselectoptions) | No | Options for selecting files. If this parameter is not specified, up to 50 images and videos are selected by default.| 1861 1862**Return value** 1863 1864| Type | Description | 1865| ----------------------------- | :---- | 1866| Promise<[PhotoSelectResult](#photoselectresult)> | Promise return information about the images or videos selected.| 1867 1868**Error codes** 1869 1870For details about the error codes, see [Universal Error Codes](../errorcode-universal.md) and [File Management Error Codes](../apis-core-file-kit/errorcode-filemanagement.md). 1871 1872| ID| Error Message| 1873| -------- | ---------------------------------------- | 1874| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types; 3. Parameter verification failed. | 1875| 13900042 | Unknown error. | 1876 1877**Example** 1878 1879```ts 1880import { BusinessError } from '@kit.BasicServicesKit'; 1881async function example01() { 1882 try { 1883 let PhotoSelectOptions = new photoAccessHelper.PhotoSelectOptions(); 1884 PhotoSelectOptions.MIMEType = photoAccessHelper.PhotoViewMIMETypes.IMAGE_TYPE; 1885 PhotoSelectOptions.maxSelectNumber = 5; 1886 let photoPicker = new photoAccessHelper.PhotoViewPicker(); 1887 photoPicker.select(PhotoSelectOptions).then((PhotoSelectResult: photoAccessHelper.PhotoSelectResult) => { 1888 console.info('PhotoViewPicker.select successfully, PhotoSelectResult uri: ' + JSON.stringify(PhotoSelectResult)); 1889 }).catch((err: BusinessError) => { 1890 console.error(`PhotoViewPicker.select failed with err: ${err.code}, ${err.message}`); 1891 }); 1892 } catch (error) { 1893 let err: BusinessError = error as BusinessError; 1894 console.error(`PhotoViewPicker failed with err: ${err.code}, ${err.message}`); 1895 } 1896} 1897``` 1898 1899### select 1900 1901select(option: PhotoSelectOptions, callback: AsyncCallback<PhotoSelectResult>) : void 1902 1903Starts a **photoPicker** page for the user to select one or more images or videos. This API uses an asynchronous callback to return the result. You can pass in **PhotoSelectOptions** to specify the media file type and the maximum number of files to select. 1904 1905**NOTE**<br>The **photoUris** in the **PhotoSelectResult** object returned by this API has permanent authorization and can be used only by calling [photoAccessHelper.getAssets()](#getassets). For details, see [Using a Media File URI](../../file-management/user-file-uri-intro.md#using-a-media-file-uri). 1906 1907**Atomic service API**: This API can be used in atomic services since API version 11. 1908 1909**System capability**: SystemCapability.FileManagement.PhotoAccessHelper.Core 1910 1911**Parameters** 1912 1913| Name | Type | Mandatory| Description | 1914| ------- | ------- | ---- | -------------------------- | 1915| option | [PhotoSelectOptions](#photoselectoptions) | Yes | Options for selecting images or videos.| 1916| callback | AsyncCallback<[PhotoSelectResult](#photoselectresult)> | Yes | Callback used to return information about the images or videos selected.| 1917 1918**Error codes** 1919 1920For details about the error codes, see [Universal Error Codes](../errorcode-universal.md) and [File Management Error Codes](../apis-core-file-kit/errorcode-filemanagement.md). 1921 1922| ID| Error Message| 1923| -------- | ---------------------------------------- | 1924| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types; 3. Parameter verification failed. | 1925| 13900042 | Unknown error. | 1926 1927**Example** 1928 1929```ts 1930import { BusinessError } from '@kit.BasicServicesKit'; 1931async function example02() { 1932 try { 1933 let PhotoSelectOptions = new photoAccessHelper.PhotoSelectOptions(); 1934 PhotoSelectOptions.MIMEType = photoAccessHelper.PhotoViewMIMETypes.IMAGE_TYPE; 1935 PhotoSelectOptions.maxSelectNumber = 5; 1936 let photoPicker = new photoAccessHelper.PhotoViewPicker(); 1937 photoPicker.select(PhotoSelectOptions, (err: BusinessError, PhotoSelectResult: photoAccessHelper.PhotoSelectResult) => { 1938 if (err) { 1939 console.error(`PhotoViewPicker.select failed with err: ${err.code}, ${err.message}`); 1940 return; 1941 } 1942 console.info('PhotoViewPicker.select successfully, PhotoSelectResult uri: ' + JSON.stringify(PhotoSelectResult)); 1943 }); 1944 } catch (error) { 1945 let err: BusinessError = error as BusinessError; 1946 console.error(`PhotoViewPicker failed with err: ${err.code}, ${err.message}`); 1947 } 1948} 1949``` 1950 1951### select 1952 1953select(callback: AsyncCallback<PhotoSelectResult>) : void 1954 1955Starts a **photoPicker** page for the user to select one or more images or videos. This API uses an asynchronous callback to return the result. 1956 1957**NOTE**<br>The **photoUris** in the **PhotoSelectResult** object returned by this API has permanent authorization and can be used only by calling [photoAccessHelper.getAssets()](#getassets). For details, see [Using a Media File URI](../../file-management/user-file-uri-intro.md#using-a-media-file-uri). 1958 1959**Atomic service API**: This API can be used in atomic services since API version 11. 1960 1961**System capability**: SystemCapability.FileManagement.PhotoAccessHelper.Core 1962 1963**Parameters** 1964 1965| Name | Type | Mandatory| Description | 1966| ------- | ------- | ---- | -------------------------- | 1967| callback | AsyncCallback<[PhotoSelectResult](#photoselectresult)> | Yes | Callback used to return information about the images or videos selected.| 1968 1969**Error codes** 1970 1971For details about the error codes, see [Universal Error Codes](../errorcode-universal.md) and [File Management Error Codes](../apis-core-file-kit/errorcode-filemanagement.md). 1972 1973| ID| Error Message| 1974| -------- | ---------------------------------------- | 1975| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types. | 1976| 13900042 | Unknown error. | 1977 1978**Example** 1979 1980```ts 1981import { BusinessError } from '@kit.BasicServicesKit'; 1982async function example03() { 1983 try { 1984 let photoPicker = new photoAccessHelper.PhotoViewPicker(); 1985 photoPicker.select((err: BusinessError, PhotoSelectResult: photoAccessHelper.PhotoSelectResult) => { 1986 if (err) { 1987 console.error(`PhotoViewPicker.select failed with err: ${err.code}, ${err.message}`); 1988 return; 1989 } 1990 console.info('PhotoViewPicker.select successfully, PhotoSelectResult uri: ' + JSON.stringify(PhotoSelectResult)); 1991 }); 1992 } catch (error) { 1993 let err: BusinessError = error as BusinessError; 1994 console.error(`PhotoViewPicker failed with err: ${err.code}, ${err.message}`); 1995 } 1996} 1997``` 1998 1999## FetchResult 2000 2001Provides APIs to manage the file retrieval result. 2002 2003### getCount 2004 2005getCount(): number 2006 2007Obtains the total number of files in the result set. 2008 2009**System capability**: SystemCapability.FileManagement.PhotoAccessHelper.Core 2010 2011**Return value** 2012 2013| Type | Description | 2014| ------ | -------- | 2015| number | Returns the total number of files obtained.| 2016 2017**Error codes** 2018 2019For details about the error codes, see [Universal Error Codes](../errorcode-universal.md) and [File Management Error Codes](../apis-core-file-kit/errorcode-filemanagement.md). 2020 2021| ID| Error Message| 2022| -------- | ---------------------------------------- | 2023| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types. | 2024| 13900020 | Invalid argument. | 2025| 14000011 | System inner fail. | 2026 2027**Example** 2028 2029```ts 2030import { dataSharePredicates } from '@kit.ArkData'; 2031 2032async function example() { 2033 console.info('getCountDemo'); 2034 let predicates: dataSharePredicates.DataSharePredicates = new dataSharePredicates.DataSharePredicates(); 2035 let fetchOption: photoAccessHelper.FetchOptions = { 2036 fetchColumns: [], 2037 predicates: predicates 2038 }; 2039 let fetchResult: photoAccessHelper.FetchResult<photoAccessHelper.PhotoAsset> = await phAccessHelper.getAssets(fetchOption); 2040 let fetchCount = fetchResult.getCount(); 2041 console.info('fetchCount = ', fetchCount); 2042} 2043``` 2044 2045### isAfterLast 2046 2047isAfterLast(): boolean 2048 2049Checks whether the cursor is in the last row of the result set. 2050 2051**System capability**: SystemCapability.FileManagement.PhotoAccessHelper.Core 2052 2053**Return value** 2054 2055| Type | Description | 2056| ------- | ---------------------------------- | 2057| boolean | Returns **true** if the cursor is in the last row of the result set; returns **false** otherwise.| 2058 2059**Error codes** 2060 2061For details about the error codes, see [Universal Error Codes](../errorcode-universal.md) and [File Management Error Codes](../apis-core-file-kit/errorcode-filemanagement.md). 2062 2063| ID| Error Message| 2064| -------- | ---------------------------------------- | 2065| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types. | 2066| 13900020 | Invalid argument. | 2067| 14000011 | System inner fail. | 2068 2069**Example** 2070 2071```ts 2072import { dataSharePredicates } from '@kit.ArkData'; 2073 2074async function example() { 2075 let predicates: dataSharePredicates.DataSharePredicates = new dataSharePredicates.DataSharePredicates(); 2076 let fetchOption: photoAccessHelper.FetchOptions = { 2077 fetchColumns: [], 2078 predicates: predicates 2079 }; 2080 let fetchResult: photoAccessHelper.FetchResult<photoAccessHelper.PhotoAsset> = await phAccessHelper.getAssets(fetchOption); 2081 let fetchCount = fetchResult.getCount(); 2082 console.info('count:' + fetchCount); 2083 let photoAsset: photoAccessHelper.PhotoAsset = await fetchResult.getLastObject(); 2084 if (fetchResult.isAfterLast()) { 2085 console.info('photoAsset isAfterLast displayName = ', photoAsset.displayName); 2086 } else { 2087 console.info('photoAsset not isAfterLast.'); 2088 } 2089} 2090``` 2091 2092### close 2093 2094close(): void 2095 2096Closes this **FetchFileResult** instance to invalidate it. After this instance is released, the APIs in this instance cannot be invoked. 2097 2098**System capability**: SystemCapability.FileManagement.PhotoAccessHelper.Core 2099 2100**Error codes** 2101 2102For details about the error codes, see [Universal Error Codes](../errorcode-universal.md) and [File Management Error Codes](../apis-core-file-kit/errorcode-filemanagement.md). 2103 2104| ID| Error Message| 2105| -------- | ---------------------------------------- | 2106| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types. | 2107| 13900020 | Invalid argument. | 2108| 14000011 | System inner fail. | 2109 2110**Example** 2111 2112```ts 2113import { dataSharePredicates } from '@kit.ArkData'; 2114 2115async function example() { 2116 console.info('fetchResultCloseDemo'); 2117 let predicates: dataSharePredicates.DataSharePredicates = new dataSharePredicates.DataSharePredicates(); 2118 let fetchOption: photoAccessHelper.FetchOptions = { 2119 fetchColumns: [], 2120 predicates: predicates 2121 }; 2122 try { 2123 let fetchResult: photoAccessHelper.FetchResult<photoAccessHelper.PhotoAsset> = await phAccessHelper.getAssets(fetchOption); 2124 fetchResult.close(); 2125 console.info('close succeed.'); 2126 } catch (err) { 2127 console.error(`close fail. error: ${err.code}, ${err.message}`); 2128 } 2129} 2130``` 2131 2132### getFirstObject 2133 2134getFirstObject(callback: AsyncCallback<T>): void 2135 2136Obtains the first file asset in the result set. This API uses an asynchronous callback to return the result. 2137 2138**System capability**: SystemCapability.FileManagement.PhotoAccessHelper.Core 2139 2140**Parameters** 2141 2142| Name | Type | Mandatory| Description | 2143| -------- | --------------------------------------------- | ---- | ------------------------------------------- | 2144| callback | AsyncCallback<T> | Yes | Callback used to return the first file asset obtained.| 2145 2146**Error codes** 2147 2148For details about the error codes, see [Universal Error Codes](../errorcode-universal.md) and [File Management Error Codes](../apis-core-file-kit/errorcode-filemanagement.md). 2149 2150| ID| Error Message| 2151| -------- | ---------------------------------------- | 2152| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types. | 2153| 13900020 | Invalid argument. | 2154| 14000011 | System inner fail. | 2155 2156**Example** 2157 2158```ts 2159import { dataSharePredicates } from '@kit.ArkData'; 2160 2161async function example() { 2162 console.info('getFirstObjectDemo'); 2163 let predicates: dataSharePredicates.DataSharePredicates = new dataSharePredicates.DataSharePredicates(); 2164 let fetchOption: photoAccessHelper.FetchOptions = { 2165 fetchColumns: [], 2166 predicates: predicates 2167 }; 2168 let fetchResult: photoAccessHelper.FetchResult<photoAccessHelper.PhotoAsset> = await phAccessHelper.getAssets(fetchOption); 2169 fetchResult.getFirstObject((err, photoAsset) => { 2170 if (photoAsset !== undefined) { 2171 console.info('photoAsset displayName: ', photoAsset.displayName); 2172 } else { 2173 console.error(`photoAsset failed with err:${err.code}, ${err.message}`); 2174 } 2175 }); 2176} 2177``` 2178 2179### getFirstObject 2180 2181getFirstObject(): Promise<T> 2182 2183Obtains the first file asset in the result set. This API uses a promise to return the result. 2184 2185**System capability**: SystemCapability.FileManagement.PhotoAccessHelper.Core 2186 2187**Return value** 2188 2189| Type | Description | 2190| --------------------------------------- | -------------------------- | 2191| Promise<T> | Promise used to return the first object in the result set.| 2192 2193**Error codes** 2194 2195For details about the error codes, see [Universal Error Codes](../errorcode-universal.md) and [File Management Error Codes](../apis-core-file-kit/errorcode-filemanagement.md). 2196 2197| ID| Error Message| 2198| -------- | ---------------------------------------- | 2199| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types. | 2200| 13900020 | Invalid argument. | 2201| 14000011 | System inner fail. | 2202 2203**Example** 2204 2205```ts 2206import { dataSharePredicates } from '@kit.ArkData'; 2207 2208async function example() { 2209 console.info('getFirstObjectDemo'); 2210 let predicates: dataSharePredicates.DataSharePredicates = new dataSharePredicates.DataSharePredicates(); 2211 let fetchOption: photoAccessHelper.FetchOptions = { 2212 fetchColumns: [], 2213 predicates: predicates 2214 }; 2215 let fetchResult: photoAccessHelper.FetchResult<photoAccessHelper.PhotoAsset> = await phAccessHelper.getAssets(fetchOption); 2216 let photoAsset: photoAccessHelper.PhotoAsset = await fetchResult.getFirstObject(); 2217 console.info('photoAsset displayName: ', photoAsset.displayName); 2218} 2219``` 2220 2221### getNextObject 2222 2223getNextObject(callback: AsyncCallback<T>): void 2224 2225Obtains the next file asset in the result set. This API uses an asynchronous callback to return the result. 2226Before using this API, you must use [isAfterLast()](#isafterlast) to check whether the current position is the end of the result set. 2227 2228**System capability**: SystemCapability.FileManagement.PhotoAccessHelper.Core 2229 2230**Parameters** 2231 2232| Name | Type | Mandatory| Description | 2233| --------- | --------------------------------------------- | ---- | ----------------------------------------- | 2234| callback | AsyncCallback<T> | Yes | Callback used to return the next file asset.| 2235 2236**Error codes** 2237 2238For details about the error codes, see [Universal Error Codes](../errorcode-universal.md) and [File Management Error Codes](../apis-core-file-kit/errorcode-filemanagement.md). 2239 2240| ID| Error Message| 2241| -------- | ---------------------------------------- | 2242| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types. | 2243| 13900020 | Invalid argument. | 2244| 14000011 | System inner fail. | 2245 2246**Example** 2247 2248```ts 2249import { dataSharePredicates } from '@kit.ArkData'; 2250 2251async function example() { 2252 console.info('getNextObjectDemo'); 2253 let predicates: dataSharePredicates.DataSharePredicates = new dataSharePredicates.DataSharePredicates(); 2254 let fetchOption: photoAccessHelper.FetchOptions = { 2255 fetchColumns: [], 2256 predicates: predicates 2257 }; 2258 let fetchResult: photoAccessHelper.FetchResult<photoAccessHelper.PhotoAsset> = await phAccessHelper.getAssets(fetchOption); 2259 await fetchResult.getFirstObject(); 2260 if (!fetchResult.isAfterLast()) { 2261 fetchResult.getNextObject((err, photoAsset) => { 2262 if (photoAsset !== undefined) { 2263 console.info('photoAsset displayName: ', photoAsset.displayName); 2264 } else { 2265 console.error(`photoAsset failed with err: ${err.code}, ${err.message}`); 2266 } 2267 }); 2268 } 2269} 2270``` 2271 2272### getNextObject 2273 2274getNextObject(): Promise<T> 2275 2276Obtains the next file asset in the result set. This API uses a promise to return the result. 2277Before using this API, you must use [isAfterLast()](#isafterlast) to check whether the current position is the end of the result set. 2278 2279**System capability**: SystemCapability.FileManagement.PhotoAccessHelper.Core 2280 2281**Return value** 2282 2283| Type | Description | 2284| --------------------------------------- | ----------------- | 2285| Promise<T> | Promise used to return the next object in the result set.| 2286 2287**Error codes** 2288 2289For details about the error codes, see [Universal Error Codes](../errorcode-universal.md) and [File Management Error Codes](../apis-core-file-kit/errorcode-filemanagement.md). 2290 2291| ID| Error Message| 2292| -------- | ---------------------------------------- | 2293| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types. | 2294| 13900020 | Invalid argument. | 2295| 14000011 | System inner fail. | 2296 2297**Example** 2298 2299```ts 2300import { dataSharePredicates } from '@kit.ArkData'; 2301 2302async function example() { 2303 console.info('getNextObjectDemo'); 2304 let predicates: dataSharePredicates.DataSharePredicates = new dataSharePredicates.DataSharePredicates(); 2305 let fetchOption: photoAccessHelper.FetchOptions = { 2306 fetchColumns: [], 2307 predicates: predicates 2308 }; 2309 let fetchResult: photoAccessHelper.FetchResult<photoAccessHelper.PhotoAsset> = await phAccessHelper.getAssets(fetchOption); 2310 await fetchResult.getFirstObject(); 2311 if (!fetchResult.isAfterLast()) { 2312 let photoAsset: photoAccessHelper.PhotoAsset = await fetchResult.getNextObject(); 2313 console.info('photoAsset displayName: ', photoAsset.displayName); 2314 } 2315} 2316``` 2317 2318### getLastObject 2319 2320getLastObject(callback: AsyncCallback<T>): void 2321 2322Obtains the last file asset in the result set. This API uses an asynchronous callback to return the result. 2323 2324**System capability**: SystemCapability.FileManagement.PhotoAccessHelper.Core 2325 2326**Parameters** 2327 2328| Name | Type | Mandatory| Description | 2329| -------- | --------------------------------------------- | ---- | --------------------------- | 2330| callback | AsyncCallback<T> | Yes | Callback used to return the last file asset obtained.| 2331 2332**Error codes** 2333 2334For details about the error codes, see [Universal Error Codes](../errorcode-universal.md) and [File Management Error Codes](../apis-core-file-kit/errorcode-filemanagement.md). 2335 2336| ID| Error Message| 2337| -------- | ---------------------------------------- | 2338| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types. | 2339| 13900020 | Invalid argument. | 2340| 14000011 | System inner fail. | 2341 2342**Example** 2343 2344```ts 2345import { dataSharePredicates } from '@kit.ArkData'; 2346 2347async function example() { 2348 console.info('getLastObjectDemo'); 2349 let predicates: dataSharePredicates.DataSharePredicates = new dataSharePredicates.DataSharePredicates(); 2350 let fetchOption: photoAccessHelper.FetchOptions = { 2351 fetchColumns: [], 2352 predicates: predicates 2353 }; 2354 let fetchResult: photoAccessHelper.FetchResult<photoAccessHelper.PhotoAsset> = await phAccessHelper.getAssets(fetchOption); 2355 fetchResult.getLastObject((err, photoAsset) => { 2356 if (photoAsset !== undefined) { 2357 console.info('photoAsset displayName: ', photoAsset.displayName); 2358 } else { 2359 console.error(`photoAsset failed with err: ${err.code}, ${err.message}`); 2360 } 2361 }); 2362} 2363``` 2364 2365### getLastObject 2366 2367getLastObject(): Promise<T> 2368 2369Obtains the last file asset in the result set. This API uses a promise to return the result. 2370 2371**System capability**: SystemCapability.FileManagement.PhotoAccessHelper.Core 2372 2373**Return value** 2374 2375| Type | Description | 2376| --------------------------------------- | ----------------- | 2377| Promise<T> | Promise used to return the last object in the result set.| 2378 2379**Error codes** 2380 2381For details about the error codes, see [Universal Error Codes](../errorcode-universal.md) and [File Management Error Codes](../apis-core-file-kit/errorcode-filemanagement.md). 2382 2383| ID| Error Message| 2384| -------- | ---------------------------------------- | 2385| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types. | 2386| 13900020 | Invalid argument. | 2387| 14000011 | System inner fail. | 2388 2389**Example** 2390 2391```ts 2392import { dataSharePredicates } from '@kit.ArkData'; 2393 2394async function example() { 2395 console.info('getLastObjectDemo'); 2396 let predicates: dataSharePredicates.DataSharePredicates = new dataSharePredicates.DataSharePredicates(); 2397 let fetchOption: photoAccessHelper.FetchOptions = { 2398 fetchColumns: [], 2399 predicates: predicates 2400 }; 2401 let fetchResult: photoAccessHelper.FetchResult<photoAccessHelper.PhotoAsset> = await phAccessHelper.getAssets(fetchOption); 2402 let photoAsset: photoAccessHelper.PhotoAsset = await fetchResult.getLastObject(); 2403 console.info('photoAsset displayName: ', photoAsset.displayName); 2404} 2405``` 2406 2407### getObjectByPosition 2408 2409getObjectByPosition(index: number, callback: AsyncCallback<T>): void 2410 2411Obtains a file asset with the specified index in the result set. This API uses an asynchronous callback to return the result. 2412 2413**System capability**: SystemCapability.FileManagement.PhotoAccessHelper.Core 2414 2415**Parameters** 2416 2417| Name | Type | Mandatory | Description | 2418| -------- | ---------------------------------------- | ---- | ------------------ | 2419| index | number | Yes | Index of the file asset to obtain. The value starts from **0**. | 2420| callback | AsyncCallback<T> | Yes | Callback used to return the file asset obtained.| 2421 2422**Error codes** 2423 2424For details about the error codes, see [Universal Error Codes](../errorcode-universal.md) and [File Management Error Codes](../apis-core-file-kit/errorcode-filemanagement.md). 2425 2426| ID| Error Message| 2427| -------- | ---------------------------------------- | 2428| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types; 3. Parameter verification failed. | 2429| 13900020 | Invalid argument. | 2430| 14000011 | System inner fail. | 2431 2432**Example** 2433 2434```ts 2435import { dataSharePredicates } from '@kit.ArkData'; 2436 2437async function example() { 2438 console.info('getObjectByPositionDemo'); 2439 let predicates: dataSharePredicates.DataSharePredicates = new dataSharePredicates.DataSharePredicates(); 2440 let fetchOption: photoAccessHelper.FetchOptions = { 2441 fetchColumns: [], 2442 predicates: predicates 2443 }; 2444 let fetchResult: photoAccessHelper.FetchResult<photoAccessHelper.PhotoAsset> = await phAccessHelper.getAssets(fetchOption); 2445 fetchResult.getObjectByPosition(0, (err, photoAsset) => { 2446 if (photoAsset !== undefined) { 2447 console.info('photoAsset displayName: ', photoAsset.displayName); 2448 } else { 2449 console.error(`photoAsset failed with err: ${err.code}, ${err.message}`); 2450 } 2451 }); 2452} 2453``` 2454 2455### getObjectByPosition 2456 2457getObjectByPosition(index: number): Promise<T> 2458 2459Obtains a file asset with the specified index in the result set. This API uses a promise to return the result. 2460 2461**System capability**: SystemCapability.FileManagement.PhotoAccessHelper.Core 2462 2463**Parameters** 2464 2465| Name | Type | Mandatory | Description | 2466| ----- | ------ | ---- | -------------- | 2467| index | number | Yes | Index of the file asset to obtain. The value starts from **0**.| 2468 2469**Return value** 2470 2471| Type | Description | 2472| --------------------------------------- | ----------------- | 2473| Promise<T> | Promise used to return the file asset obtained.| 2474 2475**Error codes** 2476 2477For details about the error codes, see [Universal Error Codes](../errorcode-universal.md) and [File Management Error Codes](../apis-core-file-kit/errorcode-filemanagement.md). 2478 2479| ID| Error Message| 2480| -------- | ---------------------------------------- | 2481| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types; 3. Parameter verification failed. | 2482| 13900020 | Invalid argument. | 2483| 14000011 | System inner fail. | 2484 2485**Example** 2486 2487```ts 2488import { dataSharePredicates } from '@kit.ArkData'; 2489 2490async function example() { 2491 console.info('getObjectByPositionDemo'); 2492 let predicates: dataSharePredicates.DataSharePredicates = new dataSharePredicates.DataSharePredicates(); 2493 let fetchOption: photoAccessHelper.FetchOptions = { 2494 fetchColumns: [], 2495 predicates: predicates 2496 }; 2497 let fetchResult: photoAccessHelper.FetchResult<photoAccessHelper.PhotoAsset> = await phAccessHelper.getAssets(fetchOption); 2498 let photoAsset: photoAccessHelper.PhotoAsset = await fetchResult.getObjectByPosition(0); 2499 console.info('photoAsset displayName: ', photoAsset.displayName); 2500} 2501``` 2502 2503### getAllObjects 2504 2505getAllObjects(callback: AsyncCallback<Array<T>>): void 2506 2507Obtains all the file assets in the result set. This API uses an asynchronous callback to return the result. 2508 2509**System capability**: SystemCapability.FileManagement.PhotoAccessHelper.Core 2510 2511**Parameters** 2512 2513| Name | Type | Mandatory| Description | 2514| -------- | --------------------------------------------- | ---- | ------------------------------------------- | 2515| callback | AsyncCallback<Array<T>> | Yes | Callback used to return an array of all file assets in the result set.| 2516 2517**Error codes** 2518 2519For details about the error codes, see [Universal Error Codes](../errorcode-universal.md) and [File Management Error Codes](../apis-core-file-kit/errorcode-filemanagement.md). 2520 2521| ID| Error Message| 2522| -------- | ---------------------------------------- | 2523| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types. | 2524| 13900020 | Invalid argument. | 2525| 14000011 | System inner fail. | 2526 2527**Example** 2528 2529```ts 2530import { dataSharePredicates } from '@kit.ArkData'; 2531 2532async function example() { 2533 console.info('getAllObjectDemo'); 2534 let predicates: dataSharePredicates.DataSharePredicates = new dataSharePredicates.DataSharePredicates(); 2535 let fetchOption: photoAccessHelper.FetchOptions = { 2536 fetchColumns: [], 2537 predicates: predicates 2538 }; 2539 let fetchResult: photoAccessHelper.FetchResult<photoAccessHelper.PhotoAsset> = await phAccessHelper.getAssets(fetchOption); 2540 fetchResult.getAllObjects((err, photoAssetList) => { 2541 if (photoAssetList !== undefined) { 2542 console.info('photoAssetList length: ', photoAssetList.length); 2543 } else { 2544 console.error(`photoAssetList failed with err:${err.code}, ${err.message}`); 2545 } 2546 }); 2547} 2548``` 2549 2550### getAllObjects 2551 2552getAllObjects(): Promise<Array<T>> 2553 2554Obtains all the file assets in the result set. This API uses a promise to return the result. 2555 2556**System capability**: SystemCapability.FileManagement.PhotoAccessHelper.Core 2557 2558**Return value** 2559 2560| Type | Description | 2561| --------------------------------------- | -------------------------- | 2562| Promise<Array<T>> | Promise used to return an array of all file assets in the result set.| 2563 2564**Error codes** 2565 2566For details about the error codes, see [Universal Error Codes](../errorcode-universal.md) and [File Management Error Codes](../apis-core-file-kit/errorcode-filemanagement.md). 2567 2568| ID| Error Message| 2569| -------- | ---------------------------------------- | 2570| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types. | 2571| 13900020 | Invalid argument. | 2572| 14000011 | System inner fail. | 2573 2574**Example** 2575 2576```ts 2577import { dataSharePredicates } from '@kit.ArkData'; 2578 2579async function example() { 2580 console.info('getAllObjectDemo'); 2581 let predicates: dataSharePredicates.DataSharePredicates = new dataSharePredicates.DataSharePredicates(); 2582 let fetchOption: photoAccessHelper.FetchOptions = { 2583 fetchColumns: [], 2584 predicates: predicates 2585 }; 2586 let fetchResult: photoAccessHelper.FetchResult<photoAccessHelper.PhotoAsset> = await phAccessHelper.getAssets(fetchOption); 2587 let photoAssetList: Array<photoAccessHelper.PhotoAsset> = await fetchResult.getAllObjects(); 2588 console.info('photoAssetList length: ', photoAssetList.length); 2589} 2590``` 2591 2592## Album 2593 2594Provides APIs to manage albums. 2595 2596### Properties 2597 2598**System capability**: SystemCapability.FileManagement.PhotoAccessHelper.Core 2599 2600| Name | Type | Readable | Writable | Description | 2601| ------------ | ------ | ---- | ---- | ------- | 2602| albumType | [AlbumType](#albumtype) | Yes | No | Type of the album. | 2603| albumSubtype | [AlbumSubtype](#albumsubtype) | Yes | No | Subtype of the album. | 2604| albumName | string | Yes | Yes for a user album; no for a system album. | Name of the album. | 2605| albumUri | string | Yes | No | URI of the album. | 2606| count | number | Yes | No | Number of files in the album.| 2607| coverUri | string | Yes | No | URI of the cover file of the album.| 2608| imageCount<sup>11+</sup> | number | Yes | No | Number of images in the album.| 2609| videoCount<sup>11+</sup> | number | Yes | No | Number of videos in the album.| 2610 2611### getAssets 2612 2613getAssets(options: FetchOptions, callback: AsyncCallback<FetchResult<PhotoAsset>>): void 2614 2615Obtains image and video assets. This API uses an asynchronous callback to return the result. 2616 2617**Required permissions**: ohos.permission.READ_IMAGEVIDEO 2618 2619**System capability**: SystemCapability.FileManagement.PhotoAccessHelper.Core 2620 2621**Parameters** 2622 2623| Name | Type | Mandatory| Description | 2624| -------- | ------------------------- | ---- | ---------- | 2625| options | [FetchOptions](#fetchoptions) | Yes | Options for fetching the assets.| 2626| callback | AsyncCallback<[FetchResult](#fetchresult)<[PhotoAsset](#photoasset)>> | Yes | Callback used to return the image and video assets obtained.| 2627 2628**Error codes** 2629 2630For details about the error codes, see [Universal Error Codes](../errorcode-universal.md) and [File Management Error Codes](../apis-core-file-kit/errorcode-filemanagement.md). 2631 2632| ID| Error Message| 2633| -------- | ---------------------------------------- | 2634| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types; 3. Parameter verification failed. | 2635| 13900012 | Permission denied. | 2636| 13900020 | Invalid argument. | 2637| 14000011 | System inner fail. | 2638 2639**Example** 2640 2641```ts 2642import { dataSharePredicates } from '@kit.ArkData'; 2643 2644async function example() { 2645 console.info('albumGetAssetsDemoCallback'); 2646 let predicates: dataSharePredicates.DataSharePredicates = new dataSharePredicates.DataSharePredicates(); 2647 let albumFetchOptions: photoAccessHelper.FetchOptions = { 2648 fetchColumns: [], 2649 predicates: predicates 2650 }; 2651 let fetchOption: photoAccessHelper.FetchOptions = { 2652 fetchColumns: [], 2653 predicates: predicates 2654 }; 2655 let albumList: photoAccessHelper.FetchResult<photoAccessHelper.Album> = await phAccessHelper.getAlbums(photoAccessHelper.AlbumType.USER, photoAccessHelper.AlbumSubtype.USER_GENERIC, albumFetchOptions); 2656 let album: photoAccessHelper.Album = await albumList.getFirstObject(); 2657 album.getAssets(fetchOption, (err, albumFetchResult) => { 2658 if (albumFetchResult !== undefined) { 2659 console.info('album getAssets successfully, getCount: ' + albumFetchResult.getCount()); 2660 } else { 2661 console.error(`album getAssets failed with error: ${err.code}, ${err.message}`); 2662 } 2663 }); 2664} 2665``` 2666 2667### getAssets 2668 2669getAssets(options: FetchOptions): Promise<FetchResult<PhotoAsset>> 2670 2671Obtains image and video assets. This API uses a promise to return the result. 2672 2673**Required permissions**: ohos.permission.READ_IMAGEVIDEO 2674 2675**System capability**: SystemCapability.FileManagement.PhotoAccessHelper.Core 2676 2677**Parameters** 2678 2679| Name | Type | Mandatory| Description | 2680| -------- | ------------------------- | ---- | ---------- | 2681| options | [FetchOptions](#fetchoptions) | Yes | Options for fetching the assets.| 2682 2683**Return value** 2684 2685| Type | Description | 2686| --------------------------------------- | ----------------- | 2687| Promise<[FetchResult](#fetchresult)<[PhotoAsset](#photoasset)>> | Promise used to return the image and video assets obtained.| 2688 2689**Error codes** 2690 2691For details about the error codes, see [Universal Error Codes](../errorcode-universal.md) and [File Management Error Codes](../apis-core-file-kit/errorcode-filemanagement.md). 2692 2693| ID| Error Message| 2694| -------- | ---------------------------------------- | 2695| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types; 3. Parameter verification failed. | 2696| 13900012 | Permission denied. | 2697| 13900020 | Invalid argument. | 2698| 14000011 | System inner fail. | 2699 2700**Example** 2701 2702```ts 2703import { dataSharePredicates } from '@kit.ArkData'; 2704import { BusinessError } from '@kit.BasicServicesKit'; 2705 2706async function example() { 2707 console.info('albumGetAssetsDemoPromise'); 2708 let predicates: dataSharePredicates.DataSharePredicates = new dataSharePredicates.DataSharePredicates(); 2709 let albumFetchOptions: photoAccessHelper.FetchOptions = { 2710 fetchColumns: [], 2711 predicates: predicates 2712 }; 2713 let fetchOption: photoAccessHelper.FetchOptions = { 2714 fetchColumns: [], 2715 predicates: predicates 2716 }; 2717 let albumList: photoAccessHelper.FetchResult<photoAccessHelper.Album> = await phAccessHelper.getAlbums(photoAccessHelper.AlbumType.USER, photoAccessHelper.AlbumSubtype.USER_GENERIC, albumFetchOptions); 2718 let album: photoAccessHelper.Album = await albumList.getFirstObject(); 2719 album.getAssets(fetchOption).then((albumFetchResult) => { 2720 console.info('album getAssets successfully, getCount: ' + albumFetchResult.getCount()); 2721 }).catch((err: BusinessError) => { 2722 console.error(`album getAssets failed with error: ${err.code}, ${err.message}`); 2723 }); 2724} 2725``` 2726 2727### commitModify 2728 2729commitModify(callback: AsyncCallback<void>): void 2730 2731Commits the modification on the album attributes to the database. This API uses an asynchronous callback to return the result. 2732 2733**Required permissions**: ohos.permission.WRITE_IMAGEVIDEO 2734 2735**System capability**: SystemCapability.FileManagement.PhotoAccessHelper.Core 2736 2737**Parameters** 2738 2739| Name | Type | Mandatory| Description | 2740| -------- | ------------------------- | ---- | ---------- | 2741| callback | AsyncCallback<void> | Yes | Callback that returns no value.| 2742 2743**Error codes** 2744 2745For details about the error codes, see [Universal Error Codes](../errorcode-universal.md) and [File Management Error Codes](../apis-core-file-kit/errorcode-filemanagement.md). 2746 2747| ID| Error Message| 2748| -------- | ---------------------------------------- | 2749| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types. | 2750| 13900012 | Permission denied. | 2751| 13900020 | Invalid argument. | 2752| 14000011 | System inner fail. | 2753 2754**Example** 2755 2756```ts 2757import { dataSharePredicates } from '@kit.ArkData'; 2758 2759async function example() { 2760 console.info('albumCommitModifyDemo'); 2761 let predicates: dataSharePredicates.DataSharePredicates = new dataSharePredicates.DataSharePredicates(); 2762 let albumFetchOptions: photoAccessHelper.FetchOptions = { 2763 fetchColumns: [], 2764 predicates: predicates 2765 }; 2766 let albumList: photoAccessHelper.FetchResult<photoAccessHelper.Album> = await phAccessHelper.getAlbums(photoAccessHelper.AlbumType.USER, photoAccessHelper.AlbumSubtype.USER_GENERIC, albumFetchOptions); 2767 let album: photoAccessHelper.Album = await albumList.getFirstObject(); 2768 album.albumName = 'hello'; 2769 album.commitModify((err) => { 2770 if (err !== undefined) { 2771 console.error(`commitModify failed with error: ${err.code}, ${err.message}`); 2772 } else { 2773 console.info('commitModify successfully'); 2774 } 2775 }); 2776} 2777``` 2778 2779### commitModify 2780 2781commitModify(): Promise<void> 2782 2783Commits the modification on the album attributes to the database. This API uses a promise to return the result. 2784 2785**Required permissions**: ohos.permission.WRITE_IMAGEVIDEO 2786 2787**System capability**: SystemCapability.FileManagement.PhotoAccessHelper.Core 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| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types. | 2802| 13900012 | Permission denied. | 2803| 13900020 | Invalid argument. | 2804| 14000011 | System inner fail. | 2805 2806**Example** 2807 2808```ts 2809import { dataSharePredicates } from '@kit.ArkData'; 2810import { BusinessError } from '@kit.BasicServicesKit'; 2811 2812async function example() { 2813 console.info('albumCommitModifyDemo'); 2814 let predicates: dataSharePredicates.DataSharePredicates = new dataSharePredicates.DataSharePredicates(); 2815 let albumFetchOptions: photoAccessHelper.FetchOptions = { 2816 fetchColumns: [], 2817 predicates: predicates 2818 }; 2819 let albumList: photoAccessHelper.FetchResult<photoAccessHelper.Album> = await phAccessHelper.getAlbums(photoAccessHelper.AlbumType.USER, photoAccessHelper.AlbumSubtype.USER_GENERIC, albumFetchOptions); 2820 let album: photoAccessHelper.Album = await albumList.getFirstObject(); 2821 album.albumName = 'hello'; 2822 album.commitModify().then(() => { 2823 console.info('commitModify successfully'); 2824 }).catch((err: BusinessError) => { 2825 console.error(`commitModify failed with error: ${err.code}, ${err.message}`); 2826 }); 2827} 2828``` 2829 2830### addAssets<sup>(deprecated)</sup> 2831 2832addAssets(assets: Array<PhotoAsset>, callback: AsyncCallback<void>): void 2833 2834Adds image and video assets to an album. Before the operation, ensure that the image and video assets to add and the album exist. This API uses an asynchronous callback to return the result. 2835 2836> **NOTE** 2837> 2838> This API is supported since API version 10 and deprecated since API version 11. Use [MediaAlbumChangeRequest.addAssets](#addassets11) instead. 2839 2840**Required permissions**: ohos.permission.WRITE_IMAGEVIDEO 2841 2842**System capability**: SystemCapability.FileManagement.PhotoAccessHelper.Core 2843 2844**Parameters** 2845 2846| Name | Type | Mandatory| Description | 2847| -------- | ------------------------- | ---- | ---------- | 2848| assets | Array<[PhotoAsset](#photoasset)> | Yes | Array of the image and video assets to add.| 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| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types; 3. Parameter verification failed. | 2858| 13900012 | Permission denied. | 2859| 13900020 | Invalid argument. | 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('addAssetsDemoCallback'); 2870 let predicates: dataSharePredicates.DataSharePredicates = new dataSharePredicates.DataSharePredicates(); 2871 let fetchOption: photoAccessHelper.FetchOptions = { 2872 fetchColumns: [], 2873 predicates: predicates 2874 }; 2875 let albumFetchResult: photoAccessHelper.FetchResult<photoAccessHelper.Album> = await phAccessHelper.getAlbums(photoAccessHelper.AlbumType.USER, photoAccessHelper.AlbumSubtype.USER_GENERIC); 2876 let album: photoAccessHelper.Album = await albumFetchResult.getFirstObject(); 2877 let fetchResult: photoAccessHelper.FetchResult<photoAccessHelper.PhotoAsset> = await phAccessHelper.getAssets(fetchOption); 2878 let asset: photoAccessHelper.PhotoAsset = await fetchResult.getFirstObject(); 2879 album.addAssets([asset], (err) => { 2880 if (err === undefined) { 2881 console.info('album addAssets successfully'); 2882 } else { 2883 console.error(`album addAssets failed with error: ${err.code}, ${err.message}`); 2884 } 2885 }); 2886 } catch (err) { 2887 console.error(`addAssetsDemoCallback failed with error: ${err.code}, ${err.message}`); 2888 } 2889} 2890``` 2891 2892### addAssets<sup>(deprecated)</sup> 2893 2894addAssets(assets: Array<PhotoAsset>): Promise<void> 2895 2896Adds image and video assets to an album. Before the operation, ensure that the image and video assets to add and the album exist. This API uses a promise to return the result. 2897 2898> **NOTE** 2899> 2900> This API is supported since API version 10 and deprecated since API version 11. Use [MediaAlbumChangeRequest.addAssets](#addassets11) instead. 2901 2902**Required permissions**: ohos.permission.WRITE_IMAGEVIDEO 2903 2904**System capability**: SystemCapability.FileManagement.PhotoAccessHelper.Core 2905 2906**Parameters** 2907 2908| Name | Type | Mandatory| Description | 2909| -------- | ------------------------- | ---- | ---------- | 2910| assets | Array<[PhotoAsset](#photoasset)> | Yes | Array of the image and video assets to add.| 2911 2912**Return value** 2913 2914| Type | Description | 2915| --------------------------------------- | ----------------- | 2916|Promise<void> | Promise that returns no value.| 2917 2918**Error codes** 2919 2920For details about the error codes, see [Universal Error Codes](../errorcode-universal.md) and [File Management Error Codes](../apis-core-file-kit/errorcode-filemanagement.md). 2921 2922| ID| Error Message| 2923| -------- | ---------------------------------------- | 2924| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types; 3. Parameter verification failed. | 2925| 13900012 | Permission denied. | 2926| 13900020 | Invalid argument. | 2927| 14000011 | System inner fail. | 2928 2929**Example** 2930 2931```ts 2932import { dataSharePredicates } from '@kit.ArkData'; 2933import { BusinessError } from '@kit.BasicServicesKit'; 2934 2935async function example() { 2936 try { 2937 console.info('addAssetsDemoPromise'); 2938 let predicates: dataSharePredicates.DataSharePredicates = new dataSharePredicates.DataSharePredicates(); 2939 let fetchOption: photoAccessHelper.FetchOptions = { 2940 fetchColumns: [], 2941 predicates: predicates 2942 }; 2943 let albumFetchResult: photoAccessHelper.FetchResult<photoAccessHelper.Album> = await phAccessHelper.getAlbums(photoAccessHelper.AlbumType.USER, photoAccessHelper.AlbumSubtype.USER_GENERIC); 2944 let album: photoAccessHelper.Album = await albumFetchResult.getFirstObject(); 2945 let fetchResult: photoAccessHelper.FetchResult<photoAccessHelper.PhotoAsset> = await phAccessHelper.getAssets(fetchOption); 2946 let asset: photoAccessHelper.PhotoAsset = await fetchResult.getFirstObject(); 2947 album.addAssets([asset]).then(() => { 2948 console.info('album addAssets successfully'); 2949 }).catch((err: BusinessError) => { 2950 console.error(`album addAssets failed with error: ${err.code}, ${err.message}`); 2951 }); 2952 } catch (err) { 2953 console.error(`addAssetsDemoPromise failed with error: ${err.code}, ${err.message}`); 2954 } 2955} 2956``` 2957 2958### removeAssets<sup>(deprecated)</sup> 2959 2960removeAssets(assets: Array<PhotoAsset>, callback: AsyncCallback<void>): void 2961 2962Removes image and video assets from an album. The album and file resources must exist. This API uses an asynchronous callback to return the result. 2963 2964> **NOTE** 2965> 2966> This API is supported since API version 10 and deprecated since API version 11. Use [MediaAlbumChangeRequest.removeAssets](#removeassets11) instead. 2967 2968**Required permissions**: ohos.permission.WRITE_IMAGEVIDEO 2969 2970**System capability**: SystemCapability.FileManagement.PhotoAccessHelper.Core 2971 2972**Parameters** 2973 2974| Name | Type | Mandatory| Description | 2975| -------- | ------------------------- | ---- | ---------- | 2976| assets | Array<[PhotoAsset](#photoasset)> | Yes | Array of the image and video assets to remove.| 2977| callback | AsyncCallback<void> | Yes | Callback that returns no value.| 2978 2979**Error codes** 2980 2981For details about the error codes, see [Universal Error Codes](../errorcode-universal.md) and [File Management Error Codes](../apis-core-file-kit/errorcode-filemanagement.md). 2982 2983| ID| Error Message| 2984| -------- | ---------------------------------------- | 2985| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types; 3. Parameter verification failed. | 2986| 13900012 | Permission denied. | 2987| 13900020 | Invalid argument. | 2988| 14000011 | System inner fail. | 2989 2990**Example** 2991 2992```ts 2993import { dataSharePredicates } from '@kit.ArkData'; 2994 2995async function example() { 2996 try { 2997 console.info('removeAssetsDemoCallback'); 2998 let predicates: dataSharePredicates.DataSharePredicates = new dataSharePredicates.DataSharePredicates(); 2999 let fetchOption: photoAccessHelper.FetchOptions = { 3000 fetchColumns: [], 3001 predicates: predicates 3002 }; 3003 let albumFetchResult: photoAccessHelper.FetchResult<photoAccessHelper.Album> = await phAccessHelper.getAlbums(photoAccessHelper.AlbumType.USER, photoAccessHelper.AlbumSubtype.USER_GENERIC); 3004 let album: photoAccessHelper.Album = await albumFetchResult.getFirstObject(); 3005 let fetchResult: photoAccessHelper.FetchResult<photoAccessHelper.PhotoAsset> = await album.getAssets(fetchOption); 3006 let asset: photoAccessHelper.PhotoAsset = await fetchResult.getFirstObject(); 3007 album.removeAssets([asset], (err) => { 3008 if (err === undefined) { 3009 console.info('album removeAssets successfully'); 3010 } else { 3011 console.error(`album removeAssets failed with error: ${err.code}, ${err.message}`); 3012 } 3013 }); 3014 } catch (err) { 3015 console.error(`removeAssetsDemoCallback failed with error: ${err.code}, ${err.message}`); 3016 } 3017} 3018``` 3019 3020### removeAssets<sup>(deprecated)</sup> 3021 3022removeAssets(assets: Array<PhotoAsset>): Promise<void> 3023 3024Removes image and video assets from an album. The album and file resources must exist. This API uses a promise to return the result. 3025 3026> **NOTE** 3027> 3028> This API is supported since API version 10 and deprecated since API version 11. Use [MediaAlbumChangeRequest.removeAssets](#removeassets11) instead. 3029 3030**Required permissions**: ohos.permission.WRITE_IMAGEVIDEO 3031 3032**System capability**: SystemCapability.FileManagement.PhotoAccessHelper.Core 3033 3034**Parameters** 3035 3036| Name | Type | Mandatory| Description | 3037| -------- | ------------------------- | ---- | ---------- | 3038| assets | Array<[PhotoAsset](#photoasset)> | Yes | Array of the image and video assets to remove.| 3039 3040**Return value** 3041 3042| Type | Description | 3043| --------------------------------------- | ----------------- | 3044|Promise<void> | Promise that returns no value.| 3045 3046**Error codes** 3047 3048For details about the error codes, see [Universal Error Codes](../errorcode-universal.md) and [File Management Error Codes](../apis-core-file-kit/errorcode-filemanagement.md). 3049 3050| ID| Error Message| 3051| -------- | ---------------------------------------- | 3052| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types; 3. Parameter verification failed. | 3053| 13900012 | Permission denied. | 3054| 13900020 | Invalid argument. | 3055| 14000011 | System inner fail. | 3056 3057**Example** 3058 3059```ts 3060import { dataSharePredicates } from '@kit.ArkData'; 3061import { BusinessError } from '@kit.BasicServicesKit'; 3062 3063async function example() { 3064 try { 3065 console.info('removeAssetsDemoPromise'); 3066 let predicates: dataSharePredicates.DataSharePredicates = new dataSharePredicates.DataSharePredicates(); 3067 let fetchOption: photoAccessHelper.FetchOptions = { 3068 fetchColumns: [], 3069 predicates: predicates 3070 }; 3071 let albumFetchResult: photoAccessHelper.FetchResult<photoAccessHelper.Album> = await phAccessHelper.getAlbums(photoAccessHelper.AlbumType.USER, photoAccessHelper.AlbumSubtype.USER_GENERIC); 3072 let album: photoAccessHelper.Album = await albumFetchResult.getFirstObject(); 3073 let fetchResult: photoAccessHelper.FetchResult<photoAccessHelper.PhotoAsset> = await album.getAssets(fetchOption); 3074 let asset: photoAccessHelper.PhotoAsset = await fetchResult.getFirstObject(); 3075 album.removeAssets([asset]).then(() => { 3076 console.info('album removeAssets successfully'); 3077 }).catch((err: BusinessError) => { 3078 console.error(`album removeAssets failed with error: ${err.code}, ${err.message}`); 3079 }); 3080 } catch (err) { 3081 console.error(`removeAssetsDemoPromise failed with error: ${err.code}, ${err.message}`); 3082 } 3083} 3084``` 3085 3086## MediaAssetChangeRequest<sup>11+</sup> 3087 3088Represents a media asset change request. 3089 3090**System capability**: SystemCapability.FileManagement.PhotoAccessHelper.Core 3091 3092### constructor<sup>11+</sup> 3093 3094constructor(asset: PhotoAsset) 3095 3096Constructor. 3097 3098**Atomic service API**: This API can be used in atomic services since API version 12. 3099 3100**System capability**: SystemCapability.FileManagement.PhotoAccessHelper.Core 3101 3102**Parameters** 3103 3104| Name | Type | Mandatory| Description | 3105| -------- | ------------------------- | ---- | ---------- | 3106| asset | [PhotoAsset](#photoasset) | Yes | Assets to change.| 3107 3108**Error codes** 3109 3110For details about the error codes, see [Universal Error Codes](../errorcode-universal.md) and [File Management Error Codes](../apis-core-file-kit/errorcode-filemanagement.md). 3111 3112| ID| Error Message| 3113| -------- | ---------------------------------------- | 3114| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types; 3. Parameter verification failed. | 3115| 14000011 | System inner fail. | 3116 3117**Example** 3118 3119```ts 3120import { dataSharePredicates } from '@kit.ArkData'; 3121 3122async function example() { 3123 console.info('MediaAssetChangeRequest constructorDemo'); 3124 let predicates: dataSharePredicates.DataSharePredicates = new dataSharePredicates.DataSharePredicates(); 3125 let fetchOptions: photoAccessHelper.FetchOptions = { 3126 fetchColumns: [], 3127 predicates: predicates 3128 }; 3129 let fetchResult: photoAccessHelper.FetchResult<photoAccessHelper.PhotoAsset> = await phAccessHelper.getAssets(fetchOptions); 3130 let photoAsset: photoAccessHelper.PhotoAsset = await fetchResult.getFirstObject(); 3131 let assetChangeRequest: photoAccessHelper.MediaAssetChangeRequest = new photoAccessHelper.MediaAssetChangeRequest(photoAsset); 3132} 3133``` 3134 3135### createImageAssetRequest<sup>11+</sup> 3136 3137static createImageAssetRequest(context: Context, fileUri: string): MediaAssetChangeRequest 3138 3139Creates an image asset change request. 3140 3141Use **fileUri** to specify the data source of the asset to be created. For details, see [FileUri](../apis-core-file-kit/js-apis-file-fileuri.md). 3142 3143**Atomic service API**: This API can be used in atomic services since API version 12. 3144 3145**System capability**: SystemCapability.FileManagement.PhotoAccessHelper.Core 3146 3147**Parameters** 3148 3149| Name | Type | Mandatory| Description | 3150| ------- | ------- | ---- | -------------------------- | 3151| context | [Context](../apis-ability-kit/js-apis-inner-application-context.md) | Yes | Context of the ability instance.| 3152| fileUri | string | Yes | Data source of the image asset, which is specified by a URI in the application sandbox directory.| 3153 3154**Return value** 3155 3156| Type | Description | 3157| --------------------------------------- | ----------------- | 3158| [MediaAssetChangeRequest](#mediaassetchangerequest11) | **MediaAssetChangeRequest** created.| 3159 3160**Error codes** 3161 3162For details about the error codes, see [Universal Error Codes](../errorcode-universal.md) and [File Management Error Codes](../apis-core-file-kit/errorcode-filemanagement.md). 3163 3164| ID| Error Message| 3165| -------- | ---------------------------------------- | 3166| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types; 3. Parameter verification failed. | 3167| 13900002 | No such file. | 3168| 14000011 | System inner fail. | 3169 3170**Example** 3171 3172```ts 3173async function example() { 3174 console.info('createImageAssetRequestDemo'); 3175 try { 3176 // Ensure that the asset specified by fileUri exists. 3177 let fileUri = 'file://com.example.temptest/data/storage/el2/base/haps/entry/files/test.jpg'; 3178 let assetChangeRequest: photoAccessHelper.MediaAssetChangeRequest = photoAccessHelper.MediaAssetChangeRequest.createImageAssetRequest(context, fileUri); 3179 await phAccessHelper.applyChanges(assetChangeRequest); 3180 console.info('apply createImageAssetRequest successfully'); 3181 } catch (err) { 3182 console.error(`createImageAssetRequestDemo failed with error: ${err.code}, ${err.message}`); 3183 } 3184} 3185``` 3186 3187### createVideoAssetRequest<sup>11+</sup> 3188 3189static createVideoAssetRequest(context: Context, fileUri: string): MediaAssetChangeRequest 3190 3191Creates a video asset change request. 3192 3193Use **fileUri** to specify the data source of the asset to be created. For details, see [FileUri](../apis-core-file-kit/js-apis-file-fileuri.md). 3194 3195**System capability**: SystemCapability.FileManagement.PhotoAccessHelper.Core 3196 3197**Parameters** 3198 3199| Name | Type | Mandatory| Description | 3200| ------- | ------- | ---- | -------------------------- | 3201| context | [Context](../apis-ability-kit/js-apis-inner-application-context.md) | Yes | Context of the ability instance.| 3202| fileUri | string | Yes | Data source of the video asset, which is specified by a URI in the application sandbox directory.| 3203 3204**Return value** 3205 3206| Type | Description | 3207| --------------------------------------- | ----------------- | 3208| [MediaAssetChangeRequest](#mediaassetchangerequest11) | **MediaAssetChangeRequest** created.| 3209 3210**Error codes** 3211 3212For details about the error codes, see [Universal Error Codes](../errorcode-universal.md) and [File Management Error Codes](../apis-core-file-kit/errorcode-filemanagement.md). 3213 3214| ID| Error Message| 3215| -------- | ---------------------------------------- | 3216| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types; 3. Parameter verification failed. | 3217| 13900002 | No such file. | 3218| 14000011 | System inner fail. | 3219 3220**Example** 3221 3222```ts 3223async function example() { 3224 console.info('createVideoAssetRequestDemo'); 3225 try { 3226 // Ensure that the asset specified by fileUri exists. 3227 let fileUri = 'file://com.example.temptest/data/storage/el2/base/haps/entry/files/test.mp4'; 3228 let assetChangeRequest: photoAccessHelper.MediaAssetChangeRequest = photoAccessHelper.MediaAssetChangeRequest.createVideoAssetRequest(context, fileUri); 3229 await phAccessHelper.applyChanges(assetChangeRequest); 3230 console.info('apply createVideoAssetRequest successfully'); 3231 } catch (err) { 3232 console.error(`createVideoAssetRequestDemo failed with error: ${err.code}, ${err.message}`); 3233 } 3234} 3235``` 3236 3237### createAssetRequest<sup>11+</sup> 3238 3239static createAssetRequest(context: Context, photoType: PhotoType, extension: string, options?: CreateOptions): MediaAssetChangeRequest 3240 3241Create an asset change request based on the file type and filename extension. 3242 3243**Atomic service API**: This API can be used in atomic services since API version 11. 3244 3245**System capability**: SystemCapability.FileManagement.PhotoAccessHelper.Core 3246 3247**Parameters** 3248 3249| Name | Type | Mandatory| Description | 3250| ------- | ------- | ---- | -------------------------- | 3251| context | [Context](../apis-ability-kit/js-apis-inner-application-context.md) | Yes | Context of the ability instance.| 3252| photoType | [PhotoType](#phototype) | Yes | Type of the file to create, which can be **IMAGE** or **VIDEO**. | 3253| extension | string | Yes | File name extension, for example, **'jpg'**. | 3254| options | [CreateOptions](#createoptions) | No | Options for creating the image or video asset, for example, **{title: 'testPhoto'}**. | 3255 3256**Return value** 3257 3258| Type | Description | 3259| --------------------------------------- | ----------------- | 3260| [MediaAssetChangeRequest](#mediaassetchangerequest11) | **MediaAssetChangeRequest** created.| 3261 3262**Error codes** 3263 3264For details about the error codes, see [Universal Error Codes](../errorcode-universal.md) and [File Management Error Codes](../apis-core-file-kit/errorcode-filemanagement.md). 3265 3266| ID| Error Message| 3267| -------- | ---------------------------------------- | 3268| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types; 3. Parameter verification failed. | 3269| 14000011 | System inner fail. | 3270 3271**Example** 3272 3273```ts 3274async function example() { 3275 console.info('createAssetRequestDemo'); 3276 try { 3277 let photoType: photoAccessHelper.PhotoType = photoAccessHelper.PhotoType.IMAGE; 3278 let extension: string = 'jpg'; 3279 let options: photoAccessHelper.CreateOptions = { 3280 title: 'testPhoto' 3281 } 3282 let assetChangeRequest: photoAccessHelper.MediaAssetChangeRequest = photoAccessHelper.MediaAssetChangeRequest.createAssetRequest(context, photoType, extension, options); 3283 // Ensure that the asset specified by fileUri exists. 3284 let fileUri = 'file://com.example.temptest/data/storage/el2/base/haps/entry/files/test.jpg'; 3285 assetChangeRequest.addResource(photoAccessHelper.ResourceType.IMAGE_RESOURCE, fileUri); 3286 await phAccessHelper.applyChanges(assetChangeRequest); 3287 console.info('apply createAssetRequest successfully'); 3288 } catch (err) { 3289 console.error(`createAssetRequestDemo failed with error: ${err.code}, ${err.message}`); 3290 } 3291} 3292``` 3293 3294### deleteAssets<sup>11+</sup> 3295 3296static deleteAssets(context: Context, assets: Array<PhotoAsset>): Promise<void> 3297 3298Deletes media assets. This API uses a promise to return the result. The deleted assets are moved to the trash. 3299 3300**Required permissions**: ohos.permission.WRITE_IMAGEVIDEO 3301 3302**System capability**: SystemCapability.FileManagement.PhotoAccessHelper.Core 3303 3304**Parameters** 3305 3306| Name | Type | Mandatory| Description | 3307| ------- | ------- | ---- | -------------------------- | 3308| context | [Context](../apis-ability-kit/js-apis-inner-application-context.md) | Yes | Context of the ability instance.| 3309| assets | Array<[PhotoAsset](#photoasset)> | Yes | Media assets to delete.| 3310 3311**Return value** 3312 3313| Type | Description | 3314| --------------------------------------- | ----------------- | 3315| Promise<void>| Promise that returns no value.| 3316 3317**Error codes** 3318 3319For details about the error codes, see [Universal Error Codes](../errorcode-universal.md) and [File Management Error Codes](../apis-core-file-kit/errorcode-filemanagement.md). 3320 3321| ID| Error Message| 3322| -------- | ---------------------------------------- | 3323| 201 | Permission denied. | 3324| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types; 3. Parameter verification failed. | 3325| 14000011 | System inner fail. | 3326 3327**Example** 3328 3329```ts 3330import { dataSharePredicates } from '@kit.ArkData'; 3331 3332async function example() { 3333 console.info('deleteAssetsDemo'); 3334 let predicates: dataSharePredicates.DataSharePredicates = new dataSharePredicates.DataSharePredicates(); 3335 let fetchOptions: photoAccessHelper.FetchOptions = { 3336 fetchColumns: [], 3337 predicates: predicates 3338 }; 3339 try { 3340 let fetchResult: photoAccessHelper.FetchResult<photoAccessHelper.PhotoAsset> = await phAccessHelper.getAssets(fetchOptions); 3341 let photoAssetList: Array<photoAccessHelper.PhotoAsset> = await fetchResult.getAllObjects(); 3342 await photoAccessHelper.MediaAssetChangeRequest.deleteAssets(context, photoAssetList); 3343 console.info('deleteAssets successfully'); 3344 } catch (err) { 3345 console.error(`deleteAssetsDemo failed with error: ${err.code}, ${err.message}`); 3346 } 3347} 3348``` 3349 3350### deleteAssets<sup>11+</sup> 3351 3352static deleteAssets(context: Context, uriList: Array<string>): Promise<void> 3353 3354Deletes media assets. This API uses a promise to return the result. The deleted assets are moved to the trash. 3355 3356**Required permissions**: ohos.permission.WRITE_IMAGEVIDEO 3357 3358**System capability**: SystemCapability.FileManagement.PhotoAccessHelper.Core 3359 3360**Parameters** 3361 3362| Name | Type | Mandatory| Description | 3363| ------- | ------- | ---- | -------------------------- | 3364| context | [Context](../apis-ability-kit/js-apis-inner-application-context.md) | Yes | Context of the ability instance.| 3365| uriList | Array<string> | Yes | URIs of the media files to delete.| 3366 3367**Return value** 3368 3369| Type | Description | 3370| --------------------------------------- | ----------------- | 3371| Promise<void>| Promise that returns no value.| 3372 3373**Error codes** 3374 3375For details about the error codes, see [Universal Error Codes](../errorcode-universal.md) and [File Management Error Codes](../apis-core-file-kit/errorcode-filemanagement.md). 3376 3377| ID| Error Message| 3378| -------- | ---------------------------------------- | 3379| 201 | Permission denied. | 3380| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types; 3. Parameter verification failed. | 3381| 14000002 | Invalid asset uri. | 3382| 14000011 | System inner fail. | 3383 3384**Example** 3385 3386```ts 3387import { dataSharePredicates } from '@kit.ArkData'; 3388 3389async function example() { 3390 console.info('deleteAssetsDemo'); 3391 let predicates: dataSharePredicates.DataSharePredicates = new dataSharePredicates.DataSharePredicates(); 3392 let fetchOptions: photoAccessHelper.FetchOptions = { 3393 fetchColumns: [], 3394 predicates: predicates 3395 }; 3396 try { 3397 let fetchResult: photoAccessHelper.FetchResult<photoAccessHelper.PhotoAsset> = await phAccessHelper.getAssets(fetchOptions); 3398 let asset: photoAccessHelper.PhotoAsset = await fetchResult.getFirstObject(); 3399 await photoAccessHelper.MediaAssetChangeRequest.deleteAssets(context, [asset.uri]); 3400 console.info('deleteAssets successfully'); 3401 } catch (err) { 3402 console.error(`deleteAssetsDemo failed with error: ${err.code}, ${err.message}`); 3403 } 3404} 3405``` 3406 3407### getAsset<sup>11+</sup> 3408 3409getAsset(): PhotoAsset 3410 3411Obtains the asset in this asset change request. 3412 3413> **NOTE**<br>For the change request used to create an asset, this API returns **null** before [applyChanges](#applychanges11) is called to apply the changes. 3414 3415**Atomic service API**: This API can be used in atomic services since API version 12. 3416 3417**System capability**: SystemCapability.FileManagement.PhotoAccessHelper.Core 3418 3419**Return value** 3420 3421| Type | Description | 3422| --------------------------------------- | ----------------- | 3423| [PhotoAsset](#photoasset) | Asset obtained.| 3424 3425**Error codes** 3426 3427For details about the error codes, see [Universal Error Codes](../errorcode-universal.md) and [File Management Error Codes](../apis-core-file-kit/errorcode-filemanagement.md). 3428 3429| ID| Error Message| 3430| -------- | ---------------------------------------- | 3431| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types. | 3432| 14000011 | System inner fail. | 3433 3434**Example** 3435 3436```ts 3437async function example() { 3438 console.info('getAssetDemo'); 3439 try { 3440 // Ensure that the asset specified by fileUri exists. 3441 let fileUri = 'file://com.example.temptest/data/storage/el2/base/haps/entry/files/test.jpg'; 3442 let assetChangeRequest: photoAccessHelper.MediaAssetChangeRequest = photoAccessHelper.MediaAssetChangeRequest.createImageAssetRequest(context, fileUri); 3443 await phAccessHelper.applyChanges(assetChangeRequest); 3444 let asset: photoAccessHelper.PhotoAsset = assetChangeRequest.getAsset(); 3445 console.info('create asset successfully with uri = ' + asset.uri); 3446 } catch (err) { 3447 console.error(`getAssetDemo failed with error: ${err.code}, ${err.message}`); 3448 } 3449} 3450``` 3451 3452### setTitle<sup>11+</sup> 3453 3454setTitle(title: string): void 3455 3456Sets the media asset title. 3457 3458**Atomic service API**: This API can be used in atomic services since API version 12. 3459 3460**System capability**: SystemCapability.FileManagement.PhotoAccessHelper.Core 3461 3462**Parameters** 3463 3464| Name | Type | Mandatory | Description | 3465| ---------- | ------- | ---- | ---------------------------------- | 3466| title | string | Yes | Title to set.| 3467 3468The title must meet the following requirements: 3469- It does not contain a file name extension. 3470- The file name cannot exceed 255 characters. 3471- It does not contain any of the following characters:<br> . \ / : * ? " ' ` < > | { } [ ] 3472 3473**Error codes** 3474 3475For details about the error codes, see [Universal Error Codes](../errorcode-universal.md) and [File Management Error Codes](../apis-core-file-kit/errorcode-filemanagement.md). 3476 3477| ID| Error Message| 3478| -------- | ---------------------------------------- | 3479| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types; 3. Parameter verification failed. | 3480| 14000011 | System inner fail. | 3481 3482**Example** 3483 3484```ts 3485import { dataSharePredicates } from '@kit.ArkData'; 3486import { BusinessError } from '@kit.BasicServicesKit'; 3487 3488async function example() { 3489 console.info('setTitleDemo'); 3490 let predicates: dataSharePredicates.DataSharePredicates = new dataSharePredicates.DataSharePredicates(); 3491 let fetchOption: photoAccessHelper.FetchOptions = { 3492 fetchColumns: [], 3493 predicates: predicates 3494 }; 3495 let fetchResult: photoAccessHelper.FetchResult<photoAccessHelper.PhotoAsset> = await phAccessHelper.getAssets(fetchOption); 3496 let asset = await fetchResult.getFirstObject(); 3497 let assetChangeRequest: photoAccessHelper.MediaAssetChangeRequest = new photoAccessHelper.MediaAssetChangeRequest(asset); 3498 let newTitle: string = 'newTitle'; 3499 assetChangeRequest.setTitle(newTitle); 3500 phAccessHelper.applyChanges(assetChangeRequest).then(() => { 3501 console.info('apply setTitle successfully'); 3502 }).catch((err: BusinessError) => { 3503 console.error(`apply setTitle failed with error: ${err.code}, ${err.message}`); 3504 }); 3505} 3506``` 3507 3508### getWriteCacheHandler<sup>11+</sup> 3509 3510getWriteCacheHandler(): Promise<number> 3511 3512Obtains the handler used for writing a file to cache. 3513 3514> **NOTE**<br>For the same asset change request, this API cannot be repeatedly called after a temporary file write handle is successfully obtained. 3515 3516**Required permissions**: ohos.permission.WRITE_IMAGEVIDEO 3517 3518**System capability**: SystemCapability.FileManagement.PhotoAccessHelper.Core 3519 3520**Return value** 3521 3522| Type | Description | 3523| --------------------------------------- | ----------------- | 3524| Promise<number> | Promise used to return the write handle obtained.| 3525 3526**Error codes** 3527 3528For details about the error codes, see [Universal Error Codes](../errorcode-universal.md) and [File Management Error Codes](../apis-core-file-kit/errorcode-filemanagement.md). 3529 3530| ID| Error Message| 3531| -------- | ---------------------------------------- | 3532| 201 | Permission denied. | 3533| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types. | 3534| 14000011 | System inner fail. | 3535| 14000016 | Operation Not Support. | 3536 3537**Example** 3538 3539```ts 3540import { fileIo } from '@kit.CoreFileKit'; 3541 3542async function example() { 3543 console.info('getWriteCacheHandlerDemo'); 3544 try { 3545 let photoType: photoAccessHelper.PhotoType = photoAccessHelper.PhotoType.VIDEO; 3546 let extension: string = 'mp4'; 3547 let assetChangeRequest: photoAccessHelper.MediaAssetChangeRequest = photoAccessHelper.MediaAssetChangeRequest.createAssetRequest(context, photoType, extension); 3548 let fd: number = await assetChangeRequest.getWriteCacheHandler(); 3549 console.info('getWriteCacheHandler successfully'); 3550 // write date into fd.. 3551 await fileIo.close(fd); 3552 await phAccessHelper.applyChanges(assetChangeRequest); 3553 } catch (err) { 3554 console.error(`getWriteCacheHandlerDemo failed with error: ${err.code}, ${err.message}`); 3555 } 3556} 3557``` 3558 3559### addResource<sup>11+</sup> 3560 3561addResource(type: ResourceType, fileUri: string): void 3562 3563Adds a resource using **fileUri**. 3564 3565> **NOTE**<br>For the same asset change request, this API cannot be repeatedly called after the resource is successfully added. For a moving photo, you can call this API twice to add the image and video resources. 3566 3567**Atomic service API**: This API can be used in atomic services since API version 11. 3568 3569**System capability**: SystemCapability.FileManagement.PhotoAccessHelper.Core 3570 3571**Parameters** 3572 3573| Name | Type | Mandatory| Description | 3574| ------- | ------- | ---- | -------------------------- | 3575| type | [ResourceType](#resourcetype11) | Yes | Type of the resource to add.| 3576| fileUri | string | Yes | Data source of the resource to be added, which is specified by a URI in the application sandbox directory.| 3577 3578**Error codes** 3579 3580For details about the error codes, see [Universal Error Codes](../errorcode-universal.md) and [File Management Error Codes](../apis-core-file-kit/errorcode-filemanagement.md). 3581 3582| ID| Error Message| 3583| -------- | ---------------------------------------- | 3584| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types; 3. Parameter verification failed. | 3585| 13900002 | No such file. | 3586| 14000011 | System inner fail. | 3587| 14000016 | Operation Not Support. | 3588 3589**Example** 3590 3591```ts 3592async function example() { 3593 console.info('addResourceByFileUriDemo'); 3594 try { 3595 let photoType: photoAccessHelper.PhotoType = photoAccessHelper.PhotoType.IMAGE; 3596 let extension: string = 'jpg'; 3597 let assetChangeRequest: photoAccessHelper.MediaAssetChangeRequest = photoAccessHelper.MediaAssetChangeRequest.createAssetRequest(context, photoType, extension); 3598 // Ensure that the asset specified by fileUri exists. 3599 let fileUri = 'file://com.example.temptest/data/storage/el2/base/haps/entry/files/test.jpg'; 3600 assetChangeRequest.addResource(photoAccessHelper.ResourceType.IMAGE_RESOURCE, fileUri); 3601 await phAccessHelper.applyChanges(assetChangeRequest); 3602 console.info('addResourceByFileUri successfully'); 3603 } catch (err) { 3604 console.error(`addResourceByFileUriDemo failed with error: ${err.code}, ${err.message}`); 3605 } 3606} 3607``` 3608 3609### addResource<sup>11+</sup> 3610 3611addResource(type: ResourceType, data: ArrayBuffer): void 3612 3613Adds a resource using **ArrayBuffer** data. 3614 3615> **NOTE**<br>For the same asset change request, this API cannot be repeatedly called after the resource is successfully added. For a moving photo, you can call this API twice to add the image and video resources. 3616 3617**Atomic service API**: This API can be used in atomic services since API version 11. 3618 3619**System capability**: SystemCapability.FileManagement.PhotoAccessHelper.Core 3620 3621**Parameters** 3622 3623| Name | Type | Mandatory| Description | 3624| ------- | ------- | ---- | -------------------------- | 3625| type | [ResourceType](#resourcetype11) | Yes | Type of the resource to add.| 3626| data | ArrayBuffer | Yes | Data of the resource to add.| 3627 3628**Error codes** 3629 3630For details about the error codes, see [Universal Error Codes](../errorcode-universal.md) and [File Management Error Codes](../apis-core-file-kit/errorcode-filemanagement.md). 3631 3632| ID| Error Message| 3633| -------- | ---------------------------------------- | 3634| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types; 3. Parameter verification failed. | 3635| 14000011 | System inner fail. | 3636| 14000016 | Operation Not Support. | 3637 3638**Example** 3639 3640```ts 3641async function example() { 3642 console.info('addResourceByArrayBufferDemo'); 3643 try { 3644 let photoType: photoAccessHelper.PhotoType = photoAccessHelper.PhotoType.IMAGE; 3645 let extension: string = 'jpg'; 3646 let assetChangeRequest: photoAccessHelper.MediaAssetChangeRequest = photoAccessHelper.MediaAssetChangeRequest.createAssetRequest(context, photoType, extension); 3647 let buffer: ArrayBuffer = new ArrayBuffer(2048); 3648 assetChangeRequest.addResource(photoAccessHelper.ResourceType.IMAGE_RESOURCE, buffer); 3649 await phAccessHelper.applyChanges(assetChangeRequest); 3650 console.info('addResourceByArrayBuffer successfully'); 3651 } catch (err) { 3652 console.error(`addResourceByArrayBufferDemo failed with error: ${err.code}, ${err.message}`); 3653 } 3654} 3655``` 3656 3657### saveCameraPhoto<sup>12+</sup> 3658 3659saveCameraPhoto(): void 3660 3661Saves the photo taken by the camera. 3662 3663**System capability**: SystemCapability.FileManagement.PhotoAccessHelper.Core 3664 3665**Error codes** 3666 3667For details about the error codes, see [File Management Error Codes](../apis-core-file-kit/errorcode-filemanagement.md). 3668 3669| ID| Error Message| 3670| -------- | ---------------------------------------- | 3671| 14000011 | System inner fail. | 3672| 14000016 | Operation Not Support. | 3673 3674**Example** 3675 3676```ts 3677async function example(asset: photoAccessHelper.PhotoAsset) { 3678 console.info('saveCameraPhotoDemo'); 3679 try { 3680 let assetChangeRequest: photoAccessHelper.MediaAssetChangeRequest = new photoAccessHelper.MediaAssetChangeRequest(asset); 3681 assetChangeRequest.saveCameraPhoto(); 3682 await phAccessHelper.applyChanges(assetChangeRequest); 3683 console.info('apply saveCameraPhoto successfully'); 3684 } catch (err) { 3685 console.error(`apply saveCameraPhoto failed with error: ${err.code}, ${err.message}`); 3686 } 3687} 3688``` 3689 3690### saveCameraPhoto<sup>13+</sup> 3691 3692saveCameraPhoto(imageFileType: ImageFileType): void 3693 3694Saves the photo taken by the camera. 3695 3696**System capability**: SystemCapability.FileManagement.PhotoAccessHelper.Core 3697 3698**Parameters** 3699 3700| Name | Type | Mandatory| Description | 3701| -------- | ------------------------- | ---- | ---------- | 3702| imageFileType | [ImageFileType](#imagefiletype13) | Yes | File type of the photo to save.| 3703 3704**Error codes** 3705 3706For details about the error codes, see [File Management Error Codes](../apis-core-file-kit/errorcode-filemanagement.md). 3707 3708| ID| Error Message| 3709| -------- | ---------------------------------------- | 3710| 14000011 | System inner fail. | 3711| 14000016 | Operation Not Support. | 3712 3713**Example** 3714 3715```ts 3716import { photoAccessHelper } from '@kit.MediaLibraryKit'; 3717import { dataSharePredicates } from '@kit.ArkData'; 3718import { image } from '@kit.ImageKit'; 3719 3720async function example(asset: photoAccessHelper.PhotoAsset) { 3721 console.info('saveCameraPhotoDemo'); 3722 try { 3723 let phAccessHelper = photoAccessHelper.getPhotoAccessHelper(context); 3724 let assetChangeRequest: photoAccessHelper.MediaAssetChangeRequest = new photoAccessHelper.MediaAssetChangeRequest(asset); 3725 assetChangeRequest.saveCameraPhoto(photoAccessHelper.ImageFileType.JPEG); 3726 await phAccessHelper.applyChanges(assetChangeRequest); 3727 console.info('apply saveCameraPhoto successfully'); 3728 } catch (err) { 3729 console.error(`apply saveCameraPhoto failed with error: ${err.code}, ${err.message}`); 3730 } 3731} 3732``` 3733 3734### discardCameraPhoto<sup>12+</sup> 3735 3736discardCameraPhoto(): void 3737 3738Discards the photo taken by the camera. 3739 3740**System capability**: SystemCapability.FileManagement.PhotoAccessHelper.Core 3741 3742**Error codes** 3743 3744For details about the error codes, see [File Management Error Codes](../apis-core-file-kit/errorcode-filemanagement.md). 3745 3746| ID| Error Message| 3747| -------- | ---------------------------------------- | 3748| 14000011 | Internal system error. | 3749| 14000016 | Operation Not Support. | 3750 3751**Example** 3752 3753```ts 3754async function example(asset: photoAccessHelper.PhotoAsset) { 3755 console.info('discardCameraPhotoDemo'); 3756 try { 3757 let assetChangeRequest: photoAccessHelper.MediaAssetChangeRequest = new photoAccessHelper.MediaAssetChangeRequest(asset); 3758 assetChangeRequest.discardCameraPhoto(); 3759 await phAccessHelper.applyChanges(assetChangeRequest); 3760 console.info('apply discardCameraPhoto successfully'); 3761 } catch (err) { 3762 console.error(`apply discardCameraPhoto failed with error: ${err.code}, ${err.message}`); 3763 } 3764} 3765``` 3766 3767### setOrientation<sup>15+</sup> 3768 3769setOrientation(orientation: number): void 3770 3771Sets the orientation of this image. 3772 3773**System capability**: SystemCapability.FileManagement.PhotoAccessHelper.Core 3774 3775**Parameters** 3776 3777| Name | Type | Mandatory | Description | 3778| ---------- | ------- | ---- | ---------------------------------- | 3779| orientation | number | Yes | Rotation angle of the image to set. The value can only be **0**, **90**, **180**, or **270**.| 3780 3781**Error codes** 3782 3783For details about the error codes, see [Universal Error Codes](../errorcode-universal.md) and [File Management Error Codes](../apis-core-file-kit/errorcode-filemanagement.md). 3784 3785| ID| Error Message| 3786| -------- | ---------------------------------------- | 3787| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types; 3. Parameter verification failed. | 3788| 14000011 | Internal system error. | 3789 3790**Example** 3791 3792```ts 3793import { dataSharePredicates } from '@kit.ArkData'; 3794import { BusinessError } from '@kit.BasicServicesKit'; 3795 3796async function example() { 3797 console.info('setOrientationDemo'); 3798 let predicates: dataSharePredicates.DataSharePredicates = new dataSharePredicates.DataSharePredicates(); 3799 let fetchOption: photoAccessHelper.FetchOptions = { 3800 fetchColumns: [], 3801 predicates: predicates 3802 }; 3803 let fetchResult: photoAccessHelper.FetchResult<photoAccessHelper.PhotoAsset> = await phAccessHelper.getAssets(fetchOption); 3804 let asset = await fetchResult.getFirstObject(); 3805 let assetChangeRequest: photoAccessHelper.MediaAssetChangeRequest = new photoAccessHelper.MediaAssetChangeRequest(asset); 3806 assetChangeRequest.setOrientation(90); 3807 phAccessHelper.applyChanges(assetChangeRequest).then(() => { 3808 console.info('apply setOrientation successfully'); 3809 }).catch((err: BusinessError) => { 3810 console.error(`apply setOrientation failed with error: ${err.code}, ${err.message}`); 3811 }); 3812} 3813``` 3814 3815## MediaAlbumChangeRequest<sup>11+</sup> 3816 3817Provides APIs for managing the media album change request. 3818 3819**System capability**: SystemCapability.FileManagement.PhotoAccessHelper.Core 3820 3821### constructor<sup>11+</sup> 3822 3823constructor(album: Album) 3824 3825Constructor. 3826 3827**System capability**: SystemCapability.FileManagement.PhotoAccessHelper.Core 3828 3829**Parameters** 3830 3831| Name | Type | Mandatory| Description | 3832| -------- | ------------------------- | ---- | ---------- | 3833| album | [Album](#album) | Yes | Album to change.| 3834 3835**Error codes** 3836 3837For details about the error codes, see [Universal Error Codes](../errorcode-universal.md) and [File Management Error Codes](../apis-core-file-kit/errorcode-filemanagement.md). 3838 3839| ID| Error Message| 3840| -------- | ---------------------------------------- | 3841| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types; 3. Parameter verification failed. | 3842| 14000011 | System inner fail. | 3843 3844**Example** 3845 3846```ts 3847import { dataSharePredicates } from '@kit.ArkData'; 3848 3849async function example() { 3850 console.info('MediaAlbumChangeRequest constructorDemo'); 3851 let predicates: dataSharePredicates.DataSharePredicates = new dataSharePredicates.DataSharePredicates(); 3852 let fetchOptions: photoAccessHelper.FetchOptions = { 3853 fetchColumns: [], 3854 predicates: predicates 3855 }; 3856 let fetchResult: photoAccessHelper.FetchResult<photoAccessHelper.Album> = await phAccessHelper.getAlbums(photoAccessHelper.AlbumType.USER, photoAccessHelper.AlbumSubtype.USER_GENERIC, fetchOptions); 3857 let album: photoAccessHelper.Album = await fetchResult.getFirstObject(); 3858 let albumChangeRequest: photoAccessHelper.MediaAlbumChangeRequest = new photoAccessHelper.MediaAlbumChangeRequest(album); 3859} 3860``` 3861 3862### getAlbum<sup>11+</sup> 3863 3864getAlbum(): Album 3865 3866Obtains the album in the current album change request. 3867 3868> **NOTE**<br>For the change request for creating an album, this API returns **null** before [applyChanges](#applychanges11) is called to apply the changes. 3869 3870**System capability**: SystemCapability.FileManagement.PhotoAccessHelper.Core 3871 3872**Return value** 3873 3874| Type | Description | 3875| --------------------------------------- | ----------------- | 3876| [Album](#album) | Album obtained.| 3877 3878**Error codes** 3879 3880For details about the error codes, see [Universal Error Codes](../errorcode-universal.md) and [File Management Error Codes](../apis-core-file-kit/errorcode-filemanagement.md). 3881 3882| ID| Error Message| 3883| -------- | ---------------------------------------- | 3884| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types. | 3885| 14000011 | System inner fail. | 3886 3887**Example** 3888 3889```ts 3890async function example() { 3891 console.info('getAlbumDemo'); 3892 try { 3893 // Ensure that the user album exists in the gallery. 3894 let albumFetchResult: photoAccessHelper.FetchResult<photoAccessHelper.Album> = await phAccessHelper.getAlbums(photoAccessHelper.AlbumType.USER, photoAccessHelper.AlbumSubtype.USER_GENERIC); 3895 let album: photoAccessHelper.Album = await albumFetchResult.getFirstObject(); 3896 let albumChangeRequest: photoAccessHelper.MediaAlbumChangeRequest = new photoAccessHelper.MediaAlbumChangeRequest(album); 3897 let changeRequestAlbum: photoAccessHelper.Album = albumChangeRequest.getAlbum(); 3898 console.info('change request album uri: ' + changeRequestAlbum.albumUri); 3899 } catch (err) { 3900 console.error(`getAlbumDemo failed with error: ${err.code}, ${err.message}`); 3901 } 3902} 3903``` 3904 3905### setAlbumName<sup>11+</sup> 3906 3907setAlbumName(name: string): void 3908 3909Sets the album name. 3910 3911The album name must comply with the following specifications: 3912- It does not exceed 255 characters. 3913- It does not contain any of the following characters:<br> . \ / : * ? " ' ` < > | { } [ ] 3914- It is case-insensitive. 3915- Duplicate album names are not allowed. 3916 3917**System capability**: SystemCapability.FileManagement.PhotoAccessHelper.Core 3918 3919**Parameters** 3920 3921| Name | Type | Mandatory | Description | 3922| ---------- | ------- | ---- | ---------------------------------- | 3923| name | string | Yes | Album name to set.| 3924 3925**Error codes** 3926 3927For details about the error codes, see [Universal Error Codes](../errorcode-universal.md) and [File Management Error Codes](../apis-core-file-kit/errorcode-filemanagement.md). 3928 3929| ID| Error Message| 3930| -------- | ---------------------------------------- | 3931| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types; 3. Parameter verification failed. | 3932| 14000011 | System inner fail. | 3933 3934**Example** 3935 3936```ts 3937async function example() { 3938 console.info('setAlbumNameDemo'); 3939 try { 3940 let albumFetchResult: photoAccessHelper.FetchResult<photoAccessHelper.Album> = await phAccessHelper.getAlbums(photoAccessHelper.AlbumType.USER, photoAccessHelper.AlbumSubtype.USER_GENERIC); 3941 let album: photoAccessHelper.Album = await albumFetchResult.getFirstObject(); 3942 let albumChangeRequest: photoAccessHelper.MediaAlbumChangeRequest = new photoAccessHelper.MediaAlbumChangeRequest(album); 3943 let newAlbumName: string = 'newAlbumName' + new Date().getTime(); 3944 albumChangeRequest.setAlbumName(newAlbumName); 3945 await phAccessHelper.applyChanges(albumChangeRequest); 3946 console.info('setAlbumName successfully'); 3947 } catch (err) { 3948 console.error(`setAlbumNameDemo failed with error: ${err.code}, ${err.message}`); 3949 } 3950} 3951``` 3952 3953### addAssets<sup>11+</sup> 3954 3955addAssets(assets: Array<PhotoAsset>): void 3956 3957Add assets to the album. 3958 3959**System capability**: SystemCapability.FileManagement.PhotoAccessHelper.Core 3960 3961**Parameters** 3962 3963| Name | Type | Mandatory | Description | 3964| ---------- | ------- | ---- | ---------------------------------- | 3965| assets | Array<[PhotoAsset](#photoasset)> | Yes | Assets to add.| 3966 3967**Error codes** 3968 3969For details about the error codes, see [Universal Error Codes](../errorcode-universal.md) and [File Management Error Codes](../apis-core-file-kit/errorcode-filemanagement.md). 3970 3971| ID| Error Message| 3972| -------- | ---------------------------------------- | 3973| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types; 3. Parameter verification failed. | 3974| 14000011 | System inner fail. | 3975| 14000016 | Operation Not Support. | 3976 3977**Example** 3978 3979```ts 3980import { dataSharePredicates } from '@kit.ArkData'; 3981 3982async function example() { 3983 console.info('addAssetsDemo'); 3984 let predicates: dataSharePredicates.DataSharePredicates = new dataSharePredicates.DataSharePredicates(); 3985 let fetchOptions: photoAccessHelper.FetchOptions = { 3986 fetchColumns: [], 3987 predicates: predicates 3988 }; 3989 try { 3990 // Ensure that user albums and photos exist in Gallery. 3991 let fetchResult: photoAccessHelper.FetchResult<photoAccessHelper.PhotoAsset> = await phAccessHelper.getAssets(fetchOptions); 3992 let asset: photoAccessHelper.PhotoAsset = await fetchResult.getFirstObject(); 3993 let albumFetchResult: photoAccessHelper.FetchResult<photoAccessHelper.Album> = await phAccessHelper.getAlbums(photoAccessHelper.AlbumType.USER, photoAccessHelper.AlbumSubtype.USER_GENERIC); 3994 let album: photoAccessHelper.Album = await albumFetchResult.getFirstObject(); 3995 let albumChangeRequest: photoAccessHelper.MediaAlbumChangeRequest = new photoAccessHelper.MediaAlbumChangeRequest(album); 3996 albumChangeRequest.addAssets([asset]); 3997 await phAccessHelper.applyChanges(albumChangeRequest); 3998 console.info('addAssets successfully'); 3999 } catch (err) { 4000 console.error(`addAssetsDemo failed with error: ${err.code}, ${err.message}`); 4001 } 4002} 4003``` 4004 4005### removeAssets<sup>11+</sup> 4006 4007removeAssets(assets: Array<PhotoAsset>): void 4008 4009Removes assets from the album. 4010 4011**System capability**: SystemCapability.FileManagement.PhotoAccessHelper.Core 4012 4013**Parameters** 4014 4015| Name | Type | Mandatory | Description | 4016| ---------- | ------- | ---- | ---------------------------------- | 4017| assets | Array<[PhotoAsset](#photoasset)> | Yes | Assets to remove.| 4018 4019**Error codes** 4020 4021For details about the error codes, see [Universal Error Codes](../errorcode-universal.md) and [File Management Error Codes](../apis-core-file-kit/errorcode-filemanagement.md). 4022 4023| ID| Error Message| 4024| -------- | ---------------------------------------- | 4025| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types; 3. Parameter verification failed. | 4026| 14000011 | System inner fail. | 4027| 14000016 | Operation Not Support. | 4028 4029**Example** 4030 4031```ts 4032import { dataSharePredicates } from '@kit.ArkData'; 4033 4034async function example() { 4035 console.info('removeAssetsDemo'); 4036 let predicates: dataSharePredicates.DataSharePredicates = new dataSharePredicates.DataSharePredicates(); 4037 let fetchOptions: photoAccessHelper.FetchOptions = { 4038 fetchColumns: [], 4039 predicates: predicates 4040 }; 4041 try { 4042 let albumFetchResult: photoAccessHelper.FetchResult<photoAccessHelper.Album> = await phAccessHelper.getAlbums(photoAccessHelper.AlbumType.USER, photoAccessHelper.AlbumSubtype.USER_GENERIC); 4043 let album: photoAccessHelper.Album = await albumFetchResult.getFirstObject(); 4044 let fetchResult: photoAccessHelper.FetchResult<photoAccessHelper.PhotoAsset> = await album.getAssets(fetchOptions); 4045 let asset: photoAccessHelper.PhotoAsset = await fetchResult.getFirstObject(); 4046 4047 let albumChangeRequest: photoAccessHelper.MediaAlbumChangeRequest = new photoAccessHelper.MediaAlbumChangeRequest(album); 4048 albumChangeRequest.removeAssets([asset]); 4049 await phAccessHelper.applyChanges(albumChangeRequest); 4050 console.info('removeAssets successfully'); 4051 } catch (err) { 4052 console.error(`removeAssetsDemo failed with error: ${err.code}, ${err.message}`); 4053 } 4054} 4055``` 4056 4057## MediaAssetManager<sup>11+</sup> 4058 4059A media asset manager class, used for manipulating the read and write operations of media assets. 4060 4061**System capability**: SystemCapability.FileManagement.PhotoAccessHelper.Core 4062 4063### requestImage<sup>11+</sup> 4064 4065static requestImage(context: Context, asset: PhotoAsset, requestOptions: RequestOptions, dataHandler: MediaAssetDataHandler<image.ImageSource>): Promise<string> 4066 4067Requests an image. 4068 4069**System capability**: SystemCapability.FileManagement.PhotoAccessHelper.Core 4070 4071**Required permissions**: ohos.permission.READ_IMAGEVIDEO 4072 4073- When you call this API in Picker mode, you do not need to request the ohos.permission.READ_IMAGEVIDEO permission. For details, see [Obtaining an Image or Video by URI](../../media/medialibrary/photoAccessHelper-photoviewpicker.md#obtaining-an-image-or-video-by-uri). 4074- For the media assets saved to the media library by this application, the application can access them without the ohos.permission.READ_IMAGEVIDEO permission. 4075 4076**Parameters** 4077 4078| Name | Type | Mandatory| Description | 4079|----------------|-----------------------------------------------------------------------------------------------------------| ---- | ------------------------- | 4080| context | [Context](../apis-ability-kit/js-apis-inner-application-context.md) | Yes | Context of the ability instance.| 4081| asset | [PhotoAsset](#photoasset) | Yes | Image to request.| 4082| requestOptions | [RequestOptions](#requestoptions11) | Yes | Options for requesting the image.| 4083| dataHandler | [MediaAssetDataHandler](#mediaassetdatahandler11)<[image.ImageSource](../apis-image-kit/js-apis-image.md#imagesource)> | Yes | Media asset handler, which invokes a callback to return the image when the requested image is ready.| 4084 4085**Return value** 4086 4087| Type | Description | 4088| --------------------------------------- | ----------------- | 4089| Promise\<string> | Promise used to return the request ID, which can be used in [cancelRequest](#cancelrequest12) to cancel a request.| 4090 4091**Error codes** 4092 4093For details about the error codes, see [Universal Error Codes](../errorcode-universal.md) and [File Management Error Codes](../apis-core-file-kit/errorcode-filemanagement.md). 4094 4095| ID| Error Message| 4096| -------- | ---------------------------------------- | 4097| 201 | Permission denied | 4098| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types; 3. Parameter verification failed. | 4099| 14000011 | System inner fail. | 4100 4101**Example** 4102 4103```ts 4104import { dataSharePredicates } from '@kit.ArkData'; 4105import { image } from '@kit.ImageKit'; 4106 4107class MediaHandler implements photoAccessHelper.MediaAssetDataHandler<image.ImageSource> { 4108 onDataPrepared(data: image.ImageSource) { 4109 if (data === undefined) { 4110 console.error('Error occurred when preparing data'); 4111 return; 4112 } 4113 console.info('on image data prepared'); 4114 } 4115} 4116 4117async function example() { 4118 console.info('requestImage'); 4119 let predicates: dataSharePredicates.DataSharePredicates = new dataSharePredicates.DataSharePredicates(); 4120 let fetchOptions: photoAccessHelper.FetchOptions = { 4121 fetchColumns: [], 4122 predicates: predicates 4123 }; 4124 let requestOptions: photoAccessHelper.RequestOptions = { 4125 deliveryMode: photoAccessHelper.DeliveryMode.HIGH_QUALITY_MODE, 4126 } 4127 const handler = new MediaHandler(); 4128 4129 phAccessHelper.getAssets(fetchOptions, async (err, fetchResult) => { 4130 console.info('fetchResult success'); 4131 let photoAsset: photoAccessHelper.PhotoAsset = await fetchResult.getFirstObject(); 4132 await photoAccessHelper.MediaAssetManager.requestImage(context, photoAsset, requestOptions, handler); 4133 console.info('requestImage successfully'); 4134 }); 4135} 4136``` 4137 4138### requestImageData<sup>11+</sup> 4139 4140static requestImageData(context: Context, asset: PhotoAsset, requestOptions: RequestOptions, dataHandler: MediaAssetDataHandler<ArrayBuffer>): Promise<string> 4141 4142Requests image data. 4143 4144**System capability**: SystemCapability.FileManagement.PhotoAccessHelper.Core 4145 4146**Required permissions**: ohos.permission.READ_IMAGEVIDEO 4147 4148- When you call this API in Picker mode, you do not need to request the ohos.permission.READ_IMAGEVIDEO permission. For details, see [Obtaining an Image or Video by URI](../../media/medialibrary/photoAccessHelper-photoviewpicker.md#obtaining-an-image-or-video-by-uri). 4149- For the media assets saved to the media library by this application, the application can access them without the ohos.permission.READ_IMAGEVIDEO permission. 4150 4151**Parameters** 4152 4153| Name | Type | Mandatory| Description | 4154| -------- |----------------------------------------------------------------------| ---- | ------------------------- | 4155| context | [Context](../apis-ability-kit/js-apis-inner-application-context.md) | Yes | Context of the ability instance.| 4156| asset | [PhotoAsset](#photoasset) | Yes | Image to request.| 4157| requestOptions | [RequestOptions](#requestoptions11) | Yes | Options for requesting the image.| 4158| dataHandler | [MediaAssetDataHandler](#mediaassetdatahandler11)<ArrayBuffer> | Yes | Media asset handler, which invokes a callback to return the image when the requested image is ready.| 4159 4160**Return value** 4161 4162| Type | Description | 4163| --------------------------------------- | ----------------- | 4164| Promise\<string> | Promise used to return the request ID, which can be used in [cancelRequest](#cancelrequest12) to cancel a request.| 4165 4166**Error codes** 4167 4168For details about the error codes, see [Universal Error Codes](../errorcode-universal.md) and [File Management Error Codes](../apis-core-file-kit/errorcode-filemanagement.md). 4169 4170| ID| Error Message| 4171| -------- | ---------------------------------------- | 4172| 201 | Permission denied | 4173| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types; 3. Parameter verification failed. | 4174| 14000011 | System inner fail. | 4175 4176**Example** 4177 4178```ts 4179import { dataSharePredicates } from '@kit.ArkData'; 4180class MediaDataHandler implements photoAccessHelper.MediaAssetDataHandler<ArrayBuffer> { 4181 onDataPrepared(data: ArrayBuffer) { 4182 if (data === undefined) { 4183 console.error('Error occurred when preparing data'); 4184 return; 4185 } 4186 console.info('on image data prepared'); 4187 } 4188} 4189 4190async function example() { 4191 console.info('requestImageData'); 4192 let predicates: dataSharePredicates.DataSharePredicates = new dataSharePredicates.DataSharePredicates(); 4193 let fetchOptions: photoAccessHelper.FetchOptions = { 4194 fetchColumns: [], 4195 predicates: predicates 4196 }; 4197 let requestOptions: photoAccessHelper.RequestOptions = { 4198 deliveryMode: photoAccessHelper.DeliveryMode.HIGH_QUALITY_MODE, 4199 } 4200 const handler = new MediaDataHandler(); 4201 4202 phAccessHelper.getAssets(fetchOptions, async (err, fetchResult) => { 4203 console.info('fetchResult success'); 4204 let photoAsset: photoAccessHelper.PhotoAsset = await fetchResult.getFirstObject(); 4205 await photoAccessHelper.MediaAssetManager.requestImageData(context, photoAsset, requestOptions, handler); 4206 console.info('requestImageData successfully'); 4207 }); 4208} 4209``` 4210 4211### requestMovingPhoto<sup>12+</sup> 4212 4213static requestMovingPhoto(context: Context, asset: PhotoAsset, requestOptions: RequestOptions, dataHandler: MediaAssetDataHandler<MovingPhoto>): Promise<string> 4214 4215Requests a moving photo object, which can be used to request the asset data of the moving photo. 4216 4217**System capability**: SystemCapability.FileManagement.PhotoAccessHelper.Core 4218 4219**Required permissions**: ohos.permission.READ_IMAGEVIDEO 4220 4221- When you call this API in Picker mode, you do not need to request the ohos.permission.READ_IMAGEVIDEO permission. For details, see [Obtaining an Image or Video by URI](../../media/medialibrary/photoAccessHelper-photoviewpicker.md#obtaining-an-image-or-video-by-uri). 4222- For the moving photos saved to the media library by this application, the application can access them without the ohos.permission.READ_IMAGEVIDEO permission. 4223 4224**Parameters** 4225 4226| Name | Type | Mandatory| Description | 4227| -------- |----------------------------------------------------------------------| ---- | ------------------------- | 4228| context | [Context](../apis-ability-kit/js-apis-inner-application-context.md) | Yes | Context of the ability instance.| 4229| asset | [PhotoAsset](#photoasset) | Yes | Image to request.| 4230| requestOptions | [RequestOptions](#requestoptions11) | Yes | Options for requesting the image.| 4231| dataHandler | [MediaAssetDataHandler](#mediaassetdatahandler11)<[MovingPhoto](#movingphoto12)> | Yes | Media asset handler, which invokes a callback to return the image when the requested image is ready.| 4232 4233**Return value** 4234 4235| Type | Description | 4236| --------------------------------------- | ----------------- | 4237| Promise\<string> | Promise used to return the request ID, which can be used in [cancelRequest](#cancelrequest12) to cancel a request.| 4238 4239**Error codes** 4240 4241For details about the error codes, see [Universal Error Codes](../errorcode-universal.md) and [File Management Error Codes](../apis-core-file-kit/errorcode-filemanagement.md). 4242 4243| ID| Error Message| 4244| -------- | ---------------------------------------- | 4245| 201 | Permission denied | 4246| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types; 3. Parameter verification failed. | 4247| 14000011 | System inner fail | 4248 4249**Example** 4250 4251```ts 4252import { dataSharePredicates } from '@kit.ArkData'; 4253 4254class MovingPhotoHandler implements photoAccessHelper.MediaAssetDataHandler<photoAccessHelper.MovingPhoto> { 4255 async onDataPrepared(movingPhoto: photoAccessHelper.MovingPhoto) { 4256 if (movingPhoto === undefined) { 4257 console.error('Error occurred when preparing data'); 4258 return; 4259 } 4260 console.info("moving photo acquired successfully, uri: " + movingPhoto.getUri()); 4261 } 4262} 4263 4264async function example() { 4265 let predicates: dataSharePredicates.DataSharePredicates = new dataSharePredicates.DataSharePredicates(); 4266 predicates.equalTo(photoAccessHelper.PhotoKeys.PHOTO_SUBTYPE, photoAccessHelper.PhotoSubtype.MOVING_PHOTO); 4267 let fetchOptions: photoAccessHelper.FetchOptions = { 4268 fetchColumns: [], 4269 predicates: predicates 4270 }; 4271 // Ensure that there are moving photos in Gallery. 4272 let assetResult: photoAccessHelper.FetchResult<photoAccessHelper.PhotoAsset> = await phAccessHelper.getAssets(fetchOptions); 4273 let asset: photoAccessHelper.PhotoAsset = await assetResult.getFirstObject(); 4274 let requestOptions: photoAccessHelper.RequestOptions = { 4275 deliveryMode: photoAccessHelper.DeliveryMode.FAST_MODE, 4276 } 4277 const handler = new MovingPhotoHandler(); 4278 try { 4279 let requestId: string = await photoAccessHelper.MediaAssetManager.requestMovingPhoto(context, asset, requestOptions, handler); 4280 console.info("moving photo requested successfully, requestId: " + requestId); 4281 } catch (err) { 4282 console.error(`failed to request moving photo, error code is ${err.code}, message is ${err.message}`); 4283 } 4284} 4285 4286``` 4287 4288### requestVideoFile<sup>12+</sup> 4289 4290static requestVideoFile(context: Context, asset: PhotoAsset, requestOptions: RequestOptions, fileUri: string, dataHandler: MediaAssetDataHandler<boolean>): Promise<string> 4291 4292Requests a video and saves it to the specified sandbox directory. 4293 4294**System capability**: SystemCapability.FileManagement.PhotoAccessHelper.Core 4295 4296**Required permissions**: ohos.permission.READ_IMAGEVIDEO 4297 4298- When you call this API in Picker mode, you do not need to request the ohos.permission.READ_IMAGEVIDEO permission. For details, see [Obtaining an Image or Video by URI](../../media/medialibrary/photoAccessHelper-photoviewpicker.md#obtaining-an-image-or-video-by-uri). 4299- For the videos saved to the media library by this application, the application can access them without the ohos.permission.READ_IMAGEVIDEO permission. 4300 4301**Parameters** 4302 4303| Name | Type | Mandatory| Description | 4304| -------- |----------------------------------------------------------------------| ---- | ------------------------- | 4305| context | [Context](../apis-ability-kit/js-apis-inner-application-context.md) | Yes | Context of the ability instance.| 4306| asset | [PhotoAsset](#photoasset) | Yes | Image to request.| 4307| requestOptions | [RequestOptions](#requestoptions11) | Yes | Options for requesting the video asset.| 4308| fileUri| string | Yes| URI of the sandbox directory, to which the requested video asset is to be saved.| 4309| dataHandler | [MediaAssetDataHandler](#mediaassetdatahandler11)<boolean> | Yes | Media asset handler. When the requested video is written to the specified directory, a callback is triggered.| 4310 4311**Return value** 4312 4313| Type | Description | 4314| --------------------------------------- | ----------------- | 4315| Promise\<string> | Promise used to return the request ID, which can be used in [cancelRequest](#cancelrequest12) to cancel a request.| 4316 4317**Error codes** 4318 4319For details about the error codes, see [Universal Error Codes](../errorcode-universal.md) and [File Management Error Codes](../apis-core-file-kit/errorcode-filemanagement.md). 4320 4321| ID| Error Message| 4322| -------- | ---------------------------------------- | 4323| 201 | Permission denied | 4324| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types; 3. Parameter verification failed. | 4325| 801<sup>15+</sup> | Capability not supported. | 4326| 14000011 | System inner fail. | 4327 4328**Example** 4329 4330```ts 4331import { dataSharePredicates } from '@kit.ArkData'; 4332class MediaDataHandler implements photoAccessHelper.MediaAssetDataHandler<boolean> { 4333 onDataPrepared(data: boolean) { 4334 console.info('on video request status prepared'); 4335 } 4336} 4337 4338async function example() { 4339 console.info('requestVideoFile'); 4340 let predicates: dataSharePredicates.DataSharePredicates = new dataSharePredicates.DataSharePredicates(); 4341 let fetchOptions: photoAccessHelper.FetchOptions = { 4342 fetchColumns: [], 4343 predicates: predicates 4344 }; 4345 let requestOptions: photoAccessHelper.RequestOptions = { 4346 deliveryMode: photoAccessHelper.DeliveryMode.HIGH_QUALITY_MODE, 4347 } 4348 const handler = new MediaDataHandler(); 4349 let fileUri = 'file://com.example.temptest/data/storage/el2/base/haps/entry/files/test.mp4'; 4350 phAccessHelper.getAssets(fetchOptions, async (err, fetchResult) => { 4351 console.info('fetchResult success'); 4352 let photoAsset: photoAccessHelper.PhotoAsset = await fetchResult.getFirstObject(); 4353 await photoAccessHelper.MediaAssetManager.requestVideoFile(context, photoAsset, requestOptions, fileUri, handler); 4354 console.info('requestVideoFile successfully'); 4355 }); 4356} 4357``` 4358 4359### cancelRequest<sup>12+</sup> 4360 4361static cancelRequest(context: Context, requestId: string): Promise\<void> 4362 4363Cancels a request for the asset, the callback of which has not been triggered yet. 4364 4365**System capability**: SystemCapability.FileManagement.PhotoAccessHelper.Core 4366 4367**Required permissions**: ohos.permission.READ_IMAGEVIDEO 4368 4369**Parameters** 4370 4371| Name | Type | Mandatory| Description | 4372| -------- |----------------------------------------------------------------------| ---- | ------------------------- | 4373| context | [Context](../apis-ability-kit/js-apis-inner-application-context.md) | Yes | Context of the ability instance.| 4374| requestId | string | Yes | ID of the request to cancel.| 4375 4376**Return value** 4377 4378| Type | Description | 4379| --------------------------------------- | ----------------- | 4380| Promise\<void> | Promise that returns no value.| 4381 4382**Error codes** 4383 4384For details about the error codes, see [Universal Error Codes](../errorcode-universal.md) and [File Management Error Codes](../apis-core-file-kit/errorcode-filemanagement.md). 4385 4386| ID| Error Message| 4387| -------- | ---------------------------------------- | 4388| 201 | Permission denied | 4389| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types; 3. Parameter verification failed. | 4390| 14000011 | System inner fail | 4391 4392**Example** 4393 4394```ts 4395import { dataSharePredicates } from '@kit.ArkData'; 4396 4397async function example() { 4398 try { 4399 let requestId: string = 'xxx-xxx'; // A valid requestId returned by APIs such as requestImage() must be used. 4400 await photoAccessHelper.MediaAssetManager.cancelRequest(context, requestId); 4401 console.info("request cancelled successfully"); 4402 } catch (err) { 4403 console.error(`cancelRequest failed with error: ${err.code}, ${err.message}`); 4404 } 4405} 4406 4407``` 4408 4409### loadMovingPhoto<sup>12+</sup> 4410 4411static loadMovingPhoto(context: Context, imageFileUri: string, videoFileUri: string): Promise\<MovingPhoto> 4412 4413Loads a moving photo in the application sandbox. 4414 4415**Atomic service API**: This API can be used in atomic services since API version 14. 4416 4417**System capability**: SystemCapability.FileManagement.PhotoAccessHelper.Core 4418 4419**Parameters** 4420 4421| Name | Type | Mandatory| Description | 4422| -------- |----------------------------------------------------------------------| ---- | ------------------------- | 4423| context | [Context](../apis-ability-kit/js-apis-inner-application-context.md) | Yes | **AbilityContext** or **UIExtensionContext** instance.| 4424| imageFileUri | string | Yes | URI of the image file of the moving photo in the application sandbox.| 4425| videoFileUri | string | Yes | URI of the video file of the moving photo in the application sandbox.| 4426 4427**Return value** 4428 4429| Type | Description | 4430| --------------------------------------- | ----------------- | 4431| Promise\<MovingPhoto> | Promise used to return a [MovingPhoto](#movingphoto12) instance.| 4432 4433**Error codes** 4434 4435For details about the error codes, see [Universal Error Codes](../errorcode-universal.md) and [File Management Error Codes](../apis-core-file-kit/errorcode-filemanagement.md). 4436 4437| ID| Error Message| 4438| -------- | ---------------------------------------- | 4439| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types; 3. Parameter verification failed. | 4440| 14000011 | Internal system error. | 4441 4442**Example** 4443 4444```ts 4445async function example() { 4446 try { 4447 let imageFileUri: string = 'file://com.example.temptest/data/storage/el2/base/haps/ImageFile.jpg'; // URI of the image file of the moving photo in the application sandbox. 4448 let videoFileUri: string = 'file://com.example.temptest/data/storage/el2/base/haps/VideoFile.mp4'; // URI of the video file of the moving photo in the application sandbox. 4449 let movingPhoto: photoAccessHelper.MovingPhoto = await photoAccessHelper.MediaAssetManager.loadMovingPhoto(context, imageFileUri, videoFileUri); 4450 } catch (err) { 4451 console.error(`loadMovingPhoto failed with error: ${err.code}, ${err.message}`); 4452 } 4453} 4454 4455``` 4456 4457### quickRequestImage<sup>13+</sup> 4458 4459static quickRequestImage(context: Context, asset: PhotoAsset, requestOptions: RequestOptions, dataHandler: QuickImageDataHandler<image.Picture>): Promise<string> 4460 4461Requests an image quickly. 4462 4463**System capability**: SystemCapability.FileManagement.PhotoAccessHelper.Core 4464 4465**Required permissions**: ohos.permission.READ_IMAGEVIDEO 4466 4467- When you call this API in Picker mode, you do not need to request the ohos.permission.READ_IMAGEVIDEO permission. For details, see [Obtaining an Image or Video by URI](../../media/medialibrary/photoAccessHelper-photoviewpicker.md#obtaining-an-image-or-video-by-uri). 4468 4469**Parameters** 4470 4471| Name | Type | Mandatory| Description | 4472|----------------|-----------------------------------------------------------------------------------------------------------| ---- | ------------------------- | 4473| context | [Context](../apis-ability-kit/js-apis-inner-application-context.md) | Yes | Context of the ability instance.| 4474| asset | [PhotoAsset](#photoasset) | Yes | Image to request.| 4475| requestOptions | [RequestOptions](#requestoptions11) | Yes | Options for requesting the image.| 4476| dataHandler | [QuickImageDataHandler](#quickimagedatahandler13)<[image.Picture](../apis-image-kit/js-apis-image.md#picture13)> | Yes | Media asset handler, which invokes a callback to return the image when the requested image is ready.| 4477 4478**Return value** 4479 4480| Type | Description | 4481| --------------------------------------- | ----------------- | 4482| Promise\<string> | Promise used to return the request ID, which can be used in [cancelRequest](#cancelrequest12) to cancel a request.| 4483 4484**Error codes** 4485 4486For details about the error codes, see [Universal Error Codes](../errorcode-universal.md) and [File Management Error Codes](../apis-core-file-kit/errorcode-filemanagement.md). 4487 4488| ID| Error Message| 4489| -------- | ---------------------------------------- | 4490| 201 | Permission denied | 4491| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types; 3. Parameter verification failed. | 4492| 14000011 | Internal system error. | 4493 4494**Example** 4495 4496```ts 4497import { photoAccessHelper } from '@kit.MediaLibraryKit'; 4498import { dataSharePredicates } from '@kit.ArkData'; 4499import { image } from '@kit.ImageKit'; 4500 4501class MediaHandler implements photoAccessHelper.QuickImageDataHandler<image.Picture> { 4502 onDataPrepared(data: image.Picture, imageSource: image.ImageSource, map: Map<string, string>) { 4503 console.info('on image data prepared'); 4504 } 4505} 4506 4507async function example() { 4508 console.info('quickRequestImage'); 4509 let predicates: dataSharePredicates.DataSharePredicates = new dataSharePredicates.DataSharePredicates(); 4510 let fetchOptions: photoAccessHelper.FetchOptions = { 4511 fetchColumns: [], 4512 predicates: predicates 4513 }; 4514 let requestOptions: photoAccessHelper.RequestOptions = { 4515 deliveryMode: photoAccessHelper.DeliveryMode.HIGH_QUALITY_MODE, 4516 } 4517 const handler = new MediaHandler(); 4518 let phAccessHelper = photoAccessHelper.getPhotoAccessHelper(context); 4519 phAccessHelper.getAssets(fetchOptions, async (err, fetchResult) => { 4520 console.info('fetchResult success'); 4521 let photoAsset: photoAccessHelper.PhotoAsset = await fetchResult.getFirstObject(); 4522 await photoAccessHelper.MediaAssetManager.quickRequestImage(context, photoAsset, requestOptions, handler); 4523 console.info('quickRequestImage successfully'); 4524 }); 4525} 4526``` 4527 4528## MediaAssetDataHandler<sup>11+</sup> 4529 4530Media asset handler, which can be used to customize the media asset processing logic in **onDataPrepared**. 4531 4532**System capability**: SystemCapability.FileManagement.PhotoAccessHelper.Core 4533 4534### onDataPrepared<sup>11+</sup> 4535 4536onDataPrepared(data: T, map?: Map<string, string>): void 4537 4538Called when the requested media asset is ready. If an error occurs, **data** returned by the callback is **undefined**. Each media asset request corresponds to a callback. 4539T supports the following data types: ArrayBuffer, [ImageSource](../apis-image-kit/js-apis-image.md#imagesource), [MovingPhoto](#movingphoto12), and boolean. ArrayBuffer indicates the image or video asset data, [ImageSource](../apis-image-kit/js-apis-image.md#imagesource) indicates the image source, [MovingPhoto](#movingphoto12) indicates a moving photo object, and boolean indicates whether the image or video is successfully written to the application sandbox directory. 4540 4541Information returned by **map**: 4542| Map Key | **Description**| 4543|----------|-------| 4544| 'quality' | Image quality. The value **high** means high quality, and **low** means poor quality.| 4545 4546**System capability**: SystemCapability.FileManagement.PhotoAccessHelper.Core 4547 4548**Parameters** 4549 4550| Name | Type| Mandatory| Description | 4551|------|---| ---- |-------------------------------------------------------------------------------| 4552| data | T | Yes | Data of the image asset that is ready. The value supports the following types: ArrayBuffer, [ImageSource](../apis-image-kit/js-apis-image.md#imagesource), [MovingPhoto](#movingphoto12), and boolean.| 4553| map<sup>12+</sup> | Map<string, string> | No | Additional information about the image asset, such as the image quality.| 4554 4555**Example** 4556```ts 4557import { image } from '@kit.ImageKit'; 4558 4559class MediaHandler implements photoAccessHelper.MediaAssetDataHandler<image.ImageSource> { 4560 onDataPrepared = (data: image.ImageSource, map: Map<string, string>) => { 4561 if (data === undefined) { 4562 console.error('Error occurred when preparing data'); 4563 return; 4564 } 4565 // Customize the processing logic for ImageSource. 4566 console.info('on image data prepared, photo quality is ' + map['quality']); 4567 } 4568} 4569 4570class MediaDataHandler implements photoAccessHelper.MediaAssetDataHandler<ArrayBuffer> { 4571 onDataPrepared = (data: ArrayBuffer, map: Map<string, string>) => { 4572 if (data === undefined) { 4573 console.error('Error occurred when preparing data'); 4574 return; 4575 } 4576 // Customize the processing logic for ArrayBuffer. 4577 console.info('on image data prepared, photo quality is ' + map['quality']); 4578 } 4579} 4580 4581class MovingPhotoHandler implements photoAccessHelper.MediaAssetDataHandler<photoAccessHelper.MovingPhoto> { 4582 onDataPrepared = (data: photoAccessHelper.MovingPhoto, map: Map<string, string>) => { 4583 if (data === undefined) { 4584 console.error('Error occurred when preparing data'); 4585 return; 4586 } 4587 // Customize the processing logic for MovingPhoto. 4588 console.info('on image data prepared, photo quality is ' + map['quality']); 4589 } 4590} 4591``` 4592 4593## QuickImageDataHandler<sup>13+</sup> 4594 4595Media asset handler, which can be used to customize the media asset processing logic in **onDataPrepared**. 4596 4597**System capability**: SystemCapability.FileManagement.PhotoAccessHelper.Core 4598 4599### onDataPrepared<sup>13+</sup> 4600 4601onDataPrepared(data: T, imageSource: image.ImageSource, map: Map<string, string>): void 4602 4603Called when the requested image is ready. If an error occurs, **data** returned by the callback is **undefined**. 4604**T** supports the Picture data type. 4605 4606Information returned by **map**: 4607| Map Key | **Description**| 4608|----------|-------| 4609| 'quality' | Image quality. The value **high** means high quality, and **low** means poor quality.| 4610 4611**System capability**: SystemCapability.FileManagement.PhotoAccessHelper.Core 4612 4613**Parameters** 4614 4615| Name | Type| Mandatory| Description | 4616|------|---| ---- |-------------------------------------------------------------------------------| 4617| data | T | Yes | Data of the image asset that is ready. It is of the T type, which supports the [Picture](../apis-image-kit/js-apis-image.md#picture13) type.| 4618| imageSource | image.ImageSource | Yes | Data of the image asset that is ready.| 4619| map<sup>13+</sup> | Map<string, string> | Yes | Additional information about the image asset, such as the image quality.| 4620 4621**Example** 4622```ts 4623import { image } from '@kit.ImageKit'; 4624 4625class MediaHandler implements photoAccessHelper.QuickImageDataHandler<image.Picture> { 4626 onDataPrepared(data: image.Picture, imageSource: image.ImageSource, map: Map<string, string>) { 4627 console.info('on image data prepared'); 4628 } 4629} 4630``` 4631 4632## MovingPhoto<sup>12+</sup> 4633 4634Provides APIs for managing a moving photo instance. 4635 4636**Atomic service API**: This API can be used in atomic services since API version 12. 4637 4638**System capability**: SystemCapability.FileManagement.PhotoAccessHelper.Core 4639 4640### getUri<sup>12+</sup> 4641 4642getUri(): string 4643 4644Obtains the URI of this moving photo. 4645 4646**Atomic service API**: This API can be used in atomic services since API version 12. 4647 4648**System capability**: SystemCapability.FileManagement.PhotoAccessHelper.Core 4649 4650**Return value** 4651 4652| Type | Description | 4653| --------------------------------------- | ----------------- | 4654| string | URI of the moving photo obtained.| 4655 4656**Error codes** 4657 4658For details about the error codes, see [Universal Error Codes](../errorcode-universal.md) and [File Management Error Codes](../apis-core-file-kit/errorcode-filemanagement.md). 4659 4660| ID| Error Message| 4661| -------- | ---------------------------------------- | 4662| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types. | 4663| 14000011 | System inner fail. | 4664 4665**Example** 4666 4667```ts 4668import { dataSharePredicates } from '@kit.ArkData'; 4669 4670class MovingPhotoHandler implements photoAccessHelper.MediaAssetDataHandler<photoAccessHelper.MovingPhoto> { 4671 async onDataPrepared(movingPhoto: photoAccessHelper.MovingPhoto) { 4672 if (movingPhoto === undefined) { 4673 console.error('Error occurred when preparing data'); 4674 return; 4675 } 4676 console.info("moving photo acquired successfully, uri: " + movingPhoto.getUri()); 4677 } 4678} 4679 4680async function example() { 4681 let predicates: dataSharePredicates.DataSharePredicates = new dataSharePredicates.DataSharePredicates(); 4682 predicates.equalTo(photoAccessHelper.PhotoKeys.PHOTO_SUBTYPE, photoAccessHelper.PhotoSubtype.MOVING_PHOTO); 4683 let fetchOptions: photoAccessHelper.FetchOptions = { 4684 fetchColumns: [], 4685 predicates: predicates 4686 }; 4687 // Ensure that there are moving photos in Gallery. 4688 let assetResult: photoAccessHelper.FetchResult<photoAccessHelper.PhotoAsset> = await phAccessHelper.getAssets(fetchOptions); 4689 let asset: photoAccessHelper.PhotoAsset = await assetResult.getFirstObject(); 4690 let requestOptions: photoAccessHelper.RequestOptions = { 4691 deliveryMode: photoAccessHelper.DeliveryMode.FAST_MODE, 4692 } 4693 const handler = new MovingPhotoHandler(); 4694 try { 4695 let requestId: string = await photoAccessHelper.MediaAssetManager.requestMovingPhoto(context, asset, requestOptions, handler); 4696 console.info("moving photo requested successfully, requestId: " + requestId); 4697 } catch (err) { 4698 console.error(`failed to request moving photo, error code is ${err.code}, message is ${err.message}`); 4699 } 4700} 4701``` 4702 4703### requestContent<sup>12+</sup> 4704 4705requestContent(imageFileUri: string, videoFileUri: string): Promise\<void> 4706 4707Requests the image data and video data of this moving photo and writes them to the specified URIs, respectively. 4708 4709**Atomic service API**: This API can be used in atomic services since API version 12. 4710 4711**System capability**: SystemCapability.FileManagement.PhotoAccessHelper.Core 4712 4713**Required permissions**: ohos.permission.READ_IMAGEVIDEO 4714 4715- When you call this API in Picker mode, you do not need to request the ohos.permission.READ_IMAGEVIDEO permission. For details, see [Accessing and Managing Moving Photos](../../media/medialibrary/photoAccessHelper-movingphoto.md). 4716- For the moving photos saved to the media library by this application, the application can access them without the ohos.permission.READ_IMAGEVIDEO permission. 4717 4718**Parameters** 4719 4720| Name | Type | Mandatory| Description | 4721| -------- |----------------------------------------------------------------------| ---- | ------------------------- | 4722| imageFileUri | string | Yes | URI to which the image data of the moving photo is to be written.| 4723| videoFileUri | string | Yes | URI to which the video data of the moving photo is to be written.| 4724 4725**Return value** 4726 4727| Type | Description | 4728| --------------------------------------- | ----------------- | 4729| Promise\<void> | Promise that returns no value.| 4730 4731**Error codes** 4732 4733For details about the error codes, see [Universal Error Codes](../errorcode-universal.md) and [File Management Error Codes](../apis-core-file-kit/errorcode-filemanagement.md). 4734 4735| ID| Error Message| 4736| -------- | ---------------------------------------- | 4737| 201 | Permission denied | 4738| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types; 3. Parameter verification failed. | 4739| 14000011 | System inner fail | 4740 4741**Example** 4742 4743```ts 4744import { dataSharePredicates } from '@kit.ArkData'; 4745 4746class MovingPhotoHandler implements photoAccessHelper.MediaAssetDataHandler<photoAccessHelper.MovingPhoto> { 4747 async onDataPrepared(movingPhoto: photoAccessHelper.MovingPhoto) { 4748 if (movingPhoto === undefined) { 4749 console.error('Error occurred when preparing data'); 4750 return; 4751 } 4752 // The URIs must be valid. 4753 let imageFileUri: string = "file://com.example.temptest/data/storage/el2/base/haps/ImageFile.jpg"; 4754 let videoFileUri: string = "file://com.example.temptest/data/storage/el2/base/haps/VideoFile.mp4"; 4755 try { 4756 await movingPhoto.requestContent(imageFileUri, videoFileUri); 4757 console.log("moving photo contents retrieved successfully"); 4758 } catch (err) { 4759 console.error(`failed to retrieve contents of moving photo, error code is ${err.code}, message is ${err.message}`); 4760 } 4761 } 4762} 4763 4764async function example() { 4765 let predicates: dataSharePredicates.DataSharePredicates = new dataSharePredicates.DataSharePredicates(); 4766 predicates.equalTo(photoAccessHelper.PhotoKeys.PHOTO_SUBTYPE, photoAccessHelper.PhotoSubtype.MOVING_PHOTO); 4767 let fetchOptions: photoAccessHelper.FetchOptions = { 4768 fetchColumns: [], 4769 predicates: predicates 4770 }; 4771 // Ensure that there are moving photos in Gallery. 4772 let assetResult: photoAccessHelper.FetchResult<photoAccessHelper.PhotoAsset> = await phAccessHelper.getAssets(fetchOptions); 4773 let asset: photoAccessHelper.PhotoAsset = await assetResult.getFirstObject(); 4774 let requestOptions: photoAccessHelper.RequestOptions = { 4775 deliveryMode: photoAccessHelper.DeliveryMode.FAST_MODE, 4776 } 4777 const handler = new MovingPhotoHandler(); 4778 try { 4779 let requestId: string = await photoAccessHelper.MediaAssetManager.requestMovingPhoto(context, asset, requestOptions, handler); 4780 console.info("moving photo requested successfully, requestId: " + requestId); 4781 } catch (err) { 4782 console.error(`failed to request moving photo, error code is ${err.code}, message is ${err.message}`); 4783 } 4784} 4785``` 4786 4787### requestContent<sup>12+</sup> 4788 4789requestContent(resourceType: ResourceType, fileUri: string): Promise\<void> 4790 4791Requests the moving photo content of the specified resource type and writes it to the specified URI. 4792 4793**Atomic service API**: This API can be used in atomic services since API version 12. 4794 4795**System capability**: SystemCapability.FileManagement.PhotoAccessHelper.Core 4796 4797**Required permissions**: ohos.permission.READ_IMAGEVIDEO 4798 4799- When you call this API in Picker mode, you do not need to request the ohos.permission.READ_IMAGEVIDEO permission. For details, see [Accessing and Managing Moving Photos](../../media/medialibrary/photoAccessHelper-movingphoto.md). 4800- For the moving photos saved to the media library by this application, the application can access them without the ohos.permission.READ_IMAGEVIDEO permission. 4801 4802**Parameters** 4803 4804| Name | Type | Mandatory| Description | 4805| -------- |----------------------------------------------------------------------| ---- | ------------------------- | 4806| resourceType | [ResourceType](#resourcetype11) | Yes | Resource type of the moving photo content to request.| 4807| fileUri | string | Yes |URI to which the moving photo content is to be written.| 4808 4809**Return value** 4810 4811| Type | Description | 4812| --------------------------------------- | ----------------- | 4813| Promise\<void> | Promise that returns no value.| 4814 4815**Error codes** 4816 4817For details about the error codes, see [Universal Error Codes](../errorcode-universal.md) and [File Management Error Codes](../apis-core-file-kit/errorcode-filemanagement.md). 4818 4819| ID| Error Message| 4820| -------- | ---------------------------------------- | 4821| 201 | Permission denied | 4822| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types; 3. Parameter verification failed. | 4823| 14000011 | System inner fail | 4824 4825**Example** 4826 4827```ts 4828import { dataSharePredicates } from '@kit.ArkData'; 4829 4830class MovingPhotoHandler implements photoAccessHelper.MediaAssetDataHandler<photoAccessHelper.MovingPhoto> { 4831 async onDataPrepared(movingPhoto: photoAccessHelper.MovingPhoto) { 4832 if (movingPhoto === undefined) { 4833 console.error('Error occurred when preparing data'); 4834 return; 4835 } 4836 // The URIs must be valid. 4837 let imageFileUri: string = "file://com.example.temptest/data/storage/el2/base/haps/ImageFile.jpg"; 4838 try { 4839 await movingPhoto.requestContent(photoAccessHelper.ResourceType.IMAGE_RESOURCE, imageFileUri); 4840 console.log("moving photo image content retrieved successfully"); 4841 } catch (err) { 4842 console.error(`failed to retrieve image content of moving photo, error code is ${err.code}, message is ${err.message}`); 4843 } 4844 } 4845} 4846 4847async function example() { 4848 let predicates: dataSharePredicates.DataSharePredicates = new dataSharePredicates.DataSharePredicates(); 4849 predicates.equalTo(photoAccessHelper.PhotoKeys.PHOTO_SUBTYPE, photoAccessHelper.PhotoSubtype.MOVING_PHOTO); 4850 let fetchOptions: photoAccessHelper.FetchOptions = { 4851 fetchColumns: [], 4852 predicates: predicates 4853 }; 4854 // Ensure that there are moving photos in Gallery. 4855 let assetResult: photoAccessHelper.FetchResult<photoAccessHelper.PhotoAsset> = await phAccessHelper.getAssets(fetchOptions); 4856 let asset: photoAccessHelper.PhotoAsset = await assetResult.getFirstObject(); 4857 let requestOptions: photoAccessHelper.RequestOptions = { 4858 deliveryMode: photoAccessHelper.DeliveryMode.FAST_MODE, 4859 } 4860 const handler = new MovingPhotoHandler(); 4861 try { 4862 let requestId: string = await photoAccessHelper.MediaAssetManager.requestMovingPhoto(context, asset, requestOptions, handler); 4863 console.info("moving photo requested successfully, requestId: " + requestId); 4864 } catch (err) { 4865 console.error(`failed to request moving photo, error code is ${err.code}, message is ${err.message}`); 4866 } 4867} 4868``` 4869 4870### requestContent<sup>12+</sup> 4871 4872requestContent(resourceType: ResourceType): Promise\<ArrayBuffer> 4873 4874Requests the moving photo content of the specified resource type and returns it in ArrayBuffer format. 4875 4876**Atomic service API**: This API can be used in atomic services since API version 12. 4877 4878**System capability**: SystemCapability.FileManagement.PhotoAccessHelper.Core 4879 4880**Required permissions**: ohos.permission.READ_IMAGEVIDEO 4881 4882- When you call this API in Picker mode, you do not need to request the ohos.permission.READ_IMAGEVIDEO permission. For details, see [Accessing and Managing Moving Photos](../../media/medialibrary/photoAccessHelper-movingphoto.md). 4883- For the moving photos saved to the media library by this application, the application can access them without the ohos.permission.READ_IMAGEVIDEO permission. 4884 4885**Parameters** 4886 4887| Name | Type | Mandatory| Description | 4888| -------- |----------------------------------------------------------------------| ---- | ------------------------- | 4889| resourceType | [ResourceType](#resourcetype11) | Yes | Resource type of the moving photo content to request.| 4890 4891**Return value** 4892 4893| Type | Description | 4894| --------------------------------------- | ----------------- | 4895| Promise\<ArrayBuffer> | Promise used to return the requested content in an ArrayBuffer.| 4896 4897**Error codes** 4898 4899For details about the error codes, see [Universal Error Codes](../errorcode-universal.md) and [File Management Error Codes](../apis-core-file-kit/errorcode-filemanagement.md). 4900 4901| ID| Error Message| 4902| -------- | ---------------------------------------- | 4903| 201 | Permission denied | 4904| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types; 3. Parameter verification failed. | 4905| 14000011 | System inner fail | 4906 4907**Example** 4908 4909```ts 4910import { dataSharePredicates } from '@kit.ArkData'; 4911 4912class MovingPhotoHandler implements photoAccessHelper.MediaAssetDataHandler<photoAccessHelper.MovingPhoto> { 4913 async onDataPrepared(movingPhoto: photoAccessHelper.MovingPhoto) { 4914 if (movingPhoto === undefined) { 4915 console.error('Error occurred when preparing data'); 4916 return; 4917 } 4918 try { 4919 let buffer: ArrayBuffer = await movingPhoto.requestContent(photoAccessHelper.ResourceType.IMAGE_RESOURCE); 4920 console.log("moving photo image content retrieved successfully, buffer length: " + buffer.byteLength); 4921 } catch (err) { 4922 console.error(`failed to retrieve image content of moving photo, error code is ${err.code}, message is ${err.message}`); 4923 } 4924 } 4925} 4926 4927async function example() { 4928 let predicates: dataSharePredicates.DataSharePredicates = new dataSharePredicates.DataSharePredicates(); 4929 predicates.equalTo(photoAccessHelper.PhotoKeys.PHOTO_SUBTYPE, photoAccessHelper.PhotoSubtype.MOVING_PHOTO); 4930 let fetchOptions: photoAccessHelper.FetchOptions = { 4931 fetchColumns: [], 4932 predicates: predicates 4933 }; 4934 // Ensure that there are moving photos in Gallery. 4935 let assetResult: photoAccessHelper.FetchResult<photoAccessHelper.PhotoAsset> = await phAccessHelper.getAssets(fetchOptions); 4936 let asset: photoAccessHelper.PhotoAsset = await assetResult.getFirstObject(); 4937 let requestOptions: photoAccessHelper.RequestOptions = { 4938 deliveryMode: photoAccessHelper.DeliveryMode.FAST_MODE, 4939 } 4940 const handler = new MovingPhotoHandler(); 4941 try { 4942 let requestId: string = await photoAccessHelper.MediaAssetManager.requestMovingPhoto(context, asset, requestOptions, handler); 4943 console.info("moving photo requested successfully, requestId: " + requestId); 4944 } catch (err) { 4945 console.error(`failed to request moving photo, error code is ${err.code}, message is ${err.message}`); 4946 } 4947} 4948``` 4949 4950## MemberType 4951 4952type MemberType = number | string | boolean 4953 4954Defines the types of the **PhotoAsset** members. 4955 4956The member types are the union of the types listed in the following table. 4957 4958**System capability**: SystemCapability.FileManagement.PhotoAccessHelper.Core 4959 4960| Type| Description| 4961| ---- | ---- | 4962| number | The member value is any number.| 4963| string | The member value is any string.| 4964| boolean | The member value is true or false.| 4965 4966## PhotoType 4967 4968Enumerates media file types. 4969 4970**Atomic service API**: This API can be used in atomic services since API version 11. 4971 4972**System capability**: SystemCapability.FileManagement.PhotoAccessHelper.Core 4973 4974| Name | Value| Description| 4975| ----- | ---- | ---- | 4976| IMAGE | 1 | Image.| 4977| VIDEO | 2 | Video.| 4978 4979## PhotoSubtype<sup>12+</sup> 4980 4981Enumerates the [PhotoAsset](#photoasset) types. 4982 4983**Atomic service API**: This API can be used in atomic services since API version 12. 4984 4985**System capability**: SystemCapability.FileManagement.PhotoAccessHelper.Core 4986 4987| Name | Value| Description| 4988| ----- | ---- | ---- | 4989| DEFAULT | 0 | Photo, which is the default type.| 4990| MOVING_PHOTO | 3 | Moving photo.| 4991| BURST | 4 | Burst photo.| 4992 4993## DynamicRangeType<sup>12+</sup> 4994 4995Enumerates the formats for displaying media assets. 4996 4997**System capability**: SystemCapability.FileManagement.PhotoAccessHelper.Core 4998 4999| Name | Value| Description| 5000| ----- | ---- | ---- | 5001| SDR | 0 | Standard dynamic range (SDR).| 5002| HDR | 1 | High dynamic range (HDR). | 5003 5004## AlbumType 5005 5006Enumerates the album types. 5007 5008**System capability**: SystemCapability.FileManagement.PhotoAccessHelper.Core 5009 5010| Name | Value | Description | 5011| ------------------- | ---- | ------------------------- | 5012| USER | 0 | User album. | 5013| SYSTEM | 1024 | System album. | 5014 5015## AlbumSubtype 5016 5017Enumerate the album subtypes. 5018 5019**System capability**: SystemCapability.FileManagement.PhotoAccessHelper.Core 5020 5021| Name | Value | Description | 5022| --------------------------------- | ---------- | ------------------------------- | 5023| USER\_GENERIC | 1 | User album. | 5024| FAVORITE | 1025 | Favorites. | 5025| VIDEO | 1026 | Video album. | 5026| IMAGE<sup>12+</sup> | 1031 | Photo album. | 5027| ANY | 2147483647 | Any album. | 5028 5029## PhotoKeys 5030 5031Defines the key information about an image or video file. 5032 5033**System capability**: SystemCapability.FileManagement.PhotoAccessHelper.Core 5034 5035| Name | Value | Description | 5036| ------------- | ------------------- | ---------------------------------------------------------- | 5037| URI | 'uri' | URI of the file.<br>**NOTE**: Only the [DataSharePredicates.equalTo](../apis-arkdata/js-apis-data-dataSharePredicates.md#equalto10) predicate can be used for this field during photo query. | 5038| PHOTO_TYPE | 'media_type' | Type of the file. | 5039| DISPLAY_NAME | 'display_name' | File name displayed. | 5040| SIZE | 'size' | File size, in bytes. | 5041| DATE_ADDED | 'date_added' | Unix timestamp when the file was created, in seconds. | 5042| DATE_MODIFIED | 'date_modified' | Unix timestamp when the file was modified, in seconds. This value is updated when the file content is modified, but not when the file name is modified.| 5043| DURATION | 'duration' | Duration, in ms. | 5044| WIDTH | 'width' | Image width, in pixels. | 5045| HEIGHT | 'height' | Image height, in pixels. | 5046| DATE_TAKEN | 'date_taken' | Unix timestamp when the image was captured, in seconds. | 5047| ORIENTATION | 'orientation' | Orientation of the file, in degrees. | 5048| FAVORITE | 'is_favorite' | Whether the file is added to favorites. | 5049| TITLE | 'title' | Title in the file. | 5050| DATE_ADDED_MS<sup>12+</sup> | 'date_added_ms' | Unix timestamp when the file was created, in milliseconds.<br>**NOTE**: The photos queried cannot be sorted based on this field. | 5051| DATE_MODIFIED_MS<sup>12+</sup> | 'date_modified_ms' | Unix timestamp when the file was modified, in milliseconds. This value is updated when the file content is modified, but not when the file name is modified.<br>**NOTE**: The photos queried cannot be sorted based on this field.| 5052| PHOTO_SUBTYPE<sup>12+</sup> | 'subtype' | Subtype of the media file. | 5053| DYNAMIC_RANGE_TYPE<sup>12+</sup> | 'dynamic_range_type' | Dynamic range type of the media asset. | 5054| COVER_POSITION<sup>12+</sup> | 'cover_position' | Position of the moving photo cover, which is the video timestamp (in μs) corresponding to the cover frame.| 5055| BURST_KEY<sup>12+</sup> | 'burst_key' | Unique ID of a group of burst photos.| 5056| LCD_SIZE<sup>12+</sup> | 'lcd_size' | Width and height of an LCD image, in the format of a **width:height** string.| 5057| THM_SIZE<sup>12+</sup> | 'thm_size' | Width and height of a thumbnail image, in the format of a **width:height** string.| 5058| DETAIL_TIME<sup>13+</sup> | 'detail_time' | Detailed time. The value is a string of time when the image or video was taken in the time zone and does not change with the time zone.| 5059| DATE_TAKEN_MS<sup>13+</sup> | 'date_taken_ms' | Unix timestamp when the image was captured, in milliseconds.| 5060 5061## AlbumKeys 5062 5063Enumerates the key album attributes. 5064 5065**System capability**: SystemCapability.FileManagement.PhotoAccessHelper.Core 5066 5067| Name | Value | Description | 5068| ------------- | ------------------- | ---------------------------------------------------------- | 5069| URI | 'uri' | URI of the album. | 5070| ALBUM_NAME | 'album_name' | Name of the album. | 5071 5072## CreateOptions 5073 5074Options for creating an image or video asset. 5075 5076The title must meet the following requirements: 5077- It does not contain a file name extension. 5078- The file name cannot exceed 255 characters. 5079- It does not contain any of the following characters:<br> . .. \ / : * ? " ' ` < > | { } [ ] 5080 5081**Atomic service API**: This API can be used in atomic services since API version 11. 5082 5083**System capability**: SystemCapability.FileManagement.PhotoAccessHelper.Core 5084 5085| Name | Type | Mandatory| Description | 5086| ---------------------- | ------------------- | ---- | ------------------------------------------------ | 5087| title | string | No | Title of the image or video. | 5088| subtype<sup>12+</sup> | [PhotoSubtype](#photosubtype12) | No | Subtype of the image or video file.<br>**Atomic service API**: This API can be used in atomic services since API version 12. | 5089 5090 5091## FetchOptions 5092 5093Defines the options for fetching media files. 5094 5095**System capability**: SystemCapability.FileManagement.PhotoAccessHelper.Core 5096 5097| Name | Type | Readable| Writable| Description | 5098| ---------------------- | ------------------- | ---- |---- | ------------------------------------------------ | 5099| fetchColumns | Array<string> | Yes | Yes | Names of the columns specified for query.<br>If this parameter is left blank for photos, photos are fetched by **'uri'**, **'media_type'**, **'subtype'**, and **'display_name'** by default. An error will be thrown if [get](#get) is used to obtain other attributes of this object. <br>Example: **fetchColumns: ['uri', 'title']**.<br>If this parameter is left blank for albums, albums are fetched by **'uri'** and **'album_name'** by default.| 5100| predicates | [dataSharePredicates.DataSharePredicates](../apis-arkdata/js-apis-data-dataSharePredicates.md#datasharepredicates) | Yes | Yes | Predicates that specify the fetch criteria.| 5101 5102## RequestOptions<sup>11+</sup> 5103 5104Represents request options. 5105 5106**System capability**: SystemCapability.FileManagement.PhotoAccessHelper.Core 5107 5108| Name | Type | Read-Only| Optional| Description | 5109| ---------------------- |----------------------------| ---- | ---- | ------------------------------------------- | 5110| deliveryMode | [DeliveryMode](#deliverymode11) | No | No | Delivery mode of the requested asset. The value can be **FAST_MODE**, **HIGH_QUALITY_MODE**, or **BALANCE_MODE**.| 5111| compatibleMode<sup>15+</sup> | [CompatibleMode](#compatiblemode15) | No | Yes | HDR video transcoding policy, which can be **FAST_ORIGINAL_FORMAT_MODE** (maintaining the original HDR format) or **COMPATIBLE_FORMAT_MODE** (converting HDR content to SDR format).| 5112| mediaAssetProgressHandler<sup>15+</sup> | [MediaAssetProgressHandler](#mediaassetprogresshandler15) | No | Yes | Callback used to return the HDR-to-SDR conversion progress.| 5113 5114## MediaChangeRequest<sup>11+</sup> 5115 5116Media change request, which is the parent class of the asset change request and album change request. 5117 5118> **NOTE**<br>**MediaChangeRequest** takes effect only after [applyChanges](#applychanges11) is called. 5119 5120**System capability**: SystemCapability.FileManagement.PhotoAccessHelper.Core 5121 5122## ResourceType<sup>11+</sup> 5123 5124Enumerates the types of the resources to write. 5125 5126**Atomic service API**: This API can be used in atomic services since API version 11. 5127 5128**System capability**: SystemCapability.FileManagement.PhotoAccessHelper.Core 5129 5130| Name | Value| Description| 5131| ----- | ---- | ---- | 5132| IMAGE_RESOURCE | 1 | Image resource.| 5133| VIDEO_RESOURCE | 2 | Video resource.| 5134 5135## ImageFileType<sup>13+</sup> 5136 5137Enumerates the types of image files to save. 5138 5139**System capability**: SystemCapability.FileManagement.PhotoAccessHelper.Core 5140 5141| Name | Value| Description| 5142| ----- | ---- | ---- | 5143| JPEG | 1 | JPEG.| 5144| HEIF | 2 | HEIF.| 5145 5146## ChangeData 5147 5148Defines the return value of the listener callback. 5149 5150**System capability**: SystemCapability.FileManagement.PhotoAccessHelper.Core 5151 5152| Name | Type | Readable| Writable| Description | 5153| ------- | --------------------------- | ---- | ---- | ------------------------------------------------------------ | 5154| type | [NotifyType](#notifytype) | Yes | No | Notification type. | 5155| uris | Array<string> | Yes | No | All URIs with the same [NotifyType](#notifytype), which can be **PhotoAsset** or **Album**.| 5156| extraUris | Array<string> | Yes | No | URIs of the changed files in the album. | 5157 5158## NotifyType 5159 5160Enumerates the notification event types. 5161 5162**System capability**: SystemCapability.FileManagement.PhotoAccessHelper.Core 5163 5164| Name | Value | Description | 5165| ------------------------- | ---- | -------------------------------- | 5166| NOTIFY_ADD | 0 | A file asset or album is added. | 5167| NOTIFY_UPDATE | 1 | A file asset or album is updated. | 5168| NOTIFY_REMOVE | 2 | A file asset or album is removed. | 5169| NOTIFY_ALBUM_ADD_ASSET | 3 | A file asset is added to the album.| 5170| NOTIFY_ALBUM_REMOVE_ASSET | 4 | A file asset is removed from the album.| 5171 5172## DefaultChangeUri 5173 5174Enumerates the **DefaultChangeUri** subtypes. 5175 5176**System capability**: SystemCapability.FileManagement.PhotoAccessHelper.Core 5177 5178| Name | Value | Description | 5179| ----------------- | ----------------------- | ------------------------------------------------------------ | 5180| DEFAULT_PHOTO_URI | 'file://media/Photo' | Default **PhotoAsset** URI, which must be used with **forChildUris{true}** to subscribe to change notifications of all photo assets.| 5181| DEFAULT_ALBUM_URI | 'file://media/PhotoAlbum' | Default album URI, which must be used with **forChildUris{true}** to subscribe to change notifications of all albums.| 5182 5183## PhotoViewMIMETypes 5184 5185Enumerates the media file types that can be selected. 5186 5187**Atomic service API**: This API can be used in atomic services since API version 11. 5188 5189**System capability**: SystemCapability.FileManagement.PhotoAccessHelper.Core 5190 5191| Name | Value| Description | 5192|---------------------------------------| ---- |----------| 5193| IMAGE_TYPE | 'image/*' | Image. | 5194| VIDEO_TYPE | 'video/*' | Video. | 5195| IMAGE_VIDEO_TYPE | '\*/*' | Image and video.| 5196| MOVING_PHOTO_IMAGE_TYPE<sup>12+</sup> | 'image/movingPhoto' | Moving photo.<br>**Atomic service API**: This API can be used in atomic services since API version 12. | 5197 5198## RecommendationType<sup>11+</sup> 5199 5200Enumerates the types of recommended images. 5201 5202**Atomic service API**: This API can be used in atomic services since API version 11. 5203 5204**System capability**: SystemCapability.FileManagement.PhotoAccessHelper.Core 5205 5206| Name | Value| Description| 5207| ----- | ---- | ---- | 5208| QR_OR_BAR_CODE | 1 | QR code or barcode.| 5209| QR_CODE | 2 | QR code.| 5210| BAR_CODE | 3 | Barcode.| 5211| ID_CARD | 4 | ID card.| 5212| PROFILE_PICTURE | 5 | Profile.| 5213| PASSPORT<sup>12+</sup> | 6 | passport.<br>**Atomic service API**: This API can be used in atomic services since API version 12.| 5214| BANK_CARD<sup>12+</sup> | 7 | Bank card.<br>**Atomic service API**: This API can be used in atomic services since API version 12.| 5215| DRIVER_LICENSE<sup>12+</sup> | 8 | Driver license.<br>**Atomic service API**: This API can be used in atomic services since API version 12.| 5216| DRIVING_LICENSE<sup>12+</sup> | 9 | Vehicle license<br>**Atomic service API**: This API can be used in atomic services since API version 12.| 5217| FEATURED_SINGLE_PORTRAIT<sup>12+</sup> | 10 | Recommended portrait.<br>**Atomic service API**: This API can be used in atomic services since API version 12.| 5218 5219**Example** 5220 5221```ts 5222import { BusinessError } from '@kit.BasicServicesKit'; 5223async function example() { 5224 try { 5225 let recommendOptions: photoAccessHelper.RecommendationOptions = { 5226 recommendationType: photoAccessHelper.RecommendationType.ID_CARD 5227 } 5228 let options: photoAccessHelper.PhotoSelectOptions = { 5229 MIMEType: photoAccessHelper.PhotoViewMIMETypes.IMAGE_TYPE, 5230 maxSelectNumber: 1, 5231 recommendationOptions: recommendOptions 5232 } 5233 let photoPicker = new photoAccessHelper.PhotoViewPicker(); 5234 photoPicker.select(options).then((PhotoSelectResult: photoAccessHelper.PhotoSelectResult) => { 5235 console.info('PhotoViewPicker.select successfully, PhotoSelectResult uri: ' + JSON.stringify(PhotoSelectResult)); 5236 }).catch((err: BusinessError) => { 5237 console.error(`PhotoViewPicker.select failed with err: ${err.code}, ${err.message}`); 5238 }); 5239 } catch (error) { 5240 let err: BusinessError = error as BusinessError; 5241 console.error(`PhotoViewPicker failed with err: ${err.code}, ${err.message}`); 5242 } 5243} 5244``` 5245 5246## TextContextInfo<sup>12+</sup> 5247 5248Represents the text information about the recommended images. 5249 5250**Atomic service API**: This API can be used in atomic services since API version 12. 5251 5252**System capability**: SystemCapability.FileManagement.PhotoAccessHelper.Core 5253 5254| Name | Type | Mandatory| Description | 5255| ----------------------- | ------------------- | ---- | -------------------------------- | 5256| text | string | No | Text based on which images are recommended. The text cannot exceed 250 characters.| 5257 5258**Example** 5259 5260```ts 5261import { BusinessError } from '@kit.BasicServicesKit'; 5262async function example() { 5263 try { 5264 let textInfo: photoAccessHelper.TextContextInfo = { 5265 text: 'Pandas at Shanghai Wild Zoo' 5266 } 5267 let recommendOptions: photoAccessHelper.RecommendationOptions = { 5268 textContextInfo: textInfo 5269 } 5270 let options: photoAccessHelper.PhotoSelectOptions = { 5271 MIMEType: photoAccessHelper.PhotoViewMIMETypes.IMAGE_TYPE, 5272 maxSelectNumber: 1, 5273 recommendationOptions: recommendOptions 5274 } 5275 let photoPicker = new photoAccessHelper.PhotoViewPicker(); 5276 photoPicker.select(options).then((PhotoSelectResult: photoAccessHelper.PhotoSelectResult) => { 5277 console.info('PhotoViewPicker.select successfully, PhotoSelectResult uri: ' + JSON.stringify(PhotoSelectResult)); 5278 }).catch((err: BusinessError) => { 5279 console.error(`PhotoViewPicker.select failed with err: ${err.code}, ${err.message}`); 5280 }); 5281 } catch (error) { 5282 let err: BusinessError = error as BusinessError; 5283 console.error(`PhotoViewPicker failed with err: ${err.code}, ${err.message}`); 5284 } 5285} 5286``` 5287 5288## RecommendationOptions<sup>11+</sup> 5289 5290Defines the image recommendation options. The image recommendation feature depends on the image data analysis capability, which varies with devices. 5291 5292**Atomic service API**: This API can be used in atomic services since API version 11. 5293 5294**System capability**: SystemCapability.FileManagement.PhotoAccessHelper.Core 5295 5296| Name | Type | Mandatory| Description | 5297| ----------------------- | ------------------- | ---- | -------------------------------- | 5298| recommendationType | [RecommendationType](#recommendationtype11) | No | Type of the recommended image.| 5299| textContextInfo<sup>12+</sup> | [TextContextInfo](#textcontextinfo12) | No | Text based on which images are recommended. If both **recommendationType** and **textContextInfo** are set, **textContextInfo** takes precedence over **recommendationType**.<br>**Atomic service API**: This API can be used in atomic services since API version 12.| 5300 5301## BaseSelectOptions<sup>12+</sup> 5302 5303Defines the basic options for selecting media assets from Gallery. 5304 5305**System capability**: SystemCapability.FileManagement.PhotoAccessHelper.Core 5306 5307| Name | Type | Mandatory| Description | 5308| ----------------------- | ------------------- | ---- | -------------------------------- | 5309| MIMEType<sup>10+</sup> | [PhotoViewMIMETypes](#photoviewmimetypes) | No | Available media file types. **IMAGE_VIDEO_TYPE** is used by default.<br>**Atomic service API**: This API can be used in atomic services since API version 11.| 5310| maxSelectNumber<sup>10+</sup> | number | No | Maximum number of media files that can be selected.<br>Maximum value: **500**<br>Default value: **50**<br>**Atomic service API**: This API can be used in atomic services since API version 11. | 5311| isPhotoTakingSupported<sup>11+</sup> | boolean | No | Whether photo taking is supported.<br>The value **true** means photo taking is supported; the value **false** means the opposite.<br>**Atomic service API**: This API can be used in atomic services since API version 11.| 5312| isSearchSupported<sup>11+</sup> | boolean | No | Whether the image is searchable.<br>The value **true** means the image is searchable; the value **false** means the opposite.<br>**Atomic service API**: This API can be used in atomic services since API version 11.| 5313| recommendationOptions<sup>11+</sup> | [RecommendationOptions](#recommendationoptions11) | No | Image recommendation parameters.<br>**Atomic service API**: This API can be used in atomic services since API version 11.| 5314| preselectedUris<sup>11+</sup> | Array<string> | No | URI of the preselected image.<br>**Atomic service API**: This API can be used in atomic services since API version 11.| 5315| isPreviewForSingleSelectionSupported<sup>12+</sup> | boolean | No | Whether to enable full image preview if a single image is selected.<br>The value **true** means to enable full image preview; the value **false** means the opposite.<br>Default value: **true**<br>**Atomic service API**: This API can be used in atomic services since API version 12.| 5316 5317## PhotoSelectOptions 5318 5319Defines additional options for selecting media assets from Gallery. It inherits from **BaseSelectOptions**. 5320 5321**Atomic service API**: This API can be used in atomic services since API version 11. 5322 5323**System capability**: SystemCapability.FileManagement.PhotoAccessHelper.Core 5324 5325| Name | Type | Mandatory| Description | 5326| ----------------------- | ------------------- | ---- | -------------------------------- | 5327| isEditSupported<sup>11+</sup> | boolean | No | Whether the image can be edited.<br>The value **true** means the image can be edited; the value **false** means the opposite. | 5328| isOriginalSupported<sup>12+</sup> | boolean | No | Whether to display the button for selecting the original image. <br>The value **true** means to display the button; the value **false** means the opposite.<br>Default value: **false**<br>**Atomic service API**: This API can be used in atomic services since API version 12. | 5329| subWindowName<sup>12+</sup> | string | No | Name of the sub-window.<br>**Atomic service API**: This API can be used in atomic services since API version 12. | 5330| completeButtonText<sup>14+</sup> | [CompleteButtonText](#completebuttontext14) | No | Text displayed on the complete button.<br>The complete button is located in the lower right corner of the page. It is used by users to signify that they have finished selecting images.<br>**Atomic service API**: This API can be used in atomic services since API version 14. | 5331 5332## PhotoSelectResult 5333 5334Defines information about the images or videos selected. 5335 5336**Atomic service API**: This API can be used in atomic services since API version 11. 5337 5338**System capability**: SystemCapability.FileManagement.PhotoAccessHelper.Core 5339 5340| Name | Type | Readable| Writable| Description | 5341| ----------------------- | ------------------- | ---- | ---- | ------------------------------ | 5342| photoUris | Array<string> | Yes | Yes | URIs of the images or videos selected. The URI array can be used only by calling [photoAccessHelper.getAssets](#getassets) with temporary authorization. For details about how to use the media file URI, see [Using a Media File URI](../../file-management/user-file-uri-intro.md#using-a-media-file-uri).| 5343| isOriginalPhoto | boolean | Yes | Yes | Whether the selected media asset is the original image.| 5344 5345 5346## DeliveryMode<sup>11+</sup> 5347 5348Enumerates the asset delivery modes. 5349 5350**System capability**: SystemCapability.FileManagement.PhotoAccessHelper.Core 5351 5352| Name | Value| Description| 5353| ----- | ---- | ---- | 5354| FAST_MODE | 0 | Fast mode.| 5355| HIGH_QUALITY_MODE | 1 | High-quality mode.| 5356| BALANCE_MODE | 2 | Balance mode.| 5357 5358## PhotoCreationConfig<sup>12+</sup> 5359 5360Represents the configuration for saving a media asset (image or video) to the media library, including the file name. 5361 5362**Atomic service API**: This API can be used in atomic services since API version 12. 5363 5364**System capability**: SystemCapability.FileManagement.PhotoAccessHelper.Core 5365 5366| Name | Type | Mandatory| Description | 5367| ---------------------- | ------------------- | ---- | ------------------------------------------------ | 5368| title | string | No | Title of the image or video.| 5369| fileNameExtension | string | Yes | File name extension, for example, **'jpg'**.| 5370| photoType | [PhotoType](#phototype) | Yes | Type of the file to create, which can be **IMAGE** or **VIDEO**.| 5371| subtype | [PhotoSubtype](#photosubtype12) | No | Image or video file subtype. Currently, only **DEFAULT** is supported.| 5372 5373## CompatibleMode<sup>15+</sup> 5374 5375Enumerates the video transcoding mode. 5376 5377**System capability**: SystemCapability.FileManagement.PhotoAccessHelper.Core 5378 5379| Name | Value| Description| 5380| ----- | ---- | ---- | 5381| ORIGINAL_FORMAT_MODE | 0 | Maintains the original video format. | 5382| COMPATIBLE_FORMAT_MODE | 1 | Converts the HDR content to SDR format. | 5383 5384## CompleteButtonText<sup>14+</sup> 5385 5386Enumerates the text displayed on the complete button. 5387 5388**System capability**: SystemCapability.FileManagement.PhotoAccessHelper.Core 5389 5390| Name | Value| Description| 5391| ----- | ---- | ---- | 5392| TEXT_DONE<sup>14+</sup> | 0 | The text "Done" is displayed.<br>**Atomic service API**: This API can be used in atomic services since API version 14.| 5393| TEXT_SEND<sup>14+</sup> | 1 | The text "Send" is displayed.<br>**Atomic service API**: This API can be used in atomic services since API version 14.| 5394| TEXT_ADD<sup>14+</sup> | 2 | The text "Add" is displayed.<br>**Atomic service API**: This API can be used in atomic services since API version 14. | 5395 5396## MediaAssetProgressHandler<sup>15+</sup> 5397 5398Represents the media asset progress handler, which is used to obtain the media asset processing progress from **onProgress()**. 5399 5400**System capability**: SystemCapability.FileManagement.PhotoAccessHelper.Core 5401 5402### onProgress<sup>15+</sup> 5403 5404onProgress(progress: number): void 5405 5406Called when the progress of the requested video is returned. 5407 5408**System capability**: SystemCapability.FileManagement.PhotoAccessHelper.Core 5409 5410**Parameters** 5411 5412| Name | Type | Mandatory| Description | 5413| ------- | ------- | ---- | -------------------------- | 5414| progress | number | Yes | Progress in percentage. <br>Value range: 0 to 100| 5415