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