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