1# @ohos.file.photoAccessHelper (相册管理模块)(系统接口) 2 3该模块提供相册管理模块能力,包括创建相册以及访问、修改相册中的媒体数据信息等。 4 5> **说明:** 6> 7> - 本模块首批接口从API version 10开始支持。后续版本的新增接口,采用上角标单独标记接口的起始版本。 8> - 当前页面仅包含本模块的系统接口,其他公开接口参见[@ohos.file.photoAccessHelper (相册管理模块)](js-apis-photoAccessHelper.md)。 9 10## 导入模块 11 12```ts 13import { photoAccessHelper } from '@kit.MediaLibraryKit'; 14``` 15 16## PhotoAccessHelper 17 18### createAsset 19 20createAsset(displayName: string, callback: AsyncCallback<PhotoAsset>): void 21 22指定待创建的图片或者视频的文件名,创建图片或视频资源,使用callback方式返回结果。 23 24待创建的文件名参数规格为: 25- 应包含有效文件主名和图片或视频扩展名。 26- 文件名字符串长度为1~255。 27- 文件主名中不允许出现的非法英文字符,包括:<br> . .. \ / : * ? " ' ` < > | { } [ ] 28 29**系统接口**:此接口为系统接口。 30 31**系统能力**:SystemCapability.FileManagement.PhotoAccessHelper.Core 32 33**需要权限**:ohos.permission.WRITE_IMAGEVIDEO 34 35**参数:** 36 37| 参数名 | 类型 | 必填 | 说明 | 38| -------- | ------------------------ | ---- | ------------------------- | 39| displayName | string | 是 | 创建的图片或者视频文件名。 | 40| callback | AsyncCallback<[PhotoAsset](#photoasset)> | 是 | callback返回创建的图片和视频结果。 | 41 42**错误码:** 43 44接口抛出错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)和[文件管理错误码](../apis-core-file-kit/errorcode-filemanagement.md)。 45 46| 错误码ID | 错误信息 | 47| -------- | ---------------------------------------- | 48| 202 | Called by non-system application. | 49| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types; 3. Parameter verification failed. | 50| 13900012 | Permission denied. | 51| 13900020 | Invalid argument. | 52| 14000001 | Invalid display name. | 53| 14000011 | System inner fail. | 54 55**示例:** 56 57```ts 58async function example() { 59 console.info('createAssetDemo'); 60 let testFileName: string = 'testFile' + Date.now() + '.jpg'; 61 phAccessHelper.createAsset(testFileName, (err, photoAsset) => { 62 if (photoAsset !== undefined) { 63 console.info('createAsset file displayName' + photoAsset.displayName); 64 console.info('createAsset successfully'); 65 } else { 66 console.error(`createAsset failed, error: ${err.code}, ${err.message}`); 67 } 68 }); 69} 70``` 71 72### createAsset 73 74createAsset(displayName: string): Promise<PhotoAsset> 75 76指定待创建的图片或者视频的文件名,创建图片或视频资源,使用Promise方式返回结果。 77 78待创建的文件名参数规格为: 79- 应包含有效文件主名和图片或视频扩展名。 80- 文件名字符串长度为1~255。 81- 文件主名中不允许出现的非法英文字符,包括:<br> . .. \ / : * ? " ' ` < > | { } [ ] 82 83**系统接口**:此接口为系统接口。 84 85**系统能力**:SystemCapability.FileManagement.PhotoAccessHelper.Core 86 87**需要权限**:ohos.permission.WRITE_IMAGEVIDEO 88 89**参数:** 90 91| 参数名 | 类型 | 必填 | 说明 | 92| -------- | ------------------------ | ---- | ------------------------- | 93| displayName | string | 是 | 创建的图片或者视频文件名。 | 94 95**返回值:** 96 97| 类型 | 说明 | 98| --------------------------- | -------------- | 99| Promise<[PhotoAsset](#photoasset)> | Promise对象,返回创建的图片和视频结果。 | 100 101**错误码:** 102 103接口抛出错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)和[文件管理错误码](../apis-core-file-kit/errorcode-filemanagement.md)。 104 105| 错误码ID | 错误信息 | 106| -------- | ---------------------------------------- | 107| 202 | Called by non-system application. | 108| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types; 3. Parameter verification failed. | 109| 13900012 | Permission denied. | 110| 13900020 | Invalid argument. | 111| 14000001 | Invalid display name. | 112| 14000011 | System inner fail. | 113 114**示例:** 115 116```ts 117async function example() { 118 console.info('createAssetDemo'); 119 try { 120 let testFileName: string = 'testFile' + Date.now() + '.jpg'; 121 let photoAsset: photoAccessHelper.PhotoAsset = await phAccessHelper.createAsset(testFileName); 122 console.info('createAsset file displayName' + photoAsset.displayName); 123 console.info('createAsset successfully'); 124 } catch (err) { 125 console.error(`createAsset failed, error: ${err.code}, ${err.message}`); 126 } 127} 128``` 129 130### createAsset 131 132createAsset(displayName: string, options: PhotoCreateOptions, callback: AsyncCallback<PhotoAsset>): void 133 134指定待创建的图片或者视频的文件名和创建选项,创建图片或视频资源,使用callback方式返回结果。 135 136待创建的文件名参数规格为: 137- 应包含有效文件主名和图片或视频扩展名。 138- 文件名字符串长度为1~255。 139- 文件主名中不允许出现的非法英文字符,包括:<br> . .. \ / : * ? " ' ` < > | { } [ ] 140 141**系统接口**:此接口为系统接口。 142 143**系统能力**:SystemCapability.FileManagement.PhotoAccessHelper.Core 144 145**需要权限**:ohos.permission.WRITE_IMAGEVIDEO 146 147**参数:** 148 149| 参数名 | 类型 | 必填 | 说明 | 150| -------- | ------------------------ | ---- | ------------------------- | 151| displayName | string | 是 | 创建的图片或者视频文件名。 | 152| options | [PhotoCreateOptions](#photocreateoptions) | 是 | 图片或视频的创建选项。 | 153| callback | AsyncCallback<[PhotoAsset](#photoasset)> | 是 | callback返回创建的图片和视频结果。 | 154 155**错误码:** 156 157接口抛出错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)和[文件管理错误码](../apis-core-file-kit/errorcode-filemanagement.md)。 158 159| 错误码ID | 错误信息 | 160| -------- | ---------------------------------------- | 161| 202 | Called by non-system application. | 162| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types; 3. Parameter verification failed. | 163| 13900012 | Permission denied. | 164| 13900020 | Invalid argument. | 165| 14000001 | Invalid display name. | 166| 14000011 | System inner fail. | 167 168**示例:** 169 170```ts 171async function example() { 172 console.info('createAssetDemo'); 173 let testFileName: string = 'testFile' + Date.now() + '.jpg'; 174 let createOption: photoAccessHelper.PhotoCreateOptions = { 175 subtype: photoAccessHelper.PhotoSubtype.DEFAULT 176 } 177 phAccessHelper.createAsset(testFileName, createOption, (err, photoAsset) => { 178 if (photoAsset !== undefined) { 179 console.info('createAsset file displayName' + photoAsset.displayName); 180 console.info('createAsset successfully'); 181 } else { 182 console.error(`createAsset failed, error: ${err.code}, ${err.message}`); 183 } 184 }); 185} 186``` 187 188### createAsset 189 190createAsset(displayName: string, options: PhotoCreateOptions): Promise<PhotoAsset> 191 192指定待创建的图片或者视频的文件名和创建选项,创建图片或视频资源,使用Promise方式返回结果。 193 194待创建的文件名参数规格为: 195- 应包含有效文件主名和图片或视频扩展名。 196- 文件名字符串长度为1~255。 197- 文件主名中不允许出现的非法英文字符,包括:<br> . .. \ / : * ? " ' ` < > | { } [ ] 198 199**系统接口**:此接口为系统接口。 200 201**系统能力**:SystemCapability.FileManagement.PhotoAccessHelper.Core 202 203**需要权限**:ohos.permission.WRITE_IMAGEVIDEO 204 205**参数:** 206 207| 参数名 | 类型 | 必填 | 说明 | 208| -------- | ------------------------ | ---- | ------------------------- | 209| displayName | string | 是 | 创建的图片或者视频文件名。 | 210| options | [PhotoCreateOptions](#photocreateoptions) | 是 | 图片或视频的创建选项。 | 211 212**返回值:** 213 214| 类型 | 说明 | 215| --------------------------- | -------------- | 216| Promise<[PhotoAsset](#photoasset)> | Promise对象,返回创建的图片和视频结果。 | 217 218**错误码:** 219 220接口抛出错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)和[文件管理错误码](../apis-core-file-kit/errorcode-filemanagement.md)。 221 222| 错误码ID | 错误信息 | 223| -------- | ---------------------------------------- | 224| 202 | Called by non-system application. | 225| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types; 3. Parameter verification failed. | 226| 13900012 | Permission denied. | 227| 13900020 | Invalid argument. | 228| 14000001 | Invalid display name. | 229| 14000011 | System inner fail. | 230 231**示例:** 232 233```ts 234async function example() { 235 console.info('createAssetDemo'); 236 try { 237 let testFileName:string = 'testFile' + Date.now() + '.jpg'; 238 let createOption: photoAccessHelper.PhotoCreateOptions = { 239 subtype: photoAccessHelper.PhotoSubtype.DEFAULT 240 } 241 let photoAsset: photoAccessHelper.PhotoAsset = await phAccessHelper.createAsset(testFileName, createOption); 242 console.info('createAsset file displayName' + photoAsset.displayName); 243 console.info('createAsset successfully'); 244 } catch (err) { 245 console.error(`createAsset failed, error: ${err.code}, ${err.message}`); 246 } 247} 248``` 249 250### createAlbum<sup>(deprecated)</sup> 251 252createAlbum(name: string, callback: AsyncCallback<Album>): void 253 254创建相册,使用callback方式返回结果。 255 256待创建的相册名参数规格为: 257- 相册名字符串长度为1~255。 258- 不允许出现的非法英文字符,包括:<br> . .. \ / : * ? " ' ` < > | { } [ ] 259- 英文字符大小写不敏感。 260- 相册名不允许重名。 261 262> **说明:** 263> 264> 从API version 10开始支持,从API version 11开始废弃。建议使用[MediaAlbumChangeRequest.createAlbumRequest](#createalbumrequest11)替代。 265 266**系统接口**:此接口为系统接口。 267 268**系统能力**:SystemCapability.FileManagement.PhotoAccessHelper.Core 269 270**需要权限**:ohos.permission.WRITE_IMAGEVIDEO 271 272**参数:** 273 274| 参数名 | 类型 | 必填 | 说明 | 275| -------- | ------------------------ | ---- | ------------------------- | 276| name | string | 是 | 待创建相册的相册名。 | 277| callback | AsyncCallback<[Album](#album)> | 是 | callback返回创建的相册实例。 | 278 279**错误码:** 280 281接口抛出错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)和[文件管理错误码](../apis-core-file-kit/errorcode-filemanagement.md)。 282 283| 错误码ID | 错误信息 | 284| -------- | ---------------------------------------- | 285| 202 | Called by non-system application. | 286| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types; 3. Parameter verification failed. | 287| 13900012 | Permission denied. | 288| 13900015 | File exists. | 289| 13900020 | Invalid argument. | 290| 14000011 | System inner fail. | 291 292**示例:** 293 294```ts 295async function example() { 296 console.info('createAlbumDemo'); 297 let albumName: string = 'newAlbumName' + new Date().getTime(); 298 phAccessHelper.createAlbum(albumName, (err, album) => { 299 if (err) { 300 console.error(`createAlbumCallback failed with err: ${err.code}, ${err.message}`); 301 return; 302 } 303 console.info('createAlbumCallback successfully, album: ' + album.albumName + ' album uri: ' + album.albumUri); 304 }); 305} 306``` 307 308### createAlbum<sup>(deprecated)</sup> 309 310createAlbum(name: string): Promise<Album> 311 312创建相册,使用Promise方式返回结果。 313 314待创建的相册名参数规格为: 315- 相册名字符串长度为1~255。 316- 不允许出现的非法英文字符,包括:<br> . .. \ / : * ? " ' ` < > | { } [ ] 317- 英文字符大小写不敏感。 318- 相册名不允许重名。 319 320> **说明:** 321> 322> 从API version 10开始支持,从API version 11开始废弃。建议使用[MediaAlbumChangeRequest.createAlbumRequest](#createalbumrequest11)替代。 323 324**系统接口**:此接口为系统接口。 325 326**系统能力**:SystemCapability.FileManagement.PhotoAccessHelper.Core 327 328**需要权限**:ohos.permission.WRITE_IMAGEVIDEO 329 330**参数:** 331 332| 参数名 | 类型 | 必填 | 说明 | 333| -------- | ------------------------ | ---- | ------------------------- | 334| name | string | 是 | 待创建相册的相册名。 | 335 336**返回值:** 337 338| 类型 | 说明 | 339| --------------------------- | -------------- | 340| Promise<[Album](#album)> | Promise对象,返回创建的相册实例。 | 341 342**错误码:** 343 344接口抛出错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)和[文件管理错误码](../apis-core-file-kit/errorcode-filemanagement.md)。 345 346| 错误码ID | 错误信息 | 347| -------- | ---------------------------------------- | 348| 202 | Called by non-system application. | 349| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types; 3. Parameter verification failed. | 350| 13900012 | Permission denied. | 351| 13900015 | File exists. | 352| 13900020 | Invalid argument. | 353| 14000011 | System inner fail. | 354 355**示例:** 356 357```ts 358import { BusinessError } from '@kit.BasicServicesKit'; 359 360async function example() { 361 console.info('createAlbumDemo'); 362 let albumName: string = 'newAlbumName' + new Date().getTime(); 363 phAccessHelper.createAlbum(albumName).then((album) => { 364 console.info('createAlbumPromise successfully, album: ' + album.albumName + ' album uri: ' + album.albumUri); 365 }).catch((err: BusinessError) => { 366 console.error(`createAlbumPromise failed with err: ${err.code}, ${err.message}`); 367 }); 368} 369``` 370 371### deleteAlbums<sup>(deprecated)</sup> 372 373deleteAlbums(albums: Array<Album>, callback: AsyncCallback<void>): void 374 375删除相册,使用callback方式返回结果。 376 377删除相册前需先确保相册存在,只能删除用户相册。 378 379> **说明:** 380> 381> 从API version 10开始支持,从API version 11开始废弃。建议使用[MediaAlbumChangeRequest.deleteAlbums](#deletealbums11)替代。 382 383**系统接口**:此接口为系统接口。 384 385**系统能力**:SystemCapability.FileManagement.PhotoAccessHelper.Core 386 387**需要权限**:ohos.permission.WRITE_IMAGEVIDEO 388 389**参数:** 390 391| 参数名 | 类型 | 必填 | 说明 | 392| -------- | ------------------------ | ---- | ------------------------- | 393| albums | Array<[Album](#album)> | 是 | 待删除相册的数组。 | 394| callback | AsyncCallback<void> | 是 | callback返回void。 | 395 396**错误码:** 397 398接口抛出错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)和[文件管理错误码](../apis-core-file-kit/errorcode-filemanagement.md)。 399 400| 错误码ID | 错误信息 | 401| -------- | ---------------------------------------- | 402| 202 | Called by non-system application. | 403| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types; 3. Parameter verification failed. | 404| 13900012 | Permission denied. | 405| 13900020 | Invalid argument. | 406| 14000011 | System inner fail. | 407 408**示例:** 409 410```ts 411import { dataSharePredicates } from '@kit.ArkData'; 412 413async function example() { 414 // 示例代码为删除相册名为newAlbumName的相册。 415 console.info('deleteAlbumsDemo'); 416 let predicates: dataSharePredicates.DataSharePredicates = new dataSharePredicates.DataSharePredicates(); 417 predicates.equalTo('album_name', 'newAlbumName'); 418 let fetchOptions: photoAccessHelper.FetchOptions = { 419 fetchColumns: [], 420 predicates: predicates 421 }; 422 let fetchResult: photoAccessHelper.FetchResult<photoAccessHelper.Album> = await phAccessHelper.getAlbums(photoAccessHelper.AlbumType.USER, photoAccessHelper.AlbumSubtype.USER_GENERIC, fetchOptions); 423 let album: photoAccessHelper.Album = await fetchResult.getFirstObject(); 424 phAccessHelper.deleteAlbums([album], (err) => { 425 if (err) { 426 console.error(`deletePhotoAlbumsCallback failed with err: ${err.code}, ${err.message}`); 427 return; 428 } 429 console.info('deletePhotoAlbumsCallback successfully'); 430 }); 431 fetchResult.close(); 432} 433``` 434 435### deleteAlbums<sup>(deprecated)</sup> 436 437deleteAlbums(albums: Array<Album>): Promise<void> 438 439删除相册,使用Promise方式返回结果。 440 441删除相册前需先确保相册存在,只能删除用户相册。 442 443> **说明:** 444> 445> 从API version 10开始支持,从API version 11开始废弃。建议使用[MediaAlbumChangeRequest.deleteAlbums](#deletealbums11)替代。 446 447**系统接口**:此接口为系统接口。 448 449**系统能力**:SystemCapability.FileManagement.PhotoAccessHelper.Core 450 451**需要权限**:ohos.permission.WRITE_IMAGEVIDEO 452 453**参数:** 454 455| 参数名 | 类型 | 必填 | 说明 | 456| -------- | ------------------------ | ---- | ------------------------- | 457| albums | Array<[Album](#album)> | 是 | 待删除相册的数组。 | 458 459**返回值:** 460 461| 类型 | 说明 | 462| --------------------------- | -------------- | 463| Promise<void> | Promise对象,返回void。 | 464 465**错误码:** 466 467接口抛出错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)和[文件管理错误码](../apis-core-file-kit/errorcode-filemanagement.md)。 468 469| 错误码ID | 错误信息 | 470| -------- | ---------------------------------------- | 471| 202 | Called by non-system application. | 472| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types; 3. Parameter verification failed. | 473| 13900012 | Permission denied. | 474| 13900020 | Invalid argument. | 475| 14000011 | System inner fail. | 476 477**示例:** 478 479```ts 480import { dataSharePredicates } from '@kit.ArkData'; 481import { BusinessError } from '@kit.BasicServicesKit'; 482 483async function example() { 484 // 示例代码为删除相册名为newAlbumName的相册。 485 console.info('deleteAlbumsDemo'); 486 let predicates: dataSharePredicates.DataSharePredicates = new dataSharePredicates.DataSharePredicates(); 487 predicates.equalTo('album_name', 'newAlbumName'); 488 let fetchOptions: photoAccessHelper.FetchOptions = { 489 fetchColumns: [], 490 predicates: predicates 491 }; 492 let fetchResult: photoAccessHelper.FetchResult<photoAccessHelper.Album> = await phAccessHelper.getAlbums(photoAccessHelper.AlbumType.USER, photoAccessHelper.AlbumSubtype.USER_GENERIC, fetchOptions); 493 let album: photoAccessHelper.Album = await fetchResult.getFirstObject(); 494 phAccessHelper.deleteAlbums([album]).then(() => { 495 console.info('deletePhotoAlbumsPromise successfully'); 496 }).catch((err: BusinessError) => { 497 console.error(`deletePhotoAlbumsPromise failed with err: ${err.code}, ${err.message}`); 498 }); 499 fetchResult.close(); 500} 501``` 502 503### getHiddenAlbums<sup>11+</sup> 504 505getHiddenAlbums(mode: HiddenPhotosDisplayMode, options: FetchOptions, callback: AsyncCallback<FetchResult<Album>>): void 506 507根据隐藏文件显示模式和检索选项获取系统中的隐藏相册,使用callback方式返回结果。 508 509**系统接口**:此接口为系统接口。 510 511**需要权限**:ohos.permission.READ_IMAGEVIDEO 和 ohos.permission.MANAGE_PRIVATE_PHOTOS 512 513**系统能力**:SystemCapability.FileManagement.PhotoAccessHelper.Core 514 515**参数:** 516 517| 参数名 | 类型 | 必填 | 说明 | 518| -------- | ------------------------ | ---- | ------------------------- | 519| mode | [HiddenPhotosDisplayMode](#hiddenphotosdisplaymode11) | 是 | 隐藏文件显示模式。 | 520| options | [FetchOptions](js-apis-photoAccessHelper.md#fetchoptions) | 是 | 检索选项。 | 521| callback | AsyncCallback<[FetchResult](js-apis-photoAccessHelper.md#fetchresult)<[Album](#album)>> | 是 | callback返回获取相册的结果集。 | 522 523**错误码:** 524 525接口抛出错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)和[文件管理错误码](../apis-core-file-kit/errorcode-filemanagement.md)。 526 527| 错误码ID | 错误信息 | 528| -------- | ---------------------------------------- | 529| 201 | Permission verification failed, usually the result returned by VerifyAccessToken. | 530| 202 | Permission verification failed, application which is not a system application uses system API. | 531| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types; 3. Parameter verification failed. | 532| 14000011 | System inner fail. | 533 534**示例:** 535 536```ts 537import { dataSharePredicates } from '@kit.ArkData'; 538 539// 获取系统中包含隐藏文件且相册名为'newAlbumName'的相册。 540async function getHiddenAlbumsView() { 541 console.info('getHiddenAlbumsViewDemo'); 542 let predicates: dataSharePredicates.DataSharePredicates = new dataSharePredicates.DataSharePredicates(); 543 predicates.equalTo('album_name', 'newAlbumName'); 544 let fetchOptions: photoAccessHelper.FetchOptions = { 545 fetchColumns: [], 546 predicates: predicates 547 }; 548 phAccessHelper.getHiddenAlbums(photoAccessHelper.HiddenPhotosDisplayMode.ALBUMS_MODE, fetchOptions, 549 async (err, fetchResult) => { 550 if (fetchResult === undefined) { 551 console.error('getHiddenAlbumsViewCallback fetchResult is undefined'); 552 return; 553 } 554 let album = await fetchResult.getFirstObject(); 555 console.info('getHiddenAlbumsViewCallback successfully, album name: ' + album.albumName); 556 fetchResult.close(); 557 }); 558} 559``` 560 561### getHiddenAlbums<sup>11+</sup> 562 563getHiddenAlbums(mode: HiddenPhotosDisplayMode, callback: AsyncCallback<FetchResult<Album>>): void 564 565根据隐藏文件显示模式获取系统中的隐藏相册,使用callback方式返回结果 566 567**系统接口**:此接口为系统接口。 568 569**需要权限**:ohos.permission.READ_IMAGEVIDEO 和 ohos.permission.MANAGE_PRIVATE_PHOTOS 570 571**系统能力**:SystemCapability.FileManagement.PhotoAccessHelper.Core 572 573**参数:** 574 575| 参数名 | 类型 | 必填 | 说明 | 576| -------- | ------------------------ | ---- | ------------------------- | 577| mode | [HiddenPhotosDisplayMode](#hiddenphotosdisplaymode11) | 是 | 隐藏文件显示模式。 | 578| callback | AsyncCallback<[FetchResult](js-apis-photoAccessHelper.md#fetchresult)<[Album](#album)>> | 是 | callback返回获取相册的结果集。 | 579 580**错误码:** 581 582接口抛出错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)和[文件管理错误码](../apis-core-file-kit/errorcode-filemanagement.md)。 583 584| 错误码ID | 错误信息 | 585| -------- | ---------------------------------------- | 586| 201 | Permission verification failed, usually the result returned by VerifyAccessToken. | 587| 202 | Permission verification failed, application which is not a system application uses system API. | 588| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types; 3. Parameter verification failed. | 589| 14000011 | System inner fail. | 590 591**示例:** 592 593```ts 594import { dataSharePredicates } from '@kit.ArkData'; 595 596// 获取系统预置的隐藏相册。 597async function getSysHiddenAlbum() { 598 console.info('getSysHiddenAlbumDemo'); 599 phAccessHelper.getHiddenAlbums(photoAccessHelper.HiddenPhotosDisplayMode.ASSETS_MODE, async (err, fetchResult) => { 600 if (fetchResult === undefined) { 601 console.error('getSysHiddenAlbumCallback fetchResult is undefined'); 602 return; 603 } 604 let hiddenAlbum: photoAccessHelper.Album = await fetchResult.getFirstObject(); 605 console.info('getSysHiddenAlbumCallback successfully, albumUri: ' + hiddenAlbum.albumUri); 606 fetchResult.close(); 607 }); 608} 609 610// 获取隐藏相册-相册视图,即系统中包含隐藏文件的相册(不包含系统预置的隐藏相册本身和回收站相册)。 611async function getHiddenAlbumsView() { 612 console.info('getHiddenAlbumsViewDemo'); 613 phAccessHelper.getHiddenAlbums(photoAccessHelper.HiddenPhotosDisplayMode.ALBUMS_MODE, async (err, fetchResult) => { 614 if (fetchResult === undefined) { 615 console.error('getHiddenAlbumsViewCallback fetchResult is undefined'); 616 return; 617 } 618 let albums: Array<photoAccessHelper.Album> = await fetchResult.getAllObjects(); 619 console.info('getHiddenAlbumsViewCallback successfully, albums size: ' + albums.length); 620 621 let predicates: dataSharePredicates.DataSharePredicates = new dataSharePredicates.DataSharePredicates(); 622 let fetchOption: photoAccessHelper.FetchOptions = { 623 fetchColumns: [], 624 predicates: predicates 625 }; 626 for (let i = 0; i < albums.length; i++) { 627 // 获取相册中的隐藏文件。 628 albums[i].getAssets(fetchOption, (err, assetFetchResult) => { 629 console.info('album get hidden assets successfully, getCount: ' + assetFetchResult.getCount()); 630 }); 631 } 632 fetchResult.close(); 633 }); 634} 635``` 636 637### getHiddenAlbums<sup>11+</sup> 638 639getHiddenAlbums(mode: HiddenPhotosDisplayMode, options?: FetchOptions): Promise<FetchResult<Album>> 640 641根据隐藏文件显示模式和检索选项获取系统中的隐藏相册,使用Promise方式返回结果。 642 643**系统接口**:此接口为系统接口。 644 645**需要权限**:ohos.permission.READ_IMAGEVIDEO 和 ohos.permission.MANAGE_PRIVATE_PHOTOS 646 647**系统能力**:SystemCapability.FileManagement.PhotoAccessHelper.Core 648 649**参数:** 650 651| 参数名 | 类型 | 必填 | 说明 | 652| -------- | ------------------------ | ---- | ------------------------- | 653| mode | [HiddenPhotosDisplayMode](#hiddenphotosdisplaymode11) | 是 | 隐藏文件显示模式。 | 654| options | [FetchOptions](js-apis-photoAccessHelper.md#fetchoptions) | 否 | 检索选项,不填时默认根据隐藏文件显示模式检索。 | 655 656**返回值:** 657 658| 类型 | 说明 | 659| --------------------------- | -------------- | 660| Promise<[FetchResult](js-apis-photoAccessHelper.md#fetchresult)<[Album](#album)>> | Promise对象,返回获取相册的结果集。 661 662**错误码:** 663 664接口抛出错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)和[文件管理错误码](../apis-core-file-kit/errorcode-filemanagement.md)。 665 666| 错误码ID | 错误信息 | 667| -------- | ---------------------------------------- | 668| 201 | Permission verification failed, usually the result returned by VerifyAccessToken. | 669| 202 | Permission verification failed, application which is not a system application uses system API. | 670| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types; 3. Parameter verification failed. | 671| 14000011 | System inner fail. | 672 673**示例:** 674 675```ts 676import { dataSharePredicates } from '@kit.ArkData'; 677import { BusinessError } from '@kit.BasicServicesKit'; 678 679// 获取系统预置的隐藏相册。 680async function getSysHiddenAlbum() { 681 console.info('getSysHiddenAlbumDemo'); 682 phAccessHelper.getHiddenAlbums(photoAccessHelper.HiddenPhotosDisplayMode.ASSETS_MODE) 683 .then( async (fetchResult) => { 684 if (fetchResult === undefined) { 685 console.error('getSysHiddenAlbumPromise fetchResult is undefined'); 686 return; 687 } 688 let hiddenAlbum: photoAccessHelper.Album = await fetchResult.getFirstObject(); 689 console.info('getAlbumsPromise successfully, albumUri: ' + hiddenAlbum.albumUri); 690 fetchResult.close(); 691 }).catch((err: BusinessError) => { 692 console.error(`getSysHiddenAlbumPromise failed with err: ${err.code}, ${err.message}`); 693 }); 694} 695 696// 获取隐藏相册-相册视图,即系统中包含隐藏文件的相册(不包含系统预置的隐藏相册本身和回收站相册)。 697async function getHiddenAlbumsView() { 698 console.info('getHiddenAlbumsViewDemo'); 699 phAccessHelper.getHiddenAlbums(photoAccessHelper.HiddenPhotosDisplayMode.ALBUMS_MODE).then( async (fetchResult) => { 700 if (fetchResult === undefined) { 701 console.error('getHiddenAlbumsViewPromise fetchResult is undefined'); 702 return; 703 } 704 let albums: Array<photoAccessHelper.Album> = await fetchResult.getAllObjects(); 705 console.info('getHiddenAlbumsViewPromise successfully, albums size: ' + albums.length); 706 707 let predicates: dataSharePredicates.DataSharePredicates = new dataSharePredicates.DataSharePredicates(); 708 let fetchOption: photoAccessHelper.FetchOptions = { 709 fetchColumns: [], 710 predicates: predicates 711 }; 712 for (let i = 0; i < albums.length; i++) { 713 // 获取相册中的隐藏文件。 714 albums[i].getAssets(fetchOption).then((assetFetchResult) => { 715 console.info('album get hidden assets successfully, getCount: ' + assetFetchResult.getCount()); 716 }).catch((err: BusinessError) => { 717 console.error(`album get hidden assets failed with error: ${err.code}, ${err.message}`); 718 }); 719 } 720 fetchResult.close(); 721 }).catch((err: BusinessError) => { 722 console.error(`getHiddenAlbumsViewPromise failed with err: ${err.code}, ${err.message}`); 723 }); 724} 725``` 726 727### deleteAssets<sup>(deprecated)</sup> 728 729deleteAssets(uriList: Array<string>, callback: AsyncCallback<void>): void 730 731删除媒体文件,删除的文件进入到回收站,使用callback方式返回结果。 732 733> **说明:** 734> 735> 从API version 10开始支持,从API version 11开始废弃。建议使用[MediaAssetChangeRequest.deleteAssets](js-apis-photoAccessHelper.md#deleteassets11)替代。 736 737**系统接口**:此接口为系统接口。 738 739**需要权限**:ohos.permission.WRITE_IMAGEVIDEO 740 741**系统能力**:SystemCapability.FileManagement.PhotoAccessHelper.Core 742 743**参数:** 744 745| 参数名 | 类型 | 必填 | 说明 | 746| -------- | ------------------------- | ---- | ---------- | 747| uriList | Array<string> | 是 | 待删除的媒体文件uri数组。 | 748| callback | AsyncCallback<void> | 是 | callback返回void。 | 749 750**错误码:** 751 752接口抛出错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)和[文件管理错误码](../apis-core-file-kit/errorcode-filemanagement.md)。 753 754| 错误码ID | 错误信息 | 755| -------- | ---------------------------------------- | 756| 202 | Called by non-system application. | 757| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types; 3. Parameter verification failed. | 758| 13900012 | Permission denied. | 759| 13900020 | Invalid argument. | 760| 14000002 | Invalid uri. | 761| 14000011 | System inner fail. | 762 763**示例:** 764 765```ts 766import { dataSharePredicates } from '@kit.ArkData'; 767 768async function example() { 769 console.info('deleteAssetDemo'); 770 let predicates: dataSharePredicates.DataSharePredicates = new dataSharePredicates.DataSharePredicates(); 771 let fetchOptions: photoAccessHelper.FetchOptions = { 772 fetchColumns: [], 773 predicates: predicates 774 }; 775 try { 776 let fetchResult: photoAccessHelper.FetchResult<photoAccessHelper.PhotoAsset> = await phAccessHelper.getAssets(fetchOptions); 777 let asset: photoAccessHelper.PhotoAsset = await fetchResult.getFirstObject(); 778 if (asset === undefined) { 779 console.error('asset not exist'); 780 return; 781 } 782 phAccessHelper.deleteAssets([asset.uri], (err) => { 783 if (err === undefined) { 784 console.info('deleteAssets successfully'); 785 } else { 786 console.error(`deleteAssets failed with error: ${err.code}, ${err.message}`); 787 } 788 }); 789 } catch (err) { 790 console.error(`fetch failed, error: ${err.code}, ${err.message}`); 791 } 792} 793``` 794 795### deleteAssets<sup>(deprecated)</sup> 796 797deleteAssets(uriList: Array<string>): Promise<void> 798 799删除媒体文件,删除的文件进入到回收站,使用Promise方式返回结果。 800 801> **说明:** 802> 803> 从API version 10开始支持,从API version 11开始废弃。建议使用[MediaAssetChangeRequest.deleteAssets](js-apis-photoAccessHelper.md#deleteassets11)替代。 804 805**系统接口**:此接口为系统接口。 806 807**需要权限**:ohos.permission.WRITE_IMAGEVIDEO 808 809**系统能力**:SystemCapability.FileManagement.PhotoAccessHelper.Core 810 811**参数:** 812 813| 参数名 | 类型 | 必填 | 说明 | 814| -------- | ------------------------- | ---- | ---------- | 815| uriList | Array<string> | 是 | 待删除的媒体文件uri数组。 | 816 817**返回值:** 818 819| 类型 | 说明 | 820| --------------------------------------- | ----------------- | 821| Promise<void>| Promise对象,返回void。 | 822 823**错误码:** 824 825接口抛出错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)和[文件管理错误码](../apis-core-file-kit/errorcode-filemanagement.md)。 826 827| 错误码ID | 错误信息 | 828| -------- | ---------------------------------------- | 829| 202 | Called by non-system application. | 830| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types; 3. Parameter verification failed. | 831| 13900012 | Permission denied. | 832| 13900020 | Invalid argument. | 833| 14000002 | Invalid uri. | 834| 14000011 | System inner fail. | 835 836**示例:** 837 838```ts 839import { dataSharePredicates } from '@kit.ArkData'; 840 841async function example() { 842 console.info('deleteDemo'); 843 let predicates: dataSharePredicates.DataSharePredicates = new dataSharePredicates.DataSharePredicates(); 844 let fetchOptions: photoAccessHelper.FetchOptions = { 845 fetchColumns: [], 846 predicates: predicates 847 }; 848 try { 849 let fetchResult: photoAccessHelper.FetchResult<photoAccessHelper.PhotoAsset> = await phAccessHelper.getAssets(fetchOptions); 850 let asset: photoAccessHelper.PhotoAsset = await fetchResult.getFirstObject(); 851 if (asset === undefined) { 852 console.error('asset not exist'); 853 return; 854 } 855 await phAccessHelper.deleteAssets([asset.uri]); 856 console.info('deleteAssets successfully'); 857 } catch (err) { 858 console.error(`deleteAssets failed with error: ${err.code}, ${err.message}`); 859 } 860} 861``` 862 863### getPhotoIndex 864 865getPhotoIndex(photoUri: string, albumUri: string, options: FetchOptions, callback: AsyncCallback<number>): void 866 867获取相册中图片或视频的位置,使用callback方式返回结果。 868 869**系统接口**:此接口为系统接口。 870 871**需要权限**:ohos.permission.READ_IMAGEVIDEO 872 873**系统能力**:SystemCapability.FileManagement.PhotoAccessHelper.Core 874 875**参数:** 876 877| 参数名 | 类型 | 必填 | 说明 | 878| -------- | ------------------------- | ---- | ---------- | 879| photoUri | string | 是 | 所查询的图库资源的uri。 | 880| albumUri | string | 是 | 相册uri,可以为空字符串,为空字符串时默认查询全部图库资源。 | 881| options | [FetchOptions](js-apis-photoAccessHelper.md#fetchoptions) | 是 | 检索选项,predicates中必须设置一种检索排序方式,不设置或多设置均会导致接口调用异常。 | 882| callback | AsyncCallback<number>| 是 | callback返回相册中资源的索引。 | 883 884**错误码:** 885 886接口抛出错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)和[文件管理错误码](../apis-core-file-kit/errorcode-filemanagement.md)。 887 888| 错误码ID | 错误信息 | 889| -------- | ---------------------------------------- | 890| 202 | Called by non-system application. | 891| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types; 3. Parameter verification failed. | 892| 13900012 | Permission denied. | 893| 13900020 | Invalid argument. | 894| 14000011 | System inner fail. | 895 896**示例:** 897 898```ts 899import { dataSharePredicates } from '@kit.ArkData'; 900 901async function example() { 902 try { 903 console.info('getPhotoIndexDemo'); 904 let predicatesForGetAsset: dataSharePredicates.DataSharePredicates = new dataSharePredicates.DataSharePredicates(); 905 let fetchOp: photoAccessHelper.FetchOptions = { 906 fetchColumns: [], 907 predicates: predicatesForGetAsset 908 }; 909 // Obtain the uri of the album. 910 let albumFetchResult: photoAccessHelper.FetchResult<photoAccessHelper.Album> = await phAccessHelper.getAlbums(photoAccessHelper.AlbumType.SYSTEM, photoAccessHelper.AlbumSubtype.FAVORITE, fetchOp); 911 let album: photoAccessHelper.Album = await albumFetchResult.getFirstObject(); 912 let predicates: dataSharePredicates.DataSharePredicates = new dataSharePredicates.DataSharePredicates(); 913 predicates.orderByAsc(photoAccessHelper.PhotoKeys.DATE_MODIFIED); 914 let fetchOptions: photoAccessHelper.FetchOptions = { 915 fetchColumns: [photoAccessHelper.PhotoKeys.DATE_MODIFIED], 916 predicates: predicates 917 }; 918 let photoFetchResult: photoAccessHelper.FetchResult<photoAccessHelper.PhotoAsset> = await album.getAssets(fetchOptions); 919 let expectIndex = 1; 920 // Obtain the uri of the second file. 921 let photoAsset: photoAccessHelper.PhotoAsset = await photoFetchResult.getObjectByPosition(expectIndex); 922 923 phAccessHelper.getPhotoIndex(photoAsset.uri, album.albumUri, fetchOptions, (err, index) => { 924 if (err === undefined) { 925 console.info(`getPhotoIndex successfully and index is : ${index}`); 926 } else { 927 console.error(`getPhotoIndex failed; error: ${err.code}, ${err.message}`); 928 } 929 }); 930 } catch (error) { 931 console.error(`getPhotoIndex failed; error: ${error.code}, ${error.message}`); 932 } 933} 934``` 935 936### getPhotoIndex 937 938getPhotoIndex(photoUri: string, albumUri: string, options: FetchOptions): Promise<number> 939 940获取相册中图片或视频的位置,使用Promise方式返回结果。 941 942**系统接口**:此接口为系统接口。 943 944**需要权限**:ohos.permission.READ_IMAGEVIDEO 945 946**系统能力**:SystemCapability.FileManagement.PhotoAccessHelper.Core 947 948**参数:** 949 950| 参数名 | 类型 | 必填 | 说明 | 951| -------- | ------------------------- | ---- | ---------- | 952| photoUri | string | 是 | 所查询的图库资源的uri。 | 953| albumUri | string | 是 | 相册uri,可以为空字符串,为空字符串时默认查询全部图库资源。 | 954| options | [FetchOptions](js-apis-photoAccessHelper.md#fetchoptions) | 是 | 检索选项,predicates中必须设置一种检索排序方式,不设置或多设置均会导致接口调用异常。 | 955 956**返回值:** 957 958| 类型 | 说明 | 959| --------------------------------------- | ----------------- | 960| Promise<number>| 返回相册中资源的索引。 | 961 962**错误码:** 963 964接口抛出错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)和[文件管理错误码](../apis-core-file-kit/errorcode-filemanagement.md)。 965 966| 错误码ID | 错误信息 | 967| -------- | ---------------------------------------- | 968| 202 | Called by non-system application. | 969| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types; 3. Parameter verification failed. | 970| 13900012 | Permission denied. | 971| 13900020 | Invalid argument. | 972| 14000011 | System inner fail. | 973 974**示例:** 975 976```ts 977import { dataSharePredicates } from '@kit.ArkData'; 978import { BusinessError } from '@kit.BasicServicesKit'; 979 980async function example() { 981 try { 982 console.info('getPhotoIndexDemo'); 983 let predicatesForGetAsset: dataSharePredicates.DataSharePredicates = new dataSharePredicates.DataSharePredicates(); 984 let fetchOp: photoAccessHelper.FetchOptions = { 985 fetchColumns: [], 986 predicates: predicatesForGetAsset 987 }; 988 // Obtain the uri of the album. 989 let albumFetchResult: photoAccessHelper.FetchResult<photoAccessHelper.Album> = await phAccessHelper.getAlbums(photoAccessHelper.AlbumType.SYSTEM, photoAccessHelper.AlbumSubtype.FAVORITE, fetchOp); 990 let album: photoAccessHelper.Album = await albumFetchResult.getFirstObject(); 991 let predicates: dataSharePredicates.DataSharePredicates = new dataSharePredicates.DataSharePredicates(); 992 predicates.orderByAsc(photoAccessHelper.PhotoKeys.DATE_MODIFIED); 993 let fetchOptions: photoAccessHelper.FetchOptions = { 994 fetchColumns: [photoAccessHelper.PhotoKeys.DATE_MODIFIED], 995 predicates: predicates 996 }; 997 let photoFetchResult: photoAccessHelper.FetchResult<photoAccessHelper.PhotoAsset> = await album.getAssets(fetchOptions); 998 let expectIndex = 1; 999 // Obtain the uri of the second file. 1000 let photoAsset: photoAccessHelper.PhotoAsset = await photoFetchResult.getObjectByPosition(expectIndex); 1001 phAccessHelper.getPhotoIndex(photoAsset.uri, album.albumUri, fetchOptions).then((index) => { 1002 console.info(`getPhotoIndex successfully and index is : ${index}`); 1003 }).catch((err: BusinessError) => { 1004 console.error(`getPhotoIndex failed; error: ${err.code}, ${err.message}`); 1005 }); 1006 } catch (error) { 1007 console.error(`getPhotoIndex failed; error: ${error.code}, ${error.message}`); 1008 } 1009} 1010``` 1011 1012### saveFormInfo<sup>11+</sup> 1013 1014saveFormInfo(info:FormInfo, callback: AsyncCallback<void>):void 1015 1016将图库卡片相关信息保存到数据库中,使用callback方式返回结果。 1017 1018**系统接口**:此接口为系统接口。 1019 1020**需要权限**:ohos.permission.WRITE_IMAGEVIDEO 1021 1022**系统能力**:SystemCapability.FileManagement.PhotoAccessHelper.Core 1023 1024**参数:** 1025 1026| 参数名 | 类型 | 必填 | 说明 | 1027| -------- | ------------------------ | ---- | ------------------------- | 1028| info | [FormInfo](#forminfo11) | 是 | 图库卡片信息,包括图库卡片的id和卡片绑定的图片的uri。 | 1029| callback | AsyncCallback<void> | 是 | callback返回void。 | 1030 1031**错误码:** 1032 1033接口抛出错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)和[文件管理错误码](../apis-core-file-kit/errorcode-filemanagement.md)。 1034 1035| 错误码ID | 错误信息 | 1036| -------- | ---------------------------------------- | 1037| 201 | Permission verification failed, usually the result returned by VerifyAccessToken. | 1038| 202 | Permission verification failed, application which is not a system application uses system API. | 1039| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types; 3. Parameter verification failed. | 1040| 14000011 | System inner fail. | 1041 1042 1043**示例:** 1044 1045```ts 1046import { dataSharePredicates } from '@kit.ArkData'; 1047import { BusinessError } from '@kit.BasicServicesKit'; 1048 1049async function example() { 1050 console.info('saveFormInfoDemo'); 1051 let predicates: dataSharePredicates.DataSharePredicates = new dataSharePredicates.DataSharePredicates(); 1052 let fetchOptions: photoAccessHelper.FetchOptions = { 1053 fetchColumns: [], 1054 predicates: predicates 1055 }; 1056 let fetchResult: photoAccessHelper.FetchResult<photoAccessHelper.PhotoAsset> = await phAccessHelper.getAssets(fetchOptions); 1057 let photoAsset: photoAccessHelper.PhotoAsset = await fetchResult.getFirstObject(); 1058 1059 let info: photoAccessHelper.FormInfo = { 1060 //formId是一个由纯数字组成的字符串,uri为图库中存在的图片的uri信息,图库中无图片创建卡片时uri需为空字符串。 1061 formId : "20230116123", 1062 uri: photoAsset.uri, 1063 } 1064 1065 phAccessHelper.saveFormInfo(info, async (err: BusinessError) => { 1066 if (err == undefined) { 1067 console.info('saveFormInfo success'); 1068 } else { 1069 console.error(`saveFormInfo fail with error: ${err.code}, ${err.message}`); 1070 } 1071 }); 1072} 1073``` 1074 1075### saveFormInfo<sup>11+</sup> 1076 1077saveFormInfo(info:FormInfo):Promise<void> 1078 1079将图库卡片相关信息保存到数据库中,使用Promise方式返回结果。 1080 1081**系统接口**:此接口为系统接口。 1082 1083**需要权限**:ohos.permission.WRITE_IMAGEVIDEO 1084 1085**系统能力**:SystemCapability.FileManagement.PhotoAccessHelper.Core 1086 1087**参数:** 1088 1089| 参数名 | 类型 | 必填 | 说明 | 1090| -------- | ------------------------ | ---- | ------------------------- | 1091| info | [FormInfo](#forminfo11) | 是 | 图库卡片信息,包括图库卡片的id和卡片绑定的图片的uri。 | 1092 1093**返回值:** 1094 1095| 类型 | 说明 | 1096| --------------------------------------- | ----------------- | 1097| Promise<void>| Promise对象,返回void。 | 1098 1099**错误码:** 1100 1101接口抛出错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)和[文件管理错误码](../apis-core-file-kit/errorcode-filemanagement.md)。 1102 1103| 错误码ID | 错误信息 | 1104| -------- | ---------------------------------------- | 1105| 201 | Permission verification failed, usually the result returned by VerifyAccessToken. | 1106| 202 | Permission verification failed, application which is not a system application uses system API. | 1107| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types; 3. Parameter verification failed. | 1108| 14000011 | System inner fail. | 1109 1110**示例:** 1111 1112```ts 1113import { dataSharePredicates } from '@kit.ArkData'; 1114import { BusinessError } from '@kit.BasicServicesKit'; 1115 1116async function example() { 1117 console.info('saveFormInfoDemo'); 1118 let predicates: dataSharePredicates.DataSharePredicates = new dataSharePredicates.DataSharePredicates(); 1119 let fetchOptions: photoAccessHelper.FetchOptions = { 1120 fetchColumns: [], 1121 predicates: predicates 1122 }; 1123 let fetchResult: photoAccessHelper.FetchResult<photoAccessHelper.PhotoAsset> = await phAccessHelper.getAssets(fetchOptions); 1124 let photoAsset: photoAccessHelper.PhotoAsset = await fetchResult.getFirstObject(); 1125 1126 let info: photoAccessHelper.FormInfo = { 1127 //formId是一个由纯数字组成的字符串,uri为图库中存在的图片的uri信息,图库中无图片创建卡片时uri需为空字符串。 1128 formId: "20230116123", 1129 uri: photoAsset.uri, 1130 } 1131 1132 phAccessHelper.saveFormInfo(info).then(() => { 1133 console.info('saveFormInfo successfully'); 1134 }).catch((err: BusinessError) => { 1135 console.error(`saveFormInfo failed with error: ${err.code}, ${err.message}`); 1136 }); 1137} 1138``` 1139 1140### removeFormInfo<sup>11+</sup> 1141 1142removeFormInfo(info:FormInfo, callback: AsyncCallback<void>):void 1143 1144从数据库中删除图库卡片信息,使用callback方式返回结果。 1145 1146**系统接口**:此接口为系统接口。 1147 1148**需要权限**:ohos.permission.WRITE_IMAGEVIDEO 1149 1150**系统能力**:SystemCapability.FileManagement.PhotoAccessHelper.Core 1151 1152**参数:** 1153 1154| 参数名 | 类型 | 必填 | 说明 | 1155| -------- | ------------------------ | ---- | ------------------------- | 1156| info | [FormInfo](#forminfo11) | 是 | 图库卡片信息,包括图库卡片的id和卡片绑定的图片的uri。 | 1157| callback | AsyncCallback<void> | 是 | callback返回void。 | 1158 1159**错误码:** 1160 1161接口抛出错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)和[文件管理错误码](../apis-core-file-kit/errorcode-filemanagement.md)。 1162 1163| 错误码ID | 错误信息 | 1164| -------- | ---------------------------------------- | 1165| 201 | Permission verification failed, usually the result returned by VerifyAccessToken. | 1166| 202 | Permission verification failed, application which is not a system application uses system API. | 1167| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types; 3. Parameter verification failed. | 1168| 14000011 | System inner fail. | 1169 1170**示例:** 1171 1172```ts 1173import { BusinessError } from '@kit.BasicServicesKit'; 1174 1175async function example() { 1176 console.info('removeFormInfoDemo'); 1177 let info: photoAccessHelper.FormInfo = { 1178 //formId是一个由纯数字组成的字符串,移除卡片的时候uri填空即可。 1179 formId: "20230116123", 1180 uri: "", 1181 } 1182 1183 phAccessHelper.removeFormInfo(info, async (err: BusinessError) => { 1184 if (err == undefined) { 1185 console.info('removeFormInfo success'); 1186 } else { 1187 console.error(`removeFormInfo fail with error: ${err.code}, ${err.message}`); 1188 } 1189 }); 1190} 1191``` 1192 1193### removeFormInfo<sup>11+</sup> 1194 1195removeFormInfo(info:FormInfo):Promise<void> 1196 1197从数据库中删除图库卡片信息,使用Promise方式返回结果。 1198 1199**系统接口**:此接口为系统接口。 1200 1201**需要权限**:ohos.permission.WRITE_IMAGEVIDEO 1202 1203**系统能力**:SystemCapability.FileManagement.PhotoAccessHelper.Core 1204 1205**参数:** 1206 1207| 参数名 | 类型 | 必填 | 说明 | 1208| -------- | ------------------------ | ---- | ------------------------- | 1209| info | [FormInfo](#forminfo11) | 是 | 图库卡片信息,包括图库卡片的id和卡片绑定的图片的uri。 | 1210 1211**返回值:** 1212 1213| 类型 | 说明 | 1214| --------------------------------------- | ----------------- | 1215| Promise<void>| Promise对象,返回void。 | 1216 1217**错误码:** 1218 1219接口抛出错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)和[文件管理错误码](../apis-core-file-kit/errorcode-filemanagement.md)。 1220 1221| 错误码ID | 错误信息 | 1222| -------- | ---------------------------------------- | 1223| 201 | Permission verification failed, usually the result returned by VerifyAccessToken. | 1224| 202 | Permission verification failed, application which is not a system application uses system API. | 1225| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types; 3. Parameter verification failed. | 1226| 14000011 | System inner fail. | 1227 1228**示例:** 1229 1230```ts 1231import { BusinessError } from '@kit.BasicServicesKit'; 1232 1233async function example() { 1234 console.info('removeFormInfoDemo'); 1235 let info: photoAccessHelper.FormInfo = { 1236 //formId是一个由纯数字组成的字符串,移除卡片的时候uri填空即可。 1237 formId: "20230116123", 1238 uri: "", 1239 } 1240 1241 phAccessHelper.removeFormInfo(info).then(() => { 1242 console.info('removeFormInfo successfully'); 1243 }).catch((err: BusinessError) => { 1244 console.error(`removeFormInfo failed with error: ${err.code}, ${err.message}`); 1245 }); 1246} 1247``` 1248 1249### createAssetsForApp<sup>12+</sup> 1250 1251createAssetsForApp(bundleName: string, appName: string, appId: string, photoCreationConfigs: Array<PhotoCreationConfig>): Promise<Array<string>> 1252 1253调用接口代替应用创建媒体库uri列表。Uri已对appId对应的应用授权,支持应用使用uri写入图片/视频。 1254 1255**系统接口**:此接口为系统接口。 1256 1257**需要权限**:ohos.permission.WRITE_IMAGEVIDEO 1258 1259**系统能力**:SystemCapability.FileManagement.PhotoAccessHelper.Core 1260 1261**参数:** 1262 1263| 参数名 | 类型 | 必填 | 说明 | 1264| -------- |----------------------------------------------------------------------| ---- | ------------------------- | 1265| bundleName | string | 是 | 需保存图片/视频文件的应用bundle name。 | 1266| appName | string | 是 | 需保存图片/视频文件的应用app name。 | 1267| appId | string | 是 | 需保存图片/视频文件的应用app id。 | 1268| photoCreationConfigs | Array<[PhotoCreationConfig](./js-apis-photoAccessHelper.md#photocreationconfig12)> | 是 | 保存图片/视频到媒体库的配置。 | 1269 1270**返回值:** 1271 1272| 类型 | 说明 | 1273| --------------------------------------- | ----------------- | 1274| Promise<Array<string>> | Promise对象,返回给接口调用方的的媒体库文件uri列表。Uri已对appId对应的应用授权,支持应用写入数据。如果生成uri异常,则返回批量创建错误码。<br>返回-3006表不允许出现非法字符;返回-2004表示图片类型和后缀不符;返回-203表示文件操作异常。 | 1275 1276**错误码:** 1277 1278接口抛出错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)和[文件管理错误码](../apis-core-file-kit/errorcode-filemanagement.md)。 1279 1280| 错误码ID | 错误信息 | 1281| -------- | ---------------------------------------- | 1282| 201 | Permission denied. | 1283| 202 | Called by non-system application. | 1284| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameters types; 3. Parameter verification failed. | 1285| 14000011 | Internal system error. | 1286 1287**示例:** 1288 1289```ts 1290async function example() { 1291 console.info('createAssetsForAppDemo.'); 1292 1293 try { 1294 let bundleName: string = 'testBundleName'; 1295 let appName: string = 'testAppName'; 1296 let appId: string = 'testAppId'; 1297 let photoCreationConfigs: Array<photoAccessHelper.PhotoCreationConfig> = [ 1298 { 1299 title: 'test', 1300 fileNameExtension: 'jpg', 1301 photoType: photoAccessHelper.PhotoType.IMAGE, 1302 subtype: photoAccessHelper.PhotoSubtype.DEFAULT, 1303 } 1304 ]; 1305 let desFileUris: Array<string> = await phAccessHelper.createAssetsForApp(bundleName, appName, appId, photoCreationConfigs); 1306 console.info('createAssetsForApp success, data is ' + desFileUris); 1307 } catch (err) { 1308 console.error(`createAssetsForApp failed with error: ${err.code}, ${err.message}`); 1309 } 1310} 1311``` 1312 1313### grantPhotoUriPermission<sup>12+</sup> 1314 1315grantPhotoUriPermission(appid: string, uri: string, photoPermissionType: PhotoPermissionType, hideSensitiveType: HideSensitiveType): Promise<number> 1316 1317给应用授予uri的访问权限,使用Promise方式返回结果。 1318 1319**系统接口**:此接口为系统接口。 1320 1321**系统能力**:SystemCapability.FileManagement.PhotoAccessHelper.Core 1322 1323**需要权限:** ohos.permission.WRITE_IMAGEVIDEO 1324 1325**参数:** 1326 1327| 参数名 | 类型 | 必填 | 说明 | 1328| -------- |----------------------------------------------------------------------| ---- | ------------------------- | 1329| appid | string | 是 | 应用标识,将访问权限授予给appid标识的应用。 | 1330| uri | string | 是 | 媒体资源的uri,uri表示的资源的访问权限将授予给应用。| 1331| photoPermissionType | [PhotoPermissionType](#photopermissiontype12) | 是 | 权限类型,将photoPermissionType表示的权限授予给应用。权限的覆盖规则参考枚举类。| 1332| hideSensitiveType | [HideSensitiveType](#hidesensitivetype12) | 是 | 脱敏类型,预留参数,目前可传枚举类中任一值。| 1333 1334**返回值:** 1335 1336| 类型 | 说明 | 1337| --------------------------------------- | ----------------- | 1338| Promise<number> | Promise对象,0:授权成功。 1:已有权限。-1:授权失败。| 1339 1340**错误码:** 1341 1342接口抛出错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)和[文件管理错误码](../apis-core-file-kit/errorcode-filemanagement.md)。 1343 1344| 错误码ID | 错误信息 | 1345| -------- | ---------------------------------------- | 1346| 201 | Permission denied. | 1347| 202 | Called by non-system application. | 1348| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameters types; 3. Parameter verification failed. | 1349| 14000011 | Internal system error. | 1350 1351**示例:** 1352 1353```ts 1354async function example() { 1355 console.info('grantPhotoUriPermissionDemo'); 1356 1357 try { 1358 let result = await phAccessHelper.grantPhotoUriPermission('com.example.myapplication01', 1359 'file://media/Photo/1/IMG_datetime_0001/displayName.jpg', 1360 photoAccessHelper.PhotoPermissionType.TEMPORARY_READ_IMAGEVIDEO, 1361 photoAccessHelper.HideSensitiveType.HIDE_LOCATION_AND_SHOTING_PARM); 1362 1363 console.info('grantPhotoUriPermission success, result=' + result); 1364 } catch (err) { 1365 console.error('grantPhotoUriPermission failed, error=' + err); 1366 } 1367} 1368``` 1369 1370### grantPhotoUrisPermission<sup>12+</sup> 1371 1372grantPhotoUrisPermission(appid: string, uriList: Array<string>, photoPermissionType: PhotoPermissionType, hideSensitiveType: HideSensitiveType): Promise<number> 1373 1374给应用授予uri列表的访问权限,使用Promise方式返回结果。 1375 1376**系统接口**:此接口为系统接口。 1377 1378**系统能力**:SystemCapability.FileManagement.PhotoAccessHelper.Core 1379 1380**需要权限:** ohos.permission.WRITE_IMAGEVIDEO 1381 1382**参数:** 1383 1384| 参数名 | 类型 | 必填 | 说明 | 1385| -------- |----------------------------------------------------------------------| ---- | ------------------------- | 1386| appid | string | 是 | 应用标识,将访问权限授予给appid标识的应用。 | 1387| uriList | Array<string> | 是 | 媒体资源的uri列表,uri列表中的资源的访问权限将授予给应用。uri列表最多容纳 1000 条uri。| 1388| photoPermissionType | [PhotoPermissionType](#photopermissiontype12) | 是 | 权限类型,将photoPermissionType表示的权限授予给应用。权限的覆盖规则参考枚举类。| 1389| hideSensitiveType | [HideSensitiveType](#hidesensitivetype12) | 是 | 脱敏类型,预留参数,目前可传枚举类中任一值。| 1390 1391**返回值:** 1392 1393| 类型 | 说明 | 1394| --------------------------------------- | ----------------- | 1395| Promise<number> | Promise对象,0: 授权成功。 -1:授权失败。| 1396 1397**错误码:** 1398 1399接口抛出错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)和[文件管理错误码](../apis-core-file-kit/errorcode-filemanagement.md)。 1400 1401| 错误码ID | 错误信息 | 1402| -------- | ---------------------------------------- | 1403| 201 | Permission denied. | 1404| 202 | Called by non-system application. | 1405| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameters types; 3. Parameter verification failed. | 1406| 14000011 | Internal system error. | 1407 1408**示例:** 1409 1410```ts 1411async function example() { 1412 console.info('grantPhotoUrisPermissionDemo'); 1413 1414 try { 1415 // 媒体资源的uri列表。 1416 let uris: Array<string> = [ 1417 'file://media/Photo/11/IMG_datetime_0001/displayName1.jpg', 1418 'file://media/Photo/22/IMG_datetime_0002/displayName2.jpg']; 1419 let result = await phAccessHelper.grantPhotoUrisPermission('com.example.myapplication01', uris, 1420 photoAccessHelper.PhotoPermissionType.TEMPORARY_READ_IMAGEVIDEO, 1421 photoAccessHelper.HideSensitiveType.HIDE_LOCATION_AND_SHOTING_PARM); 1422 1423 console.info('grantPhotoUrisPermission success, result=' + result); 1424 } catch (err) { 1425 console.error('grantPhotoUrisPermission failed, error=' + err); 1426 } 1427} 1428``` 1429 1430### cancelPhotoUriPermission<sup>12+</sup> 1431 1432cancelPhotoUriPermission(appid: string, uri: string, photoPermissionType: PhotoPermissionType): Promise<number> 1433 1434取消应用对uri的访问权限,使用Promise方式返回结果。 1435 1436**系统接口**:此接口为系统接口。 1437 1438**系统能力**:SystemCapability.FileManagement.PhotoAccessHelper.Core 1439 1440**需要权限:** ohos.permission.WRITE_IMAGEVIDEO 1441 1442**参数:** 1443 1444| 参数名 | 类型 | 必填 | 说明 | 1445| -------- |----------------------------------------------------------------------| ---- | ------------------------- | 1446| appid | string | 是 | 应用标识,将取消appid标识应用对媒体资源的访问权限。 | 1447| uri | string | 是 | 媒体资源的uri,取消应用对uri表示的资源的访问权限。| 1448| photoPermissionType | [PhotoPermissionType](#photopermissiontype12) | 是 | 权限类型,取消应用对媒体资源的访问权限为photoPermissionType。| 1449 1450**返回值:** 1451 1452| 类型 | 说明 | 1453| --------------------------------------- | ----------------- | 1454| Promise<number> | Promise对象,0:取消成功。-1:取消失败。| 1455 1456**错误码:** 1457 1458接口抛出错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)和[文件管理错误码](../apis-core-file-kit/errorcode-filemanagement.md)。 1459 1460| 错误码ID | 错误信息 | 1461| -------- | ---------------------------------------- | 1462| 201 | Permission denied. | 1463| 202 | Called by non-system application. | 1464| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameters types; 3. Parameter verification failed. | 1465| 14000011 | Internal system error. | 1466 1467**示例:** 1468 1469```ts 1470async function example() { 1471 console.info('cancelPhotoUriPermissionDemo'); 1472 1473 try { 1474 let result = await phAccessHelper.cancelPhotoUriPermission('com.example.myapplication01', 1475 'file://media/Photo/11/IMG_datetime_0001/displayName.jpg', 1476 photoAccessHelper.PhotoPermissionType.TEMPORARY_READ_IMAGEVIDEO); 1477 1478 console.info('cancelPhotoUriPermission success, result=' + result); 1479 } catch (err) { 1480 console.error('cancelPhotoUriPermission failed, error=' + err); 1481 } 1482} 1483``` 1484 1485### createAssetsForAppWithMode<sup>12+</sup> 1486 1487createAssetsForAppWithMode(boundleName: string, appName: string, appId: string, tokenId: number, authorizationMode: AuthorizationMode, photoCreationConfigs:Array\<PhotoCreationConfig>): Promise\<Array\<string>> 1488 1489提供给应用保存短时授权,使用Promise方式返回结果。 1490 1491**系统接口**:此接口为系统接口。 1492 1493**系统能力**:SystemCapability.FileManagement.PhotoAccessHelper.Core 1494 1495**需要权限:** ohos.permission.WRITE_IMAGEVIDEO 1496 1497**参数:** 1498 1499| 参数名 | 类型 | 必填 | 说明 | 1500| -------- |----------------------------------------------------------------------| ---- | ------------------------- | 1501| boundleName| string | 是 | 需要保存图片/视频文件的应用boundleName。 | 1502| appName| string | 是 | 需要保存图片/视频文件的应用appName。| 1503| appId| string | 是 | 需要保存图片/视频文件的应用app id。 | 1504| tokenId| number| 是 | 需要短时授权应用的唯一标识。 | 1505| authorizationMode| [AuthorizationMode](#authorizationmode12)| 是 | 授权模式。授予应用短期内再次保存无需重复弹框确认。 | 1506| PhotoCreationConfig| Array\<[PhotoCreationConfig](js-apis-photoAccessHelper.md#photocreationconfig12)> | 是 | 保存图片/视频到媒体库的配置。| 1507 1508**返回值:** 1509 1510| 类型 | 说明 | 1511| --------------------------------------- | ----------------- | 1512| Promise\<Array\<string>> | Promise对象,返回给接口调用方的媒体库文件uri列表。Uri已对appId对应的应用授权,支持应用写入数据。如果生成uri异常,则返回批量创建错误码。<br>返回-3006表不允许出现非法字符;返回-2004表示图片类型和后缀不符;返回-203表示文件操作异常。| 1513 1514**错误码:** 1515 1516接口抛出错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)和[文件管理错误码](../apis-core-file-kit/errorcode-filemanagement.md)。 1517 1518| 错误码ID | 错误信息 | 1519| -------- | ---------------------------------------- | 1520| 201 | Permission denied. | 1521| 202 | Called by non-system application. | 1522| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameters types; 3. Parameter verification failed. | 1523| 14000011 | Internal system error. | 1524 1525**示例:** 1526 1527```ts 1528async function example() { 1529 console.info('createAssetsForAppWithModeDemo.'); 1530 1531 try { 1532 let photoCreationConfigs: Array<photoAccessHelper.PhotoCreationConfig> = [ 1533 { 1534 title: '123456', 1535 fileNameExtension: 'jpg', 1536 photoType: photoAccessHelper.PhotoType.IMAGE, 1537 subtype: photoAccessHelper.PhotoSubtype.DEFAULT, 1538 } 1539 ]; 1540 let bundleName: string = 'testBundleName'; 1541 let appName: string = 'testAppName'; 1542 let appId: string = 'testAppId'; 1543 let tokenId: number = 537197950; 1544 let authorizationMode: photoAccessHelper.AuthorizationMode = photoAccessHelper.AuthorizationMode.SHORT_TIME_AUTHORIZATION; 1545 let result: Array<string> = await phAccessHelper.createAssetsForAppWithMode(bundleName, appName, appId, tokenId, authorizationMode, photoCreationConfigs); 1546 console.info(`result: ${JSON.stringify(result)}`); 1547 console.info('Photo createAssetsForAppWithMode success.'); 1548 } catch (err) { 1549 console.error(`createAssetsForAppWithMode failed with error: ${err.code}, ${err.message}`); 1550 } 1551} 1552``` 1553## PhotoAsset 1554 1555提供封装文件属性的方法。 1556 1557### open<sup>(deprecated)</sup> 1558 1559open(mode: string, callback: AsyncCallback<number>): void 1560 1561打开当前文件,使用callback方式返回异步结果。 1562 1563> **说明:** 1564> 1565> 从API version 10开始支持,从API version 11开始废弃。出于安全考量,不再提供获取正式媒体文件句柄的接口。 1566 1567**注意**:当前此(写)操作是互斥的操作,返回的文件描述符在使用完毕后需要调用close进行释放。 1568 1569**系统接口**:此接口为系统接口。 1570 1571**需要权限**:ohos.permission.READ_IMAGEVIDEO 或 ohos.permission.WRITE_IMAGEVIDEO 1572 1573**系统能力**:SystemCapability.FileManagement.PhotoAccessHelper.Core 1574 1575**参数:** 1576 1577| 参数名 | 类型 | 必填 | 说明 | 1578| -------- | --------------------------- | ---- | ----------------------------------- | 1579| mode | string | 是 | 打开文件方式,分别为:'r'(只读), 'w'(只写), 'rw'(读写)。 | 1580| callback | AsyncCallback<number> | 是 | callback返回文件描述符。 | 1581 1582**错误码:** 1583 1584接口抛出错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)和[文件管理错误码](../apis-core-file-kit/errorcode-filemanagement.md)。 1585 1586| 错误码ID | 错误信息 | 1587| -------- | ---------------------------------------- | 1588| 202 | Called by non-system application. | 1589| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types; 3. Parameter verification failed. | 1590| 13900012 | Permission denied. | 1591| 13900020 | Invalid argument. | 1592| 14000011 | System inner fail. | 1593 1594**示例:** 1595 1596```ts 1597async function example() { 1598 console.info('Open demo'); 1599 let testFileName: string = 'testFile' + Date.now() + '.jpg'; 1600 let photoAsset: photoAccessHelper.PhotoAsset = await phAccessHelper.createAsset(testFileName); 1601 photoAsset.open('rw', (err, fd) => { 1602 if (fd !== undefined) { 1603 console.info('File fd' + fd); 1604 photoAsset.close(fd); 1605 } else { 1606 console.error(`Open file err: ${err.code}, ${err.message}`); 1607 } 1608 }); 1609} 1610``` 1611 1612### open<sup>(deprecated)</sup> 1613 1614open(mode: string): Promise<number> 1615 1616打开当前文件,使用promise方式返回异步结果。 1617 1618> **说明:** 1619> 1620> 从API version 10开始支持,从API version 11开始废弃。出于安全考量,不再提供获取正式媒体文件句柄的接口。 1621 1622**注意**:当前此(写)操作是互斥的操作,返回的文件描述符在使用完毕后需要调用close进行释放。 1623 1624**系统接口**:此接口为系统接口。 1625 1626**需要权限**:ohos.permission.READ_IMAGEVIDEO 或 ohos.permission.WRITE_IMAGEVIDEO 1627 1628**系统能力**:SystemCapability.FileManagement.PhotoAccessHelper.Core 1629 1630**参数:** 1631 1632| 参数名 | 类型 | 必填 | 说明 | 1633| ---- | ------ | ---- | ----------------------------------- | 1634| mode | string | 是 | 打开文件方式,分别为:'r'(只读), 'w'(只写), 'rw'(读写)。 | 1635 1636**返回值:** 1637 1638| 类型 | 说明 | 1639| --------------------- | ------------- | 1640| Promise<number> | Promise对象,返回文件描述符。 | 1641 1642**错误码:** 1643 1644接口抛出错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)和[文件管理错误码](../apis-core-file-kit/errorcode-filemanagement.md)。 1645 1646| 错误码ID | 错误信息 | 1647| -------- | ---------------------------------------- | 1648| 202 | Called by non-system application. | 1649| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types; 3. Parameter verification failed. | 1650| 13900012 | Permission denied. | 1651| 13900020 | Invalid argument. | 1652| 14000011 | System inner fail. | 1653 1654**示例:** 1655 1656```ts 1657async function example() { 1658 console.info('Open demo'); 1659 try { 1660 let testFileName: string = 'testFile' + Date.now() + '.jpg'; 1661 let photoAsset: photoAccessHelper.PhotoAsset = await phAccessHelper.createAsset(testFileName); 1662 let fd: number = await photoAsset.open('rw'); 1663 if (fd !== undefined) { 1664 console.info('File fd' + fd); 1665 photoAsset.close(fd); 1666 } else { 1667 console.error('Open file fail'); 1668 } 1669 } catch (err) { 1670 console.error(`Open demo err: ${err.code}, ${err.message}`); 1671 } 1672} 1673``` 1674 1675### setFavorite<sup>(deprecated)</sup> 1676 1677setFavorite(favoriteState: boolean, callback: AsyncCallback<void>): void 1678 1679将文件设置为收藏文件,使用callback方式返回异步结果。 1680 1681> **说明:** 1682> 1683> 从API version 10开始支持,从API version 11开始废弃。建议使用[MediaAssetChangeRequest.setFavorite](#setfavorite11)替代。 1684 1685**系统接口**:此接口为系统接口。 1686 1687**需要权限**:ohos.permission.WRITE_IMAGEVIDEO 1688 1689**系统能力**:SystemCapability.FileManagement.PhotoAccessHelper.Core 1690 1691**参数:** 1692 1693| 参数名 | 类型 | 必填 | 说明 | 1694| ---------- | ------------------------- | ---- | ---------------------------------- | 1695| favoriteState | boolean | 是 | 是否设置为收藏文件, true:设置为收藏文件,false:取消收藏。 | 1696| callback | AsyncCallback<void> | 是 | callback返回void。 | 1697 1698**错误码:** 1699 1700接口抛出错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)和[文件管理错误码](../apis-core-file-kit/errorcode-filemanagement.md)。 1701 1702| 错误码ID | 错误信息 | 1703| -------- | ---------------------------------------- | 1704| 202 | Called by non-system application. | 1705| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types; 3. Parameter verification failed. | 1706| 13900012 | Permission denied. | 1707| 13900020 | Invalid argument. | 1708| 14000011 | System inner fail. | 1709 1710**示例:** 1711 1712```ts 1713import { dataSharePredicates } from '@kit.ArkData'; 1714 1715async function example() { 1716 console.info('setFavoriteDemo'); 1717 let predicates: dataSharePredicates.DataSharePredicates = new dataSharePredicates.DataSharePredicates(); 1718 let fetchOption: photoAccessHelper.FetchOptions = { 1719 fetchColumns: [], 1720 predicates: predicates 1721 }; 1722 let fetchResult: photoAccessHelper.FetchResult<photoAccessHelper.PhotoAsset> = await phAccessHelper.getAssets(fetchOption); 1723 let asset = await fetchResult.getFirstObject(); 1724 asset.setFavorite(true, (err) => { 1725 if (err === undefined) { 1726 console.info('favorite successfully'); 1727 } else { 1728 console.error(`favorite failed with error: ${err.code}, ${err.message}`); 1729 } 1730 }); 1731} 1732``` 1733 1734### setFavorite<sup>(deprecated)</sup> 1735 1736setFavorite(favoriteState: boolean): Promise<void> 1737 1738将文件设置为收藏文件,使用promise方式返回异步结果。 1739 1740> **说明:** 1741> 1742> 从API version 10开始支持,从API version 11开始废弃。建议使用[MediaAssetChangeRequest.setFavorite](#setfavorite11)替代。 1743 1744**系统接口**:此接口为系统接口。 1745 1746**需要权限**:ohos.permission.WRITE_IMAGEVIDEO 1747 1748**系统能力**:SystemCapability.FileManagement.PhotoAccessHelper.Core 1749 1750**参数:** 1751 1752| 参数名 | 类型 | 必填 | 说明 | 1753| ---------- | ------- | ---- | ---------------------------------- | 1754| favoriteState | boolean | 是 | 是否设置为收藏文件, true:设置为收藏文件,false:取消收藏。 | 1755 1756**返回值:** 1757 1758| 类型 | 说明 | 1759| ------------------- | ---------- | 1760| Promise<void> | Promise对象,返回void。 | 1761 1762**错误码:** 1763 1764接口抛出错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)和[文件管理错误码](../apis-core-file-kit/errorcode-filemanagement.md)。 1765 1766| 错误码ID | 错误信息 | 1767| -------- | ---------------------------------------- | 1768| 202 | Called by non-system application. | 1769| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types; 3. Parameter verification failed. | 1770| 13900012 | Permission denied. | 1771| 13900020 | Invalid argument. | 1772| 14000011 | System inner fail. | 1773 1774**示例:** 1775 1776```ts 1777import { dataSharePredicates } from '@kit.ArkData'; 1778import { BusinessError } from '@kit.BasicServicesKit'; 1779 1780async function example() { 1781 console.info('setFavoriteDemo'); 1782 let predicates: dataSharePredicates.DataSharePredicates = new dataSharePredicates.DataSharePredicates(); 1783 let fetchOption: photoAccessHelper.FetchOptions = { 1784 fetchColumns: [], 1785 predicates: predicates 1786 }; 1787 let fetchResult: photoAccessHelper.FetchResult<photoAccessHelper.PhotoAsset> = await phAccessHelper.getAssets(fetchOption); 1788 let asset = await fetchResult.getFirstObject(); 1789 asset.setFavorite(true).then(() => { 1790 console.info('setFavorite successfully'); 1791 }).catch((err: BusinessError) => { 1792 console.error(`setFavorite failed with error: ${err.code}, ${err.message}`); 1793 }); 1794} 1795``` 1796 1797### setHidden<sup>(deprecated)</sup> 1798 1799setHidden(hiddenState: boolean, callback: AsyncCallback<void>): void 1800 1801将文件设置为隐私文件,使用callback方式返回异步结果。 1802 1803隐私文件存在隐私相册中,用户通过隐私相册去获取隐私文件后可以通过设置hiddenState为false来从隐私相册中移除。 1804 1805> **说明:** 1806> 1807> 从API version 10开始支持,从API version 11开始废弃。建议使用[MediaAssetChangeRequest.setHidden](#sethidden11)替代。 1808 1809**系统接口**:此接口为系统接口。 1810 1811**需要权限**:ohos.permission.WRITE_IMAGEVIDEO 1812 1813**系统能力**:SystemCapability.FileManagement.PhotoAccessHelper.Core 1814 1815**参数:** 1816 1817| 参数名 | 类型 | 必填 | 说明 | 1818| ---------- | ------------------------- | ---- | ---------------------------------- | 1819| hiddenState | boolean | 是 | 是否设置为隐藏文件,true:将文件资产放入隐藏相册;false:从隐藏相册中恢复。 | 1820| callback | AsyncCallback<void> | 是 | callback返回void。 | 1821 1822**错误码:** 1823 1824接口抛出错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)和[文件管理错误码](../apis-core-file-kit/errorcode-filemanagement.md)。 1825 1826| 错误码ID | 错误信息 | 1827| -------- | ---------------------------------------- | 1828| 202 | Called by non-system application. | 1829| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types; 3. Parameter verification failed. | 1830| 13900012 | Permission denied. | 1831| 13900020 | Invalid argument. | 1832| 14000011 | System inner fail. | 1833 1834**示例:** 1835 1836```ts 1837import { dataSharePredicates } from '@kit.ArkData'; 1838 1839async function example() { 1840 console.info('setHiddenDemo'); 1841 let predicates: dataSharePredicates.DataSharePredicates = new dataSharePredicates.DataSharePredicates(); 1842 let fetchOption: photoAccessHelper.FetchOptions = { 1843 fetchColumns: [], 1844 predicates: predicates 1845 }; 1846 let fetchResult: photoAccessHelper.FetchResult<photoAccessHelper.PhotoAsset> = await phAccessHelper.getAssets(fetchOption); 1847 let asset = await fetchResult.getFirstObject(); 1848 asset.setHidden(true, (err) => { 1849 if (err === undefined) { 1850 console.info('setHidden successfully'); 1851 } else { 1852 console.error(`setHidden failed with error: ${err.code}, ${err.message}`); 1853 } 1854 }); 1855} 1856``` 1857 1858### setHidden<sup>(deprecated)</sup> 1859 1860setHidden(hiddenState: boolean): Promise<void> 1861 1862将文件设置为隐私文件,使用promise方式返回异步结果。 1863 1864隐私文件存在隐私相册中,用户通过隐私相册去获取隐私文件后可以通过设置hiddenState为false来从隐私相册中移除。 1865 1866> **说明:** 1867> 1868> 从API version 10开始支持,从API version 11开始废弃。建议使用[MediaAssetChangeRequest.setHidden](#sethidden11)替代。 1869 1870**系统接口**:此接口为系统接口。 1871 1872**需要权限**:ohos.permission.WRITE_IMAGEVIDEO 1873 1874**系统能力**:SystemCapability.FileManagement.PhotoAccessHelper.Core 1875 1876**参数:** 1877 1878| 参数名 | 类型 | 必填 | 说明 | 1879| ---------- | ------- | ---- | ---------------------------------- | 1880| hiddenState | boolean | 是 | 是否设置为隐藏文件,true:将文件资产放入隐藏相册;false:从隐藏相册中恢复。 | 1881 1882**返回值:** 1883 1884| 类型 | 说明 | 1885| ------------------- | ---------- | 1886| Promise<void> | Promise对象,返回void。 | 1887 1888**错误码:** 1889 1890接口抛出错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)和[文件管理错误码](../apis-core-file-kit/errorcode-filemanagement.md)。 1891 1892| 错误码ID | 错误信息 | 1893| -------- | ---------------------------------------- | 1894| 202 | Called by non-system application. | 1895| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types; 3. Parameter verification failed. | 1896| 13900012 | Permission denied. | 1897| 13900020 | Invalid argument. | 1898| 14000011 | System inner fail. | 1899 1900**示例:** 1901 1902```ts 1903import { dataSharePredicates } from '@kit.ArkData'; 1904import { BusinessError } from '@kit.BasicServicesKit'; 1905 1906async function example() { 1907 // 示例代码为将文件从隐藏相册中恢复,需要先在隐藏相册预置资源。 1908 console.info('setHiddenDemo'); 1909 let predicates: dataSharePredicates.DataSharePredicates = new dataSharePredicates.DataSharePredicates(); 1910 let fetchOption: photoAccessHelper.FetchOptions = { 1911 fetchColumns: [], 1912 predicates: predicates 1913 }; 1914 let albumList: photoAccessHelper.FetchResult<photoAccessHelper.Album> = await phAccessHelper.getAlbums(photoAccessHelper.AlbumType.SYSTEM, photoAccessHelper.AlbumSubtype.HIDDEN); 1915 let album = await albumList.getFirstObject(); 1916 let fetchResult: photoAccessHelper.FetchResult<photoAccessHelper.PhotoAsset> = await album.getAssets(fetchOption); 1917 let asset = await fetchResult.getFirstObject(); 1918 asset.setHidden(false).then(() => { 1919 console.info('setHidden successfully'); 1920 }).catch((err: BusinessError) => { 1921 console.error(`setHidden failed with error: ${err.code}, ${err.message}`); 1922 }); 1923} 1924``` 1925 1926### getExif 1927 1928getExif(): Promise<string> 1929 1930返回jpg格式图片Exif标签组成的json格式的字符串,该方法使用Promise方式返回结果。 1931 1932此接口中获取的Exif标签信息是由[image](../apis-image-kit/js-apis-image.md)模块提供。Exif标签详细信息请参考[image.PropertyKey](../apis-image-kit/js-apis-image.md#propertykey7)。 1933 1934**注意**:此接口返回的是Exif标签组成的json格式的字符串,完整Exif信息由all_exif与[PhotoKeys.USER_COMMENT](#photokeys)组成,fetchColumns需要传入这两个字段。 1935 1936**系统接口**:此接口为系统接口。 1937 1938**需要权限**:ohos.permission.READ_IMAGEVIDEO 1939 1940**系统能力**:SystemCapability.FileManagement.PhotoAccessHelper.Core 1941 1942**返回值:** 1943 1944| 类型 | 说明 | 1945| --------------------------------------- | ----------------- | 1946| Promise<string> | 返回Exif标签组成的json格式的字符串。 | 1947 1948**错误码:** 1949 1950接口抛出错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)和[文件管理错误码](../apis-core-file-kit/errorcode-filemanagement.md)。 1951 1952| 错误码ID | 错误信息 | 1953| -------- | ---------------------------------------- | 1954| 202 | Called by non-system application. | 1955| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types. | 1956| 13900012 | Permission denied. | 1957| 13900020 | Invalid argument. | 1958| 14000011 | System inner fail. | 1959 1960**示例:** 1961 1962```ts 1963import { dataSharePredicates } from '@kit.ArkData'; 1964 1965async function example() { 1966 try { 1967 console.info('getExifDemo'); 1968 let predicates: dataSharePredicates.DataSharePredicates = new dataSharePredicates.DataSharePredicates(); 1969 let fetchOptions: photoAccessHelper.FetchOptions = { 1970 fetchColumns: [ 'all_exif', photoAccessHelper.PhotoKeys.USER_COMMENT], 1971 predicates: predicates 1972 }; 1973 let fetchResult: photoAccessHelper.FetchResult<photoAccessHelper.PhotoAsset> = await phAccessHelper.getAssets(fetchOptions); 1974 let photoAsset: photoAccessHelper.PhotoAsset = await fetchResult.getFirstObject(); 1975 let exifMessage = await photoAsset.getExif(); 1976 let userCommentKey = 'UserComment'; 1977 let userComment = JSON.stringify(JSON.parse(exifMessage), [userCommentKey]); 1978 console.info('getExifDemo userComment: ' + JSON.stringify(userComment)); 1979 fetchResult.close(); 1980 } catch (err) { 1981 console.error(`getExifDemoCallback failed with error: ${err.code}, ${err.message}`); 1982 } 1983} 1984``` 1985 1986### getExif 1987 1988getExif(callback: AsyncCallback<string>): void 1989 1990返回jpg格式图片Exif标签组成的json格式的字符串,使用callback方式返回异步结果。 1991 1992此接口中获取的Exif标签信息是由[image](../apis-image-kit/js-apis-image.md)模块提供。Exif标签详细信息请参考[image.PropertyKey](../apis-image-kit/js-apis-image.md#propertykey7)。 1993 1994**注意**:此接口返回的是Exif标签组成的json格式的字符串,完整Exif信息由all_exif与[PhotoKeys.USER_COMMENT](#photokeys)组成,fetchColumns需要传入这两个字段。 1995 1996**系统接口**:此接口为系统接口。 1997 1998**需要权限**:ohos.permission.READ_IMAGEVIDEO 1999 2000**系统能力**:SystemCapability.FileManagement.PhotoAccessHelper.Core 2001 2002**参数:** 2003 2004| 参数名 | 类型 | 必填 | 说明 | 2005| -------- | ------------------------- | ---- | ---------- | 2006| callback | AsyncCallback<string> | 是 | 返回Exif字段组成的json格式的字符串。 | 2007 2008**错误码:** 2009 2010接口抛出错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)和[文件管理错误码](../apis-core-file-kit/errorcode-filemanagement.md)。 2011 2012| 错误码ID | 错误信息 | 2013| -------- | ---------------------------------------- | 2014| 202 | Called by non-system application. | 2015| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types. | 2016| 13900012 | Permission denied. | 2017| 13900020 | Invalid argument. | 2018| 14000011 | System inner fail. | 2019 2020**示例:** 2021 2022```ts 2023import { dataSharePredicates } from '@kit.ArkData'; 2024 2025async function example() { 2026 try { 2027 console.info('getExifDemo'); 2028 let predicates: dataSharePredicates.DataSharePredicates = new dataSharePredicates.DataSharePredicates(); 2029 predicates.isNotNull('all_exif') 2030 let fetchOptions: photoAccessHelper.FetchOptions = { 2031 fetchColumns: ['all_exif', photoAccessHelper.PhotoKeys.USER_COMMENT], 2032 predicates: predicates 2033 }; 2034 let fetchResult: photoAccessHelper.FetchResult<photoAccessHelper.PhotoAsset> = await phAccessHelper.getAssets(fetchOptions); 2035 let photoAsset: photoAccessHelper.PhotoAsset = await fetchResult.getFirstObject(); 2036 console.info('getExifDemo photoAsset displayName: ' + JSON.stringify(photoAsset.displayName)); 2037 let userCommentKey = 'UserComment'; 2038 photoAsset.getExif((err, exifMessage) => { 2039 if (exifMessage !== undefined) { 2040 let userComment = JSON.stringify(JSON.parse(exifMessage), [userCommentKey]); 2041 console.info('getExifDemo userComment: ' + JSON.stringify(userComment)); 2042 } else { 2043 console.error(`getExif failed, error: ${err.code}, ${err.message}`); 2044 } 2045 }); 2046 fetchResult.close(); 2047 } catch (err) { 2048 console.error(`getExifDemoCallback failed with error: ${err.code}, ${err.message}`); 2049 } 2050} 2051``` 2052 2053### setUserComment<sup>(deprecated)</sup> 2054 2055setUserComment(userComment: string): Promise<void> 2056 2057修改图片或者视频的备注信息,该方法使用Promise来返回结果。 2058 2059> **说明:** 2060> 2061> 从API version 10开始支持,从API version 11开始废弃。建议使用[MediaAssetChangeRequest.setUserComment](#setusercomment11)替代。 2062 2063**注意**:此接口只可修改图片或者视频的备注信息。 2064 2065**系统接口**:此接口为系统接口。 2066 2067**需要权限**:ohos.permission.WRITE_IMAGEVIDEO 2068 2069**系统能力**:SystemCapability.FileManagement.PhotoAccessHelper.Core 2070 2071**参数:** 2072 2073| 参数名 | 类型 | 必填 | 说明 | 2074| -------- | ------------------------- | ---- | ---------- | 2075| userComment | string | 是 | 待修改的图片或视频的备注信息,备注信息最长为420字符。 | 2076 2077**返回值:** 2078 2079| 类型 | 说明 | 2080| --------------------------------------- | ----------------- | 2081|Promise<void> | Promise对象,返回void。 | 2082 2083**错误码:** 2084 2085接口抛出错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)和[文件管理错误码](../apis-core-file-kit/errorcode-filemanagement.md)。 2086 2087| 错误码ID | 错误信息 | 2088| -------- | ---------------------------------------- | 2089| 202 | Called by non-system application. | 2090| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types; 3. Parameter verification failed. | 2091| 13900012 | Permission denied. | 2092| 13900020 | Invalid argument. | 2093| 14000011 | System inner fail. | 2094 2095**示例:** 2096 2097```ts 2098import { dataSharePredicates } from '@kit.ArkData'; 2099 2100async function example() { 2101 try { 2102 console.info('setUserCommentDemo') 2103 let predicates: dataSharePredicates.DataSharePredicates = new dataSharePredicates.DataSharePredicates(); 2104 let fetchOptions: photoAccessHelper.FetchOptions = { 2105 fetchColumns: [], 2106 predicates: predicates 2107 }; 2108 let fetchResult: photoAccessHelper.FetchResult<photoAccessHelper.PhotoAsset> = await phAccessHelper.getAssets(fetchOptions); 2109 let photoAsset: photoAccessHelper.PhotoAsset = await fetchResult.getFirstObject(); 2110 let userComment = 'test_set_user_comment'; 2111 await photoAsset.setUserComment(userComment); 2112 } catch (err) { 2113 console.error(`setUserCommentDemoPromise failed with error: ${err.code}, ${err.message}`); 2114 } 2115} 2116``` 2117 2118### setUserComment<sup>(deprecated)</sup> 2119 2120setUserComment(userComment: string, callback: AsyncCallback<void>): void 2121 2122修改图片或者视频的备注信息,该方法使用callback形式来返回结果。 2123 2124> **说明:** 2125> 2126> 从API version 10开始支持,从API version 11开始废弃。建议使用[MediaAssetChangeRequest.setUserComment](#setusercomment11)替代。 2127 2128**注意**:此接口只可修改图片或者视频的备注信息。 2129 2130**系统接口**:此接口为系统接口。 2131 2132**需要权限**:ohos.permission.WRITE_IMAGEVIDEO 2133 2134**系统能力**:SystemCapability.FileManagement.PhotoAccessHelper.Core 2135 2136**参数:** 2137 2138| 参数名 | 类型 | 必填 | 说明 | 2139| -------- | ------------------------- | ---- | ---------- | 2140| userComment | string | 是 | 待修改的图片或视频的备注信息,备注信息最长为420字符。 | 2141| callback | AsyncCallback<void> | 是 | callback返回void。 | 2142 2143**错误码:** 2144 2145接口抛出错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)和[文件管理错误码](../apis-core-file-kit/errorcode-filemanagement.md)。 2146 2147| 错误码ID | 错误信息 | 2148| -------- | ---------------------------------------- | 2149| 202 | Called by non-system application. | 2150| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types; 3. Parameter verification failed. | 2151| 13900012 | Permission denied. | 2152| 13900020 | Invalid argument. | 2153| 14000011 | System inner fail. | 2154 2155**示例:** 2156 2157```ts 2158import { dataSharePredicates } from '@kit.ArkData'; 2159 2160async function example() { 2161 try { 2162 console.info('setUserCommentDemo') 2163 let predicates: dataSharePredicates.DataSharePredicates = new dataSharePredicates.DataSharePredicates(); 2164 let fetchOptions: photoAccessHelper.FetchOptions = { 2165 fetchColumns: [], 2166 predicates: predicates 2167 }; 2168 let fetchResult: photoAccessHelper.FetchResult<photoAccessHelper.PhotoAsset> = await phAccessHelper.getAssets(fetchOptions); 2169 let photoAsset: photoAccessHelper.PhotoAsset = await fetchResult.getFirstObject(); 2170 let userComment = 'test_set_user_comment'; 2171 photoAsset.setUserComment(userComment, (err) => { 2172 if (err === undefined) { 2173 console.info('setUserComment successfully'); 2174 } else { 2175 console.error(`setUserComment failed with error: ${err.code}, ${err.message}`); 2176 } 2177 }); 2178 } catch (err) { 2179 console.error(`setUserCommentDemoCallback failed with error: ${err.code}, ${err.message}`); 2180 } 2181} 2182``` 2183 2184### setPending<sup>11+</sup> 2185 2186setPending(pendingState: boolean, callback: AsyncCallback<void>): void 2187 2188为图片或视频资源设置pending状态,该方法使用callback形式来返回结果。 2189 2190将文件通过`setPending(true)`设置为pending状态后,只能通过`setPending(false)`解除pending状态。可以通过`photoAsset.get(photoAccessHelper.PhotoKeys.PENDING)`的方式获取是否为pending状态,pending状态下返回true,否则返回false。 2191 2192**注意**:setPending只能在文件的创建期使用,在文件的首次创建流程的close之后,无法通过setPending(true)将文件设置为pending状态。 2193 2194**系统接口**:此接口为系统接口。 2195 2196**需要权限**:ohos.permission.WRITE_IMAGEVIDEO 2197 2198**系统能力**:SystemCapability.FileManagement.PhotoAccessHelper.Core 2199 2200**参数:** 2201 2202| 参数名 | 类型 | 必填 | 说明 | 2203| ---------- | ------- | ---- | ---------------------------------- | 2204| pendingState | boolean | 是 | 设置的pending状态,true为设置pending状态,false为解除pending状态。 | 2205| callback | AsyncCallback<void> | 是 | Callback对象,返回void。 | 2206 2207**错误码:** 2208 2209接口抛出错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)和[文件管理错误码](../apis-core-file-kit/errorcode-filemanagement.md)。 2210 2211| 错误码ID | 错误信息 | 2212| -------- | ---------------------------------------- | 2213| 201 | Permission denied. | 2214| 202 | Called by non-system application. | 2215| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types; 3. Parameter verification failed. | 2216| 14000011 | System inner fail. | 2217 2218**示例:** 2219 2220```ts 2221async function example() { 2222 try { 2223 console.info('setPendingCallbackDemo'); 2224 let testFileName: string = 'testFile' + Date.now() + '.jpg'; 2225 let photoAsset = await phAccessHelper.createAsset(testFileName); 2226 let fd = await photoAsset.open('rw'); 2227 photoAsset.setPending(true, async (err) => { 2228 if (err !== undefined) { 2229 console.error(`setPending(true) failed with error: ${err.code}, ${err.message}`); 2230 return; 2231 } 2232 // write photo buffer in fd. 2233 photoAsset.setPending(false, async (err) => { 2234 if (err !== undefined) { 2235 console.error(`setPending(false) failed with error: ${err.code}, ${err.message}`); 2236 return; 2237 } 2238 await photoAsset.close(fd); 2239 }); 2240 }); 2241 } catch (err) { 2242 console.error(`setPendingCallbackDemo failed with error: ${err.code}, ${err.message}`); 2243 } 2244} 2245``` 2246 2247### setPending<sup>11+</sup> 2248 2249setPending(pendingState: boolean): Promise<void> 2250 2251为图片或视频资源设置pending状态,该方法使用promise形式来返回结果。 2252 2253将文件通过`setPending(true)`设置为pending状态后,只能通过`setPending(false)`解除pending状态。可以通过`photoAsset.get(photoAccessHelper.PhotoKeys.PENDING)`的方式获取是否为pending状态,pending状态下返回true,否则返回false。 2254 2255**注意**:setPending只能在文件的创建期使用,在文件的首次创建流程的close之后,无法通过setPending(true)将文件设置为pending状态。 2256 2257**系统接口**:此接口为系统接口。 2258 2259**需要权限**:ohos.permission.WRITE_IMAGEVIDEO 2260 2261**系统能力**:SystemCapability.FileManagement.PhotoAccessHelper.Core 2262 2263**参数:** 2264 2265| 参数名 | 类型 | 必填 | 说明 | 2266| ---------- | ------- | ---- | ---------------------------------- | 2267| pendingState | boolean | 是 | 设置的pending状态,true为设置pending状态,false为解除pending状态。 | 2268 2269**返回值:** 2270 2271| 类型 | 说明 | 2272| --------------------------------------- | ----------------- | 2273|Promise<boolean> | Promise对象,返回void。 | 2274 2275**错误码:** 2276 2277接口抛出错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)和[文件管理错误码](../apis-core-file-kit/errorcode-filemanagement.md)。 2278 2279| 错误码ID | 错误信息 | 2280| -------- | ---------------------------------------- | 2281| 201 | Permission denied. | 2282| 202 | Called by non-system application. | 2283| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types; 3. Parameter verification failed. | 2284| 14000011 | System inner fail. | 2285 2286**示例:** 2287 2288```ts 2289async function example() { 2290 try { 2291 console.info('setPendingPromiseDemo'); 2292 let testFileName: string = 'testFile' + Date.now() + '.jpg'; 2293 let photoAsset = await phAccessHelper.createAsset(testFileName); 2294 let fd = await photoAsset.open('rw'); 2295 await photoAsset.setPending(true); 2296 // write photo buffer in fd. 2297 photoAsset.setPending(false); 2298 await photoAsset.close(fd); 2299 } catch (err) { 2300 console.error(`setPendingPromiseDemo failed with error: ${err.code}, ${err.message}`); 2301 } 2302} 2303``` 2304 2305### isEdited<sup>11+</sup> 2306 2307isEdited(callback: AsyncCallback<boolean>): void 2308 2309查询图片或视频资源是否被编辑过,该方法使用callback形式来返回结果。 2310 2311**系统接口**:此接口为系统接口。 2312 2313**需要权限**:ohos.permission.READ_IMAGEVIDEO 2314 2315**系统能力**:SystemCapability.FileManagement.PhotoAccessHelper.Core 2316 2317**参数:** 2318 2319| 参数名 | 类型 | 必填 | 说明 | 2320| ---------- | ------- | ---- | ---------------------------------- | 2321| callback | AsyncCallback<boolean> | 是 | Callback对象,返回图片或视频资源是否被编辑过。 | 2322 2323**错误码:** 2324 2325接口抛出错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)和[文件管理错误码](../apis-core-file-kit/errorcode-filemanagement.md)。 2326 2327| 错误码ID | 错误信息 | 2328| -------- | ---------------------------------------- | 2329| 201 | Permission denied. | 2330| 202 | Called by non-system application. | 2331| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types. | 2332| 14000011 | System inner fail. | 2333 2334**示例:** 2335 2336```ts 2337import { dataSharePredicates } from '@kit.ArkData'; 2338 2339async function example() { 2340 try { 2341 console.info('isEditedCallbackDemo') 2342 let predicates: dataSharePredicates.DataSharePredicates = new dataSharePredicates.DataSharePredicates(); 2343 let fetchOptions: photoAccessHelper.FetchOptions = { 2344 fetchColumns: [], 2345 predicates: predicates 2346 }; 2347 let fetchResult: photoAccessHelper.FetchResult<photoAccessHelper.PhotoAsset> = await phAccessHelper.getAssets(fetchOptions); 2348 let photoAsset: photoAccessHelper.PhotoAsset = await fetchResult.getFirstObject(); 2349 photoAsset.isEdited((err, isEdited) => { 2350 if (err === undefined) { 2351 if (isEdited === true) { 2352 console.info('Photo is edited'); 2353 } else { 2354 console.info('Photo is not edited'); 2355 } 2356 } else { 2357 console.error(`isEdited failed with error: ${err.code}, ${err.message}`); 2358 } 2359 }); 2360 } catch (err) { 2361 console.error(`isEditedDemoCallback failed with error: ${err.code}, ${err.message}`); 2362 } 2363} 2364``` 2365 2366### isEdited<sup>11+</sup> 2367 2368isEdited(): Promise<boolean> 2369 2370查询图片或视频资源是否被编辑过,该方法使用promise形式来返回结果。 2371 2372**系统接口**:此接口为系统接口。 2373 2374**需要权限**:ohos.permission.READ_IMAGEVIDEO 2375 2376**系统能力**:SystemCapability.FileManagement.PhotoAccessHelper.Core 2377 2378**返回值:** 2379 2380| 类型 | 说明 | 2381| --------------------------------------- | ----------------- | 2382|Promise<boolean> | Promise对象,返回图片或视频资源是否被编辑过。 | 2383 2384 2385**错误码:** 2386 2387接口抛出错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)和[文件管理错误码](../apis-core-file-kit/errorcode-filemanagement.md)。 2388 2389| 错误码ID | 错误信息 | 2390| -------- | ---------------------------------------- | 2391| 201 | Permission denied. | 2392| 202 | Called by non-system application. | 2393| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types. | 2394| 14000011 | System inner fail. | 2395 2396**示例:** 2397 2398```ts 2399import { dataSharePredicates } from '@kit.ArkData'; 2400 2401async function example() { 2402 try { 2403 console.info('isEditedPromiseDemo') 2404 let predicates: dataSharePredicates.DataSharePredicates = new dataSharePredicates.DataSharePredicates(); 2405 let fetchOptions: photoAccessHelper.FetchOptions = { 2406 fetchColumns: [], 2407 predicates: predicates 2408 }; 2409 let fetchResult: photoAccessHelper.FetchResult<photoAccessHelper.PhotoAsset> = await phAccessHelper.getAssets(fetchOptions); 2410 let photoAsset: photoAccessHelper.PhotoAsset = await fetchResult.getFirstObject(); 2411 let isEdited = await photoAsset.isEdited(); 2412 if (isEdited === true) { 2413 console.info('Photo is edited'); 2414 } else { 2415 console.info('Photo is not edited'); 2416 } 2417 } catch (err) { 2418 console.error(`isEditedDemoCallback failed with error: ${err.code}, ${err.message}`); 2419 } 2420} 2421``` 2422 2423### requestEditData<sup>11+</sup> 2424 2425requestEditData(callback: AsyncCallback<string>): void 2426 2427获得图片或视频资源的编辑数据,该方法使用callback形式来返回结果。 2428 2429如果资源未编辑过,则返回一个空字符串。 2430 2431**系统接口**:此接口为系统接口。 2432 2433**需要权限**:ohos.permission.READ_IMAGEVIDEO 2434 2435**系统能力**:SystemCapability.FileManagement.PhotoAccessHelper.Core 2436 2437**参数:** 2438 2439| 参数名 | 类型 | 必填 | 说明 | 2440| ---------- | ------- | ---- | ---------------------------------- | 2441| callback | AsyncCallback<string> | 是 | Callback对象,返回图片或视频资源的编辑数据。 | 2442 2443**错误码:** 2444 2445接口抛出错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)和[文件管理错误码](../apis-core-file-kit/errorcode-filemanagement.md)。 2446 2447| 错误码ID | 错误信息 | 2448| -------- | ---------------------------------------- | 2449| 201 | Permission denied. | 2450| 202 | Called by non-system application. | 2451| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types. | 2452| 14000011 | System inner fail. | 2453 2454**示例:** 2455 2456```ts 2457import { dataSharePredicates } from '@kit.ArkData'; 2458 2459async function example() { 2460 try { 2461 console.info('requestEditDataCallbackDemo') 2462 let predicates: dataSharePredicates.DataSharePredicates = new dataSharePredicates.DataSharePredicates(); 2463 let fetchOptions: photoAccessHelper.FetchOptions = { 2464 fetchColumns: [], 2465 predicates: predicates 2466 }; 2467 let fetchResult: photoAccessHelper.FetchResult<photoAccessHelper.PhotoAsset> = await phAccessHelper.getAssets(fetchOptions); 2468 let photoAsset: photoAccessHelper.PhotoAsset = await fetchResult.getFirstObject(); 2469 photoAsset.requestEditData((err, editdata) => { 2470 if (err === undefined) { 2471 console.info('Editdata is ' + editdata); 2472 } else { 2473 console.error(`requestEditData failed with error: ${err.code}, ${err.message}`); 2474 } 2475 }); 2476 } catch (err) { 2477 console.error(`requestEditDataCallbackDemo failed with error: ${err.code}, ${err.message}`); 2478 } 2479} 2480``` 2481 2482### requestEditData<sup>11+</sup> 2483 2484requestEditData(): Promise<string> 2485 2486获得图片或视频资源的编辑数据,该方法使用promise形式来返回结果。 2487 2488如果资源未编辑过,则返回一个空字符串。 2489 2490**系统接口**:此接口为系统接口。 2491 2492**需要权限**:ohos.permission.READ_IMAGEVIDEO 2493 2494**系统能力**:SystemCapability.FileManagement.PhotoAccessHelper.Core 2495 2496**返回值:** 2497 2498| 类型 | 说明 | 2499| --------------------------------------- | ----------------- | 2500|Promise<string> | Promise对象,返回图片或视频资源的编辑数据。 | 2501 2502 2503**错误码:** 2504 2505接口抛出错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)和[文件管理错误码](../apis-core-file-kit/errorcode-filemanagement.md)。 2506 2507| 错误码ID | 错误信息 | 2508| -------- | ---------------------------------------- | 2509| 201 | Permission denied. | 2510| 202 | Called by non-system application. | 2511| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types. | 2512| 14000011 | System inner fail. | 2513 2514**示例:** 2515 2516```ts 2517import { dataSharePredicates } from '@kit.ArkData'; 2518 2519async function example() { 2520 try { 2521 console.info('requestEditDataPromiseDemo') 2522 let predicates: dataSharePredicates.DataSharePredicates = new dataSharePredicates.DataSharePredicates(); 2523 let fetchOptions: photoAccessHelper.FetchOptions = { 2524 fetchColumns: [], 2525 predicates: predicates 2526 }; 2527 let fetchResult: photoAccessHelper.FetchResult<photoAccessHelper.PhotoAsset> = await phAccessHelper.getAssets(fetchOptions); 2528 let photoAsset: photoAccessHelper.PhotoAsset = await fetchResult.getFirstObject(); 2529 let editdata: string = await photoAsset.requestEditData(); 2530 console.info('Editdata is ' + editdata); 2531 } catch (err) { 2532 console.error(`requestEditDataPromiseDemo failed with error: ${err.code}, ${err.message}`); 2533 } 2534} 2535``` 2536 2537### getEditData<sup>11+</sup> 2538 2539getEditData(): Promise<MediaAssetEditData> 2540 2541获得资产编辑数据,该方法使用promise形式来返回结果。 2542 2543如果资源未编辑过,则返回的编辑数据的内容为空字符串。 2544 2545**系统接口**:此接口为系统接口。 2546 2547**需要权限**:ohos.permission.READ_IMAGEVIDEO 2548 2549**系统能力**:SystemCapability.FileManagement.PhotoAccessHelper.Core 2550 2551**返回值:** 2552 2553| 类型 | 说明 | 2554| --------------------------------------- | ----------------- | 2555|Promise<[MediaAssetEditData](#mediaasseteditdata11)> | Promise对象,返回资产编辑数据。 | 2556 2557**错误码:** 2558 2559接口抛出错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)和[文件管理错误码](../apis-core-file-kit/errorcode-filemanagement.md)。 2560 2561| 错误码ID | 错误信息 | 2562| -------- | ---------------------------------------- | 2563| 201 | Permission denied. | 2564| 202 | Called by non-system application. | 2565| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types. | 2566| 14000011 | System inner fail. | 2567 2568**示例:** 2569 2570```ts 2571import { dataSharePredicates } from '@kit.ArkData'; 2572 2573async function example() { 2574 try { 2575 console.info('getEditDataDemo') 2576 let predicates: dataSharePredicates.DataSharePredicates = new dataSharePredicates.DataSharePredicates(); 2577 let fetchOptions: photoAccessHelper.FetchOptions = { 2578 fetchColumns: [], 2579 predicates: predicates 2580 }; 2581 let fetchResult: photoAccessHelper.FetchResult<photoAccessHelper.PhotoAsset> = await phAccessHelper.getAssets(fetchOptions); 2582 let photoAsset: photoAccessHelper.PhotoAsset = await fetchResult.getFirstObject(); 2583 let assetEditData: photoAccessHelper.MediaAssetEditData = await photoAsset.getEditData(); 2584 let data: string = assetEditData.data; 2585 console.info('edit data is ' + data); 2586 } catch (err) { 2587 console.error(`getEditDataDemo failed with error: ${err.code}, ${err.message}`); 2588 } 2589} 2590``` 2591 2592### requestSource<sup>11+</sup> 2593 2594requestSource(callback: AsyncCallback<number>): void 2595 2596打开源文件并返回fd,该方法使用callback形式来返回结果。 2597 2598**系统接口**:此接口为系统接口。 2599 2600**需要权限**:ohos.permission.READ_IMAGEVIDEO 2601 2602**系统能力**:SystemCapability.FileManagement.PhotoAccessHelper.Core 2603 2604**参数:** 2605 2606| 参数名 | 类型 | 必填 | 说明 | 2607| ---------- | ------- | ---- | ---------------------------------- | 2608| callback | AsyncCallback<number> | 是 | Callback对象,返回源文件fd。 | 2609 2610**错误码:** 2611 2612接口抛出错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)和[文件管理错误码](../apis-core-file-kit/errorcode-filemanagement.md)。 2613 2614| 错误码ID | 错误信息 | 2615| -------- | ---------------------------------------- | 2616| 201 | Permission denied. | 2617| 202 | Called by non-system application. | 2618| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types. | 2619| 14000011 | System inner fail. | 2620 2621**示例:** 2622 2623```ts 2624import { dataSharePredicates } from '@kit.ArkData'; 2625 2626async function example() { 2627 try { 2628 console.info('requsetSourceCallbackDemo') 2629 let predicates: dataSharePredicates.DataSharePredicates = new dataSharePredicates.DataSharePredicates(); 2630 let fetchOptions: photoAccessHelper.FetchOptions = { 2631 fetchColumns: [], 2632 predicates: predicates 2633 }; 2634 let fetchResult: photoAccessHelper.FetchResult<photoAccessHelper.PhotoAsset> = await phAccessHelper.getAssets(fetchOptions); 2635 let photoAsset: photoAccessHelper.PhotoAsset = await fetchResult.getFirstObject(); 2636 photoAsset.requestSource((err, fd) => { 2637 if (err === undefined) { 2638 console.info('Source fd is ' + fd); 2639 } else { 2640 console.error(`requestSource failed with error: ${err.code}, ${err.message}`); 2641 } 2642 }); 2643 } catch (err) { 2644 console.error(`requsetSourceCallbackDemo failed with error: ${err.code}, ${err.message}`); 2645 } 2646} 2647``` 2648 2649### requestSource<sup>11+</sup> 2650 2651requestSource(): Promise<number> 2652 2653打开源文件并返回fd,该方法使用promise形式来返回结果。 2654 2655**系统接口**:此接口为系统接口。 2656 2657**需要权限**:ohos.permission.READ_IMAGEVIDEO 2658 2659**系统能力**:SystemCapability.FileManagement.PhotoAccessHelper.Core 2660 2661**返回值:** 2662 2663| 类型 | 说明 | 2664| --------------------------------------- | ----------------- | 2665|Promise<number> | Promise对象,返回源文件fd。 | 2666 2667**错误码:** 2668 2669接口抛出错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)和[文件管理错误码](../apis-core-file-kit/errorcode-filemanagement.md)。 2670 2671| 错误码ID | 错误信息 | 2672| -------- | ---------------------------------------- | 2673| 201 | Permission denied. | 2674| 202 | Called by non-system application. | 2675| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types. | 2676| 14000011 | System inner fail. | 2677 2678**示例:** 2679 2680```ts 2681import { dataSharePredicates } from '@kit.ArkData'; 2682 2683async function example() { 2684 try { 2685 console.info('requsetSourcePromiseDemo') 2686 let predicates: dataSharePredicates.DataSharePredicates = new dataSharePredicates.DataSharePredicates(); 2687 let fetchOptions: photoAccessHelper.FetchOptions = { 2688 fetchColumns: [], 2689 predicates: predicates 2690 }; 2691 let fetchResult: photoAccessHelper.FetchResult<photoAccessHelper.PhotoAsset> = await phAccessHelper.getAssets(fetchOptions); 2692 let photoAsset: photoAccessHelper.PhotoAsset = await fetchResult.getFirstObject(); 2693 let fd = await photoAsset.requestSource(); 2694 console.info('Source fd is ' + fd); 2695 } catch (err) { 2696 console.error(`requsetSourcePromiseDemo failed with error: ${err.code}, ${err.message}`); 2697 } 2698} 2699``` 2700 2701### commitEditedAsset<sup>11+</sup> 2702 2703commitEditedAsset(editData: string, uri: string, callback: AsyncCallback<void>) 2704 2705提交编辑数据以及编辑后的图片或视频,该方法使用callback形式来返回结果。 2706 2707通过uri将编辑后的文件传递给媒体库,uri是编辑后的文件在应用沙箱下的FileUri,可参考[FileUri](../apis-core-file-kit/js-apis-file-fileuri.md)。 2708 2709**注意**:新的编辑数据提交后,将覆盖掉原来的编辑数据。 2710 2711**系统接口**:此接口为系统接口。 2712 2713**需要权限**:ohos.permission.WRITE_IMAGEVIDEO 2714 2715**系统能力**:SystemCapability.FileManagement.PhotoAccessHelper.Core 2716 2717**参数:** 2718 2719| 参数名 | 类型 | 必填 | 说明 | 2720| ---------- | ------- | ---- | ---------------------------------- | 2721| editData | string | 是 | 提交的编辑数据。 | 2722| uri | string | 是 | 提交的编辑后的图片或视频,在应用沙箱下的uri。 | 2723| callback | AsyncCallback<void> | 是 | Callback对象,返回void。 | 2724 2725**错误码:** 2726 2727接口抛出错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)和[文件管理错误码](../apis-core-file-kit/errorcode-filemanagement.md)。 2728 2729| 错误码ID | 错误信息 | 2730| -------- | ---------------------------------------- | 2731| 201 | Permission denied. | 2732| 202 | Called by non-system application. | 2733| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types; 3. Parameter verification failed. | 2734| 14000011 | System inner fail. | 2735 2736**示例:** 2737 2738```ts 2739import { dataSharePredicates } from '@kit.ArkData'; 2740 2741async function example() { 2742 try { 2743 console.info('commitEditedAssetCallbackDemo') 2744 let predicates: dataSharePredicates.DataSharePredicates = new dataSharePredicates.DataSharePredicates(); 2745 let fetchOptions: photoAccessHelper.FetchOptions = { 2746 fetchColumns: [], 2747 predicates: predicates 2748 }; 2749 let fetchResult: photoAccessHelper.FetchResult<photoAccessHelper.PhotoAsset> = await phAccessHelper.getAssets(fetchOptions); 2750 let photoAsset: photoAccessHelper.PhotoAsset = await fetchResult.getFirstObject(); 2751 let editData = '123456'; 2752 let uri = 'file://com.example.temptest/data/storage/el2/base/haps/entry/files/test.jpg'; 2753 photoAsset.commitEditedAsset(editData, uri, (err) => { 2754 if (err === undefined) { 2755 console.info('commitEditedAsset is successful'); 2756 } else { 2757 console.error(`commitEditedAsset failed with error: ${err.code}, ${err.message}`); 2758 } 2759 }); 2760 } catch (err) { 2761 console.error(`commitEditedAssetCallbackDemo failed with error: ${err.code}, ${err.message}`); 2762 } 2763} 2764``` 2765 2766### commitEditedAsset<sup>11+</sup> 2767 2768commitEditedAsset(editData: string, uri: string): Promise<void> 2769 2770提交编辑数据以及编辑后的图片或视频,该方法使用promise形式来返回结果。 2771 2772通过uri将编辑后的文件传递给媒体库,uri是编辑后的文件在应用沙箱下的FileUri,可参考[FileUri](../apis-core-file-kit/js-apis-file-fileuri.md)。 2773 2774**注意**:新的编辑数据提交后,将覆盖掉原来的编辑数据。 2775 2776**系统接口**:此接口为系统接口。 2777 2778**需要权限**:ohos.permission.WRITE_IMAGEVIDEO 2779 2780**系统能力**:SystemCapability.FileManagement.PhotoAccessHelper.Core 2781 2782**参数:** 2783 2784| 参数名 | 类型 | 必填 | 说明 | 2785| ---------- | ------- | ---- | ---------------------------------- | 2786| editData | string | 是 | 提交的编辑数据。 | 2787| uri | string | 是 | 提交的编辑后的图片或视频,在应用沙箱下的uri。 | 2788 2789**返回值:** 2790 2791| 类型 | 说明 | 2792| --------------------------------------- | ----------------- | 2793|Promise<void> | Promise对象,返回void。 | 2794 2795**错误码:** 2796 2797接口抛出错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)和[文件管理错误码](../apis-core-file-kit/errorcode-filemanagement.md)。 2798 2799| 错误码ID | 错误信息 | 2800| -------- | ---------------------------------------- | 2801| 201 | Permission denied. | 2802| 202 | Called by non-system application. | 2803| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types; 3. Parameter verification failed. | 2804| 14000011 | System inner fail. | 2805 2806**示例:** 2807 2808```ts 2809import { dataSharePredicates } from '@kit.ArkData'; 2810 2811async function example() { 2812 try { 2813 console.info('commitEditedAssetPromiseDemo') 2814 let predicates: dataSharePredicates.DataSharePredicates = new dataSharePredicates.DataSharePredicates(); 2815 let fetchOptions: photoAccessHelper.FetchOptions = { 2816 fetchColumns: [], 2817 predicates: predicates 2818 }; 2819 let fetchResult: photoAccessHelper.FetchResult<photoAccessHelper.PhotoAsset> = await phAccessHelper.getAssets(fetchOptions); 2820 let photoAsset: photoAccessHelper.PhotoAsset = await fetchResult.getFirstObject(); 2821 let editData = '123456'; 2822 let uri = 'file://com.example.temptest/data/storage/el2/base/haps/entry/files/test.jpg'; 2823 await photoAsset.commitEditedAsset(editData, uri); 2824 console.info('commitEditedAsset is successful'); 2825 } catch (err) { 2826 console.error(`commitEditedAssetPromiseDemo failed with error: ${err.code}, ${err.message}`); 2827 } 2828} 2829``` 2830 2831### revertToOriginal<sup>11+</sup> 2832 2833revertToOriginal(callback: AsyncCallback<void>) 2834 2835回退到编辑前的状态,该方法使用callback形式来返回结果。 2836 2837**注意**:调用该接口后,编辑数据和编辑后的图片或视频资源都将被删除,无法恢复,请谨慎调用。 2838 2839**系统接口**:此接口为系统接口。 2840 2841**需要权限**:ohos.permission.WRITE_IMAGEVIDEO 2842 2843**系统能力**:SystemCapability.FileManagement.PhotoAccessHelper.Core 2844 2845**参数:** 2846 2847| 参数名 | 类型 | 必填 | 说明 | 2848| ---------- | ------- | ---- | ---------------------------------- | 2849| callback | AsyncCallback<void> | 是 | Callback对象,返回void。 | 2850 2851**错误码:** 2852 2853接口抛出错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)和[文件管理错误码](../apis-core-file-kit/errorcode-filemanagement.md)。 2854 2855| 错误码ID | 错误信息 | 2856| -------- | ---------------------------------------- | 2857| 201 | Permission denied. | 2858| 202 | Called by non-system application. | 2859| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types. | 2860| 14000011 | System inner fail. | 2861 2862**示例:** 2863 2864```ts 2865import { dataSharePredicates } from '@kit.ArkData'; 2866 2867async function example() { 2868 try { 2869 console.info('revertToOriginalCallbackDemo') 2870 let predicates: dataSharePredicates.DataSharePredicates = new dataSharePredicates.DataSharePredicates(); 2871 let fetchOptions: photoAccessHelper.FetchOptions = { 2872 fetchColumns: [], 2873 predicates: predicates 2874 }; 2875 let fetchResult: photoAccessHelper.FetchResult<photoAccessHelper.PhotoAsset> = await phAccessHelper.getAssets(fetchOptions); 2876 let photoAsset: photoAccessHelper.PhotoAsset = await fetchResult.getFirstObject(); 2877 photoAsset.revertToOriginal((err) => { 2878 if (err === undefined) { 2879 console.info('revertToOriginal is successful'); 2880 } else { 2881 console.error(`revertToOriginal failed with error: ${err.code}, ${err.message}`); 2882 } 2883 }); 2884 } catch (err) { 2885 console.error(`revertToOriginalCallbackDemo failed with error: ${err.code}, ${err.message}`); 2886 } 2887} 2888``` 2889 2890### revertToOriginal<sup>11+</sup> 2891 2892revertToOriginal(): Promise<void> 2893 2894回退到编辑前的状态,该方法使用promise形式来返回结果。 2895 2896**注意**:调用该接口后,编辑数据和编辑后的图片或视频资源都将被删除,无法恢复,请谨慎调用。 2897 2898**系统接口**:此接口为系统接口。 2899 2900**需要权限**:ohos.permission.WRITE_IMAGEVIDEO 2901 2902**系统能力**:SystemCapability.FileManagement.PhotoAccessHelper.Core 2903 2904**返回值:** 2905 2906| 类型 | 说明 | 2907| --------------------------------------- | ----------------- | 2908|Promise<string> | Promise对象,返回void。 | 2909 2910**错误码:** 2911 2912接口抛出错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)和[文件管理错误码](../apis-core-file-kit/errorcode-filemanagement.md)。 2913 2914| 错误码ID | 错误信息 | 2915| -------- | ---------------------------------------- | 2916| 201 | Permission denied. | 2917| 202 | Called by non-system application. | 2918| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types. | 2919| 14000011 | System inner fail. | 2920 2921**示例:** 2922 2923```ts 2924import { dataSharePredicates } from '@kit.ArkData'; 2925 2926async function example() { 2927 try { 2928 console.info('revertToOriginalPromiseDemo') 2929 let predicates: dataSharePredicates.DataSharePredicates = new dataSharePredicates.DataSharePredicates(); 2930 let fetchOptions: photoAccessHelper.FetchOptions = { 2931 fetchColumns: [], 2932 predicates: predicates 2933 }; 2934 let fetchResult: photoAccessHelper.FetchResult<photoAccessHelper.PhotoAsset> = await phAccessHelper.getAssets(fetchOptions); 2935 let photoAsset: photoAccessHelper.PhotoAsset = await fetchResult.getFirstObject(); 2936 photoAsset.revertToOriginal(); 2937 console.info('revertToOriginal is successful'); 2938 } catch (err) { 2939 console.error(`revertToOriginalPromiseDemo failed with error: ${err.code}, ${err.message}`); 2940 } 2941} 2942``` 2943 2944### requestPhoto<sup>11+</sup> 2945 2946requestPhoto(callback: AsyncCallback<image.PixelMap>): string 2947 2948通过callback的形式,获取资源的快速缩略图和普通缩略图。 2949 2950快速缩略图尺寸为128\*128,普通缩略图尺寸为256\*256。应用调用接口后,callback将返回两次缩略图对象,第一次为快速缩略图,第二次为普通缩略图。 2951 2952**系统接口**:此接口为系统接口。 2953 2954**需要权限**:ohos.permission.READ_IMAGEVIDEO 2955 2956**系统能力**:SystemCapability.FileManagement.PhotoAccessHelper.Core 2957 2958**参数:** 2959 2960| 参数名 | 类型 | 必填 | 说明 | 2961| ---------- | ------- | ---- | ---------------------------------- | 2962| callback | AsyncCallback<[image.PixelMap](../apis-image-kit/js-apis-image.md#pixelmap7)> | 是 | Callback对象,返回获取的缩略图,调用2次。 | 2963 2964**返回值:** 2965 2966| 类型 | 说明 | 2967| --------------------------------------- | ----------------- | 2968| string | 本次获取任务的id。 | 2969 2970**错误码:** 2971 2972接口抛出错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)和[文件管理错误码](../apis-core-file-kit/errorcode-filemanagement.md)。 2973 2974| 错误码ID | 错误信息 | 2975| -------- | ---------------------------------------- | 2976| 201 | Permission verification failed, usually the result returned by VerifyAccessToken. | 2977| 202 | Permission verification failed, application which is not a system application uses system API. | 2978| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types. | 2979| 14000011 | System inner fail. | 2980 2981**示例:** 2982 2983```ts 2984import { dataSharePredicates } from '@kit.ArkData'; 2985import { image } from '@kit.ImageKit'; 2986 2987async function example() { 2988 try { 2989 console.info('requestPhotoDemo') 2990 let options: photoAccessHelper.FetchOptions = { 2991 fetchColumns: [], 2992 predicates: new dataSharePredicates.DataSharePredicates() 2993 } 2994 let fetchResult = await phAccessHelper.getAssets(options); 2995 let photoAsset = await fetchResult.getFirstObject(); 2996 let taskId: string = photoAsset.requestPhoto(async (err, pixel: image.PixelMap) => { 2997 if (err === undefined) { 2998 console.info("requestSource in, size: " + JSON.stringify((await pixel.getImageInfo()).size)) 2999 } else { 3000 console.error(`requestSource failed with error: ${err.code}, ${err.message}`); 3001 } 3002 }) 3003 console.info('requestSource taskId: ' + taskId) 3004 } catch (err) { 3005 console.error(`requestPhotoDemo failed with error: ${err.code}, ${err.message}`); 3006 } 3007} 3008``` 3009 3010### requestPhoto<sup>11+</sup> 3011 3012requestPhoto(options: RequestPhotoOptions, callback: AsyncCallback<image.PixelMap>): string 3013 3014通过callback的形式,根据传入的选项,获取资源的缩略图。 3015 3016**系统接口**:此接口为系统接口。 3017 3018**需要权限**:ohos.permission.READ_IMAGEVIDEO 3019 3020**系统能力**:SystemCapability.FileManagement.PhotoAccessHelper.Core 3021 3022**参数:** 3023 3024| 参数名 | 类型 | 必填 | 说明 | 3025| ---------- | ------- | ---- | ---------------------------------- | 3026| options | [RequestPhotoOptions](#requestphotooptions11) | 是 | 获取资源缩略图的选项。 | 3027| callback | AsyncCallback<[image.PixelMap](../apis-image-kit/js-apis-image.md#pixelmap7)> | 是 | Callback对象,返回获取的缩略图,根据选项的设置可能调用超过1次。 | 3028 3029**返回值:** 3030 3031| 类型 | 说明 | 3032| --------------------------------------- | ----------------- | 3033| string | 本次获取任务的id。 | 3034 3035**错误码:** 3036 3037接口抛出错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)和[文件管理错误码](../apis-core-file-kit/errorcode-filemanagement.md)。 3038 3039| 错误码ID | 错误信息 | 3040| -------- | ---------------------------------------- | 3041| 201 | Permission verification failed, usually the result returned by VerifyAccessToken. | 3042| 202 | Permission verification failed, application which is not a system application uses system API. | 3043| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types; 3. Parameter verification failed. | 3044| 14000011 | System inner fail. | 3045 3046**示例:** 3047 3048```ts 3049import { dataSharePredicates } from '@kit.ArkData'; 3050import { image } from '@kit.ImageKit'; 3051 3052async function example() { 3053 try { 3054 console.info('requestPhotoDemo') 3055 let options: photoAccessHelper.FetchOptions = { 3056 fetchColumns: [], 3057 predicates: new dataSharePredicates.DataSharePredicates() 3058 } 3059 let fetchResult = await phAccessHelper.getAssets(options); 3060 let photoAsset = await fetchResult.getFirstObject(); 3061 let taskId: string = photoAsset.requestPhoto({ 3062 "size": { 3063 "width": 256, 3064 "height": 256 3065 }, 3066 "requestPhotoType": photoAccessHelper.RequestPhotoType.REQUEST_ALL_THUMBNAILS 3067 }, async (err, pixel: image.PixelMap) => { 3068 if (err === undefined) { 3069 console.info("requestSource in, size: " + JSON.stringify((await pixel.getImageInfo()).size)) 3070 } else { 3071 console.error(`requestSource failed with error: ${err.code}, ${err.message}`); 3072 } 3073 }) 3074 console.info('requestSource taskId: ' + taskId) 3075 } catch (err) { 3076 console.error(`requestPhotoDemo failed with error: ${err.code}, ${err.message}`); 3077 } 3078} 3079``` 3080 3081### cancelPhotoRequest<sup>11+</sup> 3082 3083cancelPhotoRequest(requestId: string): void 3084 3085根据id取消指定的获取媒体缩略图的任务。 3086 3087**系统接口**:此接口为系统接口。 3088 3089**需要权限**:ohos.permission.READ_IMAGEVIDEO 3090 3091**系统能力**:SystemCapability.FileManagement.PhotoAccessHelper.Core 3092 3093**参数:** 3094 3095| 参数名 | 类型 | 必填 | 说明 | 3096| ---------- | ------- | ---- | ---------------------------------- | 3097| requestId | string | 是 | 待取消的获取媒体缩略图的任务id。 | 3098 3099**错误码:** 3100 3101接口抛出错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)和[文件管理错误码](../apis-core-file-kit/errorcode-filemanagement.md)。 3102 3103| 错误码ID | 错误信息 | 3104| -------- | ---------------------------------------- | 3105| 201 | Permission verification failed, usually the result returned by VerifyAccessToken. | 3106| 202 | Permission verification failed, application which is not a system application uses system API. | 3107| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types; 3. Parameter verification failed. | 3108| 14000011 | System inner fail. | 3109 3110**示例:** 3111 3112```ts 3113import { dataSharePredicates } from '@kit.ArkData'; 3114import { image } from '@kit.ImageKit'; 3115 3116async function example() { 3117 try { 3118 console.info('cancelPhotoRequestDemo') 3119 let options: photoAccessHelper.FetchOptions = { 3120 fetchColumns: [], 3121 predicates: new dataSharePredicates.DataSharePredicates() 3122 } 3123 let fetchResult = await phAccessHelper.getAssets(options); 3124 let photoAsset = await fetchResult.getFirstObject(); 3125 let taskId: string = photoAsset.requestPhoto({ 3126 "size": { 3127 "width": 256, 3128 "height": 256 3129 }, 3130 "requestPhotoType": photoAccessHelper.RequestPhotoType.REQUEST_ALL_THUMBNAILS 3131 }, async (err, pixel: image.PixelMap) => { 3132 if (err === undefined) { 3133 console.info("requestSource in, size: " + JSON.stringify((await pixel.getImageInfo()).size)) 3134 } else { 3135 console.error(`requestSource failed with error: ${err.code}, ${err.message}`); 3136 } 3137 }) 3138 console.info('requestSource taskId: ' + taskId) 3139 photoAsset.cancelPhotoRequest(taskId); 3140 } catch (err) { 3141 console.error(`cancelPhotoRequestDemo failed with error: ${err.code}, ${err.message}`); 3142 } 3143} 3144``` 3145 3146### getAnalysisData<sup>11+</sup> 3147 3148getAnalysisData(analysisType: AnalysisType): Promise\<string> 3149 3150根据智慧分析类型获取指定分析结果数据。 3151 3152**系统接口**:此接口为系统接口。 3153 3154**需要权限**:ohos.permission.READ\_IMAGEVIDEO 3155 3156**系统能力**:SystemCapability.FileManagement.PhotoAccessHelper.Core 3157 3158**参数:** 3159 3160| 参数名 | 类型 | 必填 | 说明 | 3161| :----------- | :----------- | :- | :----------- | 3162| analysisType | [AnalysisType](#analysistype11) | 是 | 需要获取的智慧分析类型。 | 3163 3164**错误码:** 3165 3166接口抛出错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)和[文件管理错误码](../apis-core-file-kit/errorcode-filemanagement.md)。 3167 3168| 错误码ID | 错误信息 | 3169| :------- | :-------------------------------- | 3170| 201 | Permission denied. | 3171| 202 | Called by non-system application. | 3172| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types; 3. Parameter verification failed. | 3173| 14000011 | System inner fail. | 3174 3175**示例:** 3176 3177```ts 3178import { dataSharePredicates } from '@kit.ArkData'; 3179 3180async function example() { 3181 try { 3182 console.info('getAnalysisDataDemo') 3183 let fetchOptions: photoAccessHelper.FetchOptions = { 3184 fetchColumns: [], 3185 predicates: new dataSharePredicates.DataSharePredicates() 3186 } 3187 let fetchResult: photoAccessHelper.FetchResult<photoAccessHelper.PhotoAsset> = 3188 await phAccessHelper.getAssets(fetchOptions); 3189 let photoAsset: photoAccessHelper.PhotoAsset = await fetchResult.getFirstObject(); 3190 if (photoAsset != undefined) { 3191 let analysisData: string = await photoAsset.getAnalysisData( 3192 photoAccessHelper.AnalysisType.ANALYSIS_OCR); 3193 console.info('get ocr result: ' + JSON.stringify(analysisData)); 3194 } 3195 fetchResult.close(); 3196 } catch (err) { 3197 console.error(`getAnalysisDataDemofailed with error: ${err.code}, ${err.message}`); 3198 } 3199} 3200``` 3201 3202## Album 3203 3204实体相册 3205 3206### recoverAssets<sup>(deprecated)</sup> 3207 3208recoverAssets(assets: Array<PhotoAsset>, callback: AsyncCallback<void>): void 3209 3210从回收站中恢复图片或者视频,需要先在回收站中预置文件资源。该方法使用callback形式来返回结果。 3211 3212> **说明:** 3213> 3214> 从API version 10开始支持,从API version 11开始废弃。建议使用[MediaAlbumChangeRequest.recoverAssets](#recoverassets11)替代。 3215 3216**系统接口**:此接口为系统接口。 3217 3218**需要权限**:ohos.permission.WRITE_IMAGEVIDEO 3219 3220**系统能力**:SystemCapability.FileManagement.PhotoAccessHelper.Core 3221 3222**参数:** 3223 3224| 参数名 | 类型 | 必填 | 说明 | 3225| -------- | ------------------------- | ---- | ---------- | 3226| assets | Array<[PhotoAsset](#photoasset)> | 是 | 回收站中待恢复图片或者视频数组。 | 3227| callback | AsyncCallback<void> | 是 | callback返回void。 | 3228 3229**错误码:** 3230 3231接口抛出错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)和[文件管理错误码](../apis-core-file-kit/errorcode-filemanagement.md)。 3232 3233| 错误码ID | 错误信息 | 3234| -------- | ---------------------------------------- | 3235| 202 | Called by non-system application. | 3236| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types; 3. Parameter verification failed. | 3237| 13900012 | Permission denied. | 3238| 13900020 | Invalid argument. | 3239| 14000011 | System inner fail. | 3240 3241**示例:** 3242 3243```ts 3244import { dataSharePredicates } from '@kit.ArkData'; 3245 3246async function example() { 3247 try { 3248 console.info('recoverAssetsDemoCallback'); 3249 let predicates: dataSharePredicates.DataSharePredicates = new dataSharePredicates.DataSharePredicates(); 3250 let fetchOption: photoAccessHelper.FetchOptions = { 3251 fetchColumns: [], 3252 predicates: predicates 3253 }; 3254 let albumFetchResult: photoAccessHelper.FetchResult<photoAccessHelper.Album> = await phAccessHelper.getAlbums(photoAccessHelper.AlbumType.SYSTEM, photoAccessHelper.AlbumSubtype.TRASH); 3255 let album: photoAccessHelper.Album = await albumFetchResult.getFirstObject(); 3256 let fetchResult: photoAccessHelper.FetchResult<photoAccessHelper.PhotoAsset> = await album.getAssets(fetchOption); 3257 let asset: photoAccessHelper.PhotoAsset = await fetchResult.getFirstObject(); 3258 album.recoverAssets([asset], (err) => { 3259 if (err === undefined) { 3260 console.info('album recoverAssets successfully'); 3261 } else { 3262 console.error(`album recoverAssets failed with error: ${err.code}, ${err.message}`); 3263 } 3264 }); 3265 } catch (err) { 3266 console.error(`recoverAssetsDemoCallback failed with error: ${err.code}, ${err.message}`); 3267 } 3268} 3269``` 3270 3271### recoverAssets<sup>(deprecated)</sup> 3272 3273recoverAssets(assets: Array<PhotoAsset>): Promise<void> 3274 3275从回收站中恢复图片或者视频,需要先在回收站中预置文件资源。该方法使用Promise来返回结果。 3276 3277> **说明:** 3278> 3279> 从API version 10开始支持,从API version 11开始废弃。建议使用[MediaAlbumChangeRequest.recoverAssets](#recoverassets11)替代。 3280 3281**系统接口**:此接口为系统接口。 3282 3283**需要权限**:ohos.permission.WRITE_IMAGEVIDEO 3284 3285**系统能力**:SystemCapability.FileManagement.PhotoAccessHelper.Core 3286 3287**参数:** 3288 3289| 参数名 | 类型 | 必填 | 说明 | 3290| -------- | ------------------------- | ---- | ---------- | 3291| assets | Array<[PhotoAsset](#photoasset)> | 是 | 回收站中待恢复图片或者视频数组。 | 3292 3293**返回值:** 3294 3295| 类型 | 说明 | 3296| --------------------------------------- | ----------------- | 3297|Promise<void> | Promise对象,返回void。 | 3298 3299**错误码:** 3300 3301接口抛出错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)和[文件管理错误码](../apis-core-file-kit/errorcode-filemanagement.md)。 3302 3303| 错误码ID | 错误信息 | 3304| -------- | ---------------------------------------- | 3305| 202 | Called by non-system application. | 3306| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types; 3. Parameter verification failed. | 3307| 13900012 | Permission denied. | 3308| 13900020 | Invalid argument. | 3309| 14000011 | System inner fail. | 3310 3311**示例:** 3312 3313```ts 3314import { dataSharePredicates } from '@kit.ArkData'; 3315import { BusinessError } from '@kit.BasicServicesKit'; 3316 3317async function example() { 3318 try { 3319 console.info('recoverAssetsDemoPromise'); 3320 let predicates: dataSharePredicates.DataSharePredicates = new dataSharePredicates.DataSharePredicates(); 3321 let fetchOption: photoAccessHelper.FetchOptions = { 3322 fetchColumns: [], 3323 predicates: predicates 3324 }; 3325 let albumFetchResult: photoAccessHelper.FetchResult<photoAccessHelper.Album> = await phAccessHelper.getAlbums(photoAccessHelper.AlbumType.SYSTEM, photoAccessHelper.AlbumSubtype.TRASH); 3326 let album: photoAccessHelper.Album = await albumFetchResult.getFirstObject(); 3327 let fetchResult: photoAccessHelper.FetchResult<photoAccessHelper.PhotoAsset> = await album.getAssets(fetchOption); 3328 let asset: photoAccessHelper.PhotoAsset = await fetchResult.getFirstObject(); 3329 album.recoverAssets([asset]).then(() => { 3330 console.info('album recoverAssets successfully'); 3331 }).catch((err: BusinessError) => { 3332 console.error(`album recoverAssets failed with error: ${err.code}, ${err.message}`); 3333 }); 3334 } catch (err) { 3335 console.error(`recoverAssetsDemoPromise failed with error: ${err.code}, ${err.message}`); 3336 } 3337} 3338``` 3339 3340### deleteAssets<sup>(deprecated)</sup> 3341 3342deleteAssets(assets: Array<PhotoAsset>, callback: AsyncCallback<void>): void 3343 3344从回收站中彻底删除图片或者视频,需要先在回收站中预置文件资源。该方法使用callback形式来返回结果。 3345 3346> **说明:** 3347> 3348> 从API version 10开始支持,从API version 11开始废弃。建议使用[MediaAlbumChangeRequest.deleteAssets](#deleteassets11)替代。 3349 3350**注意**:此操作不可逆,执行此操作后文件资源将彻底删除,请谨慎操作。 3351 3352**系统接口**:此接口为系统接口。 3353 3354**需要权限**:ohos.permission.WRITE_IMAGEVIDEO 3355 3356**系统能力**:SystemCapability.FileManagement.PhotoAccessHelper.Core 3357 3358**参数:** 3359 3360| 参数名 | 类型 | 必填 | 说明 | 3361| -------- | ------------------------- | ---- | ---------- | 3362| assets | Array<[PhotoAsset](#photoasset)> | 是 | 回收站中待彻底删除图片或者视频数组。 | 3363| callback | AsyncCallback<void> | 是 | callback返回void。 | 3364 3365**错误码:** 3366 3367接口抛出错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)和[文件管理错误码](../apis-core-file-kit/errorcode-filemanagement.md)。 3368 3369| 错误码ID | 错误信息 | 3370| -------- | ---------------------------------------- | 3371| 202 | Called by non-system application. | 3372| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types; 3. Parameter verification failed. | 3373| 13900012 | Permission denied. | 3374| 13900020 | Invalid argument. | 3375| 14000011 | System inner fail. | 3376 3377**示例:** 3378 3379```ts 3380import { dataSharePredicates } from '@kit.ArkData'; 3381 3382async function example() { 3383 try { 3384 console.info('deleteAssetsDemoCallback'); 3385 let predicates: dataSharePredicates.DataSharePredicates = new dataSharePredicates.DataSharePredicates(); 3386 let fetchOption: photoAccessHelper.FetchOptions = { 3387 fetchColumns: [], 3388 predicates: predicates 3389 }; 3390 let albumFetchResult: photoAccessHelper.FetchResult<photoAccessHelper.Album> = await phAccessHelper.getAlbums(photoAccessHelper.AlbumType.SYSTEM, photoAccessHelper.AlbumSubtype.TRASH); 3391 let album: photoAccessHelper.Album = await albumFetchResult.getFirstObject(); 3392 let fetchResult: photoAccessHelper.FetchResult<photoAccessHelper.PhotoAsset> = await album.getAssets(fetchOption); 3393 let asset: photoAccessHelper.PhotoAsset = await fetchResult.getFirstObject(); 3394 album.deleteAssets([asset], (err) => { 3395 if (err === undefined) { 3396 console.info('album deleteAssets successfully'); 3397 } else { 3398 console.error(`album deleteAssets failed with error: ${err.code}, ${err.message}`); 3399 } 3400 }); 3401 } catch (err) { 3402 console.error(`deleteAssetsDemoCallback failed with error: ${err.code}, ${err.message}`); 3403 } 3404} 3405``` 3406 3407### deleteAssets<sup>(deprecated)</sup> 3408 3409deleteAssets(assets: Array<PhotoAsset>): Promise<void> 3410 3411从回收站中彻底删除图片或者视频,需要先在回收站中预置文件资源。该方法使用Promise来返回结果。 3412 3413> **说明:** 3414> 3415> 从API version 10开始支持,从API version 11开始废弃。建议使用[MediaAlbumChangeRequest.deleteAssets](#deleteassets11)替代。 3416 3417**注意**:此操作不可逆,执行此操作后文件资源将彻底删除,请谨慎操作。 3418 3419**系统接口**:此接口为系统接口。 3420 3421**需要权限**:ohos.permission.WRITE_IMAGEVIDEO 3422 3423**系统能力**:SystemCapability.FileManagement.PhotoAccessHelper.Core 3424 3425**参数:** 3426 3427| 参数名 | 类型 | 必填 | 说明 | 3428| -------- | ------------------------- | ---- | ---------- | 3429| assets | Array<[PhotoAsset](#photoasset)> | 是 | 回收站中待彻底删除图片或者视频数组。 | 3430 3431**返回值:** 3432 3433| 类型 | 说明 | 3434| --------------------------------------- | ----------------- | 3435|Promise<void> | Promise对象,返回void。 | 3436 3437**错误码:** 3438 3439接口抛出错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)和[文件管理错误码](../apis-core-file-kit/errorcode-filemanagement.md)。 3440 3441| 错误码ID | 错误信息 | 3442| -------- | ---------------------------------------- | 3443| 202 | Called by non-system application. | 3444| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types; 3. Parameter verification failed. | 3445| 13900012 | Permission denied. | 3446| 13900020 | Invalid argument. | 3447| 14000011 | System inner fail. | 3448 3449**示例:** 3450 3451```ts 3452import { dataSharePredicates } from '@kit.ArkData'; 3453import { BusinessError } from '@kit.BasicServicesKit'; 3454 3455async function example() { 3456 try { 3457 console.info('deleteAssetsDemoPromise'); 3458 let predicates: dataSharePredicates.DataSharePredicates = new dataSharePredicates.DataSharePredicates(); 3459 let fetchOption: photoAccessHelper.FetchOptions = { 3460 fetchColumns: [], 3461 predicates: predicates 3462 }; 3463 let albumFetchResult: photoAccessHelper.FetchResult<photoAccessHelper.Album> = await phAccessHelper.getAlbums(photoAccessHelper.AlbumType.SYSTEM, photoAccessHelper.AlbumSubtype.TRASH); 3464 let album: photoAccessHelper.Album = await albumFetchResult.getFirstObject(); 3465 let fetchResult: photoAccessHelper.FetchResult<photoAccessHelper.PhotoAsset> = await album.getAssets(fetchOption); 3466 let asset: photoAccessHelper.PhotoAsset = await fetchResult.getFirstObject(); 3467 album.deleteAssets([asset]).then(() => { 3468 console.info('album deleteAssets successfully'); 3469 }).catch((err: BusinessError) => { 3470 console.error(`album deleteAssets failed with error: ${err.code}, ${err.message}`); 3471 }); 3472 } catch (err) { 3473 console.error(`deleteAssetsDemoPromise failed with error: ${err.code}, ${err.message}`); 3474 } 3475} 3476``` 3477 3478### setCoverUri<sup>(deprecated)</sup> 3479 3480setCoverUri(uri: string, callback: AsyncCallback<void>): void 3481 3482设置相册封面,该方法使用callback形式来返回结果。 3483 3484> **说明:** 3485> 3486> 从API version 10开始支持,从API version 11开始废弃。建议使用[MediaAlbumChangeRequest.setCoverUri](#setcoveruri11)替代。 3487 3488**注意**:此接口只可修改用户相册封面,不允许修改系统相册封面。 3489 3490**系统接口**:此接口为系统接口。 3491 3492**需要权限**:ohos.permission.WRITE_IMAGEVIDEO 3493 3494**系统能力**:SystemCapability.FileManagement.PhotoAccessHelper.Core 3495 3496**参数:** 3497 3498| 参数名 | 类型 | 必填 | 说明 | 3499| -------- | ------------------------- | ---- | ---------- | 3500| uri | string | 是 | 待设置为相册封面文件的uri。 | 3501| callback | AsyncCallback<void> | 是 | callback返回void。 | 3502 3503**错误码:** 3504 3505接口抛出错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)和[文件管理错误码](../apis-core-file-kit/errorcode-filemanagement.md)。 3506 3507| 错误码ID | 错误信息 | 3508| -------- | ---------------------------------------- | 3509| 202 | Called by non-system application. | 3510| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types; 3. Parameter verification failed. | 3511| 13900012 | Permission denied. | 3512| 13900020 | Invalid argument. | 3513| 14000011 | System inner fail. | 3514 3515**示例:** 3516 3517```ts 3518import { dataSharePredicates } from '@kit.ArkData'; 3519 3520async function example() { 3521 try { 3522 console.info('setCoverUriDemoCallback'); 3523 let predicates: dataSharePredicates.DataSharePredicates = new dataSharePredicates.DataSharePredicates(); 3524 let fetchOption: photoAccessHelper.FetchOptions = { 3525 fetchColumns: [], 3526 predicates: predicates 3527 }; 3528 let albumFetchResult: photoAccessHelper.FetchResult<photoAccessHelper.Album> = await phAccessHelper.getAlbums(photoAccessHelper.AlbumType.USER, photoAccessHelper.AlbumSubtype.USER_GENERIC); 3529 let album: photoAccessHelper.Album = await albumFetchResult.getFirstObject(); 3530 let fetchResult: photoAccessHelper.FetchResult<photoAccessHelper.PhotoAsset> = await album.getAssets(fetchOption); 3531 let asset: photoAccessHelper.PhotoAsset = await fetchResult.getFirstObject(); 3532 album.setCoverUri(asset.uri, (err) => { 3533 if (err === undefined) { 3534 console.info('album setCoverUri successfully'); 3535 } else { 3536 console.error(`album setCoverUri failed with error: ${err.code}, ${err.message}`); 3537 } 3538 }); 3539 } catch (err) { 3540 console.error(`setCoverUriDemoCallback failed with error: ${err.code}, ${err.message}`); 3541 } 3542} 3543``` 3544 3545### setCoverUri<sup>(deprecated)</sup> 3546 3547setCoverUri(uri: string): Promise<void> 3548 3549设置相册封面,该方法使用Promise来返回结果。 3550 3551> **说明:** 3552> 3553> 从API version 10开始支持,从API version 11开始废弃。建议使用[MediaAlbumChangeRequest.setCoverUri](#setcoveruri11)替代。 3554 3555**注意**:此接口只可修改用户相册封面,不允许修改系统相册封面。 3556 3557**系统接口**:此接口为系统接口。 3558 3559**需要权限**:ohos.permission.WRITE_IMAGEVIDEO 3560 3561**系统能力**:SystemCapability.FileManagement.PhotoAccessHelper.Core 3562 3563**参数:** 3564 3565| 参数名 | 类型 | 必填 | 说明 | 3566| -------- | ------------------------- | ---- | ---------- | 3567| uri | string | 是 | 待设置为相册封面文件的uri。 | 3568 3569**返回值:** 3570 3571| 类型 | 说明 | 3572| --------------------------------------- | ----------------- | 3573|Promise<void> | Promise对象,返回void。 | 3574 3575**错误码:** 3576 3577接口抛出错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)和[文件管理错误码](../apis-core-file-kit/errorcode-filemanagement.md)。 3578 3579| 错误码ID | 错误信息 | 3580| -------- | ---------------------------------------- | 3581| 202 | Called by non-system application. | 3582| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types; 3. Parameter verification failed. | 3583| 13900012 | Permission denied. | 3584| 13900020 | Invalid argument. | 3585| 14000011 | System inner fail. | 3586**示例:** 3587 3588```ts 3589import { dataSharePredicates } from '@kit.ArkData'; 3590import { BusinessError } from '@kit.BasicServicesKit'; 3591 3592async function example() { 3593 try { 3594 console.info('setCoverUriDemoPromise'); 3595 let predicates: dataSharePredicates.DataSharePredicates = new dataSharePredicates.DataSharePredicates(); 3596 let fetchOption: photoAccessHelper.FetchOptions = { 3597 fetchColumns: [], 3598 predicates: predicates 3599 }; 3600 let albumFetchResult: photoAccessHelper.FetchResult<photoAccessHelper.Album> = await phAccessHelper.getAlbums(photoAccessHelper.AlbumType.USER, photoAccessHelper.AlbumSubtype.USER_GENERIC); 3601 let album: photoAccessHelper.Album = await albumFetchResult.getFirstObject(); 3602 let fetchResult: photoAccessHelper.FetchResult<photoAccessHelper.PhotoAsset> = await album.getAssets(fetchOption); 3603 let asset: photoAccessHelper.PhotoAsset = await fetchResult.getFirstObject(); 3604 album.setCoverUri(asset.uri).then(() => { 3605 console.info('album setCoverUri successfully'); 3606 }).catch((err: BusinessError) => { 3607 console.error(`album setCoverUri failed with error: ${err.code}, ${err.message}`); 3608 }); 3609 } catch (err) { 3610 console.error(`setCoverUriDemoPromise failed with error: ${err.code}, ${err.message}`); 3611 } 3612} 3613``` 3614 3615## MediaAssetEditData<sup>11+</sup> 3616 3617资产编辑数据。 3618 3619**系统接口**:此接口为系统接口。 3620 3621**系统能力**:SystemCapability.FileManagement.PhotoAccessHelper.Core 3622 3623### 属性 3624 3625| 名称 | 类型 | 可读 | 可写 | 说明 | 3626| ------------ | ------ | ---- | ---- | ------- | 3627| compatibleFormat | string | 是 | 是 | 编辑数据的格式。<br>**系统接口**:此接口为系统接口。 | 3628| formatVersion | string | 是 | 是 | 编辑数据格式的版本。<br>**系统接口**:此接口为系统接口。 | 3629| data | string | 是 | 是 | 编辑数据的内容。<br>**系统接口**:此接口为系统接口。 | 3630 3631### constructor<sup>11+</sup> 3632 3633constructor(compatibleFormat: string, formatVersion: string) 3634 3635构造函数。 3636 3637**系统接口**:此接口为系统接口。 3638 3639**系统能力**:SystemCapability.FileManagement.PhotoAccessHelper.Core 3640 3641**参数:** 3642 3643| 参数名 | 类型 | 必填 | 说明 | 3644| -------- | ------------------------- | ---- | ---------- | 3645| compatibleFormat | string | 是 | 编辑数据的格式。 | 3646| formatVersion | string | 是 | 编辑数据格式的版本。 | 3647 3648**错误码:** 3649 3650接口抛出错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)和[文件管理错误码](../apis-core-file-kit/errorcode-filemanagement.md)。 3651 3652| 错误码ID | 错误信息 | 3653| -------- | ---------------------------------------- | 3654| 202 | Called by non-system application. | 3655| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types; 3. Parameter verification failed. | 3656| 14000011 | System inner fail. | 3657 3658**示例:** 3659 3660```ts 3661let assetEditData: photoAccessHelper.MediaAssetEditData = new photoAccessHelper.MediaAssetEditData('system', '1.0'); 3662``` 3663 3664## MediaAssetChangeRequest<sup>11+</sup> 3665 3666资产变更请求。 3667 3668**系统能力**:SystemCapability.FileManagement.PhotoAccessHelper.Core 3669 3670### createAssetRequest<sup>11+</sup> 3671 3672static createAssetRequest(context: Context, displayName: string, options?: PhotoCreateOptions): MediaAssetChangeRequest 3673 3674指定待创建的图片或者视频的文件名,创建资产变更请求。 3675 3676待创建的文件名参数规格为: 3677- 应包含有效文件主名和图片或视频扩展名。 3678- 文件名字符串长度为1~255。 3679- 文件主名中不允许出现非法字符,包括:<br> . .. \ / : * ? " ' ` < > | { } [ ] 3680 3681**系统接口**:此接口为系统接口。 3682 3683**系统能力**:SystemCapability.FileManagement.PhotoAccessHelper.Core 3684 3685**参数:** 3686 3687| 参数名 | 类型 | 必填 | 说明 | 3688| ------- | ------- | ---- | -------------------------- | 3689| context | [Context](../apis-ability-kit/js-apis-inner-application-context.md) | 是 | 传入Ability实例的Context。 | 3690| displayName | string | 是 | 待创建的图片或者视频文件名。 | 3691| options | [PhotoCreateOptions](#photocreateoptions) | 否 | 图片或视频的创建选项。 | 3692 3693**返回值:** 3694 3695| 类型 | 说明 | 3696| --------------------------------------- | ----------------- | 3697| [MediaAssetChangeRequest](#mediaassetchangerequest11) | 返回创建资产的变更请求。 | 3698 3699**错误码:** 3700 3701接口抛出错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)和[文件管理错误码](../apis-core-file-kit/errorcode-filemanagement.md)。 3702 3703| 错误码ID | 错误信息 | 3704| -------- | ---------------------------------------- | 3705| 202 | Called by non-system application. | 3706| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types; 3. Parameter verification failed. | 3707| 14000001 | Invalid display name. | 3708| 14000011 | System inner fail. | 3709 3710**示例:** 3711 3712```ts 3713async function example() { 3714 console.info('createAssetRequestDemo'); 3715 try { 3716 let testFileName: string = 'testFile' + Date.now() + '.jpg'; 3717 let assetChangeRequest: photoAccessHelper.MediaAssetChangeRequest = photoAccessHelper.MediaAssetChangeRequest.createAssetRequest(context, testFileName); 3718 // 需要确保fileUri对应的资源存在。 3719 let fileUri = 'file://com.example.temptest/data/storage/el2/base/haps/entry/files/test.jpg'; 3720 assetChangeRequest.addResource(photoAccessHelper.ResourceType.IMAGE_RESOURCE, fileUri); 3721 await phAccessHelper.applyChanges(assetChangeRequest); 3722 console.info('apply createAssetRequest successfully'); 3723 } catch (err) { 3724 console.error(`createAssetRequestDemo failed with error: ${err.code}, ${err.message}`); 3725 } 3726} 3727``` 3728 3729### setFavorite<sup>11+</sup> 3730 3731setFavorite(favoriteState: boolean): void 3732 3733将文件设置为收藏文件。 3734 3735**系统接口**:此接口为系统接口。 3736 3737**系统能力**:SystemCapability.FileManagement.PhotoAccessHelper.Core 3738 3739**参数:** 3740 3741| 参数名 | 类型 | 必填 | 说明 | 3742| ---------- | ------- | ---- | ---------------------------------- | 3743| favoriteState | boolean | 是 | 是否设置为收藏文件, true:设置为收藏文件;false:取消收藏。 | 3744 3745**错误码:** 3746 3747接口抛出错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)和[文件管理错误码](../apis-core-file-kit/errorcode-filemanagement.md)。 3748 3749| 错误码ID | 错误信息 | 3750| -------- | ---------------------------------------- | 3751| 202 | Called by non-system application. | 3752| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types; 3. Parameter verification failed. | 3753| 14000011 | System inner fail. | 3754 3755**示例:** 3756 3757```ts 3758import { dataSharePredicates } from '@kit.ArkData'; 3759import { BusinessError } from '@kit.BasicServicesKit'; 3760 3761async function example() { 3762 console.info('setFavoriteDemo'); 3763 let predicates: dataSharePredicates.DataSharePredicates = new dataSharePredicates.DataSharePredicates(); 3764 let fetchOption: photoAccessHelper.FetchOptions = { 3765 fetchColumns: [], 3766 predicates: predicates 3767 }; 3768 let fetchResult: photoAccessHelper.FetchResult<photoAccessHelper.PhotoAsset> = await phAccessHelper.getAssets(fetchOption); 3769 let asset = await fetchResult.getFirstObject(); 3770 let assetChangeRequest: photoAccessHelper.MediaAssetChangeRequest = new photoAccessHelper.MediaAssetChangeRequest(asset); 3771 assetChangeRequest.setFavorite(true); 3772 phAccessHelper.applyChanges(assetChangeRequest).then(() => { 3773 console.info('apply setFavorite successfully'); 3774 }).catch((err: BusinessError) => { 3775 console.error(`apply setFavorite failed with error: ${err.code}, ${err.message}`); 3776 }); 3777} 3778``` 3779 3780### setHidden<sup>11+</sup> 3781 3782setHidden(hiddenState: boolean): void 3783 3784将文件设置为隐藏文件。 3785 3786**系统接口**:此接口为系统接口。 3787 3788**系统能力**:SystemCapability.FileManagement.PhotoAccessHelper.Core 3789 3790**参数:** 3791 3792| 参数名 | 类型 | 必填 | 说明 | 3793| ---------- | ------- | ---- | ---------------------------------- | 3794| hiddenState | boolean | 是 | 是否设置为隐藏文件,true:将文件资产放入隐藏相册;false:从隐藏相册中恢复。 | 3795 3796**错误码:** 3797 3798接口抛出错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)和[文件管理错误码](../apis-core-file-kit/errorcode-filemanagement.md)。 3799 3800| 错误码ID | 错误信息 | 3801| -------- | ---------------------------------------- | 3802| 202 | Called by non-system application. | 3803| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types; 3. Parameter verification failed. | 3804| 14000011 | System inner fail. | 3805 3806**示例:** 3807 3808```ts 3809import { dataSharePredicates } from '@kit.ArkData'; 3810import { BusinessError } from '@kit.BasicServicesKit'; 3811 3812async function example() { 3813 console.info('setHiddenDemo'); 3814 let predicates: dataSharePredicates.DataSharePredicates = new dataSharePredicates.DataSharePredicates(); 3815 let fetchOption: photoAccessHelper.FetchOptions = { 3816 fetchColumns: [], 3817 predicates: predicates 3818 }; 3819 let fetchResult: photoAccessHelper.FetchResult<photoAccessHelper.PhotoAsset> = await phAccessHelper.getAssets(fetchOption); 3820 let asset = await fetchResult.getFirstObject(); 3821 let assetChangeRequest: photoAccessHelper.MediaAssetChangeRequest = new photoAccessHelper.MediaAssetChangeRequest(asset); 3822 assetChangeRequest.setHidden(true); 3823 phAccessHelper.applyChanges(assetChangeRequest).then(() => { 3824 console.info('apply setHidden successfully'); 3825 }).catch((err: BusinessError) => { 3826 console.error(`apply setHidden failed with error: ${err.code}, ${err.message}`); 3827 }); 3828} 3829``` 3830 3831### setUserComment<sup>11+</sup> 3832 3833setUserComment(userComment: string): void 3834 3835修改媒体资产的备注信息。 3836 3837**系统接口**:此接口为系统接口。 3838 3839**系统能力**:SystemCapability.FileManagement.PhotoAccessHelper.Core 3840 3841**参数:** 3842 3843| 参数名 | 类型 | 必填 | 说明 | 3844| ---------- | ------- | ---- | ---------------------------------- | 3845| userComment | string | 是 | 待修改的资产备注信息,备注信息最长为420字符。 | 3846 3847**错误码:** 3848 3849接口抛出错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)和[文件管理错误码](../apis-core-file-kit/errorcode-filemanagement.md)。 3850 3851| 错误码ID | 错误信息 | 3852| -------- | ---------------------------------------- | 3853| 202 | Called by non-system application. | 3854| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types; 3. Parameter verification failed. | 3855| 14000011 | System inner fail. | 3856 3857**示例:** 3858 3859```ts 3860import { dataSharePredicates } from '@kit.ArkData'; 3861import { BusinessError } from '@kit.BasicServicesKit'; 3862 3863async function example() { 3864 console.info('setUserCommentDemo'); 3865 let predicates: dataSharePredicates.DataSharePredicates = new dataSharePredicates.DataSharePredicates(); 3866 let fetchOption: photoAccessHelper.FetchOptions = { 3867 fetchColumns: [], 3868 predicates: predicates 3869 }; 3870 let fetchResult: photoAccessHelper.FetchResult<photoAccessHelper.PhotoAsset> = await phAccessHelper.getAssets(fetchOption); 3871 let asset = await fetchResult.getFirstObject(); 3872 let assetChangeRequest: photoAccessHelper.MediaAssetChangeRequest = new photoAccessHelper.MediaAssetChangeRequest(asset); 3873 let userComment: string = 'test_set_user_comment'; 3874 assetChangeRequest.setUserComment(userComment); 3875 phAccessHelper.applyChanges(assetChangeRequest).then(() => { 3876 console.info('apply setUserComment successfully'); 3877 }).catch((err: BusinessError) => { 3878 console.error(`apply setUserComment failed with error: ${err.code}, ${err.message}`); 3879 }); 3880} 3881``` 3882 3883### setEditData<sup>11+</sup> 3884 3885setEditData(editData: MediaAssetEditData): void 3886 3887保存资产的编辑数据。 3888 3889**系统接口**:此接口为系统接口。 3890 3891**系统能力**:SystemCapability.FileManagement.PhotoAccessHelper.Core 3892 3893**参数:** 3894 3895| 参数名 | 类型 | 必填 | 说明 | 3896| ---------- | ------- | ---- | ---------------------------------- | 3897| editData | [MediaAssetEditData](#mediaasseteditdata11) | 是 | 待保存的资产编辑数据。 | 3898 3899**错误码:** 3900 3901接口抛出错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)和[文件管理错误码](../apis-core-file-kit/errorcode-filemanagement.md)。 3902 3903| 错误码ID | 错误信息 | 3904| -------- | ---------------------------------------- | 3905| 202 | Called by non-system application. | 3906| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types; 3. Parameter verification failed. | 3907| 14000011 | System inner fail. | 3908 3909**示例:** 3910 3911```ts 3912import { dataSharePredicates } from '@kit.ArkData'; 3913import { BusinessError } from '@kit.BasicServicesKit'; 3914 3915async function example() { 3916 console.info('setEditDataDemo'); 3917 let predicates: dataSharePredicates.DataSharePredicates = new dataSharePredicates.DataSharePredicates(); 3918 let fetchOption: photoAccessHelper.FetchOptions = { 3919 fetchColumns: [], 3920 predicates: predicates 3921 }; 3922 let fetchResult: photoAccessHelper.FetchResult<photoAccessHelper.PhotoAsset> = await phAccessHelper.getAssets(fetchOption); 3923 let asset = await fetchResult.getFirstObject(); 3924 let assetChangeRequest: photoAccessHelper.MediaAssetChangeRequest = new photoAccessHelper.MediaAssetChangeRequest(asset); 3925 3926 let assetEditData: photoAccessHelper.MediaAssetEditData = new photoAccessHelper.MediaAssetEditData('system', '1.0'); 3927 let fileUri = 'file://com.example.temptest/data/storage/el2/base/haps/entry/files/test.jpg'; 3928 assetChangeRequest.addResource(photoAccessHelper.ResourceType.IMAGE_RESOURCE, fileUri); 3929 assetEditData.data = '123456'; 3930 assetChangeRequest.setEditData(assetEditData); 3931 phAccessHelper.applyChanges(assetChangeRequest).then(() => { 3932 console.info('apply setEditData successfully'); 3933 }).catch((err: BusinessError) => { 3934 console.error(`apply setEditData failed with error: ${err.code}, ${err.message}`); 3935 }); 3936} 3937``` 3938 3939### addResource<sup>11+</sup> 3940 3941addResource(type: ResourceType, proxy: PhotoProxy): void 3942 3943通过PhotoProxy数据添加资源。 3944 3945**注意**:对于同一个资产变更请求,不支持在成功添加资源后,重复调用该接口。 3946 3947**系统接口**:此接口为系统接口,仅提供给相机应用使用。 3948 3949**系统能力**:SystemCapability.FileManagement.PhotoAccessHelper.Core 3950 3951**参数:** 3952 3953| 参数名 | 类型 | 必填 | 说明 | 3954| ------- |---------------------------------| ---- |----------------------| 3955| type | [ResourceType](#resourcetype11) | 是 | 待添加资源的类型。 | 3956| proxy | [PhotoProxy](#photoproxy11) | 是 | 待添加资源的PhotoProxy 数据。 | 3957 3958**错误码:** 3959 3960接口抛出错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)和[文件管理错误码](../apis-core-file-kit/errorcode-filemanagement.md)。 3961 3962| 错误码ID | 错误信息 | 3963|----------|-----------------------------------| 3964| 202 | Called by non-system application. | 3965| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types; 3. Parameter verification failed. | 3966| 14000011 | System inner fail. | 3967| 14000016 | Operation Not Support. | 3968 3969**示例:** 3970 3971```ts 3972class PhotoProxyImpl implements photoAccessHelper.PhotoProxy { 3973 // 应用实现PhotoProxy。 3974} 3975 3976async function example() { 3977 console.info('addResourceByPhotoProxyDemo'); 3978 try { 3979 let photoType: photoAccessHelper.PhotoType = photoAccessHelper.PhotoType.IMAGE; 3980 let extension: string = 'jpg'; 3981 let assetChangeRequest: photoAccessHelper.MediaAssetChangeRequest = photoAccessHelper.MediaAssetChangeRequest.createAssetRequest(context, photoType, extension); 3982 let photoProxy: PhotoProxyImpl = new PhotoProxyImpl(); 3983 assetChangeRequest.addResource(photoAccessHelper.ResourceType.IMAGE_RESOURCE, photoProxy); 3984 await phAccessHelper.applyChanges(assetChangeRequest); 3985 console.info('addResourceByPhotoProxy successfully'); 3986 } catch (err) { 3987 console.error(`addResourceByPhotoProxyDemo failed with error: ${err.code}, ${err.message}`); 3988 } 3989} 3990``` 3991 3992### setLocation<sup>11+</sup> 3993 3994setLocation(longitude: number, latitude: number): void 3995 3996设置文件的经纬度信息。 3997 3998**系统接口**:此接口为系统接口 3999 4000**系统能力**:SystemCapability.FileManagement.PhotoAccessHelper.Core 4001 4002**参数:** 4003 4004| 参数名 | 类型 | 必填 | 说明 | 4005| ------- |-------------| ---- |-------| 4006| longitude | number | 是 | 经度。 | 4007| latitude | number | 是 | 纬度。 | 4008 4009**错误码:** 4010 4011接口抛出错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)和[文件管理错误码](../apis-core-file-kit/errorcode-filemanagement.md)。 4012 4013| 错误码ID | 错误信息 | 4014| -------- | ---------------------------------------- | 4015| 202 | Called by non-system application. | 4016| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types; 3. Parameter verification failed. | 4017| 14000011 | System inner fail. | 4018 4019**示例:** 4020 4021```ts 4022import { dataSharePredicates } from '@kit.ArkData'; 4023import { BusinessError } from '@kit.BasicServicesKit'; 4024 4025async function example() { 4026 console.info('setLocationDemo'); 4027 let predicates: dataSharePredicates.DataSharePredicates = new dataSharePredicates.DataSharePredicates(); 4028 let fetchOption: photoAccessHelper.FetchOptions = { 4029 fetchColumns: [], 4030 predicates: predicates 4031 }; 4032 let fetchResult: photoAccessHelper.FetchResult<photoAccessHelper.PhotoAsset> = await phAccessHelper.getAssets(fetchOption); 4033 let asset = await fetchResult.getFirstObject(); 4034 let assetChangeRequest: photoAccessHelper.MediaAssetChangeRequest = new photoAccessHelper.MediaAssetChangeRequest(asset); 4035 assetChangeRequest.setLocation(120.52, 30.40); 4036 phAccessHelper.applyChanges(assetChangeRequest).then(() => { 4037 console.info('apply setLocation successfully'); 4038 }).catch((err: BusinessError) => { 4039 console.error(`apply setLocation failed with error: ${err.code}, ${err.message}`); 4040 }); 4041} 4042``` 4043 4044### setCameraShotKey<sup>12+</sup> 4045 4046setCameraShotKey(cameraShotKey: string): void 4047 4048设置锁屏相机拍照或录像的标记字段。 4049 4050**系统接口**:此接口为系统接口。 4051 4052**系统能力**:SystemCapability.FileManagement.PhotoAccessHelper.Core 4053 4054**参数:** 4055 4056| 参数名 | 类型 | 必填 | 说明 | 4057| ---------- | ------- | ---- | ---------------------------------- | 4058| cameraShotKey | string | 是 | 锁屏相机拍照或录像的标记字段(仅开放给系统相机,其key值由系统相机定义)。 | 4059 4060**错误码:** 4061 4062接口抛出错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)和[文件管理错误码](../apis-core-file-kit/errorcode-filemanagement.md)。 4063 4064| 错误码ID | 错误信息 | 4065| -------- | ---------------------------------------- | 4066| 202 | Called by non-system application. | 4067| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types; 3. Parameter verification failed. | 4068| 14000011 | System inner fail. | 4069 4070**示例:** 4071 4072```ts 4073async function example(asset: photoAccessHelper.PhotoAsset) { 4074 console.info('setCameraShotKeyDemo'); 4075 try { 4076 let assetChangeRequest: photoAccessHelper.MediaAssetChangeRequest = new photoAccessHelper.MediaAssetChangeRequest(asset); 4077 let cameraShotKey: string = 'test_MediaAssetChangeRequest_setCameraShotKey'; 4078 assetChangeRequest.setCameraShotKey(cameraShotKey); 4079 await phAccessHelper.applyChanges(assetChangeRequest); 4080 console.info('apply setCameraShotKey successfully'); 4081 } catch (err) { 4082 console.error(`apply setCameraShotKey failed with error: ${err.code}, ${err.message}`); 4083 } 4084} 4085``` 4086 4087### setEffectMode<sup>12+</sup> 4088 4089setEffectMode(mode: MovingPhotoEffectMode): void 4090 4091设置动态照片的效果模式。 4092 4093**系统接口**:此接口为系统接口。 4094 4095**系统能力**:SystemCapability.FileManagement.PhotoAccessHelper.Core 4096 4097**参数:** 4098 4099| 参数名 | 类型 | 必填 | 说明 | 4100| ---------- | ------- | ---- | ---------------------------------- | 4101| mode | [MovingPhotoEffectMode](#movingphotoeffectmode12) | 是 | 动态照片效果模式。 | 4102 4103**错误码:** 4104 4105接口抛出错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)和[文件管理错误码](../apis-core-file-kit/errorcode-filemanagement.md)。 4106 4107| 错误码ID | 错误信息 | 4108| -------- | ---------------------------------------- | 4109| 202 | Called by non-system application. | 4110| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types; 3. Parameter verification failed. | 4111| 14000011 | System inner fail. | 4112| 14000016 | Operation Not Support. | 4113 4114**示例:** 4115 4116```ts 4117async function example(asset: photoAccessHelper.PhotoAsset) { 4118 console.info('setEffectModeDemo'); 4119 try { 4120 let assetChangeRequest: photoAccessHelper.MediaAssetChangeRequest = new photoAccessHelper.MediaAssetChangeRequest(asset); 4121 assetChangeRequest.setEffectMode(photoAccessHelper.MovingPhotoEffectMode.LONG_EXPOSURE); 4122 // 需要确保fileUri对应的资源存在。 4123 let imageFileUri = 'file://com.example.temptest/data/storage/el2/base/haps/entry/files/long_exposure.jpg'; 4124 let videoFileUri = 'file://com.example.temptest/data/storage/el2/base/haps/entry/files/long_exposure.mp4'; 4125 assetChangeRequest.addResource(photoAccessHelper.ResourceType.IMAGE_RESOURCE, imageFileUri); 4126 assetChangeRequest.addResource(photoAccessHelper.ResourceType.VIDEO_RESOURCE, videoFileUri); 4127 await phAccessHelper.applyChanges(assetChangeRequest); 4128 console.info('apply setEffectMode successfully'); 4129 } catch (err) { 4130 console.error(`apply setEffectMode failed with error: ${err.code}, ${err.message}`); 4131 } 4132} 4133``` 4134 4135### setSupportedWatermarkType<sup>14+</sup> 4136 4137setSupportedWatermarkType(watermarkType: WatermarkType): void 4138 4139设置拍照照片支持的水印类型。 4140 4141**系统接口**:此接口为系统接口。 4142 4143**系统能力**:SystemCapability.FileManagement.PhotoAccessHelper.Core 4144 4145**参数:** 4146 4147| 参数名 | 类型 | 必填 | 说明 | 4148| ---------- | ------- | ---- | ---------------------------------- | 4149| watermarkType | [WatermarkType](#watermarktype14) | 是 | 水印可编辑标识。 | 4150 4151**错误码:** 4152 4153接口抛出错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)和[文件管理错误码](../apis-core-file-kit/errorcode-filemanagement.md)。 4154 4155| 错误码ID | 错误信息 | 4156| -------- | ---------------------------------------- | 4157| 202 | Called by non-system application. | 4158| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types; 3. Parameter verification failed. | 4159| 14000011 | Internal system error. | 4160 4161**示例:** 4162 4163```ts 4164import { dataSharePredicates } from '@kit.ArkData'; 4165import photoAccessHelper from '@ohos.file.photoAccessHelper'; 4166 4167const context = getContext(this); 4168let phAccessHelper = photoAccessHelper.getPhotoAccessHelper(context); 4169 4170async function example() { 4171 console.info('setSupportedWatermarkTypeDemo'); 4172 let predicates: dataSharePredicates.DataSharePredicates = new dataSharePredicates.DataSharePredicates(); 4173 let fetchOption: photoAccessHelper.FetchOptions = { 4174 fetchColumns: [], 4175 predicates: predicates 4176 }; 4177 try { 4178 let fetchResult: photoAccessHelper.FetchResult<photoAccessHelper.PhotoAsset> = await phAccessHelper.getAssets(fetchOption); 4179 let asset = await fetchResult.getFirstObject(); 4180 let assetChangeRequest: photoAccessHelper.MediaAssetChangeRequest = new photoAccessHelper.MediaAssetChangeRequest(asset); 4181 assetChangeRequest.setSupportedWatermarkType(photoAccessHelper.WatermarkType.BRAND_COMMON); 4182 await phAccessHelper.applyChanges(assetChangeRequest); 4183 console.info('apply setSupportedWatermarkType successfully'); 4184 } catch (err) { 4185 console.error(`apply setSupportedWatermarkType failed with error: ${err.code}, ${err.message}`); 4186 } 4187} 4188``` 4189 4190## MediaAssetsChangeRequest<sup>11+</sup> 4191 4192批量资产变更请求。 4193 4194**系统接口**:此接口为系统接口。 4195 4196**系统能力**:SystemCapability.FileManagement.PhotoAccessHelper.Core 4197 4198### constructor<sup>11+</sup> 4199 4200constructor(assets: Array<PhotoAsset>) 4201 4202构造函数。 4203 4204**系统接口**:此接口为系统接口。 4205 4206**系统能力**:SystemCapability.FileManagement.PhotoAccessHelper.Core 4207 4208**参数:** 4209 4210| 参数名 | 类型 | 必填 | 说明 | 4211| -------- | ------------------------- | ---- | ---------- | 4212| assets | Array<[PhotoAsset](#photoasset)> | 是 | 需要变更的资产数组。 | 4213 4214**错误码:** 4215 4216接口抛出错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)和[文件管理错误码](../apis-core-file-kit/errorcode-filemanagement.md)。 4217 4218| 错误码ID | 错误信息 | 4219| -------- | ---------------------------------------- | 4220| 202 | Called by non-system application. | 4221| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types; 3. Parameter verification failed. | 4222| 14000011 | System inner fail. | 4223 4224**示例:** 4225 4226```ts 4227import { dataSharePredicates } from '@kit.ArkData'; 4228 4229async function example() { 4230 console.info('MediaAssetsChangeRequest constructorDemo'); 4231 let predicates: dataSharePredicates.DataSharePredicates = new dataSharePredicates.DataSharePredicates(); 4232 let fetchOption: photoAccessHelper.FetchOptions = { 4233 fetchColumns: [], 4234 predicates: predicates 4235 }; 4236 let fetchResult: photoAccessHelper.FetchResult<photoAccessHelper.PhotoAsset> = await phAccessHelper.getAssets(fetchOption); 4237 let photoAssetList: Array<photoAccessHelper.PhotoAsset> = await fetchResult.getAllObjects(); 4238 let assetsChangeRequest: photoAccessHelper.MediaAssetsChangeRequest = new photoAccessHelper.MediaAssetsChangeRequest(photoAssetList); 4239} 4240``` 4241 4242### setFavorite<sup>11+</sup> 4243 4244setFavorite(favoriteState: boolean): void 4245 4246将文件设置为收藏文件。 4247 4248**系统接口**:此接口为系统接口。 4249 4250**系统能力**:SystemCapability.FileManagement.PhotoAccessHelper.Core 4251 4252**参数:** 4253 4254| 参数名 | 类型 | 必填 | 说明 | 4255| ---------- | ------- | ---- | ---------------------------------- | 4256| favoriteState | boolean | 是 | 是否设置为收藏文件, true:设置为收藏文件;false:取消收藏。 | 4257 4258**错误码:** 4259 4260接口抛出错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)和[文件管理错误码](../apis-core-file-kit/errorcode-filemanagement.md)。 4261 4262| 错误码ID | 错误信息 | 4263| -------- | ---------------------------------------- | 4264| 202 | Called by non-system application. | 4265| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types; 3. Parameter verification failed. | 4266| 14000011 | System inner fail. | 4267 4268**示例:** 4269 4270```ts 4271import { dataSharePredicates } from '@kit.ArkData'; 4272import { BusinessError } from '@kit.BasicServicesKit'; 4273 4274async function example() { 4275 console.info('setFavoriteDemo'); 4276 let predicates: dataSharePredicates.DataSharePredicates = new dataSharePredicates.DataSharePredicates(); 4277 let fetchOption: photoAccessHelper.FetchOptions = { 4278 fetchColumns: [], 4279 predicates: predicates 4280 }; 4281 let fetchResult: photoAccessHelper.FetchResult<photoAccessHelper.PhotoAsset> = await phAccessHelper.getAssets(fetchOption); 4282 let photoAssetList: Array<photoAccessHelper.PhotoAsset> = await fetchResult.getAllObjects(); 4283 let assetsChangeRequest: photoAccessHelper.MediaAssetsChangeRequest = new photoAccessHelper.MediaAssetsChangeRequest(photoAssetList); 4284 assetsChangeRequest.setFavorite(true); 4285 phAccessHelper.applyChanges(assetsChangeRequest).then(() => { 4286 console.info('apply setFavorite successfully'); 4287 }).catch((err: BusinessError) => { 4288 console.error(`apply setFavorite failed with error: ${err.code}, ${err.message}`); 4289 }); 4290} 4291``` 4292 4293### setHidden<sup>11+</sup> 4294 4295setHidden(hiddenState: boolean): void 4296 4297将文件设置为隐藏文件。 4298 4299**系统接口**:此接口为系统接口。 4300 4301**系统能力**:SystemCapability.FileManagement.PhotoAccessHelper.Core 4302 4303**参数:** 4304 4305| 参数名 | 类型 | 必填 | 说明 | 4306| ---------- | ------- | ---- | ---------------------------------- | 4307| hiddenState | boolean | 是 | 是否设置为隐藏文件,true:将文件资产放入隐藏相册;false:从隐藏相册中恢复。 | 4308 4309**错误码:** 4310 4311接口抛出错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)和[文件管理错误码](../apis-core-file-kit/errorcode-filemanagement.md)。 4312 4313| 错误码ID | 错误信息 | 4314| -------- | ---------------------------------------- | 4315| 202 | Called by non-system application. | 4316| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types; 3. Parameter verification failed. | 4317| 14000011 | System inner fail. | 4318 4319**示例:** 4320 4321```ts 4322import { dataSharePredicates } from '@kit.ArkData'; 4323import { BusinessError } from '@kit.BasicServicesKit'; 4324 4325async function example() { 4326 console.info('setHiddenDemo'); 4327 let predicates: dataSharePredicates.DataSharePredicates = new dataSharePredicates.DataSharePredicates(); 4328 let fetchOption: photoAccessHelper.FetchOptions = { 4329 fetchColumns: [], 4330 predicates: predicates 4331 }; 4332 let fetchResult: photoAccessHelper.FetchResult<photoAccessHelper.PhotoAsset> = await phAccessHelper.getAssets(fetchOption); 4333 let photoAssetList: Array<photoAccessHelper.PhotoAsset> = await fetchResult.getAllObjects(); 4334 let assetsChangeRequest: photoAccessHelper.MediaAssetsChangeRequest = new photoAccessHelper.MediaAssetsChangeRequest(photoAssetList); 4335 assetsChangeRequest.setHidden(true); 4336 phAccessHelper.applyChanges(assetsChangeRequest).then(() => { 4337 console.info('apply setHidden successfully'); 4338 }).catch((err: BusinessError) => { 4339 console.error(`apply setHidden failed with error: ${err.code}, ${err.message}`); 4340 }); 4341} 4342``` 4343 4344### setUserComment<sup>11+</sup> 4345 4346setUserComment(userComment: string): void 4347 4348修改媒体资产的备注信息。 4349 4350**系统接口**:此接口为系统接口。 4351 4352**系统能力**:SystemCapability.FileManagement.PhotoAccessHelper.Core 4353 4354**参数:** 4355 4356| 参数名 | 类型 | 必填 | 说明 | 4357| ---------- | ------- | ---- | ---------------------------------- | 4358| userComment | string | 是 | 待修改的资产备注信息,备注信息最长为420字符。 | 4359 4360**错误码:** 4361 4362接口抛出错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)和[文件管理错误码](../apis-core-file-kit/errorcode-filemanagement.md)。 4363 4364| 错误码ID | 错误信息 | 4365| -------- | ---------------------------------------- | 4366| 202 | Called by non-system application. | 4367| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types; 3. Parameter verification failed. | 4368| 14000011 | System inner fail. | 4369 4370**示例:** 4371 4372```ts 4373import { dataSharePredicates } from '@kit.ArkData'; 4374import { BusinessError } from '@kit.BasicServicesKit'; 4375 4376async function example() { 4377 console.info('setUserCommentDemo'); 4378 let predicates: dataSharePredicates.DataSharePredicates = new dataSharePredicates.DataSharePredicates(); 4379 let fetchOption: photoAccessHelper.FetchOptions = { 4380 fetchColumns: [], 4381 predicates: predicates 4382 }; 4383 let fetchResult: photoAccessHelper.FetchResult<photoAccessHelper.PhotoAsset> = await phAccessHelper.getAssets(fetchOption); 4384 let photoAssetList: Array<photoAccessHelper.PhotoAsset> = await fetchResult.getAllObjects(); 4385 let assetsChangeRequest: photoAccessHelper.MediaAssetsChangeRequest = new photoAccessHelper.MediaAssetsChangeRequest(photoAssetList); 4386 assetsChangeRequest.setUserComment('test_set_user_comment'); 4387 phAccessHelper.applyChanges(assetsChangeRequest).then(() => { 4388 console.info('apply setUserComment successfully'); 4389 }).catch((err: BusinessError) => { 4390 console.error(`apply setUserComment failed with error: ${err.code}, ${err.message}`); 4391 }); 4392} 4393``` 4394 4395## MediaAlbumChangeRequest<sup>11+</sup> 4396 4397相册变更请求。 4398 4399**系统能力**:SystemCapability.FileManagement.PhotoAccessHelper.Core 4400 4401### createAlbumRequest<sup>11+</sup> 4402 4403static createAlbumRequest(context: Context, name: string): MediaAlbumChangeRequest 4404 4405创建相册变更请求。 4406 4407相册名的参数规格为: 4408- 相册名字符串长度为1~255。 4409- 不允许出现非法字符,包括:<br> . .. \ / : * ? " ' ` < > | { } [ ] 4410- 英文字符大小写不敏感。 4411- 相册名不允许重名。 4412 4413**系统接口**:此接口为系统接口。 4414 4415**系统能力**:SystemCapability.FileManagement.PhotoAccessHelper.Core 4416 4417**参数:** 4418 4419| 参数名 | 类型 | 必填 | 说明 | 4420| ------- | ------- | ---- | -------------------------- | 4421| context | [Context](../apis-ability-kit/js-apis-inner-application-context.md) | 是 | 传入Ability实例的Context。 | 4422| name | string | 是 | 待创建相册的名称。| 4423 4424**返回值:** 4425 4426| 类型 | 说明 | 4427| --------------------------------------- | ----------------- | 4428| [MediaAlbumChangeRequest](#mediaalbumchangerequest11) | 返回创建相册的变更请求。 | 4429 4430**错误码:** 4431 4432接口抛出错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)和[文件管理错误码](../apis-core-file-kit/errorcode-filemanagement.md)。 4433 4434| 错误码ID | 错误信息 | 4435| -------- | ---------------------------------------- | 4436| 202 | Called by non-system application. | 4437| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types; 3. Parameter verification failed. | 4438| 14000011 | System inner fail. | 4439 4440**示例:** 4441 4442```ts 4443async function example() { 4444 console.info('createAlbumRequestDemo'); 4445 try { 4446 let albumName: string = 'newAlbumName' + new Date().getTime(); 4447 let albumChangeRequest: photoAccessHelper.MediaAlbumChangeRequest = photoAccessHelper.MediaAlbumChangeRequest.createAlbumRequest(context, albumName); 4448 await phAccessHelper.applyChanges(albumChangeRequest); 4449 console.info('apply createAlbumRequest successfully'); 4450 } catch (err) { 4451 console.error(`createAlbumRequestDemo failed with error: ${err.code}, ${err.message}`); 4452 } 4453} 4454``` 4455 4456### deleteAlbums<sup>11+</sup> 4457 4458static deleteAlbums(context: Context, albums: Array<Album>): Promise<void> 4459 4460删除相册,使用Promise方式返回结果。 4461 4462删除相册前需先确保相册存在,只能删除用户相册。 4463 4464**系统接口**:此接口为系统接口。 4465 4466**需要权限**:ohos.permission.WRITE_IMAGEVIDEO 4467 4468**系统能力**:SystemCapability.FileManagement.PhotoAccessHelper.Core 4469 4470**参数:** 4471 4472| 参数名 | 类型 | 必填 | 说明 | 4473| ------- | ------- | ---- | -------------------------- | 4474| context | [Context](../apis-ability-kit/js-apis-inner-application-context.md) | 是 | 传入Ability实例的Context。 | 4475| albums | Array<[Album](#album)> | 是 | 待删除的相册数组。 | 4476 4477**返回值:** 4478 4479| 类型 | 说明 | 4480| --------------------------------------- | ----------------- | 4481| Promise<void>| Promise对象,返回void。 | 4482 4483**错误码:** 4484 4485接口抛出错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)和[文件管理错误码](../apis-core-file-kit/errorcode-filemanagement.md)。 4486 4487| 错误码ID | 错误信息 | 4488| -------- | ---------------------------------------- | 4489| 201 | Permission denied. | 4490| 202 | Called by non-system application. | 4491| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types; 3. Parameter verification failed. | 4492| 14000011 | System inner fail. | 4493 4494**示例:** 4495 4496```ts 4497import { dataSharePredicates } from '@kit.ArkData'; 4498 4499async function example() { 4500 console.info('deleteAlbumsDemo'); 4501 let predicates: dataSharePredicates.DataSharePredicates = new dataSharePredicates.DataSharePredicates(); 4502 let fetchOptions: photoAccessHelper.FetchOptions = { 4503 fetchColumns: [], 4504 predicates: predicates 4505 }; 4506 try { 4507 let fetchResult: photoAccessHelper.FetchResult<photoAccessHelper.Album> = await phAccessHelper.getAlbums(photoAccessHelper.AlbumType.USER, photoAccessHelper.AlbumSubtype.USER_GENERIC, fetchOptions); 4508 let album: photoAccessHelper.Album = await fetchResult.getFirstObject(); 4509 await photoAccessHelper.MediaAlbumChangeRequest.deleteAlbums(context, [album]); 4510 console.info('deleteAlbums successfully'); 4511 } catch (err) { 4512 console.error(`deleteAlbumsDemo failed with error: ${err.code}, ${err.message}`); 4513 } 4514} 4515``` 4516 4517### setCoverUri<sup>11+</sup> 4518 4519setCoverUri(coverUri: string): void 4520 4521设置相册封面。 4522 4523**系统接口**:此接口为系统接口。 4524 4525**系统能力**:SystemCapability.FileManagement.PhotoAccessHelper.Core 4526 4527**参数:** 4528 4529| 参数名 | 类型 | 必填 | 说明 | 4530| ---------- | ------- | ---- | ---------------------------------- | 4531| coverUri | string | 是 | 待设置为相册封面文件的uri。 | 4532 4533**错误码:** 4534 4535接口抛出错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)和[文件管理错误码](../apis-core-file-kit/errorcode-filemanagement.md)。 4536 4537| 错误码ID | 错误信息 | 4538| -------- | ---------------------------------------- | 4539| 202 | Called by non-system application. | 4540| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types; 3. Parameter verification failed. | 4541| 14000011 | System inner fail. | 4542 4543**示例:** 4544 4545```ts 4546import { dataSharePredicates } from '@kit.ArkData'; 4547 4548async function example() { 4549 console.info('setCoverUriDemo'); 4550 let predicates: dataSharePredicates.DataSharePredicates = new dataSharePredicates.DataSharePredicates(); 4551 let fetchOptions: photoAccessHelper.FetchOptions = { 4552 fetchColumns: [], 4553 predicates: predicates 4554 }; 4555 try { 4556 let albumFetchResult: photoAccessHelper.FetchResult<photoAccessHelper.Album> = await phAccessHelper.getAlbums(photoAccessHelper.AlbumType.USER, photoAccessHelper.AlbumSubtype.USER_GENERIC); 4557 let album: photoAccessHelper.Album = await albumFetchResult.getFirstObject(); 4558 let fetchResult: photoAccessHelper.FetchResult<photoAccessHelper.PhotoAsset> = await album.getAssets(fetchOptions); 4559 let asset: photoAccessHelper.PhotoAsset = await fetchResult.getFirstObject(); 4560 4561 let albumChangeRequest: photoAccessHelper.MediaAlbumChangeRequest = new photoAccessHelper.MediaAlbumChangeRequest(album); 4562 albumChangeRequest.setCoverUri(asset.uri); 4563 await phAccessHelper.applyChanges(albumChangeRequest); 4564 console.info('setCoverUri successfully'); 4565 } catch (err) { 4566 console.error(`setCoverUriDemo failed with error: ${err.code}, ${err.message}`); 4567 } 4568} 4569``` 4570 4571### moveAssets<sup>11+</sup> 4572 4573moveAssets(assets: Array<PhotoAsset>, targetAlbum: Album): void 4574 4575从相册中移动资产到另一个目标相册。 4576 4577**系统接口**:此接口为系统接口。 4578 4579**系统能力**:SystemCapability.FileManagement.PhotoAccessHelper.Core 4580 4581**参数:** 4582 4583| 参数名 | 类型 | 必填 | 说明 | 4584| ---------- | ------- | ---- | ---------------------------------- | 4585| assets | Array<[PhotoAsset](#photoasset)> | 是 | 待从相册中移出的资产数组。 | 4586| targetAlbum | Album | 是 | 待移入资产的目标相册。 | 4587 4588**错误码:** 4589 4590接口抛出错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)和[文件管理错误码](../apis-core-file-kit/errorcode-filemanagement.md)。 4591 4592| 错误码ID | 错误信息 | 4593| -------- | ---------------------------------------- | 4594| 202 | Called by non-system application. | 4595| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types; 3. Parameter verification failed. | 4596| 14000011 | System inner fail. | 4597| 14000016 | Operation Not Support. | 4598 4599**示例:** 4600 4601```ts 4602import { dataSharePredicates } from '@kit.ArkData'; 4603 4604async function example() { 4605 console.info('moveAssetsDemo'); 4606 let predicates: dataSharePredicates.DataSharePredicates = new dataSharePredicates.DataSharePredicates(); 4607 let fetchOptions: photoAccessHelper.FetchOptions = { 4608 fetchColumns: [], 4609 predicates: predicates 4610 }; 4611 try { 4612 let albumFetchResult: photoAccessHelper.FetchResult<photoAccessHelper.Album> = await phAccessHelper.getAlbums(photoAccessHelper.AlbumType.USER, photoAccessHelper.AlbumSubtype.USER_GENERIC); 4613 let album: photoAccessHelper.Album = await albumFetchResult.getFirstObject(); 4614 let fetchResult: photoAccessHelper.FetchResult<photoAccessHelper.PhotoAsset> = await album.getAssets(fetchOptions); 4615 let asset: photoAccessHelper.PhotoAsset = await fetchResult.getFirstObject(); 4616 4617 if (albumFetchResult.isAfterLast()) { 4618 console.error('lack of album to be moved into'); 4619 return; 4620 } 4621 let nextAlbum: photoAccessHelper.Album = await albumFetchResult.getNextObject(); 4622 let albumChangeRequest: photoAccessHelper.MediaAlbumChangeRequest = new photoAccessHelper.MediaAlbumChangeRequest(album); 4623 albumChangeRequest.moveAssets([asset], nextAlbum); 4624 await phAccessHelper.applyChanges(albumChangeRequest); 4625 console.info('moveAssets successfully'); 4626 } catch (err) { 4627 console.error(`moveAssetsDemo failed with error: ${err.code}, ${err.message}`); 4628 } 4629} 4630``` 4631 4632### recoverAssets<sup>11+</sup> 4633 4634recoverAssets(assets: Array<PhotoAsset>): void 4635 4636从回收站中恢复资产。 4637 4638**系统接口**:此接口为系统接口。 4639 4640**系统能力**:SystemCapability.FileManagement.PhotoAccessHelper.Core 4641 4642**参数:** 4643 4644| 参数名 | 类型 | 必填 | 说明 | 4645| ---------- | ------- | ---- | ---------------------------------- | 4646| assets | Array<[PhotoAsset](#photoasset)> | 是 | 待从回收站中恢复的资产数组。 | 4647 4648**错误码:** 4649 4650接口抛出错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)和[文件管理错误码](../apis-core-file-kit/errorcode-filemanagement.md)。 4651 4652| 错误码ID | 错误信息 | 4653| -------- | ---------------------------------------- | 4654| 202 | Called by non-system application. | 4655| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types; 3. Parameter verification failed. | 4656| 14000011 | System inner fail. | 4657| 14000016 | Operation Not Support. | 4658 4659**示例:** 4660 4661```ts 4662import { dataSharePredicates } from '@kit.ArkData'; 4663 4664async function example() { 4665 console.info('recoverAssetsDemo'); 4666 let predicates: dataSharePredicates.DataSharePredicates = new dataSharePredicates.DataSharePredicates(); 4667 let fetchOptions: photoAccessHelper.FetchOptions = { 4668 fetchColumns: [], 4669 predicates: predicates 4670 }; 4671 try { 4672 let albumFetchResult: photoAccessHelper.FetchResult<photoAccessHelper.Album> = await phAccessHelper.getAlbums(photoAccessHelper.AlbumType.SYSTEM, photoAccessHelper.AlbumSubtype.TRASH); 4673 let album: photoAccessHelper.Album = await albumFetchResult.getFirstObject(); 4674 let fetchResult: photoAccessHelper.FetchResult<photoAccessHelper.PhotoAsset> = await album.getAssets(fetchOptions); 4675 let asset: photoAccessHelper.PhotoAsset = await fetchResult.getFirstObject(); 4676 4677 let albumChangeRequest: photoAccessHelper.MediaAlbumChangeRequest = new photoAccessHelper.MediaAlbumChangeRequest(album); 4678 albumChangeRequest.recoverAssets([asset]); 4679 await phAccessHelper.applyChanges(albumChangeRequest); 4680 console.info('recoverAssets successfully'); 4681 } catch (err) { 4682 console.error(`recoverAssetsDemo failed with error: ${err.code}, ${err.message}`); 4683 } 4684} 4685``` 4686 4687### deleteAssets<sup>11+</sup> 4688 4689deleteAssets(assets: Array<PhotoAsset>): void 4690 4691从回收站中彻底删除资产。 4692 4693**注意**:此操作不可逆,执行此操作后文件资源将彻底删除,请谨慎操作。 4694 4695**系统接口**:此接口为系统接口。 4696 4697**系统能力**:SystemCapability.FileManagement.PhotoAccessHelper.Core 4698 4699**参数:** 4700 4701| 参数名 | 类型 | 必填 | 说明 | 4702| ---------- | ------- | ---- | ---------------------------------- | 4703| assets | Array<[PhotoAsset](#photoasset)> | 是 | 待从回收站中彻底删除的资产数组。 | 4704 4705**错误码:** 4706 4707接口抛出错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)和[文件管理错误码](../apis-core-file-kit/errorcode-filemanagement.md)。 4708 4709| 错误码ID | 错误信息 | 4710| -------- | ---------------------------------------- | 4711| 202 | Called by non-system application. | 4712| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types; 3. Parameter verification failed. | 4713| 14000011 | System inner fail. | 4714| 14000016 | Operation Not Support. | 4715 4716**示例:** 4717 4718```ts 4719import { dataSharePredicates } from '@kit.ArkData'; 4720 4721async function example() { 4722 console.info('deleteAssetsPermanentlyDemo'); 4723 let predicates: dataSharePredicates.DataSharePredicates = new dataSharePredicates.DataSharePredicates(); 4724 let fetchOptions: photoAccessHelper.FetchOptions = { 4725 fetchColumns: [], 4726 predicates: predicates 4727 }; 4728 try { 4729 let albumFetchResult: photoAccessHelper.FetchResult<photoAccessHelper.Album> = await phAccessHelper.getAlbums(photoAccessHelper.AlbumType.SYSTEM, photoAccessHelper.AlbumSubtype.TRASH); 4730 let album: photoAccessHelper.Album = await albumFetchResult.getFirstObject(); 4731 let fetchResult: photoAccessHelper.FetchResult<photoAccessHelper.PhotoAsset> = await album.getAssets(fetchOptions); 4732 let asset: photoAccessHelper.PhotoAsset = await fetchResult.getFirstObject(); 4733 4734 let albumChangeRequest: photoAccessHelper.MediaAlbumChangeRequest = new photoAccessHelper.MediaAlbumChangeRequest(album); 4735 albumChangeRequest.deleteAssets([asset]); 4736 await phAccessHelper.applyChanges(albumChangeRequest); 4737 console.info('succeed to deleteAssets permanently'); 4738 } catch (err) { 4739 console.error(`deleteAssetsPermanentlyDemo failed with error: ${err.code}, ${err.message}`); 4740 } 4741} 4742``` 4743 4744### setDisplayLevel<sup>11+</sup> 4745 4746setDisplayLevel(displayLevel: number): void 4747 4748设置人像相册的显示级别。 4749 4750**系统接口**:此接口为系统接口。 4751 4752**系统能力**:SystemCapability.FileManagement.PhotoAccessHelper.Core 4753 4754**参数:** 4755 4756| 参数名 | 类型 | 必填 | 说明 | 4757| ---------- | ------- | ---- | ---------------------------------- | 4758| displayLevel | number | 是 | 设置人像相册的显示级别, 0:取消该人像相册收藏;1:设置人像相册为首届面;2:设置人像相册为更多界面;3:设置人像相册为收藏界面。 | 4759 4760**错误码:** 4761 4762接口抛出错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)和[文件管理错误码](../apis-core-file-kit/errorcode-filemanagement.md)。 4763 4764| 错误码ID | 错误信息 | 4765| -------- | ---------------------------------------- | 4766| 202 | Called by non-system application. | 4767| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types; 3. Parameter verification failed. | 4768| 14000011 | System inner fail. | 4769 4770**示例:** 4771 4772``` ts 4773import { dataSharePredicates } from '@kit.ArkData'; 4774 4775async function example() { 4776 try { 4777 console.info('setDisplayLevel Example') 4778 let predicates: dataSharePredicates.DataSharePredicates = new dataSharePredicates.DataSharePredicates(); 4779 predicates.equalTo('user_display_level', 2); 4780 let fetchOptions: photoAccessHelper.FetchOptions = { 4781 fetchColumns: [], 4782 predicates: predicates 4783 }; 4784 let fetchResult: photoAccessHelper.FetchResult<photoAccessHelper.Album> = await phAccessHelper.getAlbums(photoAccessHelper.AlbumType.SMART, photoAccessHelper.AlbumSubtype.PORTRAIT, fetchOptions); 4785 let album: photoAccessHelper.Album = await fetchResult.getFirstObject(); 4786 let changeRequest: photoAccessHelper.MediaAlbumChangeRequest = new photoAccessHelper.MediaAlbumChangeRequest(album); 4787 changeRequest.setDisplayLevel(1); 4788 await phAccessHelper.applyChanges(changeRequest); 4789 } catch (err) { 4790 console.error(`setDisplayLevel failed with error: ${err.code}, ${err.message}`); 4791 } 4792} 4793``` 4794 4795### setIsMe<sup>11+</sup> 4796 4797setIsMe(): void 4798 4799将人像相册的人物关系设置为“我”。 4800 4801**系统接口**:此接口为系统接口。 4802 4803**系统能力**:SystemCapability.FileManagement.PhotoAccessHelper.Core 4804 4805**错误码:** 4806 4807接口抛出错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)和[文件管理错误码](../apis-core-file-kit/errorcode-filemanagement.md)。 4808 4809| 错误码ID | 错误信息 | 4810| -------- | ---------------------------------------- | 4811| 202 | Called by non-system application. | 4812| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types. | 4813| 14000011 | System inner fail. | 4814 4815**示例:** 4816 4817``` ts 4818import { dataSharePredicates } from '@kit.ArkData'; 4819 4820async function example() { 4821 try { 4822 console.info('setIsMe Example') 4823 let predicates: dataSharePredicates.DataSharePredicates = new dataSharePredicates.DataSharePredicates(); 4824 predicates.equalTo('user_display_level', 2); 4825 let fetchOptions: photoAccessHelper.FetchOptions = { 4826 fetchColumns: [], 4827 predicates: predicates 4828 }; 4829 let fetchResult: photoAccessHelper.FetchResult<photoAccessHelper.Album> = await phAccessHelper.getAlbums(photoAccessHelper.AlbumType.SMART, photoAccessHelper.AlbumSubtype.PORTRAIT, fetchOptions); 4830 let album: photoAccessHelper.Album = await fetchResult.getFirstObject(); 4831 let changeRequest: photoAccessHelper.MediaAlbumChangeRequest = new photoAccessHelper.MediaAlbumChangeRequest(album); 4832 changeRequest.setIsMe(); 4833 await phAccessHelper.applyChanges(changeRequest); 4834 } catch (err) { 4835 console.error(`setIsMe failed with error: ${err.code}, ${err.message}`); 4836 } 4837} 4838``` 4839 4840### dismissAssets<sup>11+</sup> 4841 4842dismissAssets(assets: Array<PhotoAsset>): void 4843 4844从该人像相册或合影相册中移除指定图片。 4845 4846**系统接口**:此接口为系统接口。 4847 4848**系统能力**:SystemCapability.FileManagement.PhotoAccessHelper.Core 4849 4850**参数:** 4851 4852| 参数名 | 类型 | 必填 | 说明 | 4853| ---------- | ------- | ---- | ---------------------------------- | 4854| assets | Array<PhotoAsset> | 是 | 需要移除的文件列表。 | 4855 4856**错误码:** 4857 4858接口抛出错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)和[文件管理错误码](../apis-core-file-kit/errorcode-filemanagement.md)。 4859 4860| 错误码ID | 错误信息 | 4861| -------- | ---------------------------------------- | 4862| 202 | Called by non-system application. | 4863| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types; 3. Parameter verification failed. | 4864| 14000011 | System inner fail. | 4865| 14000016 | Operation Not support. | 4866 4867**示例:** 4868 4869``` ts 4870import { dataSharePredicates } from '@kit.ArkData'; 4871 4872async function example() { 4873 try { 4874 console.info('dismissAssets Example') 4875 let predicates: dataSharePredicates.DataSharePredicates = new dataSharePredicates.DataSharePredicates(); 4876 predicates.equalTo('user_display_level', 2); 4877 let fetchOptions: photoAccessHelper.FetchOptions = { 4878 fetchColumns: [], 4879 predicates: predicates 4880 }; 4881 let fetchResult: photoAccessHelper.FetchResult<photoAccessHelper.Album> = await phAccessHelper.getAlbums(photoAccessHelper.AlbumType.SMART, photoAccessHelper.AlbumSubtype.PORTRAIT, fetchOptions); 4882 let album: photoAccessHelper.Album = await fetchResult.getFirstObject(); 4883 4884 let predicatesAsset: dataSharePredicates.DataSharePredicates = new dataSharePredicates.DataSharePredicates(); 4885 let assetFetchOptions: photoAccessHelper.FetchOptions = { 4886 fetchColumns: [], 4887 predicates: predicatesAsset 4888 }; 4889 let assetFetchResult: photoAccessHelper.FetchResult<photoAccessHelper.PhotoAsset> = await phAccessHelper.getAssets(assetFetchOptions); 4890 let asset: photoAccessHelper.PhotoAsset = await assetFetchResult.getFirstObject(); 4891 4892 let changeRequest: photoAccessHelper.MediaAlbumChangeRequest = new photoAccessHelper.MediaAlbumChangeRequest(album); 4893 changeRequest.dismissAssets([asset]); 4894 await phAccessHelper.applyChanges(changeRequest); 4895 } catch (err) { 4896 console.error(`dismissAssets failed with error: ${err.code}, ${err.message}`); 4897 } 4898} 4899``` 4900 4901### mergeAlbum<sup>11+</sup> 4902 4903mergeAlbum(target: Album): void 4904 4905将两个人像相册合并。 4906 4907**系统接口**:此接口为系统接口。 4908 4909**系统能力**:SystemCapability.FileManagement.PhotoAccessHelper.Core 4910 4911**参数:** 4912 4913| 参数名 | 类型 | 必填 | 说明 | 4914| ---------- | ------- | ---- | ---------------------------------- | 4915| target | [Album](#album) | 是 | 需要合并的目标相册,合并相册必须重命名。 | 4916 4917**错误码:** 4918 4919接口抛出错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)和[文件管理错误码](../apis-core-file-kit/errorcode-filemanagement.md)。 4920 4921| 错误码ID | 错误信息 | 4922| -------- | ---------------------------------------- | 4923| 202 | Called by non-system application. | 4924| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types; 3. Parameter verification failed. | 4925| 14000011 | System inner fail. | 4926| 14000016 | Operation Not support. | 4927 4928**示例:** 4929 4930``` ts 4931import { dataSharePredicates } from '@kit.ArkData'; 4932 4933async function example() { 4934 try { 4935 console.info('mergeAlbum Example') 4936 let predicates: dataSharePredicates.DataSharePredicates = new dataSharePredicates.DataSharePredicates(); 4937 predicates.equalTo('user_display_level', 2); 4938 let fetchOptions: photoAccessHelper.FetchOptions = { 4939 fetchColumns: [], 4940 predicates: predicates 4941 }; 4942 let fetchResult: photoAccessHelper.FetchResult<photoAccessHelper.Album> = await phAccessHelper.getAlbums(photoAccessHelper.AlbumType.SMART, photoAccessHelper.AlbumSubtype.PORTRAIT, fetchOptions); 4943 let album: photoAccessHelper.Album = await fetchResult.getFirstObject(); 4944 if (fetchResult.isAfterLast()) { 4945 console.error('lack of album to merge'); 4946 return; 4947 } 4948 let target: photoAccessHelper.Album = await fetchResult.getNextObject(); 4949 4950 let changeRequest: photoAccessHelper.MediaAlbumChangeRequest = new photoAccessHelper.MediaAlbumChangeRequest(album); 4951 changeRequest.mergeAlbum(target); 4952 changeRequest.setAlbumName("testName"); 4953 await phAccessHelper.applyChanges(changeRequest); 4954 } catch (err) { 4955 console.error(`mergeAlbum failed with error: ${err.code}, ${err.message}`); 4956 } 4957} 4958``` 4959 4960### placeBefore<sup>11+</sup> 4961 4962placeBefore(album: Album): void; 4963 4964将当前相册排序到目标相册之前。 4965 4966**系统接口**:此接口为系统接口。 4967 4968**系统能力**:SystemCapability.FileManagement.PhotoAccessHelper.Core 4969 4970**参数:** 4971 4972| 参数名 | 类型 | 必填 | 说明 | 4973| ---------- | ------- | ---- | ---------------------------------- | 4974| album | [Album](#album) | 是 | 目标相册。如果要将当前相册排序到末位,则目标相册传入null。 | 4975 4976**错误码:** 4977 4978接口抛出错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)和[文件管理错误码](../apis-core-file-kit/errorcode-filemanagement.md)。 4979 4980| 错误码ID | 错误信息 | 4981| -------- | ---------------------------------------- | 4982| 202 | Called by non-system application. | 4983| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types; 3. Parameter verification failed. | 4984| 14000011 | System inner fail. | 4985 4986**示例:** 4987 4988```ts 4989async function example() { 4990 console.info('placeBeforeDemo'); 4991 try { 4992 let albumFetchResult: photoAccessHelper.FetchResult<photoAccessHelper.Album> = await phAccessHelper.getAlbums(photoAccessHelper.AlbumType.USER, photoAccessHelper.AlbumSubtype.USER_GENERIC); 4993 let firstAlbum: photoAccessHelper.Album = await albumFetchResult.getFirstObject(); 4994 if (albumFetchResult.isAfterLast()) { 4995 console.error('lack of album to place before'); 4996 return; 4997 } 4998 let secondAlbum: photoAccessHelper.Album = await albumFetchResult.getNextObject(); 4999 let albumChangeRequest: photoAccessHelper.MediaAlbumChangeRequest = new photoAccessHelper.MediaAlbumChangeRequest(secondAlbum); 5000 albumChangeRequest.placeBefore(firstAlbum); 5001 await phAccessHelper.applyChanges(albumChangeRequest); 5002 console.info('placeBefore successfully'); 5003 } catch (err) { 5004 console.error(`placeBeforeDemo failed with error: ${err.code}, ${err.message}`); 5005 } 5006} 5007``` 5008 5009### dismiss<sup>13+</sup> 5010 5011dismiss(): void 5012 5013删除合影相册。 5014 5015**系统接口**:此接口为系统接口。 5016 5017**系统能力**:SystemCapability.FileManagement.PhotoAccessHelper.Core 5018 5019**错误码:** 5020 5021接口抛出错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)和[文件管理错误码](../apis-core-file-kit/errorcode-filemanagement.md)。 5022 5023| 错误码ID | 错误信息 | 5024| :------- | :-------------------------------- | 5025| 202 | Called by non-system application. | 5026| 401 | Parameter error. Possible causes: Incorrect parameter types. | 5027| 14000011 | System inner fail. | 5028 5029**示例:** 5030 5031```ts 5032import { dataSharePredicates } from '@kit.ArkData'; 5033 5034async function example() { 5035 console.info('dismissDemo'); 5036 try { 5037 let albumFetchResult: photoAccessHelper.FetchResult<photoAccessHelper.Album> = await phAccessHelper.getAlbums(photoAccessHelper.AlbumType.SMART, photoAccessHelper.AlbumSubtype.GROUP_PHOTO); 5038 let album: photoAccessHelper.Album = await albumFetchResult.getFirstObject(); 5039 5040 let albumChangeRequest: photoAccessHelper.MediaAlbumChangeRequest = new photoAccessHelper.MediaAlbumChangeRequest(album); 5041 albumChangeRequest.dismiss(); 5042 await phAccessHelper.applyChanges(albumChangeRequest); 5043 console.info('dismiss successfully'); 5044 } catch (err) { 5045 console.error(`dismissDemo failed with error: ${err.code}, ${err.message}`); 5046 } 5047} 5048``` 5049 5050## HighlightAlbum<sup>12+</sup> 5051 5052时刻相册。 5053 5054**系统接口**:此接口为系统接口。 5055 5056**系统能力**:SystemCapability.FileManagement.PhotoAccessHelper.Core 5057 5058### constructor<sup>12+</sup> 5059 5060constructor(album: Album) 5061 5062构造函数。 5063 5064**系统接口**:此接口为系统接口。 5065 5066**系统能力**:SystemCapability.FileManagement.PhotoAccessHelper.Core 5067 5068**参数:** 5069 5070| 参数名 | 类型 | 必填 | 说明 | 5071| -------- | ------------------------- | ---- | ---------- | 5072| album | [Album](#album) | 是 | 智慧相册。 | 5073 5074**错误码:** 5075 5076接口抛出错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)和[文件管理错误码](../apis-core-file-kit/errorcode-filemanagement.md)。 5077 5078| 错误码ID | 错误信息 | 5079| -------- | ---------------------------------------- | 5080| 202 | Called by non-system application. | 5081| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types; 3. Parameter verification failed. | 5082| 14000011 | Internal system error. | 5083 5084**示例:** 5085 5086```ts 5087import { dataSharePredicates } from '@kit.ArkData'; 5088 5089async function example() { 5090 console.info('HighlightAlbum constructorDemo'); 5091 let predicates: dataSharePredicates.DataSharePredicates = new dataSharePredicates.DataSharePredicates(); 5092 let fetchOption: photoAccessHelper.FetchOptions = { 5093 fetchColumns: [], 5094 predicates: predicates 5095 }; 5096 let albumFetchResult: photoAccessHelper.FetchResult<photoAccessHelper.Album> = await photoAccessHelper.getAlbums( 5097 photoAccessHelper.AlbumType.SMART, photoAccessHelper.AlbumSubtype.HIGHLIGHT, fetchOption); 5098 let album: photoAccessHelper.Album = await albumFetchResult.getFirstObject(); 5099 let highlightAlbum: photoAccessHelper.HighlightAlbum = new photoAccessHelper.HighlightAlbum(album); 5100 albumFetchResult.close(); 5101} 5102``` 5103 5104### getHighlightAlbumInfo<sup>12+</sup> 5105 5106getHighlightAlbumInfo(type: HighlightAlbumInfoType): Promise<string> 5107 5108获取指定时刻相册的特定信息。 5109 5110**系统接口**:此接口为系统接口。 5111 5112**需要权限**:ohos.permission.READ\_IMAGEVIDEO 5113 5114**系统能力**:SystemCapability.FileManagement.PhotoAccessHelper.Core 5115 5116**参数:** 5117 5118| 参数名 | 类型 | 必填 | 说明 | 5119| ---------- | ------- | ---- | ---------------------------------- | 5120| type | [HighlightAlbumInfoType](#highlightalbuminfotype12) | 是 | 需要获取的时刻相册信息类型。 | 5121 5122**错误码:** 5123 5124接口抛出错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)和[文件管理错误码](../apis-core-file-kit/errorcode-filemanagement.md)。 5125 5126| 错误码ID | 错误信息 | 5127| :------- | :-------------------------------- | 5128| 201 | Permission denied. | 5129| 202 | Called by non-system application. | 5130| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types; 3. Parameter verification failed. | 5131| 14000011 | Internal system error. | 5132 5133**示例:** 5134 5135```ts 5136import { dataSharePredicates } from '@kit.ArkData'; 5137 5138async function example() { 5139 try { 5140 console.info('getHighlightAlbumInfoDemo') 5141 let fetchOptions: photoAccessHelper.FetchOptions = { 5142 fetchColumns: [], 5143 predicates: new dataSharePredicates.DataSharePredicates() 5144 } 5145 let albumFetchResult: photoAccessHelper.FetchResult<photoAccessHelper.Album> = await photoAccessHelper.getAlbums( 5146 photoAccessHelper.AlbumType.SMART, photoAccessHelper.AlbumSubtype.HIGHLIGHT, fetchOption); 5147 let album: photoAccessHelper.Album = await albumFetchResult.getFirstObject();、 5148 if (album != undefined) { 5149 let highlightAlbum: photoAccessHelper.HighlightAlbum = new photoAccessHelper.HighlightAlbum(album); 5150 let coverInfo: string = await highlightAlbum.getHighlightAlbumInfo( 5151 photoAccessHelper.HighlightAlbumInfoType.COVER_INFO); 5152 console.info('get cover info result: ' + JSON.stringify(coverInfo)); 5153 } 5154 5155 albumFetchResult.close(); 5156 } catch (err) { 5157 console.error(`getHighlightAlbumInfoDemofailed with error: ${err.code}, ${err.message}`); 5158 } 5159} 5160``` 5161 5162### getHighlightResource<sup>12+</sup> 5163 5164getHighlightResource(resourceUri: string): Promise<ArrayBuffer> 5165 5166获取指定时刻缓存资源的ArrayBuffer。 5167 5168**系统接口**:此接口为系统接口。 5169 5170**需要权限**:ohos.permission.READ\_IMAGEVIDEO 5171 5172**系统能力**:SystemCapability.FileManagement.PhotoAccessHelper.Core 5173 5174**参数:** 5175 5176| 参数名 | 类型 | 必填 | 说明 | 5177| ---------- | ------- | ---- | ---------------------------------- | 5178| resourceUri | string | 是 | 指定时刻缓存资源uri。 | 5179 5180**错误码:** 5181 5182接口抛出错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)和[文件管理错误码](../apis-core-file-kit/errorcode-filemanagement.md)。 5183 5184| 错误码ID | 错误信息 | 5185| :------- | :-------------------------------- | 5186| 201 | Permission denied. | 5187| 202 | Called by non-system application. | 5188| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types; 3. Parameter verification failed. | 5189| 14000011 | Internal system error. | 5190 5191**示例:** 5192 5193```ts 5194import { dataSharePredicates } from '@kit.ArkData'; 5195 5196async function example() { 5197 try { 5198 console.info('getHighlightResourceDemo') 5199 let fetchOptions: photoAccessHelper.FetchOptions = { 5200 fetchColumns: [], 5201 predicates: new dataSharePredicates.DataSharePredicates() 5202 } 5203 let albumFetchResult: photoAccessHelper.FetchResult<photoAccessHelper.Album> = await photoAccessHelper.getAlbums( 5204 photoAccessHelper.AlbumType.SMART, photoAccessHelper.AlbumSubtype.HIGHLIGHT, fetchOption); 5205 let album: photoAccessHelper.Album = await albumFetchResult.getFirstObject();、 5206 if (album != undefined) { 5207 let highlightAlbum: photoAccessHelper.HighlightAlbum = new photoAccessHelper.HighlightAlbum(album); 5208 let uri: string = 'file://media/highlight/cover/10/1_1/background.png?oper=highlight' 5209 let arrayBuffer: ArrayBuffer = await highlightAlbum.getHighlightResource(uri); 5210 } 5211 albumFetchResult.close(); 5212 } catch (err) { 5213 console.error(`getHighlightResourceDemofailed with error: ${err.code}, ${err.message}`); 5214 } 5215} 5216``` 5217 5218### setHighlightUserActionData<sup>12+</sup> 5219 5220setHighlightUserActionData(type: HighlightUserActionType, actionData: number): Promise<void> 5221 5222设置指定时刻用户行为数据。 5223 5224**系统接口**:此接口为系统接口。 5225 5226**需要权限**:ohos.permission.WRITE\_IMAGEVIDEO 5227 5228**系统能力**:SystemCapability.FileManagement.PhotoAccessHelper.Core 5229 5230**参数:** 5231 5232| 参数名 | 类型 | 必填 | 说明 | 5233| ---------- | ------- | ---- | ---------------------------------- | 5234| type | [HighlightUserActionType](#highlightuseractiontype12) | 是 | 需要设置的用户行为数据类型。 | 5235| actionData | number | 是 | 行为数据。 | 5236 5237**错误码:** 5238 5239接口抛出错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)和[文件管理错误码](../apis-core-file-kit/errorcode-filemanagement.md)。 5240 5241| 错误码ID | 错误信息 | 5242| :------- | :-------------------------------- | 5243| 201 | Permission denied. | 5244| 202 | Called by non-system application. | 5245| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types; 3. Parameter verification failed. | 5246| 14000011 | Internal system error. | 5247 5248**示例:** 5249 5250```ts 5251import { dataSharePredicates } from '@kit.ArkData'; 5252 5253async function example() { 5254 try { 5255 console.info('setHighlightUserActionDataDemo') 5256 let fetchOptions: photoAccessHelper.FetchOptions = { 5257 fetchColumns: [], 5258 predicates: new dataSharePredicates.DataSharePredicates() 5259 } 5260 let albumFetchResult: photoAccessHelper.FetchResult<photoAccessHelper.Album> = await photoAccessHelper.getAlbums( 5261 photoAccessHelper.AlbumType.SMART, photoAccessHelper.AlbumSubtype.HIGHLIGHT, fetchOption); 5262 let album: photoAccessHelper.Album = await albumFetchResult.getFirstObject();、 5263 if (album != undefined) { 5264 let highlightAlbum: photoAccessHelper.HighlightAlbum = new photoAccessHelper.HighlightAlbum(album); 5265 highlightAlbum.setHighlightUserActionData(photoAccessHelper.HighlightUserActionType.INSERTED_PIC_COUNT, 1); 5266 } 5267 albumFetchResult.close(); 5268 } catch (err) { 5269 console.error(`setHighlightUserActionDataDemofailed with error: ${err.code}, ${err.message}`); 5270 } 5271} 5272``` 5273 5274## CloudEnhancement<sup>13+</sup> 5275 5276云增强管理类,该类用于生成AI云增强照片任务的管理、获取原照片与AI云增强照片的关联关系。 5277 5278**系统接口**:此接口为系统接口。 5279 5280**系统能力**:SystemCapability.FileManagement.PhotoAccessHelper.Core 5281 5282### getCloudEnhancementInstance<sup>13+</sup> 5283 5284static getCloudEnhancementInstance(context: Context): CloudEnhancement 5285 5286获取云增强类实例。 5287 5288**系统接口**:此接口为系统接口。 5289 5290**系统能力**:SystemCapability.FileManagement.PhotoAccessHelper.Core 5291 5292**参数:** 5293 5294| 参数名 | 类型 | 必填 | 说明 | 5295| -------- | ------------------------- | ---- | ---------- | 5296| context | [Context](../apis-ability-kit/js-apis-inner-application-context.md) | 是 | 传入Ability实例的Context。 | 5297 5298**错误码:** 5299 5300接口抛出错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)和[文件管理错误码](../apis-core-file-kit/errorcode-filemanagement.md)。 5301 5302| 错误码ID | 错误信息 | 5303| -------- | ---------------------------------------- | 5304| 202 | Called by non-system application. | 5305| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types; 3. Parameter verification failed. | 5306| 14000011 | Internal system error. | 5307 5308**示例:** 5309 5310```ts 5311import { dataSharePredicates } from '@kit.ArkData'; 5312 5313async function example() { 5314 console.info('getCloudEnhancementInstanceDemo'); 5315 let photoPredicates: dataSharePredicates.DataSharePredicates = new dataSharePredicates.DataSharePredicates(); 5316 let photoFetchOptions: photoAccessHelper.FetchOptions = { 5317 fetchColumns: [], 5318 predicates: photoPredicates 5319 }; 5320 let phAccessHelper = photoAccessHelper.getPhotoAccessHelper(context); 5321 try { 5322 let fetchResult = await phAccessHelper.getAssets(photoFetchOptions); 5323 let asset = await fetchResult.getLastObject(); 5324 let cloudEnhancementInstance: photoAccessHelper.CloudEnhancement 5325 = photoAccessHelper.CloudEnhancement.getCloudEnhancementInstance(context); 5326 let hasCloudWatermark = true; 5327 await cloudEnhancementInstance.submitCloudEnhancementTasks([asset], hasCloudWatermark); 5328 } catch (err) { 5329 console.error(`getCloudEnhancementInstanceDemo failed with error: ${err.code}, ${err.message}`); 5330 } 5331} 5332``` 5333 5334### submitCloudEnhancementTasks<sup>13+</sup> 5335 5336submitCloudEnhancementTasks(photoAssets: Array<PhotoAsset>, hasCloudWatermark: boolean): Promise<void> 5337 5338提交云增强任务。 5339 5340**系统接口**:此接口为系统接口。 5341 5342**系统能力**:SystemCapability.FileManagement.PhotoAccessHelper.Core 5343 5344**参数:** 5345 5346| 参数名 | 类型 | 必填 | 说明 | 5347| -------- | ------------------------- | ---- | ---------- | 5348| photoAssets | Array<[PhotoAsset](#photoasset)> | 是 | 需要增强照片的[PhotoAsset](#photoasset)集合。 | 5349| hasCloudWatermark | boolean | 是 | 增强后图片是否添加云增强水印。 | 5350 5351**错误码:** 5352 5353接口抛出错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)和[文件管理错误码](../apis-core-file-kit/errorcode-filemanagement.md)。 5354 5355| 错误码ID | 错误信息 | 5356| -------- | ---------------------------------------- | 5357| 201 | Permission denied. | 5358| 202 | Called by non-system application. | 5359| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types; 3. Parameter verification failed. | 5360| 14000011 | Internal system error. | 5361 5362**示例:** 5363 5364```ts 5365import { dataSharePredicates } from '@kit.ArkData'; 5366 5367async function example() { 5368 console.info('submitCloudEnhancementTasksDemo'); 5369 let photoPredicates: dataSharePredicates.DataSharePredicates = new dataSharePredicates.DataSharePredicates(); 5370 let photoFetchOptions: photoAccessHelper.FetchOptions = { 5371 fetchColumns: [], 5372 predicates: photoPredicates 5373 }; 5374 let phAccessHelper = photoAccessHelper.getPhotoAccessHelper(context); 5375 try { 5376 let fetchResult = await phAccessHelper.getAssets(photoFetchOptions); 5377 let asset = await fetchResult.getLastObject(); 5378 let cloudEnhancementInstance: photoAccessHelper.CloudEnhancement 5379 = photoAccessHelper.CloudEnhancement.getCloudEnhancementInstance(context); 5380 let hasCloudWatermark = true; 5381 await cloudEnhancementInstance.submitCloudEnhancementTasks([asset], hasCloudWatermark); 5382 } catch (err) { 5383 console.error(`submitCloudEnhancementTasksDemo failed with error: ${err.code}, ${err.message}`); 5384 } 5385} 5386``` 5387 5388### prioritizeCloudEnhancementTask<sup>13+</sup> 5389 5390prioritizeCloudEnhancementTask(photoAsset: PhotoAsset): Promise<void> 5391 5392提升指定云增强任务的优先级。 5393 5394**系统接口**:此接口为系统接口。 5395 5396**系统能力**:SystemCapability.FileManagement.PhotoAccessHelper.Core 5397 5398**参数:** 5399 5400| 参数名 | 类型 | 必填 | 说明 | 5401| -------- | ------------------------- | ---- | ---------- | 5402| photoAsset | [PhotoAsset](#photoasset) | 是 | 需要修改云增强优先级照片的[PhotoAsset](#photoasset)。 | 5403 5404**错误码:** 5405 5406接口抛出错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)和[文件管理错误码](../apis-core-file-kit/errorcode-filemanagement.md)。 5407 5408| 错误码ID | 错误信息 | 5409| -------- | ---------------------------------------- | 5410| 201 | Permission denied. | 5411| 202 | Called by non-system application. | 5412| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types; 3. Parameter verification failed. | 5413| 14000011 | Internal system error. | 5414 5415**示例:** 5416 5417```ts 5418import { dataSharePredicates } from '@kit.ArkData'; 5419 5420async function example() { 5421 console.info('prioritizeCloudEnhancementTaskDemo'); 5422 let photoPredicates: dataSharePredicates.DataSharePredicates = new dataSharePredicates.DataSharePredicates(); 5423 // 查询进行中的云增强任务。 5424 photoPredicates.equalTo(photoAccessHelper.PhotoKeys.CE_AVAILABLE, 2); 5425 let photoFetchOptions: photoAccessHelper.FetchOptions = { 5426 fetchColumns: [], 5427 predicates: photoPredicates 5428 }; 5429 let phAccessHelper = photoAccessHelper.getPhotoAccessHelper(context); 5430 try { 5431 let fetchResult = await phAccessHelper.getAssets(photoFetchOptions); 5432 let asset = await fetchResult.getLastObject(); 5433 let cloudEnhancementInstance: photoAccessHelper.CloudEnhancement 5434 = photoAccessHelper.CloudEnhancement.getCloudEnhancementInstance(context); 5435 let hasCloudWatermark = true; 5436 await cloudEnhancementInstance.prioritizeCloudEnhancementTask(asset); 5437 } catch (err) { 5438 console.error(`prioritizeCloudEnhancementTaskDemo failed with error: ${err.code}, ${err.message}`); 5439 } 5440} 5441``` 5442 5443### cancelCloudEnhancementTasks<sup>13+</sup> 5444 5445cancelCloudEnhancementTasks(photoAssets: Array<PhotoAsset>): Promise<void> 5446 5447取消指定云增强任务。 5448 5449**系统接口**:此接口为系统接口。 5450 5451**系统能力**:SystemCapability.FileManagement.PhotoAccessHelper.Core 5452 5453**参数:** 5454 5455| 参数名 | 类型 | 必填 | 说明 | 5456| -------- | ------------------------- | ---- | ---------- | 5457| photoAssets | Array<[PhotoAsset](#photoasset)> | 是 | 需要取消云增强任务的[PhotoAsset](#photoasset)集合。 | 5458 5459**错误码:** 5460 5461接口抛出错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)和[文件管理错误码](../apis-core-file-kit/errorcode-filemanagement.md)。 5462 5463| 错误码ID | 错误信息 | 5464| -------- | ---------------------------------------- | 5465| 201 | Permission denied. | 5466| 202 | Called by non-system application. | 5467| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types; 3. Parameter verification failed. | 5468| 14000011 | Internal system error. | 5469 5470**示例:** 5471 5472```ts 5473import { dataSharePredicates } from '@kit.ArkData'; 5474 5475async function example() { 5476 console.info('cancelCloudEnhancementTasksDemo'); 5477 let photoPredicates: dataSharePredicates.DataSharePredicates = new dataSharePredicates.DataSharePredicates(); 5478 // 查询进行中的云增强任务。 5479 photoPredicates.equalTo(photoAccessHelper.PhotoKeys.CE_AVAILABLE, 2); 5480 let photoFetchOptions: photoAccessHelper.FetchOptions = { 5481 fetchColumns: [], 5482 predicates: photoPredicates 5483 }; 5484 let phAccessHelper = photoAccessHelper.getPhotoAccessHelper(context); 5485 try { 5486 let fetchResult = await phAccessHelper.getAssets(photoFetchOptions); 5487 let asset = await fetchResult.getLastObject(); 5488 let cloudEnhancementInstance: photoAccessHelper.CloudEnhancement 5489 = photoAccessHelper.CloudEnhancement.getCloudEnhancementInstance(context); 5490 await cloudEnhancementInstance.cancelCloudEnhancementTasks([asset]); 5491 } catch (err) { 5492 console.error(`cancelCloudEnhancementTasksDemo failed with error: ${err.code}, ${err.message}`); 5493 } 5494} 5495``` 5496 5497### cancelAllCloudEnhancementTasks<sup>13+</sup> 5498 5499cancelAllCloudEnhancementTasks(): Promise<void> 5500 5501取消全部云增强任务。 5502 5503**系统接口**:此接口为系统接口。 5504 5505**系统能力**:SystemCapability.FileManagement.PhotoAccessHelper.Core 5506 5507**错误码:** 5508 5509接口抛出错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)和[文件管理错误码](../apis-core-file-kit/errorcode-filemanagement.md)。 5510 5511| 错误码ID | 错误信息 | 5512| -------- | ---------------------------------------- | 5513| 201 | Permission denied. | 5514| 202 | Called by non-system application. | 5515| 14000011 | Internal system error. | 5516 5517**示例:** 5518 5519```ts 5520import { dataSharePredicates } from '@kit.ArkData'; 5521 5522async function example() { 5523 console.info('cancelAllCloudEnhancementTasksDemo'); 5524 try { 5525 let cloudEnhancementInstance: photoAccessHelper.CloudEnhancement 5526 = photoAccessHelper.CloudEnhancement.getCloudEnhancementInstance(context); 5527 await cloudEnhancementInstance.cancelCloudEnhancementTasks(); 5528 } catch (err) { 5529 console.error(`cancelAllCloudEnhancementTasksDemo failed with error: ${err.code}, ${err.message}`); 5530 } 5531} 5532``` 5533 5534### queryCloudEnhancementTaskState<sup>13+</sup> 5535 5536queryCloudEnhancementTaskState(photoAsset: PhotoAsset): Promise<CloudEnhancementTaskState> 5537 5538查询云增强任务信息。 5539 5540**系统接口**:此接口为系统接口。 5541 5542**系统能力**:SystemCapability.FileManagement.PhotoAccessHelper.Core 5543 5544**参数:** 5545 5546| 参数名 | 类型 | 必填 | 说明 | 5547| -------- | ------------------------- | ---- | ---------- | 5548| photoAsset | [PhotoAsset](#photoasset) | 是 | 需要查询云增强任务信息的[PhotoAsset](#photoasset)。 | 5549 5550**错误码:** 5551 5552接口抛出错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)和[文件管理错误码](../apis-core-file-kit/errorcode-filemanagement.md)。 5553 5554| 错误码ID | 错误信息 | 5555| -------- | ---------------------------------------- | 5556| 201 | Permission denied. | 5557| 202 | Called by non-system application. | 5558| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types; 3. Parameter verification failed. | 5559| 14000011 | Internal system error. | 5560 5561**示例:** 5562 5563```ts 5564import { dataSharePredicates } from '@kit.ArkData'; 5565 5566async function example() { 5567 console.info('queryCloudEnhancementTaskStateDemo'); 5568 let photoPredicates: dataSharePredicates.DataSharePredicates = new dataSharePredicates.DataSharePredicates(); 5569 // 查询进行中的云增强任务。 5570 photoPredicates.equalTo(photoAccessHelper.PhotoKeys.CE_AVAILABLE, 2); 5571 let photoFetchOptions: photoAccessHelper.FetchOptions = { 5572 fetchColumns: [], 5573 predicates: photoPredicates 5574 }; 5575 let phAccessHelper = photoAccessHelper.getPhotoAccessHelper(context); 5576 try { 5577 let fetchResult = await phAccessHelper.getAssets(photoFetchOptions); 5578 let asset = await fetchResult.getLastObject(); 5579 let cloudEnhancementInstance: photoAccessHelper.CloudEnhancement 5580 = photoAccessHelper.CloudEnhancement.getCloudEnhancementInstance(context); 5581 const cloudEnhancementTaskState: photoAccessHelper.CloudEnhancementTaskState 5582 = await cloudEnhancementInstance.queryCloudEnhancementTaskState(asset); 5583 let taskStage = cloudEnhancementTaskState.taskStage; 5584 if (taskStage == photoAccessHelper.CloudEnhancementTaskStage.TASK_STAGE_EXCEPTION) { 5585 console.log("task has exception"); 5586 } else if (taskStage == photoAccessHelper.CloudEnhancementTaskStage.TASK_STAGE_PREPARING) { 5587 console.log("task is preparing"); 5588 } else if (taskStage == photoAccessHelper.CloudEnhancementTaskStage.TASK_STAGE_UPLOADING) { 5589 let transferredFileSize = cloudEnhancementTaskState.transferredFileSize; 5590 let totalFileSize = cloudEnhancementTaskState.totalFileSize; 5591 let message = `task is uploading, transferredFileSize: ${transferredFileSize}, totalFileSize: ${totalFileSize}`; 5592 console.log(message); 5593 } else if (taskStage == photoAccessHelper.CloudEnhancementTaskStage.TASK_STAGE_EXECUTING) { 5594 let expectedDuration = cloudEnhancementTaskState.expectedDuration; 5595 let message = `task is executing, expectedDuration: ${expectedDuration}`; 5596 console.log(message); 5597 } else if (taskStage == photoAccessHelper.CloudEnhancementTaskStage.TASK_STAGE_DOWNLOADING) { 5598 let transferredFileSize = cloudEnhancementTaskState.transferredFileSize; 5599 let totalFileSize = cloudEnhancementTaskState.totalFileSize; 5600 let message = `task is downloading, transferredFileSize: ${transferredFileSize}, totalFileSize: ${totalFileSize}`; 5601 console.log(message); 5602 } else if (taskStage == photoAccessHelper.CloudEnhancementTaskStage.TASK_STAGE_FAILED) { 5603 let errCode = cloudEnhancementTaskState.statusCode; 5604 let message = `task is failed, errCode: ${errCode}`; 5605 console.log(message); 5606 } else if (taskStage == photoAccessHelper.CloudEnhancementTaskStage.TASK_STAGE_COMPLETED) { 5607 console.log("task is completed"); 5608 } 5609 } catch (err) { 5610 console.error(`queryCloudEnhancementTaskStateDemo failed with error: ${err.code}, ${err.message}`); 5611 } 5612} 5613``` 5614 5615### syncCloudEnhancementTaskStatus<sup>13+</sup> 5616 5617syncCloudEnhancementTaskStatus(): Promise<void> 5618 5619同步云增强任务状态。 5620 5621**系统接口**:此接口为系统接口。 5622 5623**系统能力**:SystemCapability.FileManagement.PhotoAccessHelper.Core 5624 5625**错误码:** 5626 5627接口抛出错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)和[文件管理错误码](../apis-core-file-kit/errorcode-filemanagement.md)。 5628 5629| 错误码ID | 错误信息 | 5630| -------- | ---------------------------------------- | 5631| 201 | Permission denied. | 5632| 202 | Called by non-system application. | 5633| 14000011 | Internal system error. | 5634 5635**示例:** 5636 5637```ts 5638import { dataSharePredicates } from '@kit.ArkData'; 5639 5640async function example() { 5641 console.info('syncCloudEnhancementTaskStatusDemo'); 5642 try { 5643 let cloudEnhancementInstance: photoAccessHelper.CloudEnhancement 5644 = photoAccessHelper.CloudEnhancement.getCloudEnhancementInstance(context); 5645 await cloudEnhancementInstance.syncCloudEnhancementTaskStatus(); 5646 } catch (err) { 5647 console.error(`syncCloudEnhancementTaskStatusDemo failed with error: ${err.code}, ${err.message}`); 5648 } 5649} 5650``` 5651 5652### getCloudEnhancementPair<sup>13+</sup> 5653 5654getCloudEnhancementPair(asset: PhotoAsset): Promise<PhotoAsset> 5655 5656查询云增强配对照片。 5657 5658**系统接口**:此接口为系统接口。 5659 5660**系统能力**:SystemCapability.FileManagement.PhotoAccessHelper.Core 5661 5662**参数:** 5663 5664| 参数名 | 类型 | 必填 | 说明 | 5665| -------- | ------------------------- | ---- | ---------- | 5666| photoAsset | [PhotoAsset](#photoasset) | 是 | 需要查询云增强配对照片的[PhotoAsset](#photoasset)。 | 5667 5668**错误码:** 5669 5670接口抛出错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)和[文件管理错误码](../apis-core-file-kit/errorcode-filemanagement.md)。 5671 5672| 错误码ID | 错误信息 | 5673| -------- | ---------------------------------------- | 5674| 201 | Permission denied. | 5675| 202 | Called by non-system application. | 5676| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types; 3. Parameter verification failed. | 5677| 14000011 | Internal system error. | 5678 5679**示例:** 5680 5681```ts 5682import { dataSharePredicates } from '@kit.ArkData'; 5683 5684async function example() { 5685 console.info('getCloudEnhancementPairDemo'); 5686 let photoPredicates: dataSharePredicates.DataSharePredicates = new dataSharePredicates.DataSharePredicates(); 5687 // 查询已完成的云增强任务。 5688 photoPredicates.equalTo(photoAccessHelper.PhotoKeys.CE_AVAILABLE, 5); 5689 let photoFetchOptions: photoAccessHelper.FetchOptions = { 5690 fetchColumns: [], 5691 predicates: photoPredicates 5692 }; 5693 let phAccessHelper = photoAccessHelper.getPhotoAccessHelper(context); 5694 try { 5695 let fetchResult = await phAccessHelper.getAssets(photoFetchOptions); 5696 let asset = await fetchResult.getLastObject(); 5697 let cloudEnhancementInstance: photoAccessHelper.CloudEnhancement 5698 = photoAccessHelper.CloudEnhancement.getCloudEnhancementInstance(context); 5699 let photoAsset: photoAccessHelper.PhotoAsset 5700 = await cloudEnhancementInstance.getCloudEnhancementPair(asset); 5701 } catch (err) { 5702 console.error(`getCloudEnhancementPairDemo failed with error: ${err.code}, ${err.message}`); 5703 } 5704} 5705``` 5706 5707### setVideoEnhancementAttr<sup>13+</sup> 5708 5709setVideoEnhancementAttr(videoEnhancementType: VideoEnhancementType, photoId: string): Promise<void> 5710 5711设置视频的二阶段增强处理类型。 5712 5713**系统接口**:此接口为系统接口。 5714 5715**需要权限**:ohos.permission.WRITE\_IMAGEVIDEO 5716 5717**系统能力**:SystemCapability.FileManagement.PhotoAccessHelper.Core 5718 5719**参数:** 5720 5721| 参数名 | 类型 | 必填 | 说明 | 5722| ---------- | ------- | ---- | ---------------------------------- | 5723| videoEnhancementType | [VideoEnhancementType](#videoenhancementtype13) | 是 | 需要进行分段式视频的处理类型。 | 5724| photoId | string | 是 | 图片的photoId。 | 5725 5726**错误码:** 5727 5728接口抛出错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)和[文件管理错误码](../apis-core-file-kit/errorcode-filemanagement.md)。 5729 5730| 错误码ID | 错误信息 | 5731| :------- | :-------------------------------- | 5732| 202 | Called by non-system application. | 5733| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types; 3. Parameter verification failed. | 5734| 14000011 | Internal system error. | 5735| 14000016 | Operation Not Support. | 5736 5737**示例:** 5738 5739```ts 5740async function example(asset: photoAccessHelper.PhotoAsset) { 5741 try { 5742 let assetChangeRequest: photoAccessHelper.MediaAssetChangeRequest = new photoAccessHelper.MediaAssetChangeRequest(asset); 5743 let photoId = "202410011800"; 5744 assetChangeRequest.setVideoEnhancementAttr(photoAccessHelper.VideoEnhancementType.QUALITY_ENHANCEMENT_LOCAL, photoId); 5745 await phAccessHelper.applyChanges(assetChangeRequest); 5746 } catch (err) { 5747 console.error(`setVideoEnhancementAttr fail with error: ${err.code}, ${err.message}`); 5748 } 5749} 5750``` 5751 5752### getFaceId<sup>13+</sup> 5753 5754getFaceId(): Promise\<string> 5755 5756获取人像相册或合影相册的封面人脸标识。 5757 5758**系统接口**:此接口为系统接口。 5759 5760**需要权限**:ohos.permission.READ\_IMAGEVIDEO 5761 5762**系统能力**:SystemCapability.FileManagement.PhotoAccessHelper.Core 5763 5764**返回值:** 5765 5766| 类型 | 说明 | 5767| :------------------ | :---------------------------------- | 5768| Promise<string> | Promise对象,人像相册返回tag_id,合影相册返回group_tag,未找到返回空字符串。 | 5769 5770**错误码:** 5771 5772接口抛出错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)和[文件管理错误码](../apis-core-file-kit/errorcode-filemanagement.md)。 5773 5774| 错误码ID | 错误信息 | 5775| :------- | :----------------------------------------------------------- | 5776| 201 | Permission denied. | 5777| 202 | Called by non-system application. | 5778| 14000011 | Internal system error | 5779 5780**示例:** 5781 5782```ts 5783import { dataSharePredicates } from '@kit.ArkData'; 5784 5785async function example() { 5786 try { 5787 console.info('getFaceIdDemo'); 5788 let predicates: dataSharePredicates.DataSharePredicates = new dataSharePredicates.DataSharePredicates(); 5789 predicates.equalTo("user_display_level", 1); 5790 let fetchOptions: photoAccessHelper.FetchOptions = { 5791 fetchColumns: [], 5792 predicates: predicates 5793 }; 5794 let fetchResult = 5795 await phAccessHelper.getAlbums(photoAccessHelper.AlbumType.SMART, photoAccessHelper.AlbumSubtype.PORTRAIT, 5796 fetchOptions); 5797 let album = await fetchResult?.getFirstObject(); 5798 let faceId = await album?.getFaceId(); 5799 console.info(`getFaceId successfully, faceId: ${faceId}`); 5800 fetchResult.close(); 5801 } catch (err) { 5802 console.error(`getFaceId failed with err: ${err.code}, ${err.message}`); 5803 } 5804} 5805``` 5806 5807## CloudMediaAssetManager<sup>14+</sup> 5808 5809云端媒体资产管理类,该类用于管理云端资产的下载任务,以及删除云端资产在本地的数据和文件。 5810 5811**系统接口**:此接口为系统接口。 5812 5813**系统能力**:SystemCapability.FileManagement.PhotoAccessHelper.Core 5814 5815### getCloudMediaAssetManagerInstance<sup>14+</sup> 5816 5817static getCloudMediaAssetManagerInstance(context: Context): CloudMediaAssetManager 5818 5819获取云端媒体资产管理类实例。 5820 5821**系统接口**:此接口为系统接口。 5822 5823**系统能力**:SystemCapability.FileManagement.PhotoAccessHelper.Core 5824 5825**参数:** 5826 5827| 参数名 | 类型 | 必填 | 说明 | 5828| -------- | ------------------------- | ---- | ---------- | 5829| context | [Context](../apis-ability-kit/js-apis-inner-application-context.md) | 是 | 传入Ability实例的Context。 | 5830 5831**返回值:** 5832 5833| 类型 | 说明 | 5834| --------------------------------------- | ----------------- | 5835| [CloudMediaAssetManager](#cloudmediaassetmanager14) | 返回云端媒体资产管理类实例。 | 5836 5837**错误码:** 5838 5839接口抛出错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)和[文件管理错误码](../apis-core-file-kit/errorcode-filemanagement.md)。 5840 5841| 错误码ID | 错误信息 | 5842| -------- | ---------------------------------------- | 5843| 202 | Called by non-system application. | 5844| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types; 3. Parameter verification failed. | 5845| 14000011 | Internal system error. It is recommended to retry and check the logs. Possible causes: 1. Database corrupted; 2. The file system is abnormal; 3. The IPC request timed out. | 5846 5847**示例:** 5848 5849```ts 5850import photoAccessHelper from '@ohos.file.photoAccessHelper' 5851const context = getContext(this); 5852async function example() { 5853 console.info('getCloudMediaAssetManagerInstanceDemo'); 5854 try { 5855 let cloudMediaAssetManagerInstance: photoAccessHelper.CloudMediaAssetManager 5856 = photoAccessHelper.CloudMediaAssetManager.getCloudMediaAssetManagerInstance(context); 5857 await cloudMediaAssetManagerInstance.pauseDownloadCloudMedia(); 5858 } catch (err) { 5859 console.error(`getCloudMediaAssetManagerInstanceDemo failed with error: ${err.code}, ${err.message}`); 5860 } 5861} 5862``` 5863 5864### startDownloadCloudMedia<sup>14+</sup> 5865 5866startDownloadCloudMedia(downloadType: CloudMediaDownloadType): Promise<void> 5867 5868开始或恢复云端媒体资产下载任务。 5869 5870**系统接口**:此接口为系统接口。 5871 5872**系统能力**:SystemCapability.FileManagement.PhotoAccessHelper.Core 5873 5874**参数:** 5875 5876| 参数名 | 类型 | 必填 | 说明 | 5877| -------- | ------------------------- | ---- | ---------- | 5878| downloadType | [CloudMediaDownloadType](#cloudmediadownloadtype14) | 是 | 云端媒体资产的下载方式。 | 5879 5880**返回值:** 5881 5882| 类型 | 说明 | 5883| --------------------------------------- | ----------------- | 5884| Promise<void>| Promise对象,返回void。 | 5885 5886**错误码:** 5887 5888接口抛出错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)和[文件管理错误码](../apis-core-file-kit/errorcode-filemanagement.md)。 5889 5890| 错误码ID | 错误信息 | 5891| -------- | ---------------------------------------- | 5892| 201 | Permission denied. | 5893| 202 | Called by non-system application. | 5894| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types; 3. Parameter verification failed. | 5895| 14000011 | Internal system error. It is recommended to retry and check the logs. Possible causes: 1. Database corrupted; 2. The file system is abnormal; 3. The IPC request timed out. | 5896 5897**示例:** 5898 5899```ts 5900import photoAccessHelper from '@ohos.file.photoAccessHelper' 5901const context = getContext(this); 5902async function example() { 5903 console.info('startDownloadCloudMediaDemo'); 5904 try { 5905 let cloudMediaAssetManagerInstance: photoAccessHelper.CloudMediaAssetManager 5906 = photoAccessHelper.CloudMediaAssetManager.getCloudMediaAssetManagerInstance(context); 5907 await cloudMediaAssetManagerInstance.startDownloadCloudMedia(photoAccessHelper.CloudMediaDownloadType.DOWNLOAD_FORCE); 5908 } catch (err) { 5909 console.error(`startDownloadCloudMediaDemo failed with error: ${err.code}, ${err.message}`); 5910 } 5911} 5912``` 5913 5914### pauseDownloadCloudMedia<sup>14+</sup> 5915 5916pauseDownloadCloudMedia(): Promise<void> 5917 5918暂停云端媒体资产下载任务。 5919 5920**系统接口**:此接口为系统接口。 5921 5922**系统能力**:SystemCapability.FileManagement.PhotoAccessHelper.Core 5923 5924**返回值:** 5925 5926| 类型 | 说明 | 5927| --------------------------------------- | ----------------- | 5928| Promise<void>| Promise对象,返回void。 | 5929 5930**错误码:** 5931 5932接口抛出错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)和[文件管理错误码](../apis-core-file-kit/errorcode-filemanagement.md)。 5933 5934| 错误码ID | 错误信息 | 5935| -------- | ---------------------------------------- | 5936| 201 | Permission denied. | 5937| 202 | Called by non-system application. | 5938| 14000011 | Internal system error. It is recommended to retry and check the logs. Possible causes: 1. Database corrupted; 2. The file system is abnormal; 3. The IPC request timed out. | 5939 5940**示例:** 5941 5942```ts 5943import photoAccessHelper from '@ohos.file.photoAccessHelper' 5944const context = getContext(this); 5945async function example() { 5946 console.info('pauseDownloadCloudMediaDemo'); 5947 try { 5948 let cloudMediaAssetManagerInstance: photoAccessHelper.CloudMediaAssetManager 5949 = photoAccessHelper.CloudMediaAssetManager.getCloudMediaAssetManagerInstance(context); 5950 await cloudMediaAssetManagerInstance.pauseDownloadCloudMedia(); 5951 } catch (err) { 5952 console.error(`pauseDownloadCloudMediaDemo failed with error: ${err.code}, ${err.message}`); 5953 } 5954} 5955``` 5956 5957### cancelDownloadCloudMedia<sup>14+</sup> 5958 5959cancelDownloadCloudMedia(): Promise<void> 5960 5961取消云端媒体资产下载任务。 5962 5963**系统接口**:此接口为系统接口。 5964 5965**系统能力**:SystemCapability.FileManagement.PhotoAccessHelper.Core 5966 5967**返回值:** 5968 5969| 类型 | 说明 | 5970| --------------------------------------- | ----------------- | 5971| Promise<void>| Promise对象,返回void。 | 5972 5973**错误码:** 5974 5975接口抛出错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)和[文件管理错误码](../apis-core-file-kit/errorcode-filemanagement.md)。 5976 5977| 错误码ID | 错误信息 | 5978| -------- | ---------------------------------------- | 5979| 201 | Permission denied. | 5980| 202 | Called by non-system application. | 5981| 14000011 | Internal system error. It is recommended to retry and check the logs. Possible causes: 1. Database corrupted; 2. The file system is abnormal; 3. The IPC request timed out. | 5982 5983**示例:** 5984 5985```ts 5986import photoAccessHelper from '@ohos.file.photoAccessHelper' 5987const context = getContext(this); 5988async function example() { 5989 console.info('cancelDownloadCloudMediaDemo'); 5990 try { 5991 let cloudMediaAssetManagerInstance: photoAccessHelper.CloudMediaAssetManager 5992 = photoAccessHelper.CloudMediaAssetManager.getCloudMediaAssetManagerInstance(context); 5993 await cloudMediaAssetManagerInstance.cancelDownloadCloudMedia(); 5994 } catch (err) { 5995 console.error(`cancelDownloadCloudMediaDemo failed with error: ${err.code}, ${err.message}`); 5996 } 5997} 5998``` 5999 6000### retainCloudMediaAsset<sup>14+</sup> 6001 6002retainCloudMediaAsset(retainType: CloudMediaRetainType): Promise<void> 6003 6004删除云端媒体资产在本地的元数据和文件。 6005 6006**系统接口**:此接口为系统接口。 6007 6008**系统能力**:SystemCapability.FileManagement.PhotoAccessHelper.Core 6009 6010**参数:** 6011 6012| 参数名 | 类型 | 必填 | 说明 | 6013| -------- | ------------------------- | ---- | ---------- | 6014| retainType | [CloudMediaRetainType](#cloudmediaretaintype14) | 是 | 云端媒体资产的删除方式。 | 6015 6016**返回值:** 6017 6018| 类型 | 说明 | 6019| --------------------------------------- | ----------------- | 6020| Promise<void>| Promise对象,返回void。 | 6021 6022**错误码:** 6023 6024接口抛出错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)和[文件管理错误码](../apis-core-file-kit/errorcode-filemanagement.md)。 6025 6026| 错误码ID | 错误信息 | 6027| -------- | ---------------------------------------- | 6028| 201 | Permission denied. | 6029| 202 | Called by non-system application. | 6030| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types; 3. Parameter verification failed. | 6031| 14000011 | Internal system error. It is recommended to retry and check the logs. Possible causes: 1. Database corrupted; 2. The file system is abnormal; 3. The IPC request timed out. | 6032 6033**示例:** 6034 6035```ts 6036import photoAccessHelper from '@ohos.file.photoAccessHelper' 6037const context = getContext(this); 6038async function example() { 6039 console.info('retainCloudMediaAssetDemo'); 6040 try { 6041 let cloudMediaAssetManagerInstance: photoAccessHelper.CloudMediaAssetManager 6042 = photoAccessHelper.CloudMediaAssetManager.getCloudMediaAssetManagerInstance(context); 6043 await cloudMediaAssetManagerInstance.retainCloudMediaAsset(photoAccessHelper.CloudMediaRetainType.RETAIN_FORCE); 6044 } catch (err) { 6045 console.error(`retainCloudMediaAssetDemo failed with error: ${err.code}, ${err.message}`); 6046 } 6047} 6048``` 6049 6050### getCloudMediaAssetStatus<sup>14+</sup> 6051 6052getCloudMediaAssetStatus(): Promise<CloudMediaAssetStatus> 6053 6054查询云端媒体资产下载任务状态。 6055 6056**系统接口**:此接口为系统接口。 6057 6058**系统能力**:SystemCapability.FileManagement.PhotoAccessHelper.Core 6059 6060**返回值:** 6061 6062| 类型 | 说明 | 6063| --------------------------------------- | ----------------- | 6064|Promise<[CloudMediaAssetStatus](#cloudmediaassetstatus14)> | Promise对象,返回云端媒体资产下载任务状态。 | 6065 6066**错误码:** 6067 6068接口抛出错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)和[文件管理错误码](../apis-core-file-kit/errorcode-filemanagement.md)。 6069 6070| 错误码ID | 错误信息 | 6071| -------- | ---------------------------------------- | 6072| 201 | Permission denied. | 6073| 202 | Called by non-system application. | 6074| 14000011 | Internal system error. It is recommended to retry and check the logs. Possible causes: 1. Database corrupted; 2. The file system is abnormal; 3. The IPC request timed out. | 6075 6076**示例:** 6077 6078```ts 6079import photoAccessHelper from '@ohos.file.photoAccessHelper' 6080const context = getContext(this); 6081async function example() { 6082 console.info('getCloudMediaAssetStatusDemo'); 6083 try { 6084 let cloudMediaAssetManagerInstance: photoAccessHelper.CloudMediaAssetManager 6085 = photoAccessHelper.CloudMediaAssetManager.getCloudMediaAssetManagerInstance(context); 6086 const cloudMediaAssetStatus: photoAccessHelper.CloudMediaAssetStatus = await cloudMediaAssetManagerInstance.getCloudMediaAssetStatus(); 6087 let taskStatus = cloudMediaAssetStatus.taskStatus; 6088 let taskInfo = cloudMediaAssetStatus.taskInfo; 6089 let errorCode = cloudMediaAssetStatus.errorCode; 6090 let message = `taskStatus: ${taskStatus}, taskInfo: ${taskInfo}, errorCode: ${errorCode}`; 6091 console.log(message); 6092 } catch (err) { 6093 console.error(`getCloudMediaAssetStatusDemo failed with error: ${err.code}, ${err.message}`); 6094 } 6095} 6096``` 6097 6098## PhotoSubtype 6099 6100枚举,不同[PhotoAsset](#photoasset)的类型。 6101 6102**系统能力**:SystemCapability.FileManagement.PhotoAccessHelper.Core 6103 6104| 名称 | 值 | 说明 | 6105| ----- | ---- | ---- | 6106| SCREENSHOT | 1 | 截屏录屏文件类型。<br>**系统接口**:此接口为系统接口。 | 6107 6108## AlbumType 6109 6110枚举,相册类型,表示是用户相册还是系统预置相册。 6111 6112**系统能力**:SystemCapability.FileManagement.PhotoAccessHelper.Core 6113 6114| 名称 | 值 | 说明 | 6115| ------------------- | ---- | ------------------------- | 6116| SMART<sup>11+</sup> | 4096 | 智慧分析相册。<br>**系统接口**:此接口为系统接口。 | 6117 6118## AlbumSubtype 6119 6120枚举,相册子类型,表示具体的相册类型。 6121 6122**系统能力**:SystemCapability.FileManagement.PhotoAccessHelper.Core 6123 6124| 名称 | 值 | 说明 | 6125| --------------------------------- | ---------- | ------------------------------- | 6126| HIDDEN | 1027 | 隐藏相册。**系统接口**:此接口为系统接口。 | 6127| TRASH | 1028 | 回收站。**系统接口**:此接口为系统接口。 | 6128| SCREENSHOT | 1029 | 截屏和录屏相册。**系统接口**:此接口为系统接口。 | 6129| CAMERA | 1030 | 相机拍摄的照片和视频相册。**系统接口**:此接口为系统接口。 | 6130| SOURCE\_GENERIC<sup>11+</sup> | 2049 | 来源相册。**系统接口**:此接口为系统接口。 | 6131| CLASSIFY<sup>11+</sup> | 4097 | 分类相册。**系统接口**:此接口为系统接口。 | 6132| GEOGRAPHY\_LOCATION<sup>11+</sup> | 4099 | 地图相册。**系统接口**:此接口为系统接口。 | 6133| GEOGRAPHY\_CITY<sup>11+</sup> | 4100 | 城市相册。**系统接口**:此接口为系统接口。 | 6134| SHOOTING\_MODE<sup>11+</sup> | 4101 | 拍摄模式相册。**系统接口**:此接口为系统接口。 | 6135| PORTRAIT<sup>11+</sup> | 4102 | 人像相册。**系统接口**:此接口为系统接口。 | 6136| GROUP_PHOTO<sup>13+</sup> | 4103 | 合影相册。**系统接口**:此接口为系统接口。 | 6137| HIGHLIGHT<sup>12+</sup> | 4104 | 时刻相册。**系统接口**:此接口为系统接口。 | 6138| HIGHLIGHT_SUGGESTIONS<sup>12+</sup> | 4105 | 时刻建议相册。**系统接口**:此接口为系统接口。 | 6139| CLOUD_ENHANCEMENT<sup>13+</sup> | 1032 | AI云增强相册。**系统接口**:此接口为系统接口。 | 6140 6141## RequestPhotoType<sup>11+</sup> 6142 6143枚举,获取图片或视频缩略图的操作类型。 6144 6145**系统接口**:此接口为系统接口。 6146 6147**系统能力**:SystemCapability.FileManagement.PhotoAccessHelper.Core 6148 6149| 名称 | 值 | 说明 | 6150| ----- | ---- | ---- | 6151| REQUEST_ALL_THUMBNAILS | 0 | 即获取快速缩略图,又获取质量缩略图。 | 6152| REQUEST_FAST_THUMBNAIL | 1 | 只获取快速缩略图。 | 6153| REQUEST_QUALITY_THUMBNAIL | 2 | 只获取质量缩略图。 | 6154 6155## PhotoKeys 6156 6157枚举,图片和视频文件关键信息。 6158 6159**系统能力**:SystemCapability.FileManagement.PhotoAccessHelper.Core 6160 6161| 名称 | 值 | 说明 | 6162| ------------- | ------------------- | ---------------------------------------------------------- | 6163| DATE_TRASHED | 'date_trashed' | 删除日期(删除文件时间距1970年1月1日的秒数值)。**系统接口**:此接口为系统接口。 | 6164| HIDDEN | 'hidden' | 文件的隐藏状态。**系统接口**:此接口为系统接口。 | 6165| CAMERA_SHOT_KEY | 'camera_shot_key' | 锁屏相机拍照或录像的标记字段(仅开放给系统相机,其key值由系统相机定义)。**系统接口**:此接口为系统接口。 | 6166| USER_COMMENT<sup>10+</sup> | 'user_comment' | 用户注释信息。**系统接口**:此接口为系统接口。 | 6167| DATE_YEAR<sup>11+</sup> | 'date_year' | 创建文件的年份。**系统接口**:此接口为系统接口。 | 6168| DATE_MONTH<sup>11+</sup> | 'date_month' | 创建文件的月份。**系统接口**:此接口为系统接口。 | 6169| DATE_DAY<sup>11+</sup> | 'date_day' | 创建文件的日期。**系统接口**:此接口为系统接口。 | 6170| PENDING<sup>11+</sup> | 'pending' | pending状态。**系统接口**:此接口为系统接口。 | 6171| DATE_TRASHED_MS<sup>12+</sup> | 'date_trashed_ms' | 删除日期(删除文件时间距1970年1月1日的毫秒数值)。**系统接口**:此接口为系统接口。<br>注意:查询照片时,不支持基于该字段排序。 | 6172| MOVING_PHOTO_EFFECT_MODE<sup>12+</sup> | 'moving_photo_effect_mode' | 动态照片效果模式。**系统接口**:此接口为系统接口。 | 6173| CE_AVAILABLE<sup>13+</sup> | 'ce_available' | 云增强任务标识。**系统接口**:此接口为系统接口。 | 6174| SUPPORTED_WATERMARK_TYPE<sup>14+</sup> | 'supported_watermark_type' | 水印可编辑标识。**系统接口**:此接口为系统接口。 | 6175 6176## HiddenPhotosDisplayMode<sup>11+</sup> 6177 6178枚举,系统中隐藏文件显示模式。 6179 6180**系统接口**:此接口为系统接口。 6181 6182**系统能力**:SystemCapability.FileManagement.PhotoAccessHelper.Core 6183 6184| 名称 | 值 | 说明 | 6185| ------------- | ------------------- | ---------------------------------------------------------- | 6186| ASSETS_MODE | 0 | 按系统预置的隐藏相册显示隐藏文件,即显示系统中所有的隐藏文件。 | 6187| ALBUMS_MODE | 1 | 按相册显示隐藏文件(即显示系统中所有包含隐藏文件的相册,除系统预置的隐藏相册本身和回收站相册以外)。 | 6188 6189## PhotoCreateOptions 6190 6191图片或视频的创建选项。 6192 6193**系统接口**:此接口为系统接口。 6194 6195**系统能力**:SystemCapability.FileManagement.PhotoAccessHelper.Core 6196 6197| 名称 | 类型 | 必填 | 说明 | 6198| ---------------------- | ------------------- | ---- | ------------------------------------------------ | 6199| subtype | [PhotoSubtype](#photosubtype) | 否 | 图片或者视频的子类型。 | 6200| cameraShotKey | string | 否 | 锁屏相机拍照或录像的标记字段(仅开放给系统相机,其key值由系统相机定义)。 | 6201 6202## RequestPhotoOptions<sup>11+</sup> 6203 6204获取图片或视频缩略图的选项。 6205 6206**系统接口**:此接口为系统接口。 6207 6208**系统能力**:SystemCapability.FileManagement.PhotoAccessHelper.Core 6209 6210| 名称 | 类型 | 必填 | 说明 | 6211| ---------------------- | ------------------- | ---- | ------------------------------------------------ | 6212| size | [image.Size](../apis-image-kit/js-apis-image.md#size) | 否 | 获取缩略图的尺寸。 | 6213| requestPhotoType | [RequestPhotoType](#requestphototype11) | 否 | 获取的操作类型。 | 6214 6215## RequestOptions<sup>11+</sup> 6216 6217请求策略。 6218 6219**系统能力**:SystemCapability.FileManagement.PhotoAccessHelper.Core 6220 6221| 名称 | 类型 | 可读 | 可写 | 说明 | 6222| ---------------------- |---------------------------------| ---- |---- | ------------------------------------------------ | 6223| sourceMode | [SourceMode](#sourcemode11) | 是 | 是 | 资源文件的读取类型,可以指定当前请求获取的是源文件,或是编辑后的文件。**系统接口**:此接口为系统接口。 | 6224 6225## PhotoProxy<sup>11+</sup> 6226 6227照片代理,相机应用通过该对象写入图片数据。 6228 6229**系统接口**:此接口为系统接口。 6230 6231**系统能力**:SystemCapability.FileManagement.PhotoAccessHelper.Core 6232 6233## MediaChangeRequest<sup>11+</sup> 6234 6235媒体变更请求,资产变更请求和相册变更请求的父类型。 6236 6237**注意**:媒体变更请求需要在调用[applyChanges](js-apis-photoAccessHelper.md#applychanges11)后才会提交生效。 6238 6239**系统能力**:SystemCapability.FileManagement.PhotoAccessHelper.Core 6240 6241## FormInfo<sup>11+</sup> 6242 6243图库卡片相关信息。 6244 6245**系统接口**:此接口为系统接口。 6246 6247**系统能力**:SystemCapability.FileManagement.PhotoAccessHelper.Core 6248 6249| 名称 | 类型 | 必填 | 说明 | 6250| ---------------------- | ------------------- | ---- | ------------------------------------------------ | 6251|formId |string |是 | 卡片的ID,由图库创建卡片时提供。 | 6252|uri |string |是 | 卡片绑定的图片的uri。创建卡片时uri可为空或图片的uri,移除卡片时uri不做校验,传空即可。 | 6253 6254## ResourceType<sup>11+</sup> 6255 6256枚举,写入资源的类型。 6257 6258**系统能力**:SystemCapability.FileManagement.PhotoAccessHelper.Core 6259 6260| 名称 | 值 | 说明 | 6261| ----- | ---- | ---- | 6262| PHOTO_PROXY | 3 | 表示照片代理资源。**系统接口**:此接口为系统接口。 | 6263| PRIVATE_MOVING_PHOTO_RESOURCE<sup>13+</sup> | 4 | 表示私有动态照片资源。**系统接口**:此接口为系统接口。 | 6264 6265## DefaultChangeUri 6266 6267枚举,DefaultChangeUri子类型。 6268 6269**系统能力**:SystemCapability.FileManagement.PhotoAccessHelper.Core 6270 6271| 名称 | 值 | 说明 | 6272| ----------------- | ----------------------- | ------------------------------------------------------------ | 6273| DEFAULT_HIDDEN_ALBUM_URI<sup>11+</sup> | 'file://media/HiddenAlbum' | 隐藏相册-相册视图中相册的Uri,即系统中包含隐藏文件的相册(不包含系统预置隐藏相册和回收站相册)的Uri,仅用于隐藏相册-相册视图场景的通知。**系统接口**:此接口为系统接口。 | 6274 6275## SourceMode<sup>11+</sup> 6276 6277枚举,资源文件的读取类型。 6278 6279**系统接口**:此接口为系统接口。 6280 6281**系统能力**:SystemCapability.FileManagement.PhotoAccessHelper.Core 6282 6283| 名称 | 值 | 说明 | 6284| ----- | ---- | ---- | 6285| ORIGINAL_MODE | 0 | 读取源文件。 | 6286| EDITED_MODE | 1 | 读取编辑后的文件。| 6287## AuthorizationMode<sup>12+</sup> 6288 6289枚举,授权模式。 6290 6291**系统接口**:此接口为系统接口。 6292 6293**系统能力**:SystemCapability.FileManagement.PhotoAccessHelper.Core 6294 6295| 名称 | 值 | 说明 | 6296| ----- | ---- | ---- | 6297| SHORT_TIME_AUTHORIZATION| 0 | 短时授权。 | 6298 6299## AnalysisType<sup>11+</sup> 6300 6301枚举,智慧分析类型。 6302 6303**系统能力**:SystemCapability.FileManagement.PhotoAccessHelper.Core 6304 6305| 名称 | 值 | 说明 | 6306| :---------------------------- | :- | :------- | 6307| ANALYSIS\_AESTHETICS\_SCORE | 0 | 美学评分分析类别。**系统接口**:此接口为系统接口。 | 6308| ANALYSIS\_LABEL | 1 | 分类标签分析类别。**系统接口**:此接口为系统接口。 | 6309| ANALYSIS\_OCR | 2 | 文字识别分析类别。**系统接口**:此接口为系统接口。 | 6310| ANALYSIS\_FACE | 3 | 人脸检测分析类别。**系统接口**:此接口为系统接口。 | 6311| ANALYSIS\_OBJECT | 4 | 目标检测分析类别。**系统接口**:此接口为系统接口。 | 6312| ANALYSIS\_RECOMMENDATION | 5 | 推荐构图分析类别。**系统接口**:此接口为系统接口。 | 6313| ANALYSIS\_SEGMENTATION | 6 | 抠图分析类别。**系统接口**:此接口为系统接口。 | 6314| ANALYSIS\_COMPOSITION | 7 | 美学构图分析类别。**系统接口**:此接口为系统接口。 | 6315| ANALYSIS\_SALIENCY | 8 | 最佳呈现主体中心分析类别。**系统接口**:此接口为系统接口。 | 6316| ANALYSIS\_DETAIL\_ADDRESS | 9 | 详细地址分析类别。**系统接口**:此接口为系统接口。 | 6317| ANALYSIS\_HUMAN\_FACE\_TAG<sup>12+</sup> | 10 | 人像聚类信息分析类别。**系统接口**:此接口为系统接口。 | 6318| ANALYSIS\_HEAD\_POSITION<sup>12+</sup> | 11 | 人头、宠物头位置分析类别。**系统接口**:此接口为系统接口。 | 6319| ANALYSIS\_BONE\_POSE<sup>12+</sup> | 12 | 人体骨骼点信息分析类别。**系统接口**:此接口为系统接口。 | 6320| ANALYSIS\_VIDEO\_LABEL<sup>12+</sup> | 13 | 视频标签。**系统接口**:此接口为系统接口。 | 6321 6322## HighlightAlbumInfoType<sup>12+</sup> 6323 6324枚举,时刻相册信息类型。 6325 6326**系统接口**:此接口为系统接口。 6327 6328**系统能力**:SystemCapability.FileManagement.PhotoAccessHelper.Core 6329 6330| 名称 | 值 | 说明 | 6331| :------------ | :- | :------- | 6332| COVER\_INFO | 0 | 封面信息类别。 | 6333| PLAY\_INFO | 1 | 音乐信息类别。 | 6334 6335## HighlightUserActionType<sup>12+</sup> 6336 6337枚举,时刻用户行为类型。 6338 6339**系统接口**:此接口为系统接口。 6340 6341**系统能力**:SystemCapability.FileManagement.PhotoAccessHelper.Core 6342 6343| 名称 | 值 | 说明 | 6344| :---------------------------- | :- | :------- | 6345| INSERTED\_PIC\_COUNT | 0 | 新增图片数量类别。 | 6346| REMOVED\_PIC\_COUNT | 1 | 移除图片数量类别。 | 6347| SHARED\_SCREENSHOT\_COUNT | 2 | 分享二级界面长图次数类别。 | 6348| SHARED\_COVER\_COUNT | 3 | 分享时刻封面次数类别。 | 6349| RENAMED\_COUNT | 4 | 重命名次数类别。 | 6350| CHANGED\_COVER\_COUNT | 5 | 修改封面次数类别。 | 6351| RENDER\_VIEWED\_TIMES | 100 | 轮播观看次数类别。 | 6352| RENDER\_VIEWED\_DURATION | 101 | 轮播观看总时长类别。 | 6353| ART\_LAYOUT\_VIEWED\_TIMES | 102 | 二级界面观看次数类别。 | 6354| ART\_LAYOUT\_VIEWED\_DURATION | 103 | 二级界面观看总时长类别。 | 6355 6356## MovingPhotoEffectMode<sup>12+</sup> 6357 6358枚举,动态照片效果模式。 6359 6360**系统接口**:此接口为系统接口。 6361 6362**系统能力**:SystemCapability.FileManagement.PhotoAccessHelper.Core 6363 6364| 名称 | 值 | 说明 | 6365| :---------------------------- | :- | :------- | 6366| DEFAULT | 0 | 默认模式。| 6367| BOUNCE\_PLAY | 1 | 来回播放。| 6368| LOOP\_PLAY | 2 | 循环播放。| 6369| LONG\_EXPOSURE | 3 | 长曝光。 | 6370| MULTI\_EXPOSURE | 4 | 多曝光。 | 6371| CINEMA\_GRAPH<sup>13+</sup> | 5 | 微动瞬间。 | 6372| IMAGE\_ONLY<sup>13+</sup> | 10 | 关闭模式。 | 6373 6374## PhotoPermissionType<sup>12+</sup> 6375 6376枚举,应用对媒体资源不同访问权限的类型。 6377 6378包括临时读权限和永久读权限,临时读权限会随着应用的死亡而删除,永久读权限不会。 6379 6380同一个应用对同一个媒体资源的权限覆盖规则:永久读会覆盖临时读,而临时读不会覆盖永久读。 6381 6382**系统接口**:此接口为系统接口。 6383 6384**系统能力**:SystemCapability.FileManagement.PhotoAccessHelper.Core 6385 6386| 名称 | 值 | 说明 | 6387| ----- | ---- | ---- | 6388| TEMPORARY_READ_IMAGEVIDEO | 0 | 临时读权限类型。 | 6389| PERSISTENT_READ_IMAGEVIDEO | 1 | 永久读权限类型。 | 6390 6391## HideSensitiveType<sup>12+</sup> 6392 6393枚举,应用访问媒体资源时,对媒体资源进行信息脱敏的类型。 6394 6395**系统接口**:此接口为系统接口。 6396 6397**系统能力**:SystemCapability.FileManagement.PhotoAccessHelper.Core 6398 6399| 名称 | 值 | 说明 | 6400| ----- | ---- | ---- | 6401| HIDE_LOCATION_AND_SHOOTING_PARAM | 0 | 脱敏地理位置和拍摄参数。 | 6402| HIDE_LOCATION_ONLY | 1 | 脱敏地理位置信息。 | 6403| HIDE_SHOOTING_PARAM_ONLY | 2 | 脱敏拍摄参数。 | 6404| NO_HIDE_SENSITIVE_TYPE | 3 | 不脱敏。 | 6405 6406## CloudEnhancementTaskStage<sup>13+</sup> 6407 6408枚举,应用查询云增强任务状态时,在[CloudEnhancementTaskState](#cloudenhancement13)接口中返回,表示云增强任务状态。 6409 6410**系统接口**:此接口为系统接口。 6411 6412**系统能力**:SystemCapability.FileManagement.PhotoAccessHelper.Core 6413 6414| 名称 | 值 | 说明 | 6415| ----- | ---- | ---- | 6416| TASK_STAGE_EXCEPTION | -1 | 云增强任务异常。 | 6417| TASK_STAGE_PREPARING | 0 | 云增强任务准备中。 | 6418| TASK_STAGE_UPLOADING | 1 | 云增强任务上传中。 | 6419| TASK_STAGE_EXECUTING | 2 | 云增强任务执行中。 | 6420| TASK_STAGE_DOWNLOADING | 3 | 云增强任务下载中。 | 6421| TASK_STAGE_FAILED | 4 | 云增强任务失败。 | 6422| TASK_STAGE_COMPLETED | 5 | 云增强任务已完成。 | 6423 6424## CloudEnhancementState<sup>13+</sup> 6425 6426枚举,表示云增强状态。 6427 6428**系统接口**:此接口为系统接口。 6429 6430**系统能力**:SystemCapability.FileManagement.PhotoAccessHelper.Core 6431 6432| 名称 | 值 | 说明 | 6433| ----- | ---- | ---- | 6434| UNAVAILABLE | 0 | 云增强不可用。 | 6435| AVAILABLE | 1 | 云增强可用。 | 6436| EXECUTING | 2 | 云增强执行中。 | 6437| COMPLETED | 3 | 云增强已完成。 | 6438 6439## CloudEnhancementTaskState<sup>13+</sup> 6440 6441云增强任务状态,应用调用调用云增强任务查询接口的返回类型,包含云增强任务状态及部分状态下的额外信息。 6442 6443**系统接口**:此接口为系统接口。 6444 6445**系统能力**:SystemCapability.FileManagement.PhotoAccessHelper.Core 6446 6447| 名称 | 类型 | 必定提供 | 说明 | 6448| ---------------------- | ------------------- | ---- | ------------------------------------------------ | 6449|taskStage |[CloudEnhancementTaskStage](#cloudenhancementtaskstage13) |是 | 云增强任务状态。 | 6450|transferredFileSize |number |否 | 已传输的文件大小。当taskStage为CloudEnhancementTaskStage.TASK_STAGE_UPLOADING或者CloudEnhancementTaskStage.TASK_STAGE_DOWNLOADING时提供。 | 6451|totalFileSize |number |否 | 总文件大小。当taskStage为CloudEnhancementTaskStage.TASK_STAGE_UPLOADING或者CloudEnhancementTaskStage.TASK_STAGE_DOWNLOADING时提供。 | 6452|expectedDuration |number |否 | 排队时间。当taskStage为CloudEnhancementTaskStage.TASK_STAGE_EXECUTING时提供。 | 6453|statusCode |number |否 | 状态码。当taskStage为CloudEnhancementTaskStage.TASK_STAGE_FAILED时提供。 | 6454 6455## VideoEnhancementType<sup>13+</sup> 6456 6457枚举,分段式视频的二段式触发类型。 6458 6459**系统接口**:此接口为系统接口。 6460 6461**系统能力**:SystemCapability.FileManagement.PhotoAccessHelper.Core 6462 6463| 名称 | 值 | 说明 | 6464| ----- | ---- | ---- | 6465| QUALITY_ENHANCEMENT_LOCAL | 0 | 在端侧增强处理。 | 6466| QUALITY_ENHANCEMENT_CLOUD | 1 | 在云侧增强处理。 | 6467| QUALITY_ENHANCEMENT_LOCAL_AND_CLOUD | 2 | 在端侧和云侧同时增强处理。 | 6468 6469## ThumbnailType<sup>13+</sup> 6470 6471枚举,缩略图类型。 6472 6473**系统接口**:此接口为系统接口。 6474 6475**系统能力**:SystemCapability.FileManagement.PhotoAccessHelper.Core 6476 6477| 名称 | 值 | 说明 | 6478| :---------------------------- | :- | :------- | 6479| LCD | 1 | 获取LCD缩略图。 | 6480| THM | 2 | 获取THM缩略图。 | 6481 6482## WatermarkType<sup>14+</sup> 6483 6484枚举,水印可编辑标识。 6485 6486**系统接口**:此接口为系统接口。 6487 6488**系统能力**:SystemCapability.FileManagement.PhotoAccessHelper.Core 6489 6490| 名称 | 值 | 说明 | 6491| ----- | ---- | ---- | 6492| DEFAULT | 0 | 不支持水印可编辑。 | 6493| BRAND_COMMON | 1 | 支持品牌和通用水印可编辑。 | 6494| COMMON | 2 | 支持通用水印可编辑。 | 6495| BRAND | 3 | 支持品牌水印可编辑。 | 6496 6497## CloudMediaDownloadType<sup>14+</sup> 6498 6499枚举,表示云端媒体资产的下载方式。 6500 6501**系统接口**:此接口为系统接口。 6502 6503**系统能力**:SystemCapability.FileManagement.PhotoAccessHelper.Core 6504 6505| 名称 | 值 | 说明 | 6506| ----- | ---- | ---- | 6507| DOWNLOAD_FORCE | 0 | 高优先级下载,无需进入息屏充电模式。 | 6508| DOWNLOAD_GENTLE | 1 | 低优先级下载,需要进入息屏充电模式。 | 6509 6510## CloudMediaRetainType<sup>14+</sup> 6511 6512枚举,表示云端媒体资产的删除方式。 6513 6514**系统接口**:此接口为系统接口。 6515 6516**系统能力**:SystemCapability.FileManagement.PhotoAccessHelper.Core 6517 6518| 名称 | 值 | 说明 | 6519| ----- | ---- | ---- | 6520| RETAIN_FORCE | 0 | 删除原文件在云端的本地元数据和缩略图。 | 6521 6522## CloudMediaAssetTaskStatus<sup>14+</sup> 6523 6524枚举,表示云端媒体资产的下载任务状态。 6525 6526**系统接口**:此接口为系统接口。 6527 6528**系统能力**:SystemCapability.FileManagement.PhotoAccessHelper.Core 6529 6530| 名称 | 值 | 说明 | 6531| ----- | ---- | ---- | 6532| DOWNLOADING | 0 | 当前任务下载中。 | 6533| PAUSED | 1 | 当前任务已暂停。 | 6534| IDLE | 2 | 当前无下载任务。 | 6535 6536## CloudMediaTaskPauseCause<sup>14+</sup> 6537 6538枚举,表示云端媒体资产下载任务暂停的类型。 6539 6540**系统接口**:此接口为系统接口。 6541 6542**系统能力**:SystemCapability.FileManagement.PhotoAccessHelper.Core 6543 6544| 名称 | 值 | 说明 | 6545| ----- | ---- | ---- | 6546| NO_PAUSE | 0 | 正常下载,无暂停。 | 6547| TEMPERATURE_LIMIT | 1 | 温度过高。 | 6548| ROM_LIMIT | 2 | 本地磁盘空间不足。 | 6549| NETWORK_FLOW_LIMIT | 3 | 流量使用有限制,且没有Wi-Fi。 | 6550| WIFI_UNAVAILABLE | 4 | 网络异常。 | 6551| POWER_LIMIT | 5 | 功耗限制。 | 6552| BACKGROUND_TASK_UNAVAILABLE | 6 | 充电息屏未启动。 | 6553| FREQUENT_USER_REQUESTS | 7 | 用户请求频繁。 | 6554| CLOUD_ERROR | 8 | 端云错误。 | 6555| USER_PAUSED | 9 | 用户暂停。 | 6556 6557## CloudMediaAssetStatus<sup>14+</sup> 6558 6559云端媒体资产下载任务的详细信息,应用调用云端资产下载任务查询接口的返回类型。 6560 6561**系统接口**:此接口为系统接口。 6562 6563**系统能力**:SystemCapability.FileManagement.PhotoAccessHelper.Core 6564 6565| 名称 | 类型 | 必定提供 | 说明 | 6566| ---------------------- | ------------------- | ---- | ------------------------------------------------ | 6567|taskStatus |[CloudMediaAssetTaskStatus](#cloudmediaassettaskstatus14) |是 | 云端媒体资产下载任务状态。 | 6568|taskInfo |string |是 | 下载资产的的总个数和总大小(byte),以及未下载的总个数和总大小(byte)。 | 6569|errorCode |[CloudMediaTaskPauseCause](#cloudmediataskpausecause14) |是 | 云端媒体资产下载任务暂停类型。 |