1# @ohos.file.photoAccessHelper (相册管理模块)(系统接口) 2<!--Kit: Media Library Kit--> 3<!--Subsystem: Multimedia--> 4<!--Owner: @yixiaoff--> 5<!--Designer: @liweilu1--> 6<!--Tester: @xchaosioda--> 7<!--Adviser: @zengyawen--> 8 9该模块提供相册管理模块能力,包括创建相册以及访问、修改相册中的媒体数据信息等。 10 11> **说明:** 12> 13> - 本模块首批接口从API version 10开始支持。后续版本的新增接口,采用上角标单独标记接口的起始版本。 14> - 当前页面仅包含本模块的系统接口,其他公开接口参见[@ohos.file.photoAccessHelper (相册管理模块)](arkts-apis-photoAccessHelper.md)。 15 16## 导入模块 17 18```ts 19import { photoAccessHelper } from '@kit.MediaLibraryKit'; 20``` 21## photoAccessHelper.getPhotoAccessHelper<sup>19+</sup> 22 23getPhotoAccessHelper(context: Context, userId: number): PhotoAccessHelper 24 25支持跨用户获取相册管理模块的实例,用于访问和修改相册中的媒体文件。 26 27**模型约束**:此接口仅可在Stage模型下使用。 28 29**系统接口**:此接口为系统接口。 30 31**系统能力**:SystemCapability.FileManagement.PhotoAccessHelper.Core 32 33**参数:** 34 35| 参数名 | 类型 | 必填 | 说明 | 36| ------- | ------- | ---- | -------------------------- | 37| context | [Context](../apis-ability-kit/js-apis-inner-application-context.md) | 是 | 传入Ability实例的上下文。 | 38| userId | number | 是 | 传入待访问用户的id。 | 39 40**返回值:** 41 42| 类型 | 说明 | 43| ----------------------------- | :---- | 44| [PhotoAccessHelper](#photoaccesshelper) | 相册管理模块的实例。 | 45 46**错误码:** 47 48接口抛出错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)。 49 50| 错误码ID | 错误信息 | 51| -------- | ---------------------------------------- | 52| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types; 3. Parameter verification failed. | 53 54**示例:** 55 56```ts 57// 此处获取的phAccessHelper实例为全局对象,后续使用到phAccessHelper的地方默认为使用此处获取的对象,如未添加此段代码报phAccessHelper未定义的错误请自行添加。 58// 请在组件内获取context,确保this.getUiContext().getHostContext()返回结果为UIAbilityContext 59import { common } from '@kit.AbilityKit'; 60 61@Entry 62@Component 63struct Index { 64 build() { 65 Row() { 66 Button("example").onClick(async () => { 67 let context: Context = this.getUIContext().getHostContext() as common.UIAbilityContext; 68 // 此处101表示其他用户空间的userid 69 let phAccessHelper = photoAccessHelper.getPhotoAccessHelper(context, 101); 70 }).width('100%') 71 } 72 .height('90%') 73 } 74} 75``` 76 77## PhotoAccessHelper 78 79### createAsset 80 81createAsset(displayName: string, callback: AsyncCallback<PhotoAsset>): void 82 83指定待创建的图片或者视频的文件名,创建图片或视频资源,使用callback方式返回结果。 84 85待创建的文件名参数规格为: 86- 应包含有效文件主名和图片或视频扩展名。 87- 文件名字符串长度为1~255。 88- 文件主名中不允许出现的非法英文字符。<br>API18开始,非法字符包括: \ / : * ? " < > | <br>API10-17,非法字符包括:. .. \ / : * ? " ' ` < > | { } [ ] 89 90**系统接口**:此接口为系统接口。 91 92**系统能力**:SystemCapability.FileManagement.PhotoAccessHelper.Core 93 94**需要权限**:ohos.permission.WRITE_IMAGEVIDEO 95 96**参数:** 97 98| 参数名 | 类型 | 必填 | 说明 | 99| -------- | ------------------------ | ---- | ------------------------- | 100| displayName | string | 是 | 创建的图片或者视频文件名。 | 101| callback | AsyncCallback<[PhotoAsset](#photoasset)> | 是 | callback返回创建的图片和视频结果。 | 102 103**错误码:** 104 105接口抛出错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)和[文件管理错误码](../apis-core-file-kit/errorcode-filemanagement.md)。 106 107错误码14000001,请参考 [PhotoKeys](#photokeys)获取有关文件名的格式和长度要求。 108 109错误码13900012,请参考[开发准备](../../media/medialibrary/photoAccessHelper-preparation.md)。 110 111| 错误码ID | 错误信息 | 112| -------- | ---------------------------------------- | 113| 202 | Called by non-system application. | 114| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types; 3. Parameter verification failed. | 115| 13900012 | Permission denied. | 116| 13900020 | Invalid argument. | 117| 14000001 | Invalid display name. | 118| 14000011 | System inner fail. | 119 120**示例:** 121 122phAccessHelper的创建请参考[@ohos.file.photoAccessHelper (相册管理模块)](arkts-apis-photoAccessHelper-f.md)的示例使用。 123 124```ts 125async function example(phAccessHelper: photoAccessHelper.PhotoAccessHelper) { 126 console.info('createAssetDemo'); 127 let testFileName: string = 'testFile' + Date.now() + '.jpg'; 128 phAccessHelper.createAsset(testFileName, (err, photoAsset) => { 129 if (photoAsset !== undefined) { 130 console.info('createAsset file displayName' + photoAsset.displayName); 131 console.info('createAsset successfully'); 132 } else { 133 console.error(`createAsset failed, error: ${err.code}, ${err.message}`); 134 } 135 }); 136} 137``` 138 139### createAsset 140 141createAsset(displayName: string): Promise<PhotoAsset> 142 143指定待创建的图片或者视频的文件名,创建图片或视频资源,使用Promise方式返回结果。 144 145待创建的文件名参数规格为: 146- 应包含有效文件主名和图片或视频扩展名。 147- 文件名字符串长度为1~255。 148- 文件主名中不允许出现的非法英文字符。<br>API18开始,非法字符包括: \ / : * ? " < > | <br>API10-17,非法字符包括:. .. \ / : * ? " ' ` < > | { } [ ] 149 150**系统接口**:此接口为系统接口。 151 152**系统能力**:SystemCapability.FileManagement.PhotoAccessHelper.Core 153 154**需要权限**:ohos.permission.WRITE_IMAGEVIDEO 155 156**参数:** 157 158| 参数名 | 类型 | 必填 | 说明 | 159| -------- | ------------------------ | ---- | ------------------------- | 160| displayName | string | 是 | 创建的图片或者视频文件名。 | 161 162**返回值:** 163 164| 类型 | 说明 | 165| --------------------------- | -------------- | 166| Promise<[PhotoAsset](#photoasset)> | Promise对象,返回创建的图片和视频结果。 | 167 168**错误码:** 169 170接口抛出错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)和[文件管理错误码](../apis-core-file-kit/errorcode-filemanagement.md)。 171 172错误码14000001,请参考 [PhotoKeys](#photokeys)获取有关文件名的格式和长度要求。 173 174错误码13900012,请参考[开发准备](../../media/medialibrary/photoAccessHelper-preparation.md)。 175 176| 错误码ID | 错误信息 | 177| -------- | ---------------------------------------- | 178| 202 | Called by non-system application. | 179| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types; 3. Parameter verification failed. | 180| 13900012 | Permission denied. | 181| 13900020 | Invalid argument. | 182| 14000001 | Invalid display name. | 183| 14000011 | System inner fail. | 184 185**示例:** 186 187phAccessHelper的创建请参考[@ohos.file.photoAccessHelper (相册管理模块)](arkts-apis-photoAccessHelper-f.md)的示例使用。 188 189```ts 190async function example(phAccessHelper: photoAccessHelper.PhotoAccessHelper) { 191 console.info('createAssetDemo'); 192 try { 193 let testFileName: string = 'testFile' + Date.now() + '.jpg'; 194 let photoAsset: photoAccessHelper.PhotoAsset = await phAccessHelper.createAsset(testFileName); 195 console.info('createAsset file displayName' + photoAsset.displayName); 196 console.info('createAsset successfully'); 197 } catch (err) { 198 console.error(`createAsset failed, error: ${err.code}, ${err.message}`); 199 } 200} 201``` 202 203### createAsset 204 205createAsset(displayName: string, options: PhotoCreateOptions, callback: AsyncCallback<PhotoAsset>): void 206 207指定待创建的图片或者视频的文件名和创建选项,创建图片或视频资源,使用callback方式返回结果。 208 209待创建的文件名参数规格为: 210- 应包含有效文件主名和图片或视频扩展名。 211- 文件名字符串长度为1~255。 212- 文件主名中不允许出现的非法英文字符。<br>API18开始,非法字符包括: \ / : * ? " < > | <br>API10-17,非法字符包括:. .. \ / : * ? " ' ` < > | { } [ ] 213 214**系统接口**:此接口为系统接口。 215 216**系统能力**:SystemCapability.FileManagement.PhotoAccessHelper.Core 217 218**需要权限**:ohos.permission.WRITE_IMAGEVIDEO 219 220**参数:** 221 222| 参数名 | 类型 | 必填 | 说明 | 223| -------- | ------------------------ | ---- | ------------------------- | 224| displayName | string | 是 | 创建的图片或者视频文件名。 | 225| options | [PhotoCreateOptions](#photocreateoptions) | 是 | 图片或视频的创建选项。 | 226| callback | AsyncCallback<[PhotoAsset](#photoasset)> | 是 | callback返回创建的图片和视频结果。 | 227 228**错误码:** 229 230接口抛出错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)和[文件管理错误码](../apis-core-file-kit/errorcode-filemanagement.md)。 231 232错误码14000001,请参考 [PhotoKeys](#photokeys)获取有关文件名的格式和长度要求。 233 234错误码13900012,请参考[开发准备](../../media/medialibrary/photoAccessHelper-preparation.md)。 235 236| 错误码ID | 错误信息 | 237| -------- | ---------------------------------------- | 238| 202 | Called by non-system application. | 239| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types; 3. Parameter verification failed. | 240| 13900012 | Permission denied. | 241| 13900020 | Invalid argument. | 242| 14000001 | Invalid display name. | 243| 14000011 | System inner fail. | 244 245**示例:** 246 247phAccessHelper的创建请参考[@ohos.file.photoAccessHelper (相册管理模块)](arkts-apis-photoAccessHelper-f.md)的示例使用。 248 249```ts 250async function example(phAccessHelper: photoAccessHelper.PhotoAccessHelper) { 251 console.info('createAssetDemo'); 252 let testFileName: string = 'testFile' + Date.now() + '.jpg'; 253 let createOption: photoAccessHelper.PhotoCreateOptions = { 254 subtype: photoAccessHelper.PhotoSubtype.DEFAULT 255 } 256 phAccessHelper.createAsset(testFileName, createOption, (err, photoAsset) => { 257 if (photoAsset !== undefined) { 258 console.info('createAsset file displayName' + photoAsset.displayName); 259 console.info('createAsset successfully'); 260 } else { 261 console.error(`createAsset failed, error: ${err.code}, ${err.message}`); 262 } 263 }); 264} 265``` 266 267### createAsset 268 269createAsset(displayName: string, options: PhotoCreateOptions): Promise<PhotoAsset> 270 271指定待创建的图片或者视频的文件名和创建选项,创建图片或视频资源,使用Promise方式返回结果。 272 273待创建的文件名参数规格为: 274- 应包含有效文件主名和图片或视频扩展名。 275- 文件名字符串长度为1~255。 276- 文件主名中不允许出现的非法英文字符。<br>API18开始,非法字符包括: \ / : * ? " < > | <br>API10-17,非法字符包括:. .. \ / : * ? " ' ` < > | { } [ ] 277 278**系统接口**:此接口为系统接口。 279 280**系统能力**:SystemCapability.FileManagement.PhotoAccessHelper.Core 281 282**需要权限**:ohos.permission.WRITE_IMAGEVIDEO 283 284**参数:** 285 286| 参数名 | 类型 | 必填 | 说明 | 287| -------- | ------------------------ | ---- | ------------------------- | 288| displayName | string | 是 | 创建的图片或者视频文件名。 | 289| options | [PhotoCreateOptions](#photocreateoptions) | 是 | 图片或视频的创建选项。 | 290 291**返回值:** 292 293| 类型 | 说明 | 294| --------------------------- | -------------- | 295| Promise<[PhotoAsset](#photoasset)> | Promise对象,返回创建的图片和视频结果。 | 296 297**错误码:** 298 299接口抛出错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)和[文件管理错误码](../apis-core-file-kit/errorcode-filemanagement.md)。 300 301错误码14000001,请参考 [PhotoKeys](#photokeys)获取有关文件名的格式和长度要求。 302 303错误码13900012,请参考[开发准备](../../media/medialibrary/photoAccessHelper-preparation.md)。 304 305| 错误码ID | 错误信息 | 306| -------- | ---------------------------------------- | 307| 202 | Called by non-system application. | 308| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types; 3. Parameter verification failed. | 309| 13900012 | Permission denied. | 310| 13900020 | Invalid argument. | 311| 14000001 | Invalid display name. | 312| 14000011 | System inner fail. | 313 314**示例:** 315 316phAccessHelper的创建请参考[@ohos.file.photoAccessHelper (相册管理模块)](arkts-apis-photoAccessHelper-f.md)的示例使用。 317 318```ts 319async function example(phAccessHelper: photoAccessHelper.PhotoAccessHelper) { 320 console.info('createAssetDemo'); 321 try { 322 let testFileName:string = 'testFile' + Date.now() + '.jpg'; 323 let createOption: photoAccessHelper.PhotoCreateOptions = { 324 subtype: photoAccessHelper.PhotoSubtype.DEFAULT 325 } 326 let photoAsset: photoAccessHelper.PhotoAsset = await phAccessHelper.createAsset(testFileName, createOption); 327 console.info('createAsset file displayName' + photoAsset.displayName); 328 console.info('createAsset successfully'); 329 } catch (err) { 330 console.error(`createAsset failed, error: ${err.code}, ${err.message}`); 331 } 332} 333``` 334 335### createAlbum<sup>(deprecated)</sup> 336 337createAlbum(name: string, callback: AsyncCallback<Album>): void 338 339创建相册,使用callback方式返回结果。 340 341待创建的相册名参数规格为: 342- 相册名字符串长度为1~255。 343- 不允许出现的非法英文字符,包括:<br> . .. \ / : * ? " ' ` < > | { } [ ] 344- 相册名不允许重名。 345 346> **说明:** 347> 348> 从API version 10开始支持,从API version 11开始废弃。建议使用[MediaAlbumChangeRequest.createAlbumRequest](#createalbumrequest11)替代。 349 350**系统接口**:此接口为系统接口。 351 352**系统能力**:SystemCapability.FileManagement.PhotoAccessHelper.Core 353 354**需要权限**:ohos.permission.WRITE_IMAGEVIDEO 355 356**参数:** 357 358| 参数名 | 类型 | 必填 | 说明 | 359| -------- | ------------------------ | ---- | ------------------------- | 360| name | string | 是 | 待创建相册的相册名。 | 361| callback | AsyncCallback<[Album](#album)> | 是 | callback返回创建的相册实例。 | 362 363**错误码:** 364 365接口抛出错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)和[文件管理错误码](../apis-core-file-kit/errorcode-filemanagement.md)。 366 367错误码13900012,请参考[开发准备](../../media/medialibrary/photoAccessHelper-preparation.md)。 368 369| 错误码ID | 错误信息 | 370| -------- | ---------------------------------------- | 371| 202 | Called by non-system application. | 372| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types; 3. Parameter verification failed. | 373| 13900012 | Permission denied. | 374| 13900015 | The file name already exists. | 375| 13900020 | Invalid argument. | 376| 14000011 | System inner fail. | 377 378**示例:** 379 380phAccessHelper的创建请参考[@ohos.file.photoAccessHelper (相册管理模块)](arkts-apis-photoAccessHelper-f.md)的示例使用。 381 382```ts 383async function example(phAccessHelper: photoAccessHelper.PhotoAccessHelper) { 384 console.info('createAlbumDemo'); 385 let albumName: string = 'newAlbumName' + new Date().getTime(); 386 phAccessHelper.createAlbum(albumName, (err, album) => { 387 if (err) { 388 console.error(`createAlbumCallback failed with err: ${err.code}, ${err.message}`); 389 return; 390 } 391 console.info('createAlbumCallback successfully, album: ' + album.albumName + ' album uri: ' + album.albumUri); 392 }); 393} 394``` 395 396### createAlbum<sup>(deprecated)</sup> 397 398createAlbum(name: string): Promise<Album> 399 400创建相册,使用Promise方式返回结果。 401 402待创建的相册名参数规格为: 403- 相册名字符串长度为1~255。 404- 不允许出现的非法英文字符,包括:<br> . .. \ / : * ? " ' ` < > | { } [ ] 405- 相册名不允许重名。 406 407> **说明:** 408> 409> 从API version 10开始支持,从API version 11开始废弃。建议使用[MediaAlbumChangeRequest.createAlbumRequest](#createalbumrequest11)替代。 410 411**系统接口**:此接口为系统接口。 412 413**系统能力**:SystemCapability.FileManagement.PhotoAccessHelper.Core 414 415**需要权限**:ohos.permission.WRITE_IMAGEVIDEO 416 417**参数:** 418 419| 参数名 | 类型 | 必填 | 说明 | 420| -------- | ------------------------ | ---- | ------------------------- | 421| name | string | 是 | 待创建相册的相册名。 | 422 423**返回值:** 424 425| 类型 | 说明 | 426| --------------------------- | -------------- | 427| Promise<[Album](#album)> | Promise对象,返回创建的相册实例。 | 428 429**错误码:** 430 431接口抛出错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)和[文件管理错误码](../apis-core-file-kit/errorcode-filemanagement.md)。 432 433错误码13900012,请参考[开发准备](../../media/medialibrary/photoAccessHelper-preparation.md)。 434 435| 错误码ID | 错误信息 | 436| -------- | ---------------------------------------- | 437| 202 | Called by non-system application. | 438| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types; 3. Parameter verification failed. | 439| 13900012 | Permission denied. | 440| 13900015 | The file name already exists. | 441| 13900020 | Invalid argument. | 442| 14000011 | System inner fail. | 443 444**示例:** 445 446phAccessHelper的创建请参考[@ohos.file.photoAccessHelper (相册管理模块)](arkts-apis-photoAccessHelper-f.md)的示例使用。 447 448```ts 449import { BusinessError } from '@kit.BasicServicesKit'; 450 451async function example(phAccessHelper: photoAccessHelper.PhotoAccessHelper) { 452 console.info('createAlbumDemo'); 453 let albumName: string = 'newAlbumName' + new Date().getTime(); 454 phAccessHelper.createAlbum(albumName).then((album) => { 455 console.info('createAlbumPromise successfully, album: ' + album.albumName + ' album uri: ' + album.albumUri); 456 }).catch((err: BusinessError) => { 457 console.error(`createAlbumPromise failed with err: ${err.code}, ${err.message}`); 458 }); 459} 460``` 461 462### deleteAlbums<sup>(deprecated)</sup> 463 464deleteAlbums(albums: Array<Album>, callback: AsyncCallback<void>): void 465 466删除相册,使用callback方式返回结果。 467 468删除相册前需先确保相册存在,只能删除用户相册。 469 470> **说明:** 471> 472> 从API version 10开始支持,从API version 11开始废弃。建议使用[MediaAlbumChangeRequest.deleteAlbums](#deletealbums11)替代。 473 474**系统接口**:此接口为系统接口。 475 476**系统能力**:SystemCapability.FileManagement.PhotoAccessHelper.Core 477 478**需要权限**:ohos.permission.WRITE_IMAGEVIDEO 479 480**参数:** 481 482| 参数名 | 类型 | 必填 | 说明 | 483| -------- | ------------------------ | ---- | ------------------------- | 484| albums | Array<[Album](#album)> | 是 | 待删除相册的数组。 | 485| callback | AsyncCallback<void> | 是 | callback返回void。 | 486 487**错误码:** 488 489接口抛出错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)和[文件管理错误码](../apis-core-file-kit/errorcode-filemanagement.md)。 490 491错误码13900012,请参考[开发准备](../../media/medialibrary/photoAccessHelper-preparation.md)。 492 493| 错误码ID | 错误信息 | 494| -------- | ---------------------------------------- | 495| 202 | Called by non-system application. | 496| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types; 3. Parameter verification failed. | 497| 13900012 | Permission denied. | 498| 13900020 | Invalid argument. | 499| 14000011 | System inner fail. | 500 501**示例:** 502 503phAccessHelper的创建请参考[@ohos.file.photoAccessHelper (相册管理模块)](arkts-apis-photoAccessHelper-f.md)的示例使用。 504 505```ts 506import { dataSharePredicates } from '@kit.ArkData'; 507 508async function example(phAccessHelper: photoAccessHelper.PhotoAccessHelper) { 509 // 示例代码为删除相册名为newAlbumName的相册。 510 console.info('deleteAlbumsDemo'); 511 let predicates: dataSharePredicates.DataSharePredicates = new dataSharePredicates.DataSharePredicates(); 512 predicates.equalTo('album_name', 'newAlbumName'); 513 let fetchOptions: photoAccessHelper.FetchOptions = { 514 fetchColumns: [], 515 predicates: predicates 516 }; 517 let fetchResult: photoAccessHelper.FetchResult<photoAccessHelper.Album> = await phAccessHelper.getAlbums(photoAccessHelper.AlbumType.USER, photoAccessHelper.AlbumSubtype.USER_GENERIC, fetchOptions); 518 let album: photoAccessHelper.Album = await fetchResult.getFirstObject(); 519 phAccessHelper.deleteAlbums([album], (err) => { 520 if (err) { 521 console.error(`deletePhotoAlbumsCallback failed with err: ${err.code}, ${err.message}`); 522 return; 523 } 524 console.info('deletePhotoAlbumsCallback successfully'); 525 }); 526 fetchResult.close(); 527} 528``` 529 530### deleteAlbums<sup>(deprecated)</sup> 531 532deleteAlbums(albums: Array<Album>): Promise<void> 533 534删除相册,使用Promise方式返回结果。 535 536删除相册前需先确保相册存在,只能删除用户相册。 537 538> **说明:** 539> 540> 从API version 10开始支持,从API version 11开始废弃。建议使用[MediaAlbumChangeRequest.deleteAlbums](#deletealbums11)替代。 541 542**系统接口**:此接口为系统接口。 543 544**系统能力**:SystemCapability.FileManagement.PhotoAccessHelper.Core 545 546**需要权限**:ohos.permission.WRITE_IMAGEVIDEO 547 548**参数:** 549 550| 参数名 | 类型 | 必填 | 说明 | 551| -------- | ------------------------ | ---- | ------------------------- | 552| albums | Array<[Album](#album)> | 是 | 待删除相册的数组。 | 553 554**返回值:** 555 556| 类型 | 说明 | 557| --------------------------- | -------------- | 558| Promise<void> | Promise对象,返回void。 | 559 560**错误码:** 561 562接口抛出错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)和[文件管理错误码](../apis-core-file-kit/errorcode-filemanagement.md)。 563 564错误码13900012,请参考[开发准备](../../media/medialibrary/photoAccessHelper-preparation.md)。 565 566| 错误码ID | 错误信息 | 567| -------- | ---------------------------------------- | 568| 202 | Called by non-system application. | 569| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types; 3. Parameter verification failed. | 570| 13900012 | Permission denied. | 571| 13900020 | Invalid argument. | 572| 14000011 | System inner fail. | 573 574**示例:** 575 576phAccessHelper的创建请参考[@ohos.file.photoAccessHelper (相册管理模块)](arkts-apis-photoAccessHelper-f.md)的示例使用。 577 578```ts 579import { dataSharePredicates } from '@kit.ArkData'; 580import { BusinessError } from '@kit.BasicServicesKit'; 581 582async function example(phAccessHelper: photoAccessHelper.PhotoAccessHelper) { 583 // 示例代码为删除相册名为newAlbumName的相册。 584 console.info('deleteAlbumsDemo'); 585 let predicates: dataSharePredicates.DataSharePredicates = new dataSharePredicates.DataSharePredicates(); 586 predicates.equalTo('album_name', 'newAlbumName'); 587 let fetchOptions: photoAccessHelper.FetchOptions = { 588 fetchColumns: [], 589 predicates: predicates 590 }; 591 let fetchResult: photoAccessHelper.FetchResult<photoAccessHelper.Album> = await phAccessHelper.getAlbums(photoAccessHelper.AlbumType.USER, photoAccessHelper.AlbumSubtype.USER_GENERIC, fetchOptions); 592 let album: photoAccessHelper.Album = await fetchResult.getFirstObject(); 593 phAccessHelper.deleteAlbums([album]).then(() => { 594 console.info('deletePhotoAlbumsPromise successfully'); 595 }).catch((err: BusinessError) => { 596 console.error(`deletePhotoAlbumsPromise failed with err: ${err.code}, ${err.message}`); 597 }); 598 fetchResult.close(); 599} 600``` 601 602### getHiddenAlbums<sup>11+</sup> 603 604getHiddenAlbums(mode: HiddenPhotosDisplayMode, options: FetchOptions, callback: AsyncCallback<FetchResult<Album>>): void 605 606根据隐藏文件显示模式和检索选项获取系统中的隐藏相册,使用callback方式返回结果。 607 608**系统接口**:此接口为系统接口。 609 610**需要权限**:ohos.permission.READ_IMAGEVIDEO 和 ohos.permission.MANAGE_PRIVATE_PHOTOS 611 612**系统能力**:SystemCapability.FileManagement.PhotoAccessHelper.Core 613 614**参数:** 615 616| 参数名 | 类型 | 必填 | 说明 | 617| -------- | ------------------------ | ---- | ------------------------- | 618| mode | [HiddenPhotosDisplayMode](#hiddenphotosdisplaymode11) | 是 | 隐藏文件显示模式。 | 619| options | [FetchOptions](arkts-apis-photoAccessHelper-i.md#fetchoptions) | 是 | 检索选项。 | 620| callback | AsyncCallback<[FetchResult](arkts-apis-photoAccessHelper-FetchResult.md)<[Album](#album)>> | 是 | callback返回获取相册的结果集。 | 621 622**错误码:** 623 624接口抛出错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)和[文件管理错误码](../apis-core-file-kit/errorcode-filemanagement.md)。 625 626| 错误码ID | 错误信息 | 627| -------- | ---------------------------------------- | 628| 201 | Permission verification failed, usually the result returned by VerifyAccessToken. | 629| 202 | Permission verification failed, application which is not a system application uses system API. | 630| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types; 3. Parameter verification failed. | 631| 14000011 | System inner fail. | 632 633**示例:** 634 635phAccessHelper的创建请参考[@ohos.file.photoAccessHelper (相册管理模块)](arkts-apis-photoAccessHelper-f.md)的示例使用。 636 637```ts 638import { dataSharePredicates } from '@kit.ArkData'; 639 640// 获取系统中包含隐藏文件且相册名为'newAlbumName'的相册 641async function getHiddenAlbumsView(phAccessHelper: photoAccessHelper.PhotoAccessHelper) { 642 console.info('getHiddenAlbumsViewDemo'); 643 let predicates: dataSharePredicates.DataSharePredicates = new dataSharePredicates.DataSharePredicates(); 644 predicates.equalTo('album_name', 'newAlbumName'); 645 let fetchOptions: photoAccessHelper.FetchOptions = { 646 fetchColumns: [], 647 predicates: predicates 648 }; 649 phAccessHelper.getHiddenAlbums(photoAccessHelper.HiddenPhotosDisplayMode.ALBUMS_MODE, fetchOptions, 650 async (err, fetchResult) => { 651 if (err !== undefined) { 652 console.error(`getHiddenAlbumsViewCallback failed with error: ${err.code}, ${err.message}`); 653 return; 654 } 655 if (fetchResult === undefined) { 656 console.error('getHiddenAlbumsViewCallback fetchResult is undefined'); 657 return; 658 } 659 let album = await fetchResult.getFirstObject(); 660 if (album === undefined) { 661 console.error('getHiddenAlbumsViewCallback album is undefined'); 662 fetchResult.close(); 663 return; 664 } 665 console.info('getHiddenAlbumsViewCallback successfully, album name: ' + album.albumName); 666 fetchResult.close(); 667 }); 668} 669``` 670 671### getHiddenAlbums<sup>11+</sup> 672 673getHiddenAlbums(mode: HiddenPhotosDisplayMode, callback: AsyncCallback<FetchResult<Album>>): void 674 675根据隐藏文件显示模式获取系统中的隐藏相册,使用callback方式返回结果 676 677**系统接口**:此接口为系统接口。 678 679**需要权限**:ohos.permission.READ_IMAGEVIDEO 和 ohos.permission.MANAGE_PRIVATE_PHOTOS 680 681**系统能力**:SystemCapability.FileManagement.PhotoAccessHelper.Core 682 683**参数:** 684 685| 参数名 | 类型 | 必填 | 说明 | 686| -------- | ------------------------ | ---- | ------------------------- | 687| mode | [HiddenPhotosDisplayMode](#hiddenphotosdisplaymode11) | 是 | 隐藏文件显示模式。 | 688| callback | AsyncCallback<[FetchResult](arkts-apis-photoAccessHelper-FetchResult.md)<[Album](#album)>> | 是 | callback返回获取相册的结果集。 | 689 690**错误码:** 691 692接口抛出错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)和[文件管理错误码](../apis-core-file-kit/errorcode-filemanagement.md)。 693 694| 错误码ID | 错误信息 | 695| -------- | ---------------------------------------- | 696| 201 | Permission verification failed, usually the result returned by VerifyAccessToken. | 697| 202 | Permission verification failed, application which is not a system application uses system API. | 698| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types; 3. Parameter verification failed. | 699| 14000011 | System inner fail. | 700 701**示例:** 702 703phAccessHelper的创建请参考[@ohos.file.photoAccessHelper (相册管理模块)](arkts-apis-photoAccessHelper-f.md)的示例使用。 704 705```ts 706import { dataSharePredicates } from '@kit.ArkData'; 707 708// 获取系统预置的隐藏相册 709async function getSysHiddenAlbum(phAccessHelper: photoAccessHelper.PhotoAccessHelper) { 710 console.info('getSysHiddenAlbumDemo'); 711 phAccessHelper.getHiddenAlbums(photoAccessHelper.HiddenPhotosDisplayMode.ASSETS_MODE, async (err, fetchResult) => { 712 if (fetchResult === undefined) { 713 console.error('getSysHiddenAlbumCallback fetchResult is undefined'); 714 return; 715 } 716 let hiddenAlbum: photoAccessHelper.Album = await fetchResult.getFirstObject(); 717 if (hiddenAlbum === undefined) { 718 console.error('getSysHiddenAlbumCallback hiddenAlbum is undefined'); 719 fetchResult.close(); 720 return; 721 } 722 console.info('getSysHiddenAlbumCallback successfully, albumUri: ' + hiddenAlbum.albumUri); 723 fetchResult.close(); 724 }); 725} 726 727// 获取隐藏相册-相册视图,即系统中包含隐藏文件的相册(不包含系统预置的隐藏相册本身和回收站相册) 728async function getHiddenAlbumsView(phAccessHelper: photoAccessHelper.PhotoAccessHelper) { 729 console.info('getHiddenAlbumsViewDemo'); 730 phAccessHelper.getHiddenAlbums(photoAccessHelper.HiddenPhotosDisplayMode.ALBUMS_MODE, async (err, fetchResult) => { 731 if (fetchResult === undefined) { 732 console.error('getHiddenAlbumsViewCallback fetchResult is undefined'); 733 return; 734 } 735 let albums: Array<photoAccessHelper.Album> = await fetchResult.getAllObjects(); 736 if (albums === undefined) { 737 console.error('getHiddenAlbumsViewCallback albums is undefined'); 738 fetchResult.close(); 739 return; 740 } 741 console.info('getHiddenAlbumsViewCallback successfully, albums size: ' + albums.length); 742 743 let predicates: dataSharePredicates.DataSharePredicates = new dataSharePredicates.DataSharePredicates(); 744 let fetchOption: photoAccessHelper.FetchOptions = { 745 fetchColumns: [], 746 predicates: predicates 747 }; 748 for (let i = 0; i < albums.length; i++) { 749 // 获取相册中的隐藏文件。 750 albums[i].getAssets(fetchOption, (err, assetFetchResult) => { 751 if (assetFetchResult === undefined) { 752 console.error('getHiddenAlbumsViewCallback assetFetchResult is undefined'); 753 return; 754 } 755 console.info('album get hidden assets successfully, getCount: ' + assetFetchResult.getCount()); 756 }); 757 } 758 fetchResult.close(); 759 }); 760} 761``` 762 763### getHiddenAlbums<sup>11+</sup> 764 765getHiddenAlbums(mode: HiddenPhotosDisplayMode, options?: FetchOptions): Promise<FetchResult<Album>> 766 767根据隐藏文件显示模式和检索选项获取系统中的隐藏相册,使用Promise方式返回结果。 768 769**系统接口**:此接口为系统接口。 770 771**需要权限**:ohos.permission.READ_IMAGEVIDEO 和 ohos.permission.MANAGE_PRIVATE_PHOTOS 772 773**系统能力**:SystemCapability.FileManagement.PhotoAccessHelper.Core 774 775**参数:** 776 777| 参数名 | 类型 | 必填 | 说明 | 778| -------- | ------------------------ | ---- | ------------------------- | 779| mode | [HiddenPhotosDisplayMode](#hiddenphotosdisplaymode11) | 是 | 隐藏文件显示模式。 | 780| options | [FetchOptions](arkts-apis-photoAccessHelper-i.md#fetchoptions) | 否 | 检索选项,不填时默认根据隐藏文件显示模式检索。 | 781 782**返回值:** 783 784| 类型 | 说明 | 785| --------------------------- | -------------- | 786| Promise<[FetchResult](arkts-apis-photoAccessHelper-FetchResult.md)<[Album](#album)>> | Promise对象,返回获取相册的结果集。 787 788**错误码:** 789 790接口抛出错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)和[文件管理错误码](../apis-core-file-kit/errorcode-filemanagement.md)。 791 792| 错误码ID | 错误信息 | 793| -------- | ---------------------------------------- | 794| 201 | Permission verification failed, usually the result returned by VerifyAccessToken. | 795| 202 | Permission verification failed, application which is not a system application uses system API. | 796| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types; 3. Parameter verification failed. | 797| 14000011 | System inner fail. | 798 799**示例:** 800 801phAccessHelper的创建请参考[@ohos.file.photoAccessHelper (相册管理模块)](arkts-apis-photoAccessHelper-f.md)的示例使用。 802 803```ts 804import { dataSharePredicates } from '@kit.ArkData'; 805import { BusinessError } from '@kit.BasicServicesKit'; 806 807// 获取系统预置的隐藏相册 808async function getSysHiddenAlbum(phAccessHelper: photoAccessHelper.PhotoAccessHelper) { 809 console.info('getSysHiddenAlbumDemo'); 810 phAccessHelper.getHiddenAlbums(photoAccessHelper.HiddenPhotosDisplayMode.ASSETS_MODE) 811 .then( async (fetchResult) => { 812 if (fetchResult === undefined) { 813 console.error('getSysHiddenAlbumPromise fetchResult is undefined'); 814 return; 815 } 816 let hiddenAlbum: photoAccessHelper.Album = await fetchResult.getFirstObject(); 817 console.info('getAlbumsPromise successfully, albumUri: ' + hiddenAlbum.albumUri); 818 fetchResult.close(); 819 }).catch((err: BusinessError) => { 820 console.error(`getSysHiddenAlbumPromise failed with err: ${err.code}, ${err.message}`); 821 }); 822} 823 824// 获取隐藏相册-相册视图,即系统中包含隐藏文件的相册(不包含系统预置的隐藏相册本身和回收站相册) 825async function getHiddenAlbumsView(phAccessHelper: photoAccessHelper.PhotoAccessHelper) { 826 console.info('getHiddenAlbumsViewDemo'); 827 phAccessHelper.getHiddenAlbums(photoAccessHelper.HiddenPhotosDisplayMode.ALBUMS_MODE).then( async (fetchResult) => { 828 if (fetchResult === undefined) { 829 console.error('getHiddenAlbumsViewPromise fetchResult is undefined'); 830 return; 831 } 832 let albums: Array<photoAccessHelper.Album> = await fetchResult.getAllObjects(); 833 console.info('getHiddenAlbumsViewPromise successfully, albums size: ' + albums.length); 834 835 let predicates: dataSharePredicates.DataSharePredicates = new dataSharePredicates.DataSharePredicates(); 836 let fetchOption: photoAccessHelper.FetchOptions = { 837 fetchColumns: [], 838 predicates: predicates 839 }; 840 for (let i = 0; i < albums.length; i++) { 841 // 获取相册中的隐藏文件。 842 albums[i].getAssets(fetchOption).then((assetFetchResult) => { 843 console.info('album get hidden assets successfully, getCount: ' + assetFetchResult.getCount()); 844 }).catch((err: BusinessError) => { 845 console.error(`album get hidden assets failed with error: ${err.code}, ${err.message}`); 846 }); 847 } 848 fetchResult.close(); 849 }).catch((err: BusinessError) => { 850 console.error(`getHiddenAlbumsViewPromise failed with err: ${err.code}, ${err.message}`); 851 }); 852} 853``` 854 855### deleteAssets<sup>(deprecated)</sup> 856 857deleteAssets(uriList: Array<string>, callback: AsyncCallback<void>): void 858 859删除媒体文件,删除的文件进入到回收站,使用callback方式返回结果。 860 861> **说明:** 862> 863> 从API version 10开始支持,从API version 11开始废弃。建议使用[MediaAssetChangeRequest.deleteAssets](arkts-apis-photoAccessHelper-MediaAssetChangeRequest.md#deleteassets11)替代。 864 865**系统接口**:此接口为系统接口。 866 867**需要权限**:ohos.permission.WRITE_IMAGEVIDEO 868 869**系统能力**:SystemCapability.FileManagement.PhotoAccessHelper.Core 870 871**参数:** 872 873| 参数名 | 类型 | 必填 | 说明 | 874| -------- | ------------------------- | ---- | ---------- | 875| uriList | Array<string> | 是 | 待删除的媒体文件uri数组。 | 876| callback | AsyncCallback<void> | 是 | callback返回void。 | 877 878**错误码:** 879 880接口抛出错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)和[文件管理错误码](../apis-core-file-kit/errorcode-filemanagement.md)。 881 882错误码13900012,请参考[开发准备](../../media/medialibrary/photoAccessHelper-preparation.md)。 883 884| 错误码ID | 错误信息 | 885| -------- | ---------------------------------------- | 886| 202 | Called by non-system application. | 887| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types; 3. Parameter verification failed. | 888| 13900012 | Permission denied. | 889| 13900020 | Invalid argument. | 890| 14000002 | The uri format is incorrect or does not exist. | 891| 14000011 | System inner fail. | 892 893**示例:** 894 895phAccessHelper的创建请参考[@ohos.file.photoAccessHelper (相册管理模块)](arkts-apis-photoAccessHelper-f.md)的示例使用。 896 897```ts 898import { dataSharePredicates } from '@kit.ArkData'; 899 900async function example(phAccessHelper: photoAccessHelper.PhotoAccessHelper) { 901 console.info('deleteAssetDemo'); 902 let predicates: dataSharePredicates.DataSharePredicates = new dataSharePredicates.DataSharePredicates(); 903 let fetchOptions: photoAccessHelper.FetchOptions = { 904 fetchColumns: [], 905 predicates: predicates 906 }; 907 try { 908 let fetchResult: photoAccessHelper.FetchResult<photoAccessHelper.PhotoAsset> = await phAccessHelper.getAssets(fetchOptions); 909 let asset: photoAccessHelper.PhotoAsset = await fetchResult.getFirstObject(); 910 if (asset === undefined) { 911 console.error('asset not exist'); 912 return; 913 } 914 phAccessHelper.deleteAssets([asset.uri], (err) => { 915 if (err === undefined) { 916 console.info('deleteAssets successfully'); 917 } else { 918 console.error(`deleteAssets failed with error: ${err.code}, ${err.message}`); 919 } 920 }); 921 } catch (err) { 922 console.error(`fetch failed, error: ${err.code}, ${err.message}`); 923 } 924} 925``` 926 927### deleteAssets<sup>(deprecated)</sup> 928 929deleteAssets(uriList: Array<string>): Promise<void> 930 931删除媒体文件,删除的文件进入到回收站,使用Promise方式返回结果。 932 933> **说明:** 934> 935> 从API version 10开始支持,从API version 11开始废弃。建议使用[MediaAssetChangeRequest.deleteAssets](arkts-apis-photoAccessHelper-MediaAssetChangeRequest.md#deleteassets11)替代。 936 937**系统接口**:此接口为系统接口。 938 939**需要权限**:ohos.permission.WRITE_IMAGEVIDEO 940 941**系统能力**:SystemCapability.FileManagement.PhotoAccessHelper.Core 942 943**参数:** 944 945| 参数名 | 类型 | 必填 | 说明 | 946| -------- | ------------------------- | ---- | ---------- | 947| uriList | Array<string> | 是 | 待删除的媒体文件uri数组。 | 948 949**返回值:** 950 951| 类型 | 说明 | 952| --------------------------------------- | ----------------- | 953| Promise<void>| Promise对象,返回void。 | 954 955**错误码:** 956 957接口抛出错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)和[文件管理错误码](../apis-core-file-kit/errorcode-filemanagement.md)。 958 959错误码13900012,请参考[开发准备](../../media/medialibrary/photoAccessHelper-preparation.md)。 960 961| 错误码ID | 错误信息 | 962| -------- | ---------------------------------------- | 963| 202 | Called by non-system application. | 964| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types; 3. Parameter verification failed. | 965| 13900012 | Permission denied. | 966| 13900020 | Invalid argument. | 967| 14000002 | The uri format is incorrect or does not exist. | 968| 14000011 | System inner fail. | 969 970**示例:** 971 972phAccessHelper的创建请参考[@ohos.file.photoAccessHelper (相册管理模块)](arkts-apis-photoAccessHelper-f.md)的示例使用。 973 974```ts 975import { dataSharePredicates } from '@kit.ArkData'; 976 977async function example(phAccessHelper: photoAccessHelper.PhotoAccessHelper) { 978 console.info('deleteDemo'); 979 let predicates: dataSharePredicates.DataSharePredicates = new dataSharePredicates.DataSharePredicates(); 980 let fetchOptions: photoAccessHelper.FetchOptions = { 981 fetchColumns: [], 982 predicates: predicates 983 }; 984 try { 985 let fetchResult: photoAccessHelper.FetchResult<photoAccessHelper.PhotoAsset> = await phAccessHelper.getAssets(fetchOptions); 986 let asset: photoAccessHelper.PhotoAsset = await fetchResult.getFirstObject(); 987 if (asset === undefined) { 988 console.error('asset not exist'); 989 return; 990 } 991 await phAccessHelper.deleteAssets([asset.uri]); 992 console.info('deleteAssets successfully'); 993 } catch (err) { 994 console.error(`deleteAssets failed with error: ${err.code}, ${err.message}`); 995 } 996} 997``` 998 999### getPhotoIndex 1000 1001getPhotoIndex(photoUri: string, albumUri: string, options: FetchOptions, callback: AsyncCallback<number>): void 1002 1003获取相册中图片或视频的位置,使用callback方式返回结果。 1004 1005**系统接口**:此接口为系统接口。 1006 1007**需要权限**:ohos.permission.READ_IMAGEVIDEO 1008 1009**系统能力**:SystemCapability.FileManagement.PhotoAccessHelper.Core 1010 1011**参数:** 1012 1013| 参数名 | 类型 | 必填 | 说明 | 1014| -------- | ------------------------- | ---- | ---------- | 1015| photoUri | string | 是 | 所查询的图库资源的uri。 | 1016| albumUri | string | 是 | 相册uri,可以为空字符串,为空字符串时默认查询全部图库资源。 | 1017| options | [FetchOptions](arkts-apis-photoAccessHelper-i.md#fetchoptions) | 是 | 检索选项,predicates中必须设置一种检索排序方式,不设置或多设置均会导致接口调用异常。 | 1018| callback | AsyncCallback<number>| 是 | callback返回相册中资源的索引。 | 1019 1020**错误码:** 1021 1022接口抛出错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)和[文件管理错误码](../apis-core-file-kit/errorcode-filemanagement.md)。 1023 1024错误码13900012,请参考[开发准备](../../media/medialibrary/photoAccessHelper-preparation.md)。 1025 1026| 错误码ID | 错误信息 | 1027| -------- | ---------------------------------------- | 1028| 202 | Called by non-system application. | 1029| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types; 3. Parameter verification failed. | 1030| 13900012 | Permission denied. | 1031| 13900020 | Invalid argument. | 1032| 14000011 | System inner fail. | 1033 1034**示例:** 1035 1036phAccessHelper的创建请参考[@ohos.file.photoAccessHelper (相册管理模块)](arkts-apis-photoAccessHelper-f.md)的示例使用。 1037 1038```ts 1039import { dataSharePredicates } from '@kit.ArkData'; 1040 1041async function example(phAccessHelper: photoAccessHelper.PhotoAccessHelper) { 1042 try { 1043 console.info('getPhotoIndexDemo'); 1044 let predicatesForGetAsset: dataSharePredicates.DataSharePredicates = new dataSharePredicates.DataSharePredicates(); 1045 let fetchOp: photoAccessHelper.FetchOptions = { 1046 fetchColumns: [], 1047 predicates: predicatesForGetAsset 1048 }; 1049 // Obtain the uri of the album. 1050 let albumFetchResult: photoAccessHelper.FetchResult<photoAccessHelper.Album> = await phAccessHelper.getAlbums(photoAccessHelper.AlbumType.SYSTEM, photoAccessHelper.AlbumSubtype.FAVORITE, fetchOp); 1051 let album: photoAccessHelper.Album = await albumFetchResult.getFirstObject(); 1052 let predicates: dataSharePredicates.DataSharePredicates = new dataSharePredicates.DataSharePredicates(); 1053 predicates.orderByAsc(photoAccessHelper.PhotoKeys.DATE_MODIFIED); 1054 let fetchOptions: photoAccessHelper.FetchOptions = { 1055 fetchColumns: [photoAccessHelper.PhotoKeys.DATE_MODIFIED], 1056 predicates: predicates 1057 }; 1058 let photoFetchResult: photoAccessHelper.FetchResult<photoAccessHelper.PhotoAsset> = await album.getAssets(fetchOptions); 1059 let expectIndex = 1; 1060 // Obtain the uri of the second file. 1061 let photoAsset: photoAccessHelper.PhotoAsset = await photoFetchResult.getObjectByPosition(expectIndex); 1062 1063 phAccessHelper.getPhotoIndex(photoAsset.uri, album.albumUri, fetchOptions, (err, index) => { 1064 if (err === undefined) { 1065 console.info(`getPhotoIndex successfully and index is : ${index}`); 1066 } else { 1067 console.error(`getPhotoIndex failed; error: ${err.code}, ${err.message}`); 1068 } 1069 }); 1070 } catch (error) { 1071 console.error(`getPhotoIndex failed; error: ${error.code}, ${error.message}`); 1072 } 1073} 1074``` 1075 1076### getPhotoIndex 1077 1078getPhotoIndex(photoUri: string, albumUri: string, options: FetchOptions): Promise<number> 1079 1080获取相册中图片或视频的位置,使用Promise方式返回结果。 1081 1082**系统接口**:此接口为系统接口。 1083 1084**需要权限**:ohos.permission.READ_IMAGEVIDEO 1085 1086**系统能力**:SystemCapability.FileManagement.PhotoAccessHelper.Core 1087 1088**参数:** 1089 1090| 参数名 | 类型 | 必填 | 说明 | 1091| -------- | ------------------------- | ---- | ---------- | 1092| photoUri | string | 是 | 所查询的图库资源的uri。 | 1093| albumUri | string | 是 | 相册uri,可以为空字符串,为空字符串时默认查询全部图库资源。 | 1094| options | [FetchOptions](arkts-apis-photoAccessHelper-i.md#fetchoptions) | 是 | 检索选项,predicates中必须设置一种检索排序方式,不设置或多设置均会导致接口调用异常。 | 1095 1096**返回值:** 1097 1098| 类型 | 说明 | 1099| --------------------------------------- | ----------------- | 1100| Promise<number>| 返回相册中资源的索引。 | 1101 1102**错误码:** 1103 1104接口抛出错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)和[文件管理错误码](../apis-core-file-kit/errorcode-filemanagement.md)。 1105 1106错误码13900012,请参考[开发准备](../../media/medialibrary/photoAccessHelper-preparation.md)。 1107 1108| 错误码ID | 错误信息 | 1109| -------- | ---------------------------------------- | 1110| 202 | Called by non-system application. | 1111| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types; 3. Parameter verification failed. | 1112| 13900012 | Permission denied. | 1113| 13900020 | Invalid argument. | 1114| 14000011 | System inner fail. | 1115 1116**示例:** 1117 1118phAccessHelper的创建请参考[@ohos.file.photoAccessHelper (相册管理模块)](arkts-apis-photoAccessHelper-f.md)的示例使用。 1119 1120```ts 1121import { dataSharePredicates } from '@kit.ArkData'; 1122import { BusinessError } from '@kit.BasicServicesKit'; 1123 1124async function example(phAccessHelper: photoAccessHelper.PhotoAccessHelper) { 1125 try { 1126 console.info('getPhotoIndexDemo'); 1127 let predicatesForGetAsset: dataSharePredicates.DataSharePredicates = new dataSharePredicates.DataSharePredicates(); 1128 let fetchOp: photoAccessHelper.FetchOptions = { 1129 fetchColumns: [], 1130 predicates: predicatesForGetAsset 1131 }; 1132 // Obtain the uri of the album. 1133 let albumFetchResult: photoAccessHelper.FetchResult<photoAccessHelper.Album> = await phAccessHelper.getAlbums(photoAccessHelper.AlbumType.SYSTEM, photoAccessHelper.AlbumSubtype.FAVORITE, fetchOp); 1134 let album: photoAccessHelper.Album = await albumFetchResult.getFirstObject(); 1135 let predicates: dataSharePredicates.DataSharePredicates = new dataSharePredicates.DataSharePredicates(); 1136 predicates.orderByAsc(photoAccessHelper.PhotoKeys.DATE_MODIFIED); 1137 let fetchOptions: photoAccessHelper.FetchOptions = { 1138 fetchColumns: [photoAccessHelper.PhotoKeys.DATE_MODIFIED], 1139 predicates: predicates 1140 }; 1141 let photoFetchResult: photoAccessHelper.FetchResult<photoAccessHelper.PhotoAsset> = await album.getAssets(fetchOptions); 1142 let expectIndex = 1; 1143 // Obtain the uri of the second file. 1144 let photoAsset: photoAccessHelper.PhotoAsset = await photoFetchResult.getObjectByPosition(expectIndex); 1145 phAccessHelper.getPhotoIndex(photoAsset.uri, album.albumUri, fetchOptions).then((index) => { 1146 console.info(`getPhotoIndex successfully and index is : ${index}`); 1147 }).catch((err: BusinessError) => { 1148 console.error(`getPhotoIndex failed; error: ${err.code}, ${err.message}`); 1149 }); 1150 } catch (error) { 1151 console.error(`getPhotoIndex failed; error: ${error.code}, ${error.message}`); 1152 } 1153} 1154``` 1155 1156### saveFormInfo<sup>11+</sup> 1157 1158saveFormInfo(info:FormInfo, callback: AsyncCallback<void>):void 1159 1160将图库卡片相关信息保存到数据库中,使用callback方式返回结果。 1161 1162**系统接口**:此接口为系统接口。 1163 1164**需要权限**:ohos.permission.WRITE_IMAGEVIDEO 1165 1166**系统能力**:SystemCapability.FileManagement.PhotoAccessHelper.Core 1167 1168**参数:** 1169 1170| 参数名 | 类型 | 必填 | 说明 | 1171| -------- | ------------------------ | ---- | ------------------------- | 1172| info | [FormInfo](#forminfo11) | 是 | 图库卡片信息,包括图库卡片的id和卡片绑定的图片的uri。 | 1173| callback | AsyncCallback<void> | 是 | callback返回void。 | 1174 1175**错误码:** 1176 1177接口抛出错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)和[文件管理错误码](../apis-core-file-kit/errorcode-filemanagement.md)。 1178 1179| 错误码ID | 错误信息 | 1180| -------- | ---------------------------------------- | 1181| 201 | Permission verification failed, usually the result returned by VerifyAccessToken. | 1182| 202 | Permission verification failed, application which is not a system application uses system API. | 1183| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types; 3. Parameter verification failed. | 1184| 14000011 | System inner fail. | 1185 1186 1187**示例:** 1188 1189phAccessHelper的创建请参考[@ohos.file.photoAccessHelper (相册管理模块)](arkts-apis-photoAccessHelper-f.md)的示例使用。 1190 1191```ts 1192import { dataSharePredicates } from '@kit.ArkData'; 1193import { BusinessError } from '@kit.BasicServicesKit'; 1194 1195async function example(phAccessHelper: photoAccessHelper.PhotoAccessHelper) { 1196 console.info('saveFormInfoDemo'); 1197 let predicates: dataSharePredicates.DataSharePredicates = new dataSharePredicates.DataSharePredicates(); 1198 let fetchOptions: photoAccessHelper.FetchOptions = { 1199 fetchColumns: [], 1200 predicates: predicates 1201 }; 1202 let fetchResult: photoAccessHelper.FetchResult<photoAccessHelper.PhotoAsset> = await phAccessHelper.getAssets(fetchOptions); 1203 let photoAsset: photoAccessHelper.PhotoAsset = await fetchResult.getFirstObject(); 1204 1205 let info: photoAccessHelper.FormInfo = { 1206 //formId是一个由纯数字组成的字符串,uri为图库中存在的图片的uri信息,图库中无图片创建卡片时uri需为空字符串。 1207 formId : "20230116123", 1208 uri: photoAsset.uri, 1209 } 1210 1211 phAccessHelper.saveFormInfo(info, async (err: BusinessError) => { 1212 if (err == undefined) { 1213 console.info('saveFormInfo success'); 1214 } else { 1215 console.error(`saveFormInfo fail with error: ${err.code}, ${err.message}`); 1216 } 1217 }); 1218} 1219``` 1220 1221### saveFormInfo<sup>11+</sup> 1222 1223saveFormInfo(info:FormInfo):Promise<void> 1224 1225将图库卡片相关信息保存到数据库中,使用Promise方式返回结果。 1226 1227**系统接口**:此接口为系统接口。 1228 1229**需要权限**:ohos.permission.WRITE_IMAGEVIDEO 1230 1231**系统能力**:SystemCapability.FileManagement.PhotoAccessHelper.Core 1232 1233**参数:** 1234 1235| 参数名 | 类型 | 必填 | 说明 | 1236| -------- | ------------------------ | ---- | ------------------------- | 1237| info | [FormInfo](#forminfo11) | 是 | 图库卡片信息,包括图库卡片的id和卡片绑定的图片的uri。 | 1238 1239**返回值:** 1240 1241| 类型 | 说明 | 1242| --------------------------------------- | ----------------- | 1243| Promise<void>| Promise对象,返回void。 | 1244 1245**错误码:** 1246 1247接口抛出错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)和[文件管理错误码](../apis-core-file-kit/errorcode-filemanagement.md)。 1248 1249| 错误码ID | 错误信息 | 1250| -------- | ---------------------------------------- | 1251| 201 | Permission verification failed, usually the result returned by VerifyAccessToken. | 1252| 202 | Permission verification failed, application which is not a system application uses system API. | 1253| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types; 3. Parameter verification failed. | 1254| 14000011 | System inner fail. | 1255 1256**示例:** 1257 1258phAccessHelper的创建请参考[@ohos.file.photoAccessHelper (相册管理模块)](arkts-apis-photoAccessHelper-f.md)的示例使用。 1259 1260```ts 1261import { dataSharePredicates } from '@kit.ArkData'; 1262import { BusinessError } from '@kit.BasicServicesKit'; 1263 1264async function example(phAccessHelper: photoAccessHelper.PhotoAccessHelper) { 1265 console.info('saveFormInfoDemo'); 1266 let predicates: dataSharePredicates.DataSharePredicates = new dataSharePredicates.DataSharePredicates(); 1267 let fetchOptions: photoAccessHelper.FetchOptions = { 1268 fetchColumns: [], 1269 predicates: predicates 1270 }; 1271 let fetchResult: photoAccessHelper.FetchResult<photoAccessHelper.PhotoAsset> = await phAccessHelper.getAssets(fetchOptions); 1272 let photoAsset: photoAccessHelper.PhotoAsset = await fetchResult.getFirstObject(); 1273 1274 let info: photoAccessHelper.FormInfo = { 1275 //formId是一个由纯数字组成的字符串,uri为图库中存在的图片的uri信息,图库中无图片创建卡片时uri需为空字符串。 1276 formId: "20230116123", 1277 uri: photoAsset.uri, 1278 } 1279 1280 phAccessHelper.saveFormInfo(info).then(() => { 1281 console.info('saveFormInfo successfully'); 1282 }).catch((err: BusinessError) => { 1283 console.error(`saveFormInfo failed with error: ${err.code}, ${err.message}`); 1284 }); 1285} 1286``` 1287 1288### removeFormInfo<sup>11+</sup> 1289 1290removeFormInfo(info:FormInfo, callback: AsyncCallback<void>):void 1291 1292从数据库中删除图库卡片信息,使用callback方式返回结果。 1293 1294**系统接口**:此接口为系统接口。 1295 1296**需要权限**:ohos.permission.WRITE_IMAGEVIDEO 1297 1298**系统能力**:SystemCapability.FileManagement.PhotoAccessHelper.Core 1299 1300**参数:** 1301 1302| 参数名 | 类型 | 必填 | 说明 | 1303| -------- | ------------------------ | ---- | ------------------------- | 1304| info | [FormInfo](#forminfo11) | 是 | 图库卡片信息,包括图库卡片的id和卡片绑定的图片的uri。 | 1305| callback | AsyncCallback<void> | 是 | callback返回void。 | 1306 1307**错误码:** 1308 1309接口抛出错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)和[文件管理错误码](../apis-core-file-kit/errorcode-filemanagement.md)。 1310 1311| 错误码ID | 错误信息 | 1312| -------- | ---------------------------------------- | 1313| 201 | Permission verification failed, usually the result returned by VerifyAccessToken. | 1314| 202 | Permission verification failed, application which is not a system application uses system API. | 1315| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types; 3. Parameter verification failed. | 1316| 14000011 | System inner fail. | 1317 1318**示例:** 1319 1320phAccessHelper的创建请参考[@ohos.file.photoAccessHelper (相册管理模块)](arkts-apis-photoAccessHelper-f.md)的示例使用。 1321 1322```ts 1323import { BusinessError } from '@kit.BasicServicesKit'; 1324 1325async function example(phAccessHelper: photoAccessHelper.PhotoAccessHelper) { 1326 console.info('removeFormInfoDemo'); 1327 let info: photoAccessHelper.FormInfo = { 1328 //formId是一个由纯数字组成的字符串,移除卡片的时候uri填空即可。 1329 formId: "20230116123", 1330 uri: "", 1331 } 1332 1333 phAccessHelper.removeFormInfo(info, async (err: BusinessError) => { 1334 if (err == undefined) { 1335 console.info('removeFormInfo success'); 1336 } else { 1337 console.error(`removeFormInfo fail with error: ${err.code}, ${err.message}`); 1338 } 1339 }); 1340} 1341``` 1342 1343### removeFormInfo<sup>11+</sup> 1344 1345removeFormInfo(info:FormInfo):Promise<void> 1346 1347从数据库中删除图库卡片信息,使用Promise方式返回结果。 1348 1349**系统接口**:此接口为系统接口。 1350 1351**需要权限**:ohos.permission.WRITE_IMAGEVIDEO 1352 1353**系统能力**:SystemCapability.FileManagement.PhotoAccessHelper.Core 1354 1355**参数:** 1356 1357| 参数名 | 类型 | 必填 | 说明 | 1358| -------- | ------------------------ | ---- | ------------------------- | 1359| info | [FormInfo](#forminfo11) | 是 | 图库卡片信息,包括图库卡片的id和卡片绑定的图片的uri。 | 1360 1361**返回值:** 1362 1363| 类型 | 说明 | 1364| --------------------------------------- | ----------------- | 1365| Promise<void>| Promise对象,返回void。 | 1366 1367**错误码:** 1368 1369接口抛出错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)和[文件管理错误码](../apis-core-file-kit/errorcode-filemanagement.md)。 1370 1371| 错误码ID | 错误信息 | 1372| -------- | ---------------------------------------- | 1373| 201 | Permission verification failed, usually the result returned by VerifyAccessToken. | 1374| 202 | Permission verification failed, application which is not a system application uses system API. | 1375| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types; 3. Parameter verification failed. | 1376| 14000011 | System inner fail. | 1377 1378**示例:** 1379 1380phAccessHelper的创建请参考[@ohos.file.photoAccessHelper (相册管理模块)](arkts-apis-photoAccessHelper-f.md)的示例使用。 1381 1382```ts 1383import { BusinessError } from '@kit.BasicServicesKit'; 1384 1385async function example(phAccessHelper: photoAccessHelper.PhotoAccessHelper) { 1386 console.info('removeFormInfoDemo'); 1387 let info: photoAccessHelper.FormInfo = { 1388 //formId是一个由纯数字组成的字符串,移除卡片的时候uri填空即可。 1389 formId: "20230116123", 1390 uri: "", 1391 } 1392 1393 phAccessHelper.removeFormInfo(info).then(() => { 1394 console.info('removeFormInfo successfully'); 1395 }).catch((err: BusinessError) => { 1396 console.error(`removeFormInfo failed with error: ${err.code}, ${err.message}`); 1397 }); 1398} 1399``` 1400 1401### createAssetsForApp<sup>19+</sup> 1402 1403createAssetsForApp(bundleName: string, appName: string, tokenId: number, photoCreationConfigs: Array<PhotoCreationConfig>): Promise<Array<string>> 1404 1405调用接口代替应用创建媒体库uri列表。Uri已对tokenId对应的应用授权,支持应用使用uri写入图片/视频。 1406 1407**系统接口**:此接口为系统接口。 1408 1409**需要权限**:ohos.permission.WRITE_IMAGEVIDEO 1410 1411**系统能力**:SystemCapability.FileManagement.PhotoAccessHelper.Core 1412 1413**参数:** 1414 1415| 参数名 | 类型 | 必填 | 说明 | 1416| -------- |----------------------------------------------------------------------| ---- | ------------------------- | 1417| bundleName | string | 是 | 需保存图片/视频文件的应用bundle name。 | 1418| appName | string | 是 | 需保存图片/视频文件的应用app name。 | 1419| tokenId | number | 是 | 需保存图片/视频文件的应用tokenId。 | 1420| photoCreationConfigs | Array<[PhotoCreationConfig](arkts-apis-photoAccessHelper-i.md#photocreationconfig12)> | 是 | 保存图片/视频到媒体库的配置。 | 1421 1422**返回值:** 1423 1424| 类型 | 说明 | 1425| --------------------------------------- | ----------------- | 1426| Promise<Array<string>> | Promise对象,返回给接口调用方的媒体库文件uri列表。Uri已对tokenId对应的应用授权,支持应用写入数据。如果生成uri异常,则返回批量创建错误码。<br>返回-3006表不允许出现非法字符;返回-2004表示图片类型和后缀不符;返回-203表示文件操作异常。 | 1427 1428**错误码:** 1429 1430接口抛出错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)和[文件管理错误码](../apis-core-file-kit/errorcode-filemanagement.md)。 1431 1432| 错误码ID | 错误信息 | 1433| -------- | ---------------------------------------- | 1434| 201 | Permission denied. | 1435| 202 | Called by non-system application. | 1436| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameters types; 3. Parameter verification failed. | 1437| 14000011 | Internal system error. | 1438 1439**示例:** 1440 1441phAccessHelper的创建请参考[@ohos.file.photoAccessHelper (相册管理模块)](arkts-apis-photoAccessHelper-f.md)的示例使用。 1442 1443```ts 1444async function example(phAccessHelper: photoAccessHelper.PhotoAccessHelper) { 1445 console.info('createAssetsForAppDemo.'); 1446 1447 try { 1448 let bundleName: string = 'testBundleName'; 1449 let appName: string = 'testAppName'; 1450 let tokenId: number = 537197950; 1451 let photoCreationConfigs: Array<photoAccessHelper.PhotoCreationConfig> = [ 1452 { 1453 title: 'test', 1454 fileNameExtension: 'jpg', 1455 photoType: photoAccessHelper.PhotoType.IMAGE, 1456 subtype: photoAccessHelper.PhotoSubtype.DEFAULT, 1457 } 1458 ]; 1459 let desFileUris: Array<string> = await phAccessHelper.createAssetsForApp(bundleName, appName, tokenId, photoCreationConfigs); 1460 console.info('createAssetsForApp success, data is ' + desFileUris); 1461 } catch (err) { 1462 console.error(`createAssetsForApp failed with error: ${err.code}, ${err.message}`); 1463 } 1464} 1465``` 1466 1467### grantPhotoUriPermission<sup>19+</sup> 1468 1469grantPhotoUriPermission(tokenId: number, uri: string, photoPermissionType: PhotoPermissionType, hideSensitiveType: HideSensitiveType): Promise<number> 1470 1471给应用授予uri的访问权限,使用Promise方式返回结果。 1472 1473**系统接口**:此接口为系统接口。 1474 1475**系统能力**:SystemCapability.FileManagement.PhotoAccessHelper.Core 1476 1477**需要权限:** ohos.permission.WRITE_IMAGEVIDEO 1478 1479**参数:** 1480 1481| 参数名 | 类型 | 必填 | 说明 | 1482| -------- |----------------------------------------------------------------------| ---- | ------------------------- | 1483| tokenId | number | 是 | 应用标识,将访问权限授予给tokenId标识的应用。 | 1484| uri | string | 是 | 媒体资源的uri,uri表示的资源的访问权限将授予给应用。| 1485| photoPermissionType | [PhotoPermissionType](#photopermissiontype12) | 是 | 权限类型,将photoPermissionType表示的权限授予给应用。权限的覆盖规则参考枚举类。| 1486| hideSensitiveType | [HideSensitiveType](#hidesensitivetype12) | 是 | 脱敏类型,预留参数,目前可传枚举类中任一值。| 1487 1488**返回值:** 1489 1490| 类型 | 说明 | 1491| --------------------------------------- | ----------------- | 1492| Promise<number> | Promise对象,0:授权成功。 1:已有权限。-1:授权失败。| 1493 1494**错误码:** 1495 1496接口抛出错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)和[文件管理错误码](../apis-core-file-kit/errorcode-filemanagement.md)。 1497 1498| 错误码ID | 错误信息 | 1499| -------- | ---------------------------------------- | 1500| 201 | Permission denied. | 1501| 202 | Called by non-system application. | 1502| 13900020 | Invalid argument. Possible causes: 1. Incorrect uri format; 2. The value of photoPermissionType or hideSensitiveType is out of range. | 1503| 14000011 | Internal system error. | 1504 1505**示例:** 1506 1507phAccessHelper的创建请参考[@ohos.file.photoAccessHelper (相册管理模块)](arkts-apis-photoAccessHelper-f.md)的示例使用。 1508 1509```ts 1510async function example(phAccessHelper: photoAccessHelper.PhotoAccessHelper) { 1511 console.info('grantPhotoUriPermissionDemo'); 1512 1513 try { 1514 let tokenId = 502334412; 1515 let result = await phAccessHelper.grantPhotoUriPermission(tokenId, 1516 'file://media/Photo/1/IMG_datetime_0001/displayName.jpg', 1517 photoAccessHelper.PhotoPermissionType.TEMPORARY_READ_IMAGEVIDEO, 1518 photoAccessHelper.HideSensitiveType.HIDE_LOCATION_AND_SHOOTING_PARAM); 1519 1520 console.info('grantPhotoUriPermission success, result=' + result); 1521 } catch (err) { 1522 console.error('grantPhotoUriPermission failed, error=' + err); 1523 } 1524} 1525``` 1526 1527### grantPhotoUrisPermission<sup>19+</sup> 1528 1529grantPhotoUrisPermission(tokenId: number, uriList: Array<string>, photoPermissionType: PhotoPermissionType, hideSensitiveType: HideSensitiveType): Promise<number> 1530 1531给应用授予uri列表的访问权限,使用Promise方式返回结果。 1532 1533**系统接口**:此接口为系统接口。 1534 1535**系统能力**:SystemCapability.FileManagement.PhotoAccessHelper.Core 1536 1537**需要权限:** ohos.permission.WRITE_IMAGEVIDEO 1538 1539**参数:** 1540 1541| 参数名 | 类型 | 必填 | 说明 | 1542| -------- |----------------------------------------------------------------------| ---- | ------------------------- | 1543| tokenId | number | 是 | 应用标识,将访问权限授予给tokenId标识的应用。 | 1544| uriList | Array<string> | 是 | 媒体资源的uri列表,uri列表中的资源的访问权限将授予给应用。uri列表最多容纳 1000 条uri。| 1545| photoPermissionType | [PhotoPermissionType](#photopermissiontype12) | 是 | 权限类型,将photoPermissionType表示的权限授予给应用。权限的覆盖规则参考枚举类。| 1546| hideSensitiveType | [HideSensitiveType](#hidesensitivetype12) | 是 | 脱敏类型,预留参数,目前可传枚举类中任一值。| 1547 1548**返回值:** 1549 1550| 类型 | 说明 | 1551| --------------------------------------- | ----------------- | 1552| Promise<number> | Promise对象,0: 授权成功。 -1:授权失败。| 1553 1554**错误码:** 1555 1556接口抛出错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)和[文件管理错误码](../apis-core-file-kit/errorcode-filemanagement.md)。 1557 1558| 错误码ID | 错误信息 | 1559| -------- | ---------------------------------------- | 1560| 201 | Permission denied. | 1561| 202 | Called by non-system application. | 1562| 13900020 | Invalid argument. Possible causes: 1. Incorrect uri format; 2. The value of photoPermissionType or hideSensitiveType is out of range. | 1563| 14000011 | Internal system error. | 1564 1565**示例:** 1566 1567phAccessHelper的创建请参考[@ohos.file.photoAccessHelper (相册管理模块)](arkts-apis-photoAccessHelper-f.md)的示例使用。 1568 1569```ts 1570async function example(phAccessHelper: photoAccessHelper.PhotoAccessHelper) { 1571 console.info('grantPhotoUrisPermissionDemo'); 1572 1573 try { 1574 // 媒体资源的uri列表。 1575 let uris: Array<string> = [ 1576 'file://media/Photo/11/IMG_datetime_0001/displayName1.jpg', 1577 'file://media/Photo/22/IMG_datetime_0002/displayName2.jpg']; 1578 let tokenId = 502334412; 1579 let result = await phAccessHelper.grantPhotoUrisPermission(tokenId, uris, 1580 photoAccessHelper.PhotoPermissionType.TEMPORARY_READ_IMAGEVIDEO, 1581 photoAccessHelper.HideSensitiveType.HIDE_LOCATION_AND_SHOOTING_PARAM); 1582 1583 console.info('grantPhotoUrisPermission success, result=' + result); 1584 } catch (err) { 1585 console.error('grantPhotoUrisPermission failed, error=' + err); 1586 } 1587} 1588``` 1589 1590### cancelPhotoUriPermission<sup>19+</sup> 1591 1592cancelPhotoUriPermission(tokenId: number, uri: string, photoPermissionType: PhotoPermissionType): Promise<number> 1593 1594取消应用对uri的访问权限,使用Promise方式返回结果。 1595 1596**系统接口**:此接口为系统接口。 1597 1598**系统能力**:SystemCapability.FileManagement.PhotoAccessHelper.Core 1599 1600**需要权限:** ohos.permission.WRITE_IMAGEVIDEO 1601 1602**参数:** 1603 1604| 参数名 | 类型 | 必填 | 说明 | 1605| -------- |----------------------------------------------------------------------| ---- | ------------------------- | 1606| tokenId | number | 是 | 应用标识,将取消tokenId标识应用对媒体资源的访问权限。 | 1607| uri | string | 是 | 媒体资源的uri,取消应用对uri表示的资源的访问权限。| 1608| photoPermissionType | [PhotoPermissionType](#photopermissiontype12) | 是 | 权限类型,取消应用对媒体资源的访问权限为photoPermissionType。| 1609 1610**返回值:** 1611 1612| 类型 | 说明 | 1613| --------------------------------------- | ----------------- | 1614| Promise<number> | Promise对象,0:取消成功。-1:取消失败。| 1615 1616**错误码:** 1617 1618接口抛出错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)和[文件管理错误码](../apis-core-file-kit/errorcode-filemanagement.md)。 1619 1620| 错误码ID | 错误信息 | 1621| -------- | ---------------------------------------- | 1622| 201 | Permission denied. | 1623| 202 | Called by non-system application. | 1624| 13900020 | Invalid argument. Possible causes: 1. Incorrect uri format; 2. The value of photoPermissionType or hideSensitiveType is out of range. | 1625| 14000011 | Internal system error. | 1626 1627**示例:** 1628 1629phAccessHelper的创建请参考[@ohos.file.photoAccessHelper (相册管理模块)](arkts-apis-photoAccessHelper-f.md)的示例使用。 1630 1631```ts 1632async function example(phAccessHelper: photoAccessHelper.PhotoAccessHelper) { 1633 console.info('cancelPhotoUriPermissionDemo'); 1634 1635 try { 1636 let tokenId = 502334412; 1637 let result = await phAccessHelper.cancelPhotoUriPermission(tokenId, 1638 'file://media/Photo/11/IMG_datetime_0001/displayName.jpg', 1639 photoAccessHelper.PhotoPermissionType.TEMPORARY_READ_IMAGEVIDEO); 1640 1641 console.info('cancelPhotoUriPermission success, result=' + result); 1642 } catch (err) { 1643 console.error('cancelPhotoUriPermission failed, error=' + err); 1644 } 1645} 1646``` 1647 1648### startThumbnailCreationTask<sup>13+</sup> 1649 1650startThumbnailCreationTask(predicate: dataSharePredicates.DataSharePredicates, callback: AsyncCallback\<void\>): number 1651 1652按指定规则生成缩略图。 1653 1654**系统接口**:此接口为系统接口。 1655 1656**系统能力**: SystemCapability.FileManagement.PhotoAccessHelper.Core 1657 1658**需要权限:** ohos.permission.READ_IMAGEVIDEO 1659 1660**参数:** 1661 1662| 参数名 | 类型 | 必填 | 说明 | 1663| --------- | --------------------------------------- | ---- | --------------- | 1664| predicates | [dataSharePredicates.DataSharePredicates](../apis-arkdata/js-apis-data-dataSharePredicates.md#datasharepredicates) | 是 | 生成缩略图选项。 | 1665| callback | AsyncCallback<void> | 是 | 回调函数。当成功时标识通知任务结束,err为undefined,否则为错误对象。| 1666 1667**返回值:** 1668 1669| 类型 | 说明 | 1670| --------------------- | -------------------- | 1671| Promise<number> | 返回缩略图生成任务id。 | 1672 1673**错误码:** 1674 1675以下错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)和[文件管理错误码](../apis-core-file-kit/errorcode-filemanagement.md)。 1676 1677| 错误码ID | 错误信息 | 1678| -------- | ---------------------------------------- | 1679| 201 | Permission denied. | 1680| 202 | Called by non-system application. | 1681| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameters types; 3. Parameter verification failed. | 1682| 14000011 | Internal system error. | 1683 1684**示例:** 1685 1686phAccessHelper的创建请参考[@ohos.file.photoAccessHelper (相册管理模块)](arkts-apis-photoAccessHelper-f.md)的示例使用。 1687 1688```ts 1689import { dataSharePredicates } from '@kit.ArkData' 1690 1691function testCallBack() { 1692 1693} 1694 1695async function example(phAccessHelper: photoAccessHelper.PhotoAccessHelper) { 1696 let predicates: dataSharePredicates.DataSharePredicates = new dataSharePredicates.DataSharePredicates(); 1697 1698 try { 1699 console.info('startThumbnailCreationTask test start'); 1700 phAccessHelper.startThumbnailCreationTask(predicates, testCallBack); 1701 } catch (err) { 1702 console.error(`startThumbnailCreationTask failed, error: ${err.code}, ${err.message}`); 1703 } 1704} 1705``` 1706 1707### stopThumbnailCreationTask<sup>13+</sup> 1708 1709stopThumbnailCreationTask(taskId: number): void 1710 1711停止生成缩略图。 1712 1713**系统接口**:此接口为系统接口。 1714 1715**系统能力**: SystemCapability.FileManagement.PhotoAccessHelper.Core 1716 1717**需要权限:** ohos.permission.READ_IMAGEVIDEO 1718 1719**参数:** 1720 1721| 参数名 | 类型 | 必填 | 说明 | 1722| ----- | ------ | ---- | ------------------------ | 1723| taskId | number | 是 | 需要停止的缩略图生成任务id。 | 1724 1725**错误码:** 1726 1727以下错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)和[文件管理错误码](../apis-core-file-kit/errorcode-filemanagement.md)。 1728 1729| 错误码ID | 错误信息 | 1730| -------- | ---------------------------------------- | 1731| 201 | Permission denied. | 1732| 202 | Called by non-system application. | 1733| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameters types; 3. Parameter verification failed. | 1734| 14000011 | Internal system error. | 1735 1736**示例:** 1737 1738phAccessHelper的创建请参考[@ohos.file.photoAccessHelper (相册管理模块)](arkts-apis-photoAccessHelper-f.md)的示例使用。 1739 1740```ts 1741async function example(phAccessHelper: photoAccessHelper.PhotoAccessHelper) { 1742 try { 1743 console.info('stopThumbnailCreationTask test start'); 1744 let taskId: number = 75983; 1745 phAccessHelper.stopThumbnailCreationTask(taskId); 1746 } catch (err) { 1747 console.error(`stopThumbnailCreationTask failed, error: ${err.code}, ${err.message}`); 1748 } 1749} 1750``` 1751 1752### getIndexConstructProgress<sup>12+</sup> 1753 1754getIndexConstructProgress(): Promise<string> 1755 1756获取索引构建进度。使用Promise异步回调。 1757 1758**系统接口**:此接口为系统接口。 1759 1760**系统能力**:SystemCapability.FileManagement.PhotoAccessHelper.Core 1761 1762**需要权限**:ohos.permission.READ_IMAGEVIDEO 1763 1764 1765**返回值:** 1766 1767| 类型 | 说明 | 1768| --------------------------- | -------------- | 1769| Promise<string> | Promise对象,返回一个json格式的字符串。表示已完成智慧分析的图片数量、总数和已经完成智慧分析的视频数量、总数。 | 1770 1771**错误码:** 1772 1773以下错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)和[文件管理错误码](../apis-core-file-kit/errorcode-filemanagement.md)。 1774 1775 1776| 错误码ID | 错误信息 | 1777| -------- | ---------------------------------------- | 1778| 201 | Permission denied. | 1779| 202 | Called by non-system application. | 1780| 14000011 | Internal system error. | 1781 1782**示例:** 1783 1784phAccessHelper的创建请参考[photoAccessHelper.getPhotoAccessHelper](arkts-apis-photoAccessHelper-f.md#photoaccesshelpergetphotoaccesshelper)的示例使用。 1785 1786```ts 1787async function example(phAccessHelper: photoAccessHelper.PhotoAccessHelper) { 1788 1789 class indexProgress { 1790 finishedImageCount: number = 0; 1791 totalImageCount: number = 0; 1792 finishedVideoCount: number = 0; 1793 totalVideoCount: number = 0; 1794 } 1795 1796 try { 1797 console.info('getIndexConstructProgress test start'); 1798 let result: string = await phAccessHelper.getIndexConstructProgress(); 1799 console.info('getIndexProgress:' + result); 1800 1801 let jsonObj: indexProgress = JSON.parse(result); 1802 // ...使用获取到的索引构建进度数据。 1803 } catch (err) { 1804 console.error(`getIndexConstructProgress failed, error: ${err.code}, ${err.message}`); 1805 } 1806} 1807``` 1808 1809### getDataAnalysisProgress<sup>12+</sup> 1810 1811getDataAnalysisProgress(analysisType: AnalysisType): Promise<string> 1812 1813获取资产的分析进度。使用Promise异步回调。 1814 1815**系统接口**:此接口为系统接口。 1816 1817**系统能力**:SystemCapability.FileManagement.PhotoAccessHelper.Core 1818 1819**需要权限**:ohos.permission.READ_IMAGEVIDEO 1820 1821**参数:** 1822 1823| 参数名 | 类型 | 必填 | 说明 | 1824| ---- | -------------- | ---- | ----- | 1825| analysisType | [AnalysisType](#analysistype11) | 是 | 需要获取的智慧分析类型。 | 1826 1827**返回值:** 1828 1829| 类型 | 说明 | 1830| --------------------------- | -------------- | 1831| Promise<string> | Promise对象,返回一个json格式的字符串。表示资产分析的进度。 | 1832 1833**错误码:** 1834 1835以下错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)和[文件管理错误码](../apis-core-file-kit/errorcode-filemanagement.md)。 1836 1837| 错误码ID | 错误信息 | 1838| -------- | ---------------------------------------- | 1839| 201 | Permission denied. | 1840| 202 | Called by non-system application. | 1841| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types; 3. Parameter verification failed. | 1842| 14000011 | Internal system error. | 1843 1844**示例:** 1845 1846phAccessHelper的创建请参考[photoAccessHelper.getPhotoAccessHelper](arkts-apis-photoAccessHelper-f.md#photoaccesshelpergetphotoaccesshelper)的示例使用。 1847 1848```ts 1849async function example(phAccessHelper: photoAccessHelper.PhotoAccessHelper) { 1850 try { 1851 console.info('getDataAnalysisProgress test start'); 1852 1853 let result: string = await phAccessHelper.getDataAnalysisProgress(photoAccessHelper.AnalysisType.ANALYSIS_FACE); 1854 console.info('getDataAnalysisProgress:' + result); 1855 1856 } catch (err) { 1857 console.error(`getDataAnalysisProgress failed, error: ${err.code}, ${err.message}`); 1858 } 1859} 1860``` 1861 1862### getSharedPhotoAssets<sup>13+</sup> 1863 1864getSharedPhotoAssets(options: FetchOptions): Array\<SharedPhotoAsset\> 1865 1866获取共享的照片资产。 1867 1868**系统接口**:此接口为系统接口。 1869 1870**系统能力**: SystemCapability.FileManagement.PhotoAccessHelper.Core 1871 1872**需要权限:** ohos.permission.ACCESS_MEDIALIB_THUMB_DB 1873 1874**参数:** 1875 1876| 参数名 | 类型 | 必填 | 说明 | 1877| --------- | ------------ | ---- | ------- | 1878| options | [FetchOptions](arkts-apis-photoAccessHelper-i.md#fetchoptions) | 是 | 获取共享的照片资产选项。 | 1879 1880**返回值:** 1881 1882| 类型 | 说明 | 1883| ----------------------- | ------------------ | 1884| Array\<[SharedPhotoAsset](#sharedphotoasset13)\> | 返回共享的照片资产。 | 1885 1886**错误码:** 1887 1888以下错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)和[文件管理错误码](../apis-core-file-kit/errorcode-filemanagement.md)。 1889 1890| 错误码ID | 错误信息 | 1891| -------- | ---------------------------------------- | 1892| 201 | Permission denied. | 1893| 202 | Called by non-system application. | 1894| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameters types; 3. Parameter verification failed. | 1895| 14000011 | Internal system error. | 1896 1897**示例:** 1898 1899phAccessHelper的创建请参考[@ohos.file.photoAccessHelper (相册管理模块)](arkts-apis-photoAccessHelper-f.md)的示例使用。 1900 1901```ts 1902import { dataSharePredicates } from '@kit.ArkData' 1903 1904async function example(phAccessHelper: photoAccessHelper.PhotoAccessHelper) { 1905 let predicates: dataSharePredicates.DataSharePredicates = new dataSharePredicates.DataSharePredicates(); 1906 let fetchOptions: photoAccessHelper.FetchOptions = { 1907 fetchColumns: [], 1908 predicates: predicates 1909 }; 1910 1911 try { 1912 console.info('getSharedPhotoAssets test start'); 1913 phAccessHelper.getSharedPhotoAssets(fetchOptions); 1914 console.info('getSharedPhotoAssets test end'); 1915 } catch (err) { 1916 console.error(`getSharedPhotoAssets failed, error: ${err.code}, ${err.message}`); 1917 } 1918} 1919``` 1920 1921### startAssetAnalysis<sup>18+</sup> 1922 1923startAssetAnalysis(type: AnalysisType, assetUris?: Array<string>): Promise<number> 1924 1925启动资产分析服务。 1926 1927**系统接口**:此接口为系统接口。 1928 1929**系统能力**:SystemCapability.FileManagement.PhotoAccessHelper.Core 1930 1931**需要权限:** ohos.permission.WRITE_IMAGEVIDEO 1932 1933**参数:** 1934 1935| 参数名 | 类型 | 必填 | 说明 | 1936| --------- | ------------------- | ---- | ------------------------------------------------------------ | 1937| type | [AnalysisType](#analysistype11) | 是 | 需要启动的智慧分析类型。 | 1938| assetUris | Array<string> | 否 | 资产uri的数组。<br>- 填写:仅分析指定资产。<br>- 不填:全量分析。 | 1939 1940**返回值:** 1941 1942| 类型 | 说明 | 1943| --------------------- | --------------------------- | 1944| Promise<number> | Promise对象。服务的任务id。 | 1945 1946**错误码:** 1947 1948以下错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)。 1949 1950| 错误码ID | 错误信息 | 1951| -------- | ------------------------------------------------------------ | 1952| 201 | Permission denied. | 1953| 202 | Called by non-system application. | 1954| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameters types; 3. Parameter verification failed. | 1955 1956**示例:** 1957 1958phAccessHelper的创建请参考[@ohos.file.photoAccessHelper (相册管理模块)](arkts-apis-photoAccessHelper-f.md)的示例使用。 1959 1960```ts 1961async function example(context: Context) { 1962 console.info('startAssetAnalysisDemo'); 1963 try { 1964 let phAccessHelper = photoAccessHelper.getPhotoAccessHelper(context); 1965 let uris = ["file://media/Photo/14/IMG_1729066473_013/IMG_20241016_122253.jpg", 1966 "file://media/Photo/68/IMG_1729033213_018/IMG_20241016_100082.jpg"]; 1967 let taskId = await phAccessHelper.startAssetAnalysis(photoAccessHelper.AnalysisType.ANALYSIS_SEARCH_INDEX, 1968 uris); 1969 console.info('startAssetAnalysis success, taskId=' + taskId); 1970 } catch (err) { 1971 console.error('startAssetAnalysis failed, error=' + err); 1972 } 1973} 1974``` 1975 1976### createAssetsForAppWithMode<sup>12+</sup> 1977 1978createAssetsForAppWithMode(boundleName: string, appName: string, appId: string, tokenId: number, authorizationMode: AuthorizationMode, photoCreationConfigs:Array\<PhotoCreationConfig>): Promise\<Array\<string>> 1979 1980提供给应用保存短时授权,使用Promise方式返回结果。 1981 1982**系统接口**:此接口为系统接口。 1983 1984**系统能力**:SystemCapability.FileManagement.PhotoAccessHelper.Core 1985 1986**需要权限:** ohos.permission.WRITE_IMAGEVIDEO 1987 1988**参数:** 1989 1990| 参数名 | 类型 | 必填 | 说明 | 1991| -------- |----------------------------------------------------------------------| ---- | ------------------------- | 1992| boundleName| string | 是 | 需要保存图片/视频文件的应用boundleName。 | 1993| appName| string | 是 | 需要保存图片/视频文件的应用appName。| 1994| appId| string | 是 | 需要保存图片/视频文件的应用app id。 | 1995| tokenId| number| 是 | 需要短时授权应用的唯一标识。 | 1996| authorizationMode| [AuthorizationMode](#authorizationmode12)| 是 | 授权模式。授予应用短期内再次保存无需重复弹框确认。 | 1997| PhotoCreationConfig| Array\<[PhotoCreationConfig](arkts-apis-photoAccessHelper-i.md#photocreationconfig12)> | 是 | 保存图片/视频到媒体库的配置。| 1998 1999**返回值:** 2000 2001| 类型 | 说明 | 2002| --------------------------------------- | ----------------- | 2003| Promise\<Array\<string>> | Promise对象,返回给接口调用方的媒体库文件uri列表。Uri已对appId对应的应用授权,支持应用写入数据。如果生成uri异常,则返回批量创建错误码。<br>返回-3006表不允许出现非法字符;返回-2004表示图片类型和后缀不符;返回-203表示文件操作异常。| 2004 2005**错误码:** 2006 2007接口抛出错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)和[文件管理错误码](../apis-core-file-kit/errorcode-filemanagement.md)。 2008 2009| 错误码ID | 错误信息 | 2010| -------- | ---------------------------------------- | 2011| 201 | Permission denied. | 2012| 202 | Called by non-system application. | 2013| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameters types; 3. Parameter verification failed. | 2014| 14000011 | Internal system error. | 2015 2016**示例:** 2017 2018phAccessHelper的创建请参考[@ohos.file.photoAccessHelper (相册管理模块)](arkts-apis-photoAccessHelper-f.md)的示例使用。 2019 2020```ts 2021async function example(phAccessHelper: photoAccessHelper.PhotoAccessHelper) { 2022 console.info('createAssetsForAppWithModeDemo.'); 2023 2024 try { 2025 let photoCreationConfigs: Array<photoAccessHelper.PhotoCreationConfig> = [ 2026 { 2027 title: '123456', 2028 fileNameExtension: 'jpg', 2029 photoType: photoAccessHelper.PhotoType.IMAGE, 2030 subtype: photoAccessHelper.PhotoSubtype.DEFAULT, 2031 } 2032 ]; 2033 let bundleName: string = 'testBundleName'; 2034 let appName: string = 'testAppName'; 2035 let appId: string = 'testAppId'; 2036 let tokenId: number = 537197950; 2037 let authorizationMode: photoAccessHelper.AuthorizationMode = photoAccessHelper.AuthorizationMode.SHORT_TIME_AUTHORIZATION; 2038 let result: Array<string> = await phAccessHelper.createAssetsForAppWithMode(bundleName, appName, appId, tokenId, authorizationMode, photoCreationConfigs); 2039 console.info(`result: ${JSON.stringify(result)}`); 2040 console.info('Photo createAssetsForAppWithMode success.'); 2041 } catch (err) { 2042 console.error(`createAssetsForAppWithMode failed with error: ${err.code}, ${err.message}`); 2043 } 2044} 2045``` 2046 2047### getKeyFrameThumbnail<sup>18+</sup> 2048 2049getKeyFrameThumbnail(beginFrameTimeMs: number, type: ThumbnailType): Promise<image.PixelMap> 2050 2051获取视频中关键视频帧位置的指定类型缩略图,使用promise方式返回异步结果。 2052 2053**系统接口**:此接口为系统接口。 2054 2055**系统能力**:SystemCapability.FileManagement.PhotoAccessHelper.Core 2056 2057**需要权限**:ohos.permission.READ_IMAGEVIDEO 2058 2059**参数:** 2060 2061| 参数名 | 类型 | 必填 | 说明 | 2062| ---- | -------------- | ---- | ----- | 2063| beginFrameTimeMs | number | 是 | 获取视频帧的时间位置,单位ms,0:封面帧。 | 2064| type | [ThumbnailType](#thumbnailtype13)| 是 | 缩略图类型。 | 2065 2066**返回值:** 2067 2068| 类型 | 说明 | 2069| ----------------------------- | --------------------- | 2070| Promise<[image.PixelMap](../apis-image-kit/arkts-apis-image-PixelMap.md)> | Promise对象,返回缩略图的PixelMap。若获取不到,默认返回封面帧 | 2071 2072**错误码:** 2073 2074接口抛出错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)和[文件管理错误码](../apis-core-file-kit/errorcode-filemanagement.md)。 2075 2076| 错误码ID | 错误信息 | 2077| -------- | ---------------------------------------- | 2078| 201 | Permission denied. | 2079| 202 | Called by non-system application. | 2080| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types; 3. Parameter verification failed. | 2081| 14000011 | Internal system error. 2082 2083**示例:** 2084 2085phAccessHelper的创建请参考[@ohos.file.photoAccessHelper (相册管理模块)](arkts-apis-photoAccessHelper-f.md)的示例使用。 2086 2087```ts 2088import { common } from '@kit.AbilityKit'; 2089import { dataSharePredicates } from '@kit.ArkData'; 2090import { image } from '@kit.ImageKit'; 2091 2092async function example(context: Context) { 2093 try{ 2094 console.info('getKeyFrameThumbnail demo'); 2095 let phAccessHelper:photoAccessHelper.PhotoAccessHelper = photoAccessHelper.getPhotoAccessHelper(context); 2096 let predicates: dataSharePredicates.DataSharePredicates = new dataSharePredicates.DataSharePredicates(); 2097 predicates.equalTo(photoAccessHelper.PhotoKeys.PHOTO_TYPE, photoAccessHelper.PhotoType.VIDEO); 2098 let fetchOption: photoAccessHelper.FetchOptions = { 2099 fetchColumns: [], 2100 predicates: predicates 2101 }; 2102 let fetchResult: photoAccessHelper.FetchResult<photoAccessHelper.PhotoAsset> = await phAccessHelper.getAssets(fetchOption); 2103 let asset: photoAccessHelper.PhotoAsset = await fetchResult.getLastObject(); 2104 let pixelMap: image.PixelMap = await asset.getKeyFrameThumbnail(0, photoAccessHelper.ThumbnailType.LCD); 2105 console.info('getKeyFrameThumbnail success'); 2106 } catch (error) { 2107 console.error('getKeyFrameThumbnail failed, error: ' + JSON.stringify(error)); 2108 } 2109} 2110``` 2111 2112### saveGalleryFormInfo<sup>18+</sup> 2113 2114saveGalleryFormInfo(info:GalleryFormInfo):Promise<void> 2115 2116将图库卡片相关信息保存到数据库中,使用Promise方式返回结果。 2117 2118**系统接口**:此接口为系统接口。 2119 2120**需要权限**:ohos.permission.WRITE_IMAGEVIDEO 2121 2122**系统能力**:SystemCapability.FileManagement.PhotoAccessHelper.Core 2123 2124**参数:** 2125 2126| 参数名 | 类型 | 必填 | 说明 | 2127| -------- | ------------------------ | ---- | ------------------------- | 2128| info | [GalleryFormInfo](#galleryforminfo18) | 是 | 图库卡片信息,包括图库卡片的id、卡片绑定的图片或相册的uri集合。 | 2129 2130**返回值:** 2131 2132| 类型 | 说明 | 2133| --------------------------------------- | ----------------- | 2134| Promise<void>| Promise对象,返回void。 | 2135 2136**错误码:** 2137 2138以下错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)和[文件管理错误码](../apis-core-file-kit/errorcode-filemanagement.md)。 2139 2140| 错误码ID | 错误信息 | 2141| -------- | ---------------------------------------- | 2142| 201 | Permission verification failed, usually the result returned by VerifyAccessToken. | 2143| 202 | Permission verification failed, application which is not a system application uses system API. | 2144| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types; 3. Parameter verification failed. | 2145| 14000011 | System inner fail. | 2146 2147**示例:** 2148 2149```ts 2150import { dataSharePredicates } from '@kit.ArkData'; 2151import { BusinessError } from '@kit.BasicServicesKit'; 2152 2153async function example(phAccessHelper: photoAccessHelper.PhotoAccessHelper) { 2154 console.info('saveGalleryFormInfoDemo'); 2155 let predicates: dataSharePredicates.DataSharePredicates = new dataSharePredicates.DataSharePredicates(); 2156 let fetchOptions: photoAccessHelper.FetchOptions = { 2157 fetchColumns: [], 2158 predicates: predicates 2159 }; 2160 let fetchResult: photoAccessHelper.FetchResult<photoAccessHelper.PhotoAsset> = await phAccessHelper.getAssets(fetchOptions); 2161 let photoAsset: photoAccessHelper.PhotoAsset = await fetchResult.getFirstObject(); 2162 let uriList: Array<string> = [ 2163 photoAsset.uri, 2164 ]; 2165 let info: photoAccessHelper.GalleryFormInfo = { 2166 // formId是一个由纯数字组成的字符串,assetUris为图库中存在的图片或者相册的uri信息集合。 2167 formId: "20230116123", 2168 assetUris: uriList, 2169 } 2170 2171 phAccessHelper.saveGalleryFormInfo(info).then(() => { 2172 console.info('saveGalleryFormInfo successfully'); 2173 }).catch((err: BusinessError) => { 2174 console.error(`saveGalleryFormInfo failed with error: ${err.code}, ${err.message}`); 2175 }); 2176} 2177``` 2178 2179### updateGalleryFormInfo<sup>18+</sup> 2180 2181updateGalleryFormInfo(info:GalleryFormInfo):Promise<void> 2182 2183更新既存的图库卡片的相关信息,并保存到数据库中,使用Promise方式返回结果。 2184 2185**系统接口**:此接口为系统接口。 2186 2187**需要权限**:ohos.permission.WRITE_IMAGEVIDEO 2188 2189**系统能力**:SystemCapability.FileManagement.PhotoAccessHelper.Core 2190 2191**参数:** 2192 2193| 参数名 | 类型 | 必填 | 说明 | 2194| -------- | ------------------------ | ---- | ------------------------- | 2195| info | [GalleryFormInfo](#galleryforminfo18) | 是 | 图库卡片信息,包括图库卡片的id、卡片绑定的图片或相册的uri集合。 | 2196 2197**返回值:** 2198 2199| 类型 | 说明 | 2200| --------------------------------------- | ----------------- | 2201| Promise<void>| Promise对象,返回void。 | 2202 2203**错误码:** 2204 2205以下错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)和[文件管理错误码](../apis-core-file-kit/errorcode-filemanagement.md)。 2206 2207| 错误码ID | 错误信息 | 2208| -------- | ---------------------------------------- | 2209| 201 | Permission verification failed, usually the result returned by VerifyAccessToken. | 2210| 202 | Permission verification failed, application which is not a system application uses system API. | 2211| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types; 3. Parameter verification failed. | 2212| 14000011 | System inner fail. | 2213 2214**示例:** 2215 2216```ts 2217import { dataSharePredicates } from '@kit.ArkData'; 2218import { BusinessError } from '@kit.BasicServicesKit'; 2219 2220async function example(phAccessHelper: photoAccessHelper.PhotoAccessHelper) { 2221 console.info('updateGalleryFormInfoDemo'); 2222 let predicates: dataSharePredicates.DataSharePredicates = new dataSharePredicates.DataSharePredicates(); 2223 let fetchOptions: photoAccessHelper.FetchOptions = { 2224 fetchColumns: [], 2225 predicates: predicates 2226 }; 2227 let fetchResult: photoAccessHelper.FetchResult<photoAccessHelper.PhotoAsset> = await phAccessHelper.getAssets(fetchOptions); 2228 let photoAsset: photoAccessHelper.PhotoAsset = await fetchResult.getFirstObject(); 2229 let photoAssetLast: photoAccessHelper.PhotoAsset = await fetchResult.getLastObject(); 2230 let uriList: Array<string> = [ 2231 photoAsset.uri, 2232 photoAssetLast.uri 2233 ]; 2234 let info: photoAccessHelper.GalleryFormInfo = { 2235 // formId是一个由纯数字组成的字符串,assetUris为图库中存在的图片或者相册的uri信息集合。 2236 formId: "20230116123", 2237 assetUris: uriList, 2238 } 2239 2240 phAccessHelper.updateGalleryFormInfo(info).then(() => { 2241 console.info('updateGalleryFormInfo successfully'); 2242 }).catch((err: BusinessError) => { 2243 console.error(`updateGalleryFormInfo failed with error: ${err.code}, ${err.message}`); 2244 }); 2245} 2246``` 2247 2248### removeGalleryFormInfo<sup>18+</sup> 2249 2250removeGalleryFormInfo(info:GalleryFormInfo):Promise<void> 2251 2252从数据库中删除图库卡片信息,使用Promise方式返回结果。 2253 2254**系统接口**:此接口为系统接口。 2255 2256**需要权限**:ohos.permission.WRITE_IMAGEVIDEO 2257 2258**系统能力**:SystemCapability.FileManagement.PhotoAccessHelper.Core 2259 2260**参数:** 2261 2262| 参数名 | 类型 | 必填 | 说明 | 2263| -------- | ------------------------ | ---- | ------------------------- | 2264| info | [GalleryFormInfo](#galleryforminfo18) | 是 | 图库卡片信息,包括图库卡片的id、卡片绑定的图片或相册的uri集合。 | 2265 2266**返回值:** 2267 2268| 类型 | 说明 | 2269| --------------------------------------- | ----------------- | 2270| Promise<void>| Promise对象,返回void。 | 2271 2272**错误码:** 2273 2274以下错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)和[文件管理错误码](../apis-core-file-kit/errorcode-filemanagement.md)。 2275 2276| 错误码ID | 错误信息 | 2277| -------- | ---------------------------------------- | 2278| 201 | Permission verification failed, usually the result returned by VerifyAccessToken. | 2279| 202 | Permission verification failed, application which is not a system application uses system API. | 2280| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types; 3. Parameter verification failed. | 2281| 14000011 | System inner fail. | 2282 2283**示例:** 2284 2285```ts 2286import { BusinessError } from '@kit.BasicServicesKit'; 2287 2288async function example(phAccessHelper: photoAccessHelper.PhotoAccessHelper) { 2289 console.info('removeGalleryFormInfoDemo'); 2290 let info: photoAccessHelper.GalleryFormInfo = { 2291 // formId是一个由纯数字组成的字符串,移除卡片时assertUris不填。 2292 formId: "20230116123" 2293 } 2294 2295 phAccessHelper.removeGalleryFormInfo(info).then(() => { 2296 console.info('removeGalleryFormInfo successfully'); 2297 }).catch((err: BusinessError) => { 2298 console.error(`removeGalleryFormInfo failed with error: ${err.code}, ${err.message}`); 2299 }); 2300} 2301``` 2302 2303 2304### getAlbumsByIds<sup>18+</sup> 2305 2306getAlbumsByIds(albumIds: Array<number>): Promise<Map<number, Album>> 2307 2308通过相册id查询相册信息。使用Promise异步回调。 2309 2310**系统接口**:此接口为系统接口。 2311 2312**系统能力**:SystemCapability.FileManagement.PhotoAccessHelper.Core 2313 2314**需要权限:** ohos.permission.READ_IMAGEVIDEO 2315 2316**参数:** 2317 2318| 参数名 | 类型 | 必填 | 说明 | 2319| --------- | ------------------- | ---- | ------------------------------------------------------------ | 2320| albumIds | Array<number> | 是 | 相册id列表。 | 2321 2322**返回值:** 2323 2324| 类型 | 说明 | 2325| --------------------- | --------------------------- | 2326| Promise<Map<number, Album>> | Promise对象。返回相册信息map对象。 | 2327 2328**错误码:** 2329 2330以下错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)和[文件管理错误码](../apis-core-file-kit/errorcode-filemanagement.md)。 2331 2332| 错误码ID | 错误信息 | 2333| -------- | ------------------------------------------------------------ | 2334| 201 | Permission denied. | 2335| 202 | Called by non-system application. | 2336| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameters types; 3. Parameter verification failed. | 2337| 14000011 | Internal system error. | 2338 2339**示例:** 2340 2341phAccessHelper的创建请参考[@ohos.file.photoAccessHelper (相册管理模块)](arkts-apis-photoAccessHelper-f.md)的示例使用。 2342 2343```ts 2344async function example(phAccessHelper: photoAccessHelper.PhotoAccessHelper) { 2345 console.info('startGetAlbumsByIdsDemo'); 2346 2347 try { 2348 // 获取需要保存到媒体库的位于应用沙箱的图片/视频uri。 2349 let albumIds: Array<number> = [ 2350 12 // 实际场景请使用albumId 2351 ]; 2352 let map: Map<number, photoAccessHelper.Album> = await phAccessHelper.getAlbumsByIds(albumIds); 2353 console.info('getAlbumsByIds success, size is ' + map.size); 2354 } catch (err) { 2355 console.error('getAlbumsByIds failed, errCode is ' + err.code + ', errMsg is ' + err.message); 2356 } 2357} 2358``` 2359 2360### createAssetsForAppWithAlbum<sup>18+</sup> 2361 2362createAssetsForAppWithAlbum(source: PhotoCreationSource, albumUri: string, isAuthorized: boolean, photoCreationConfigs: Array<PhotoCreationConfig>): Promise<Array<string>> 2363 2364为应用自己或者其他应用创建资产到指定来源或者用户相册。使用Promise异步回调。 2365 2366**系统接口**:此接口为系统接口。 2367 2368**系统能力**:SystemCapability.FileManagement.PhotoAccessHelper.Core 2369 2370**需要权限:** ohos.permission.WRITE_IMAGEVIDEO 2371 2372**参数:** 2373 2374| 参数名 | 类型 | 必填 | 说明 | 2375| --------- | ------------------- | ---- | ------------------------------------------------------------ | 2376| source | [PhotoCreationSource](#photocreationsource18) | 是 | 代替应用创建资产传入的应用信息。 | 2377| albumUri | string | 是 | 相册uri。 | 2378| isAuthorized | boolean | 是 | 是否授权其他应用。true表示授权,false表示不授权。 | 2379| PhotoCreationConfigs| Array\<[PhotoCreationConfig](arkts-apis-photoAccessHelper-i.md#photocreationconfig12)> | 是 | 保存图片/视频到媒体库的配置。| 2380 2381**返回值:** 2382 2383| 类型 | 说明 | 2384| --------------------- | --------------------------- | 2385| Promise<Array<string>> | Promise对象,返回接口调用方的媒体库文件uri列表。<br>uri已对appId对应的应用授权,支持应用写入数据。如果生成uri异常,则返回批量创建错误码。<br>返回-3006表示不允许出现非法字符;返回-2004表示图片类型和后缀不符;返回-203表示文件操作异常。 | 2386 2387**错误码:** 2388 2389以下错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)和[文件管理错误码](../apis-core-file-kit/errorcode-filemanagement.md)。 2390 2391| 错误码ID | 错误信息 | 2392| -------- | ------------------------------------------------------------ | 2393| 201 | Permission denied. | 2394| 202 | Called by non-system application. | 2395| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameters types; 3. Parameter verification failed. | 2396| 14000011 | Internal system error. | 2397 2398**示例:** 2399 2400phAccessHelper的创建请参考[@ohos.file.photoAccessHelper (相册管理模块)](arkts-apis-photoAccessHelper-f.md)的示例使用。 2401 2402```ts 2403async function example(phAccessHelper: photoAccessHelper.PhotoAccessHelper) { 2404 console.info('createAssetsForAppWithAlbumDemo.'); 2405 2406 try { 2407 let source: photoAccessHelper.PhotoCreationSource = { 2408 bundleName: 'testBundleName', 2409 appName: 'testAppName', 2410 appId: 'testAppId', 2411 tokenId: 537197950, 2412 } 2413 let albumUri: string = 'file://media/PhotoAlbum/10'; 2414 let isAuthorized: boolean = true; 2415 let photoCreationConfigs: Array<photoAccessHelper.PhotoCreationConfig> = [ 2416 { 2417 title: 'test', 2418 fileNameExtension: 'jpg', 2419 photoType: photoAccessHelper.PhotoType.IMAGE, 2420 subtype: photoAccessHelper.PhotoSubtype.DEFAULT, 2421 } 2422 ]; 2423 let desFileUris: Array<string> = await phAccessHelper.createAssetsForAppWithAlbum(source, albumUri, isAuthorized, photoCreationConfigs); 2424 console.info('createAssetsForAppWithAlbum success, data is ' + desFileUris); 2425 } catch (err) { 2426 console.error(`createAssetsForAppWithAlbum failed with error: ${err.code}, ${err.message}`); 2427 } 2428} 2429``` 2430 2431### on('hiddenPhotoChange')<sup>20+</sup> 2432 2433on(type: 'hiddenPhotoChange', callback: Callback<PhotoAssetChangeInfos>): void 2434 2435注册'hiddenPhotoChange'监听隐藏的媒体资产,并通过callback方式返回隐藏资产变化结果,可以注册多个callback。 2436 2437**系统接口**:此接口为系统接口。 2438 2439**系统能力**:SystemCapability.FileManagement.PhotoAccessHelper.Core 2440 2441**需要权限**:ohos.permission.READ_IMAGEVIDEO 和 ohos.permission.MANAGE_PRIVATE_PHOTOS 2442 2443**参数:** 2444 2445| 参数名 | 类型 | 必填 | 说明 | 2446|-----------|-------------------------|-----------|-----------------| 2447| type | string | 是 | 注册监听隐藏资产,取值为'hiddenPhotoChange'。注册完成后,有隐藏资产发生变化时,通过callback返回变更信息。 | 2448| callback | Callback<[PhotoAssetChangeInfos](arkts-apis-photoAccessHelper-i.md#photoassetchangeinfos20)> | 是 | 返回变更的隐藏媒体资产信息[PhotoAssetChangeInfos](arkts-apis-photoAccessHelper-i.md#photoassetchangeinfos20)。<br>**注意:** 该接口可以注册多个不同的callback监听,[off('hiddenPhotoChange')](#offhiddenphotochange20)即可以关闭所有监听,也可以关闭指定callback监听。 | 2449 2450**错误码:** 2451 2452以下错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)和[媒体库错误码](errcode-medialibrary.md)。 2453 2454| 错误码ID | 错误信息 | 2455| -------- | ---------------------------------------- | 2456| 201 | Permission denied. | 2457| 202 | Called by non-system application. | 2458| 23800151 | The scenario parameter verification fails.<br>Possible causes: 1. The type is not fixed at 'hiddenPhotoChange'; 2. The same callback is registered repeatedly. | 2459| 23800301 | Internal system error. You are advised to retry and check the logs.<br>Possible causes: 1. The database is corrupted. 2. The file system is abnormal. 3. The IPC request timed out. | 2460 2461**示例:** 2462 2463phAccessHelper的创建请参考[@ohos.file.photoAccessHelper (相册管理模块)](arkts-apis-photoAccessHelper-f.md)的示例使用。 2464 2465```ts 2466import { dataSharePredicates } from '@kit.ArkData' 2467 2468let onCallback1 = (changeData: photoAccessHelper.PhotoAssetChangeInfos) => { 2469 console.info('onCallback1 success, changData: ' + JSON.stringify(changeData)); 2470 // file had changed, do something. 2471} 2472let onCallback2 = (changeData: photoAccessHelper.PhotoAssetChangeInfos) => { 2473 console.info('onCallback2 success, changData: ' + JSON.stringify(changeData)); 2474 // file had changed, do something. 2475} 2476 2477async function example(phAccessHelper: photoAccessHelper.PhotoAccessHelper){ 2478 console.info('onHiddenPhotoChangeDemo.'); 2479 2480 try { 2481 // 注册onCallback1监听。 2482 phAccessHelper.on('hiddenPhotoChange', onCallback1); 2483 // 注册onCallback2监听。 2484 phAccessHelper.on('hiddenPhotoChange', onCallback2); 2485 } catch (error) { 2486 console.error('onHiddenPhotoChange failed, errCode is', error); 2487 } 2488} 2489``` 2490 2491### off('hiddenPhotoChange')<sup>20+</sup> 2492 2493off(type: 'hiddenPhotoChange', callback?: Callback<PhotoAssetChangeInfos>): void 2494 2495取消对'hiddenPhotoChange'隐藏资产的监听。存在多个callback监听时,可以取消指定注册的callback监听;不指定callback时取消所有监听。 2496 2497**系统接口**:此接口为系统接口。 2498 2499**系统能力**:SystemCapability.FileManagement.PhotoAccessHelper.Core 2500 2501**需要权限**:ohos.permission.READ_IMAGEVIDEO 和 ohos.permission.MANAGE_PRIVATE_PHOTOS 2502 2503**参数:** 2504 2505| 参数名 | 类型 | 必填 | 说明 | 2506|-----------|-------------------------|-----------|-----------------| 2507| type | string | 是 | 取消监听隐藏资产,取值为'hiddenPhotoChange'。取消监听后,有隐藏资产发生变化时,不再通过callback返回变更信息。 | 2508| callback | Callback<[PhotoAssetChangeInfos](arkts-apis-photoAccessHelper-i.md#photoassetchangeinfos20)> | 否 | 取消[on('hiddenPhotoChange')](#onhiddenphotochange20)注册时指定的callback监听;不填时,则取消对'hiddenPhotoChange'的所有监听。<br>**注意:** 取消注册的callback后,有隐藏资产发生变化时,不会进入此回调。 | 2509 2510**错误码:** 2511 2512以下错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)和[媒体库错误码](errcode-medialibrary.md)。 2513 2514| 错误码ID | 错误信息 | 2515| -------- | ---------------------------------------- | 2516| 201 | Permission denied. | 2517| 202 | Called by non-system application. | 2518| 23800151 | The scenario parameter verification fails.<br>Possible causes: 1. The type is not fixed at 'hiddenPhotoChange'; 2. The same callback is unregistered repeatedly. | 2519| 23800301 | Internal system error. You are advised to retry and check the logs.<br>Possible causes: 1. The database is corrupted. 2. The file system is abnormal. 3. The IPC request timed out. | 2520 2521**示例:** 2522 2523phAccessHelper的创建请参考[@ohos.file.photoAccessHelper (相册管理模块)](arkts-apis-photoAccessHelper-f.md)的示例使用。 2524 2525```ts 2526import { dataSharePredicates } from '@kit.ArkData' 2527 2528let onCallback1 = (changeData: photoAccessHelper.PhotoAssetChangeInfos) => { 2529 console.info('onCallback1 success, changData: ' + JSON.stringify(changeData)); 2530 // file had changed, do something. 2531} 2532let onCallback2 = (changeData: photoAccessHelper.PhotoAssetChangeInfos) => { 2533 console.info('onCallback2 success, changData: ' + JSON.stringify(changeData)); 2534 // file had changed, do something. 2535} 2536 2537async function example(phAccessHelper: photoAccessHelper.PhotoAccessHelper){ 2538 console.info('offHiddenPhotoChangeDemo.'); 2539 2540 try { 2541 // 注册onCallback1监听。 2542 phAccessHelper.on('hiddenPhotoChange', onCallback1); 2543 // 注册onCallback2监听。 2544 phAccessHelper.on('hiddenPhotoChange', onCallback2); 2545 2546 // 关闭onCallback1监听,onCallback2继续监听。 2547 phAccessHelper.off('hiddenPhotoChange', onCallback1); 2548 } catch (error) { 2549 console.error('offHiddenPhotoChange failed, errCode is', error); 2550 } 2551} 2552``` 2553 2554### on('trashedPhotoChange')<sup>20+</sup> 2555 2556on(type: 'trashedPhotoChange', callback: Callback<PhotoAssetChangeInfos>): void 2557 2558注册'trashedPhotoChange'监听回收站的媒体资产,并通过callback方式返回回收站资产变化结果,可以注册多个callback。 2559 2560**系统接口**:此接口为系统接口。 2561 2562**系统能力**:SystemCapability.FileManagement.PhotoAccessHelper.Core 2563 2564**需要权限**:ohos.permission.READ_IMAGEVIDEO 2565 2566**参数:** 2567 2568| 参数名 | 类型 | 必填 | 说明 | 2569|-----------|-------------------------|-----------|-----------------| 2570| type | string | 是 | 注册监听回收站资产,取值为'trashedPhotoChange'。注册完成后,有回收站资产发生变化时,通过callback返回变更信息。 | 2571| callback | Callback<[PhotoAssetChangeInfos](arkts-apis-photoAccessHelper-i.md#photoassetchangeinfos20)> | 是 | 返回变更的回收站媒体资产信息[PhotoAssetChangeInfos](arkts-apis-photoAccessHelper-i.md#photoassetchangeinfos20)。<br>**注意:** 该接口可以注册多个不同的callback监听,[off('trashedPhotoChange')](#offtrashedphotochange20)即可以关闭所有监听,也可以关闭指定callback监听。 | 2572 2573**错误码:** 2574 2575以下错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)和[媒体库错误码](errcode-medialibrary.md)。 2576 2577| 错误码ID | 错误信息 | 2578| -------- | ---------------------------------------- | 2579| 201 | Permission denied. | 2580| 202 | Called by non-system application. | 2581| 23800151 | The scenario parameter verification fails.<br>Possible causes: 1. The type is not fixed at 'trashedPhotoChange'; 2. The same callback is registered repeatedly. | 2582| 23800301 | Internal system error. You are advised to retry and check the logs.<br>Possible causes: 1. The database is corrupted. 2. The file system is abnormal. 3. The IPC request timed out. | 2583 2584**示例:** 2585 2586phAccessHelper的创建请参考[@ohos.file.photoAccessHelper (相册管理模块)](arkts-apis-photoAccessHelper-f.md)的示例使用。 2587 2588```ts 2589import { dataSharePredicates } from '@kit.ArkData' 2590 2591let onCallback1 = (changeData: photoAccessHelper.PhotoAssetChangeInfos) => { 2592 console.info('onCallback1 success, changData: ' + JSON.stringify(changeData)); 2593 // file had changed, do something. 2594} 2595let onCallback2 = (changeData: photoAccessHelper.PhotoAssetChangeInfos) => { 2596 console.info('onCallback2 success, changData: ' + JSON.stringify(changeData)); 2597 // file had changed, do something. 2598} 2599 2600async function example(phAccessHelper: photoAccessHelper.PhotoAccessHelper, context: Context){ 2601 console.info('onTrashedPhotoChangeDemo.'); 2602 2603 try { 2604 // 注册onCallback1监听。 2605 phAccessHelper.on('trashedPhotoChange', onCallback1); 2606 // 注册onCallback2监听。 2607 phAccessHelper.on('trashedPhotoChange', onCallback2); 2608 } catch (error) { 2609 console.error('onTrashedPhotoChangeDemo failed, errCode is', error); 2610 } 2611} 2612``` 2613 2614### off('trashedPhotoChange')<sup>20+</sup> 2615 2616off(type: 'trashedPhotoChange', callback?: Callback<PhotoAssetChangeInfos>): void 2617 2618取消对'trashedPhotoChange'回收站资产的监听。存在多个callback监听时,可以取消指定注册的callback监听;不指定callback时取消所有监听。 2619 2620**系统接口**:此接口为系统接口。 2621 2622**系统能力**:SystemCapability.FileManagement.PhotoAccessHelper.Core 2623 2624**需要权限**:ohos.permission.READ_IMAGEVIDEO 2625 2626**参数:** 2627 2628| 参数名 | 类型 | 必填 | 说明 | 2629|-----------|-------------------------|-----------|-----------------| 2630| type | string | 是 | 取消监听回收站资产,取值为'trashedPhotoChange'。取消监听后,有回收站资产发生变化时,不再通过callback返回变更信息。 | 2631| callback | Callback<[PhotoAssetChangeInfos](arkts-apis-photoAccessHelper-i.md#photoassetchangeinfos20)> | 否 | 取消[on('trashedPhotoChange')](#ontrashedphotochange20)注册时指定的callback监听;不填时,则取消对'trashedPhotoChange'的所有监听。<br>**注意:** 取消注册的callback后,有回收站资产发生变化时,不会进入此回调。 | 2632 2633**错误码:** 2634 2635以下错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)和[媒体库错误码](errcode-medialibrary.md)。 2636 2637| 错误码ID | 错误信息 | 2638| -------- | ---------------------------------------- | 2639| 201 | Permission denied. | 2640| 202 | Called by non-system application. | 2641| 23800151 | The scenario parameter verification fails.<br>Possible causes: 1. The type is not fixed at 'trashedPhotoChange'; 2. The same callback is unregistered repeatedly. | 2642| 23800301 | Internal system error. You are advised to retry and check the logs.<br>Possible causes: 1. The database is corrupted. 2. The file system is abnormal. 3. The IPC request timed out. | 2643 2644**示例:** 2645 2646phAccessHelper的创建请参考[@ohos.file.photoAccessHelper (相册管理模块)](arkts-apis-photoAccessHelper-f.md)的示例使用。 2647 2648```ts 2649import { dataSharePredicates } from '@kit.ArkData' 2650 2651let onCallback1 = (changeData: photoAccessHelper.PhotoAssetChangeInfos) => { 2652 console.info('onCallback1 success, changData: ' + JSON.stringify(changeData)); 2653 // file had changed, do something. 2654} 2655let onCallback2 = (changeData: photoAccessHelper.PhotoAssetChangeInfos) => { 2656 console.info('onCallback2 success, changData: ' + JSON.stringify(changeData)); 2657 // file had changed, do something. 2658} 2659 2660async function example(phAccessHelper: photoAccessHelper.PhotoAccessHelper, context: Context){ 2661 console.info('offTrashedPhotoChangeDemo.'); 2662 2663 try { 2664 // 注册onCallback1监听。 2665 phAccessHelper.on('trashedPhotoChange', onCallback1); 2666 // 注册onCallback2监听。 2667 phAccessHelper.on('trashedPhotoChange', onCallback2); 2668 2669 // 关闭onCallback1监听,onCallback2继续监听。 2670 phAccessHelper.off('trashedPhotoChange', onCallback1); 2671 } catch (error) { 2672 console.error('offTrashedPhotoChangeDemo failed, errCode is', error); 2673 } 2674} 2675``` 2676 2677### on('hiddenAlbumChange')<sup>20+</sup> 2678 2679on(type: 'hiddenAlbumChange', callback: Callback<AlbumChangeInfos>): void 2680 2681注册'hiddenAlbumChange'监听隐藏相册,并通过callback方式返回相册变化结果,可以注册多个callback。 2682 2683**系统接口**:此接口为系统接口。 2684 2685**系统能力**:SystemCapability.FileManagement.PhotoAccessHelper.Core 2686 2687**需要权限**:ohos.permission.READ_IMAGEVIDEO 和 ohos.permission.MANAGE_PRIVATE_PHOTOS 2688 2689**参数:** 2690 2691| 参数名 | 类型 | 必填 | 说明 | 2692|-----------|-------------------------|-----------|-----------------| 2693| type | string | 是 | 注册监听隐藏相册,取值为'hiddenAlbumChange'。注册完成后,有隐藏相册发生变化时,通过callback返回变更信息。 | 2694| callback | Callback<[AlbumChangeInfos](arkts-apis-photoAccessHelper-i.md#albumchangeinfos20)> | 是 | 返回变更的隐藏相册信息[AlbumChangeInfos](arkts-apis-photoAccessHelper-i.md#albumchangeinfos20)。<br>**注意:** 该接口可以注册多个不同的callback监听,[off('hiddenAlbumChange')](#offhiddenalbumchange20)即可以关闭所有监听,也可以关闭指定callback监听。 | 2695 2696**错误码:** 2697 2698以下错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)和[媒体库错误码](errcode-medialibrary.md)。 2699 2700| 错误码ID | 错误信息 | 2701| -------- | ---------------------------------------- | 2702| 201 | Permission denied. | 2703| 202 | Called by non-system application. | 2704| 23800151 | The scenario parameter verification fails.<br>Possible causes: 1. The type is not fixed at 'hiddenAlbumChange'; 2. The same callback is registered repeatedly. | 2705| 23800301 | Internal system error. You are advised to retry and check the logs.<br>Possible causes: 1. The database is corrupted. 2. The file system is abnormal. 3. The IPC request timed out. | 2706 2707**示例:** 2708 2709phAccessHelper的创建请参考[@ohos.file.photoAccessHelper (相册管理模块)](arkts-apis-photoAccessHelper-f.md)的示例使用。 2710 2711```ts 2712import { dataSharePredicates } from '@kit.ArkData' 2713 2714let onCallback1 = (changeData: photoAccessHelper.AlbumChangeInfos) => { 2715 console.info('onCallback1 success, changData: ' + JSON.stringify(changeData)); 2716 // file had changed, do something. 2717} 2718let onCallback2 = (changeData: photoAccessHelper.AlbumChangeInfos) => { 2719 console.info('onCallback2 success, changData: ' + JSON.stringify(changeData)); 2720 // file had changed, do something. 2721} 2722 2723async function example(phAccessHelper: photoAccessHelper.PhotoAccessHelper){ 2724 console.info('onHiddenAlbumChangeDemo.'); 2725 2726 try { 2727 // 注册onCallback1监听。 2728 phAccessHelper.on('hiddenAlbumChange', onCallback1); 2729 // 注册onCallback2监听。 2730 phAccessHelper.on('hiddenAlbumChange', onCallback2); 2731 } catch (error) { 2732 console.error('onHiddenAlbumChangeDemo failed, errCode is', error); 2733 } 2734} 2735``` 2736 2737### off('hiddenAlbumChange')<sup>20+</sup> 2738 2739off(type: 'hiddenAlbumChange', callback?: Callback<AlbumChangeInfos>): void 2740 2741取消对'hiddenAlbumChange'隐藏相册的监听。存在多个callback监听时,可以取消指定注册的callback监听;不指定callback时取消所有监听。 2742 2743**系统接口**:此接口为系统接口。 2744 2745**系统能力**:SystemCapability.FileManagement.PhotoAccessHelper.Core 2746 2747**需要权限**:ohos.permission.READ_IMAGEVIDEO 和 ohos.permission.MANAGE_PRIVATE_PHOTOS 2748 2749**参数:** 2750 2751| 参数名 | 类型 | 必填 | 说明 | 2752|-----------|-------------------------|-----------|-----------------| 2753| type | string | 是 | 取消监听隐藏相册,取值为'hiddenAlbumChange'。取消监听后,有隐藏相册发生变化时,不再通过callback返回变更信息。 | 2754| callback | Callback<[AlbumChangeInfos](arkts-apis-photoAccessHelper-i.md#albumchangeinfos20)> | 否 | 取消[on('hiddenAlbumChange')](#onhiddenalbumchange20)注册时指定的callback监听;不填时,则取消对'hiddenAlbumChange'的所有监听。<br>**注意:** 取消注册的callback后,有隐藏相册发生变化时,不会进入此回调。 | 2755 2756**错误码:** 2757 2758以下错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)和[媒体库错误码](errcode-medialibrary.md)。 2759 2760| 错误码ID | 错误信息 | 2761| -------- | ---------------------------------------- | 2762| 201 | Permission denied. | 2763| 202 | Called by non-system application. | 2764| 23800151 | The scenario parameter verification fails.<br>Possible causes: 1. The type is not fixed at 'hiddenAlbumChange'; 2. The same callback is unregistered repeatedly. | 2765| 23800301 | Internal system error. You are advised to retry and check the logs.<br>Possible causes: 1. The database is corrupted. 2. The file system is abnormal. 3. The IPC request timed out. | 2766 2767**示例:** 2768 2769phAccessHelper的创建请参考[@ohos.file.photoAccessHelper (相册管理模块)](arkts-apis-photoAccessHelper-f.md)的示例使用。 2770 2771```ts 2772import { dataSharePredicates } from '@kit.ArkData' 2773 2774let onCallback1 = (changeData: photoAccessHelper.AlbumChangeInfos) => { 2775 console.info('onCallback1 success, changData: ' + JSON.stringify(changeData)); 2776 // file had changed, do something. 2777} 2778let onCallback2 = (changeData: photoAccessHelper.AlbumChangeInfos) => { 2779 console.info('onCallback2 success, changData: ' + JSON.stringify(changeData)); 2780 // file had changed, do something. 2781} 2782 2783async function example(phAccessHelper: photoAccessHelper.PhotoAccessHelper){ 2784 console.info('onHiddenAlbumChangeDemo.'); 2785 2786 try { 2787 // 注册onCallback1监听。 2788 phAccessHelper.on('hiddenAlbumChange', onCallback1); 2789 // 注册onCallback2监听。 2790 phAccessHelper.on('hiddenAlbumChange', onCallback2); 2791 2792 // 关闭onCallback1监听,onCallback2继续监听。 2793 phAccessHelper.off('hiddenAlbumChange', onCallback1); 2794 } catch (error) { 2795 console.error('onHiddenAlbumChangeDemo failed, errCode is', error); 2796 } 2797} 2798``` 2799 2800### on('trashedAlbumChange')<sup>20+</sup> 2801 2802on(type: 'trashedAlbumChange', callback: Callback<AlbumChangeInfos>): void 2803 2804注册'trashedAlbumChange'监听回收站相册,并通过callback方式返回相册变化结果,可以注册多个callback。 2805 2806**系统接口**:此接口为系统接口。 2807 2808**系统能力**:SystemCapability.FileManagement.PhotoAccessHelper.Core 2809 2810**需要权限**:ohos.permission.READ_IMAGEVIDEO 2811 2812**参数:** 2813 2814| 参数名 | 类型 | 必填 | 说明 | 2815|-----------|-------------------------|-----------|-----------------| 2816| type | string | 是 | 注册监听回收站相册,取值为'trashedAlbumChange'。注册完成后,有回收站相册发生变化时,通过callback返回变更信息。 | 2817| callback | Callback<[AlbumChangeInfos](arkts-apis-photoAccessHelper-i.md#albumchangeinfos20)> | 是 | 返回变更的相册信息[AlbumChangeInfos](arkts-apis-photoAccessHelper-i.md#albumchangeinfos20)。<br>**注意:** 该接口可以注册多个不同的callback监听,[off('trashedAlbumChange')](#offtrashedalbumchange20)即可以关闭所有监听,也可以关闭指定callback监听。 | 2818 2819**错误码:** 2820 2821以下错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)和[媒体库错误码](errcode-medialibrary.md)。 2822 2823| 错误码ID | 错误信息 | 2824| -------- | ---------------------------------------- | 2825| 201 | Permission denied. | 2826| 202 | Called by non-system application. | 2827| 23800151 | The scenario parameter verification fails.<br>Possible causes: 1. The type is not fixed at 'trashedAlbumChange'; 2. The same callback is registered repeatedly. | 2828| 23800301 | Internal system error. You are advised to retry and check the logs.<br>Possible causes: 1. The database is corrupted. 2. The file system is abnormal. 3. The IPC request timed out. | 2829 2830**示例:** 2831 2832phAccessHelper的创建请参考[@ohos.file.photoAccessHelper (相册管理模块)](arkts-apis-photoAccessHelper-f.md)的示例使用。 2833 2834```ts 2835import { dataSharePredicates } from '@kit.ArkData' 2836 2837let onCallback1 = (changeData: photoAccessHelper.AlbumChangeInfos) => { 2838 console.info('onCallback1 success, changData: ' + JSON.stringify(changeData)); 2839 // file had changed, do something. 2840} 2841let onCallback2 = (changeData: photoAccessHelper.AlbumChangeInfos) => { 2842 console.info('onCallback2 success, changData: ' + JSON.stringify(changeData)); 2843 // file had changed, do something. 2844} 2845 2846async function example(phAccessHelper: photoAccessHelper.PhotoAccessHelper, context: Context){ 2847 console.info('onTrashedAlbumChangeDemo.'); 2848 2849 try { 2850 // 注册onCallback1监听。 2851 phAccessHelper.on('trashedAlbumChange', onCallback1); 2852 // 注册onCallback2监听。 2853 phAccessHelper.on('trashedAlbumChange', onCallback2); 2854 } catch (error) { 2855 console.error('onTrashedAlbumChangeDemo failed, errCode is', error); 2856 } 2857} 2858``` 2859 2860### off('trashedAlbumChange')<sup>20+</sup> 2861 2862off(type: 'trashedAlbumChange', callback?: Callback<AlbumChangeInfos>): void 2863 2864取消对'trashedAlbumChange'回收站相册的监听。存在多个callback监听时,可以取消指定注册的callback监听;不指定callback时取消所有监听。 2865 2866**系统接口**:此接口为系统接口。 2867 2868**系统能力**:SystemCapability.FileManagement.PhotoAccessHelper.Core 2869 2870**需要权限**:ohos.permission.READ_IMAGEVIDEO 2871 2872**参数:** 2873 2874| 参数名 | 类型 | 必填 | 说明 | 2875|-----------|-------------------------|-----------|-----------------| 2876| type | string | 是 | 取消监听回收站相册,取值为'trashedAlbumChange'。取消监听后,有回收站相册发生变化时,不再通过callback返回变更信息。 | 2877| callback | Callback<[AlbumChangeInfos](arkts-apis-photoAccessHelper-i.md#albumchangeinfos20)> | 否 | 取消[on('trashedAlbumChange')](#ontrashedalbumchange20)注册时指定的callback监听;不填时,则取消对'trashedAlbumChange'的所有监听。<br>**注意:** 取消注册的callback后,有回收站相册发生变化时,不会进入此回调。 | 2878 2879**错误码:** 2880 2881以下错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)和[媒体库错误码](errcode-medialibrary.md)。 2882 2883| 错误码ID | 错误信息 | 2884| -------- | ---------------------------------------- | 2885| 201 | Permission denied. | 2886| 202 | Called by non-system application. | 2887| 23800151 | The scenario parameter verification fails.<br>Possible causes: 1. The type is not fixed at 'trashedAlbumChange'; 2. The same callback is unregistered repeatedly. | 2888| 23800301 | Internal system error. You are advised to retry and check the logs.<br>Possible causes: 1. The database is corrupted. 2. The file system is abnormal. 3. The IPC request timed out. | 2889 2890**示例:** 2891 2892phAccessHelper的创建请参考[@ohos.file.photoAccessHelper (相册管理模块)](arkts-apis-photoAccessHelper-f.md)的示例使用。 2893 2894```ts 2895import { dataSharePredicates } from '@kit.ArkData' 2896 2897let onCallback1 = (changeData: photoAccessHelper.AlbumChangeInfos) => { 2898 console.info('onCallback1 success, changData: ' + JSON.stringify(changeData)); 2899 // file had changed, do something. 2900} 2901let onCallback2 = (changeData: photoAccessHelper.AlbumChangeInfos) => { 2902 console.info('onCallback2 success, changData: ' + JSON.stringify(changeData)); 2903 // file had changed, do something. 2904} 2905 2906async function example(phAccessHelper: photoAccessHelper.PhotoAccessHelper, context: Context){ 2907 console.info('onTrashedAlbumChangeDemo.'); 2908 2909 try { 2910 // 注册onCallback1监听。 2911 phAccessHelper.on('trashedAlbumChange', onCallback1); 2912 // 注册onCallback2监听。 2913 phAccessHelper.on('trashedAlbumChange', onCallback2); 2914 2915 // 关闭onCallback1监听,onCallback2继续监听。 2916 phAccessHelper.off('trashedAlbumChange', onCallback1); 2917 } catch (error) { 2918 console.error('onTrashedAlbumChangeDemo failed, errCode is', error); 2919 } 2920} 2921``` 2922 2923### getPhotoAlbums<sup>20+</sup> 2924 2925getPhotoAlbums(options?: FetchOptions): Promise<FetchResult<Album>> 2926 2927根据指定的选项获取系统、用户和来源相册。使用Promise异步回调。 2928 2929在获取相册之前,确保相册已存在。 2930 2931**系统接口**:此接口为系统接口。 2932 2933**需要权限:** ohos.permission.READ_IMAGEVIDEO 2934 2935**系统能力**:SystemCapability.FileManagement.PhotoAccessHelper.Core 2936 2937**参数:** 2938 2939| 参数名 | 类型 | 必填 | 说明 | 2940| --------- | ------------------- | ---- | ------------------------------------------------------------ | 2941| options | [FetchOptions](arkts-apis-photoAccessHelper-i.md#fetchoptions) | 否 | 检索选项,不填时默认根据相册类型检索。 | 2942 2943**返回值:** 2944 2945| 类型 | 说明 | 2946| --------------------- | --------------------------- | 2947| Promise<[FetchResult](arkts-apis-photoAccessHelper-FetchResult.md)<[Album](#album)>> | Promise对象,返回获取相册的结果集。 | 2948 2949**错误码:** 2950 2951以下错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)和[媒体库错误码](errcode-medialibrary.md)。 2952 2953| 错误码ID | 错误信息 | 2954| -------- | ------------------------------------------------------------ | 2955| 201 | Permission denied. | 2956| 202 | Called by non-system application. | 2957| 23800301 | Internal system error. It is recommended to retry and check the logs.<br>Possible causes: 1. Database corrupted; 2. The file system is abnormal; 3. The IPC request timed out. | 2958 2959 2960**示例:** 2961 2962phAccessHelper的创建请参考[photoAccessHelper.getPhotoAccessHelper](arkts-apis-photoAccessHelper-f.md#photoaccesshelpergetphotoaccesshelper)的示例使用。 2963 2964```ts 2965import { dataSharePredicates } from '@kit.ArkData'; 2966import { BusinessError } from '@kit.BasicServicesKit'; 2967 2968async function example(phAccessHelper: photoAccessHelper.PhotoAccessHelper) { 2969 console.info('getPhotoAlbumsDemo'); 2970 let predicates: dataSharePredicates.DataSharePredicates = new dataSharePredicates.DataSharePredicates(); 2971 let fetchOptions: photoAccessHelper.FetchOptions = { 2972 fetchColumns: [], 2973 predicates: predicates 2974 }; 2975 phAccessHelper.getPhotoAlbums(fetchOptions).then( async (fetchResult) => { 2976 if (fetchResult === undefined) { 2977 console.error('getPhotoAlbumsPromise fetchResult is undefined'); 2978 return; 2979 } 2980 let albums: photoAccessHelper.Album[] = await fetchResult.getAllObjects(); 2981 console.info(`getPhotoAlbumsPromise successfully, albums length: ${albums.length}`); 2982 fetchResult.close(); 2983 }).catch((err: BusinessError) => { 2984 console.error(`getPhotoAlbumsPromise failed with err: ${err.code}, ${err.message}`); 2985 }); 2986} 2987``` 2988 2989### getPhotoAlbumOrder<sup>20+</sup> 2990 2991getPhotoAlbumOrder(orderStyle: number, options?: FetchOptions): Promise<FetchResult<AlbumOrder>> 2992 2993获取系统、用户和来源相册的排序信息。使用Promise异步回调。 2994 2995**系统接口**:此接口为系统接口。 2996 2997**需要权限:** ohos.permission.READ_IMAGEVIDEO 2998 2999**系统能力**:SystemCapability.FileManagement.PhotoAccessHelper.Core 3000 3001**参数:** 3002 3003| 参数名 | 类型 | 必填 | 说明 | 3004| --------- | ------------------- | ---- | ------------------------------------------------------------ | 3005| orderStyle | number | 是 | 选择相册的排序风格。<br>0:Phone风格。1:PC风格。 | 3006| options | [FetchOptions](arkts-apis-photoAccessHelper-i.md#fetchoptions) | 否 | 检索选项,不填时默认根据相册类型检索。 | 3007 3008**返回值:** 3009 3010| 类型 | 说明 | 3011| --------------------- | --------------------------- | 3012| Promise<[FetchResult](arkts-apis-photoAccessHelper-FetchResult.md)<[AlbumOrder](#albumorder20)>> | Promise对象,返回获取相册排序的结果集。 | 3013 3014**错误码:** 3015 3016以下错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)和[媒体库错误码](errcode-medialibrary.md)。 3017 3018| 错误码ID | 错误信息 | 3019| -------- | ------------------------------------------------------------ | 3020| 201 | Permission denied. | 3021| 202 | Called by non-system application. | 3022| 23800151 | The scenario parameter verification fails.<br>Possible causes: 1. The input parameter is not within the valid range. | 3023| 23800301 | Internal system error. It is recommended to retry and check the logs.<br>Possible causes: 1. Database corrupted; 2. The file system is abnormal; 3. The IPC request timed out. | 3024 3025**示例:** 3026 3027phAccessHelper的创建请参考[photoAccessHelper.getPhotoAccessHelper](arkts-apis-photoAccessHelper-f.md#photoaccesshelpergetphotoaccesshelper)的示例使用。 3028 3029```ts 3030import { dataSharePredicates } from '@kit.ArkData'; 3031import { BusinessError } from '@kit.BasicServicesKit'; 3032 3033async function example(phAccessHelper: photoAccessHelper.PhotoAccessHelper) { 3034 console.info('getPhotoAlbumOrderDemo'); 3035 let predicates: dataSharePredicates.DataSharePredicates = new dataSharePredicates.DataSharePredicates(); 3036 let fetchOptions: photoAccessHelper.FetchOptions = { 3037 fetchColumns: [], 3038 predicates: predicates 3039 }; 3040 let orderStyle: number = 0; 3041 phAccessHelper.getPhotoAlbumOrder(orderStyle, fetchOptions).then( async (fetchResult) => { 3042 if (fetchResult === undefined) { 3043 console.error('getPhotoAlbumOrderPromise fetchResult is undefined'); 3044 return; 3045 } 3046 let albumOrders: photoAccessHelper.AlbumOrder[] = await fetchResult.getAllObjects(); 3047 console.info(`getPhotoAlbumOrderPromise successfully, albumOrders length: ${albumOrders.length}`); 3048 fetchResult.close(); 3049 }).catch((err: BusinessError) => { 3050 console.error(`getPhotoAlbumOrderPromise failed with err: ${err.code}, ${err.message}`); 3051 }); 3052} 3053``` 3054 3055### setPhotoAlbumOrder<sup>20+</sup> 3056 3057setPhotoAlbumOrder(orderStyle: number, albumOrders: Array<AlbumOrder>): Promise<void> 3058 3059设置系统、用户和来源相册的排序。使用Promise异步回调。 3060 3061**系统接口**:此接口为系统接口。 3062 3063**需要权限:** ohos.permission.WRITE_IMAGEVIDEO 3064 3065**系统能力**:SystemCapability.FileManagement.PhotoAccessHelper.Core 3066 3067**参数:** 3068 3069| 参数名 | 类型 | 必填 | 说明 | 3070| --------- | ------------------- | ---- | ------------------------------------------------------------ | 3071| orderStyle | number | 是 | 选择相册的排序风格。<br>0:Phone风格。1:PC风格。 | 3072| albumOrders | Array<[AlbumOrder](#albumorder20)> | 是 | 待设置的相册排序结果数组。 | 3073 3074**返回值:** 3075 3076| 类型 | 说明 | 3077| --------------------- | --------------------------- | 3078| Promise&lt;void&gt;| Promise对象,无返回结果。 | 3079 3080**错误码:** 3081 3082以下错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)和[媒体库错误码](errcode-medialibrary.md)。 3083 3084| 错误码ID | 错误信息 | 3085| -------- | ------------------------------------------------------------ | 3086| 201 | Permission denied. | 3087| 202 | Called by non-system application. | 3088| 23800151 | The scenario parameter verification fails.<br>Possible causes: 1. The input parameter is not within the valid range. | 3089| 23800301 | Internal system error. It is recommended to retry and check the logs.<br>Possible causes: 1. Database corrupted; 2. The file system is abnormal; 3. The IPC request timed out. | 3090 3091**示例:** 3092 3093phAccessHelper的创建请参考[photoAccessHelper.getPhotoAccessHelper](arkts-apis-photoAccessHelper-f.md#photoaccesshelpergetphotoaccesshelper)的示例使用。 3094 3095```ts 3096import { dataSharePredicates } from '@kit.ArkData'; 3097import { BusinessError } from '@kit.BasicServicesKit'; 3098 3099async function example(phAccessHelper: photoAccessHelper.PhotoAccessHelper) { 3100 console.info('setPhotoAlbumOrderDemo'); 3101 let predicates: dataSharePredicates.DataSharePredicates = new dataSharePredicates.DataSharePredicates(); 3102 let fetchOptions: photoAccessHelper.FetchOptions = { 3103 fetchColumns: [], 3104 predicates: predicates 3105 }; 3106 let orderStyle: number = 0; 3107 phAccessHelper.getPhotoAlbumOrder(orderStyle, fetchOptions).then( async (fetchResult) => { 3108 if (fetchResult === undefined) { 3109 console.error('getPhotoAlbumOrderPromise fetchResult is undefined'); 3110 return; 3111 } 3112 let albumOrder: photoAccessHelper.AlbumOrder = await fetchResult.getFirstObject(); 3113 albumOrder.albumOrder = 10; 3114 albumOrder.orderSection = 0; 3115 albumOrder.orderType = 1; 3116 albumOrder.orderStatus = 1; 3117 await phAccessHelper.setPhotoAlbumOrder(orderStyle, [albumOrder]); 3118 console.info('setPhotoAlbumOrderPromise successfully.'); 3119 fetchResult.close(); 3120 }).catch((err: BusinessError) => { 3121 console.error(`setPhotoAlbumOrderPromise failed with err: ${err.code}, ${err.message}`); 3122 }); 3123} 3124``` 3125 3126## PhotoAsset 3127 3128提供封装文件属性的方法。 3129 3130### open<sup>(deprecated)</sup> 3131 3132open(mode: string, callback: AsyncCallback<number>): void 3133 3134打开当前文件,使用callback方式返回异步结果。 3135 3136> **说明:** 3137> 3138> 从API version 10开始支持,从API version 11开始废弃。出于安全考量,不再提供获取正式媒体文件句柄的接口。 3139 3140**注意**:当前此(写)操作是互斥的操作,返回的文件描述符在使用完毕后需要调用close进行释放。 3141 3142**系统接口**:此接口为系统接口。 3143 3144**需要权限**:ohos.permission.READ_IMAGEVIDEO 或 ohos.permission.WRITE_IMAGEVIDEO 3145 3146**系统能力**:SystemCapability.FileManagement.PhotoAccessHelper.Core 3147 3148**参数:** 3149 3150| 参数名 | 类型 | 必填 | 说明 | 3151| -------- | --------------------------- | ---- | ----------------------------------- | 3152| mode | string | 是 | 打开文件方式,分别为:'r'(只读), 'w'(只写), 'rw'(读写)。 | 3153| callback | AsyncCallback<number> | 是 | callback返回文件描述符。 | 3154 3155**错误码:** 3156 3157接口抛出错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)和[文件管理错误码](../apis-core-file-kit/errorcode-filemanagement.md)。 3158 3159错误码13900012,请参考[开发准备](../../media/medialibrary/photoAccessHelper-preparation.md)。 3160 3161| 错误码ID | 错误信息 | 3162| -------- | ---------------------------------------- | 3163| 202 | Called by non-system application. | 3164| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types; 3. Parameter verification failed. | 3165| 13900012 | Permission denied. | 3166| 13900020 | Invalid argument. | 3167| 14000011 | System inner fail. Possible causes: 1. The database is corrupted; 2. The file system is abnormal; 3. The IPC request timed out; 4. Permission denied. | 3168 3169**示例:** 3170 3171phAccessHelper的创建请参考[@ohos.file.photoAccessHelper (相册管理模块)](arkts-apis-photoAccessHelper-f.md)的示例使用。 3172 3173```ts 3174async function example(phAccessHelper: photoAccessHelper.PhotoAccessHelper) { 3175 console.info('Open demo'); 3176 let testFileName: string = 'testFile' + Date.now() + '.jpg'; 3177 let photoAsset: photoAccessHelper.PhotoAsset = await phAccessHelper.createAsset(testFileName); 3178 photoAsset.open('rw', (err, fd) => { 3179 if (fd !== undefined) { 3180 console.info('File fd' + fd); 3181 photoAsset.close(fd); 3182 } else { 3183 console.error(`Open file err: ${err.code}, ${err.message}`); 3184 } 3185 }); 3186} 3187``` 3188 3189### open<sup>(deprecated)</sup> 3190 3191open(mode: string): Promise<number> 3192 3193打开当前文件,使用promise方式返回异步结果。 3194 3195> **说明:** 3196> 3197> 从API version 10开始支持,从API version 11开始废弃。出于安全考量,不再提供获取正式媒体文件句柄的接口。 3198 3199**注意**:当前此(写)操作是互斥的操作,返回的文件描述符在使用完毕后需要调用close进行释放。 3200 3201**系统接口**:此接口为系统接口。 3202 3203**需要权限**:ohos.permission.READ_IMAGEVIDEO 或 ohos.permission.WRITE_IMAGEVIDEO 3204 3205**系统能力**:SystemCapability.FileManagement.PhotoAccessHelper.Core 3206 3207**参数:** 3208 3209| 参数名 | 类型 | 必填 | 说明 | 3210| ---- | ------ | ---- | ----------------------------------- | 3211| mode | string | 是 | 打开文件方式,分别为:'r'(只读), 'w'(只写), 'rw'(读写)。 | 3212 3213**返回值:** 3214 3215| 类型 | 说明 | 3216| --------------------- | ------------- | 3217| Promise<number> | Promise对象,返回文件描述符。 | 3218 3219**错误码:** 3220 3221接口抛出错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)和[文件管理错误码](../apis-core-file-kit/errorcode-filemanagement.md)。 3222 3223错误码13900012,请参考[开发准备](../../media/medialibrary/photoAccessHelper-preparation.md)。 3224 3225| 错误码ID | 错误信息 | 3226| -------- | ---------------------------------------- | 3227| 202 | Called by non-system application. | 3228| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types; 3. Parameter verification failed. | 3229| 13900012 | Permission denied. | 3230| 13900020 | Invalid argument. | 3231| 14000011 | System inner fail. Possible causes: 1. The database is corrupted; 2. The file system is abnormal; 3. The IPC request timed out; 4. Permission denied. | 3232 3233**示例:** 3234 3235phAccessHelper的创建请参考[@ohos.file.photoAccessHelper (相册管理模块)](arkts-apis-photoAccessHelper-f.md)的示例使用。 3236 3237```ts 3238async function example(phAccessHelper: photoAccessHelper.PhotoAccessHelper) { 3239 console.info('Open demo'); 3240 try { 3241 let testFileName: string = 'testFile' + Date.now() + '.jpg'; 3242 let photoAsset: photoAccessHelper.PhotoAsset = await phAccessHelper.createAsset(testFileName); 3243 let fd: number = await photoAsset.open('rw'); 3244 if (fd !== undefined) { 3245 console.info('File fd' + fd); 3246 photoAsset.close(fd); 3247 } else { 3248 console.error('Open file fail'); 3249 } 3250 } catch (err) { 3251 console.error(`Open demo err: ${err.code}, ${err.message}`); 3252 } 3253} 3254``` 3255 3256### setFavorite<sup>(deprecated)</sup> 3257 3258setFavorite(favoriteState: boolean, callback: AsyncCallback<void>): void 3259 3260将文件设置为收藏文件,使用callback方式返回异步结果。 3261 3262> **说明:** 3263> 3264> 从API version 10开始支持,从API version 11开始废弃。建议使用[MediaAssetChangeRequest.setFavorite](#setfavorite11)替代。 3265 3266**系统接口**:此接口为系统接口。 3267 3268**需要权限**:ohos.permission.WRITE_IMAGEVIDEO 3269 3270**系统能力**:SystemCapability.FileManagement.PhotoAccessHelper.Core 3271 3272**参数:** 3273 3274| 参数名 | 类型 | 必填 | 说明 | 3275| ---------- | ------------------------- | ---- | ---------------------------------- | 3276| favoriteState | boolean | 是 | 是否设置为收藏文件, true:设置为收藏文件,false:取消收藏。 | 3277| callback | AsyncCallback<void> | 是 | callback返回void。 | 3278 3279**错误码:** 3280 3281接口抛出错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)和[文件管理错误码](../apis-core-file-kit/errorcode-filemanagement.md)。 3282 3283错误码201,请参考[开发准备](../../media/medialibrary/photoAccessHelper-preparation.md)。 3284 3285| 错误码ID | 错误信息 | 3286| -------- | ---------------------------------------- | 3287| 201 | Permission denied. | 3288| 202 | Called by non-system application. | 3289| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types; 3. Parameter verification failed. | 3290| 13900020 | Invalid argument. | 3291| 14000011 | System inner fail. | 3292 3293**示例:** 3294 3295phAccessHelper的创建请参考[@ohos.file.photoAccessHelper (相册管理模块)](arkts-apis-photoAccessHelper-f.md)的示例使用。 3296 3297```ts 3298import { dataSharePredicates } from '@kit.ArkData'; 3299 3300async function example(phAccessHelper: photoAccessHelper.PhotoAccessHelper) { 3301 console.info('setFavoriteDemo'); 3302 let predicates: dataSharePredicates.DataSharePredicates = new dataSharePredicates.DataSharePredicates(); 3303 let fetchOption: photoAccessHelper.FetchOptions = { 3304 fetchColumns: [], 3305 predicates: predicates 3306 }; 3307 let fetchResult: photoAccessHelper.FetchResult<photoAccessHelper.PhotoAsset> = await phAccessHelper.getAssets(fetchOption); 3308 let asset = await fetchResult.getFirstObject(); 3309 asset.setFavorite(true, (err) => { 3310 if (err === undefined) { 3311 console.info('favorite successfully'); 3312 } else { 3313 console.error(`favorite failed with error: ${err.code}, ${err.message}`); 3314 } 3315 }); 3316} 3317``` 3318 3319### setFavorite<sup>(deprecated)</sup> 3320 3321setFavorite(favoriteState: boolean): Promise<void> 3322 3323将文件设置为收藏文件,使用promise方式返回异步结果。 3324 3325> **说明:** 3326> 3327> 从API version 10开始支持,从API version 11开始废弃。建议使用[MediaAssetChangeRequest.setFavorite](#setfavorite11)替代。 3328 3329**系统接口**:此接口为系统接口。 3330 3331**需要权限**:ohos.permission.WRITE_IMAGEVIDEO 3332 3333**系统能力**:SystemCapability.FileManagement.PhotoAccessHelper.Core 3334 3335**参数:** 3336 3337| 参数名 | 类型 | 必填 | 说明 | 3338| ---------- | ------- | ---- | ---------------------------------- | 3339| favoriteState | boolean | 是 | 是否设置为收藏文件, true:设置为收藏文件,false:取消收藏。 | 3340 3341**返回值:** 3342 3343| 类型 | 说明 | 3344| ------------------- | ---------- | 3345| Promise<void> | Promise对象,返回void。 | 3346 3347**错误码:** 3348 3349接口抛出错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)和[文件管理错误码](../apis-core-file-kit/errorcode-filemanagement.md)。 3350 3351错误码201,请参考[开发准备](../../media/medialibrary/photoAccessHelper-preparation.md)。 3352 3353| 错误码ID | 错误信息 | 3354| -------- | ---------------------------------------- | 3355| 201 | Permission denied. | 3356| 202 | Called by non-system application. | 3357| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types; 3. Parameter verification failed. | 3358| 13900020 | Invalid argument. | 3359| 14000011 | System inner fail. | 3360 3361**示例:** 3362 3363phAccessHelper的创建请参考[@ohos.file.photoAccessHelper (相册管理模块)](arkts-apis-photoAccessHelper-f.md)的示例使用。 3364 3365```ts 3366import { dataSharePredicates } from '@kit.ArkData'; 3367import { BusinessError } from '@kit.BasicServicesKit'; 3368 3369async function example(phAccessHelper: photoAccessHelper.PhotoAccessHelper) { 3370 console.info('setFavoriteDemo'); 3371 let predicates: dataSharePredicates.DataSharePredicates = new dataSharePredicates.DataSharePredicates(); 3372 let fetchOption: photoAccessHelper.FetchOptions = { 3373 fetchColumns: [], 3374 predicates: predicates 3375 }; 3376 let fetchResult: photoAccessHelper.FetchResult<photoAccessHelper.PhotoAsset> = await phAccessHelper.getAssets(fetchOption); 3377 let asset = await fetchResult.getFirstObject(); 3378 asset.setFavorite(true).then(() => { 3379 console.info('setFavorite successfully'); 3380 }).catch((err: BusinessError) => { 3381 console.error(`setFavorite failed with error: ${err.code}, ${err.message}`); 3382 }); 3383} 3384``` 3385 3386### setHidden<sup>(deprecated)</sup> 3387 3388setHidden(hiddenState: boolean, callback: AsyncCallback<void>): void 3389 3390将文件设置为隐私文件,使用callback方式返回异步结果。 3391 3392隐私文件存在隐私相册中,用户通过隐私相册去获取隐私文件后可以通过设置hiddenState为false来从隐私相册中移除。 3393 3394> **说明:** 3395> 3396> 从API version 10开始支持,从API version 11开始废弃。建议使用[MediaAssetChangeRequest.setHidden](#sethidden11)替代。 3397 3398**系统接口**:此接口为系统接口。 3399 3400**需要权限**:ohos.permission.WRITE_IMAGEVIDEO 3401 3402**系统能力**:SystemCapability.FileManagement.PhotoAccessHelper.Core 3403 3404**参数:** 3405 3406| 参数名 | 类型 | 必填 | 说明 | 3407| ---------- | ------------------------- | ---- | ---------------------------------- | 3408| hiddenState | boolean | 是 | 是否设置为隐藏文件,true:将文件资产放入隐藏相册;false:从隐藏相册中恢复。 | 3409| callback | AsyncCallback<void> | 是 | callback返回void。 | 3410 3411**错误码:** 3412 3413接口抛出错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)和[文件管理错误码](../apis-core-file-kit/errorcode-filemanagement.md)。 3414 3415错误码201,请参考[开发准备](../../media/medialibrary/photoAccessHelper-preparation.md)。 3416 3417| 错误码ID | 错误信息 | 3418| -------- | ---------------------------------------- | 3419| 201 | Permission denied. | 3420| 202 | Called by non-system application. | 3421| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types; 3. Parameter verification failed. | 3422| 13900020 | Invalid argument. | 3423| 14000011 | System inner fail. | 3424 3425**示例:** 3426 3427phAccessHelper的创建请参考[@ohos.file.photoAccessHelper (相册管理模块)](arkts-apis-photoAccessHelper-f.md)的示例使用。 3428 3429```ts 3430import { dataSharePredicates } from '@kit.ArkData'; 3431 3432async function example(phAccessHelper: photoAccessHelper.PhotoAccessHelper) { 3433 console.info('setHiddenDemo'); 3434 let predicates: dataSharePredicates.DataSharePredicates = new dataSharePredicates.DataSharePredicates(); 3435 let fetchOption: photoAccessHelper.FetchOptions = { 3436 fetchColumns: [], 3437 predicates: predicates 3438 }; 3439 let fetchResult: photoAccessHelper.FetchResult<photoAccessHelper.PhotoAsset> = await phAccessHelper.getAssets(fetchOption); 3440 let asset = await fetchResult.getFirstObject(); 3441 asset.setHidden(true, (err) => { 3442 if (err === undefined) { 3443 console.info('setHidden successfully'); 3444 } else { 3445 console.error(`setHidden failed with error: ${err.code}, ${err.message}`); 3446 } 3447 }); 3448} 3449``` 3450 3451### setHidden<sup>(deprecated)</sup> 3452 3453setHidden(hiddenState: boolean): Promise<void> 3454 3455将文件设置为隐私文件,使用promise方式返回异步结果。 3456 3457隐私文件存在隐私相册中,用户通过隐私相册去获取隐私文件后可以通过设置hiddenState为false来从隐私相册中移除。 3458 3459> **说明:** 3460> 3461> 从API version 10开始支持,从API version 11开始废弃。建议使用[MediaAssetChangeRequest.setHidden](#sethidden11)替代。 3462 3463**系统接口**:此接口为系统接口。 3464 3465**需要权限**:ohos.permission.WRITE_IMAGEVIDEO 3466 3467**系统能力**:SystemCapability.FileManagement.PhotoAccessHelper.Core 3468 3469**参数:** 3470 3471| 参数名 | 类型 | 必填 | 说明 | 3472| ---------- | ------- | ---- | ---------------------------------- | 3473| hiddenState | boolean | 是 | 是否设置为隐藏文件,true:将文件资产放入隐藏相册;false:从隐藏相册中恢复。 | 3474 3475**返回值:** 3476 3477| 类型 | 说明 | 3478| ------------------- | ---------- | 3479| Promise<void> | Promise对象,返回void。 | 3480 3481**错误码:** 3482 3483接口抛出错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)和[文件管理错误码](../apis-core-file-kit/errorcode-filemanagement.md)。 3484 3485错误码201,请参考[开发准备](../../media/medialibrary/photoAccessHelper-preparation.md)。 3486 3487| 错误码ID | 错误信息 | 3488| -------- | ---------------------------------------- | 3489| 201 | Permission denied. | 3490| 202 | Called by non-system application. | 3491| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types; 3. Parameter verification failed. | 3492| 13900020 | Invalid argument. | 3493| 14000011 | System inner fail. | 3494 3495**示例:** 3496 3497phAccessHelper的创建请参考[@ohos.file.photoAccessHelper (相册管理模块)](arkts-apis-photoAccessHelper-f.md)的示例使用。 3498 3499```ts 3500import { dataSharePredicates } from '@kit.ArkData'; 3501import { BusinessError } from '@kit.BasicServicesKit'; 3502 3503async function example(phAccessHelper: photoAccessHelper.PhotoAccessHelper) { 3504 // 示例代码为将文件从隐藏相册中恢复,需要先在隐藏相册预置资源。 3505 console.info('setHiddenDemo'); 3506 let predicates: dataSharePredicates.DataSharePredicates = new dataSharePredicates.DataSharePredicates(); 3507 let fetchOption: photoAccessHelper.FetchOptions = { 3508 fetchColumns: [], 3509 predicates: predicates 3510 }; 3511 let albumList: photoAccessHelper.FetchResult<photoAccessHelper.Album> = await phAccessHelper.getAlbums(photoAccessHelper.AlbumType.SYSTEM, photoAccessHelper.AlbumSubtype.HIDDEN); 3512 let album = await albumList.getFirstObject(); 3513 let fetchResult: photoAccessHelper.FetchResult<photoAccessHelper.PhotoAsset> = await album.getAssets(fetchOption); 3514 let asset = await fetchResult.getFirstObject(); 3515 asset.setHidden(false).then(() => { 3516 console.info('setHidden successfully'); 3517 }).catch((err: BusinessError) => { 3518 console.error(`setHidden failed with error: ${err.code}, ${err.message}`); 3519 }); 3520} 3521``` 3522 3523### getExif 3524 3525getExif(): Promise<string> 3526 3527返回jpg格式图片Exif标签组成的json格式的字符串,该方法使用Promise方式返回结果。 3528 3529此接口中获取的Exif标签信息是由[image](../apis-image-kit/arkts-apis-image.md)模块提供。Exif标签详细信息请参考[image.PropertyKey](../apis-image-kit/arkts-apis-image-e.md#propertykey7)。 3530 3531**注意**:此接口返回的是Exif标签组成的json格式的字符串,完整Exif信息由all_exif与[PhotoKeys.USER_COMMENT](#photokeys)组成,fetchColumns需要传入这两个字段。 3532 3533**系统接口**:此接口为系统接口。 3534 3535**需要权限**:ohos.permission.READ_IMAGEVIDEO 3536 3537**系统能力**:SystemCapability.FileManagement.PhotoAccessHelper.Core 3538 3539**返回值:** 3540 3541| 类型 | 说明 | 3542| --------------------------------------- | ----------------- | 3543| Promise<string> | 返回Exif标签组成的json格式的字符串。 | 3544 3545**错误码:** 3546 3547接口抛出错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)和[文件管理错误码](../apis-core-file-kit/errorcode-filemanagement.md)。 3548 3549错误码13900012,请参考[开发准备](../../media/medialibrary/photoAccessHelper-preparation.md)。 3550 3551| 错误码ID | 错误信息 | 3552| -------- | ---------------------------------------- | 3553| 202 | Called by non-system application. | 3554| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types. | 3555| 13900012 | Permission denied. | 3556| 13900020 | Invalid argument. | 3557| 14000011 | System inner fail. | 3558 3559**示例:** 3560 3561phAccessHelper的创建请参考[@ohos.file.photoAccessHelper (相册管理模块)](arkts-apis-photoAccessHelper-f.md)的示例使用。 3562 3563```ts 3564import { dataSharePredicates } from '@kit.ArkData'; 3565 3566async function example(phAccessHelper: photoAccessHelper.PhotoAccessHelper) { 3567 try { 3568 console.info('getExifDemo'); 3569 let predicates: dataSharePredicates.DataSharePredicates = new dataSharePredicates.DataSharePredicates(); 3570 let fetchOptions: photoAccessHelper.FetchOptions = { 3571 fetchColumns: [ 'all_exif', photoAccessHelper.PhotoKeys.USER_COMMENT], 3572 predicates: predicates 3573 }; 3574 let fetchResult: photoAccessHelper.FetchResult<photoAccessHelper.PhotoAsset> = await phAccessHelper.getAssets(fetchOptions); 3575 let photoAsset: photoAccessHelper.PhotoAsset = await fetchResult.getFirstObject(); 3576 let exifMessage = await photoAsset.getExif(); 3577 let userCommentKey = 'UserComment'; 3578 let userComment = JSON.stringify(JSON.parse(exifMessage), [userCommentKey]); 3579 console.info('getExifDemo userComment: ' + JSON.stringify(userComment)); 3580 fetchResult.close(); 3581 } catch (err) { 3582 console.error(`getExifDemoCallback failed with error: ${err.code}, ${err.message}`); 3583 } 3584} 3585``` 3586 3587### getExif 3588 3589getExif(callback: AsyncCallback<string>): void 3590 3591返回jpg格式图片Exif标签组成的json格式的字符串,使用callback方式返回异步结果。 3592 3593此接口中获取的Exif标签信息是由[image](../apis-image-kit/arkts-apis-image.md)模块提供。Exif标签详细信息请参考[image.PropertyKey](../apis-image-kit/arkts-apis-image-e.md#propertykey7)。 3594 3595**注意**:此接口返回的是Exif标签组成的json格式的字符串,完整Exif信息由all_exif与[PhotoKeys.USER_COMMENT](#photokeys)组成,fetchColumns需要传入这两个字段。 3596 3597**系统接口**:此接口为系统接口。 3598 3599**需要权限**:ohos.permission.READ_IMAGEVIDEO 3600 3601**系统能力**:SystemCapability.FileManagement.PhotoAccessHelper.Core 3602 3603**参数:** 3604 3605| 参数名 | 类型 | 必填 | 说明 | 3606| -------- | ------------------------- | ---- | ---------- | 3607| callback | AsyncCallback<string> | 是 | 返回Exif字段组成的json格式的字符串。 | 3608 3609**错误码:** 3610 3611接口抛出错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)和[文件管理错误码](../apis-core-file-kit/errorcode-filemanagement.md)。 3612 3613错误码13900012,请参考[开发准备](../../media/medialibrary/photoAccessHelper-preparation.md)。 3614 3615| 错误码ID | 错误信息 | 3616| -------- | ---------------------------------------- | 3617| 202 | Called by non-system application. | 3618| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types. | 3619| 13900012 | Permission denied. | 3620| 13900020 | Invalid argument. | 3621| 14000011 | System inner fail. | 3622 3623**示例:** 3624 3625phAccessHelper的创建请参考[@ohos.file.photoAccessHelper (相册管理模块)](arkts-apis-photoAccessHelper-f.md)的示例使用。 3626 3627```ts 3628import { dataSharePredicates } from '@kit.ArkData'; 3629 3630async function example(phAccessHelper: photoAccessHelper.PhotoAccessHelper) { 3631 try { 3632 console.info('getExifDemo'); 3633 let predicates: dataSharePredicates.DataSharePredicates = new dataSharePredicates.DataSharePredicates(); 3634 predicates.isNotNull('all_exif') 3635 let fetchOptions: photoAccessHelper.FetchOptions = { 3636 fetchColumns: ['all_exif', photoAccessHelper.PhotoKeys.USER_COMMENT], 3637 predicates: predicates 3638 }; 3639 let fetchResult: photoAccessHelper.FetchResult<photoAccessHelper.PhotoAsset> = await phAccessHelper.getAssets(fetchOptions); 3640 let photoAsset: photoAccessHelper.PhotoAsset = await fetchResult.getFirstObject(); 3641 console.info('getExifDemo photoAsset displayName: ' + JSON.stringify(photoAsset.displayName)); 3642 let userCommentKey = 'UserComment'; 3643 photoAsset.getExif((err, exifMessage) => { 3644 if (exifMessage !== undefined) { 3645 let userComment = JSON.stringify(JSON.parse(exifMessage), [userCommentKey]); 3646 console.info('getExifDemo userComment: ' + JSON.stringify(userComment)); 3647 } else { 3648 console.error(`getExif failed, error: ${err.code}, ${err.message}`); 3649 } 3650 }); 3651 fetchResult.close(); 3652 } catch (err) { 3653 console.error(`getExifDemoCallback failed with error: ${err.code}, ${err.message}`); 3654 } 3655} 3656``` 3657 3658### setUserComment<sup>(deprecated)</sup> 3659 3660setUserComment(userComment: string): Promise<void> 3661 3662修改图片或者视频的备注信息,该方法使用Promise来返回结果。 3663 3664> **说明:** 3665> 3666> 从API version 10开始支持,从API version 11开始废弃。建议使用[MediaAssetChangeRequest.setUserComment](#setusercomment11)替代。 3667 3668**注意**:此接口只可修改图片或者视频的备注信息。 3669 3670**系统接口**:此接口为系统接口。 3671 3672**需要权限**:ohos.permission.WRITE_IMAGEVIDEO 3673 3674**系统能力**:SystemCapability.FileManagement.PhotoAccessHelper.Core 3675 3676**参数:** 3677 3678| 参数名 | 类型 | 必填 | 说明 | 3679| -------- | ------------------------- | ---- | ---------- | 3680| userComment | string | 是 | 待修改的图片或视频的备注信息,备注信息最长为420字符。 | 3681 3682**返回值:** 3683 3684| 类型 | 说明 | 3685| --------------------------------------- | ----------------- | 3686|Promise<void> | Promise对象,返回void。 | 3687 3688**错误码:** 3689 3690接口抛出错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)和[文件管理错误码](../apis-core-file-kit/errorcode-filemanagement.md)。 3691 3692错误码201,请参考[开发准备](../../media/medialibrary/photoAccessHelper-preparation.md)。 3693 3694| 错误码ID | 错误信息 | 3695| -------- | ---------------------------------------- | 3696| 201 | Permission denied. | 3697| 202 | Called by non-system application. | 3698| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types; 3. Parameter verification failed. | 3699| 13900020 | Invalid argument. | 3700| 14000011 | System inner fail. | 3701 3702**示例:** 3703 3704phAccessHelper的创建请参考[@ohos.file.photoAccessHelper (相册管理模块)](arkts-apis-photoAccessHelper-f.md)的示例使用。 3705 3706```ts 3707import { dataSharePredicates } from '@kit.ArkData'; 3708 3709async function example(phAccessHelper: photoAccessHelper.PhotoAccessHelper) { 3710 try { 3711 console.info('setUserCommentDemo') 3712 let predicates: dataSharePredicates.DataSharePredicates = new dataSharePredicates.DataSharePredicates(); 3713 let fetchOptions: photoAccessHelper.FetchOptions = { 3714 fetchColumns: [], 3715 predicates: predicates 3716 }; 3717 let fetchResult: photoAccessHelper.FetchResult<photoAccessHelper.PhotoAsset> = await phAccessHelper.getAssets(fetchOptions); 3718 let photoAsset: photoAccessHelper.PhotoAsset = await fetchResult.getFirstObject(); 3719 let userComment = 'test_set_user_comment'; 3720 await photoAsset.setUserComment(userComment); 3721 } catch (err) { 3722 console.error(`setUserCommentDemoPromise failed with error: ${err.code}, ${err.message}`); 3723 } 3724} 3725``` 3726 3727### setUserComment<sup>(deprecated)</sup> 3728 3729setUserComment(userComment: string, callback: AsyncCallback<void>): void 3730 3731修改图片或者视频的备注信息,该方法使用callback形式来返回结果。 3732 3733> **说明:** 3734> 3735> 从API version 10开始支持,从API version 11开始废弃。建议使用[MediaAssetChangeRequest.setUserComment](#setusercomment11)替代。 3736 3737**注意**:此接口只可修改图片或者视频的备注信息。 3738 3739**系统接口**:此接口为系统接口。 3740 3741**需要权限**:ohos.permission.WRITE_IMAGEVIDEO 3742 3743**系统能力**:SystemCapability.FileManagement.PhotoAccessHelper.Core 3744 3745**参数:** 3746 3747| 参数名 | 类型 | 必填 | 说明 | 3748| -------- | ------------------------- | ---- | ---------- | 3749| userComment | string | 是 | 待修改的图片或视频的备注信息,备注信息最长为420字符。 | 3750| callback | AsyncCallback<void> | 是 | callback返回void。 | 3751 3752**错误码:** 3753 3754接口抛出错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)和[文件管理错误码](../apis-core-file-kit/errorcode-filemanagement.md)。 3755 3756错误码201,请参考[开发准备](../../media/medialibrary/photoAccessHelper-preparation.md)。 3757 3758| 错误码ID | 错误信息 | 3759| -------- | ---------------------------------------- | 3760| 201 | Permission denied. | 3761| 202 | Called by non-system application. | 3762| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types; 3. Parameter verification failed. | 3763| 13900020 | Invalid argument. | 3764| 14000011 | System inner fail. | 3765 3766**示例:** 3767 3768phAccessHelper的创建请参考[@ohos.file.photoAccessHelper (相册管理模块)](arkts-apis-photoAccessHelper-f.md)的示例使用。 3769 3770```ts 3771import { dataSharePredicates } from '@kit.ArkData'; 3772 3773async function example(phAccessHelper: photoAccessHelper.PhotoAccessHelper) { 3774 try { 3775 console.info('setUserCommentDemo') 3776 let predicates: dataSharePredicates.DataSharePredicates = new dataSharePredicates.DataSharePredicates(); 3777 let fetchOptions: photoAccessHelper.FetchOptions = { 3778 fetchColumns: [], 3779 predicates: predicates 3780 }; 3781 let fetchResult: photoAccessHelper.FetchResult<photoAccessHelper.PhotoAsset> = await phAccessHelper.getAssets(fetchOptions); 3782 let photoAsset: photoAccessHelper.PhotoAsset = await fetchResult.getFirstObject(); 3783 let userComment = 'test_set_user_comment'; 3784 photoAsset.setUserComment(userComment, (err) => { 3785 if (err === undefined) { 3786 console.info('setUserComment successfully'); 3787 } else { 3788 console.error(`setUserComment failed with error: ${err.code}, ${err.message}`); 3789 } 3790 }); 3791 } catch (err) { 3792 console.error(`setUserCommentDemoCallback failed with error: ${err.code}, ${err.message}`); 3793 } 3794} 3795``` 3796 3797### setPending<sup>11+</sup> 3798 3799setPending(pendingState: boolean, callback: AsyncCallback<void>): void 3800 3801为图片或视频资源设置pending状态,该方法使用callback形式来返回结果。 3802 3803将文件通过`setPending(true)`设置为pending状态后,只能通过`setPending(false)`解除pending状态。可以通过`photoAsset.get(photoAccessHelper.PhotoKeys.PENDING)`的方式获取是否为pending状态,pending状态下返回true,否则返回false。 3804 3805**注意**:setPending只能在文件的创建期使用,在文件的首次创建流程的close之后,无法通过setPending(true)将文件设置为pending状态。 3806 3807**系统接口**:此接口为系统接口。 3808 3809**需要权限**:ohos.permission.WRITE_IMAGEVIDEO 3810 3811**系统能力**:SystemCapability.FileManagement.PhotoAccessHelper.Core 3812 3813**参数:** 3814 3815| 参数名 | 类型 | 必填 | 说明 | 3816| ---------- | ------- | ---- | ---------------------------------- | 3817| pendingState | boolean | 是 | 设置的pending状态,true为设置pending状态,false为解除pending状态。 | 3818| callback | AsyncCallback<void> | 是 | Callback对象,返回void。 | 3819 3820**错误码:** 3821 3822接口抛出错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)和[文件管理错误码](../apis-core-file-kit/errorcode-filemanagement.md)。 3823 3824| 错误码ID | 错误信息 | 3825| -------- | ---------------------------------------- | 3826| 201 | Permission denied. | 3827| 202 | Called by non-system application. | 3828| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types; 3. Parameter verification failed. | 3829| 14000011 | System inner fail. | 3830 3831**示例:** 3832 3833phAccessHelper的创建请参考[@ohos.file.photoAccessHelper (相册管理模块)](arkts-apis-photoAccessHelper-f.md)的示例使用。 3834 3835```ts 3836async function example(phAccessHelper: photoAccessHelper.PhotoAccessHelper) { 3837 try { 3838 console.info('setPendingCallbackDemo'); 3839 let testFileName: string = 'testFile' + Date.now() + '.jpg'; 3840 let photoAsset = await phAccessHelper.createAsset(testFileName); 3841 photoAsset.setPending(true, async (err) => { 3842 if (err !== undefined) { 3843 console.error(`setPending(true) failed with error: ${err.code}, ${err.message}`); 3844 return; 3845 } 3846 // add asset resource. 3847 photoAsset.setPending(false, async (err) => { 3848 if (err !== undefined) { 3849 console.error(`setPending(false) failed with error: ${err.code}, ${err.message}`); 3850 return; 3851 } 3852 }); 3853 }); 3854 } catch (err) { 3855 console.error(`setPendingCallbackDemo failed with error: ${err.code}, ${err.message}`); 3856 } 3857} 3858``` 3859 3860### setPending<sup>11+</sup> 3861 3862setPending(pendingState: boolean): Promise<void> 3863 3864为图片或视频资源设置pending状态,该方法使用promise形式来返回结果。 3865 3866将文件通过`setPending(true)`设置为pending状态后,只能通过`setPending(false)`解除pending状态。可以通过`photoAsset.get(photoAccessHelper.PhotoKeys.PENDING)`的方式获取是否为pending状态,pending状态下返回true,否则返回false。 3867 3868**注意**:setPending只能在文件的创建期使用,在文件的首次创建流程的close之后,无法通过setPending(true)将文件设置为pending状态。 3869 3870**系统接口**:此接口为系统接口。 3871 3872**需要权限**:ohos.permission.WRITE_IMAGEVIDEO 3873 3874**系统能力**:SystemCapability.FileManagement.PhotoAccessHelper.Core 3875 3876**参数:** 3877 3878| 参数名 | 类型 | 必填 | 说明 | 3879| ---------- | ------- | ---- | ---------------------------------- | 3880| pendingState | boolean | 是 | 设置的pending状态,true为设置pending状态,false为解除pending状态。 | 3881 3882**返回值:** 3883 3884| 类型 | 说明 | 3885| --------------------------------------- | ----------------- | 3886|Promise<boolean> | Promise对象,返回void。 | 3887 3888**错误码:** 3889 3890接口抛出错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)和[文件管理错误码](../apis-core-file-kit/errorcode-filemanagement.md)。 3891 3892| 错误码ID | 错误信息 | 3893| -------- | ---------------------------------------- | 3894| 201 | Permission denied. | 3895| 202 | Called by non-system application. | 3896| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types; 3. Parameter verification failed. | 3897| 14000011 | System inner fail. | 3898 3899**示例:** 3900 3901phAccessHelper的创建请参考[@ohos.file.photoAccessHelper (相册管理模块)](arkts-apis-photoAccessHelper-f.md)的示例使用。 3902 3903```ts 3904async function example(phAccessHelper: photoAccessHelper.PhotoAccessHelper) { 3905 try { 3906 console.info('setPendingPromiseDemo'); 3907 let testFileName: string = 'testFile' + Date.now() + '.jpg'; 3908 let photoAsset = await phAccessHelper.createAsset(testFileName); 3909 await photoAsset.setPending(true); 3910 // add asset resource. 3911 photoAsset.setPending(false); 3912 } catch (err) { 3913 console.error(`setPendingPromiseDemo failed with error: ${err.code}, ${err.message}`); 3914 } 3915} 3916``` 3917 3918### isEdited<sup>11+</sup> 3919 3920isEdited(callback: AsyncCallback<boolean>): void 3921 3922查询图片或视频资源是否被编辑过,该方法使用callback形式来返回结果。 3923 3924**系统接口**:此接口为系统接口。 3925 3926**需要权限**:ohos.permission.READ_IMAGEVIDEO 3927 3928**系统能力**:SystemCapability.FileManagement.PhotoAccessHelper.Core 3929 3930**参数:** 3931 3932| 参数名 | 类型 | 必填 | 说明 | 3933| ---------- | ------- | ---- | ---------------------------------- | 3934| callback | AsyncCallback<boolean> | 是 | Callback对象,返回图片或视频资源是否被编辑过。true为被编辑过,false为没有被编辑过,默认是false。 | 3935 3936**错误码:** 3937 3938接口抛出错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)和[文件管理错误码](../apis-core-file-kit/errorcode-filemanagement.md)。 3939 3940| 错误码ID | 错误信息 | 3941| -------- | ---------------------------------------- | 3942| 201 | Permission denied. | 3943| 202 | Called by non-system application. | 3944| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types. | 3945| 14000011 | System inner fail. | 3946 3947**示例:** 3948 3949phAccessHelper的创建请参考[@ohos.file.photoAccessHelper (相册管理模块)](arkts-apis-photoAccessHelper-f.md)的示例使用。 3950 3951```ts 3952import { dataSharePredicates } from '@kit.ArkData'; 3953 3954async function example(phAccessHelper: photoAccessHelper.PhotoAccessHelper) { 3955 try { 3956 console.info('isEditedCallbackDemo') 3957 let predicates: dataSharePredicates.DataSharePredicates = new dataSharePredicates.DataSharePredicates(); 3958 let fetchOptions: photoAccessHelper.FetchOptions = { 3959 fetchColumns: [], 3960 predicates: predicates 3961 }; 3962 let fetchResult: photoAccessHelper.FetchResult<photoAccessHelper.PhotoAsset> = await phAccessHelper.getAssets(fetchOptions); 3963 let photoAsset: photoAccessHelper.PhotoAsset = await fetchResult.getFirstObject(); 3964 photoAsset.isEdited((err, isEdited) => { 3965 if (err === undefined) { 3966 if (isEdited === true) { 3967 console.info('Photo is edited'); 3968 } else { 3969 console.info('Photo is not edited'); 3970 } 3971 } else { 3972 console.error(`isEdited failed with error: ${err.code}, ${err.message}`); 3973 } 3974 }); 3975 } catch (err) { 3976 console.error(`isEditedDemoCallback failed with error: ${err.code}, ${err.message}`); 3977 } 3978} 3979``` 3980 3981### isEdited<sup>11+</sup> 3982 3983isEdited(): Promise<boolean> 3984 3985查询图片或视频资源是否被编辑过,该方法使用promise形式来返回结果。 3986 3987**系统接口**:此接口为系统接口。 3988 3989**需要权限**:ohos.permission.READ_IMAGEVIDEO 3990 3991**系统能力**:SystemCapability.FileManagement.PhotoAccessHelper.Core 3992 3993**返回值:** 3994 3995| 类型 | 说明 | 3996| --------------------------------------- | ----------------- | 3997|Promise<boolean> | Promise对象,返回图片或视频资源是否被编辑过。true为被编辑过,false为没有被编辑过,默认是false。 | 3998 3999 4000**错误码:** 4001 4002接口抛出错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)和[文件管理错误码](../apis-core-file-kit/errorcode-filemanagement.md)。 4003 4004| 错误码ID | 错误信息 | 4005| -------- | ---------------------------------------- | 4006| 201 | Permission denied. | 4007| 202 | Called by non-system application. | 4008| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types. | 4009| 14000011 | System inner fail. | 4010 4011**示例:** 4012 4013phAccessHelper的创建请参考[@ohos.file.photoAccessHelper (相册管理模块)](arkts-apis-photoAccessHelper-f.md)的示例使用。 4014 4015```ts 4016import { dataSharePredicates } from '@kit.ArkData'; 4017 4018async function example(phAccessHelper: photoAccessHelper.PhotoAccessHelper) { 4019 try { 4020 console.info('isEditedPromiseDemo') 4021 let predicates: dataSharePredicates.DataSharePredicates = new dataSharePredicates.DataSharePredicates(); 4022 let fetchOptions: photoAccessHelper.FetchOptions = { 4023 fetchColumns: [], 4024 predicates: predicates 4025 }; 4026 let fetchResult: photoAccessHelper.FetchResult<photoAccessHelper.PhotoAsset> = await phAccessHelper.getAssets(fetchOptions); 4027 let photoAsset: photoAccessHelper.PhotoAsset = await fetchResult.getFirstObject(); 4028 let isEdited = await photoAsset.isEdited(); 4029 if (isEdited === true) { 4030 console.info('Photo is edited'); 4031 } else { 4032 console.info('Photo is not edited'); 4033 } 4034 } catch (err) { 4035 console.error(`isEditedDemoCallback failed with error: ${err.code}, ${err.message}`); 4036 } 4037} 4038``` 4039 4040### requestEditData<sup>11+</sup> 4041 4042requestEditData(callback: AsyncCallback<string>): void 4043 4044获得图片或视频资源的编辑数据,该方法使用callback形式来返回结果。 4045 4046如果资源未编辑过,则返回一个空字符串。 4047 4048**系统接口**:此接口为系统接口。 4049 4050**需要权限**:ohos.permission.READ_IMAGEVIDEO 4051 4052**系统能力**:SystemCapability.FileManagement.PhotoAccessHelper.Core 4053 4054**参数:** 4055 4056| 参数名 | 类型 | 必填 | 说明 | 4057| ---------- | ------- | ---- | ---------------------------------- | 4058| callback | AsyncCallback<string> | 是 | Callback对象,返回图片或视频资源的编辑数据。 | 4059 4060**错误码:** 4061 4062接口抛出错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)和[文件管理错误码](../apis-core-file-kit/errorcode-filemanagement.md)。 4063 4064| 错误码ID | 错误信息 | 4065| -------- | ---------------------------------------- | 4066| 201 | Permission denied. | 4067| 202 | Called by non-system application. | 4068| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types. | 4069| 14000011 | System inner fail. Possible causes: 1. The database is corrupted; 2. The file system is abnormal; 3. The IPC request timed out; 4. Permission denied. | 4070 4071**示例:** 4072 4073phAccessHelper的创建请参考[@ohos.file.photoAccessHelper (相册管理模块)](arkts-apis-photoAccessHelper-f.md)的示例使用。 4074 4075```ts 4076import { dataSharePredicates } from '@kit.ArkData'; 4077 4078async function example(phAccessHelper: photoAccessHelper.PhotoAccessHelper) { 4079 try { 4080 console.info('requestEditDataCallbackDemo') 4081 let predicates: dataSharePredicates.DataSharePredicates = new dataSharePredicates.DataSharePredicates(); 4082 let fetchOptions: photoAccessHelper.FetchOptions = { 4083 fetchColumns: [], 4084 predicates: predicates 4085 }; 4086 let fetchResult: photoAccessHelper.FetchResult<photoAccessHelper.PhotoAsset> = await phAccessHelper.getAssets(fetchOptions); 4087 let photoAsset: photoAccessHelper.PhotoAsset = await fetchResult.getFirstObject(); 4088 photoAsset.requestEditData((err, editdata) => { 4089 if (err === undefined) { 4090 console.info('Editdata is ' + editdata); 4091 } else { 4092 console.error(`requestEditData failed with error: ${err.code}, ${err.message}`); 4093 } 4094 }); 4095 } catch (err) { 4096 console.error(`requestEditDataCallbackDemo failed with error: ${err.code}, ${err.message}`); 4097 } 4098} 4099``` 4100 4101### requestEditData<sup>11+</sup> 4102 4103requestEditData(): Promise<string> 4104 4105获得图片或视频资源的编辑数据,该方法使用promise形式来返回结果。 4106 4107如果资源未编辑过,则返回一个空字符串。 4108 4109**系统接口**:此接口为系统接口。 4110 4111**需要权限**:ohos.permission.READ_IMAGEVIDEO 4112 4113**系统能力**:SystemCapability.FileManagement.PhotoAccessHelper.Core 4114 4115**返回值:** 4116 4117| 类型 | 说明 | 4118| --------------------------------------- | ----------------- | 4119|Promise<string> | Promise对象,返回图片或视频资源的编辑数据。 | 4120 4121 4122**错误码:** 4123 4124接口抛出错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)和[文件管理错误码](../apis-core-file-kit/errorcode-filemanagement.md)。 4125 4126| 错误码ID | 错误信息 | 4127| -------- | ---------------------------------------- | 4128| 201 | Permission denied. | 4129| 202 | Called by non-system application. | 4130| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types. | 4131| 14000011 | System inner fail. Possible causes: 1. The database is corrupted; 2. The file system is abnormal; 3. The IPC request timed out; 4. Permission denied. | 4132 4133**示例:** 4134 4135phAccessHelper的创建请参考[@ohos.file.photoAccessHelper (相册管理模块)](arkts-apis-photoAccessHelper-f.md)的示例使用。 4136 4137```ts 4138import { dataSharePredicates } from '@kit.ArkData'; 4139 4140async function example(phAccessHelper: photoAccessHelper.PhotoAccessHelper) { 4141 try { 4142 console.info('requestEditDataPromiseDemo') 4143 let predicates: dataSharePredicates.DataSharePredicates = new dataSharePredicates.DataSharePredicates(); 4144 let fetchOptions: photoAccessHelper.FetchOptions = { 4145 fetchColumns: [], 4146 predicates: predicates 4147 }; 4148 let fetchResult: photoAccessHelper.FetchResult<photoAccessHelper.PhotoAsset> = await phAccessHelper.getAssets(fetchOptions); 4149 let photoAsset: photoAccessHelper.PhotoAsset = await fetchResult.getFirstObject(); 4150 let editdata: string = await photoAsset.requestEditData(); 4151 console.info('Editdata is ' + editdata); 4152 } catch (err) { 4153 console.error(`requestEditDataPromiseDemo failed with error: ${err.code}, ${err.message}`); 4154 } 4155} 4156``` 4157 4158### getEditData<sup>11+</sup> 4159 4160getEditData(): Promise<MediaAssetEditData> 4161 4162获得资产编辑数据,该方法使用promise形式来返回结果。 4163 4164如果资源未编辑过,则返回的编辑数据的内容为空字符串。 4165 4166**系统接口**:此接口为系统接口。 4167 4168**需要权限**:ohos.permission.READ_IMAGEVIDEO 4169 4170**系统能力**:SystemCapability.FileManagement.PhotoAccessHelper.Core 4171 4172**返回值:** 4173 4174| 类型 | 说明 | 4175| --------------------------------------- | ----------------- | 4176|Promise<[MediaAssetEditData](#mediaasseteditdata11)> | Promise对象,返回资产编辑数据。 | 4177 4178**错误码:** 4179 4180接口抛出错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)和[文件管理错误码](../apis-core-file-kit/errorcode-filemanagement.md)。 4181 4182| 错误码ID | 错误信息 | 4183| -------- | ---------------------------------------- | 4184| 201 | Permission denied. | 4185| 202 | Called by non-system application. | 4186| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types. | 4187| 14000011 | System inner fail. Possible causes: 1. The database is corrupted; 2. The file system is abnormal; 3. The IPC request timed out; 4. Permission denied. | 4188 4189**示例:** 4190 4191phAccessHelper的创建请参考[@ohos.file.photoAccessHelper (相册管理模块)](arkts-apis-photoAccessHelper-f.md)的示例使用。 4192 4193```ts 4194import { dataSharePredicates } from '@kit.ArkData'; 4195 4196async function example(phAccessHelper: photoAccessHelper.PhotoAccessHelper) { 4197 try { 4198 console.info('getEditDataDemo') 4199 let predicates: dataSharePredicates.DataSharePredicates = new dataSharePredicates.DataSharePredicates(); 4200 let fetchOptions: photoAccessHelper.FetchOptions = { 4201 fetchColumns: [], 4202 predicates: predicates 4203 }; 4204 let fetchResult: photoAccessHelper.FetchResult<photoAccessHelper.PhotoAsset> = await phAccessHelper.getAssets(fetchOptions); 4205 let photoAsset: photoAccessHelper.PhotoAsset = await fetchResult.getFirstObject(); 4206 let assetEditData: photoAccessHelper.MediaAssetEditData = await photoAsset.getEditData(); 4207 let data: string = assetEditData.data; 4208 console.info('edit data is ' + data); 4209 } catch (err) { 4210 console.error(`getEditDataDemo failed with error: ${err.code}, ${err.message}`); 4211 } 4212} 4213``` 4214 4215### requestSource<sup>11+</sup> 4216 4217requestSource(callback: AsyncCallback<number>): void 4218 4219打开源文件并返回fd,该方法使用callback形式来返回结果。 4220 4221**系统接口**:此接口为系统接口。 4222 4223**需要权限**:ohos.permission.READ_IMAGEVIDEO 4224 4225**系统能力**:SystemCapability.FileManagement.PhotoAccessHelper.Core 4226 4227**参数:** 4228 4229| 参数名 | 类型 | 必填 | 说明 | 4230| ---------- | ------- | ---- | ---------------------------------- | 4231| callback | AsyncCallback<number> | 是 | Callback对象,返回源文件fd。 | 4232 4233**错误码:** 4234 4235接口抛出错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)和[文件管理错误码](../apis-core-file-kit/errorcode-filemanagement.md)。 4236 4237| 错误码ID | 错误信息 | 4238| -------- | ---------------------------------------- | 4239| 201 | Permission denied. | 4240| 202 | Called by non-system application. | 4241| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types. | 4242| 14000011 | System inner fail. Possible causes: 1. The database is corrupted; 2. The file system is abnormal; 3. The IPC request timed out; 4. Permission denied. | 4243 4244**示例:** 4245 4246phAccessHelper的创建请参考[@ohos.file.photoAccessHelper (相册管理模块)](arkts-apis-photoAccessHelper-f.md)的示例使用。 4247 4248```ts 4249import { dataSharePredicates } from '@kit.ArkData'; 4250 4251async function example(phAccessHelper: photoAccessHelper.PhotoAccessHelper) { 4252 try { 4253 console.info('requestSourceCallbackDemo') 4254 let predicates: dataSharePredicates.DataSharePredicates = new dataSharePredicates.DataSharePredicates(); 4255 let fetchOptions: photoAccessHelper.FetchOptions = { 4256 fetchColumns: [], 4257 predicates: predicates 4258 }; 4259 let fetchResult: photoAccessHelper.FetchResult<photoAccessHelper.PhotoAsset> = await phAccessHelper.getAssets(fetchOptions); 4260 let photoAsset: photoAccessHelper.PhotoAsset = await fetchResult.getFirstObject(); 4261 photoAsset.requestSource((err, fd) => { 4262 if (err === undefined) { 4263 console.info('Source fd is ' + fd); 4264 } else { 4265 console.error(`requestSource failed with error: ${err.code}, ${err.message}`); 4266 } 4267 }); 4268 } catch (err) { 4269 console.error(`requestSourceCallbackDemo failed with error: ${err.code}, ${err.message}`); 4270 } 4271} 4272``` 4273 4274### requestSource<sup>11+</sup> 4275 4276requestSource(): Promise<number> 4277 4278打开源文件并返回fd,该方法使用promise形式来返回结果。 4279 4280**系统接口**:此接口为系统接口。 4281 4282**需要权限**:ohos.permission.READ_IMAGEVIDEO 4283 4284**系统能力**:SystemCapability.FileManagement.PhotoAccessHelper.Core 4285 4286**返回值:** 4287 4288| 类型 | 说明 | 4289| --------------------------------------- | ----------------- | 4290|Promise<number> | Promise对象,返回源文件fd。 | 4291 4292**错误码:** 4293 4294接口抛出错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)和[文件管理错误码](../apis-core-file-kit/errorcode-filemanagement.md)。 4295 4296| 错误码ID | 错误信息 | 4297| -------- | ---------------------------------------- | 4298| 201 | Permission denied. | 4299| 202 | Called by non-system application. | 4300| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types. | 4301| 14000011 | System inner fail. Possible causes: 1. The database is corrupted; 2. The file system is abnormal; 3. The IPC request timed out; 4. Permission denied. | 4302 4303**示例:** 4304 4305phAccessHelper的创建请参考[@ohos.file.photoAccessHelper (相册管理模块)](arkts-apis-photoAccessHelper-f.md)的示例使用。 4306 4307```ts 4308import { dataSharePredicates } from '@kit.ArkData'; 4309 4310async function example(phAccessHelper: photoAccessHelper.PhotoAccessHelper) { 4311 try { 4312 console.info('requestSourcePromiseDemo') 4313 let predicates: dataSharePredicates.DataSharePredicates = new dataSharePredicates.DataSharePredicates(); 4314 let fetchOptions: photoAccessHelper.FetchOptions = { 4315 fetchColumns: [], 4316 predicates: predicates 4317 }; 4318 let fetchResult: photoAccessHelper.FetchResult<photoAccessHelper.PhotoAsset> = await phAccessHelper.getAssets(fetchOptions); 4319 let photoAsset: photoAccessHelper.PhotoAsset = await fetchResult.getFirstObject(); 4320 let fd = await photoAsset.requestSource(); 4321 console.info('Source fd is ' + fd); 4322 } catch (err) { 4323 console.error(`requestSourcePromiseDemo failed with error: ${err.code}, ${err.message}`); 4324 } 4325} 4326``` 4327 4328### commitEditedAsset<sup>11+</sup> 4329 4330commitEditedAsset(editData: string, uri: string, callback: AsyncCallback<void>) 4331 4332提交编辑数据以及编辑后的图片或视频,该方法使用callback形式来返回结果。 4333 4334通过uri将编辑后的文件传递给媒体库,uri是编辑后的文件在应用沙箱下的FileUri,可参考[FileUri](../apis-core-file-kit/js-apis-file-fileuri.md)。 4335 4336**注意**:新的编辑数据提交后,将覆盖掉原来的编辑数据。 4337 4338**系统接口**:此接口为系统接口。 4339 4340**需要权限**:ohos.permission.WRITE_IMAGEVIDEO 4341 4342**系统能力**:SystemCapability.FileManagement.PhotoAccessHelper.Core 4343 4344**参数:** 4345 4346| 参数名 | 类型 | 必填 | 说明 | 4347| ---------- | ------- | ---- | ---------------------------------- | 4348| editData | string | 是 | 提交的编辑数据。 | 4349| uri | string | 是 | 提交的编辑后的图片或视频,在应用沙箱下的uri。 | 4350| callback | AsyncCallback<void> | 是 | Callback对象,返回void。 | 4351 4352**错误码:** 4353 4354接口抛出错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)和[文件管理错误码](../apis-core-file-kit/errorcode-filemanagement.md)。 4355 4356| 错误码ID | 错误信息 | 4357| -------- | ---------------------------------------- | 4358| 201 | Permission denied. | 4359| 202 | Called by non-system application. | 4360| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types; 3. Parameter verification failed. | 4361| 14000011 | System inner fail. Possible causes: 1. The database is corrupted; 2. The file system is abnormal; 3. The IPC request timed out; 4. Permission denied. | 4362 4363**示例:** 4364 4365phAccessHelper的创建请参考[@ohos.file.photoAccessHelper (相册管理模块)](arkts-apis-photoAccessHelper-f.md)的示例使用。 4366 4367```ts 4368import { dataSharePredicates } from '@kit.ArkData'; 4369 4370async function example(phAccessHelper: photoAccessHelper.PhotoAccessHelper) { 4371 try { 4372 console.info('commitEditedAssetCallbackDemo') 4373 let predicates: dataSharePredicates.DataSharePredicates = new dataSharePredicates.DataSharePredicates(); 4374 let fetchOptions: photoAccessHelper.FetchOptions = { 4375 fetchColumns: [], 4376 predicates: predicates 4377 }; 4378 let fetchResult: photoAccessHelper.FetchResult<photoAccessHelper.PhotoAsset> = await phAccessHelper.getAssets(fetchOptions); 4379 let photoAsset: photoAccessHelper.PhotoAsset = await fetchResult.getFirstObject(); 4380 let editData = '123456'; 4381 let uri = 'file://com.example.temptest/data/storage/el2/base/haps/entry/files/test.jpg'; 4382 photoAsset.commitEditedAsset(editData, uri, (err) => { 4383 if (err === undefined) { 4384 console.info('commitEditedAsset is successful'); 4385 } else { 4386 console.error(`commitEditedAsset failed with error: ${err.code}, ${err.message}`); 4387 } 4388 }); 4389 } catch (err) { 4390 console.error(`commitEditedAssetCallbackDemo failed with error: ${err.code}, ${err.message}`); 4391 } 4392} 4393``` 4394 4395### commitEditedAsset<sup>11+</sup> 4396 4397commitEditedAsset(editData: string, uri: string): Promise<void> 4398 4399提交编辑数据以及编辑后的图片或视频,该方法使用promise形式来返回结果。 4400 4401通过uri将编辑后的文件传递给媒体库,uri是编辑后的文件在应用沙箱下的FileUri,可参考[FileUri](../apis-core-file-kit/js-apis-file-fileuri.md)。 4402 4403**注意**:新的编辑数据提交后,将覆盖掉原来的编辑数据。 4404 4405**系统接口**:此接口为系统接口。 4406 4407**需要权限**:ohos.permission.WRITE_IMAGEVIDEO 4408 4409**系统能力**:SystemCapability.FileManagement.PhotoAccessHelper.Core 4410 4411**参数:** 4412 4413| 参数名 | 类型 | 必填 | 说明 | 4414| ---------- | ------- | ---- | ---------------------------------- | 4415| editData | string | 是 | 提交的编辑数据。 | 4416| uri | string | 是 | 提交的编辑后的图片或视频,在应用沙箱下的uri。 | 4417 4418**返回值:** 4419 4420| 类型 | 说明 | 4421| --------------------------------------- | ----------------- | 4422|Promise<void> | Promise对象,返回void。 | 4423 4424**错误码:** 4425 4426接口抛出错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)和[文件管理错误码](../apis-core-file-kit/errorcode-filemanagement.md)。 4427 4428| 错误码ID | 错误信息 | 4429| -------- | ---------------------------------------- | 4430| 201 | Permission denied. | 4431| 202 | Called by non-system application. | 4432| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types; 3. Parameter verification failed. | 4433| 14000011 | System inner fail. Possible causes: 1. The database is corrupted; 2. The file system is abnormal; 3. The IPC request timed out; 4. Permission denied. | 4434 4435**示例:** 4436 4437phAccessHelper的创建请参考[@ohos.file.photoAccessHelper (相册管理模块)](arkts-apis-photoAccessHelper-f.md)的示例使用。 4438 4439```ts 4440import { dataSharePredicates } from '@kit.ArkData'; 4441 4442async function example(phAccessHelper: photoAccessHelper.PhotoAccessHelper) { 4443 try { 4444 console.info('commitEditedAssetPromiseDemo') 4445 let predicates: dataSharePredicates.DataSharePredicates = new dataSharePredicates.DataSharePredicates(); 4446 let fetchOptions: photoAccessHelper.FetchOptions = { 4447 fetchColumns: [], 4448 predicates: predicates 4449 }; 4450 let fetchResult: photoAccessHelper.FetchResult<photoAccessHelper.PhotoAsset> = await phAccessHelper.getAssets(fetchOptions); 4451 let photoAsset: photoAccessHelper.PhotoAsset = await fetchResult.getFirstObject(); 4452 let editData = '123456'; 4453 let uri = 'file://com.example.temptest/data/storage/el2/base/haps/entry/files/test.jpg'; 4454 await photoAsset.commitEditedAsset(editData, uri); 4455 console.info('commitEditedAsset is successful'); 4456 } catch (err) { 4457 console.error(`commitEditedAssetPromiseDemo failed with error: ${err.code}, ${err.message}`); 4458 } 4459} 4460``` 4461 4462### revertToOriginal<sup>11+</sup> 4463 4464revertToOriginal(callback: AsyncCallback<void>) 4465 4466回退到编辑前的状态,该方法使用callback形式来返回结果。 4467 4468**注意**:调用该接口后,编辑数据和编辑后的图片或视频资源都将被删除,无法恢复,请谨慎调用。 4469 4470**系统接口**:此接口为系统接口。 4471 4472**需要权限**:ohos.permission.WRITE_IMAGEVIDEO 4473 4474**系统能力**:SystemCapability.FileManagement.PhotoAccessHelper.Core 4475 4476**参数:** 4477 4478| 参数名 | 类型 | 必填 | 说明 | 4479| ---------- | ------- | ---- | ---------------------------------- | 4480| callback | AsyncCallback<void> | 是 | Callback对象,返回void。 | 4481 4482**错误码:** 4483 4484接口抛出错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)和[文件管理错误码](../apis-core-file-kit/errorcode-filemanagement.md)。 4485 4486| 错误码ID | 错误信息 | 4487| -------- | ---------------------------------------- | 4488| 201 | Permission denied. | 4489| 202 | Called by non-system application. | 4490| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types. | 4491| 14000011 | System inner fail. | 4492 4493**示例:** 4494 4495phAccessHelper的创建请参考[@ohos.file.photoAccessHelper (相册管理模块)](arkts-apis-photoAccessHelper-f.md)的示例使用。 4496 4497```ts 4498import { dataSharePredicates } from '@kit.ArkData'; 4499 4500async function example(phAccessHelper: photoAccessHelper.PhotoAccessHelper) { 4501 try { 4502 console.info('revertToOriginalCallbackDemo') 4503 let predicates: dataSharePredicates.DataSharePredicates = new dataSharePredicates.DataSharePredicates(); 4504 let fetchOptions: photoAccessHelper.FetchOptions = { 4505 fetchColumns: [], 4506 predicates: predicates 4507 }; 4508 let fetchResult: photoAccessHelper.FetchResult<photoAccessHelper.PhotoAsset> = await phAccessHelper.getAssets(fetchOptions); 4509 let photoAsset: photoAccessHelper.PhotoAsset = await fetchResult.getFirstObject(); 4510 photoAsset.revertToOriginal((err) => { 4511 if (err === undefined) { 4512 console.info('revertToOriginal is successful'); 4513 } else { 4514 console.error(`revertToOriginal failed with error: ${err.code}, ${err.message}`); 4515 } 4516 }); 4517 } catch (err) { 4518 console.error(`revertToOriginalCallbackDemo failed with error: ${err.code}, ${err.message}`); 4519 } 4520} 4521``` 4522 4523### revertToOriginal<sup>11+</sup> 4524 4525revertToOriginal(): Promise<void> 4526 4527回退到编辑前的状态,该方法使用promise形式来返回结果。 4528 4529**注意**:调用该接口后,编辑数据和编辑后的图片或视频资源都将被删除,无法恢复,请谨慎调用。 4530 4531**系统接口**:此接口为系统接口。 4532 4533**需要权限**:ohos.permission.WRITE_IMAGEVIDEO 4534 4535**系统能力**:SystemCapability.FileManagement.PhotoAccessHelper.Core 4536 4537**返回值:** 4538 4539| 类型 | 说明 | 4540| --------------------------------------- | ----------------- | 4541|Promise<string> | Promise对象,返回void。 | 4542 4543**错误码:** 4544 4545接口抛出错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)和[文件管理错误码](../apis-core-file-kit/errorcode-filemanagement.md)。 4546 4547| 错误码ID | 错误信息 | 4548| -------- | ---------------------------------------- | 4549| 201 | Permission denied. | 4550| 202 | Called by non-system application. | 4551| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types. | 4552| 14000011 | System inner fail. | 4553 4554**示例:** 4555 4556phAccessHelper的创建请参考[@ohos.file.photoAccessHelper (相册管理模块)](arkts-apis-photoAccessHelper-f.md)的示例使用。 4557 4558```ts 4559import { dataSharePredicates } from '@kit.ArkData'; 4560 4561async function example(phAccessHelper: photoAccessHelper.PhotoAccessHelper) { 4562 try { 4563 console.info('revertToOriginalPromiseDemo') 4564 let predicates: dataSharePredicates.DataSharePredicates = new dataSharePredicates.DataSharePredicates(); 4565 let fetchOptions: photoAccessHelper.FetchOptions = { 4566 fetchColumns: [], 4567 predicates: predicates 4568 }; 4569 let fetchResult: photoAccessHelper.FetchResult<photoAccessHelper.PhotoAsset> = await phAccessHelper.getAssets(fetchOptions); 4570 let photoAsset: photoAccessHelper.PhotoAsset = await fetchResult.getFirstObject(); 4571 photoAsset.revertToOriginal(); 4572 console.info('revertToOriginal is successful'); 4573 } catch (err) { 4574 console.error(`revertToOriginalPromiseDemo failed with error: ${err.code}, ${err.message}`); 4575 } 4576} 4577``` 4578 4579### requestPhoto<sup>11+</sup> 4580 4581requestPhoto(callback: AsyncCallback<image.PixelMap>): string 4582 4583通过callback的形式,获取资源的快速缩略图和普通缩略图。 4584 4585快速缩略图尺寸为128\*128,普通缩略图尺寸为256\*256。应用调用接口后,callback将返回两次缩略图对象,第一次为快速缩略图,第二次为普通缩略图。 4586 4587**系统接口**:此接口为系统接口。 4588 4589**需要权限**:ohos.permission.READ_IMAGEVIDEO 4590 4591**系统能力**:SystemCapability.FileManagement.PhotoAccessHelper.Core 4592 4593**参数:** 4594 4595| 参数名 | 类型 | 必填 | 说明 | 4596| ---------- | ------- | ---- | ---------------------------------- | 4597| callback | AsyncCallback<[image.PixelMap](../apis-image-kit/arkts-apis-image-PixelMap.md)> | 是 | Callback对象,返回获取的缩略图,调用2次。 | 4598 4599**返回值:** 4600 4601| 类型 | 说明 | 4602| --------------------------------------- | ----------------- | 4603| string | 本次获取任务的id。 | 4604 4605**错误码:** 4606 4607接口抛出错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)和[文件管理错误码](../apis-core-file-kit/errorcode-filemanagement.md)。 4608 4609| 错误码ID | 错误信息 | 4610| -------- | ---------------------------------------- | 4611| 201 | Permission verification failed, usually the result returned by VerifyAccessToken. | 4612| 202 | Permission verification failed, application which is not a system application uses system API. | 4613| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types. | 4614| 14000011 | System inner fail. | 4615 4616**示例:** 4617 4618phAccessHelper的创建请参考[@ohos.file.photoAccessHelper (相册管理模块)](arkts-apis-photoAccessHelper-f.md)的示例使用。 4619 4620```ts 4621import { dataSharePredicates } from '@kit.ArkData'; 4622import { image } from '@kit.ImageKit'; 4623 4624async function example(phAccessHelper: photoAccessHelper.PhotoAccessHelper) { 4625 try { 4626 console.info('requestPhotoDemo') 4627 let options: photoAccessHelper.FetchOptions = { 4628 fetchColumns: [], 4629 predicates: new dataSharePredicates.DataSharePredicates() 4630 } 4631 let fetchResult = await phAccessHelper.getAssets(options); 4632 let photoAsset = await fetchResult.getFirstObject(); 4633 let taskId: string = photoAsset.requestPhoto(async (err, pixel: image.PixelMap) => { 4634 if (err === undefined) { 4635 console.info("requestSource in, size: " + JSON.stringify((await pixel.getImageInfo()).size)) 4636 } else { 4637 console.error(`requestSource failed with error: ${err.code}, ${err.message}`); 4638 } 4639 }) 4640 console.info('requestSource taskId: ' + taskId) 4641 } catch (err) { 4642 console.error(`requestPhotoDemo failed with error: ${err.code}, ${err.message}`); 4643 } 4644} 4645``` 4646 4647### requestPhoto<sup>11+</sup> 4648 4649requestPhoto(options: RequestPhotoOptions, callback: AsyncCallback<image.PixelMap>): string 4650 4651通过callback的形式,根据传入的选项,获取资源的缩略图。 4652 4653**系统接口**:此接口为系统接口。 4654 4655**需要权限**:ohos.permission.READ_IMAGEVIDEO 4656 4657**系统能力**:SystemCapability.FileManagement.PhotoAccessHelper.Core 4658 4659**参数:** 4660 4661| 参数名 | 类型 | 必填 | 说明 | 4662| ---------- | ------- | ---- | ---------------------------------- | 4663| options | [RequestPhotoOptions](#requestphotooptions11) | 是 | 获取资源缩略图的选项。 | 4664| callback | AsyncCallback<[image.PixelMap](../apis-image-kit/arkts-apis-image-PixelMap.md)> | 是 | Callback对象,返回获取的缩略图,根据选项的设置可能调用超过1次。 | 4665 4666**返回值:** 4667 4668| 类型 | 说明 | 4669| --------------------------------------- | ----------------- | 4670| string | 本次获取任务的id。 | 4671 4672**错误码:** 4673 4674接口抛出错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)和[文件管理错误码](../apis-core-file-kit/errorcode-filemanagement.md)。 4675 4676| 错误码ID | 错误信息 | 4677| -------- | ---------------------------------------- | 4678| 201 | Permission verification failed, usually the result returned by VerifyAccessToken. | 4679| 202 | Permission verification failed, application which is not a system application uses system API. | 4680| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types; 3. Parameter verification failed. | 4681| 14000011 | System inner fail. | 4682 4683**示例:** 4684 4685phAccessHelper的创建请参考[@ohos.file.photoAccessHelper (相册管理模块)](arkts-apis-photoAccessHelper-f.md)的示例使用。 4686 4687```ts 4688import { dataSharePredicates } from '@kit.ArkData'; 4689import { image } from '@kit.ImageKit'; 4690 4691async function example(phAccessHelper: photoAccessHelper.PhotoAccessHelper) { 4692 try { 4693 console.info('requestPhotoDemo') 4694 let options: photoAccessHelper.FetchOptions = { 4695 fetchColumns: [], 4696 predicates: new dataSharePredicates.DataSharePredicates() 4697 } 4698 let fetchResult = await phAccessHelper.getAssets(options); 4699 let photoAsset = await fetchResult.getFirstObject(); 4700 let taskId: string = photoAsset.requestPhoto({ 4701 "size": { 4702 "width": 256, 4703 "height": 256 4704 }, 4705 "requestPhotoType": photoAccessHelper.RequestPhotoType.REQUEST_ALL_THUMBNAILS 4706 }, async (err, pixel: image.PixelMap) => { 4707 if (err === undefined) { 4708 console.info("requestSource in, size: " + JSON.stringify((await pixel.getImageInfo()).size)) 4709 } else { 4710 console.error(`requestSource failed with error: ${err.code}, ${err.message}`); 4711 } 4712 }) 4713 console.info('requestSource taskId: ' + taskId) 4714 } catch (err) { 4715 console.error(`requestPhotoDemo failed with error: ${err.code}, ${err.message}`); 4716 } 4717} 4718``` 4719 4720### cancelPhotoRequest<sup>11+</sup> 4721 4722cancelPhotoRequest(requestId: string): void 4723 4724根据id取消指定的获取媒体缩略图的任务。 4725 4726**系统接口**:此接口为系统接口。 4727 4728**需要权限**:ohos.permission.READ_IMAGEVIDEO 4729 4730**系统能力**:SystemCapability.FileManagement.PhotoAccessHelper.Core 4731 4732**参数:** 4733 4734| 参数名 | 类型 | 必填 | 说明 | 4735| ---------- | ------- | ---- | ---------------------------------- | 4736| requestId | string | 是 | 待取消的获取媒体缩略图的任务id。 | 4737 4738**错误码:** 4739 4740接口抛出错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)和[文件管理错误码](../apis-core-file-kit/errorcode-filemanagement.md)。 4741 4742| 错误码ID | 错误信息 | 4743| -------- | ---------------------------------------- | 4744| 201 | Permission verification failed, usually the result returned by VerifyAccessToken. | 4745| 202 | Permission verification failed, application which is not a system application uses system API. | 4746| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types; 3. Parameter verification failed. | 4747| 14000011 | System inner fail. | 4748 4749**示例:** 4750 4751phAccessHelper的创建请参考[@ohos.file.photoAccessHelper (相册管理模块)](arkts-apis-photoAccessHelper-f.md)的示例使用。 4752 4753```ts 4754import { dataSharePredicates } from '@kit.ArkData'; 4755import { image } from '@kit.ImageKit'; 4756 4757async function example(phAccessHelper: photoAccessHelper.PhotoAccessHelper) { 4758 try { 4759 console.info('cancelPhotoRequestDemo') 4760 let options: photoAccessHelper.FetchOptions = { 4761 fetchColumns: [], 4762 predicates: new dataSharePredicates.DataSharePredicates() 4763 } 4764 let fetchResult = await phAccessHelper.getAssets(options); 4765 let photoAsset = await fetchResult.getFirstObject(); 4766 let taskId: string = photoAsset.requestPhoto({ 4767 "size": { 4768 "width": 256, 4769 "height": 256 4770 }, 4771 "requestPhotoType": photoAccessHelper.RequestPhotoType.REQUEST_ALL_THUMBNAILS 4772 }, async (err, pixel: image.PixelMap) => { 4773 if (err === undefined) { 4774 console.info("requestSource in, size: " + JSON.stringify((await pixel.getImageInfo()).size)) 4775 } else { 4776 console.error(`requestSource failed with error: ${err.code}, ${err.message}`); 4777 } 4778 }) 4779 console.info('requestSource taskId: ' + taskId) 4780 photoAsset.cancelPhotoRequest(taskId); 4781 } catch (err) { 4782 console.error(`cancelPhotoRequestDemo failed with error: ${err.code}, ${err.message}`); 4783 } 4784} 4785``` 4786 4787### getAnalysisData<sup>11+</sup> 4788 4789getAnalysisData(analysisType: AnalysisType): Promise\<string> 4790 4791根据智慧分析类型获取指定分析结果数据。 4792 4793**系统接口**:此接口为系统接口。 4794 4795**需要权限**:ohos.permission.READ\_IMAGEVIDEO 4796 4797**系统能力**:SystemCapability.FileManagement.PhotoAccessHelper.Core 4798 4799**参数:** 4800 4801| 参数名 | 类型 | 必填 | 说明 | 4802| :----------- | :----------- | :- | :----------- | 4803| analysisType | [AnalysisType](#analysistype11) | 是 | 需要获取的智慧分析类型。 | 4804 4805**错误码:** 4806 4807接口抛出错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)和[文件管理错误码](../apis-core-file-kit/errorcode-filemanagement.md)。 4808 4809| 错误码ID | 错误信息 | 4810| :------- | :-------------------------------- | 4811| 201 | Permission denied. | 4812| 202 | Called by non-system application. | 4813| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types; 3. Parameter verification failed. | 4814| 14000011 | System inner fail. | 4815 4816**示例:** 4817 4818phAccessHelper的创建请参考[@ohos.file.photoAccessHelper (相册管理模块)](arkts-apis-photoAccessHelper-f.md)的示例使用。 4819 4820```ts 4821import { dataSharePredicates } from '@kit.ArkData'; 4822 4823async function example(phAccessHelper: photoAccessHelper.PhotoAccessHelper) { 4824 try { 4825 console.info('getAnalysisDataDemo') 4826 let fetchOptions: photoAccessHelper.FetchOptions = { 4827 fetchColumns: [], 4828 predicates: new dataSharePredicates.DataSharePredicates() 4829 } 4830 let fetchResult: photoAccessHelper.FetchResult<photoAccessHelper.PhotoAsset> = 4831 await phAccessHelper.getAssets(fetchOptions); 4832 let photoAsset: photoAccessHelper.PhotoAsset = await fetchResult.getFirstObject(); 4833 if (photoAsset != undefined) { 4834 let analysisData: string = await photoAsset.getAnalysisData( 4835 photoAccessHelper.AnalysisType.ANALYSIS_OCR); 4836 console.info('get ocr result: ' + JSON.stringify(analysisData)); 4837 } 4838 fetchResult.close(); 4839 } catch (err) { 4840 console.error(`getAnalysisDataDemofailed with error: ${err.code}, ${err.message}`); 4841 } 4842} 4843``` 4844 4845### getThumbnailData<sup>18+</sup> 4846 4847getThumbnailData(type: ThumbnailType): Promise<ArrayBuffer> 4848 4849获取文件缩略图的ArrayBuffer,传入缩略图的类型,使用promise异步回调。 4850 4851**需要权限**:ohos.permission.READ_IMAGEVIDEO 4852 4853**系统能力**:SystemCapability.FileManagement.PhotoAccessHelper.Core 4854 4855**参数:** 4856 4857| 参数名 | 类型 | 必填 | 说明 | 4858| ---- | -------------- | ---- | ----- | 4859| type | [ThumbnailType](#thumbnailtype13) | 是 | 缩略图类型。 | 4860 4861**返回值:** 4862 4863| 类型 | 说明 | 4864| ----------------------------- | --------------------- | 4865| Promise\<ArrayBuffer> | Promise对象,返回缩略图的ArrayBuffer。 | 4866 4867**错误码:** 4868 4869以下错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)和[文件管理错误码](../apis-core-file-kit/errorcode-filemanagement.md)。 4870 4871错误码13900012,请参考[开发准备](../../media/medialibrary/photoAccessHelper-preparation.md)。 4872 4873| 错误码ID | 错误信息 | 4874| -------- | ---------------------------------------- | 4875| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types; 3. Parameter verification failed. | 4876| 202 | Called by non-system application. | 4877| 13900012 | Permission denied. | 4878| 13900020 | Invalid argument. | 4879| 14000011 | System inner fail. | 4880 4881**示例:** 4882 4883```ts 4884import { dataSharePredicates } from '@kit.ArkData'; 4885import { BusinessError } from '@kit.BasicServicesKit'; 4886 4887async function example(phAccessHelper: photoAccessHelper.PhotoAccessHelper) { 4888 console.info('getThumbnailDataDemo'); 4889 let predicates: dataSharePredicates.DataSharePredicates = new dataSharePredicates.DataSharePredicates(); 4890 let fetchOption: photoAccessHelper.FetchOptions = { 4891 fetchColumns: [], 4892 predicates: predicates 4893 }; 4894 let fetchResult: photoAccessHelper.FetchResult<photoAccessHelper.PhotoAsset> = await phAccessHelper.getAssets(fetchOption); 4895 let asset = await fetchResult.getFirstObject(); 4896 console.info('asset displayName = ', asset.displayName); 4897 asset.getThumbnailData(photoAccessHelper.ThumbnailType.LCD).then((buffer: ArrayBuffer) => { 4898 console.info('getThumbnailData successful, buffer byteLength = ${buffer.byteLength}'); 4899 }).catch((err: BusinessError) => { 4900 console.error(`getThumbnailData fail with error: ${err.code}, ${err.message}`); 4901 }); 4902} 4903``` 4904 4905## SharedPhotoAsset<sup>13+</sup> 4906 4907共享图片资产。 4908 4909**系统接口**:此接口为系统接口。 4910 4911**系统能力**:SystemCapability.FileManagement.PhotoAccessHelper.Core 4912 4913### 属性 4914 4915| 名称 | 类型 | 只读 | 可选 | 说明 | 4916| ---- | --- | ---- | ---- | --- | 4917| fileId | number | 否 | 否 | 图片资产标识id。<br>**系统接口**:此接口为系统接口。| 4918| uri | string | 否 | 否 | 图片资产uri。<br>**系统接口**:此接口为系统接口。| 4919| data | string | 否 | 否 | 图片资产的路径数据。<br>**系统接口**:此接口为系统接口。| 4920| mediaType | [PhotoType](arkts-apis-photoAccessHelper-e.md#phototype) | 否 | 否 | 图片资产的媒体类型。<br>**系统接口**:此接口为系统接口。| 4921| displayName | string | 否 | 否 | 图片资产的显示名称。<br>**系统接口**:此接口为系统接口。| 4922| size | number | 否 | 否 | 图片资产文件大小。<br>**系统接口**:此接口为系统接口。| 4923| dataAdded | number | 否 | 否 | 添加了图片资产数据。<br>**系统接口**:此接口为系统接口。| 4924| dataModified | number | 否 | 否 | 更改了图片资产数据。<br>**系统接口**:此接口为系统接口。| 4925| duration | number | 否 | 否 | 视频类型的图片资产时长。<br>**系统接口**:此接口为系统接口。| 4926| width | number | 否 | 否 | 图片资产的像素宽度。<br>**系统接口**:此接口为系统接口。| 4927| height | number | 否 | 否 | 图片资产的像素高度。<br>**系统接口**:此接口为系统接口。| 4928| dataTaken | number | 否 | 否 | 图片资产拍照后存入本地时间。<br>**系统接口**:此接口为系统接口。| 4929| orientation | number | 否 | 否 | 图片资产的旋转角度。<br>**系统接口**:此接口为系统接口。| 4930| isFavorite | boolean | 否 | 否 | 是否收藏了此图片。<br>**系统接口**:此接口为系统接口。| 4931| title | string | 否 | 否 | 图片资产的标题。<br>**系统接口**:此接口为系统接口。| 4932| position | [PositionType](arkts-apis-photoAccessHelper-e.md#positiontype16) | 否 | 否 | 图片资产存在位置。<br>**系统接口**:此接口为系统接口。| 4933| dataTrashed | number | 否 | 否 | 图片资产是否在回收站中。<br>**系统接口**:此接口为系统接口。| 4934| hidden | boolean | 否 | 否 | 图片资产是否隐藏。<br>**系统接口**:此接口为系统接口。| 4935| userComment | string | 否 | 否 | 图片资产的用户评论信息。<br>**系统接口**:此接口为系统接口。| 4936| cameraShotKey | string | 否 | 否 | 图片资产相机拍摄信息。<br>**系统接口**:此接口为系统接口。| 4937| dateYear | string | 否 | 否 | 图片资产创建年份时间。<br>**系统接口**:此接口为系统接口。| 4938| dateMonth | string | 否 | 否 | 图片资产创建月份时间。<br>**系统接口**:此接口为系统接口。| 4939| dateDay | string | 否 | 否 | 图片资产创建日时间。<br>**系统接口**:此接口为系统接口。| 4940| pending | boolean | 否 | 否 | 图片资产等待状态,true为等待。<br>**系统接口**:此接口为系统接口。| 4941| dateAddedMs | number | 否 | 否 | 图片资产数据添加后经过时间。<br>**系统接口**:此接口为系统接口。| 4942| dateTrashedMs | number | 否 | 否 | 图片资产数据进回收站后经过时间。<br>**系统接口**:此接口为系统接口。| 4943| subtype | [PhotoSubtype](#photosubtype) | 否 | 否 | 图片资产子类型。<br>**系统接口**:此接口为系统接口。| 4944| movingPhotoEffectMode | [MovingPhotoEffectMode](#movingphotoeffectmode12) | 否 | 否 | 动态照片效果模式。<br>**系统接口**:此接口为系统接口。| 4945| dynamicRangeType | [DynamicRangeType](arkts-apis-photoAccessHelper-e.md#dynamicrangetype12) | 否 | 否 | 媒体文件的动态范围类型。<br>**系统接口**:此接口为系统接口。| 4946| thumbnailReady | boolean | 否 | 否 | 图片资产的缩略图是否准备好。<br>**系统接口**:此接口为系统接口。| 4947| lcdSize | string | 否 | 否 | 图片资产的lcd缩略图宽高信息。<br>**系统接口**:此接口为系统接口。| 4948| thmSize | string | 否 | 否 | 图片资产的thumb缩略图宽高信息。<br>**系统接口**:此接口为系统接口。| 4949| thumbnailModifiedMs<sup>14+</sup> | number | 否 | 是 | 图片资产的缩略图状态改变后经过时间。<br>**系统接口**:此接口为系统接口。| 4950| thumbnailVisible<sup>14+</sup> | [ThumbnailVisibility](#thumbnailvisibility14) | 否 | 否 | 图片资产的缩略图是否可见。<br>**系统接口**:此接口为系统接口。| 4951 4952## Album 4953 4954实体相册 4955 4956### 属性 4957 4958**系统能力**:SystemCapability.FileManagement.PhotoAccessHelper.Core 4959 4960| 名称 | 类型 | 只读 | 可选 | 说明 | 4961| ------------ | ------ | ---- | ---- | ------- | 4962| lpath<sup>18+</sup> | string | 是 | 是 | 相册虚拟路径。<br>**系统接口**:此接口为系统接口。| 4963| dateAdded<sup>18+</sup> | number | 是 | 是 | 相册添加时间。<br>**系统接口**:此接口为系统接口。| 4964| dateModified<sup>18+</sup> | number | 是 | 是 | 相册修改时间。<br>**系统接口**:此接口为系统接口。| 4965| coverUriSource<sup>20+</sup> | number | 是 | 是 | 相册封面来源。<br>**系统接口**:此接口为系统接口。| 4966 4967### recoverAssets<sup>(deprecated)</sup> 4968 4969recoverAssets(assets: Array<PhotoAsset>, callback: AsyncCallback<void>): void 4970 4971从回收站中恢复图片或者视频,需要先在回收站中预置文件资源。该方法使用callback形式来返回结果。 4972 4973> **说明:** 4974> 4975> 从API version 10开始支持,从API version 11开始废弃。建议使用[MediaAlbumChangeRequest.recoverAssets](#recoverassets11)替代。 4976 4977**系统接口**:此接口为系统接口。 4978 4979**需要权限**:ohos.permission.WRITE_IMAGEVIDEO 4980 4981**系统能力**:SystemCapability.FileManagement.PhotoAccessHelper.Core 4982 4983**参数:** 4984 4985| 参数名 | 类型 | 必填 | 说明 | 4986| -------- | ------------------------- | ---- | ---------- | 4987| assets | Array<[PhotoAsset](#photoasset)> | 是 | 回收站中待恢复图片或者视频数组。 | 4988| callback | AsyncCallback<void> | 是 | callback返回void。 | 4989 4990**错误码:** 4991 4992接口抛出错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)和[文件管理错误码](../apis-core-file-kit/errorcode-filemanagement.md)。 4993 4994错误码13900012,请参考[开发准备](../../media/medialibrary/photoAccessHelper-preparation.md)。 4995 4996| 错误码ID | 错误信息 | 4997| -------- | ---------------------------------------- | 4998| 202 | Called by non-system application. | 4999| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types; 3. Parameter verification failed. | 5000| 13900012 | Permission denied. | 5001| 13900020 | Invalid argument. | 5002| 14000011 | System inner fail. | 5003 5004**示例:** 5005 5006phAccessHelper的创建请参考[@ohos.file.photoAccessHelper (相册管理模块)](arkts-apis-photoAccessHelper-f.md)的示例使用。 5007 5008```ts 5009import { dataSharePredicates } from '@kit.ArkData'; 5010 5011async function example(phAccessHelper: photoAccessHelper.PhotoAccessHelper) { 5012 try { 5013 console.info('recoverAssetsDemoCallback'); 5014 let predicates: dataSharePredicates.DataSharePredicates = new dataSharePredicates.DataSharePredicates(); 5015 let fetchOption: photoAccessHelper.FetchOptions = { 5016 fetchColumns: [], 5017 predicates: predicates 5018 }; 5019 let albumFetchResult: photoAccessHelper.FetchResult<photoAccessHelper.Album> = await phAccessHelper.getAlbums(photoAccessHelper.AlbumType.SYSTEM, photoAccessHelper.AlbumSubtype.TRASH); 5020 let album: photoAccessHelper.Album = await albumFetchResult.getFirstObject(); 5021 let fetchResult: photoAccessHelper.FetchResult<photoAccessHelper.PhotoAsset> = await album.getAssets(fetchOption); 5022 let asset: photoAccessHelper.PhotoAsset = await fetchResult.getFirstObject(); 5023 album.recoverAssets([asset], (err) => { 5024 if (err === undefined) { 5025 console.info('album recoverAssets successfully'); 5026 } else { 5027 console.error(`album recoverAssets failed with error: ${err.code}, ${err.message}`); 5028 } 5029 }); 5030 } catch (err) { 5031 console.error(`recoverAssetsDemoCallback failed with error: ${err.code}, ${err.message}`); 5032 } 5033} 5034``` 5035 5036### recoverAssets<sup>(deprecated)</sup> 5037 5038recoverAssets(assets: Array<PhotoAsset>): Promise<void> 5039 5040从回收站中恢复图片或者视频,需要先在回收站中预置文件资源。该方法使用Promise来返回结果。 5041 5042> **说明:** 5043> 5044> 从API version 10开始支持,从API version 11开始废弃。建议使用[MediaAlbumChangeRequest.recoverAssets](#recoverassets11)替代。 5045 5046**系统接口**:此接口为系统接口。 5047 5048**需要权限**:ohos.permission.WRITE_IMAGEVIDEO 5049 5050**系统能力**:SystemCapability.FileManagement.PhotoAccessHelper.Core 5051 5052**参数:** 5053 5054| 参数名 | 类型 | 必填 | 说明 | 5055| -------- | ------------------------- | ---- | ---------- | 5056| assets | Array<[PhotoAsset](#photoasset)> | 是 | 回收站中待恢复图片或者视频数组。 | 5057 5058**返回值:** 5059 5060| 类型 | 说明 | 5061| --------------------------------------- | ----------------- | 5062|Promise<void> | Promise对象,返回void。 | 5063 5064**错误码:** 5065 5066接口抛出错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)和[文件管理错误码](../apis-core-file-kit/errorcode-filemanagement.md)。 5067 5068错误码13900012,请参考[开发准备](../../media/medialibrary/photoAccessHelper-preparation.md)。 5069 5070| 错误码ID | 错误信息 | 5071| -------- | ---------------------------------------- | 5072| 202 | Called by non-system application. | 5073| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types; 3. Parameter verification failed. | 5074| 13900012 | Permission denied. | 5075| 13900020 | Invalid argument. | 5076| 14000011 | System inner fail. | 5077 5078**示例:** 5079 5080phAccessHelper的创建请参考[@ohos.file.photoAccessHelper (相册管理模块)](arkts-apis-photoAccessHelper-f.md)的示例使用。 5081 5082```ts 5083import { dataSharePredicates } from '@kit.ArkData'; 5084import { BusinessError } from '@kit.BasicServicesKit'; 5085 5086async function example(phAccessHelper: photoAccessHelper.PhotoAccessHelper) { 5087 try { 5088 console.info('recoverAssetsDemoPromise'); 5089 let predicates: dataSharePredicates.DataSharePredicates = new dataSharePredicates.DataSharePredicates(); 5090 let fetchOption: photoAccessHelper.FetchOptions = { 5091 fetchColumns: [], 5092 predicates: predicates 5093 }; 5094 let albumFetchResult: photoAccessHelper.FetchResult<photoAccessHelper.Album> = await phAccessHelper.getAlbums(photoAccessHelper.AlbumType.SYSTEM, photoAccessHelper.AlbumSubtype.TRASH); 5095 let album: photoAccessHelper.Album = await albumFetchResult.getFirstObject(); 5096 let fetchResult: photoAccessHelper.FetchResult<photoAccessHelper.PhotoAsset> = await album.getAssets(fetchOption); 5097 let asset: photoAccessHelper.PhotoAsset = await fetchResult.getFirstObject(); 5098 album.recoverAssets([asset]).then(() => { 5099 console.info('album recoverAssets successfully'); 5100 }).catch((err: BusinessError) => { 5101 console.error(`album recoverAssets failed with error: ${err.code}, ${err.message}`); 5102 }); 5103 } catch (err) { 5104 console.error(`recoverAssetsDemoPromise failed with error: ${err.code}, ${err.message}`); 5105 } 5106} 5107``` 5108 5109### deleteAssets<sup>(deprecated)</sup> 5110 5111deleteAssets(assets: Array<PhotoAsset>, callback: AsyncCallback<void>): void 5112 5113从回收站中彻底删除图片或者视频,需要先在回收站中预置文件资源。该方法使用callback形式来返回结果。 5114 5115> **说明:** 5116> 5117> 从API version 10开始支持,从API version 11开始废弃。建议使用[MediaAlbumChangeRequest.deleteAssets](#deleteassets11)替代。 5118 5119**注意**:此操作不可逆,执行此操作后文件资源将彻底删除,请谨慎操作。 5120 5121**系统接口**:此接口为系统接口。 5122 5123**需要权限**:ohos.permission.WRITE_IMAGEVIDEO 5124 5125**系统能力**:SystemCapability.FileManagement.PhotoAccessHelper.Core 5126 5127**参数:** 5128 5129| 参数名 | 类型 | 必填 | 说明 | 5130| -------- | ------------------------- | ---- | ---------- | 5131| assets | Array<[PhotoAsset](#photoasset)> | 是 | 回收站中待彻底删除图片或者视频数组。 | 5132| callback | AsyncCallback<void> | 是 | callback返回void。 | 5133 5134**错误码:** 5135 5136接口抛出错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)和[文件管理错误码](../apis-core-file-kit/errorcode-filemanagement.md)。 5137 5138错误码13900012,请参考[开发准备](../../media/medialibrary/photoAccessHelper-preparation.md)。 5139 5140| 错误码ID | 错误信息 | 5141| -------- | ---------------------------------------- | 5142| 202 | Called by non-system application. | 5143| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types; 3. Parameter verification failed. | 5144| 13900012 | Permission denied. | 5145| 13900020 | Invalid argument. | 5146| 14000011 | System inner fail. | 5147 5148**示例:** 5149 5150phAccessHelper的创建请参考[@ohos.file.photoAccessHelper (相册管理模块)](arkts-apis-photoAccessHelper-f.md)的示例使用。 5151 5152```ts 5153import { dataSharePredicates } from '@kit.ArkData'; 5154 5155async function example(phAccessHelper: photoAccessHelper.PhotoAccessHelper) { 5156 try { 5157 console.info('deleteAssetsDemoCallback'); 5158 let predicates: dataSharePredicates.DataSharePredicates = new dataSharePredicates.DataSharePredicates(); 5159 let fetchOption: photoAccessHelper.FetchOptions = { 5160 fetchColumns: [], 5161 predicates: predicates 5162 }; 5163 let albumFetchResult: photoAccessHelper.FetchResult<photoAccessHelper.Album> = await phAccessHelper.getAlbums(photoAccessHelper.AlbumType.SYSTEM, photoAccessHelper.AlbumSubtype.TRASH); 5164 let album: photoAccessHelper.Album = await albumFetchResult.getFirstObject(); 5165 let fetchResult: photoAccessHelper.FetchResult<photoAccessHelper.PhotoAsset> = await album.getAssets(fetchOption); 5166 let asset: photoAccessHelper.PhotoAsset = await fetchResult.getFirstObject(); 5167 album.deleteAssets([asset], (err) => { 5168 if (err === undefined) { 5169 console.info('album deleteAssets successfully'); 5170 } else { 5171 console.error(`album deleteAssets failed with error: ${err.code}, ${err.message}`); 5172 } 5173 }); 5174 } catch (err) { 5175 console.error(`deleteAssetsDemoCallback failed with error: ${err.code}, ${err.message}`); 5176 } 5177} 5178``` 5179 5180### deleteAssets<sup>(deprecated)</sup> 5181 5182deleteAssets(assets: Array<PhotoAsset>): Promise<void> 5183 5184从回收站中彻底删除图片或者视频,需要先在回收站中预置文件资源,建议删除数量不超过1000张。该方法使用Promise来返回结果。 5185 5186> **说明:** 5187> 5188> 从API version 10开始支持,从API version 11开始废弃。建议使用[MediaAlbumChangeRequest.deleteAssets](#deleteassets11)替代。 5189 5190**注意**:此操作不可逆,执行此操作后文件资源将彻底删除,请谨慎操作。 5191 5192**系统接口**:此接口为系统接口。 5193 5194**需要权限**:ohos.permission.WRITE_IMAGEVIDEO 5195 5196**系统能力**:SystemCapability.FileManagement.PhotoAccessHelper.Core 5197 5198**参数:** 5199 5200| 参数名 | 类型 | 必填 | 说明 | 5201| -------- | ------------------------- | ---- | ---------- | 5202| assets | Array<[PhotoAsset](#photoasset)> | 是 | 回收站中待彻底删除图片或者视频数组。 | 5203 5204**返回值:** 5205 5206| 类型 | 说明 | 5207| --------------------------------------- | ----------------- | 5208|Promise<void> | Promise对象,返回void。 | 5209 5210**错误码:** 5211 5212接口抛出错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)和[文件管理错误码](../apis-core-file-kit/errorcode-filemanagement.md)。 5213 5214错误码13900012,请参考[开发准备](../../media/medialibrary/photoAccessHelper-preparation.md)。 5215 5216| 错误码ID | 错误信息 | 5217| -------- | ---------------------------------------- | 5218| 202 | Called by non-system application. | 5219| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types; 3. Parameter verification failed. | 5220| 13900012 | Permission denied. | 5221| 13900020 | Invalid argument. | 5222| 14000011 | System inner fail. | 5223 5224**示例:** 5225 5226phAccessHelper的创建请参考[@ohos.file.photoAccessHelper (相册管理模块)](arkts-apis-photoAccessHelper-f.md)的示例使用。 5227 5228```ts 5229import { dataSharePredicates } from '@kit.ArkData'; 5230import { BusinessError } from '@kit.BasicServicesKit'; 5231 5232async function example(phAccessHelper: photoAccessHelper.PhotoAccessHelper) { 5233 try { 5234 console.info('deleteAssetsDemoPromise'); 5235 let predicates: dataSharePredicates.DataSharePredicates = new dataSharePredicates.DataSharePredicates(); 5236 let fetchOption: photoAccessHelper.FetchOptions = { 5237 fetchColumns: [], 5238 predicates: predicates 5239 }; 5240 let albumFetchResult: photoAccessHelper.FetchResult<photoAccessHelper.Album> = await phAccessHelper.getAlbums(photoAccessHelper.AlbumType.SYSTEM, photoAccessHelper.AlbumSubtype.TRASH); 5241 let album: photoAccessHelper.Album = await albumFetchResult.getFirstObject(); 5242 let fetchResult: photoAccessHelper.FetchResult<photoAccessHelper.PhotoAsset> = await album.getAssets(fetchOption); 5243 let asset: photoAccessHelper.PhotoAsset = await fetchResult.getFirstObject(); 5244 album.deleteAssets([asset]).then(() => { 5245 console.info('album deleteAssets successfully'); 5246 }).catch((err: BusinessError) => { 5247 console.error(`album deleteAssets failed with error: ${err.code}, ${err.message}`); 5248 }); 5249 } catch (err) { 5250 console.error(`deleteAssetsDemoPromise failed with error: ${err.code}, ${err.message}`); 5251 } 5252} 5253``` 5254 5255### setCoverUri<sup>(deprecated)</sup> 5256 5257setCoverUri(uri: string, callback: AsyncCallback<void>): void 5258 5259设置相册封面,该方法使用callback形式来返回结果。 5260 5261> **说明:** 5262> 5263> 从API version 10开始支持,从API version 11开始废弃。建议使用[MediaAlbumChangeRequest.setCoverUri](#setcoveruri11)替代。 5264 5265**注意**:此接口只可修改用户相册封面,不允许修改系统相册封面。 5266 5267**系统接口**:此接口为系统接口。 5268 5269**需要权限**:ohos.permission.WRITE_IMAGEVIDEO 5270 5271**系统能力**:SystemCapability.FileManagement.PhotoAccessHelper.Core 5272 5273**参数:** 5274 5275| 参数名 | 类型 | 必填 | 说明 | 5276| -------- | ------------------------- | ---- | ---------- | 5277| uri | string | 是 | 待设置为相册封面文件的uri。 | 5278| callback | AsyncCallback<void> | 是 | callback返回void。 | 5279 5280**错误码:** 5281 5282接口抛出错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)和[文件管理错误码](../apis-core-file-kit/errorcode-filemanagement.md)。 5283 5284错误码13900012,请参考[开发准备](../../media/medialibrary/photoAccessHelper-preparation.md)。 5285 5286| 错误码ID | 错误信息 | 5287| -------- | ---------------------------------------- | 5288| 202 | Called by non-system application. | 5289| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types; 3. Parameter verification failed. | 5290| 13900012 | Permission denied. | 5291| 13900020 | Invalid argument. | 5292| 14000011 | System inner fail. | 5293 5294**示例:** 5295 5296phAccessHelper的创建请参考[@ohos.file.photoAccessHelper (相册管理模块)](arkts-apis-photoAccessHelper-f.md)的示例使用。 5297 5298```ts 5299import { dataSharePredicates } from '@kit.ArkData'; 5300 5301async function example(phAccessHelper: photoAccessHelper.PhotoAccessHelper) { 5302 try { 5303 console.info('setCoverUriDemoCallback'); 5304 let predicates: dataSharePredicates.DataSharePredicates = new dataSharePredicates.DataSharePredicates(); 5305 let fetchOption: photoAccessHelper.FetchOptions = { 5306 fetchColumns: [], 5307 predicates: predicates 5308 }; 5309 let albumFetchResult: photoAccessHelper.FetchResult<photoAccessHelper.Album> = await phAccessHelper.getAlbums(photoAccessHelper.AlbumType.USER, photoAccessHelper.AlbumSubtype.USER_GENERIC); 5310 let album: photoAccessHelper.Album = await albumFetchResult.getFirstObject(); 5311 let fetchResult: photoAccessHelper.FetchResult<photoAccessHelper.PhotoAsset> = await album.getAssets(fetchOption); 5312 let asset: photoAccessHelper.PhotoAsset = await fetchResult.getFirstObject(); 5313 album.setCoverUri(asset.uri, (err) => { 5314 if (err === undefined) { 5315 console.info('album setCoverUri successfully'); 5316 } else { 5317 console.error(`album setCoverUri failed with error: ${err.code}, ${err.message}`); 5318 } 5319 }); 5320 } catch (err) { 5321 console.error(`setCoverUriDemoCallback failed with error: ${err.code}, ${err.message}`); 5322 } 5323} 5324``` 5325 5326### setCoverUri<sup>(deprecated)</sup> 5327 5328setCoverUri(uri: string): Promise<void> 5329 5330设置相册封面,该方法使用Promise来返回结果。 5331 5332> **说明:** 5333> 5334> 从API version 10开始支持,从API version 11开始废弃。建议使用[MediaAlbumChangeRequest.setCoverUri](#setcoveruri11)替代。 5335 5336**注意**:此接口只可修改用户相册封面,不允许修改系统相册封面。 5337 5338**系统接口**:此接口为系统接口。 5339 5340**需要权限**:ohos.permission.WRITE_IMAGEVIDEO 5341 5342**系统能力**:SystemCapability.FileManagement.PhotoAccessHelper.Core 5343 5344**参数:** 5345 5346| 参数名 | 类型 | 必填 | 说明 | 5347| -------- | ------------------------- | ---- | ---------- | 5348| uri | string | 是 | 待设置为相册封面文件的uri。 | 5349 5350**返回值:** 5351 5352| 类型 | 说明 | 5353| --------------------------------------- | ----------------- | 5354|Promise<void> | Promise对象,返回void。 | 5355 5356**错误码:** 5357 5358接口抛出错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)和[文件管理错误码](../apis-core-file-kit/errorcode-filemanagement.md)。 5359 5360错误码13900012,请参考[开发准备](../../media/medialibrary/photoAccessHelper-preparation.md)。 5361 5362| 错误码ID | 错误信息 | 5363| -------- | ---------------------------------------- | 5364| 202 | Called by non-system application. | 5365| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types; 3. Parameter verification failed. | 5366| 13900012 | Permission denied. | 5367| 13900020 | Invalid argument. | 5368| 14000011 | System inner fail. | 5369**示例:** 5370 5371phAccessHelper的创建请参考[@ohos.file.photoAccessHelper (相册管理模块)](arkts-apis-photoAccessHelper-f.md)的示例使用。 5372 5373```ts 5374import { dataSharePredicates } from '@kit.ArkData'; 5375import { BusinessError } from '@kit.BasicServicesKit'; 5376 5377async function example(phAccessHelper: photoAccessHelper.PhotoAccessHelper) { 5378 try { 5379 console.info('setCoverUriDemoPromise'); 5380 let predicates: dataSharePredicates.DataSharePredicates = new dataSharePredicates.DataSharePredicates(); 5381 let fetchOption: photoAccessHelper.FetchOptions = { 5382 fetchColumns: [], 5383 predicates: predicates 5384 }; 5385 let albumFetchResult: photoAccessHelper.FetchResult<photoAccessHelper.Album> = await phAccessHelper.getAlbums(photoAccessHelper.AlbumType.USER, photoAccessHelper.AlbumSubtype.USER_GENERIC); 5386 let album: photoAccessHelper.Album = await albumFetchResult.getFirstObject(); 5387 let fetchResult: photoAccessHelper.FetchResult<photoAccessHelper.PhotoAsset> = await album.getAssets(fetchOption); 5388 let asset: photoAccessHelper.PhotoAsset = await fetchResult.getFirstObject(); 5389 album.setCoverUri(asset.uri).then(() => { 5390 console.info('album setCoverUri successfully'); 5391 }).catch((err: BusinessError) => { 5392 console.error(`album setCoverUri failed with error: ${err.code}, ${err.message}`); 5393 }); 5394 } catch (err) { 5395 console.error(`setCoverUriDemoPromise failed with error: ${err.code}, ${err.message}`); 5396 } 5397} 5398``` 5399 5400### getFaceId<sup>13+</sup> 5401 5402getFaceId(): Promise\<string> 5403 5404获取人像相册或合影相册的封面人脸标识。 5405 5406**系统接口**:此接口为系统接口。 5407 5408**需要权限**:ohos.permission.READ\_IMAGEVIDEO 5409 5410**系统能力**:SystemCapability.FileManagement.PhotoAccessHelper.Core 5411 5412**返回值:** 5413 5414| 类型 | 说明 | 5415| :------------------ | :---------------------------------- | 5416| Promise<string> | Promise对象,人像相册返回tag_id,合影相册返回group_tag,未找到返回空字符串。 | 5417 5418**错误码:** 5419 5420接口抛出错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)和[文件管理错误码](../apis-core-file-kit/errorcode-filemanagement.md)。 5421 5422| 错误码ID | 错误信息 | 5423| :------- | :----------------------------------------------------------- | 5424| 201 | Permission denied. | 5425| 202 | Called by non-system application. | 5426| 14000011 | Internal system error | 5427 5428**示例:** 5429 5430phAccessHelper的创建请参考[@ohos.file.photoAccessHelper (相册管理模块)](arkts-apis-photoAccessHelper-f.md)的示例使用。 5431 5432```ts 5433import { dataSharePredicates } from '@kit.ArkData'; 5434 5435async function example(phAccessHelper: photoAccessHelper.PhotoAccessHelper) { 5436 try { 5437 console.info('getFaceIdDemo'); 5438 let predicates: dataSharePredicates.DataSharePredicates = new dataSharePredicates.DataSharePredicates(); 5439 predicates.equalTo("user_display_level", 1); 5440 let fetchOptions: photoAccessHelper.FetchOptions = { 5441 fetchColumns: [], 5442 predicates: predicates 5443 }; 5444 let fetchResult = 5445 await phAccessHelper.getAlbums(photoAccessHelper.AlbumType.SMART, photoAccessHelper.AlbumSubtype.PORTRAIT, 5446 fetchOptions); 5447 let album = await fetchResult?.getFirstObject(); 5448 let faceId = await album?.getFaceId(); 5449 console.info(`getFaceId successfully, faceId: ${faceId}`); 5450 fetchResult.close(); 5451 } catch (err) { 5452 console.error(`getFaceId failed with err: ${err.code}, ${err.message}`); 5453 } 5454} 5455``` 5456 5457## MediaAssetEditData<sup>11+</sup> 5458 5459资产编辑数据。 5460 5461**系统接口**:此接口为系统接口。 5462 5463**系统能力**:SystemCapability.FileManagement.PhotoAccessHelper.Core 5464 5465### 属性 5466 5467| 名称 | 类型 | 可读 | 可写 | 说明 | 5468| ------------ | ------ | ---- | ---- | ------- | 5469| compatibleFormat | string | 是 | 是 | 编辑数据的格式。<br>**系统接口**:此接口为系统接口。 | 5470| formatVersion | string | 是 | 是 | 编辑数据格式的版本。<br>**系统接口**:此接口为系统接口。 | 5471| data | string | 是 | 是 | 编辑数据的内容。<br>**系统接口**:此接口为系统接口。 | 5472 5473### constructor<sup>11+</sup> 5474 5475constructor(compatibleFormat: string, formatVersion: string) 5476 5477构造函数。 5478 5479**系统接口**:此接口为系统接口。 5480 5481**系统能力**:SystemCapability.FileManagement.PhotoAccessHelper.Core 5482 5483**参数:** 5484 5485| 参数名 | 类型 | 必填 | 说明 | 5486| -------- | ------------------------- | ---- | ---------- | 5487| compatibleFormat | string | 是 | 编辑数据的格式。 | 5488| formatVersion | string | 是 | 编辑数据格式的版本。 | 5489 5490**错误码:** 5491 5492接口抛出错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)和[文件管理错误码](../apis-core-file-kit/errorcode-filemanagement.md)。 5493 5494| 错误码ID | 错误信息 | 5495| -------- | ---------------------------------------- | 5496| 202 | Called by non-system application. | 5497| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types; 3. Parameter verification failed. | 5498| 14000011 | System inner fail. | 5499 5500**示例:** 5501 5502```ts 5503let assetEditData: photoAccessHelper.MediaAssetEditData = new photoAccessHelper.MediaAssetEditData('system', '1.0'); 5504``` 5505 5506## MediaAssetChangeRequest<sup>11+</sup> 5507 5508资产变更请求。 5509 5510**系统能力**:SystemCapability.FileManagement.PhotoAccessHelper.Core 5511 5512### createAssetRequest<sup>11+</sup> 5513 5514static createAssetRequest(context: Context, displayName: string, options?: PhotoCreateOptions): MediaAssetChangeRequest 5515 5516指定待创建的图片或者视频的文件名,创建资产变更请求。 5517 5518待创建的文件名参数规格为: 5519- 应包含有效文件主名和图片或视频扩展名。 5520- 文件名字符串长度为1~255。 5521- 文件主名中不允许出现的非法英文字符。<br>API18开始,非法字符包括: \ / : * ? " < > | <br>API10-17,非法字符包括:. .. \ / : * ? " ' ` < > | { } [ ] 5522 5523**系统接口**:此接口为系统接口。 5524 5525**系统能力**:SystemCapability.FileManagement.PhotoAccessHelper.Core 5526 5527**参数:** 5528 5529| 参数名 | 类型 | 必填 | 说明 | 5530| ------- | ------- | ---- | -------------------------- | 5531| context | [Context](../apis-ability-kit/js-apis-inner-application-context.md) | 是 | 传入Ability实例的Context。 | 5532| displayName | string | 是 | 待创建的图片或者视频文件名。 | 5533| options | [PhotoCreateOptions](#photocreateoptions) | 否 | 图片或视频的创建选项。 | 5534 5535**返回值:** 5536 5537| 类型 | 说明 | 5538| --------------------------------------- | ----------------- | 5539| [MediaAssetChangeRequest](#mediaassetchangerequest11) | 返回创建资产的变更请求。 | 5540 5541**错误码:** 5542 5543接口抛出错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)和[文件管理错误码](../apis-core-file-kit/errorcode-filemanagement.md)。 5544 5545错误码14000001,请参考 [PhotoKeys](#photokeys)获取有关文件名的格式和长度要求。 5546 5547| 错误码ID | 错误信息 | 5548| -------- | ---------------------------------------- | 5549| 202 | Called by non-system application. | 5550| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types; 3. Parameter verification failed. | 5551| 14000001 | Invalid display name. | 5552| 14000011 | System inner fail. | 5553 5554**示例:** 5555 5556phAccessHelper的创建请参考[@ohos.file.photoAccessHelper (相册管理模块)](arkts-apis-photoAccessHelper-f.md)的示例使用。 5557 5558```ts 5559async function example(phAccessHelper: photoAccessHelper.PhotoAccessHelper, context: Context) { 5560 console.info('createAssetRequestDemo'); 5561 try { 5562 let testFileName: string = 'testFile' + Date.now() + '.jpg'; 5563 let assetChangeRequest: photoAccessHelper.MediaAssetChangeRequest = photoAccessHelper.MediaAssetChangeRequest.createAssetRequest(context, testFileName); 5564 // 需要确保fileUri对应的资源存在。 5565 let fileUri = 'file://com.example.temptest/data/storage/el2/base/haps/entry/files/test.jpg'; 5566 assetChangeRequest.addResource(photoAccessHelper.ResourceType.IMAGE_RESOURCE, fileUri); 5567 await phAccessHelper.applyChanges(assetChangeRequest); 5568 console.info('apply createAssetRequest successfully'); 5569 } catch (err) { 5570 console.error(`createAssetRequestDemo failed with error: ${err.code}, ${err.message}`); 5571 } 5572} 5573``` 5574 5575### setFavorite<sup>11+</sup> 5576 5577setFavorite(favoriteState: boolean): void 5578 5579将文件设置为收藏文件。 5580 5581**系统接口**:此接口为系统接口。 5582 5583**系统能力**:SystemCapability.FileManagement.PhotoAccessHelper.Core 5584 5585**参数:** 5586 5587| 参数名 | 类型 | 必填 | 说明 | 5588| ---------- | ------- | ---- | ---------------------------------- | 5589| favoriteState | boolean | 是 | 是否设置为收藏文件, true:设置为收藏文件;false:取消收藏。 | 5590 5591**错误码:** 5592 5593接口抛出错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)和[文件管理错误码](../apis-core-file-kit/errorcode-filemanagement.md)。 5594 5595| 错误码ID | 错误信息 | 5596| -------- | ---------------------------------------- | 5597| 202 | Called by non-system application. | 5598| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types; 3. Parameter verification failed. | 5599| 14000011 | System inner fail. | 5600 5601**示例:** 5602 5603phAccessHelper的创建请参考[@ohos.file.photoAccessHelper (相册管理模块)](arkts-apis-photoAccessHelper-f.md)的示例使用。 5604 5605```ts 5606import { dataSharePredicates } from '@kit.ArkData'; 5607import { BusinessError } from '@kit.BasicServicesKit'; 5608 5609async function example(phAccessHelper: photoAccessHelper.PhotoAccessHelper) { 5610 console.info('setFavoriteDemo'); 5611 let predicates: dataSharePredicates.DataSharePredicates = new dataSharePredicates.DataSharePredicates(); 5612 let fetchOption: photoAccessHelper.FetchOptions = { 5613 fetchColumns: [], 5614 predicates: predicates 5615 }; 5616 let fetchResult: photoAccessHelper.FetchResult<photoAccessHelper.PhotoAsset> = await phAccessHelper.getAssets(fetchOption); 5617 let asset = await fetchResult.getFirstObject(); 5618 let assetChangeRequest: photoAccessHelper.MediaAssetChangeRequest = new photoAccessHelper.MediaAssetChangeRequest(asset); 5619 assetChangeRequest.setFavorite(true); 5620 phAccessHelper.applyChanges(assetChangeRequest).then(() => { 5621 console.info('apply setFavorite successfully'); 5622 }).catch((err: BusinessError) => { 5623 console.error(`apply setFavorite failed with error: ${err.code}, ${err.message}`); 5624 }); 5625} 5626``` 5627 5628### setHidden<sup>11+</sup> 5629 5630setHidden(hiddenState: boolean): void 5631 5632将文件设置为隐藏文件。 5633 5634**系统接口**:此接口为系统接口。 5635 5636**系统能力**:SystemCapability.FileManagement.PhotoAccessHelper.Core 5637 5638**参数:** 5639 5640| 参数名 | 类型 | 必填 | 说明 | 5641| ---------- | ------- | ---- | ---------------------------------- | 5642| hiddenState | boolean | 是 | 是否设置为隐藏文件,true:将文件资产放入隐藏相册;false:从隐藏相册中恢复。 | 5643 5644**错误码:** 5645 5646接口抛出错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)和[文件管理错误码](../apis-core-file-kit/errorcode-filemanagement.md)。 5647 5648| 错误码ID | 错误信息 | 5649| -------- | ---------------------------------------- | 5650| 202 | Called by non-system application. | 5651| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types; 3. Parameter verification failed. | 5652| 14000011 | System inner fail. | 5653 5654**示例:** 5655 5656phAccessHelper的创建请参考[@ohos.file.photoAccessHelper (相册管理模块)](arkts-apis-photoAccessHelper-f.md)的示例使用。 5657 5658```ts 5659import { dataSharePredicates } from '@kit.ArkData'; 5660import { BusinessError } from '@kit.BasicServicesKit'; 5661 5662async function example(phAccessHelper: photoAccessHelper.PhotoAccessHelper) { 5663 console.info('setHiddenDemo'); 5664 let predicates: dataSharePredicates.DataSharePredicates = new dataSharePredicates.DataSharePredicates(); 5665 let fetchOption: photoAccessHelper.FetchOptions = { 5666 fetchColumns: [], 5667 predicates: predicates 5668 }; 5669 let fetchResult: photoAccessHelper.FetchResult<photoAccessHelper.PhotoAsset> = await phAccessHelper.getAssets(fetchOption); 5670 let asset = await fetchResult.getFirstObject(); 5671 let assetChangeRequest: photoAccessHelper.MediaAssetChangeRequest = new photoAccessHelper.MediaAssetChangeRequest(asset); 5672 assetChangeRequest.setHidden(true); 5673 phAccessHelper.applyChanges(assetChangeRequest).then(() => { 5674 console.info('apply setHidden successfully'); 5675 }).catch((err: BusinessError) => { 5676 console.error(`apply setHidden failed with error: ${err.code}, ${err.message}`); 5677 }); 5678} 5679``` 5680 5681### setUserComment<sup>11+</sup> 5682 5683setUserComment(userComment: string): void 5684 5685修改媒体资产的备注信息。 5686 5687**系统接口**:此接口为系统接口。 5688 5689**系统能力**:SystemCapability.FileManagement.PhotoAccessHelper.Core 5690 5691**参数:** 5692 5693| 参数名 | 类型 | 必填 | 说明 | 5694| ---------- | ------- | ---- | ---------------------------------- | 5695| userComment | string | 是 | 待修改的资产备注信息,备注信息最长为420字符。 | 5696 5697**错误码:** 5698 5699接口抛出错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)和[文件管理错误码](../apis-core-file-kit/errorcode-filemanagement.md)。 5700 5701| 错误码ID | 错误信息 | 5702| -------- | ---------------------------------------- | 5703| 202 | Called by non-system application. | 5704| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types; 3. Parameter verification failed. | 5705| 14000011 | System inner fail. | 5706 5707**示例:** 5708 5709phAccessHelper的创建请参考[@ohos.file.photoAccessHelper (相册管理模块)](arkts-apis-photoAccessHelper-f.md)的示例使用。 5710 5711```ts 5712import { dataSharePredicates } from '@kit.ArkData'; 5713import { BusinessError } from '@kit.BasicServicesKit'; 5714 5715async function example(phAccessHelper: photoAccessHelper.PhotoAccessHelper) { 5716 console.info('setUserCommentDemo'); 5717 let predicates: dataSharePredicates.DataSharePredicates = new dataSharePredicates.DataSharePredicates(); 5718 let fetchOption: photoAccessHelper.FetchOptions = { 5719 fetchColumns: [], 5720 predicates: predicates 5721 }; 5722 let fetchResult: photoAccessHelper.FetchResult<photoAccessHelper.PhotoAsset> = await phAccessHelper.getAssets(fetchOption); 5723 let asset = await fetchResult.getFirstObject(); 5724 let assetChangeRequest: photoAccessHelper.MediaAssetChangeRequest = new photoAccessHelper.MediaAssetChangeRequest(asset); 5725 let userComment: string = 'test_set_user_comment'; 5726 assetChangeRequest.setUserComment(userComment); 5727 phAccessHelper.applyChanges(assetChangeRequest).then(() => { 5728 console.info('apply setUserComment successfully'); 5729 }).catch((err: BusinessError) => { 5730 console.error(`apply setUserComment failed with error: ${err.code}, ${err.message}`); 5731 }); 5732} 5733``` 5734 5735### setEditData<sup>11+</sup> 5736 5737setEditData(editData: MediaAssetEditData): void 5738 5739保存资产的编辑数据。 5740 5741**系统接口**:此接口为系统接口。 5742 5743**系统能力**:SystemCapability.FileManagement.PhotoAccessHelper.Core 5744 5745**参数:** 5746 5747| 参数名 | 类型 | 必填 | 说明 | 5748| ---------- | ------- | ---- | ---------------------------------- | 5749| editData | [MediaAssetEditData](#mediaasseteditdata11) | 是 | 待保存的资产编辑数据。 | 5750 5751**错误码:** 5752 5753接口抛出错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)和[文件管理错误码](../apis-core-file-kit/errorcode-filemanagement.md)。 5754 5755| 错误码ID | 错误信息 | 5756| -------- | ---------------------------------------- | 5757| 202 | Called by non-system application. | 5758| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types; 3. Parameter verification failed. | 5759| 14000011 | System inner fail. | 5760 5761**示例:** 5762 5763phAccessHelper的创建请参考[@ohos.file.photoAccessHelper (相册管理模块)](arkts-apis-photoAccessHelper-f.md)的示例使用。 5764 5765```ts 5766import { dataSharePredicates } from '@kit.ArkData'; 5767import { BusinessError } from '@kit.BasicServicesKit'; 5768 5769async function example(phAccessHelper: photoAccessHelper.PhotoAccessHelper) { 5770 console.info('setEditDataDemo'); 5771 let predicates: dataSharePredicates.DataSharePredicates = new dataSharePredicates.DataSharePredicates(); 5772 let fetchOption: photoAccessHelper.FetchOptions = { 5773 fetchColumns: [], 5774 predicates: predicates 5775 }; 5776 let fetchResult: photoAccessHelper.FetchResult<photoAccessHelper.PhotoAsset> = await phAccessHelper.getAssets(fetchOption); 5777 let asset = await fetchResult.getFirstObject(); 5778 let assetChangeRequest: photoAccessHelper.MediaAssetChangeRequest = new photoAccessHelper.MediaAssetChangeRequest(asset); 5779 5780 let assetEditData: photoAccessHelper.MediaAssetEditData = new photoAccessHelper.MediaAssetEditData('system', '1.0'); 5781 let fileUri = 'file://com.example.temptest/data/storage/el2/base/haps/entry/files/test.jpg'; 5782 assetChangeRequest.addResource(photoAccessHelper.ResourceType.IMAGE_RESOURCE, fileUri); 5783 assetEditData.data = '123456'; 5784 assetChangeRequest.setEditData(assetEditData); 5785 phAccessHelper.applyChanges(assetChangeRequest).then(() => { 5786 console.info('apply setEditData successfully'); 5787 }).catch((err: BusinessError) => { 5788 console.error(`apply setEditData failed with error: ${err.code}, ${err.message}`); 5789 }); 5790} 5791``` 5792 5793### addResource<sup>11+</sup> 5794 5795addResource(type: ResourceType, proxy: PhotoProxy): void 5796 5797通过PhotoProxy数据添加资源。 5798 5799**注意**:对于同一个资产变更请求,不支持在成功添加资源后,重复调用该接口。 5800 5801**系统接口**:此接口为系统接口,仅提供给相机应用使用。 5802 5803**系统能力**:SystemCapability.FileManagement.PhotoAccessHelper.Core 5804 5805**参数:** 5806 5807| 参数名 | 类型 | 必填 | 说明 | 5808| ------- |---------------------------------| ---- |----------------------| 5809| type | [ResourceType](#resourcetype11) | 是 | 待添加资源的类型。 | 5810| proxy | [PhotoProxy](#photoproxy11) | 是 | 待添加资源的PhotoProxy 数据。 | 5811 5812**错误码:** 5813 5814接口抛出错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)和[文件管理错误码](../apis-core-file-kit/errorcode-filemanagement.md)。 5815 5816| 错误码ID | 错误信息 | 5817|----------|-----------------------------------| 5818| 202 | Called by non-system application. | 5819| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types; 3. Parameter verification failed. | 5820| 14000011 | System inner fail. | 5821| 14000016 | Operation Not Support. | 5822 5823**示例:** 5824 5825phAccessHelper的创建请参考[@ohos.file.photoAccessHelper (相册管理模块)](arkts-apis-photoAccessHelper-f.md)的示例使用。 5826 5827```ts 5828class PhotoProxyImpl implements photoAccessHelper.PhotoProxy { 5829 // 应用实现PhotoProxy。 5830} 5831 5832async function example(phAccessHelper: photoAccessHelper.PhotoAccessHelper, asset: photoAccessHelper.PhotoAsset, context: Context) { 5833 console.info('addResourceByPhotoProxyDemo'); 5834 try { 5835 let photoType: photoAccessHelper.PhotoType = photoAccessHelper.PhotoType.IMAGE; 5836 let extension: string = 'jpg'; 5837 let assetChangeRequest: photoAccessHelper.MediaAssetChangeRequest = photoAccessHelper.MediaAssetChangeRequest.createAssetRequest(context, photoType, extension); 5838 let photoProxy: PhotoProxyImpl = new PhotoProxyImpl(); 5839 assetChangeRequest.addResource(photoAccessHelper.ResourceType.IMAGE_RESOURCE, photoProxy); 5840 await phAccessHelper.applyChanges(assetChangeRequest); 5841 console.info('addResourceByPhotoProxy successfully'); 5842 } catch (err) { 5843 console.error(`addResourceByPhotoProxyDemo failed with error: ${err.code}, ${err.message}`); 5844 } 5845} 5846``` 5847 5848### setLocation<sup>11+</sup> 5849 5850setLocation(longitude: number, latitude: number): void 5851 5852设置文件的经纬度信息。 5853 5854**系统接口**:此接口为系统接口 5855 5856**系统能力**:SystemCapability.FileManagement.PhotoAccessHelper.Core 5857 5858**参数:** 5859 5860| 参数名 | 类型 | 必填 | 说明 | 5861| ------- |-------------| ---- |-------| 5862| longitude | number | 是 | 经度。 | 5863| latitude | number | 是 | 纬度。 | 5864 5865**错误码:** 5866 5867接口抛出错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)和[文件管理错误码](../apis-core-file-kit/errorcode-filemanagement.md)。 5868 5869| 错误码ID | 错误信息 | 5870| -------- | ---------------------------------------- | 5871| 202 | Called by non-system application. | 5872| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types; 3. Parameter verification failed. | 5873| 14000011 | System inner fail. | 5874 5875**示例:** 5876 5877phAccessHelper的创建请参考[@ohos.file.photoAccessHelper (相册管理模块)](arkts-apis-photoAccessHelper-f.md)的示例使用。 5878 5879```ts 5880import { dataSharePredicates } from '@kit.ArkData'; 5881import { BusinessError } from '@kit.BasicServicesKit'; 5882 5883async function example(phAccessHelper: photoAccessHelper.PhotoAccessHelper) { 5884 console.info('setLocationDemo'); 5885 let predicates: dataSharePredicates.DataSharePredicates = new dataSharePredicates.DataSharePredicates(); 5886 let fetchOption: photoAccessHelper.FetchOptions = { 5887 fetchColumns: [], 5888 predicates: predicates 5889 }; 5890 let fetchResult: photoAccessHelper.FetchResult<photoAccessHelper.PhotoAsset> = await phAccessHelper.getAssets(fetchOption); 5891 let asset = await fetchResult.getFirstObject(); 5892 let assetChangeRequest: photoAccessHelper.MediaAssetChangeRequest = new photoAccessHelper.MediaAssetChangeRequest(asset); 5893 assetChangeRequest.setLocation(120.52, 30.40); 5894 phAccessHelper.applyChanges(assetChangeRequest).then(() => { 5895 console.info('apply setLocation successfully'); 5896 }).catch((err: BusinessError) => { 5897 console.error(`apply setLocation failed with error: ${err.code}, ${err.message}`); 5898 }); 5899} 5900``` 5901 5902### setCameraShotKey<sup>12+</sup> 5903 5904setCameraShotKey(cameraShotKey: string): void 5905 5906设置锁屏相机拍照或录像的标记字段。 5907 5908**系统接口**:此接口为系统接口。 5909 5910**系统能力**:SystemCapability.FileManagement.PhotoAccessHelper.Core 5911 5912**参数:** 5913 5914| 参数名 | 类型 | 必填 | 说明 | 5915| ---------- | ------- | ---- | ---------------------------------- | 5916| cameraShotKey | string | 是 | 锁屏相机拍照或录像的标记字段(仅开放给系统相机,其key值由系统相机定义)。 | 5917 5918**错误码:** 5919 5920接口抛出错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)和[文件管理错误码](../apis-core-file-kit/errorcode-filemanagement.md)。 5921 5922| 错误码ID | 错误信息 | 5923| -------- | ---------------------------------------- | 5924| 202 | Called by non-system application. | 5925| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types; 3. Parameter verification failed. | 5926| 14000011 | System inner fail. | 5927 5928**示例:** 5929 5930phAccessHelper的创建请参考[@ohos.file.photoAccessHelper (相册管理模块)](arkts-apis-photoAccessHelper-f.md)的示例使用。 5931 5932```ts 5933async function example(phAccessHelper: photoAccessHelper.PhotoAccessHelper, asset: photoAccessHelper.PhotoAsset) { 5934 console.info('setCameraShotKeyDemo'); 5935 try { 5936 let assetChangeRequest: photoAccessHelper.MediaAssetChangeRequest = new photoAccessHelper.MediaAssetChangeRequest(asset); 5937 let cameraShotKey: string = 'test_MediaAssetChangeRequest_setCameraShotKey'; 5938 assetChangeRequest.setCameraShotKey(cameraShotKey); 5939 await phAccessHelper.applyChanges(assetChangeRequest); 5940 console.info('apply setCameraShotKey successfully'); 5941 } catch (err) { 5942 console.error(`apply setCameraShotKey failed with error: ${err.code}, ${err.message}`); 5943 } 5944} 5945``` 5946 5947### setEffectMode<sup>12+</sup> 5948 5949setEffectMode(mode: MovingPhotoEffectMode): void 5950 5951设置动态照片的效果模式。 5952 5953**系统接口**:此接口为系统接口。 5954 5955**系统能力**:SystemCapability.FileManagement.PhotoAccessHelper.Core 5956 5957**参数:** 5958 5959| 参数名 | 类型 | 必填 | 说明 | 5960| ---------- | ------- | ---- | ---------------------------------- | 5961| mode | [MovingPhotoEffectMode](#movingphotoeffectmode12) | 是 | 动态照片效果模式。 | 5962 5963**错误码:** 5964 5965接口抛出错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)和[文件管理错误码](../apis-core-file-kit/errorcode-filemanagement.md)。 5966 5967| 错误码ID | 错误信息 | 5968| -------- | ---------------------------------------- | 5969| 202 | Called by non-system application. | 5970| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types; 3. Parameter verification failed. | 5971| 14000011 | System inner fail. | 5972| 14000016 | Operation Not Support. | 5973 5974**示例:** 5975 5976phAccessHelper的创建请参考[@ohos.file.photoAccessHelper (相册管理模块)](arkts-apis-photoAccessHelper-f.md)的示例使用。 5977 5978```ts 5979async function example(phAccessHelper: photoAccessHelper.PhotoAccessHelper, asset: photoAccessHelper.PhotoAsset) { 5980 console.info('setEffectModeDemo'); 5981 try { 5982 let assetChangeRequest: photoAccessHelper.MediaAssetChangeRequest = new photoAccessHelper.MediaAssetChangeRequest(asset); 5983 assetChangeRequest.setEffectMode(photoAccessHelper.MovingPhotoEffectMode.LONG_EXPOSURE); 5984 // 需要确保fileUri对应的资源存在。 5985 let imageFileUri = 'file://com.example.temptest/data/storage/el2/base/haps/entry/files/long_exposure.jpg'; 5986 let videoFileUri = 'file://com.example.temptest/data/storage/el2/base/haps/entry/files/long_exposure.mp4'; 5987 assetChangeRequest.addResource(photoAccessHelper.ResourceType.IMAGE_RESOURCE, imageFileUri); 5988 assetChangeRequest.addResource(photoAccessHelper.ResourceType.VIDEO_RESOURCE, videoFileUri); 5989 await phAccessHelper.applyChanges(assetChangeRequest); 5990 console.info('apply setEffectMode successfully'); 5991 } catch (err) { 5992 console.error(`apply setEffectMode failed with error: ${err.code}, ${err.message}`); 5993 } 5994} 5995``` 5996 5997### setSupportedWatermarkType<sup>14+</sup> 5998 5999setSupportedWatermarkType(watermarkType: WatermarkType): void 6000 6001设置拍照照片支持的水印类型。 6002 6003**系统接口**:此接口为系统接口。 6004 6005**系统能力**:SystemCapability.FileManagement.PhotoAccessHelper.Core 6006 6007**参数:** 6008 6009| 参数名 | 类型 | 必填 | 说明 | 6010| ---------- | ------- | ---- | ---------------------------------- | 6011| watermarkType | [WatermarkType](#watermarktype14) | 是 | 水印可编辑标识。<br>**注意:** 不支持传入WatermarkType.DEFAULT。 | 6012 6013**错误码:** 6014 6015接口抛出错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)和[文件管理错误码](../apis-core-file-kit/errorcode-filemanagement.md)。 6016 6017| 错误码ID | 错误信息 | 6018| -------- | ---------------------------------------- | 6019| 202 | Called by non-system application. | 6020| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types; 3. Parameter verification failed. | 6021| 14000011 | Internal system error. | 6022 6023**示例:** 6024 6025```ts 6026import { dataSharePredicates } from '@kit.ArkData'; 6027 6028async function example(phAccessHelper: photoAccessHelper.PhotoAccessHelper) { 6029 console.info('setSupportedWatermarkTypeDemo'); 6030 let predicates: dataSharePredicates.DataSharePredicates = new dataSharePredicates.DataSharePredicates(); 6031 let fetchOption: photoAccessHelper.FetchOptions = { 6032 fetchColumns: [], 6033 predicates: predicates 6034 }; 6035 try { 6036 let fetchResult: photoAccessHelper.FetchResult<photoAccessHelper.PhotoAsset> = await phAccessHelper.getAssets(fetchOption); 6037 let asset = await fetchResult.getFirstObject(); 6038 let assetChangeRequest: photoAccessHelper.MediaAssetChangeRequest = new photoAccessHelper.MediaAssetChangeRequest(asset); 6039 assetChangeRequest.setSupportedWatermarkType(photoAccessHelper.WatermarkType.BRAND_COMMON); 6040 await phAccessHelper.applyChanges(assetChangeRequest); 6041 console.info('apply setSupportedWatermarkType successfully'); 6042 } catch (err) { 6043 console.error(`apply setSupportedWatermarkType failed with error: ${err.code}, ${err.message}`); 6044 } 6045} 6046``` 6047 6048### deleteLocalAssetsPermanently<sup>18+</sup> 6049 6050static deleteLocalAssetsPermanently(context: Context, assets: Array\<PhotoAsset>): Promise<void> 6051 6052批量彻底删除照片或者视频,使用promise方式返回异步结果。 6053 6054**注意**:此操作不可逆,执行此操作后文件资源将彻底删除,请谨慎操作。 6055 6056**系统接口**:此接口为系统接口。 6057 6058**系统能力**:SystemCapability.FileManagement.PhotoAccessHelper.Core 6059 6060**需要权限**:ohos.permission.WRITE_IMAGEVIDEO 6061 6062**参数:** 6063 6064| 参数名 | 类型 | 必填 | 说明 | 6065| ---- | -------------- | ---- | ----- | 6066| context | [Context](../apis-ability-kit/js-apis-inner-application-context.md) | 是 | 传入Ability实例的Context。 | 6067| assets | Array\<[PhotoAsset](#photoasset)>| 是 | 待彻底删除的图片或者视频数组,数组中元素个数不超过500个。 | 6068 6069**返回值:** 6070 6071| 类型 | 说明 | 6072| ------------------- | ---------- | 6073| Promise<void> | Promise对象,返回void。 | 6074 6075**错误码:** 6076 6077接口抛出错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)和[文件管理错误码](../apis-core-file-kit/errorcode-filemanagement.md)。 6078 6079| 错误码ID | 错误信息 | 6080| -------- | ---------------------------------------- | 6081| 201 | Permission denied. | 6082| 202 | Called by non-system application. | 6083| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types; 3. Parameter verification failed. | 6084| 14000011 | Internal system error. 6085 6086**示例:** 6087 6088```ts 6089import { dataSharePredicates } from '@kit.ArkData'; 6090import { BusinessError } from '@kit.BasicServicesKit'; 6091 6092async function example(phAccessHelper: photoAccessHelper.PhotoAccessHelper, context: Context) { 6093 console.info('deleteAssetsPermanentlyDemo'); 6094 let predicates: dataSharePredicates.DataSharePredicates = new dataSharePredicates.DataSharePredicates(); 6095 let fetchOptions: photoAccessHelper.FetchOptions = { 6096 fetchColumns: [], 6097 predicates: predicates 6098 }; 6099 try { 6100 let fetchResult: photoAccessHelper.FetchResult<photoAccessHelper.PhotoAsset> = await phAccessHelper.getAssets(fetchOptions); 6101 let photoAssetList: Array<photoAccessHelper.PhotoAsset> = await fetchResult.getAllObjects(); 6102 await photoAccessHelper.MediaAssetChangeRequest.deleteLocalAssetsPermanently(context, photoAssetList); 6103 } catch (err) { 6104 console.error(`deleteAssetsPermanentlyDemo failed with error: ${err.code}, ${err.message}`); 6105 } 6106} 6107``` 6108 6109### deleteLocalAssetsPermanentlyWithUri<sup>19+</sup> 6110 6111static deleteLocalAssetsPermanentlyWithUri(context: Context, assetUris: Array<String>): Promise<void> 6112 6113通过资产Uri批量彻底删除照片或者视频。使用promise异步回调。 6114 6115>**注意**: 6116> 此操作不可逆,执行此操作后文件资源将被彻底删除,请谨慎操作。 6117 6118**系统接口**:此接口为系统接口。 6119 6120**系统能力**:SystemCapability.FileManagement.PhotoAccessHelper.Core 6121 6122**需要权限**:ohos.permission.WRITE_IMAGEVIDEO 6123 6124**参数:** 6125 6126| 参数名 | 类型 | 必填 | 说明 | 6127| ---- | -------------- | ---- | ----- | 6128| context | [Context](../apis-ability-kit/js-apis-inner-application-context.md) | 是 | 传入Ability实例的Context。 | 6129| assetUris | Array<String> | 是 | 待彻底删除的图片或者视频Uri数组,数组中元素个数不超过500个。 | 6130 6131**返回值:** 6132 6133| 类型 | 说明 | 6134| ------------------- | ---------- | 6135| Promise<void> | Promise对象。无返回结果的Promise对象。 | 6136 6137**错误码:** 6138 6139以下错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)和[文件管理错误码](../apis-core-file-kit/errorcode-filemanagement.md)。 6140 6141| 错误码ID | 错误信息 | 6142| -------- | ---------------------------------------- | 6143| 201 | Permission denied. | 6144| 202 | Called by non-system application. | 6145| 13900020 | Invalid argument. | 6146| 14000011 | Internal system error. It is recommended to retry and check the logs.<br>Possible causes: 1. Database corrupted; 2. The file system is abnormal; 3. The IPC request timed out. | 6147 6148**示例:** 6149 6150```ts 6151import { dataSharePredicates } from '@kit.ArkData'; 6152 6153async function example(phAccessHelper: photoAccessHelper.PhotoAccessHelper, context: Context) { 6154 console.info('deleteLocalAssetsPermanentlyWithUriDemo'); 6155 let predicates: dataSharePredicates.DataSharePredicates = new dataSharePredicates.DataSharePredicates(); 6156 let fetchOptions: photoAccessHelper.FetchOptions = { 6157 fetchColumns: [], 6158 predicates: predicates 6159 }; 6160 try { 6161 let photoUris: Array<string> = []; 6162 let fetchResult: photoAccessHelper.FetchResult<photoAccessHelper.PhotoAsset> = await phAccessHelper.getAssets(fetchOptions); 6163 let assets: Array<photoAccessHelper.PhotoAsset> = await fetchResult.getAllObjects(); 6164 for (const asset of assets) { 6165 if (!asset?.uri) { 6166 continue; 6167 } 6168 let uri:string = asset.uri.trim(); 6169 photoUris.push(uri); 6170 } 6171 await photoAccessHelper.MediaAssetChangeRequest.deleteLocalAssetsPermanentlyWithUri(context, photoUris); 6172 } catch (err) { 6173 console.error(`deleteLocalAssetsPermanentlyWithUriDemo failed with error: ${err.code}, ${err.message}`); 6174} 6175} 6176``` 6177 6178## MediaAssetsChangeRequest<sup>11+</sup> 6179 6180批量资产变更请求。 6181 6182**系统接口**:此接口为系统接口。 6183 6184**系统能力**:SystemCapability.FileManagement.PhotoAccessHelper.Core 6185 6186### constructor<sup>11+</sup> 6187 6188constructor(assets: Array<PhotoAsset>) 6189 6190构造函数。 6191 6192**系统接口**:此接口为系统接口。 6193 6194**系统能力**:SystemCapability.FileManagement.PhotoAccessHelper.Core 6195 6196**参数:** 6197 6198| 参数名 | 类型 | 必填 | 说明 | 6199| -------- | ------------------------- | ---- | ---------- | 6200| assets | Array<[PhotoAsset](#photoasset)> | 是 | 需要变更的资产数组。 | 6201 6202**错误码:** 6203 6204接口抛出错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)和[文件管理错误码](../apis-core-file-kit/errorcode-filemanagement.md)。 6205 6206| 错误码ID | 错误信息 | 6207| -------- | ---------------------------------------- | 6208| 202 | Called by non-system application. | 6209| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types; 3. Parameter verification failed. | 6210| 14000011 | System inner fail. | 6211 6212**示例:** 6213 6214phAccessHelper的创建请参考[@ohos.file.photoAccessHelper (相册管理模块)](arkts-apis-photoAccessHelper-f.md)的示例使用。 6215 6216```ts 6217import { dataSharePredicates } from '@kit.ArkData'; 6218 6219async function example(phAccessHelper: photoAccessHelper.PhotoAccessHelper) { 6220 console.info('MediaAssetsChangeRequest constructorDemo'); 6221 let predicates: dataSharePredicates.DataSharePredicates = new dataSharePredicates.DataSharePredicates(); 6222 let fetchOption: photoAccessHelper.FetchOptions = { 6223 fetchColumns: [], 6224 predicates: predicates 6225 }; 6226 let fetchResult: photoAccessHelper.FetchResult<photoAccessHelper.PhotoAsset> = await phAccessHelper.getAssets(fetchOption); 6227 let photoAssetList: Array<photoAccessHelper.PhotoAsset> = await fetchResult.getAllObjects(); 6228 let assetsChangeRequest: photoAccessHelper.MediaAssetsChangeRequest = new photoAccessHelper.MediaAssetsChangeRequest(photoAssetList); 6229} 6230``` 6231 6232### setFavorite<sup>11+</sup> 6233 6234setFavorite(favoriteState: boolean): void 6235 6236将文件设置为收藏文件。 6237 6238**系统接口**:此接口为系统接口。 6239 6240**系统能力**:SystemCapability.FileManagement.PhotoAccessHelper.Core 6241 6242**参数:** 6243 6244| 参数名 | 类型 | 必填 | 说明 | 6245| ---------- | ------- | ---- | ---------------------------------- | 6246| favoriteState | boolean | 是 | 是否设置为收藏文件, true:设置为收藏文件;false:取消收藏。 | 6247 6248**错误码:** 6249 6250接口抛出错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)和[文件管理错误码](../apis-core-file-kit/errorcode-filemanagement.md)。 6251 6252| 错误码ID | 错误信息 | 6253| -------- | ---------------------------------------- | 6254| 202 | Called by non-system application. | 6255| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types; 3. Parameter verification failed. | 6256| 14000011 | System inner fail. | 6257 6258**示例:** 6259 6260phAccessHelper的创建请参考[@ohos.file.photoAccessHelper (相册管理模块)](arkts-apis-photoAccessHelper-f.md)的示例使用。 6261 6262```ts 6263import { dataSharePredicates } from '@kit.ArkData'; 6264import { BusinessError } from '@kit.BasicServicesKit'; 6265 6266async function example(phAccessHelper: photoAccessHelper.PhotoAccessHelper) { 6267 console.info('setFavoriteDemo'); 6268 let predicates: dataSharePredicates.DataSharePredicates = new dataSharePredicates.DataSharePredicates(); 6269 let fetchOption: photoAccessHelper.FetchOptions = { 6270 fetchColumns: [], 6271 predicates: predicates 6272 }; 6273 let fetchResult: photoAccessHelper.FetchResult<photoAccessHelper.PhotoAsset> = await phAccessHelper.getAssets(fetchOption); 6274 let photoAssetList: Array<photoAccessHelper.PhotoAsset> = await fetchResult.getAllObjects(); 6275 let assetsChangeRequest: photoAccessHelper.MediaAssetsChangeRequest = new photoAccessHelper.MediaAssetsChangeRequest(photoAssetList); 6276 assetsChangeRequest.setFavorite(true); 6277 phAccessHelper.applyChanges(assetsChangeRequest).then(() => { 6278 console.info('apply setFavorite successfully'); 6279 }).catch((err: BusinessError) => { 6280 console.error(`apply setFavorite failed with error: ${err.code}, ${err.message}`); 6281 }); 6282} 6283``` 6284 6285### setHidden<sup>11+</sup> 6286 6287setHidden(hiddenState: boolean): void 6288 6289将文件设置为隐藏文件。 6290 6291**系统接口**:此接口为系统接口。 6292 6293**系统能力**:SystemCapability.FileManagement.PhotoAccessHelper.Core 6294 6295**参数:** 6296 6297| 参数名 | 类型 | 必填 | 说明 | 6298| ---------- | ------- | ---- | ---------------------------------- | 6299| hiddenState | boolean | 是 | 是否设置为隐藏文件,true:将文件资产放入隐藏相册;false:从隐藏相册中恢复。 | 6300 6301**错误码:** 6302 6303接口抛出错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)和[文件管理错误码](../apis-core-file-kit/errorcode-filemanagement.md)。 6304 6305| 错误码ID | 错误信息 | 6306| -------- | ---------------------------------------- | 6307| 202 | Called by non-system application. | 6308| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types; 3. Parameter verification failed. | 6309| 14000011 | System inner fail. | 6310 6311**示例:** 6312 6313phAccessHelper的创建请参考[@ohos.file.photoAccessHelper (相册管理模块)](arkts-apis-photoAccessHelper-f.md)的示例使用。 6314 6315```ts 6316import { dataSharePredicates } from '@kit.ArkData'; 6317import { BusinessError } from '@kit.BasicServicesKit'; 6318 6319async function example(phAccessHelper: photoAccessHelper.PhotoAccessHelper) { 6320 console.info('setHiddenDemo'); 6321 let predicates: dataSharePredicates.DataSharePredicates = new dataSharePredicates.DataSharePredicates(); 6322 let fetchOption: photoAccessHelper.FetchOptions = { 6323 fetchColumns: [], 6324 predicates: predicates 6325 }; 6326 let fetchResult: photoAccessHelper.FetchResult<photoAccessHelper.PhotoAsset> = await phAccessHelper.getAssets(fetchOption); 6327 let photoAssetList: Array<photoAccessHelper.PhotoAsset> = await fetchResult.getAllObjects(); 6328 let assetsChangeRequest: photoAccessHelper.MediaAssetsChangeRequest = new photoAccessHelper.MediaAssetsChangeRequest(photoAssetList); 6329 assetsChangeRequest.setHidden(true); 6330 phAccessHelper.applyChanges(assetsChangeRequest).then(() => { 6331 console.info('apply setHidden successfully'); 6332 }).catch((err: BusinessError) => { 6333 console.error(`apply setHidden failed with error: ${err.code}, ${err.message}`); 6334 }); 6335} 6336``` 6337 6338### setUserComment<sup>11+</sup> 6339 6340setUserComment(userComment: string): void 6341 6342修改媒体资产的备注信息。 6343 6344**系统接口**:此接口为系统接口。 6345 6346**系统能力**:SystemCapability.FileManagement.PhotoAccessHelper.Core 6347 6348**参数:** 6349 6350| 参数名 | 类型 | 必填 | 说明 | 6351| ---------- | ------- | ---- | ---------------------------------- | 6352| userComment | string | 是 | 待修改的资产备注信息,备注信息最长为420字符。 | 6353 6354**错误码:** 6355 6356接口抛出错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)和[文件管理错误码](../apis-core-file-kit/errorcode-filemanagement.md)。 6357 6358| 错误码ID | 错误信息 | 6359| -------- | ---------------------------------------- | 6360| 202 | Called by non-system application. | 6361| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types; 3. Parameter verification failed. | 6362| 14000011 | System inner fail. | 6363 6364**示例:** 6365 6366phAccessHelper的创建请参考[@ohos.file.photoAccessHelper (相册管理模块)](arkts-apis-photoAccessHelper-f.md)的示例使用。 6367 6368```ts 6369import { dataSharePredicates } from '@kit.ArkData'; 6370import { BusinessError } from '@kit.BasicServicesKit'; 6371 6372async function example(phAccessHelper: photoAccessHelper.PhotoAccessHelper) { 6373 console.info('setUserCommentDemo'); 6374 let predicates: dataSharePredicates.DataSharePredicates = new dataSharePredicates.DataSharePredicates(); 6375 let fetchOption: photoAccessHelper.FetchOptions = { 6376 fetchColumns: [], 6377 predicates: predicates 6378 }; 6379 let fetchResult: photoAccessHelper.FetchResult<photoAccessHelper.PhotoAsset> = await phAccessHelper.getAssets(fetchOption); 6380 let photoAssetList: Array<photoAccessHelper.PhotoAsset> = await fetchResult.getAllObjects(); 6381 let assetsChangeRequest: photoAccessHelper.MediaAssetsChangeRequest = new photoAccessHelper.MediaAssetsChangeRequest(photoAssetList); 6382 assetsChangeRequest.setUserComment('test_set_user_comment'); 6383 phAccessHelper.applyChanges(assetsChangeRequest).then(() => { 6384 console.info('apply setUserComment successfully'); 6385 }).catch((err: BusinessError) => { 6386 console.error(`apply setUserComment failed with error: ${err.code}, ${err.message}`); 6387 }); 6388} 6389``` 6390 6391### setIsRecentShow<sup>18+</sup> 6392 6393setIsRecentShow(isRencentShow: boolean): void 6394 6395设置当前资产是否在“最近”列表中显示。 6396 6397**系统接口**:此接口为系统接口。 6398 6399**系统能力**:SystemCapability.FileManagement.PhotoAccessHelper.Core 6400 6401**参数:** 6402 6403| 参数名 | 类型 | 必填 | 说明 | 6404| ---------- | ------- | ---- | ---------------------------------- | 6405| isRencentShow | boolean | 是 | 表示当前资产是否在“最近”列表中显示。true表示显示,false表示不显示。 | 6406 6407**错误码:** 6408 6409接口抛出错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)和[文件管理错误码](../apis-core-file-kit/errorcode-filemanagement.md)。 6410 6411| 错误码ID | 错误信息 | 6412| -------- | ---------------------------------------- | 6413| 202 | Called by non-system application. | 6414| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types; 3. Parameter verification failed. | 6415| 14000011 | System inner fail. | 6416 6417**示例:** 6418 6419phAccessHelper的创建请参考[@ohos.file.photoAccessHelper (相册管理模块)](arkts-apis-photoAccessHelper-f.md)的示例使用。 6420 6421```ts 6422import { dataSharePredicates } from '@kit.ArkData'; 6423import { BusinessError } from '@kit.BasicServicesKit'; 6424 6425async function example(phAccessHelper: photoAccessHelper.PhotoAccessHelper) { 6426 console.info('setIsRecentShowDemo'); 6427 let predicates: dataSharePredicates.DataSharePredicates = new dataSharePredicates.DataSharePredicates(); 6428 let fetchOption: photoAccessHelper.FetchOptions = { 6429 fetchColumns: [], 6430 predicates: predicates 6431 }; 6432 let fetchResult: photoAccessHelper.FetchResult<photoAccessHelper.PhotoAsset> = await phAccessHelper.getAssets(fetchOption); 6433 let photoAssetList: Array<photoAccessHelper.PhotoAsset> = await fetchResult.getAllObjects(); 6434 let assetsChangeRequest: photoAccessHelper.MediaAssetsChangeRequest = new photoAccessHelper.MediaAssetsChangeRequest(photoAssetList); 6435 assetsChangeRequest.setIsRecentShow(true); 6436 phAccessHelper.applyChanges(assetsChangeRequest).then(() => { 6437 console.info('apply setIsRecentShow successfully'); 6438 }).catch((err: BusinessError) => { 6439 console.error(`apply setIsRecentShow failed with error: ${err.code}, ${err.message}`); 6440 }); 6441} 6442``` 6443 6444## MediaAlbumChangeRequest<sup>11+</sup> 6445 6446相册变更请求。 6447 6448**系统能力**:SystemCapability.FileManagement.PhotoAccessHelper.Core 6449 6450### createAlbumRequest<sup>11+</sup> 6451 6452static createAlbumRequest(context: Context, name: string): MediaAlbumChangeRequest 6453 6454创建相册变更请求。 6455 6456相册名的参数规格为: 6457- 相册名字符串长度为1~255。 6458- 不允许出现的非法英文字符,包括:<br> . .. \ / : * ? " ' ` < > | { } [ ] 6459- 英文字符大小写不敏感。 6460- 相册名不允许重名。 6461 6462**系统接口**:此接口为系统接口。 6463 6464**系统能力**:SystemCapability.FileManagement.PhotoAccessHelper.Core 6465 6466**参数:** 6467 6468| 参数名 | 类型 | 必填 | 说明 | 6469| ------- | ------- | ---- | -------------------------- | 6470| context | [Context](../apis-ability-kit/js-apis-inner-application-context.md) | 是 | 传入Ability实例的Context。 | 6471| name | string | 是 | 待创建相册的名称。| 6472 6473**返回值:** 6474 6475| 类型 | 说明 | 6476| --------------------------------------- | ----------------- | 6477| [MediaAlbumChangeRequest](#mediaalbumchangerequest11) | 返回创建相册的变更请求。 | 6478 6479**错误码:** 6480 6481接口抛出错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)和[文件管理错误码](../apis-core-file-kit/errorcode-filemanagement.md)。 6482 6483| 错误码ID | 错误信息 | 6484| -------- | ---------------------------------------- | 6485| 202 | Called by non-system application. | 6486| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types; 3. Parameter verification failed. | 6487| 14000011 | System inner fail. | 6488 6489**示例:** 6490 6491phAccessHelper的创建请参考[@ohos.file.photoAccessHelper (相册管理模块)](arkts-apis-photoAccessHelper-f.md)的示例使用。 6492 6493```ts 6494async function example(phAccessHelper: photoAccessHelper.PhotoAccessHelper, context: Context) { 6495 console.info('createAlbumRequestDemo'); 6496 try { 6497 let albumName: string = 'newAlbumName' + new Date().getTime(); 6498 let albumChangeRequest: photoAccessHelper.MediaAlbumChangeRequest = photoAccessHelper.MediaAlbumChangeRequest.createAlbumRequest(context, albumName); 6499 await phAccessHelper.applyChanges(albumChangeRequest); 6500 console.info('apply createAlbumRequest successfully'); 6501 } catch (err) { 6502 console.error(`createAlbumRequestDemo failed with error: ${err.code}, ${err.message}`); 6503 } 6504} 6505``` 6506 6507### deleteAlbums<sup>11+</sup> 6508 6509static deleteAlbums(context: Context, albums: Array<Album>): Promise<void> 6510 6511删除相册,使用Promise方式返回结果。 6512 6513删除相册前需先确保相册存在,只能删除用户相册。 6514 6515**系统接口**:此接口为系统接口。 6516 6517**需要权限**:ohos.permission.WRITE_IMAGEVIDEO 6518 6519**系统能力**:SystemCapability.FileManagement.PhotoAccessHelper.Core 6520 6521**参数:** 6522 6523| 参数名 | 类型 | 必填 | 说明 | 6524| ------- | ------- | ---- | -------------------------- | 6525| context | [Context](../apis-ability-kit/js-apis-inner-application-context.md) | 是 | 传入Ability实例的Context。 | 6526| albums | Array<[Album](#album)> | 是 | 待删除的相册数组。 | 6527 6528**返回值:** 6529 6530| 类型 | 说明 | 6531| --------------------------------------- | ----------------- | 6532| Promise<void>| Promise对象,返回void。 | 6533 6534**错误码:** 6535 6536接口抛出错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)和[文件管理错误码](../apis-core-file-kit/errorcode-filemanagement.md)。 6537 6538| 错误码ID | 错误信息 | 6539| -------- | ---------------------------------------- | 6540| 201 | Permission denied. | 6541| 202 | Called by non-system application. | 6542| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types; 3. Parameter verification failed. | 6543| 14000011 | System inner fail. | 6544 6545**示例:** 6546 6547phAccessHelper的创建请参考[@ohos.file.photoAccessHelper (相册管理模块)](arkts-apis-photoAccessHelper-f.md)的示例使用。 6548 6549```ts 6550import { dataSharePredicates } from '@kit.ArkData'; 6551 6552async function example(phAccessHelper: photoAccessHelper.PhotoAccessHelper, context: Context) { 6553 console.info('deleteAlbumsDemo'); 6554 let predicates: dataSharePredicates.DataSharePredicates = new dataSharePredicates.DataSharePredicates(); 6555 let fetchOptions: photoAccessHelper.FetchOptions = { 6556 fetchColumns: [], 6557 predicates: predicates 6558 }; 6559 try { 6560 let fetchResult: photoAccessHelper.FetchResult<photoAccessHelper.Album> = await phAccessHelper.getAlbums(photoAccessHelper.AlbumType.USER, photoAccessHelper.AlbumSubtype.USER_GENERIC, fetchOptions); 6561 let album: photoAccessHelper.Album = await fetchResult.getFirstObject(); 6562 await photoAccessHelper.MediaAlbumChangeRequest.deleteAlbums(context, [album]); 6563 console.info('deleteAlbums successfully'); 6564 } catch (err) { 6565 console.error(`deleteAlbumsDemo failed with error: ${err.code}, ${err.message}`); 6566 } 6567} 6568``` 6569 6570### deleteAlbumsWithUri<sup>19+</sup> 6571 6572static deleteAlbumsWithUri(context: Context, albumUris: Array<string>): Promise<void> 6573 6574删除已存在的用户相册。使用promise异步回调。 6575 6576**系统接口**:此接口为系统接口。 6577 6578**需要权限**:ohos.permission.WRITE_IMAGEVIDEO 6579 6580**系统能力**:SystemCapability.FileManagement.PhotoAccessHelper.Core 6581 6582**参数:** 6583 6584| 参数名 | 类型 | 必填 | 说明 | 6585| ------- | ------- | ---- | -------------------------- | 6586| context | [Context](../apis-ability-kit/js-apis-inner-application-context.md) | 是 | 传入Ability实例的Context。 | 6587| albumUris | Array<string> | 是 | 待删除相册Uri的数组。 | 6588 6589**返回值:** 6590 6591| 类型 | 说明 | 6592| --------------------------------------- | ----------------- | 6593| Promise<void>| Promise对象。无返回结果的Promise对象。 | 6594 6595**错误码:** 6596 6597以下错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)和[文件管理错误码](../apis-core-file-kit/errorcode-filemanagement.md)。 6598 6599| 错误码ID | 错误信息 | 6600| -------- | ---------------------------------------- | 6601| 201 | Permission denied. | 6602| 202 | Called by non-system application. | 6603| 13900020 | Invalid argument. | 6604| 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; | 6605 6606**示例:** 6607 6608```ts 6609async function example(context: Context, albumUri: string) { 6610 console.info('deleteAlbumsWithUriDemo'); 6611 try { 6612 await photoAccessHelper.MediaAlbumChangeRequest.deleteAlbumsWithUri(context, [albumUri]); 6613 console.info('deleteAlbums successfully'); 6614 } catch (err) { 6615 console.error(`deleteAlbumsWithUriDemo failed with error: ${err.code}, ${err.message}`); 6616 } 6617} 6618``` 6619 6620### setCoverUri<sup>11+</sup> 6621 6622setCoverUri(coverUri: string): void 6623 6624设置相册封面。 6625 6626**系统接口**:此接口为系统接口。 6627 6628**系统能力**:SystemCapability.FileManagement.PhotoAccessHelper.Core 6629 6630**参数:** 6631 6632| 参数名 | 类型 | 必填 | 说明 | 6633| ---------- | ------- | ---- | ---------------------------------- | 6634| coverUri | string | 是 | 待设置为相册封面文件的uri。 | 6635 6636**错误码:** 6637 6638接口抛出错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)和[文件管理错误码](../apis-core-file-kit/errorcode-filemanagement.md)。 6639 6640| 错误码ID | 错误信息 | 6641| -------- | ---------------------------------------- | 6642| 202 | Called by non-system application. | 6643| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types; 3. Parameter verification failed. | 6644| 14000011 | System inner fail. | 6645 6646**示例:** 6647 6648phAccessHelper的创建请参考[@ohos.file.photoAccessHelper (相册管理模块)](arkts-apis-photoAccessHelper-f.md)的示例使用。 6649 6650```ts 6651import { dataSharePredicates } from '@kit.ArkData'; 6652 6653async function example(phAccessHelper: photoAccessHelper.PhotoAccessHelper) { 6654 console.info('setCoverUriDemo'); 6655 let predicates: dataSharePredicates.DataSharePredicates = new dataSharePredicates.DataSharePredicates(); 6656 let fetchOptions: photoAccessHelper.FetchOptions = { 6657 fetchColumns: [], 6658 predicates: predicates 6659 }; 6660 try { 6661 let albumFetchResult: photoAccessHelper.FetchResult<photoAccessHelper.Album> = await phAccessHelper.getAlbums(photoAccessHelper.AlbumType.USER, photoAccessHelper.AlbumSubtype.USER_GENERIC); 6662 let album: photoAccessHelper.Album = await albumFetchResult.getFirstObject(); 6663 let fetchResult: photoAccessHelper.FetchResult<photoAccessHelper.PhotoAsset> = await album.getAssets(fetchOptions); 6664 let asset: photoAccessHelper.PhotoAsset = await fetchResult.getFirstObject(); 6665 6666 let albumChangeRequest: photoAccessHelper.MediaAlbumChangeRequest = new photoAccessHelper.MediaAlbumChangeRequest(album); 6667 albumChangeRequest.setCoverUri(asset.uri); 6668 await phAccessHelper.applyChanges(albumChangeRequest); 6669 console.info('setCoverUri successfully'); 6670 } catch (err) { 6671 console.error(`setCoverUriDemo failed with error: ${err.code}, ${err.message}`); 6672 } 6673} 6674``` 6675 6676### resetCoverUri<sup>20+</sup> 6677 6678resetCoverUri(): void 6679 6680恢复默认封面。 6681 6682**系统接口**:此接口为系统接口。 6683 6684**系统能力**:SystemCapability.FileManagement.PhotoAccessHelper.Core 6685 6686**错误码:** 6687 6688以下错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)和[媒体库错误码](errcode-medialibrary.md)。 6689 6690| 错误码ID | 错误信息 | 6691| -------- | ---------------------------------------- | 6692| 202 | Called by non-system application. | 6693| 23800301 | 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. | 6694 6695**示例:** 6696 6697phAccessHelper的创建请参考[@ohos.file.photoAccessHelper (相册管理模块)](js-apis-photoAccessHelper.md)的示例使用。 6698 6699```ts 6700import { dataSharePredicates } from '@kit.ArkData'; 6701 6702async function example(phAccessHelper: photoAccessHelper.PhotoAccessHelper) { 6703 console.info('resetCoverUriDemo'); 6704 let predicates: dataSharePredicates.DataSharePredicates = new dataSharePredicates.DataSharePredicates(); 6705 let fetchOptions: photoAccessHelper.FetchOptions = { 6706 fetchColumns: [], 6707 predicates: predicates 6708 }; 6709 try { 6710 let albumFetchResult: photoAccessHelper.FetchResult<photoAccessHelper.Album> = await phAccessHelper.getAlbums(photoAccessHelper.AlbumType.USER, photoAccessHelper.AlbumSubtype.USER_GENERIC); 6711 let album: photoAccessHelper.Album = await albumFetchResult.getFirstObject(); 6712 6713 let albumChangeRequest: photoAccessHelper.MediaAlbumChangeRequest = new photoAccessHelper.MediaAlbumChangeRequest(album); 6714 albumChangeRequest.resetCoverUri(); 6715 await phAccessHelper.applyChanges(albumChangeRequest); 6716 console.info('resetCoverUri successfully'); 6717 } catch (err) { 6718 console.error(`resetCoverUriDemo failed with error: ${err.code}, ${err.message}`); 6719 } 6720} 6721``` 6722 6723### moveAssets<sup>11+</sup> 6724 6725moveAssets(assets: Array<PhotoAsset>, targetAlbum: Album): void 6726 6727从相册中移动资产到另一个目标相册。 6728 6729**系统接口**:此接口为系统接口。 6730 6731**系统能力**:SystemCapability.FileManagement.PhotoAccessHelper.Core 6732 6733**参数:** 6734 6735| 参数名 | 类型 | 必填 | 说明 | 6736| ---------- | ------- | ---- | ---------------------------------- | 6737| assets | Array<[PhotoAsset](#photoasset)> | 是 | 待从相册中移出的资产数组。 | 6738| targetAlbum | Album | 是 | 待移入资产的目标相册。 | 6739 6740**错误码:** 6741 6742接口抛出错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)和[文件管理错误码](../apis-core-file-kit/errorcode-filemanagement.md)。 6743 6744| 错误码ID | 错误信息 | 6745| -------- | ---------------------------------------- | 6746| 202 | Called by non-system application. | 6747| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types; 3. Parameter verification failed. | 6748| 14000011 | System inner fail. | 6749| 14000016 | Operation Not Support. | 6750 6751**示例:** 6752 6753phAccessHelper的创建请参考[@ohos.file.photoAccessHelper (相册管理模块)](arkts-apis-photoAccessHelper-f.md)的示例使用。 6754 6755```ts 6756import { dataSharePredicates } from '@kit.ArkData'; 6757 6758async function example(phAccessHelper: photoAccessHelper.PhotoAccessHelper) { 6759 console.info('moveAssetsDemo'); 6760 let predicates: dataSharePredicates.DataSharePredicates = new dataSharePredicates.DataSharePredicates(); 6761 let fetchOptions: photoAccessHelper.FetchOptions = { 6762 fetchColumns: [], 6763 predicates: predicates 6764 }; 6765 try { 6766 let albumFetchResult: photoAccessHelper.FetchResult<photoAccessHelper.Album> = await phAccessHelper.getAlbums(photoAccessHelper.AlbumType.USER, photoAccessHelper.AlbumSubtype.USER_GENERIC); 6767 let album: photoAccessHelper.Album = await albumFetchResult.getFirstObject(); 6768 let fetchResult: photoAccessHelper.FetchResult<photoAccessHelper.PhotoAsset> = await album.getAssets(fetchOptions); 6769 let asset: photoAccessHelper.PhotoAsset = await fetchResult.getFirstObject(); 6770 6771 if (albumFetchResult.isAfterLast()) { 6772 console.error('lack of album to be moved into'); 6773 return; 6774 } 6775 let nextAlbum: photoAccessHelper.Album = await albumFetchResult.getNextObject(); 6776 let albumChangeRequest: photoAccessHelper.MediaAlbumChangeRequest = new photoAccessHelper.MediaAlbumChangeRequest(album); 6777 albumChangeRequest.moveAssets([asset], nextAlbum); 6778 await phAccessHelper.applyChanges(albumChangeRequest); 6779 console.info('moveAssets successfully'); 6780 } catch (err) { 6781 console.error(`moveAssetsDemo failed with error: ${err.code}, ${err.message}`); 6782 } 6783} 6784``` 6785### moveAssetsWithUri<sup>19+</sup> 6786 6787moveAssetsWithUri(assetUris: Array<String>, targetAlbum: Album): void 6788 6789把相册中的资产移动到另一个目标相册。 6790 6791**系统接口**:此接口为系统接口。 6792 6793**系统能力**:SystemCapability.FileManagement.PhotoAccessHelper.Core 6794 6795**参数:** 6796 6797| 参数名 | 类型 | 必填 | 说明 | 6798| ---------- | ------- | ---- | ---------------------------------- | 6799| assetUris | Array<String> | 是 | 待从相册中移出的资产Uri数组。 | 6800| targetAlbum | [Album](#album) | 是 | 待移入资产的目标相册。 | 6801 6802**错误码:** 6803 6804以下错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)和[文件管理错误码](../apis-core-file-kit/errorcode-filemanagement.md)。 6805 6806| 错误码ID | 错误信息 | 6807| -------- | ---------------------------------------- | 6808| 202 | Called by non-system application. | 6809| 13900020 | Invalid argument.| 6810| 14000011 | Internal system error. It is recommended to retry and check the logs.<br>Possible causes: 1. Database corrupted; 2. The file system is abnormal; 3. The IPC request timed out. | 6811| 14000016 | Operation Not Support. | 6812 6813**示例:** 6814 6815phAccessHelper的创建请参考[@ohos.file.photoAccessHelper (相册管理模块)](arkts-apis-photoAccessHelper-f.md)的示例使用。 6816 6817```ts 6818import { dataSharePredicates } from '@kit.ArkData'; 6819 6820async function example(phAccessHelper: photoAccessHelper.PhotoAccessHelper) { 6821 console.info('moveAssetsWithUriDemo'); 6822 let predicates: dataSharePredicates.DataSharePredicates = new dataSharePredicates.DataSharePredicates(); 6823 let fetchOptions: photoAccessHelper.FetchOptions = { 6824 fetchColumns: [], 6825 predicates: predicates 6826 }; 6827 try { 6828 let albumFetchResult: photoAccessHelper.FetchResult<photoAccessHelper.Album> = await phAccessHelper.getAlbums(photoAccessHelper.AlbumType.USER, photoAccessHelper.AlbumSubtype.USER_GENERIC); 6829 let album: photoAccessHelper.Album = await albumFetchResult.getFirstObject(); 6830 let fetchResult: photoAccessHelper.FetchResult<photoAccessHelper.PhotoAsset> = await album.getAssets(fetchOptions); 6831 let asset: photoAccessHelper.PhotoAsset = await fetchResult.getFirstObject(); 6832 6833 if (albumFetchResult.isAfterLast()) { 6834 console.error('lack of album to be moved into'); 6835 return; 6836 } 6837 let nextAlbum: photoAccessHelper.Album = await albumFetchResult.getNextObject(); 6838 let albumChangeRequest: photoAccessHelper.MediaAlbumChangeRequest = new photoAccessHelper.MediaAlbumChangeRequest(album); 6839 albumChangeRequest.moveAssetsWithUri([asset.uri], nextAlbum); 6840 await phAccessHelper.applyChanges(albumChangeRequest); 6841 console.info('moveAssetsWithUri successfully'); 6842 } catch (err) { 6843 console.error(`moveAssetsWithUriDemo failed with error: ${err.code}, ${err.message}`); 6844 } 6845} 6846``` 6847 6848 6849### recoverAssets<sup>11+</sup> 6850 6851recoverAssets(assets: Array<PhotoAsset>): void 6852 6853从回收站中恢复资产。 6854 6855**系统接口**:此接口为系统接口。 6856 6857**系统能力**:SystemCapability.FileManagement.PhotoAccessHelper.Core 6858 6859**参数:** 6860 6861| 参数名 | 类型 | 必填 | 说明 | 6862| ---------- | ------- | ---- | ---------------------------------- | 6863| assets | Array<[PhotoAsset](#photoasset)> | 是 | 待从回收站中恢复的资产数组。 | 6864 6865**错误码:** 6866 6867接口抛出错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)和[文件管理错误码](../apis-core-file-kit/errorcode-filemanagement.md)。 6868 6869| 错误码ID | 错误信息 | 6870| -------- | ---------------------------------------- | 6871| 202 | Called by non-system application. | 6872| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types; 3. Parameter verification failed. | 6873| 14000011 | System inner fail. | 6874| 14000016 | Operation Not Support. | 6875 6876**示例:** 6877 6878phAccessHelper的创建请参考[@ohos.file.photoAccessHelper (相册管理模块)](arkts-apis-photoAccessHelper-f.md)的示例使用。 6879 6880```ts 6881import { dataSharePredicates } from '@kit.ArkData'; 6882 6883async function example(phAccessHelper: photoAccessHelper.PhotoAccessHelper) { 6884 console.info('recoverAssetsDemo'); 6885 let predicates: dataSharePredicates.DataSharePredicates = new dataSharePredicates.DataSharePredicates(); 6886 let fetchOptions: photoAccessHelper.FetchOptions = { 6887 fetchColumns: [], 6888 predicates: predicates 6889 }; 6890 try { 6891 let albumFetchResult: photoAccessHelper.FetchResult<photoAccessHelper.Album> = await phAccessHelper.getAlbums(photoAccessHelper.AlbumType.SYSTEM, photoAccessHelper.AlbumSubtype.TRASH); 6892 let album: photoAccessHelper.Album = await albumFetchResult.getFirstObject(); 6893 let fetchResult: photoAccessHelper.FetchResult<photoAccessHelper.PhotoAsset> = await album.getAssets(fetchOptions); 6894 let asset: photoAccessHelper.PhotoAsset = await fetchResult.getFirstObject(); 6895 6896 let albumChangeRequest: photoAccessHelper.MediaAlbumChangeRequest = new photoAccessHelper.MediaAlbumChangeRequest(album); 6897 albumChangeRequest.recoverAssets([asset]); 6898 await phAccessHelper.applyChanges(albumChangeRequest); 6899 console.info('recoverAssets successfully'); 6900 } catch (err) { 6901 console.error(`recoverAssetsDemo failed with error: ${err.code}, ${err.message}`); 6902 } 6903} 6904``` 6905 6906### recoverAssetsWithUri<sup>19+</sup> 6907 6908recoverAssetsWithUri(assetUris: Array<String>): void 6909 6910从回收站中恢复资产。 6911 6912**系统接口**:此接口为系统接口。 6913 6914**系统能力**:SystemCapability.FileManagement.PhotoAccessHelper.Core 6915 6916**参数:** 6917 6918| 参数名 | 类型 | 必填 | 说明 | 6919| ---------- | ------- | ---- | ---------------------------------- | 6920| assetUris | Array<String> | 是 | 待从回收站中恢复的资产Uri数组。 | 6921 6922**错误码:** 6923 6924以下错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)和[文件管理错误码](../apis-core-file-kit/errorcode-filemanagement.md)。 6925 6926| 错误码ID | 错误信息 | 6927| -------- | ---------------------------------------- | 6928| 202 | Called by non-system application. | 6929| 13900020 | Invalid argument.| 6930| 14000011 | Internal system error. It is recommended to retry and check the logs.<br>Possible causes: 1. Database corrupted; 2. The file system is abnormal; 3. The IPC request timed out. | 6931| 14000016 | Operation Not Support. | 6932 6933**示例:** 6934 6935phAccessHelper的创建请参考[@ohos.file.photoAccessHelper (相册管理模块)](arkts-apis-photoAccessHelper-f.md)的示例使用。 6936 6937```ts 6938import { dataSharePredicates } from '@kit.ArkData'; 6939 6940async function example(phAccessHelper: photoAccessHelper.PhotoAccessHelper) { 6941 console.info('recoverAssetsWithUriDemo'); 6942 let predicates: dataSharePredicates.DataSharePredicates = new dataSharePredicates.DataSharePredicates(); 6943 let fetchOptions: photoAccessHelper.FetchOptions = { 6944 fetchColumns: [], 6945 predicates: predicates 6946 }; 6947 try { 6948 let albumFetchResult: photoAccessHelper.FetchResult<photoAccessHelper.Album> = await phAccessHelper.getAlbums(photoAccessHelper.AlbumType.SYSTEM, photoAccessHelper.AlbumSubtype.TRASH); 6949 let album: photoAccessHelper.Album = await albumFetchResult.getFirstObject(); 6950 let fetchResult: photoAccessHelper.FetchResult<photoAccessHelper.PhotoAsset> = await album.getAssets(fetchOptions); 6951 let asset: photoAccessHelper.PhotoAsset = await fetchResult.getFirstObject(); 6952 6953 let albumChangeRequest: photoAccessHelper.MediaAlbumChangeRequest = new photoAccessHelper.MediaAlbumChangeRequest(album); 6954 albumChangeRequest.recoverAssetsWithUri([asset.uri]); 6955 await phAccessHelper.applyChanges(albumChangeRequest); 6956 console.info('recoverAssetsWithUri successfully'); 6957 } catch (err) { 6958 console.error(`recoverAssetsWithUriDemo failed with error: ${err.code}, ${err.message}`); 6959 } 6960} 6961``` 6962 6963### deleteAssets<sup>11+</sup> 6964 6965deleteAssets(assets: Array<PhotoAsset>): void 6966 6967从回收站中彻底删除资产。 6968 6969**注意**:此操作不可逆,执行此操作后文件资源将彻底删除,请谨慎操作。 6970 6971**系统接口**:此接口为系统接口。 6972 6973**系统能力**:SystemCapability.FileManagement.PhotoAccessHelper.Core 6974 6975**参数:** 6976 6977| 参数名 | 类型 | 必填 | 说明 | 6978| ---------- | ------- | ---- | ---------------------------------- | 6979| assets | Array<[PhotoAsset](#photoasset)> | 是 | 待从回收站中彻底删除的资产数组。 | 6980 6981**错误码:** 6982 6983接口抛出错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)和[文件管理错误码](../apis-core-file-kit/errorcode-filemanagement.md)。 6984 6985| 错误码ID | 错误信息 | 6986| -------- | ---------------------------------------- | 6987| 202 | Called by non-system application. | 6988| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types; 3. Parameter verification failed. | 6989| 14000011 | System inner fail. | 6990| 14000016 | Operation Not Support. | 6991 6992**示例:** 6993 6994phAccessHelper的创建请参考[@ohos.file.photoAccessHelper (相册管理模块)](arkts-apis-photoAccessHelper-f.md)的示例使用。 6995 6996```ts 6997import { dataSharePredicates } from '@kit.ArkData'; 6998 6999async function example(phAccessHelper: photoAccessHelper.PhotoAccessHelper) { 7000 console.info('deleteAssetsPermanentlyDemo'); 7001 let predicates: dataSharePredicates.DataSharePredicates = new dataSharePredicates.DataSharePredicates(); 7002 let fetchOptions: photoAccessHelper.FetchOptions = { 7003 fetchColumns: [], 7004 predicates: predicates 7005 }; 7006 try { 7007 let albumFetchResult: photoAccessHelper.FetchResult<photoAccessHelper.Album> = await phAccessHelper.getAlbums(photoAccessHelper.AlbumType.SYSTEM, photoAccessHelper.AlbumSubtype.TRASH); 7008 let album: photoAccessHelper.Album = await albumFetchResult.getFirstObject(); 7009 let fetchResult: photoAccessHelper.FetchResult<photoAccessHelper.PhotoAsset> = await album.getAssets(fetchOptions); 7010 let asset: photoAccessHelper.PhotoAsset = await fetchResult.getFirstObject(); 7011 7012 let albumChangeRequest: photoAccessHelper.MediaAlbumChangeRequest = new photoAccessHelper.MediaAlbumChangeRequest(album); 7013 albumChangeRequest.deleteAssets([asset]); 7014 await phAccessHelper.applyChanges(albumChangeRequest); 7015 console.info('succeed to deleteAssets permanently'); 7016 } catch (err) { 7017 console.error(`deleteAssetsPermanentlyDemo failed with error: ${err.code}, ${err.message}`); 7018 } 7019} 7020``` 7021 7022### deleteAssetsWithUri<sup>19+</sup> 7023 7024deleteAssetsWithUri(assetUris: Array<String>): void 7025 7026从回收站中彻底删除资产。 7027 7028>**注意**: 7029> 此操作不可逆,执行此操作后文件资源将被彻底删除,请谨慎操作。 7030 7031**系统接口**:此接口为系统接口。 7032 7033**系统能力**:SystemCapability.FileManagement.PhotoAccessHelper.Core 7034 7035**参数:** 7036 7037| 参数名 | 类型 | 必填 | 说明 | 7038| ---------- | ------- | ---- | ---------------------------------- | 7039| assetUris | Array<String> | 是 | 待从回收站中彻底删除的资产Uri数组。 | 7040 7041**错误码:** 7042 7043以下错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)和[文件管理错误码](../apis-core-file-kit/errorcode-filemanagement.md)。 7044 7045| 错误码ID | 错误信息 | 7046| -------- | ---------------------------------------- | 7047| 202 | Called by non-system application. | 7048| 13900020 | Invalid argument.| 7049| 14000011 | Internal system error. It is recommended to retry and check the logs.<br>Possible causes: 1. Database corrupted; 2. The file system is abnormal; 3. The IPC request timed out. | 7050| 14000016 | Operation Not Support. | 7051 7052**示例:** 7053 7054phAccessHelper的创建请参考[@ohos.file.photoAccessHelper (相册管理模块)](arkts-apis-photoAccessHelper-f.md)的示例使用。 7055 7056```ts 7057import { dataSharePredicates } from '@kit.ArkData'; 7058 7059async function example(phAccessHelper: photoAccessHelper.PhotoAccessHelper) { 7060 console.info('deleteAssetsWithUriDemo'); 7061 let predicates: dataSharePredicates.DataSharePredicates = new dataSharePredicates.DataSharePredicates(); 7062 let fetchOptions: photoAccessHelper.FetchOptions = { 7063 fetchColumns: [], 7064 predicates: predicates 7065 }; 7066 try { 7067 let albumFetchResult: photoAccessHelper.FetchResult<photoAccessHelper.Album> = await phAccessHelper.getAlbums(photoAccessHelper.AlbumType.SYSTEM, photoAccessHelper.AlbumSubtype.TRASH); 7068 let album: photoAccessHelper.Album = await albumFetchResult.getFirstObject(); 7069 let fetchResult: photoAccessHelper.FetchResult<photoAccessHelper.PhotoAsset> = await album.getAssets(fetchOptions); 7070 let asset: photoAccessHelper.PhotoAsset = await fetchResult.getFirstObject(); 7071 7072 let albumChangeRequest: photoAccessHelper.MediaAlbumChangeRequest = new photoAccessHelper.MediaAlbumChangeRequest(album); 7073 albumChangeRequest.deleteAssetsWithUri([asset.uri]); 7074 await phAccessHelper.applyChanges(albumChangeRequest); 7075 console.info('succeed to deleteAssets permanently'); 7076 } catch (err) { 7077 console.error(`deleteAssetsWithUriDemo failed with error: ${err.code}, ${err.message}`); 7078 } 7079} 7080``` 7081 7082### setDisplayLevel<sup>11+</sup> 7083 7084setDisplayLevel(displayLevel: number): void 7085 7086设置人像相册的显示级别。 7087 7088**系统接口**:此接口为系统接口。 7089 7090**系统能力**:SystemCapability.FileManagement.PhotoAccessHelper.Core 7091 7092**参数:** 7093 7094| 参数名 | 类型 | 必填 | 说明 | 7095| ---------- | ------- | ---- | ---------------------------------- | 7096| displayLevel | number | 是 | 设置人像相册的显示级别, 0:取消该人像相册收藏;1:设置人像相册为首届面;2:设置人像相册为更多界面;3:设置人像相册为收藏界面。 | 7097 7098**错误码:** 7099 7100接口抛出错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)和[文件管理错误码](../apis-core-file-kit/errorcode-filemanagement.md)。 7101 7102| 错误码ID | 错误信息 | 7103| -------- | ---------------------------------------- | 7104| 202 | Called by non-system application. | 7105| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types; 3. Parameter verification failed. | 7106| 14000011 | System inner fail. | 7107 7108**示例:** 7109 7110phAccessHelper的创建请参考[@ohos.file.photoAccessHelper (相册管理模块)](arkts-apis-photoAccessHelper-f.md)的示例使用。 7111 7112``` ts 7113import { dataSharePredicates } from '@kit.ArkData'; 7114 7115async function example(phAccessHelper: photoAccessHelper.PhotoAccessHelper) { 7116 try { 7117 console.info('setDisplayLevel Example') 7118 let predicates: dataSharePredicates.DataSharePredicates = new dataSharePredicates.DataSharePredicates(); 7119 predicates.equalTo('user_display_level', 2); 7120 let fetchOptions: photoAccessHelper.FetchOptions = { 7121 fetchColumns: [], 7122 predicates: predicates 7123 }; 7124 let fetchResult: photoAccessHelper.FetchResult<photoAccessHelper.Album> = await phAccessHelper.getAlbums(photoAccessHelper.AlbumType.SMART, photoAccessHelper.AlbumSubtype.PORTRAIT, fetchOptions); 7125 let album: photoAccessHelper.Album = await fetchResult.getFirstObject(); 7126 let changeRequest: photoAccessHelper.MediaAlbumChangeRequest = new photoAccessHelper.MediaAlbumChangeRequest(album); 7127 changeRequest.setDisplayLevel(1); 7128 await phAccessHelper.applyChanges(changeRequest); 7129 } catch (err) { 7130 console.error(`setDisplayLevel failed with error: ${err.code}, ${err.message}`); 7131 } 7132} 7133``` 7134 7135### setIsMe<sup>11+</sup> 7136 7137setIsMe(): void 7138 7139将人像相册的人物关系设置为“我”。 7140 7141**系统接口**:此接口为系统接口。 7142 7143**系统能力**:SystemCapability.FileManagement.PhotoAccessHelper.Core 7144 7145**错误码:** 7146 7147接口抛出错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)和[文件管理错误码](../apis-core-file-kit/errorcode-filemanagement.md)。 7148 7149| 错误码ID | 错误信息 | 7150| -------- | ---------------------------------------- | 7151| 202 | Called by non-system application. | 7152| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types. | 7153| 14000011 | System inner fail. | 7154 7155**示例:** 7156 7157phAccessHelper的创建请参考[@ohos.file.photoAccessHelper (相册管理模块)](arkts-apis-photoAccessHelper-f.md)的示例使用。 7158 7159``` ts 7160import { dataSharePredicates } from '@kit.ArkData'; 7161 7162async function example(phAccessHelper: photoAccessHelper.PhotoAccessHelper) { 7163 try { 7164 console.info('setIsMe Example') 7165 let predicates: dataSharePredicates.DataSharePredicates = new dataSharePredicates.DataSharePredicates(); 7166 predicates.equalTo('user_display_level', 2); 7167 let fetchOptions: photoAccessHelper.FetchOptions = { 7168 fetchColumns: [], 7169 predicates: predicates 7170 }; 7171 let fetchResult: photoAccessHelper.FetchResult<photoAccessHelper.Album> = await phAccessHelper.getAlbums(photoAccessHelper.AlbumType.SMART, photoAccessHelper.AlbumSubtype.PORTRAIT, fetchOptions); 7172 let album: photoAccessHelper.Album = await fetchResult.getFirstObject(); 7173 let changeRequest: photoAccessHelper.MediaAlbumChangeRequest = new photoAccessHelper.MediaAlbumChangeRequest(album); 7174 changeRequest.setIsMe(); 7175 await phAccessHelper.applyChanges(changeRequest); 7176 } catch (err) { 7177 console.error(`setIsMe failed with error: ${err.code}, ${err.message}`); 7178 } 7179} 7180``` 7181 7182### dismissAssets<sup>11+</sup> 7183 7184dismissAssets(assets: Array<PhotoAsset>): void 7185 7186从该人像相册或合影相册中移除指定图片。 7187 7188**系统接口**:此接口为系统接口。 7189 7190**系统能力**:SystemCapability.FileManagement.PhotoAccessHelper.Core 7191 7192**参数:** 7193 7194| 参数名 | 类型 | 必填 | 说明 | 7195| ---------- | ------- | ---- | ---------------------------------- | 7196| assets | Array<PhotoAsset> | 是 | 需要移除的文件列表。 | 7197 7198**错误码:** 7199 7200接口抛出错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)和[文件管理错误码](../apis-core-file-kit/errorcode-filemanagement.md)。 7201 7202| 错误码ID | 错误信息 | 7203| -------- | ---------------------------------------- | 7204| 202 | Called by non-system application. | 7205| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types; 3. Parameter verification failed. | 7206| 14000011 | System inner fail. | 7207| 14000016 | Operation Not support. | 7208 7209**示例:** 7210 7211phAccessHelper的创建请参考[@ohos.file.photoAccessHelper (相册管理模块)](arkts-apis-photoAccessHelper-f.md)的示例使用。 7212 7213``` ts 7214import { dataSharePredicates } from '@kit.ArkData'; 7215 7216async function example(phAccessHelper: photoAccessHelper.PhotoAccessHelper) { 7217 try { 7218 console.info('dismissAssets Example') 7219 let predicates: dataSharePredicates.DataSharePredicates = new dataSharePredicates.DataSharePredicates(); 7220 predicates.equalTo('user_display_level', 2); 7221 let fetchOptions: photoAccessHelper.FetchOptions = { 7222 fetchColumns: [], 7223 predicates: predicates 7224 }; 7225 let fetchResult: photoAccessHelper.FetchResult<photoAccessHelper.Album> = await phAccessHelper.getAlbums(photoAccessHelper.AlbumType.SMART, photoAccessHelper.AlbumSubtype.PORTRAIT, fetchOptions); 7226 let album: photoAccessHelper.Album = await fetchResult.getFirstObject(); 7227 7228 let predicatesAsset: dataSharePredicates.DataSharePredicates = new dataSharePredicates.DataSharePredicates(); 7229 let assetFetchOptions: photoAccessHelper.FetchOptions = { 7230 fetchColumns: [], 7231 predicates: predicatesAsset 7232 }; 7233 let assetFetchResult: photoAccessHelper.FetchResult<photoAccessHelper.PhotoAsset> = await phAccessHelper.getAssets(assetFetchOptions); 7234 let asset: photoAccessHelper.PhotoAsset = await assetFetchResult.getFirstObject(); 7235 7236 let changeRequest: photoAccessHelper.MediaAlbumChangeRequest = new photoAccessHelper.MediaAlbumChangeRequest(album); 7237 changeRequest.dismissAssets([asset]); 7238 await phAccessHelper.applyChanges(changeRequest); 7239 } catch (err) { 7240 console.error(`dismissAssets failed with error: ${err.code}, ${err.message}`); 7241 } 7242} 7243``` 7244 7245### mergeAlbum<sup>11+</sup> 7246 7247mergeAlbum(target: Album): void 7248 7249将两个人像相册合并。 7250 7251**系统接口**:此接口为系统接口。 7252 7253**系统能力**:SystemCapability.FileManagement.PhotoAccessHelper.Core 7254 7255**参数:** 7256 7257| 参数名 | 类型 | 必填 | 说明 | 7258| ---------- | ------- | ---- | ---------------------------------- | 7259| target | [Album](#album) | 是 | 需要合并的目标相册,合并相册必须重命名。 | 7260 7261**错误码:** 7262 7263接口抛出错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)和[文件管理错误码](../apis-core-file-kit/errorcode-filemanagement.md)。 7264 7265| 错误码ID | 错误信息 | 7266| -------- | ---------------------------------------- | 7267| 202 | Called by non-system application. | 7268| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types; 3. Parameter verification failed. | 7269| 14000011 | System inner fail. | 7270| 14000016 | Operation Not support. | 7271 7272**示例:** 7273 7274phAccessHelper的创建请参考[@ohos.file.photoAccessHelper (相册管理模块)](arkts-apis-photoAccessHelper-f.md)的示例使用。 7275 7276``` ts 7277import { dataSharePredicates } from '@kit.ArkData'; 7278 7279async function example(phAccessHelper: photoAccessHelper.PhotoAccessHelper) { 7280 try { 7281 console.info('mergeAlbum Example') 7282 let predicates: dataSharePredicates.DataSharePredicates = new dataSharePredicates.DataSharePredicates(); 7283 predicates.equalTo('user_display_level', 2); 7284 let fetchOptions: photoAccessHelper.FetchOptions = { 7285 fetchColumns: [], 7286 predicates: predicates 7287 }; 7288 let fetchResult: photoAccessHelper.FetchResult<photoAccessHelper.Album> = await phAccessHelper.getAlbums(photoAccessHelper.AlbumType.SMART, photoAccessHelper.AlbumSubtype.PORTRAIT, fetchOptions); 7289 let album: photoAccessHelper.Album = await fetchResult.getFirstObject(); 7290 if (fetchResult.isAfterLast()) { 7291 console.error('lack of album to merge'); 7292 return; 7293 } 7294 let target: photoAccessHelper.Album = await fetchResult.getNextObject(); 7295 7296 let changeRequest: photoAccessHelper.MediaAlbumChangeRequest = new photoAccessHelper.MediaAlbumChangeRequest(album); 7297 changeRequest.mergeAlbum(target); 7298 changeRequest.setAlbumName("testName"); 7299 await phAccessHelper.applyChanges(changeRequest); 7300 } catch (err) { 7301 console.error(`mergeAlbum failed with error: ${err.code}, ${err.message}`); 7302 } 7303} 7304``` 7305 7306### placeBefore<sup>11+</sup> 7307 7308placeBefore(album: Album): void; 7309 7310将当前相册排序到目标相册之前。 7311 7312**系统接口**:此接口为系统接口。 7313 7314**系统能力**:SystemCapability.FileManagement.PhotoAccessHelper.Core 7315 7316**参数:** 7317 7318| 参数名 | 类型 | 必填 | 说明 | 7319| ---------- | ------- | ---- | ---------------------------------- | 7320| album | [Album](#album) | 是 | 目标相册。如果要将当前相册排序到末位,则目标相册传入null。 | 7321 7322**错误码:** 7323 7324接口抛出错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)和[文件管理错误码](../apis-core-file-kit/errorcode-filemanagement.md)。 7325 7326| 错误码ID | 错误信息 | 7327| -------- | ---------------------------------------- | 7328| 202 | Called by non-system application. | 7329| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types; 3. Parameter verification failed. | 7330| 14000011 | System inner fail. | 7331 7332**示例:** 7333 7334phAccessHelper的创建请参考[@ohos.file.photoAccessHelper (相册管理模块)](arkts-apis-photoAccessHelper-f.md)的示例使用。 7335 7336```ts 7337async function example(phAccessHelper: photoAccessHelper.PhotoAccessHelper) { 7338 console.info('placeBeforeDemo'); 7339 try { 7340 let albumFetchResult: photoAccessHelper.FetchResult<photoAccessHelper.Album> = await phAccessHelper.getAlbums(photoAccessHelper.AlbumType.USER, photoAccessHelper.AlbumSubtype.USER_GENERIC); 7341 let firstAlbum: photoAccessHelper.Album = await albumFetchResult.getFirstObject(); 7342 if (albumFetchResult.isAfterLast()) { 7343 console.error('lack of album to place before'); 7344 return; 7345 } 7346 let secondAlbum: photoAccessHelper.Album = await albumFetchResult.getNextObject(); 7347 let albumChangeRequest: photoAccessHelper.MediaAlbumChangeRequest = new photoAccessHelper.MediaAlbumChangeRequest(secondAlbum); 7348 albumChangeRequest.placeBefore(firstAlbum); 7349 await phAccessHelper.applyChanges(albumChangeRequest); 7350 console.info('placeBefore successfully'); 7351 } catch (err) { 7352 console.error(`placeBeforeDemo failed with error: ${err.code}, ${err.message}`); 7353 } 7354} 7355``` 7356 7357### dismiss<sup>13+</sup> 7358 7359dismiss(): void 7360 7361删除合影相册。 7362 7363**系统接口**:此接口为系统接口。 7364 7365**系统能力**:SystemCapability.FileManagement.PhotoAccessHelper.Core 7366 7367**错误码:** 7368 7369接口抛出错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)和[文件管理错误码](../apis-core-file-kit/errorcode-filemanagement.md)。 7370 7371| 错误码ID | 错误信息 | 7372| :------- | :-------------------------------- | 7373| 202 | Called by non-system application. | 7374| 401 | Parameter error. Possible causes: Incorrect parameter types. | 7375| 14000011 | System inner fail. | 7376 7377**示例:** 7378 7379phAccessHelper的创建请参考[@ohos.file.photoAccessHelper (相册管理模块)](arkts-apis-photoAccessHelper-f.md)的示例使用。 7380 7381```ts 7382import { dataSharePredicates } from '@kit.ArkData'; 7383 7384async function example(phAccessHelper: photoAccessHelper.PhotoAccessHelper) { 7385 console.info('dismissDemo'); 7386 try { 7387 let albumFetchResult: photoAccessHelper.FetchResult<photoAccessHelper.Album> = await phAccessHelper.getAlbums(photoAccessHelper.AlbumType.SMART, photoAccessHelper.AlbumSubtype.GROUP_PHOTO); 7388 let album: photoAccessHelper.Album = await albumFetchResult.getFirstObject(); 7389 7390 let albumChangeRequest: photoAccessHelper.MediaAlbumChangeRequest = new photoAccessHelper.MediaAlbumChangeRequest(album); 7391 albumChangeRequest.dismiss(); 7392 await phAccessHelper.applyChanges(albumChangeRequest); 7393 console.info('dismiss successfully'); 7394 } catch (err) { 7395 console.error(`dismissDemo failed with error: ${err.code}, ${err.message}`); 7396 } 7397} 7398``` 7399 7400## HighlightAlbum<sup>12+</sup> 7401 7402时刻相册。 7403 7404**系统接口**:此接口为系统接口。 7405 7406**系统能力**:SystemCapability.FileManagement.PhotoAccessHelper.Core 7407 7408### constructor<sup>12+</sup> 7409 7410constructor(album: Album) 7411 7412构造函数。 7413 7414**系统接口**:此接口为系统接口。 7415 7416**系统能力**:SystemCapability.FileManagement.PhotoAccessHelper.Core 7417 7418**参数:** 7419 7420| 参数名 | 类型 | 必填 | 说明 | 7421| -------- | ------------------------- | ---- | ---------- | 7422| album | [Album](#album) | 是 | 智慧相册。 | 7423 7424**错误码:** 7425 7426接口抛出错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)和[文件管理错误码](../apis-core-file-kit/errorcode-filemanagement.md)。 7427 7428| 错误码ID | 错误信息 | 7429| -------- | ---------------------------------------- | 7430| 202 | Called by non-system application. | 7431| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types; 3. Parameter verification failed. | 7432| 14000011 | Internal system error. | 7433 7434**示例:** 7435 7436```ts 7437import { dataSharePredicates } from '@kit.ArkData'; 7438 7439async function example(phAccessHelper: photoAccessHelper.PhotoAccessHelper) { 7440 console.info('HighlightAlbum constructorDemo'); 7441 let predicates: dataSharePredicates.DataSharePredicates = new dataSharePredicates.DataSharePredicates(); 7442 let fetchOption: photoAccessHelper.FetchOptions = { 7443 fetchColumns: [], 7444 predicates: predicates 7445 }; 7446 let albumFetchResult: photoAccessHelper.FetchResult<photoAccessHelper.Album> = await phAccessHelper.getAlbums( 7447 photoAccessHelper.AlbumType.SMART, photoAccessHelper.AlbumSubtype.HIGHLIGHT, fetchOption); 7448 let album: photoAccessHelper.Album = await albumFetchResult.getFirstObject(); 7449 let highlightAlbum: photoAccessHelper.HighlightAlbum = new photoAccessHelper.HighlightAlbum(album); 7450 albumFetchResult.close(); 7451} 7452``` 7453 7454### getHighlightAlbumInfo<sup>12+</sup> 7455 7456getHighlightAlbumInfo(type: HighlightAlbumInfoType): Promise<string> 7457 7458获取指定时刻相册的特定信息。 7459 7460**系统接口**:此接口为系统接口。 7461 7462**需要权限**:ohos.permission.READ\_IMAGEVIDEO 7463 7464**系统能力**:SystemCapability.FileManagement.PhotoAccessHelper.Core 7465 7466**参数:** 7467 7468| 参数名 | 类型 | 必填 | 说明 | 7469| ---------- | ------- | ---- | ---------------------------------- | 7470| type | [HighlightAlbumInfoType](#highlightalbuminfotype12) | 是 | 需要获取的时刻相册信息类型。 | 7471 7472 7473**返回值:** 7474 7475| 类型 | 说明 | 7476| --------------------------- | -------------- | 7477| Promise<string> | Promise对象,返回指定的时刻相册信息。| 7478 7479**错误码:** 7480 7481接口抛出错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)和[文件管理错误码](../apis-core-file-kit/errorcode-filemanagement.md)。 7482 7483| 错误码ID | 错误信息 | 7484| :------- | :-------------------------------- | 7485| 201 | Permission denied. | 7486| 202 | Called by non-system application. | 7487| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types; 3. Parameter verification failed. | 7488| 14000011 | Internal system error. | 7489 7490**示例:** 7491 7492```ts 7493import { dataSharePredicates } from '@kit.ArkData'; 7494 7495async function example(phAccessHelper: photoAccessHelper.PhotoAccessHelper) { 7496 try { 7497 console.info('getHighlightAlbumInfoDemo') 7498 let fetchOptions: photoAccessHelper.FetchOptions = { 7499 fetchColumns: [], 7500 predicates: new dataSharePredicates.DataSharePredicates() 7501 } 7502 let albumFetchResult: photoAccessHelper.FetchResult<photoAccessHelper.Album> = await phAccessHelper.getAlbums( 7503 photoAccessHelper.AlbumType.SMART, photoAccessHelper.AlbumSubtype.HIGHLIGHT, fetchOptions); 7504 let album: photoAccessHelper.Album = await albumFetchResult.getFirstObject(); 7505 if (album != undefined) { 7506 let highlightAlbum: photoAccessHelper.HighlightAlbum = new photoAccessHelper.HighlightAlbum(album); 7507 let coverInfo: string = await highlightAlbum.getHighlightAlbumInfo( 7508 photoAccessHelper.HighlightAlbumInfoType.COVER_INFO); 7509 console.info('get cover info result: ' + JSON.stringify(coverInfo)); 7510 } 7511 7512 albumFetchResult.close(); 7513 } catch (err) { 7514 console.error(`getHighlightAlbumInfoDemofailed with error: ${err.code}, ${err.message}`); 7515 } 7516} 7517``` 7518 7519### getHighlightResource<sup>12+</sup> 7520 7521getHighlightResource(resourceUri: string): Promise<ArrayBuffer> 7522 7523获取指定时刻缓存资源的ArrayBuffer。 7524 7525**系统接口**:此接口为系统接口。 7526 7527**需要权限**:ohos.permission.READ\_IMAGEVIDEO 7528 7529**系统能力**:SystemCapability.FileManagement.PhotoAccessHelper.Core 7530 7531**参数:** 7532 7533| 参数名 | 类型 | 必填 | 说明 | 7534| ---------- | ------- | ---- | ---------------------------------- | 7535| resourceUri | string | 是 | 指定时刻缓存资源uri。 | 7536 7537**返回值:** 7538 7539| 类型 | 说明 | 7540| --------------------------- | -------------- | 7541| Promise<ArrayBuffer> | Promise对象,返回资源的ArrayBuffer。| 7542 7543**错误码:** 7544 7545接口抛出错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)和[文件管理错误码](../apis-core-file-kit/errorcode-filemanagement.md)。 7546 7547| 错误码ID | 错误信息 | 7548| :------- | :-------------------------------- | 7549| 201 | Permission denied. | 7550| 202 | Called by non-system application. | 7551| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types; 3. Parameter verification failed. | 7552| 14000011 | Internal system error. Possible causes: 1. The database is corrupted; 2. The file system is abnormal; 3. The IPC request timed out; 4. Permission denied. | 7553 7554**示例:** 7555 7556```ts 7557import { dataSharePredicates } from '@kit.ArkData'; 7558 7559async function example(phAccessHelper: photoAccessHelper.PhotoAccessHelper) { 7560 try { 7561 console.info('getHighlightResourceDemo') 7562 let fetchOptions: photoAccessHelper.FetchOptions = { 7563 fetchColumns: [], 7564 predicates: new dataSharePredicates.DataSharePredicates() 7565 } 7566 let albumFetchResult: photoAccessHelper.FetchResult<photoAccessHelper.Album> = await phAccessHelper.getAlbums( 7567 photoAccessHelper.AlbumType.SMART, photoAccessHelper.AlbumSubtype.HIGHLIGHT, fetchOptions); 7568 let album: photoAccessHelper.Album = await albumFetchResult.getFirstObject(); 7569 if (album != undefined) { 7570 let highlightAlbum: photoAccessHelper.HighlightAlbum = new photoAccessHelper.HighlightAlbum(album); 7571 let uri: string = 'file://media/highlight/cover/10/1_1/background.png?oper=highlight' 7572 let arrayBuffer: ArrayBuffer = await highlightAlbum.getHighlightResource(uri); 7573 } 7574 albumFetchResult.close(); 7575 } catch (err) { 7576 console.error(`getHighlightResourceDemofailed with error: ${err.code}, ${err.message}`); 7577 } 7578} 7579``` 7580 7581### setHighlightUserActionData<sup>12+</sup> 7582 7583setHighlightUserActionData(type: HighlightUserActionType, actionData: number): Promise<void> 7584 7585设置指定时刻用户行为数据。 7586 7587**系统接口**:此接口为系统接口。 7588 7589**需要权限**:ohos.permission.WRITE\_IMAGEVIDEO 7590 7591**系统能力**:SystemCapability.FileManagement.PhotoAccessHelper.Core 7592 7593**参数:** 7594 7595| 参数名 | 类型 | 必填 | 说明 | 7596| ---------- | ------- | ---- | ---------------------------------- | 7597| type | [HighlightUserActionType](#highlightuseractiontype12) | 是 | 需要设置的用户行为数据类型。 | 7598| actionData | number | 是 | 行为数据。 | 7599 7600**返回值:** 7601 7602| 类型 | 说明 | 7603| --------------------------- | -------------- | 7604| Promise<void> | Promise对象。无返回结果的Promise对象。| 7605 7606**错误码:** 7607 7608接口抛出错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)和[文件管理错误码](../apis-core-file-kit/errorcode-filemanagement.md)。 7609 7610| 错误码ID | 错误信息 | 7611| :------- | :-------------------------------- | 7612| 201 | Permission denied. | 7613| 202 | Called by non-system application. | 7614| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types; 3. Parameter verification failed. | 7615| 14000011 | Internal system error. | 7616 7617**示例:** 7618 7619```ts 7620import { dataSharePredicates } from '@kit.ArkData'; 7621 7622async function example(phAccessHelper: photoAccessHelper.PhotoAccessHelper) { 7623 try { 7624 console.info('setHighlightUserActionDataDemo') 7625 let fetchOptions: photoAccessHelper.FetchOptions = { 7626 fetchColumns: [], 7627 predicates: new dataSharePredicates.DataSharePredicates() 7628 } 7629 let albumFetchResult: photoAccessHelper.FetchResult<photoAccessHelper.Album> = await phAccessHelper.getAlbums( 7630 photoAccessHelper.AlbumType.SMART, photoAccessHelper.AlbumSubtype.HIGHLIGHT, fetchOptions); 7631 let album: photoAccessHelper.Album = await albumFetchResult.getFirstObject(); 7632 if (album != undefined) { 7633 let highlightAlbum: photoAccessHelper.HighlightAlbum = new photoAccessHelper.HighlightAlbum(album); 7634 highlightAlbum.setHighlightUserActionData(photoAccessHelper.HighlightUserActionType.INSERTED_PIC_COUNT, 1); 7635 } 7636 albumFetchResult.close(); 7637 } catch (err) { 7638 console.error(`setHighlightUserActionDataDemofailed with error: ${err.code}, ${err.message}`); 7639 } 7640} 7641``` 7642 7643### setSubTitle<sup>18+</sup> 7644 7645setSubTitle(title: string): void 7646 7647设置时刻副标题内容。 7648 7649副标题参数规格为: 7650 7651- 副标题字符串长度为0~255。 7652- 不允许出现的非法英文字符,包括:<br> . \ / : * ? " ' ` < > | { } [ ] 7653- 英文字符大小写不敏感。 7654 7655**系统接口**:此接口为系统接口。 7656 7657**需要权限**:ohos.permission.WRITE\_IMAGEVIDEO 7658 7659**系统能力**:SystemCapability.FileManagement.PhotoAccessHelper.Core 7660 7661**参数:** 7662 7663| 参数名 | 类型 | 必填 | 说明 | 7664| ---------- | ------- | ---- | ---------------------------------- | 7665| title | string | 是 | 需要设置的时刻副标题内容。 | 7666 7667**错误码:** 7668 7669以下错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)和[文件管理错误码](../apis-core-file-kit/errorcode-filemanagement.md)。 7670 7671| 错误码ID | 错误信息 | 7672| :------- | :-------------------------------- | 7673| 201 | Permission denied. | 7674| 202 | Called by non-system application. | 7675| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types; 3. Parameter verification failed. | 7676| 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. | 7677 7678**示例:** 7679 7680```ts 7681import { dataSharePredicates } from '@kit.ArkData'; 7682 7683async function example(context: Context) { 7684 try { 7685 console.info('setSubTitle'); 7686 let helper: photoAccessHelper.PhotoAccessHelper = photoAccessHelper.getPhotoAccessHelper(context); 7687 let albumFetchOption: photoAccessHelper.FetchOptions = { 7688 fetchColumns: [], 7689 predicates: new dataSharePredicates.DataSharePredicates() 7690 }; 7691 let albumFetchResult: photoAccessHelper.FetchResult<photoAccessHelper.Album> = 7692 await helper.getAlbums(photoAccessHelper.AlbumType.SMART, photoAccessHelper.AlbumSubtype.HIGHLIGHT, albumFetchOption); 7693 if (albumFetchResult.getCount() === 0) { 7694 console.error('No album'); 7695 return; 7696 } 7697 let highlightAlbum: photoAccessHelper.Album = await albumFetchResult.getFirstObject(); 7698 albumFetchResult.close(); 7699 let changeHighlightAlbumRequest: photoAccessHelper.HighlightAlbum = new photoAccessHelper.HighlightAlbum(highlightAlbum); 7700 changeHighlightAlbumRequest.setSubTitle("testName"); 7701 console.info('setSubTitle success'); 7702 } catch (err) { 7703 console.error(`setSubTitle with error: ${err}`); 7704 } 7705} 7706``` 7707 7708### deleteHighlightAlbums<sup>18+</sup> 7709 7710static deleteHighlightAlbums(context: Context, albums: Array<Album>): Promise<number> 7711 7712删除指定时刻相册。 7713 7714**系统接口**:此接口为系统接口。 7715 7716**需要权限**:ohos.permission.WRITE\_IMAGEVIDEO 7717 7718**系统能力**:SystemCapability.FileManagement.PhotoAccessHelper.Core 7719 7720**参数:** 7721 7722| 参数名 | 类型 | 必填 | 说明 | 7723| ---------- | ------- | ---- | ---------------------------------- | 7724| context | [Context](../apis-ability-kit/js-apis-inner-application-context.md) | 是 | 传入Ability实例的Context。 | 7725| albums | Array<[Album](#album)> | 是 | 需要删除的时刻相册。 | 7726 7727**返回值:** 7728 7729| 类型 | 说明 | 7730| :------------------ | :---------------------------------- | 7731| Promise<number> | 是否成功删除相册。成功返回0,失败返回1。 | 7732 7733**错误码:** 7734 7735以下错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)和[文件管理错误码](../apis-core-file-kit/errorcode-filemanagement.md)。 7736 7737| 错误码ID | 错误信息 | 7738| :------- | :-------------------------------- | 7739| 201 | Permission denied. | 7740| 202 | Called by non-system application. | 7741| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types; 3. Parameter verification failed. | 7742| 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. | 7743 7744**示例:** 7745 7746```ts 7747import { dataSharePredicates } from '@kit.ArkData'; 7748 7749async function example(context: Context) { 7750 try { 7751 console.info('deleteHighlightAlbums'); 7752 let helper: photoAccessHelper.PhotoAccessHelper = photoAccessHelper.getPhotoAccessHelper(context); 7753 let albumFetchOption: photoAccessHelper.FetchOptions = { 7754 fetchColumns: [], 7755 predicates: new dataSharePredicates.DataSharePredicates() 7756 }; 7757 let albumFetchResult: photoAccessHelper.FetchResult<photoAccessHelper.Album> = 7758 await helper.getAlbums(photoAccessHelper.AlbumType.SMART, photoAccessHelper.AlbumSubtype.HIGHLIGHT, albumFetchOption); 7759 if (albumFetchResult.getCount() === 0) { 7760 console.error('No album'); 7761 return; 7762 } 7763 let highlightAlbum: photoAccessHelper.Album = await albumFetchResult.getFirstObject(); 7764 albumFetchResult.close(); 7765 let result = await photoAccessHelper.HighlightAlbum.deleteHighlightAlbums(context, [highlightAlbum]); 7766 console.info('deleteHighlightAlbums success'); 7767 } catch (err) { 7768 console.error(`deleteHighlightAlbums with error: ${err}`); 7769 } 7770} 7771``` 7772 7773## MediaAnalysisAlbumChangeRequest<sup>18+</sup> 7774 7775智慧相册变更请求。 7776 7777**系统能力**:SystemCapability.FileManagement.PhotoAccessHelper.Core 7778 7779### constructor<sup>18+</sup> 7780 7781constructor(album: Album) 7782 7783构造函数。 7784 7785**系统接口**:此接口为系统接口。 7786 7787**系统能力**:SystemCapability.FileManagement.PhotoAccessHelper.Core 7788 7789**参数:** 7790 7791| 参数名 | 类型 | 必填 | 说明 | 7792| ---------- | ------- | ---- | ---------------------------------- | 7793| album | [Album](#album) | 是 | 智慧相册。 | 7794 7795**错误码:** 7796 7797以下错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)和[文件管理错误码](../apis-core-file-kit/errorcode-filemanagement.md)。 7798 7799| 错误码ID | 错误信息 | 7800| -------- | ---------------------------------------- | 7801| 202 | Called by non-system application. | 7802| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types; 3. Parameter verification failed. | 7803 7804**示例:** 7805 7806```ts 7807import { dataSharePredicates } from '@kit.ArkData'; 7808 7809async function example(context: Context) { 7810 console.info('MediaAnalysisAlbumChangeRequest constructorDemo'); 7811 let helper: photoAccessHelper.PhotoAccessHelper = photoAccessHelper.getPhotoAccessHelper(context); 7812 let albumFetchOption: photoAccessHelper.FetchOptions = { 7813 fetchColumns: [], 7814 predicates: new dataSharePredicates.DataSharePredicates() 7815 }; 7816 let albumFetchResult: photoAccessHelper.FetchResult<photoAccessHelper.Album> = 7817 await helper.getAlbums(photoAccessHelper.AlbumType.SMART, photoAccessHelper.AlbumSubtype.HIGHLIGHT, albumFetchOption); 7818 if (albumFetchResult.getCount() === 0) { 7819 console.error('No album'); 7820 return; 7821 } 7822 let highlightAlbum: photoAccessHelper.Album = await albumFetchResult.getFirstObject(); 7823 albumFetchResult.close(); 7824 let changeRequest: photoAccessHelper.MediaAnalysisAlbumChangeRequest = 7825 new photoAccessHelper.MediaAnalysisAlbumChangeRequest(highlightAlbum); 7826} 7827``` 7828 7829### setOrderPosition<sup>18+</sup> 7830 7831setOrderPosition(assets: Array<PhotoAsset>, position: Array<number>): void 7832 7833设置智慧相册中资产的顺序位置。 7834 7835**系统接口**:此接口为系统接口。 7836 7837**需要权限**:ohos.permission.WRITE\_IMAGEVIDEO 7838 7839**系统能力**:SystemCapability.FileManagement.PhotoAccessHelper.Core 7840 7841**参数:** 7842 7843| 参数名 | 类型 | 必填 | 说明 | 7844| ---------- | ------- | ---- | ---------------------------------- | 7845| assets | Array<[PhotoAsset](#photoasset)> | 是 | 需要设置顺序位置的相册中资产。 | 7846| position | Array<number> | 是 | 相册中资产的顺序位置。 | 7847 7848**错误码:** 7849 7850以下错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)和[文件管理错误码](../apis-core-file-kit/errorcode-filemanagement.md)。 7851 7852| 错误码ID | 错误信息 | 7853| :------- | :-------------------------------- | 7854| 201 | Permission denied. | 7855| 202 | Called by non-system application. | 7856| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types; 3. Parameter verification failed. | 7857| 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. | 7858 7859**示例:** 7860 7861```ts 7862import { dataSharePredicates } from '@kit.ArkData'; 7863 7864async function example(context: Context) { 7865 try { 7866 console.info('setOrderPosition'); 7867 let helper: photoAccessHelper.PhotoAccessHelper = photoAccessHelper.getPhotoAccessHelper(context); 7868 let albumFetchOption: photoAccessHelper.FetchOptions = { 7869 fetchColumns: [], 7870 predicates: new dataSharePredicates.DataSharePredicates() 7871 }; 7872 let albumFetchResult: photoAccessHelper.FetchResult<photoAccessHelper.Album> = 7873 await helper.getAlbums(photoAccessHelper.AlbumType.SMART, photoAccessHelper.AlbumSubtype.HIGHLIGHT, albumFetchOption); 7874 if (albumFetchResult.getCount() === 0) { 7875 console.error('No album'); 7876 return; 7877 } 7878 let highlightAlbum: photoAccessHelper.Album = await albumFetchResult.getFirstObject(); 7879 albumFetchResult.close(); 7880 let predicates: dataSharePredicates.DataSharePredicates = new dataSharePredicates.DataSharePredicates(); 7881 const fetchOption: photoAccessHelper.FetchOptions = { 7882 fetchColumns: [], 7883 predicates: predicates 7884 }; 7885 let fetchResult: photoAccessHelper.FetchResult<photoAccessHelper.PhotoAsset> = 7886 await highlightAlbum.getAssets(fetchOption); 7887 let assets: photoAccessHelper.PhotoAsset[] = await fetchResult.getAllObjects(); 7888 let indexes: number[] = []; 7889 for (let i = 0; i < assets.length; i++) { 7890 indexes.push(i); 7891 } 7892 let changeRequest: photoAccessHelper.MediaAnalysisAlbumChangeRequest = 7893 new photoAccessHelper.MediaAnalysisAlbumChangeRequest(highlightAlbum); 7894 changeRequest.setOrderPosition(assets, indexes); 7895 await helper.applyChanges(changeRequest); 7896 console.info(`setOrderPosition ${indexes}`); 7897 } catch (err) { 7898 console.error(`setOrderPosition error: ${err}`); 7899 } 7900} 7901``` 7902 7903## AnalysisAlbum<sup>18+</sup> 7904 7905智慧相册。 7906 7907**系统能力**:SystemCapability.FileManagement.PhotoAccessHelper.Core 7908 7909### constructor<sup>18+</sup> 7910 7911constructor(album: Album) 7912 7913构造函数。 7914 7915**系统接口**:此接口为系统接口。 7916 7917**系统能力**:SystemCapability.FileManagement.PhotoAccessHelper.Core 7918 7919**参数:** 7920 7921| 参数名 | 类型 | 必填 | 说明 | 7922| ---------- | ------- | ---- | ---------------------------------- | 7923| album | [Album](#album) | 是 | 智慧相册。 | 7924 7925**错误码:** 7926 7927以下错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)和[文件管理错误码](../apis-core-file-kit/errorcode-filemanagement.md)。 7928 7929| 错误码ID | 错误信息 | 7930| -------- | ---------------------------------------- | 7931| 202 | Called by non-system application. | 7932| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types; 3. Parameter verification failed. | 7933 7934**示例:** 7935 7936```ts 7937import { dataSharePredicates } from '@kit.ArkData'; 7938 7939async function example(context: Context) { 7940 console.info('AnalysisAlbum constructorDemo'); 7941 let helper: photoAccessHelper.PhotoAccessHelper = photoAccessHelper.getPhotoAccessHelper(context); 7942 let albumFetchOption: photoAccessHelper.FetchOptions = { 7943 fetchColumns: [], 7944 predicates: new dataSharePredicates.DataSharePredicates() 7945 }; 7946 let albumFetchResult: photoAccessHelper.FetchResult<photoAccessHelper.Album> = 7947 await helper.getAlbums(photoAccessHelper.AlbumType.SMART, photoAccessHelper.AlbumSubtype.HIGHLIGHT, albumFetchOption); 7948 if (albumFetchResult.getCount() === 0) { 7949 console.error('No album'); 7950 return; 7951 } 7952 let highlightAlbum: photoAccessHelper.Album = await albumFetchResult.getFirstObject(); 7953 albumFetchResult.close(); 7954 let analysisAlbum: photoAccessHelper.AnalysisAlbum = new photoAccessHelper.AnalysisAlbum(highlightAlbum); 7955} 7956``` 7957 7958### getOrderPosition<sup>18+</sup> 7959 7960getOrderPosition(assets: Array<PhotoAsset>): Promise<Array<number>> 7961 7962获取智慧相册中资产的顺序位置。 7963 7964**系统接口**:此接口为系统接口。 7965 7966**需要权限**:ohos.permission.READ\_IMAGEVIDEO 7967 7968**系统能力**:SystemCapability.FileManagement.PhotoAccessHelper.Core 7969 7970**参数:** 7971 7972| 参数名 | 类型 | 必填 | 说明 | 7973| ---------- | ------- | ---- | ---------------------------------- | 7974| assets | Array<[PhotoAsset](#photoasset)> | 是 | 需要获取顺序位置的相册中资产。 | 7975 7976**返回值:** 7977 7978| 类型 | 说明 | 7979| :------------------ | :---------------------------------- | 7980| Promise<Array<number>> | 相册中资产的顺序位置值。 | 7981 7982**错误码:** 7983 7984以下错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)和[文件管理错误码](../apis-core-file-kit/errorcode-filemanagement.md)。 7985 7986| 错误码ID | 错误信息 | 7987| :------- | :-------------------------------- | 7988| 201 | Permission denied. | 7989| 202 | Called by non-system application. | 7990| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types; 3. Parameter verification failed. | 7991| 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. | 7992 7993**示例:** 7994 7995```ts 7996import { dataSharePredicates } from '@kit.ArkData'; 7997 7998async function example(context: Context) { 7999 try { 8000 console.info('getOrderPosition'); 8001 let helper: photoAccessHelper.PhotoAccessHelper = photoAccessHelper.getPhotoAccessHelper(context); 8002 let albumFetchOption: photoAccessHelper.FetchOptions = { 8003 fetchColumns: [], 8004 predicates: new dataSharePredicates.DataSharePredicates() 8005 }; 8006 let albumFetchResult: photoAccessHelper.FetchResult<photoAccessHelper.Album> = 8007 await helper.getAlbums(photoAccessHelper.AlbumType.SMART, photoAccessHelper.AlbumSubtype.HIGHLIGHT, albumFetchOption); 8008 if (albumFetchResult.getCount() === 0) { 8009 console.error('No album'); 8010 return; 8011 } 8012 let highlightAlbum: photoAccessHelper.Album = await albumFetchResult.getFirstObject(); 8013 albumFetchResult.close(); 8014 let predicates: dataSharePredicates.DataSharePredicates = new dataSharePredicates.DataSharePredicates(); 8015 let analysisAlbum: photoAccessHelper.AnalysisAlbum = new photoAccessHelper.AnalysisAlbum(highlightAlbum); 8016 const fetchOption: photoAccessHelper.FetchOptions = { 8017 fetchColumns: [], 8018 predicates: predicates 8019 }; 8020 let fetchResult: photoAccessHelper.FetchResult<photoAccessHelper.PhotoAsset> = 8021 await highlightAlbum.getAssets(fetchOption); 8022 let assets: photoAccessHelper.PhotoAsset[] = await fetchResult.getAllObjects(); 8023 let positions: number[] = await analysisAlbum.getOrderPosition(assets); 8024 console.info(`getOrderPosition ${positions}`); 8025 } catch (err) { 8026 console.error(`getOrderPosition error: ${err}`); 8027 } 8028} 8029``` 8030 8031## CloudEnhancement<sup>13+</sup> 8032 8033云增强管理类,该类用于生成AI云增强照片任务的管理、获取原照片与AI云增强照片的关联关系。 8034 8035**系统接口**:此接口为系统接口。 8036 8037**系统能力**:SystemCapability.FileManagement.PhotoAccessHelper.Core 8038 8039### getCloudEnhancementInstance<sup>13+</sup> 8040 8041static getCloudEnhancementInstance(context: Context): CloudEnhancement 8042 8043获取云增强类实例。 8044 8045**系统接口**:此接口为系统接口。 8046 8047**系统能力**:SystemCapability.FileManagement.PhotoAccessHelper.Core 8048 8049**参数:** 8050 8051| 参数名 | 类型 | 必填 | 说明 | 8052| -------- | ------------------------- | ---- | ---------- | 8053| context | [Context](../apis-ability-kit/js-apis-inner-application-context.md) | 是 | 传入Ability实例的Context。 | 8054 8055**返回值:** 8056 8057| 类型 | 说明 | 8058| --------------------------------------- | ----------------- | 8059| [CloudEnhancement](#cloudenhancement13) | 返回云增强管理类实例。 | 8060 8061**错误码:** 8062 8063接口抛出错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)和[文件管理错误码](../apis-core-file-kit/errorcode-filemanagement.md)。 8064 8065| 错误码ID | 错误信息 | 8066| -------- | ---------------------------------------- | 8067| 202 | Called by non-system application. | 8068| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types; 3. Parameter verification failed. | 8069| 14000011 | Internal system error. | 8070 8071**示例:** 8072 8073```ts 8074import { dataSharePredicates } from '@kit.ArkData'; 8075 8076async function example(context: Context) { 8077 console.info('getCloudEnhancementInstanceDemo'); 8078 let photoPredicates: dataSharePredicates.DataSharePredicates = new dataSharePredicates.DataSharePredicates(); 8079 let photoFetchOptions: photoAccessHelper.FetchOptions = { 8080 fetchColumns: [], 8081 predicates: photoPredicates 8082 }; 8083 let phAccessHelper = photoAccessHelper.getPhotoAccessHelper(context); 8084 try { 8085 let fetchResult = await phAccessHelper.getAssets(photoFetchOptions); 8086 let asset = await fetchResult.getLastObject(); 8087 let cloudEnhancementInstance: photoAccessHelper.CloudEnhancement 8088 = photoAccessHelper.CloudEnhancement.getCloudEnhancementInstance(context); 8089 let hasCloudWatermark = true; 8090 await cloudEnhancementInstance.submitCloudEnhancementTasks([asset], hasCloudWatermark); 8091 } catch (err) { 8092 console.error(`getCloudEnhancementInstanceDemo failed with error: ${err.code}, ${err.message}`); 8093 } 8094} 8095``` 8096 8097### submitCloudEnhancementTasks<sup>13+</sup> 8098 8099submitCloudEnhancementTasks(photoAssets: Array<PhotoAsset>, hasCloudWatermark: boolean): Promise<void> 8100 8101提交云增强任务。 8102 8103**系统接口**:此接口为系统接口。 8104 8105**系统能力**:SystemCapability.FileManagement.PhotoAccessHelper.Core 8106 8107**需要权限**:ohos.permission.WRITE_IMAGEVIDEO 8108 8109**参数:** 8110 8111| 参数名 | 类型 | 必填 | 说明 | 8112| -------- | ------------------------- | ---- | ---------- | 8113| photoAssets | Array<[PhotoAsset](#photoasset)> | 是 | 需要增强照片的[PhotoAsset](#photoasset)集合。 | 8114| hasCloudWatermark | boolean | 是 | 增强后图片是否添加云增强水印。 | 8115 8116**返回值:** 8117 8118| 类型 | 说明 | 8119| ------------------- | ---------- | 8120| Promise<void> | Promise对象,返回void。 | 8121 8122**错误码:** 8123 8124接口抛出错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)和[文件管理错误码](../apis-core-file-kit/errorcode-filemanagement.md)。 8125 8126| 错误码ID | 错误信息 | 8127| -------- | ---------------------------------------- | 8128| 201 | Permission denied. | 8129| 202 | Called by non-system application. | 8130| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types; 3. Parameter verification failed. | 8131| 14000011 | Internal system error. | 8132 8133**示例:** 8134 8135phAccessHelper的创建请参考[@ohos.file.photoAccessHelper (相册管理模块)](arkts-apis-photoAccessHelper-f.md)的示例使用。 8136 8137```ts 8138import { dataSharePredicates } from '@kit.ArkData'; 8139 8140async function example(context: Context) { 8141 console.info('submitCloudEnhancementTasksDemo'); 8142 let photoPredicates: dataSharePredicates.DataSharePredicates = new dataSharePredicates.DataSharePredicates(); 8143 let photoFetchOptions: photoAccessHelper.FetchOptions = { 8144 fetchColumns: [], 8145 predicates: photoPredicates 8146 }; 8147 let phAccessHelper = photoAccessHelper.getPhotoAccessHelper(context); 8148 try { 8149 let fetchResult = await phAccessHelper.getAssets(photoFetchOptions); 8150 let asset = await fetchResult.getLastObject(); 8151 let cloudEnhancementInstance: photoAccessHelper.CloudEnhancement 8152 = photoAccessHelper.CloudEnhancement.getCloudEnhancementInstance(context); 8153 let hasCloudWatermark = true; 8154 await cloudEnhancementInstance.submitCloudEnhancementTasks([asset], hasCloudWatermark); 8155 } catch (err) { 8156 console.error(`submitCloudEnhancementTasksDemo failed with error: ${err.code}, ${err.message}`); 8157 } 8158} 8159``` 8160 8161### submitCloudEnhancementTasks<sup>18+</sup> 8162 8163submitCloudEnhancementTasks(photoAssets: Array<PhotoAsset>, hasCloudWatermark: boolean, triggerMode?: number): Promise<void> 8164 8165提交云增强任务。 8166 8167**系统接口**:此接口为系统接口。 8168 8169**系统能力**:SystemCapability.FileManagement.PhotoAccessHelper.Core 8170 8171**需要权限**:ohos.permission.WRITE_IMAGEVIDEO 8172 8173**参数:** 8174 8175| 参数名 | 类型 | 必填 | 说明 | 8176| -------- | ------------------------- | ---- | ---------- | 8177| photoAssets | Array<[PhotoAsset](#photoasset)> | 是 | 需要增强照片的[PhotoAsset](#photoasset)集合。 | 8178| hasCloudWatermark | boolean | 是 | 若为true,增强后图片添加云增强水印;若为false,增强后图片不添加云增强水印。 | 8179| triggerMode | number | 否 | 云增强任务触发类型。<br>- 0:手动触发。<br>- 1:自动触发。<br>- 默认值为0。 | 8180 8181**返回值:** 8182 8183| 类型 | 说明 | 8184| ------------------- | ---------- | 8185| Promise<void> | Promise对象,返回void。 | 8186 8187**错误码:** 8188 8189以下错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)和[文件管理错误码](../apis-core-file-kit/errorcode-filemanagement.md)。 8190 8191| 错误码ID | 错误信息 | 8192| -------- | ---------------------------------------- | 8193| 201 | Permission denied. | 8194| 202 | Called by non-system application. | 8195| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types; 3. Parameter verification failed. | 8196| 14000011 | Internal system error. | 8197 8198**示例:** 8199 8200phAccessHelper的创建请参考[@ohos.file.photoAccessHelper (相册管理模块)](arkts-apis-photoAccessHelper-f.md)的示例使用。 8201 8202```ts 8203import { dataSharePredicates } from '@kit.ArkData'; 8204 8205async function example(context: Context) { 8206 console.info('submitCloudEnhancementTasksDemo'); 8207 let photoPredicates: dataSharePredicates.DataSharePredicates = new dataSharePredicates.DataSharePredicates(); 8208 let photoFetchOptions: photoAccessHelper.FetchOptions = { 8209 fetchColumns: [], 8210 predicates: photoPredicates 8211 }; 8212 let phAccessHelper = photoAccessHelper.getPhotoAccessHelper(context); 8213 try { 8214 let fetchResult = await phAccessHelper.getAssets(photoFetchOptions); 8215 let asset = await fetchResult.getLastObject(); 8216 let cloudEnhancementInstance: photoAccessHelper.CloudEnhancement 8217 = photoAccessHelper.CloudEnhancement.getCloudEnhancementInstance(context); 8218 let hasCloudWatermark = true; 8219 let triggerAuto = 1; 8220 await cloudEnhancementInstance.submitCloudEnhancementTasks([asset], hasCloudWatermark, triggerAuto); 8221 } catch (err) { 8222 console.error(`submitCloudEnhancementTasksDemo failed with error: ${err.code}, ${err.message}`); 8223 } 8224} 8225``` 8226 8227### prioritizeCloudEnhancementTask<sup>13+</sup> 8228 8229prioritizeCloudEnhancementTask(photoAsset: PhotoAsset): Promise<void> 8230 8231提升指定云增强任务的优先级。 8232 8233**系统接口**:此接口为系统接口。 8234 8235**系统能力**:SystemCapability.FileManagement.PhotoAccessHelper.Core 8236 8237**需要权限**:ohos.permission.WRITE_IMAGEVIDEO 8238 8239**参数:** 8240 8241| 参数名 | 类型 | 必填 | 说明 | 8242| -------- | ------------------------- | ---- | ---------- | 8243| photoAsset | [PhotoAsset](#photoasset) | 是 | 需要修改云增强优先级照片的[PhotoAsset](#photoasset)。 | 8244 8245**返回值:** 8246 8247| 类型 | 说明 | 8248| ------------------- | ---------- | 8249| Promise<void> | Promise对象,返回void。 | 8250 8251**错误码:** 8252 8253接口抛出错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)和[文件管理错误码](../apis-core-file-kit/errorcode-filemanagement.md)。 8254 8255| 错误码ID | 错误信息 | 8256| -------- | ---------------------------------------- | 8257| 201 | Permission denied. | 8258| 202 | Called by non-system application. | 8259| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types; 3. Parameter verification failed. | 8260| 14000011 | Internal system error. | 8261 8262**示例:** 8263 8264phAccessHelper的创建请参考[@ohos.file.photoAccessHelper (相册管理模块)](arkts-apis-photoAccessHelper-f.md)的示例使用。 8265 8266```ts 8267import { dataSharePredicates } from '@kit.ArkData'; 8268 8269async function example(context: Context) { 8270 console.info('prioritizeCloudEnhancementTaskDemo'); 8271 let photoPredicates: dataSharePredicates.DataSharePredicates = new dataSharePredicates.DataSharePredicates(); 8272 // 查询进行中的云增强任务。 8273 photoPredicates.equalTo(photoAccessHelper.PhotoKeys.CE_AVAILABLE, 2); 8274 let photoFetchOptions: photoAccessHelper.FetchOptions = { 8275 fetchColumns: [], 8276 predicates: photoPredicates 8277 }; 8278 let phAccessHelper = photoAccessHelper.getPhotoAccessHelper(context); 8279 try { 8280 let fetchResult = await phAccessHelper.getAssets(photoFetchOptions); 8281 let asset = await fetchResult.getLastObject(); 8282 let cloudEnhancementInstance: photoAccessHelper.CloudEnhancement 8283 = photoAccessHelper.CloudEnhancement.getCloudEnhancementInstance(context); 8284 let hasCloudWatermark = true; 8285 await cloudEnhancementInstance.prioritizeCloudEnhancementTask(asset); 8286 } catch (err) { 8287 console.error(`prioritizeCloudEnhancementTaskDemo failed with error: ${err.code}, ${err.message}`); 8288 } 8289} 8290``` 8291 8292### cancelCloudEnhancementTasks<sup>13+</sup> 8293 8294cancelCloudEnhancementTasks(photoAssets: Array<PhotoAsset>): Promise<void> 8295 8296取消指定云增强任务。 8297 8298**系统接口**:此接口为系统接口。 8299 8300**系统能力**:SystemCapability.FileManagement.PhotoAccessHelper.Core 8301 8302**需要权限**:ohos.permission.WRITE_IMAGEVIDEO 8303 8304**参数:** 8305 8306| 参数名 | 类型 | 必填 | 说明 | 8307| -------- | ------------------------- | ---- | ---------- | 8308| photoAssets | Array<[PhotoAsset](#photoasset)> | 是 | 需要取消云增强任务的[PhotoAsset](#photoasset)集合。 | 8309 8310**返回值:** 8311 8312| 类型 | 说明 | 8313| ------------------- | ---------- | 8314| Promise<void> | Promise对象,返回void。 | 8315 8316**错误码:** 8317 8318接口抛出错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)和[文件管理错误码](../apis-core-file-kit/errorcode-filemanagement.md)。 8319 8320| 错误码ID | 错误信息 | 8321| -------- | ---------------------------------------- | 8322| 201 | Permission denied. | 8323| 202 | Called by non-system application. | 8324| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types; 3. Parameter verification failed. | 8325| 14000011 | Internal system error. | 8326 8327**示例:** 8328 8329phAccessHelper的创建请参考[@ohos.file.photoAccessHelper (相册管理模块)](arkts-apis-photoAccessHelper-f.md)的示例使用。 8330 8331```ts 8332import { dataSharePredicates } from '@kit.ArkData'; 8333 8334async function example(context: Context) { 8335 console.info('cancelCloudEnhancementTasksDemo'); 8336 let photoPredicates: dataSharePredicates.DataSharePredicates = new dataSharePredicates.DataSharePredicates(); 8337 // 查询进行中的云增强任务。 8338 photoPredicates.equalTo(photoAccessHelper.PhotoKeys.CE_AVAILABLE, 2); 8339 let photoFetchOptions: photoAccessHelper.FetchOptions = { 8340 fetchColumns: [], 8341 predicates: photoPredicates 8342 }; 8343 let phAccessHelper = photoAccessHelper.getPhotoAccessHelper(context); 8344 try { 8345 let fetchResult = await phAccessHelper.getAssets(photoFetchOptions); 8346 let asset = await fetchResult.getLastObject(); 8347 let cloudEnhancementInstance: photoAccessHelper.CloudEnhancement 8348 = photoAccessHelper.CloudEnhancement.getCloudEnhancementInstance(context); 8349 await cloudEnhancementInstance.cancelCloudEnhancementTasks([asset]); 8350 } catch (err) { 8351 console.error(`cancelCloudEnhancementTasksDemo failed with error: ${err.code}, ${err.message}`); 8352 } 8353} 8354``` 8355 8356### cancelAllCloudEnhancementTasks<sup>13+</sup> 8357 8358cancelAllCloudEnhancementTasks(): Promise<void> 8359 8360取消全部云增强任务。 8361 8362**系统接口**:此接口为系统接口。 8363 8364**系统能力**:SystemCapability.FileManagement.PhotoAccessHelper.Core 8365 8366**需要权限**:ohos.permission.WRITE_IMAGEVIDEO 8367 8368**返回值:** 8369 8370| 类型 | 说明 | 8371| ------------------- | ---------- | 8372| Promise<void> | Promise对象,返回void。 | 8373 8374**错误码:** 8375 8376接口抛出错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)和[文件管理错误码](../apis-core-file-kit/errorcode-filemanagement.md)。 8377 8378| 错误码ID | 错误信息 | 8379| -------- | ---------------------------------------- | 8380| 201 | Permission denied. | 8381| 202 | Called by non-system application. | 8382| 14000011 | Internal system error. | 8383 8384**示例:** 8385 8386```ts 8387import { dataSharePredicates } from '@kit.ArkData'; 8388 8389async function example(context: Context) { 8390 console.info('cancelAllCloudEnhancementTasksDemo'); 8391 try { 8392 let cloudEnhancementInstance: photoAccessHelper.CloudEnhancement 8393 = photoAccessHelper.CloudEnhancement.getCloudEnhancementInstance(context); 8394 await cloudEnhancementInstance.cancelAllCloudEnhancementTasks(); 8395 } catch (err) { 8396 console.error(`cancelAllCloudEnhancementTasksDemo failed with error: ${err.code}, ${err.message}`); 8397 } 8398} 8399``` 8400 8401### queryCloudEnhancementTaskState<sup>13+</sup> 8402 8403queryCloudEnhancementTaskState(photoAsset: PhotoAsset): Promise<CloudEnhancementTaskState> 8404 8405查询云增强任务信息。 8406 8407**系统接口**:此接口为系统接口。 8408 8409**系统能力**:SystemCapability.FileManagement.PhotoAccessHelper.Core 8410 8411**需要权限**:ohos.permission.READ_IMAGEVIDEO 8412 8413**参数:** 8414 8415| 参数名 | 类型 | 必填 | 说明 | 8416| -------- | ------------------------- | ---- | ---------- | 8417| photoAsset | [PhotoAsset](#photoasset) | 是 | 需要查询云增强任务信息的[PhotoAsset](#photoasset)。 | 8418 8419**返回值:** 8420 8421| 类型 | 说明 | 8422| --------------------------------------- | ----------------- | 8423| Promise<[CloudEnhancementTaskState](#cloudenhancementtaskstate13)> | 返回云增强任务信息。 | 8424 8425**错误码:** 8426 8427接口抛出错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)和[文件管理错误码](../apis-core-file-kit/errorcode-filemanagement.md)。 8428 8429| 错误码ID | 错误信息 | 8430| -------- | ---------------------------------------- | 8431| 201 | Permission denied. | 8432| 202 | Called by non-system application. | 8433| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types; 3. Parameter verification failed. | 8434| 14000011 | Internal system error. | 8435 8436**示例:** 8437 8438phAccessHelper的创建请参考[@ohos.file.photoAccessHelper (相册管理模块)](arkts-apis-photoAccessHelper-f.md)的示例使用。 8439 8440```ts 8441import { dataSharePredicates } from '@kit.ArkData'; 8442 8443async function example(context: Context) { 8444 console.info('queryCloudEnhancementTaskStateDemo'); 8445 let photoPredicates: dataSharePredicates.DataSharePredicates = new dataSharePredicates.DataSharePredicates(); 8446 // 查询进行中的云增强任务。 8447 photoPredicates.equalTo(photoAccessHelper.PhotoKeys.CE_AVAILABLE, 2); 8448 let photoFetchOptions: photoAccessHelper.FetchOptions = { 8449 fetchColumns: [], 8450 predicates: photoPredicates 8451 }; 8452 let phAccessHelper = photoAccessHelper.getPhotoAccessHelper(context); 8453 try { 8454 let fetchResult = await phAccessHelper.getAssets(photoFetchOptions); 8455 let asset = await fetchResult.getLastObject(); 8456 let cloudEnhancementInstance: photoAccessHelper.CloudEnhancement 8457 = photoAccessHelper.CloudEnhancement.getCloudEnhancementInstance(context); 8458 const cloudEnhancementTaskState: photoAccessHelper.CloudEnhancementTaskState 8459 = await cloudEnhancementInstance.queryCloudEnhancementTaskState(asset); 8460 let taskStage = cloudEnhancementTaskState.taskStage; 8461 if (taskStage == photoAccessHelper.CloudEnhancementTaskStage.TASK_STAGE_EXCEPTION) { 8462 console.log("task has exception"); 8463 } else if (taskStage == photoAccessHelper.CloudEnhancementTaskStage.TASK_STAGE_PREPARING) { 8464 console.log("task is preparing"); 8465 } else if (taskStage == photoAccessHelper.CloudEnhancementTaskStage.TASK_STAGE_UPLOADING) { 8466 let transferredFileSize = cloudEnhancementTaskState.transferredFileSize; 8467 let totalFileSize = cloudEnhancementTaskState.totalFileSize; 8468 let message = `task is uploading, transferredFileSize: ${transferredFileSize}, totalFileSize: ${totalFileSize}`; 8469 console.log(message); 8470 } else if (taskStage == photoAccessHelper.CloudEnhancementTaskStage.TASK_STAGE_EXECUTING) { 8471 let expectedDuration = cloudEnhancementTaskState.expectedDuration; 8472 let message = `task is executing, expectedDuration: ${expectedDuration}`; 8473 console.log(message); 8474 } else if (taskStage == photoAccessHelper.CloudEnhancementTaskStage.TASK_STAGE_DOWNLOADING) { 8475 let transferredFileSize = cloudEnhancementTaskState.transferredFileSize; 8476 let totalFileSize = cloudEnhancementTaskState.totalFileSize; 8477 let message = `task is downloading, transferredFileSize: ${transferredFileSize}, totalFileSize: ${totalFileSize}`; 8478 console.log(message); 8479 } else if (taskStage == photoAccessHelper.CloudEnhancementTaskStage.TASK_STAGE_FAILED) { 8480 let errCode = cloudEnhancementTaskState.statusCode; 8481 let message = `task is failed, errCode: ${errCode}`; 8482 console.log(message); 8483 } else if (taskStage == photoAccessHelper.CloudEnhancementTaskStage.TASK_STAGE_COMPLETED) { 8484 console.log("task is completed"); 8485 } 8486 } catch (err) { 8487 console.error(`queryCloudEnhancementTaskStateDemo failed with error: ${err.code}, ${err.message}`); 8488 } 8489} 8490``` 8491 8492### syncCloudEnhancementTaskStatus<sup>13+</sup> 8493 8494syncCloudEnhancementTaskStatus(): Promise<void> 8495 8496同步云增强任务状态。 8497 8498**系统接口**:此接口为系统接口。 8499 8500**系统能力**:SystemCapability.FileManagement.PhotoAccessHelper.Core 8501 8502**需要权限**:ohos.permission.READ_IMAGEVIDEO 8503 8504**返回值:** 8505 8506| 类型 | 说明 | 8507| ------------------- | ---------- | 8508| Promise<void> | Promise对象,返回void。 | 8509 8510**错误码:** 8511 8512接口抛出错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)和[文件管理错误码](../apis-core-file-kit/errorcode-filemanagement.md)。 8513 8514| 错误码ID | 错误信息 | 8515| -------- | ---------------------------------------- | 8516| 201 | Permission denied. | 8517| 202 | Called by non-system application. | 8518| 14000011 | Internal system error. | 8519 8520**示例:** 8521 8522```ts 8523import { dataSharePredicates } from '@kit.ArkData'; 8524 8525async function example(context: Context) { 8526 console.info('syncCloudEnhancementTaskStatusDemo'); 8527 try { 8528 let cloudEnhancementInstance: photoAccessHelper.CloudEnhancement 8529 = photoAccessHelper.CloudEnhancement.getCloudEnhancementInstance(context); 8530 await cloudEnhancementInstance.syncCloudEnhancementTaskStatus(); 8531 } catch (err) { 8532 console.error(`syncCloudEnhancementTaskStatusDemo failed with error: ${err.code}, ${err.message}`); 8533 } 8534} 8535``` 8536 8537### getCloudEnhancementPair<sup>13+</sup> 8538 8539getCloudEnhancementPair(asset: PhotoAsset): Promise<PhotoAsset> 8540 8541查询云增强配对照片。 8542 8543**系统接口**:此接口为系统接口。 8544 8545**系统能力**:SystemCapability.FileManagement.PhotoAccessHelper.Core 8546 8547**需要权限**:ohos.permission.READ_IMAGEVIDEO 8548 8549**参数:** 8550 8551| 参数名 | 类型 | 必填 | 说明 | 8552| -------- | ------------------------- | ---- | ---------- | 8553| photoAsset | [PhotoAsset](#photoasset) | 是 | 需要查询云增强配对照片的[PhotoAsset](#photoasset)。 | 8554 8555**返回值:** 8556 8557| 类型 | 说明 | 8558| --------------------------------------- | ----------------- | 8559| Promise<[PhotoAsset](#photoasset)> | 返回云增强配对照片。 | 8560 8561**错误码:** 8562 8563接口抛出错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)和[文件管理错误码](../apis-core-file-kit/errorcode-filemanagement.md)。 8564 8565| 错误码ID | 错误信息 | 8566| -------- | ---------------------------------------- | 8567| 201 | Permission denied. | 8568| 202 | Called by non-system application. | 8569| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types; 3. Parameter verification failed. | 8570| 14000011 | Internal system error. | 8571 8572**示例:** 8573 8574phAccessHelper的创建请参考[@ohos.file.photoAccessHelper (相册管理模块)](arkts-apis-photoAccessHelper-f.md)的示例使用。 8575 8576```ts 8577import { dataSharePredicates } from '@kit.ArkData'; 8578 8579async function example(context: Context) { 8580 console.info('getCloudEnhancementPairDemo'); 8581 let photoPredicates: dataSharePredicates.DataSharePredicates = new dataSharePredicates.DataSharePredicates(); 8582 // 查询已完成的云增强任务。 8583 photoPredicates.equalTo(photoAccessHelper.PhotoKeys.CE_AVAILABLE, 5); 8584 let photoFetchOptions: photoAccessHelper.FetchOptions = { 8585 fetchColumns: [], 8586 predicates: photoPredicates 8587 }; 8588 let phAccessHelper = photoAccessHelper.getPhotoAccessHelper(context); 8589 try { 8590 let fetchResult = await phAccessHelper.getAssets(photoFetchOptions); 8591 let asset = await fetchResult.getLastObject(); 8592 let cloudEnhancementInstance: photoAccessHelper.CloudEnhancement 8593 = photoAccessHelper.CloudEnhancement.getCloudEnhancementInstance(context); 8594 let photoAsset: photoAccessHelper.PhotoAsset 8595 = await cloudEnhancementInstance.getCloudEnhancementPair(asset); 8596 } catch (err) { 8597 console.error(`getCloudEnhancementPairDemo failed with error: ${err.code}, ${err.message}`); 8598 } 8599} 8600``` 8601 8602### setVideoEnhancementAttr<sup>13+</sup> 8603 8604setVideoEnhancementAttr(videoEnhancementType: VideoEnhancementType, photoId: string): Promise<void> 8605 8606设置视频的二阶段增强处理类型。 8607 8608**系统接口**:此接口为系统接口。 8609 8610**需要权限**:ohos.permission.WRITE\_IMAGEVIDEO 8611 8612**系统能力**:SystemCapability.FileManagement.PhotoAccessHelper.Core 8613 8614**参数:** 8615 8616| 参数名 | 类型 | 必填 | 说明 | 8617| ---------- | ------- | ---- | ---------------------------------- | 8618| videoEnhancementType | [VideoEnhancementType](#videoenhancementtype13) | 是 | 需要进行分段式视频的处理类型。 | 8619| photoId | string | 是 | 图片的photoId。 | 8620 8621**返回值:** 8622 8623| 类型 | 说明 | 8624| ------------------- | ---------- | 8625| Promise<void> | Promise对象,返回void。 | 8626 8627**错误码:** 8628 8629接口抛出错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)和[文件管理错误码](../apis-core-file-kit/errorcode-filemanagement.md)。 8630 8631| 错误码ID | 错误信息 | 8632| :------- | :-------------------------------- | 8633| 202 | Called by non-system application. | 8634| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types; 3. Parameter verification failed. | 8635| 14000011 | Internal system error. | 8636| 14000016 | Operation Not Support. | 8637 8638**示例:** 8639 8640phAccessHelper的创建请参考[@ohos.file.photoAccessHelper (相册管理模块)](arkts-apis-photoAccessHelper-f.md)的示例使用。 8641 8642```ts 8643async function example(phAccessHelper: photoAccessHelper.PhotoAccessHelper, asset: photoAccessHelper.PhotoAsset) { 8644 try { 8645 let assetChangeRequest: photoAccessHelper.MediaAssetChangeRequest = new photoAccessHelper.MediaAssetChangeRequest(asset); 8646 let photoId = "202410011800"; 8647 assetChangeRequest.setVideoEnhancementAttr(photoAccessHelper.VideoEnhancementType.QUALITY_ENHANCEMENT_LOCAL, photoId); 8648 await phAccessHelper.applyChanges(assetChangeRequest); 8649 } catch (err) { 8650 console.error(`setVideoEnhancementAttr fail with error: ${err.code}, ${err.message}`); 8651 } 8652} 8653``` 8654 8655## CloudMediaAssetManager<sup>14+</sup> 8656 8657云端媒体资产管理类,该类用于管理云端资产的下载任务,以及删除云端资产在本地的数据和文件。 8658 8659**系统接口**:此接口为系统接口。 8660 8661**系统能力**:SystemCapability.FileManagement.PhotoAccessHelper.Core 8662 8663### getCloudMediaAssetManagerInstance<sup>14+</sup> 8664 8665static getCloudMediaAssetManagerInstance(context: Context): CloudMediaAssetManager 8666 8667获取云端媒体资产管理类实例。 8668 8669**系统接口**:此接口为系统接口。 8670 8671**系统能力**:SystemCapability.FileManagement.PhotoAccessHelper.Core 8672 8673**参数:** 8674 8675| 参数名 | 类型 | 必填 | 说明 | 8676| -------- | ------------------------- | ---- | ---------- | 8677| context | [Context](../apis-ability-kit/js-apis-inner-application-context.md) | 是 | 传入Ability实例的Context。 | 8678 8679**返回值:** 8680 8681| 类型 | 说明 | 8682| --------------------------------------- | ----------------- | 8683| [CloudMediaAssetManager](#cloudmediaassetmanager14) | 返回云端媒体资产管理类实例。 | 8684 8685**错误码:** 8686 8687接口抛出错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)和[文件管理错误码](../apis-core-file-kit/errorcode-filemanagement.md)。 8688 8689| 错误码ID | 错误信息 | 8690| -------- | ---------------------------------------- | 8691| 202 | Called by non-system application. | 8692| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types; 3. Parameter verification failed. | 8693| 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. | 8694 8695**示例:** 8696 8697```ts 8698async function example(context: Context) { 8699 console.info('getCloudMediaAssetManagerInstanceDemo'); 8700 try { 8701 let cloudMediaAssetManagerInstance: photoAccessHelper.CloudMediaAssetManager 8702 = photoAccessHelper.CloudMediaAssetManager.getCloudMediaAssetManagerInstance(context); 8703 await cloudMediaAssetManagerInstance.pauseDownloadCloudMedia(); 8704 } catch (err) { 8705 console.error(`getCloudMediaAssetManagerInstanceDemo failed with error: ${err.code}, ${err.message}`); 8706 } 8707} 8708``` 8709 8710### startDownloadCloudMedia<sup>14+</sup> 8711 8712startDownloadCloudMedia(downloadType: CloudMediaDownloadType): Promise<void> 8713 8714开始或恢复云端媒体资产下载任务。 8715 8716**系统接口**:此接口为系统接口。 8717 8718**系统能力**:SystemCapability.FileManagement.PhotoAccessHelper.Core 8719 8720**需要权限**:ohos.permission.CLOUDFILE_SYNC_MANAGER 8721 8722**参数:** 8723 8724| 参数名 | 类型 | 必填 | 说明 | 8725| -------- | ------------------------- | ---- | ---------- | 8726| downloadType | [CloudMediaDownloadType](#cloudmediadownloadtype14) | 是 | 云端媒体资产的下载方式。 | 8727 8728**返回值:** 8729 8730| 类型 | 说明 | 8731| --------------------------------------- | ----------------- | 8732| Promise<void>| Promise对象,返回void。 | 8733 8734**错误码:** 8735 8736接口抛出错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)和[文件管理错误码](../apis-core-file-kit/errorcode-filemanagement.md)。 8737 8738| 错误码ID | 错误信息 | 8739| -------- | ---------------------------------------- | 8740| 201 | Permission denied. | 8741| 202 | Called by non-system application. | 8742| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types; 3. Parameter verification failed. | 8743| 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. | 8744 8745**示例:** 8746 8747```ts 8748async function example(context: Context) { 8749 console.info('startDownloadCloudMediaDemo'); 8750 try { 8751 let cloudMediaAssetManagerInstance: photoAccessHelper.CloudMediaAssetManager 8752 = photoAccessHelper.CloudMediaAssetManager.getCloudMediaAssetManagerInstance(context); 8753 await cloudMediaAssetManagerInstance.startDownloadCloudMedia(photoAccessHelper.CloudMediaDownloadType.DOWNLOAD_FORCE); 8754 } catch (err) { 8755 console.error(`startDownloadCloudMediaDemo failed with error: ${err.code}, ${err.message}`); 8756 } 8757} 8758``` 8759 8760### pauseDownloadCloudMedia<sup>14+</sup> 8761 8762pauseDownloadCloudMedia(): Promise<void> 8763 8764暂停云端媒体资产下载任务。 8765 8766**系统接口**:此接口为系统接口。 8767 8768**系统能力**:SystemCapability.FileManagement.PhotoAccessHelper.Core 8769 8770**需要权限**:ohos.permission.CLOUDFILE_SYNC_MANAGER 8771 8772**返回值:** 8773 8774| 类型 | 说明 | 8775| --------------------------------------- | ----------------- | 8776| Promise<void>| Promise对象,返回void。 | 8777 8778**错误码:** 8779 8780接口抛出错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)和[文件管理错误码](../apis-core-file-kit/errorcode-filemanagement.md)。 8781 8782| 错误码ID | 错误信息 | 8783| -------- | ---------------------------------------- | 8784| 201 | Permission denied. | 8785| 202 | Called by non-system application. | 8786| 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. | 8787 8788**示例:** 8789 8790```ts 8791async function example(context: Context) { 8792 console.info('pauseDownloadCloudMediaDemo'); 8793 try { 8794 let cloudMediaAssetManagerInstance: photoAccessHelper.CloudMediaAssetManager 8795 = photoAccessHelper.CloudMediaAssetManager.getCloudMediaAssetManagerInstance(context); 8796 await cloudMediaAssetManagerInstance.pauseDownloadCloudMedia(); 8797 } catch (err) { 8798 console.error(`pauseDownloadCloudMediaDemo failed with error: ${err.code}, ${err.message}`); 8799 } 8800} 8801``` 8802 8803### cancelDownloadCloudMedia<sup>14+</sup> 8804 8805cancelDownloadCloudMedia(): Promise<void> 8806 8807取消云端媒体资产下载任务。 8808 8809**系统接口**:此接口为系统接口。 8810 8811**系统能力**:SystemCapability.FileManagement.PhotoAccessHelper.Core 8812 8813**需要权限**:ohos.permission.CLOUDFILE_SYNC_MANAGER 8814 8815**返回值:** 8816 8817| 类型 | 说明 | 8818| --------------------------------------- | ----------------- | 8819| Promise<void>| Promise对象,返回void。 | 8820 8821**错误码:** 8822 8823接口抛出错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)和[文件管理错误码](../apis-core-file-kit/errorcode-filemanagement.md)。 8824 8825| 错误码ID | 错误信息 | 8826| -------- | ---------------------------------------- | 8827| 201 | Permission denied. | 8828| 202 | Called by non-system application. | 8829| 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. | 8830 8831**示例:** 8832 8833```ts 8834async function example(context: Context) { 8835 console.info('cancelDownloadCloudMediaDemo'); 8836 try { 8837 let cloudMediaAssetManagerInstance: photoAccessHelper.CloudMediaAssetManager 8838 = photoAccessHelper.CloudMediaAssetManager.getCloudMediaAssetManagerInstance(context); 8839 await cloudMediaAssetManagerInstance.cancelDownloadCloudMedia(); 8840 } catch (err) { 8841 console.error(`cancelDownloadCloudMediaDemo failed with error: ${err.code}, ${err.message}`); 8842 } 8843} 8844``` 8845 8846### retainCloudMediaAsset<sup>14+</sup> 8847 8848retainCloudMediaAsset(retainType: CloudMediaRetainType): Promise<void> 8849 8850删除云端媒体资产在本地的元数据和文件。 8851 8852**系统接口**:此接口为系统接口。 8853 8854**系统能力**:SystemCapability.FileManagement.PhotoAccessHelper.Core 8855 8856**需要权限**:ohos.permission.CLOUDFILE_SYNC_MANAGER 8857 8858**参数:** 8859 8860| 参数名 | 类型 | 必填 | 说明 | 8861| -------- | ------------------------- | ---- | ---------- | 8862| retainType | [CloudMediaRetainType](#cloudmediaretaintype14) | 是 | 云端媒体资产的删除方式。 | 8863 8864**返回值:** 8865 8866| 类型 | 说明 | 8867| --------------------------------------- | ----------------- | 8868| Promise<void>| Promise对象,返回void。 | 8869 8870**错误码:** 8871 8872接口抛出错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)和[文件管理错误码](../apis-core-file-kit/errorcode-filemanagement.md)。 8873 8874| 错误码ID | 错误信息 | 8875| -------- | ---------------------------------------- | 8876| 201 | Permission denied. | 8877| 202 | Called by non-system application. | 8878| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types; 3. Parameter verification failed. | 8879| 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. | 8880 8881**示例:** 8882 8883```ts 8884async function example(context: Context) { 8885 console.info('retainCloudMediaAssetDemo'); 8886 try { 8887 let cloudMediaAssetManagerInstance: photoAccessHelper.CloudMediaAssetManager 8888 = photoAccessHelper.CloudMediaAssetManager.getCloudMediaAssetManagerInstance(context); 8889 await cloudMediaAssetManagerInstance.retainCloudMediaAsset(photoAccessHelper.CloudMediaRetainType.RETAIN_FORCE); 8890 } catch (err) { 8891 console.error(`retainCloudMediaAssetDemo failed with error: ${err.code}, ${err.message}`); 8892 } 8893} 8894``` 8895 8896### getCloudMediaAssetStatus<sup>14+</sup> 8897 8898getCloudMediaAssetStatus(): Promise<CloudMediaAssetStatus> 8899 8900查询云端媒体资产下载任务状态。 8901 8902**系统接口**:此接口为系统接口。 8903 8904**系统能力**:SystemCapability.FileManagement.PhotoAccessHelper.Core 8905 8906**需要权限**:ohos.permission.READ_IMAGEVIDEO 8907 8908**返回值:** 8909 8910| 类型 | 说明 | 8911| --------------------------------------- | ----------------- | 8912|Promise<[CloudMediaAssetStatus](#cloudmediaassetstatus14)> | Promise对象,返回云端媒体资产下载任务状态。 | 8913 8914**错误码:** 8915 8916接口抛出错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)和[文件管理错误码](../apis-core-file-kit/errorcode-filemanagement.md)。 8917 8918| 错误码ID | 错误信息 | 8919| -------- | ---------------------------------------- | 8920| 201 | Permission denied. | 8921| 202 | Called by non-system application. | 8922| 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. | 8923 8924**示例:** 8925 8926```ts 8927async function example(context: Context) { 8928 console.info('getCloudMediaAssetStatusDemo'); 8929 try { 8930 let cloudMediaAssetManagerInstance: photoAccessHelper.CloudMediaAssetManager 8931 = photoAccessHelper.CloudMediaAssetManager.getCloudMediaAssetManagerInstance(context); 8932 const cloudMediaAssetStatus: photoAccessHelper.CloudMediaAssetStatus = await cloudMediaAssetManagerInstance.getCloudMediaAssetStatus(); 8933 let taskStatus = cloudMediaAssetStatus.taskStatus; 8934 let taskInfo = cloudMediaAssetStatus.taskInfo; 8935 let errorCode = cloudMediaAssetStatus.errorCode; 8936 let message = `taskStatus: ${taskStatus}, taskInfo: ${taskInfo}, errorCode: ${errorCode}`; 8937 console.log(message); 8938 } catch (err) { 8939 console.error(`getCloudMediaAssetStatusDemo failed with error: ${err.code}, ${err.message}`); 8940 } 8941} 8942``` 8943 8944## MovingPhoto<sup>12+</sup> 8945 8946动态照片对象。 8947 8948### isVideoReady<sup>20+</sup> 8949 8950isVideoReady(): Promise<boolean> 8951 8952查询动态照片的视频是否已生成。使用Promise异步回调。 8953 8954**系统接口**:此接口为系统接口。 8955 8956**系统能力**:SystemCapability.FileManagement.PhotoAccessHelper.Core 8957 8958**需要权限**:ohos.permission.READ_IMAGEVIDEO 8959 8960**返回值:** 8961 8962| 类型 | 说明 | 8963| --------------------------------------- | ----------------- | 8964| Promise<boolean> | Promise对象。返回true表示动态照片视频已生成; 返回false表示动态照片视频未生成完成。 | 8965 8966**错误码:** 8967 8968以下错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)和[媒体库错误码](errcode-medialibrary.md)。 8969 8970| 错误码ID | 错误信息 | 8971| -------- | ---------------------------------------- | 8972| 201 | Permission denied | 8973| 202 | Called by non-system application | 8974| 23800301 | 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. | 8975 8976**示例:** 8977 8978phAccessHelper的创建请参考[photoAccessHelper.getPhotoAccessHelper](./js-apis-photoAccessHelper.md#photoaccesshelpergetphotoaccesshelper)的示例使用。 8979 8980```ts 8981import { dataSharePredicates } from '@kit.ArkData'; 8982 8983class MovingPhotoHandler implements photoAccessHelper.MediaAssetDataHandler<photoAccessHelper.MovingPhoto> { 8984 async onDataPrepared(movingPhoto: photoAccessHelper.MovingPhoto) { 8985 if (movingPhoto === undefined) { 8986 console.error('Error occurred when preparing data'); 8987 return; 8988 } 8989 try { 8990 let isVideoReady = await movingPhoto.isVideoReady() 8991 console.info("moving photo video ready:" + `${isVideoReady}`); 8992 } catch (err) { 8993 console.error(`failed to get isVideoReady, error code is ${err.code}, message is ${err.message}`) 8994 } 8995 } 8996} 8997 8998async function example(phAccessHelper: photoAccessHelper.PhotoAccessHelper, context: Context) { 8999 let predicates: dataSharePredicates.DataSharePredicates = new dataSharePredicates.DataSharePredicates(); 9000 predicates.equalTo(photoAccessHelper.PhotoKeys.PHOTO_SUBTYPE, photoAccessHelper.PhotoSubtype.MOVING_PHOTO); 9001 let fetchOptions: photoAccessHelper.FetchOptions = { 9002 fetchColumns: [], 9003 predicates: predicates 9004 }; 9005 // 请确保图库内存在动态照片。 9006 let assetResult: photoAccessHelper.FetchResult<photoAccessHelper.PhotoAsset> = await phAccessHelper.getAssets(fetchOptions); 9007 let asset: photoAccessHelper.PhotoAsset = await assetResult.getFirstObject(); 9008 let requestOptions: photoAccessHelper.RequestOptions = { 9009 deliveryMode: photoAccessHelper.DeliveryMode.FAST_MODE, 9010 } 9011 const handler = new MovingPhotoHandler(); 9012 try { 9013 let requestId: string = await photoAccessHelper.MediaAssetManager.requestMovingPhoto(context, asset, requestOptions, handler); 9014 console.info("moving photo requested successfully, requestId: " + requestId); 9015 } catch (err) { 9016 console.error(`failed to request moving photo, error code is ${err.code}, message is ${err.message}`); 9017 } 9018} 9019``` 9020 9021## PhotoAssetCustomRecordManager<sup>20+</sup> 9022 9023媒体库支持图库自定义用户统计行为接口。 9024 9025**系统接口**:此接口为系统接口。 9026 9027### getCustomRecordManagerInstance<sup>20+</sup> 9028 9029static getCustomRecordManagerInstance(context: Context): PhotoAssetCustomRecordManager 9030 9031获取图库自定义用户统计行为实例。 9032 9033**系统接口**:此接口为系统接口。 9034 9035**系统能力**: SystemCapability.FileManagement.PhotoAccessHelper.Core 9036 9037**参数:** 9038 9039| 参数名 | 类型 | 必填 | 说明 | 9040| --- | --- | --- | --- | 9041| context | [Context](../apis-ability-kit/js-apis-inner-application-context.md#context) | 是 | 传入Ability实例的上下文。 | 9042 9043**返回值:** 9044 9045| 类型 | 说明 | 9046| --- | --- | 9047| [PhotoAssetCustomRecordManager](#photoassetcustomrecordmanager20) | 用户自定义行为统计实例。 | 9048 9049**错误码:** 9050 9051以下错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)和[媒体库错误码](errcode-medialibrary.md)。 9052 9053| 错误码ID | 错误信息 | 9054| --- | --- | 9055| 202 | Called by non-system application. | 9056| 23800107 | Context is invalid. | 9057 9058**示例:** 9059 9060```ts 9061import { common } from '@kit.AbilityKit'; 9062import { BusinessError } from '@kit.BasicServicesKit'; 9063 9064async function example(context: Context) { 9065 console.info('getCustomRecordManagerInstance'); 9066 try { 9067 let crManager = photoAccessHelper.PhotoAssetCustomRecordManager.getCustomRecordManagerInstance(context); 9068 } catch(err) { 9069 console.error(`getCustomRecordManagerInstance failed with error: ${err.code}, ${err.message}`); 9070 } 9071} 9072``` 9073 9074### createCustomRecords<sup>20+</sup> 9075 9076createCustomRecords(customRecords: Array<PhotoAssetCustomRecord>): Promise<void> 9077 9078新增自定义用户统计行为数据。使用Promise异步回调。 9079 9080**系统接口**:此接口为系统接口。 9081 9082**系统能力**: SystemCapability.FileManagement.PhotoAccessHelper.Core 9083 9084**参数:** 9085 9086| 参数名 | 类型 | 必填 | 说明 | 9087| --- | --- | --- | --- | 9088| customRecords | Array<[PhotoAssetCustomRecord](#photoassetcustomrecord20)> | 是 | 新增自定义用户统计行为数据。 | 9089 9090**返回值:** 9091 9092| 类型 | 说明 | 9093| --- | --- | 9094| Promise<void> | Promise对象,无返回结果。 | 9095 9096**错误码:** 9097 9098以下错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)和[媒体库错误码](errcode-medialibrary.md)。 9099 9100| 错误码ID | 错误信息 | 9101| --- | --- | 9102| 202 | Called by non-system application. | 9103| 23800151 | Scenario parameters fail to pass the verification. Possible causes: 1. The value range of mandatory parameters in photoAssetCustomRecord does not meet the requirements. 2. The transferred record already exists. 3. The number of transferred records exceeds 200. | 9104| 23800301 | 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. | 9105 9106**示例:** 9107 9108```ts 9109import { BusinessError } from '@kit.BasicServicesKit'; 9110 9111async function example(context: Context) { 9112 console.info('createCustomRecords'); 9113 let crManager = photoAccessHelper.PhotoAssetCustomRecordManager.getCustomRecordManagerInstance(context); 9114 let crArray:Array<photoAccessHelper.PhotoAssetCustomRecord> = [ 9115 {fileId:1,shareCount:1,lcdJumpCount:1} 9116 ]; 9117 crManager.createCustomRecords(crArray).then(() => { 9118 console.info('createCustomRecords successful'); 9119 }).catch((err: BusinessError) => { 9120 console.error('createCustomRecords fail with error: ${err.code}, ${err.message}'); 9121 }); 9122} 9123``` 9124 9125### getCustomRecords<sup>20+</sup> 9126 9127getCustomRecords(optionCheck: FetchOptions): Promise<FetchResult<PhotoAssetCustomRecord>> 9128 9129根据检索选项获取自定义用户统计行为数据。使用Promise异步回调。 9130 9131**系统接口**:此接口为系统接口。 9132 9133**系统能力**: SystemCapability.FileManagement.PhotoAccessHelper.Core 9134 9135**参数:** 9136 9137| 参数名 | 类型 | 必填 | 说明 | 9138| --- | --- | --- | --- | 9139| optionCheck | [FetchOptions](js-apis-photoAccessHelper.md#fetchoptions) | 是 | 检索选项。 | 9140 9141**返回值:** 9142 9143| 类型 | 说明 | 9144| --- | --- | 9145| Promise<FetchResult<[PhotoAssetCustomRecord](#photoassetcustomrecord20)>> | Promise对象,返回自定义用户统计行为数据集合。 | 9146 9147**错误码:** 9148 9149以下错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)和[媒体库错误码](errcode-medialibrary.md)。 9150 9151| 错误码ID | 错误信息 | 9152| --- | --- | 9153| 202 | Called by non-system application. | 9154| 23800151 | Scenario parameters fail to pass the verification. Possible causes: 1. The fileter criteria or fetchColumns that are not supported by options are transferred. | 9155| 23800301 | 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. | 9156 9157**示例:** 9158 9159```ts 9160import { dataSharePredicates } from '@kit.ArkData'; 9161import { BusinessError } from '@kit.BasicServicesKit'; 9162 9163async function example(context: Context) { 9164 console.info('getCustomRecords'); 9165 let crManager = photoAccessHelper.PhotoAssetCustomRecordManager.getCustomRecordManagerInstance(context); 9166 let predicates: dataSharePredicates.DataSharePredicates = new dataSharePredicates.DataSharePredicates(); 9167 predicates.equalTo('file_id', 1); 9168 let fetchOption: photoAccessHelper.FetchOptions = { 9169 fetchColumns: [], 9170 predicates: predicates 9171 }; 9172 crManager.getCustomRecords(fetchOption).then(async (fetchResult) => { 9173 let record = await fetchResult.getFirstObject(); 9174 console.info('record file id is ' + record.fileId); 9175 }).catch((err: BusinessError) => { 9176 console.error('getCustomRecords fail with error: ${err.code}, ${err.message}'); 9177 }); 9178} 9179``` 9180 9181### setCustomRecords<sup>20+</sup> 9182 9183setCustomRecords(customRecords: Array<PhotoAssetCustomRecord>): Promise<Array<number>> 9184 9185根据自定义用户统计行为数据,更新已存在的数据库字段。使用Promise异步回调。 9186 9187**系统接口**:此接口为系统接口。 9188 9189**系统能力**: SystemCapability.FileManagement.PhotoAccessHelper.Core 9190 9191**参数:** 9192 9193| 参数名 | 类型 | 必填 | 说明 | 9194| --- | --- | --- | --- | 9195| customRecords | Array<[PhotoAssetCustomRecord](#photoassetcustomrecord20)> | 是 | 自定义用户统计行为数据。 | 9196 9197**返回值:** 9198 9199| 类型 | 说明 | 9200| --- | --- | 9201| Promise<Array<number>> | 更新失败的自定义用户统计行为数据中的fileId。 | 9202 9203**错误码:** 9204 9205以下错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)和[媒体库错误码](errcode-medialibrary.md)。 9206 9207| 错误码ID | 错误信息 | 9208| --- | --- | 9209| 202 | Called by non-system application. | 9210| 23800151 | Scenario parameters fail to pass the verification. Possible causes: 1. The value range of mandatory parameters in photoAssetCustomRecord does not meet the requirements. 2. The number of transferred records exceeds 200. | 9211| 23800301 | 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. | 9212 9213**示例:** 9214 9215```ts 9216import { BusinessError } from '@kit.BasicServicesKit'; 9217 9218async function example(context: Context) { 9219 console.info('setCustomRecords'); 9220 let crManager = photoAccessHelper.PhotoAssetCustomRecordManager.getCustomRecordManagerInstance(context); 9221 let UpdateArray: Array<photoAccessHelper.PhotoAssetCustomRecord> = [ 9222 {fileId:1,shareCount:2,lcdJumpCount:3}, 9223 {fileId:2,shareCount:2,lcdJumpCount:3} 9224 ]; 9225 crManager.setCustomRecords(UpdateArray).then((failIds) => { 9226 console.info('setCustomRecords successful'); 9227 }).catch((err: BusinessError) => { 9228 console.error('setCustomRecords file with err: ${err.code}, ${err.message}'); 9229 }); 9230} 9231``` 9232 9233### removeCustomRecords<sup>20+</sup> 9234 9235removeCustomRecords(optionCheck: FetchOptions): Promise<void> 9236 9237根据检索选项删除自定义用户统计行为数据。使用Promise异步回调。 9238 9239**系统接口**:此接口为系统接口。 9240 9241**系统能力**: SystemCapability.FileManagement.PhotoAccessHelper.Core 9242 9243**参数:** 9244 9245| 参数名 | 类型 | 必填 | 说明 | 9246| --- | --- | --- | --- | 9247| optionCheck | [FetchOptions](js-apis-photoAccessHelper.md#fetchoptions) | 是 | 检索选项。 | 9248 9249**返回值:** 9250 9251| 类型 | 说明 | 9252| --- | --- | 9253| Promise<void> | Promise对象,无返回结果。 | 9254 9255**错误码:** 9256 9257以下错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)和[媒体库错误码](errcode-medialibrary.md)。 9258 9259| 错误码ID | 错误信息 | 9260| --- | --- | 9261| 202 | Called by non-system application. | 9262| 23800151 | Scenario parameters fail to pass the verification. Possible causes: 1. The fileter criteria or fetchColumns that are not supported by options are transferred | 9263| 23800301 | 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. | 9264 9265**示例:** 9266 9267```ts 9268import { dataSharePredicates } from '@kit.ArkData'; 9269import { BusinessError } from '@kit.BasicServicesKit'; 9270 9271async function example(context: Context) { 9272 console.info('removeCustomRecords'); 9273 let crManager = photoAccessHelper.PhotoAssetCustomRecordManager.getCustomRecordManagerInstance(context); 9274 let predicates: dataSharePredicates.DataSharePredicates = new dataSharePredicates.DataSharePredicates(); 9275 predicates.equalTo('file_id', 1); 9276 let fetchOption: photoAccessHelper.FetchOptions = { 9277 fetchColumns: [], 9278 predicates: predicates 9279 }; 9280 crManager.removeCustomRecords(fetchOption).then(() => { 9281 console.info('removeCustomRecords successful'); 9282 }).catch((err: BusinessError) => { 9283 console.error('removeCustomRecords fail with error: ${err.code}, ${err.message}'); 9284 }); 9285} 9286``` 9287 9288### addShareCount<sup>20+</sup> 9289 9290addShareCount(ids: Array<number>): Promise<Array<number>> 9291 9292根据[PhotoAssetCustomRecord](#photoassetcustomrecord20)中的fileId给数据库中对应数据的shareCount加1。使用Promise异步回调。 9293 9294**系统接口**:此接口为系统接口。 9295 9296**系统能力**: SystemCapability.FileManagement.PhotoAccessHelper.Core 9297 9298**参数:** 9299 9300| 参数名 | 类型 | 必填 | 说明 | 9301| --- | --- | --- | --- | 9302| ids | Array<number> | 是 | [PhotoAssetCustomRecord](#photoassetcustomrecord20)中的fileId集合。 | 9303 9304**返回值:** 9305 9306| 类型 | 说明 | 9307| --- | --- | 9308| Promise<Array<number>> | 更新失败的自定义用户统计行为数据中的fileId。 | 9309 9310**错误码:** 9311 9312以下错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)和[媒体库错误码](errcode-medialibrary.md)。 9313 9314| 错误码ID | 错误信息 | 9315| --- | --- | 9316| 202 | Called by non-system application. | 9317| 23800151 | Scenario parameters fail to pass the verification. Possible causes: 1. The ids list is empty; 2. The number of ids lists exceeds 500. | 9318| 23800301 | 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. | 9319 9320```ts 9321import { BusinessError } from '@kit.BasicServicesKit'; 9322 9323async function example(context: Context) { 9324 console.info('addShareCount'); 9325 let crManager = photoAccessHelper.PhotoAssetCustomRecordManager.getCustomRecordManagerInstance(context); 9326 let ids: Array<number> = [1, 2]; 9327 crManager.addShareCount(ids).then((failIds) => { 9328 console.info('addShareCount successful'); 9329 }).catch((err: BusinessError) => { 9330 console.error('addShareCount fail with error: ${err.code}, ${err.message}'); 9331 }); 9332} 9333``` 9334 9335### addLcdJumpCount<sup>20+</sup> 9336 9337addLcdJumpCount(ids: Array<number>): Promise<Array<number>> 9338 9339根据[PhotoAssetCustomRecord](#photoassetcustomrecord20)中的fileId给数据库中对应数据的LcdJumpCount加1。使用Promise异步回调。 9340 9341**系统接口**:此接口为系统接口。 9342 9343**系统能力**: SystemCapability.FileManagement.PhotoAccessHelper.Core 9344 9345**参数:** 9346 9347| 参数名 | 类型 | 必填 | 说明 | 9348| --- | --- | --- | --- | 9349| ids | Array<number> | 是 | [PhotoAssetCustomRecord](#photoassetcustomrecord20)中的fileId集合。 | 9350 9351**返回值:** 9352 9353| 类型 | 说明 | 9354| --- | --- | 9355| Promise<Array<number>> | 更新失败的自定义用户统计行为数据中的fileId。 | 9356 9357**错误码:** 9358 9359以下错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)和[媒体库错误码](errcode-medialibrary.md)。 9360 9361| 错误码ID | 错误信息 | 9362| --- | --- | 9363| 202 | Called by non-system application. | 9364| 23800151 | Scenario parameters fail to pass the verification. Possible causes: 1. The ids list is empty; 2. The number of ids lists exceeds 500. | 9365| 23800301 | 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. | 9366 9367```ts 9368import { BusinessError } from '@kit.BasicServicesKit'; 9369 9370async function example(context: Context) { 9371 console.info('addLcdJumpCount'); 9372 let crManager = photoAccessHelper.PhotoAssetCustomRecordManager.getCustomRecordManagerInstance(context); 9373 let ids: Array<number> = [1, 2]; 9374 crManager.addLcdJumpCount(ids).then((failIds) => { 9375 console.info('addLcdJumpCount successful'); 9376 }).catch((err: BusinessError) => { 9377 console.error('addLcdJumpCount fail with error: ${err.code}, ${err.message}'); 9378 }); 9379} 9380``` 9381 9382## PhotoSelectOptions 9383 9384图库选择选项子类,继承于BaseSelectOptions。用于拉起对应userId空间的picker。 9385 9386**系统能力**:SystemCapability.FileManagement.PhotoAccessHelper.Core 9387 9388| 参数名 | 类型 | 必填 | 说明 | 9389| -------- | -------- | -------- | -------- | 9390| userId<sup>18+</sup> | number | 否 | 指定访问空间的Id。默认值为-1。<br>当需要作为[PhotoViewPicker.select](arkts-apis-photoAccessHelper-PhotoViewPicker.md#select)的选择参数时,请申请ohos.permission.INTERACTA_CROSS_LOCAL_ACCOUNTS。<br>**系统接口**:此接口为系统接口。 | 9391 9392**示例:** 9393 9394```ts 9395 async function photoPicker() { 9396 let picker = new photoAccessHelper.PhotoViewPicker(); 9397 let option = new photoAccessHelper.PhotoSelectOptions(); 9398 option.userId = 101; 9399 picker.select(option); 9400 } 9401``` 9402 9403## PhotoSubtype 9404 9405枚举,不同[PhotoAsset](#photoasset)的类型。 9406 9407**系统能力**:SystemCapability.FileManagement.PhotoAccessHelper.Core 9408 9409| 名称 | 值 | 说明 | 9410| ----- | ---- | ---- | 9411| SCREENSHOT | 1 | 截屏录屏文件类型。<br>**系统接口**:此接口为系统接口。 | 9412 9413## AlbumType 9414 9415枚举,相册类型,表示是用户相册还是系统预置相册。 9416 9417**系统能力**:SystemCapability.FileManagement.PhotoAccessHelper.Core 9418 9419| 名称 | 值 | 说明 | 9420| ------------------- | ---- | ------------------------- | 9421| SOURCE<sup>18+</sup> | 2048 | 来源相册。<br>**系统接口**:此接口为系统接口。 | 9422| SMART<sup>11+</sup> | 4096 | 智慧分析相册。<br>**系统接口**:此接口为系统接口。 | 9423 9424## AlbumSubtype 9425 9426枚举,相册子类型,表示具体的相册类型。 9427 9428**系统能力**:SystemCapability.FileManagement.PhotoAccessHelper.Core 9429 9430| 名称 | 值 | 说明 | 9431| --------------------------------- | ---------- | ------------------------------- | 9432| HIDDEN | 1027 | 隐藏相册。**系统接口**:此接口为系统接口。 | 9433| TRASH | 1028 | 回收站。**系统接口**:此接口为系统接口。 | 9434| SCREENSHOT | 1029 | 截屏和录屏相册。**系统接口**:此接口为系统接口。 | 9435| CAMERA | 1030 | 相机拍摄的照片和视频相册。**系统接口**:此接口为系统接口。 | 9436| SOURCE\_GENERIC<sup>11+</sup> | 2049 | 来源相册。**系统接口**:此接口为系统接口。 | 9437| CLASSIFY<sup>11+</sup> | 4097 | 分类相册。**系统接口**:此接口为系统接口。 | 9438| GEOGRAPHY\_LOCATION<sup>11+</sup> | 4099 | 地图相册。**系统接口**:此接口为系统接口。 | 9439| GEOGRAPHY\_CITY<sup>11+</sup> | 4100 | 城市相册。**系统接口**:此接口为系统接口。 | 9440| SHOOTING\_MODE<sup>11+</sup> | 4101 | 拍摄模式相册。**系统接口**:此接口为系统接口。 | 9441| PORTRAIT<sup>11+</sup> | 4102 | 人像相册。**系统接口**:此接口为系统接口。 | 9442| GROUP_PHOTO<sup>13+</sup> | 4103 | 合影相册。**系统接口**:此接口为系统接口。 | 9443| HIGHLIGHT<sup>12+</sup> | 4104 | 时刻相册。**系统接口**:此接口为系统接口。 | 9444| HIGHLIGHT_SUGGESTIONS<sup>12+</sup> | 4105 | 时刻建议相册。**系统接口**:此接口为系统接口。 | 9445| CLOUD_ENHANCEMENT<sup>13+</sup> | 1032 | AI云增强相册。**系统接口**:此接口为系统接口。 | 9446 9447## RequestPhotoType<sup>11+</sup> 9448 9449枚举,获取图片或视频缩略图的操作类型。 9450 9451**系统接口**:此接口为系统接口。 9452 9453**系统能力**:SystemCapability.FileManagement.PhotoAccessHelper.Core 9454 9455| 名称 | 值 | 说明 | 9456| ----- | ---- | ---- | 9457| REQUEST_ALL_THUMBNAILS | 0 | 即获取快速缩略图,又获取质量缩略图。 | 9458| REQUEST_FAST_THUMBNAIL | 1 | 只获取快速缩略图。 | 9459| REQUEST_QUALITY_THUMBNAIL | 2 | 只获取质量缩略图。 | 9460 9461## PhotoKeys 9462 9463枚举,图片和视频文件关键信息。 9464 9465**系统能力**:SystemCapability.FileManagement.PhotoAccessHelper.Core 9466 9467| 名称 | 值 | 说明 | 9468| ------------- | ------------------- | ---------------------------------------------------------- | 9469| DATE_TRASHED | 'date_trashed' | 删除日期(删除文件时间距1970年1月1日的秒数值)。**系统接口**:此接口为系统接口。 | 9470| HIDDEN | 'hidden' | 文件的隐藏状态。**系统接口**:此接口为系统接口。 | 9471| CAMERA_SHOT_KEY | 'camera_shot_key' | 锁屏相机拍照或录像的标记字段(仅开放给系统相机,其key值由系统相机定义)。**系统接口**:此接口为系统接口。 | 9472| USER_COMMENT<sup>10+</sup> | 'user_comment' | 用户注释信息。**系统接口**:此接口为系统接口。 | 9473| DATE_YEAR<sup>11+</sup> | 'date_year' | 创建文件的年份。**系统接口**:此接口为系统接口。 | 9474| DATE_MONTH<sup>11+</sup> | 'date_month' | 创建文件的月份。**系统接口**:此接口为系统接口。 | 9475| DATE_DAY<sup>11+</sup> | 'date_day' | 创建文件的日期。**系统接口**:此接口为系统接口。 | 9476| PENDING<sup>11+</sup> | 'pending' | pending状态。**系统接口**:此接口为系统接口。 | 9477| DATE_TRASHED_MS<sup>12+</sup> | 'date_trashed_ms' | 删除日期(删除文件时间距1970年1月1日的毫秒数值)。**系统接口**:此接口为系统接口。<br>注意:查询照片时,不支持基于该字段排序。 | 9478| MOVING_PHOTO_EFFECT_MODE<sup>12+</sup> | 'moving_photo_effect_mode' | 动态照片效果模式。**系统接口**:此接口为系统接口。 | 9479| CE_AVAILABLE<sup>13+</sup> | 'ce_available' | 云增强任务标识。**系统接口**:此接口为系统接口。 | 9480| SUPPORTED_WATERMARK_TYPE<sup>14+</sup> | 'supported_watermark_type' | 水印可编辑标识。**系统接口**:此接口为系统接口。 | 9481| IS_CE_AUTO<sup>18+</sup> | 'is_auto' | 是否支持自动云增强。**系统接口**:此接口为系统接口。 | 9482| OWNER_ALBUM_ID<sup>18+</sup> | 'owner_album_id' | 照片所属的相册id。**系统接口**:此接口为系统接口。 | 9483| IS_RECENT_SHOW<sup>18+</sup> | 'is_recent_show' | 是否设置为最近显示。**系统接口**:此接口为系统接口。 | 9484| SUM_SIZE<sup>19+</sup> | 'sum(size)' | 文件大小总和。在fetchColumns中填入SUM_SIZE属性时,仅获取到第一个资产,并且属性中带有所有资产的总大小。**系统接口**:此接口为系统接口。 | 9485| EXIF_ROTATE<sup>20+</sup> | 'exif_rotate' | 文件的旋转角度信息。**系统接口**:此接口为系统接口。 | 9486 9487## AlbumKeys 9488 9489枚举,相册关键信息。 9490 9491**系统能力**:SystemCapability.FileManagement.PhotoAccessHelper.Core 9492 9493| 名称 | 值 | 说明 | 9494| --------------------------------- | -------------------- | ----------------------------------------------------- | 9495| ALBUM_LPATH<sup>18+</sup> | 'lpath' | 相册的虚拟路径。<br>**系统接口**:此接口为系统接口。 | 9496| BUNDLE_NAME<sup>18+</sup> | 'bundle_name' | 相册的包名。<br>**系统接口**:此接口为系统接口。 | 9497| DATE_MODIFIED<sup>18+</sup> | 'date_modified' | 相册修改的时间戳(单位:毫秒)。<br>**系统接口**:此接口为系统接口。 | 9498| COVER_URI_SOURCE<sup>20+</sup> | 'cover_uri_source' | 相册封面的来源。<br>**系统接口**:此接口为系统接口。 | 9499 9500## HiddenPhotosDisplayMode<sup>11+</sup> 9501 9502枚举,系统中隐藏文件显示模式。 9503 9504**系统接口**:此接口为系统接口。 9505 9506**系统能力**:SystemCapability.FileManagement.PhotoAccessHelper.Core 9507 9508| 名称 | 值 | 说明 | 9509| ------------- | ------------------- | ---------------------------------------------------------- | 9510| ASSETS_MODE | 0 | 按系统预置的隐藏相册显示隐藏文件,即显示系统中所有的隐藏文件。 | 9511| ALBUMS_MODE | 1 | 按相册显示隐藏文件(即显示系统中所有包含隐藏文件的相册,除系统预置的隐藏相册本身和回收站相册以外)。 | 9512 9513## PhotoCreateOptions 9514 9515图片或视频的创建选项。 9516 9517**系统接口**:此接口为系统接口。 9518 9519**系统能力**:SystemCapability.FileManagement.PhotoAccessHelper.Core 9520 9521| 名称 | 类型 | 必填 | 说明 | 9522| ---------------------- | ------------------- | ---- | ------------------------------------------------ | 9523| subtype | [PhotoSubtype](#photosubtype) | 否 | 图片或者视频的子类型。 | 9524| cameraShotKey | string | 否 | 锁屏相机拍照或录像的标记字段(仅开放给系统相机,其key值由系统相机定义)。 | 9525| userId<sup>19+</sup> | number | 否 | 用户id。 | 9526 9527## RequestPhotoOptions<sup>11+</sup> 9528 9529获取图片或视频缩略图的选项。 9530 9531**系统接口**:此接口为系统接口。 9532 9533**系统能力**:SystemCapability.FileManagement.PhotoAccessHelper.Core 9534 9535| 名称 | 类型 | 必填 | 说明 | 9536| ---------------------- | ------------------- | ---- | ------------------------------------------------ | 9537| size | [image.Size](../apis-image-kit/arkts-apis-image-i.md#size) | 否 | 获取缩略图的尺寸。 | 9538| requestPhotoType | [RequestPhotoType](#requestphototype11) | 否 | 获取的操作类型。 | 9539 9540## PhotoCreationSource<sup>18+</sup> 9541 9542代替应用创建资产传入的应用信息。 9543 9544**系统接口**:此接口为系统接口。 9545 9546**系统能力**:SystemCapability.FileManagement.PhotoAccessHelper.Core 9547 9548| 名称 | 类型 | 只读 | 可选 | 说明 | 9549| ---------------------- | ------------------- | ---- | ---- | ------------------------------------------------ | 9550| bundleName | string | 是 | 是 |需保存图片/视频文件的应用bundle name。 | 9551| appName | string | 是 | 是 |需保存图片/视频文件的app name。 | 9552| appId | string | 是 | 是 |需保存图片/视频文件的app id。 | 9553| tokenId | number | 是 | 是 |应用标识,将访问权限授予tokenId标识的应用。 | 9554 9555## RequestOptions<sup>11+</sup> 9556 9557请求策略。 9558 9559**系统能力**:SystemCapability.FileManagement.PhotoAccessHelper.Core 9560 9561| 名称 | 类型 | 可读 | 可写 | 说明 | 9562| ---------------------- |---------------------------------| ---- |---- | ------------------------------------------------ | 9563| sourceMode | [SourceMode](#sourcemode11) | 是 | 是 | 资源文件的读取类型,可以指定当前请求获取的是源文件,或是编辑后的文件。**系统接口**:此接口为系统接口。 | 9564 9565## PhotoProxy<sup>11+</sup> 9566 9567照片代理,相机应用通过该对象写入图片数据。 9568 9569**系统接口**:此接口为系统接口。 9570 9571**系统能力**:SystemCapability.FileManagement.PhotoAccessHelper.Core 9572 9573## MediaChangeRequest<sup>11+</sup> 9574 9575媒体变更请求,资产变更请求和相册变更请求的父类型。 9576 9577**注意**:媒体变更请求需要在调用[applyChanges](arkts-apis-photoAccessHelper-PhotoAccessHelper.md#applychanges11)后才会提交生效。 9578 9579**系统能力**:SystemCapability.FileManagement.PhotoAccessHelper.Core 9580 9581## FormInfo<sup>11+</sup> 9582 9583图库卡片相关信息。 9584 9585**系统接口**:此接口为系统接口。 9586 9587**系统能力**:SystemCapability.FileManagement.PhotoAccessHelper.Core 9588 9589| 名称 | 类型 | 必填 | 说明 | 9590| ---------------------- | ------------------- | ---- | ------------------------------------------------ | 9591|formId |string |是 | 卡片的ID,由图库创建卡片时提供。 | 9592|uri |string |是 | 卡片绑定的图片的uri。创建卡片时uri可为空或图片的uri,移除卡片时uri不做校验,传空即可。 | 9593 9594## GalleryFormInfo<sup>18+</sup> 9595 9596图库卡片相关信息。 9597 9598**系统接口**:此接口为系统接口。 9599 9600**系统能力**:SystemCapability.FileManagement.PhotoAccessHelper.Core 9601 9602| 名称 | 类型 | 必填 | 说明 | 9603| ---------------------- | ------------------- | ---- | ------------------------------------------------ | 9604|formId |string |是 | 卡片的ID,由图库创建卡片时提供。 | 9605|assetUris |Array<string> |是 | 卡片绑定的图片或相册的uri集合。<br>创建和更新卡片时,assetUris不可为空。<br>单次创建或更新卡片时,assetUris中的uri个数如果超出500个,则只创建或更新500个uri的监听,超出500个后的uri不会被注册。<br>移除卡片时,assetUris可省略。 | 9606 9607## ResourceType<sup>11+</sup> 9608 9609枚举,写入资源的类型。 9610 9611**系统能力**:SystemCapability.FileManagement.PhotoAccessHelper.Core 9612 9613| 名称 | 值 | 说明 | 9614| ----- | ---- | ---- | 9615| PHOTO_PROXY | 3 | 表示照片代理资源。**系统接口**:此接口为系统接口。 | 9616| PRIVATE_MOVING_PHOTO_RESOURCE<sup>13+</sup> | 4 | 表示私有动态照片资源。**系统接口**:此接口为系统接口。 | 9617| PRIVATE_MOVING_PHOTO_METADATA<sup>18+</sup> | 5 | 表示私有动态照片元数据资源。**系统接口**:此接口为系统接口。 | 9618 9619## DefaultChangeUri 9620 9621枚举,DefaultChangeUri子类型。 9622 9623**系统能力**:SystemCapability.FileManagement.PhotoAccessHelper.Core 9624 9625| 名称 | 值 | 说明 | 9626| ----------------- | ----------------------- | ------------------------------------------------------------ | 9627| DEFAULT_HIDDEN_ALBUM_URI<sup>11+</sup> | 'file://media/HiddenAlbum' | 隐藏相册-相册视图中相册的Uri,即系统中包含隐藏文件的相册(不包含系统预置隐藏相册和回收站相册)的Uri,仅用于隐藏相册-相册视图场景的通知。**系统接口**:此接口为系统接口。 | 9628 9629## SourceMode<sup>11+</sup> 9630 9631枚举,资源文件的读取类型。 9632 9633**系统接口**:此接口为系统接口。 9634 9635**系统能力**:SystemCapability.FileManagement.PhotoAccessHelper.Core 9636 9637| 名称 | 值 | 说明 | 9638| ----- | ---- | ---- | 9639| ORIGINAL_MODE | 0 | 读取源文件。 | 9640| EDITED_MODE | 1 | 读取编辑后的文件。| 9641## AuthorizationMode<sup>12+</sup> 9642 9643枚举,授权模式。 9644 9645**系统接口**:此接口为系统接口。 9646 9647**系统能力**:SystemCapability.FileManagement.PhotoAccessHelper.Core 9648 9649| 名称 | 值 | 说明 | 9650| ----- | ---- | ---- | 9651| SHORT_TIME_AUTHORIZATION| 0 | 短时授权。 | 9652 9653## AnalysisType<sup>11+</sup> 9654 9655枚举,智慧分析类型。 9656 9657**系统能力**:SystemCapability.FileManagement.PhotoAccessHelper.Core 9658 9659| 名称 | 值 | 说明 | 9660| :---------------------------- | :- | :------- | 9661| ANALYSIS\_AESTHETICS\_SCORE | 0 | 美学评分分析类别。**系统接口**:此接口为系统接口。 | 9662| ANALYSIS\_LABEL | 1 | 分类标签分析类别。**系统接口**:此接口为系统接口。 | 9663| ANALYSIS\_OCR | 2 | 文字识别分析类别。**系统接口**:此接口为系统接口。 | 9664| ANALYSIS\_FACE | 3 | 人脸检测分析类别。**系统接口**:此接口为系统接口。 | 9665| ANALYSIS\_OBJECT | 4 | 目标检测分析类别。**系统接口**:此接口为系统接口。 | 9666| ANALYSIS\_RECOMMENDATION | 5 | 推荐构图分析类别。**系统接口**:此接口为系统接口。 | 9667| ANALYSIS\_SEGMENTATION | 6 | 抠图分析类别。**系统接口**:此接口为系统接口。 | 9668| ANALYSIS\_COMPOSITION | 7 | 美学构图分析类别。**系统接口**:此接口为系统接口。 | 9669| ANALYSIS\_SALIENCY | 8 | 最佳呈现主体中心分析类别。**系统接口**:此接口为系统接口。 | 9670| ANALYSIS\_DETAIL\_ADDRESS | 9 | 详细地址分析类别。**系统接口**:此接口为系统接口。 | 9671| ANALYSIS\_HUMAN\_FACE\_TAG<sup>12+</sup> | 10 | 人像聚类信息分析类别。**系统接口**:此接口为系统接口。 | 9672| ANALYSIS\_HEAD\_POSITION<sup>12+</sup> | 11 | 人头、宠物头位置分析类别。**系统接口**:此接口为系统接口。 | 9673| ANALYSIS\_BONE\_POSE<sup>12+</sup> | 12 | 人体骨骼点信息分析类别。**系统接口**:此接口为系统接口。 | 9674| ANALYSIS\_VIDEO\_LABEL<sup>12+</sup> | 13 | 视频标签。**系统接口**:此接口为系统接口。 | 9675| ANALYSIS\_HIGHLIGHT<sup>12+</sup> | 14 | 时刻标签。**系统接口**:此接口为系统接口。 | 9676 9677## HighlightAlbumInfoType<sup>12+</sup> 9678 9679枚举,时刻相册信息类型。 9680 9681**系统接口**:此接口为系统接口。 9682 9683**系统能力**:SystemCapability.FileManagement.PhotoAccessHelper.Core 9684 9685| 名称 | 值 | 说明 | 9686| :------------ | :- | :------- | 9687| COVER\_INFO | 0 | 封面信息类别。 | 9688| PLAY\_INFO | 1 | 音乐信息类别。 | 9689 9690## HighlightUserActionType<sup>12+</sup> 9691 9692枚举,时刻用户行为类型。 9693 9694**系统接口**:此接口为系统接口。 9695 9696**系统能力**:SystemCapability.FileManagement.PhotoAccessHelper.Core 9697 9698| 名称 | 值 | 说明 | 9699| :---------------------------- | :- | :------- | 9700| INSERTED\_PIC\_COUNT | 0 | 新增图片数量类别。 | 9701| REMOVED\_PIC\_COUNT | 1 | 移除图片数量类别。 | 9702| SHARED\_SCREENSHOT\_COUNT | 2 | 分享二级界面长图次数类别。 | 9703| SHARED\_COVER\_COUNT | 3 | 分享时刻封面次数类别。 | 9704| RENAMED\_COUNT | 4 | 重命名次数类别。 | 9705| CHANGED\_COVER\_COUNT | 5 | 修改封面次数类别。 | 9706| RENDER\_VIEWED\_TIMES | 100 | 轮播观看次数类别。 | 9707| RENDER\_VIEWED\_DURATION | 101 | 轮播观看总时长类别。 | 9708| ART\_LAYOUT\_VIEWED\_TIMES | 102 | 二级界面观看次数类别。 | 9709| ART\_LAYOUT\_VIEWED\_DURATION | 103 | 二级界面观看总时长类别。 | 9710 9711## ThumbnailVisibility<sup>14+</sup> 9712 9713枚举,缩略图是否可访问。 9714 9715**系统接口**:此接口为系统接口。 9716 9717**系统能力**:SystemCapability.FileManagement.PhotoAccessHelper.Core 9718 9719| 名称 | 值 | 说明 | 9720| :---------------------------- | :- | :------- | 9721| INVISIBLE | 0 | 缩略图不可访问。 | 9722| VISIBLE | 1 | 缩略图可访问。 | 9723 9724## MovingPhotoEffectMode<sup>12+</sup> 9725 9726枚举,动态照片效果模式。 9727 9728**系统接口**:此接口为系统接口。 9729 9730**系统能力**:SystemCapability.FileManagement.PhotoAccessHelper.Core 9731 9732| 名称 | 值 | 说明 | 9733| :---------------------------- | :- | :------- | 9734| DEFAULT | 0 | 默认模式。| 9735| BOUNCE\_PLAY | 1 | 来回播放。| 9736| LOOP\_PLAY | 2 | 循环播放。| 9737| LONG\_EXPOSURE | 3 | 长曝光。 | 9738| MULTI\_EXPOSURE | 4 | 多曝光。 | 9739| CINEMA\_GRAPH<sup>13+</sup> | 5 | 微动瞬间。 | 9740| IMAGE\_ONLY<sup>13+</sup> | 10 | 关闭模式。 | 9741 9742## PhotoPermissionType<sup>12+</sup> 9743 9744枚举,应用对媒体资源不同访问权限的类型。 9745 9746包括临时读权限和永久读权限,临时读权限会随着应用的死亡而删除,永久读权限不会。 9747 9748同一个应用对同一个媒体资源的权限覆盖规则:永久读会覆盖临时读,而临时读不会覆盖永久读。 9749 9750**系统接口**:此接口为系统接口。 9751 9752**系统能力**:SystemCapability.FileManagement.PhotoAccessHelper.Core 9753 9754| 名称 | 值 | 说明 | 9755| ----- | ---- | ---- | 9756| TEMPORARY_READ_IMAGEVIDEO | 0 | 临时读权限类型。 | 9757| PERSISTENT_READ_IMAGEVIDEO | 1 | 永久读权限类型。 | 9758 9759## HideSensitiveType<sup>12+</sup> 9760 9761枚举,应用访问媒体资源时,对媒体资源进行信息脱敏的类型。 9762 9763**系统接口**:此接口为系统接口。 9764 9765**系统能力**:SystemCapability.FileManagement.PhotoAccessHelper.Core 9766 9767| 名称 | 值 | 说明 | 9768| ----- | ---- | ---- | 9769| HIDE_LOCATION_AND_SHOOTING_PARAM | 0 | 脱敏地理位置和拍摄参数。 | 9770| HIDE_LOCATION_ONLY | 1 | 脱敏地理位置信息。 | 9771| HIDE_SHOOTING_PARAM_ONLY | 2 | 脱敏拍摄参数。 | 9772| NO_HIDE_SENSITIVE_TYPE | 3 | 不脱敏。 | 9773 9774## CloudEnhancementTaskStage<sup>13+</sup> 9775 9776枚举,应用查询云增强任务状态时,在[CloudEnhancementTaskState](#cloudenhancement13)接口中返回,表示云增强任务状态。 9777 9778**系统接口**:此接口为系统接口。 9779 9780**系统能力**:SystemCapability.FileManagement.PhotoAccessHelper.Core 9781 9782| 名称 | 值 | 说明 | 9783| ----- | ---- | ---- | 9784| TASK_STAGE_EXCEPTION | -1 | 云增强任务异常。 | 9785| TASK_STAGE_PREPARING | 0 | 云增强任务准备中。 | 9786| TASK_STAGE_UPLOADING | 1 | 云增强任务上传中。 | 9787| TASK_STAGE_EXECUTING | 2 | 云增强任务执行中。 | 9788| TASK_STAGE_DOWNLOADING | 3 | 云增强任务下载中。 | 9789| TASK_STAGE_FAILED | 4 | 云增强任务失败。 | 9790| TASK_STAGE_COMPLETED | 5 | 云增强任务已完成。 | 9791 9792## CloudEnhancementState<sup>13+</sup> 9793 9794枚举,表示云增强状态。 9795 9796**系统接口**:此接口为系统接口。 9797 9798**系统能力**:SystemCapability.FileManagement.PhotoAccessHelper.Core 9799 9800| 名称 | 值 | 说明 | 9801| ----- | ---- | ---- | 9802| UNAVAILABLE | 0 | 云增强不可用。 | 9803| AVAILABLE | 1 | 云增强可用。 | 9804| EXECUTING | 2 | 云增强执行中。 | 9805| COMPLETED | 3 | 云增强已完成。 | 9806 9807## CloudEnhancementTaskState<sup>13+</sup> 9808 9809云增强任务状态,应用调用调用云增强任务查询接口的返回类型,包含云增强任务状态及部分状态下的额外信息。 9810 9811**系统接口**:此接口为系统接口。 9812 9813**系统能力**:SystemCapability.FileManagement.PhotoAccessHelper.Core 9814 9815| 名称 | 类型 | 必定提供 | 说明 | 9816| ---------------------- | ------------------- | ---- | ------------------------------------------------ | 9817|taskStage |[CloudEnhancementTaskStage](#cloudenhancementtaskstage13) |是 | 云增强任务状态。 | 9818|transferredFileSize |number |否 | 已传输的文件大小。当taskStage为CloudEnhancementTaskStage.TASK_STAGE_UPLOADING或者CloudEnhancementTaskStage.TASK_STAGE_DOWNLOADING时提供。 | 9819|totalFileSize |number |否 | 总文件大小。当taskStage为CloudEnhancementTaskStage.TASK_STAGE_UPLOADING或者CloudEnhancementTaskStage.TASK_STAGE_DOWNLOADING时提供。 | 9820|expectedDuration |number |否 | 排队时间。当taskStage为CloudEnhancementTaskStage.TASK_STAGE_EXECUTING时提供。 | 9821|statusCode |number |否 | 状态码。当taskStage为CloudEnhancementTaskStage.TASK_STAGE_FAILED时提供。 | 9822 9823## VideoEnhancementType<sup>13+</sup> 9824 9825枚举,分段式视频的二段式触发类型。 9826 9827**系统接口**:此接口为系统接口。 9828 9829**系统能力**:SystemCapability.FileManagement.PhotoAccessHelper.Core 9830 9831| 名称 | 值 | 说明 | 9832| ----- | ---- | ---- | 9833| QUALITY_ENHANCEMENT_LOCAL | 0 | 在端侧增强处理。 | 9834| QUALITY_ENHANCEMENT_CLOUD | 1 | 在云侧增强处理。 | 9835| QUALITY_ENHANCEMENT_LOCAL_AND_CLOUD | 2 | 在端侧和云侧同时增强处理。 | 9836 9837## ThumbnailType<sup>13+</sup> 9838 9839枚举,缩略图类型。 9840 9841**系统接口**:此接口为系统接口。 9842 9843**系统能力**:SystemCapability.FileManagement.PhotoAccessHelper.Core 9844 9845| 名称 | 值 | 说明 | 9846| :---------------------------- | :- | :------- | 9847| LCD | 1 | 获取LCD缩略图 | 9848| THM | 2 | 获取THM缩略图 | 9849 9850## WatermarkType<sup>14+</sup> 9851 9852枚举,水印可编辑标识。 9853 9854**系统接口**:此接口为系统接口。 9855 9856**系统能力**:SystemCapability.FileManagement.PhotoAccessHelper.Core 9857 9858| 名称 | 值 | 说明 | 9859| ----- | ---- | ---- | 9860| DEFAULT | 0 | 不支持水印可编辑。 | 9861| BRAND_COMMON | 1 | 支持品牌和通用水印可编辑。 | 9862| COMMON | 2 | 支持通用水印可编辑。 | 9863| BRAND | 3 | 支持品牌水印可编辑。 | 9864 9865## CloudMediaDownloadType<sup>14+</sup> 9866 9867枚举,表示云端媒体资产的下载方式。 9868 9869**系统接口**:此接口为系统接口。 9870 9871**系统能力**:SystemCapability.FileManagement.PhotoAccessHelper.Core 9872 9873| 名称 | 值 | 说明 | 9874| ----- | ---- | ---- | 9875| DOWNLOAD_FORCE | 0 | 高优先级下载,无需进入息屏充电模式。 | 9876| DOWNLOAD_GENTLE | 1 | 低优先级下载,需要进入息屏充电模式。 | 9877 9878## CloudMediaRetainType<sup>14+</sup> 9879 9880枚举,表示云端媒体资产的删除方式。 9881 9882**系统接口**:此接口为系统接口。 9883 9884**系统能力**:SystemCapability.FileManagement.PhotoAccessHelper.Core 9885 9886| 名称 | 值 | 说明 | 9887| ----- | ---- | ---- | 9888| RETAIN_FORCE | 0 | 删除原文件在云端的本地元数据和缩略图。 | 9889 9890## CloudMediaAssetTaskStatus<sup>14+</sup> 9891 9892枚举,表示云端媒体资产的下载任务状态。 9893 9894**系统接口**:此接口为系统接口。 9895 9896**系统能力**:SystemCapability.FileManagement.PhotoAccessHelper.Core 9897 9898| 名称 | 值 | 说明 | 9899| ----- | ---- | ---- | 9900| DOWNLOADING | 0 | 当前任务下载中。 | 9901| PAUSED | 1 | 当前任务已暂停。 | 9902| IDLE | 2 | 当前无下载任务。 | 9903 9904## CloudMediaTaskPauseCause<sup>14+</sup> 9905 9906枚举,表示云端媒体资产下载任务暂停的类型。 9907 9908**系统接口**:此接口为系统接口。 9909 9910**系统能力**:SystemCapability.FileManagement.PhotoAccessHelper.Core 9911 9912| 名称 | 值 | 说明 | 9913| ----- | ---- | ---- | 9914| NO_PAUSE | 0 | 正常下载,无暂停。 | 9915| TEMPERATURE_LIMIT | 1 | 温度过高。 | 9916| ROM_LIMIT | 2 | 本地磁盘空间不足。 | 9917| NETWORK_FLOW_LIMIT | 3 | 流量使用有限制,且没有Wi-Fi。 | 9918| WIFI_UNAVAILABLE | 4 | 网络异常。 | 9919| POWER_LIMIT | 5 | 功耗限制。 | 9920| BACKGROUND_TASK_UNAVAILABLE | 6 | 充电息屏未启动。 | 9921| FREQUENT_USER_REQUESTS | 7 | 用户请求频繁。 | 9922| CLOUD_ERROR | 8 | 端云错误。 | 9923| USER_PAUSED | 9 | 用户暂停。 | 9924 9925## CloudMediaAssetStatus<sup>14+</sup> 9926 9927云端媒体资产下载任务的详细信息,应用调用云端资产下载任务查询接口的返回类型。 9928 9929**系统接口**:此接口为系统接口。 9930 9931**系统能力**:SystemCapability.FileManagement.PhotoAccessHelper.Core 9932 9933| 名称 | 类型 | 必定提供 | 说明 | 9934| ---------------------- | ------------------- | ---- | ------------------------------------------------ | 9935|taskStatus |[CloudMediaAssetTaskStatus](#cloudmediaassettaskstatus14) |是 | 云端媒体资产下载任务状态。 | 9936|taskInfo |string |是 | 下载资产的总个数和总大小(byte),以及未下载的总个数和总大小(byte)。 | 9937|errorCode |[CloudMediaTaskPauseCause](#cloudmediataskpausecause14) |是 | 云端媒体资产下载任务暂停类型。 | 9938 9939## RecommendationType<sup>11+</sup> 9940 9941枚举,推荐的图片类型。 9942 9943**系统能力**:SystemCapability.FileManagement.PhotoAccessHelper.Core 9944 9945| 名称 | 值 | 说明 | 9946| ----- | ---- | ---- | 9947| COLOR_STYLE_PHOTO<sup>18+</sup> | 12 | 推荐风格 **系统接口**:此接口为系统接口。| 9948 9949## ThumbnailChangeStatus<sup>20+</sup> 9950 9951枚举,表示缩略图(包括图片/视频)更新的状态。 9952 9953**系统接口**:此接口为系统接口。 9954 9955**系统能力**:SystemCapability.FileManagement.PhotoAccessHelper.Core 9956 9957| 名称 | 值 | 说明 | 9958| ------------------------- | ---- | -------------------------------- | 9959| THUMBNAIL_NOT_EXISTS | 0 | 缩略图不存在。 | 9960| THUMBNAIL_ADD | 1 | 缩略图已重新创建。 | 9961| THUMBNAIL_UPDATE | 2 | 缩略图已更新。 | 9962| THUMBNAIL_NOT_CHANGE | 3 | 缩略图没有变化。 | 9963 9964## StrongAssociationType<sup>20+</sup> 9965 9966枚举,表示图片的强关联类型。 9967 9968**系统接口**:此接口为系统接口。 9969 9970**系统能力**:SystemCapability.FileManagement.PhotoAccessHelper.Core 9971 9972| 名称 | 值 | 说明 | 9973| ------------------------- | ---- | -------------------------------- | 9974| NORMAL | 0 | 普通图片类型。 | 9975| CLOUD_ENHANCEMENT | 1 | 云增强图片类型。 | 9976 9977## PhotoAssetChangeInfo<sup>20+</sup> 9978 9979媒体资产(图片/视频)信息。 9980 9981**系统能力**:SystemCapability.FileManagement.PhotoAccessHelper.Core 9982 9983| 名称 | 类型 | 只读 | 可选 | 说明 | 9984| ---- | ------- | ---- | ---- | ----- | 9985| fileId | number | 否 | 否 | 媒体资产(图片/视频)的id。<br>**系统接口**:此接口为系统接口。 | 9986| dateDay | string | 否 | 否 | 创建媒体文件的日期。<br>**系统接口**:此接口为系统接口。 | 9987| isFavorite | boolean | 否 | 否 | 表示媒体资产(图片/视频)的收藏状态。true表示资产已收藏,false表示资产未收藏。<br>**系统接口**:此接口为系统接口。 | 9988| isHidden | boolean | 否 | 否 | 表示媒体资产(图片/视频)的隐藏状态。true表示资产已隐藏,false表示资产未隐藏。<br>**系统接口**:此接口为系统接口。 | 9989| strongAssociation | [StrongAssociationType](#strongassociationtype20) | 否 | 否 | 图片的强关联类型。<br>**系统接口**:此接口为系统接口。 | 9990| thumbnailVisible | [ThumbnailVisibility](#thumbnailvisibility14) | 否 | 否 | 缩略图的可访问性。<br>**系统接口**:此接口为系统接口。 | 9991| dateTrashedMs |number |否 | 否 | 文件删除时的Unix时间戳(单位:毫秒)。<br>**系统接口**:此接口为系统接口。 | 9992| dateAddedMs | number | 否 | 否 | 文件创建时的Unix时间戳(单位:毫秒)。<br>**系统接口**:此接口为系统接口。 | 9993| dateTakenMs | number | 否 | 否 | 文件拍摄时的Unix时间戳(单位:毫秒)。<br>**系统接口**:此接口为系统接口。 | 9994| position | [PositionType](arkts-apis-photoAccessHelper-e.md#positiontype16) | 否 | 是 | 媒体资产(图片/视频)的所在位置。<br>**系统接口**:此接口为系统接口。 | 9995| displayName | string | 否 | 是 | 媒体资产(图片/视频)的显示名称。<br>**系统接口**:此接口为系统接口。 | 9996| size | number | 否 | 是 | 媒体资产(图片/视频)的文件大小(单位:字节)。动态照片的size包括图片和视频的总大小。<br>**系统接口**:此接口为系统接口。 | 9997 9998## PhotoAssetChangeData<sup>20+</sup> 9999 10000媒体资产(图片/视频)的具体变更数据。 10001 10002**系统能力**:SystemCapability.FileManagement.PhotoAccessHelper.Core 10003 10004| 名称 | 类型 | 只读 | 可选 | 说明 | 10005| ---- | ------- | ---- | ---- | ----- | 10006| thumbnailChangeStatus | [ThumbnailChangeStatus](#thumbnailchangestatus20) | 否 | 否 | 缩略图(图片/视频)更新的状态。<br>**系统接口**:此接口为系统接口。 | 10007| version | number | 否 | 否 | 媒体资产(图片/视频)信息通知的版本号,用于确定通知的顺序。<br>**系统接口**:此接口为系统接口。 | 10008 10009## AlbumChangeInfo<sup>20+</sup> 10010 10011相册信息。 10012 10013**系统能力**:SystemCapability.FileManagement.PhotoAccessHelper.Core 10014 10015| 名称 | 类型 | 只读 | 可选 | 说明 | 10016| ---- | ------- | ---- | ---- | ----- | 10017| hiddenCount | number | 否 | 否 | 相册中的隐藏资产数量。<br>**系统接口**:此接口为系统接口。 | 10018| hiddenCoverUri | string | 否 | 否 | 相册中隐藏封面资产的uri。<br>**系统接口**:此接口为系统接口。 | 10019| isCoverChanged | boolean | 否 | 否 | 相册封面文件内容是否变化。true表示封面文件内容发生变化,false表示封面文件内容未发生变化。<br>**系统接口**:此接口为系统接口。 | 10020| isHiddenCoverChanged | boolean | 否 | 否 | 相册隐藏封面文件内容是否变化。true表示隐藏封面文件内容发生变化,false表示隐藏封面文件内容未发生变化。<br>**系统接口**:此接口为系统接口。 | 10021| coverInfo | [PhotoAssetChangeInfo](#photoassetchangeinfo20) | 否 | 是 | 相册封面资产的信息。<br>**系统接口**:此接口为系统接口。 | 10022| hiddenCoverInfo | [PhotoAssetChangeInfo](#photoassetchangeinfo20) | 否 | 是 | 相册隐藏封面资产的信息。<br>**系统接口**:此接口为系统接口。 | 10023| orderSection | number | 否 | 是 | 相册的排序区域,用于确认相册在图库中的展示区域。<br>**系统接口**:此接口为系统接口。 | 10024| albumOrder | number | 否 | 是 | 相册的排序值。<br>**系统接口**:此接口为系统接口。 | 10025 10026## AlbumChangeData<sup>20+</sup> 10027 10028相册的具体变更数据。 10029 10030**系统能力**:SystemCapability.FileManagement.PhotoAccessHelper.Core 10031 10032| 名称 | 类型 | 只读 | 可选 | 说明 | 10033| ---- | ------- | ---- | ---- | ----- | 10034| version | number | 否 | 否 | 相册信息通知的版本号,用于确定通知的顺序。<br>**系统接口**:此接口为系统接口。 | 10035 10036## PhotoAssetCustomRecord<sup>20+</sup> 10037 10038媒体库支持图库自定义用户统计行为。 10039 10040**系统接口**:此接口为系统接口。 10041 10042**系统能力**:SystemCapability.FileManagement.PhotoAccessHelper.Core 10043 10044| 名称 | 类型 | 只读 | 可选 | 说明 | 10045| --- | --- | --- | --- | --- | 10046| fileId | number | 是 | 否 | 图片id,必须为大于0的整数。 | 10047| shareCount | number | 是 | 否 | 图片和视频被分享的次数,必须为大于0的整数。 | 10048| lcdJumpCount | number | 是 | 否 | 大图跳转分享等次数,必须为大于0的整数。 | 10049 10050## CoverUriSource<sup>20+</sup> 10051 10052枚举,表示相册封面的来源。 10053 10054**系统接口**:此接口为系统接口。 10055 10056**系统能力**:SystemCapability.FileManagement.PhotoAccessHelper.Core 10057 10058| 名称 | 值 | 说明 | 10059| ------------------------- | ---- | -------------------------------- | 10060| DEFAULT_COVER | 0 | 默认封面。 | 10061| MANUAL_COVER | 1 | 手动设置的封面。 | 10062 10063## AlbumOrder<sup>20+</sup> 10064 10065相册排序信息。 10066 10067### 属性 10068 10069**系统接口**:此接口为系统接口。 10070 10071**系统能力**:SystemCapability.FileManagement.PhotoAccessHelper.Core 10072 10073| 名称 | 类型 | 只读 | 可选 | 说明 | 10074| ------------ | ------ | ---- | ---- | ------- | 10075| albumId | number | 否 | 否 | 相册ID。 | 10076| albumOrder | number | 否 | 否 | 相册排序值。 | 10077| orderSection | number | 否 | 否 | 相册排序区域。| 10078| orderType | number | 否 | 否 | 相册排序类型。| 10079| orderStatus | number | 否 | 否 | 相册排序状态。|