# @ohos.file.photoAccessHelper (相册管理模块)(系统接口) 该模块提供相册管理模块能力,包括创建相册以及访问、修改相册中的媒体数据信息等。 > **说明:** > > - 本模块首批接口从API version 10开始支持。后续版本的新增接口,采用上角标单独标记接口的起始版本。 > - 当前页面仅包含本模块的系统接口,其他公开接口参见[@ohos.file.photoAccessHelper (相册管理模块)](arkts-apis-photoAccessHelper.md)。 ## 导入模块 ```ts import { photoAccessHelper } from '@kit.MediaLibraryKit'; ``` ## photoAccessHelper.getPhotoAccessHelper19+ getPhotoAccessHelper(context: Context, userId: number): PhotoAccessHelper 支持跨用户获取相册管理模块的实例,用于访问和修改相册中的媒体文件。 ​**模型约束**:此接口仅可在Stage模型下使用。 **系统接口**:此接口为系统接口。 **系统能力**:SystemCapability.FileManagement.PhotoAccessHelper.Core **参数:** | 参数名 | 类型 | 必填 | 说明 | | ------- | ------- | ---- | -------------------------- | | context | [Context](../apis-ability-kit/js-apis-inner-application-context.md) | 是 | 传入Ability实例的上下文。 | | userId | number | 是 | 传入待访问用户的id。 | **返回值:** | 类型 | 说明 | | ----------------------------- | :---- | | [PhotoAccessHelper](#photoaccesshelper) | 相册管理模块的实例。 | **错误码:** 接口抛出错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)。 | 错误码ID | 错误信息 | | -------- | ---------------------------------------- | | 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types; 3. Parameter verification failed. | **示例:** ```ts // 此处获取的phAccessHelper实例为全局对象,后续使用到phAccessHelper的地方默认为使用此处获取的对象,如未添加此段代码报phAccessHelper未定义的错误请自行添加。 // 请在组件内获取context,确保this.getUiContext().getHostContext()返回结果为UIAbilityContext import { common } from '@kit.AbilityKit'; @Entry @Component struct Index { build() { Row() { Button("example").onClick(async () => { let context: Context = this.getUIContext().getHostContext() as common.UIAbilityContext; // 此处101表示其他用户空间的userid let phAccessHelper = photoAccessHelper.getPhotoAccessHelper(context, 101); }).width('100%') } .height('90%') } } ``` ​ ## PhotoAccessHelper ### createAsset createAsset(displayName: string, callback: AsyncCallback<PhotoAsset>): void 指定待创建的图片或者视频的文件名,创建图片或视频资源,使用callback方式返回结果。 待创建的文件名参数规格为: - 应包含有效文件主名和图片或视频扩展名。 - 文件名字符串长度为1~255。 - 文件主名中不允许出现的非法英文字符。
API18开始,非法字符包括: \ / : * ? " < > |
API10-17,非法字符包括:. .. \ / : * ? " ' ` < > | { } [ ] **系统接口**:此接口为系统接口。 **系统能力**:SystemCapability.FileManagement.PhotoAccessHelper.Core **需要权限**:ohos.permission.WRITE_IMAGEVIDEO **参数:** | 参数名 | 类型 | 必填 | 说明 | | -------- | ------------------------ | ---- | ------------------------- | | displayName | string | 是 | 创建的图片或者视频文件名。 | | callback | AsyncCallback<[PhotoAsset](#photoasset)> | 是 | callback返回创建的图片和视频结果。 | **错误码:** 接口抛出错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)和[文件管理错误码](../apis-core-file-kit/errorcode-filemanagement.md)。 错误码14000001,请参考 [PhotoKeys](#photokeys)获取有关文件名的格式和长度要求。 错误码13900012,请参考[开发准备](../../media/medialibrary/photoAccessHelper-preparation.md)。 | 错误码ID | 错误信息 | | -------- | ---------------------------------------- | | 202 | Called by non-system application. | | 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types; 3. Parameter verification failed. | | 13900012 | Permission denied. | | 13900020 | Invalid argument. | | 14000001 | Invalid display name. | | 14000011 | System inner fail. | **示例:** phAccessHelper的创建请参考[@ohos.file.photoAccessHelper (相册管理模块)](arkts-apis-photoAccessHelper-f.md)的示例使用。 ```ts async function example(phAccessHelper: photoAccessHelper.PhotoAccessHelper) { console.info('createAssetDemo'); let testFileName: string = 'testFile' + Date.now() + '.jpg'; phAccessHelper.createAsset(testFileName, (err, photoAsset) => { if (photoAsset !== undefined) { console.info('createAsset file displayName' + photoAsset.displayName); console.info('createAsset successfully'); } else { console.error(`createAsset failed, error: ${err.code}, ${err.message}`); } }); } ``` ### createAsset createAsset(displayName: string): Promise<PhotoAsset> 指定待创建的图片或者视频的文件名,创建图片或视频资源,使用Promise方式返回结果。 待创建的文件名参数规格为: - 应包含有效文件主名和图片或视频扩展名。 - 文件名字符串长度为1~255。 - 文件主名中不允许出现的非法英文字符。
API18开始,非法字符包括: \ / : * ? " < > |
API10-17,非法字符包括:. .. \ / : * ? " ' ` < > | { } [ ] **系统接口**:此接口为系统接口。 **系统能力**:SystemCapability.FileManagement.PhotoAccessHelper.Core **需要权限**:ohos.permission.WRITE_IMAGEVIDEO **参数:** | 参数名 | 类型 | 必填 | 说明 | | -------- | ------------------------ | ---- | ------------------------- | | displayName | string | 是 | 创建的图片或者视频文件名。 | **返回值:** | 类型 | 说明 | | --------------------------- | -------------- | | Promise<[PhotoAsset](#photoasset)> | Promise对象,返回创建的图片和视频结果。 | **错误码:** 接口抛出错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)和[文件管理错误码](../apis-core-file-kit/errorcode-filemanagement.md)。 错误码14000001,请参考 [PhotoKeys](#photokeys)获取有关文件名的格式和长度要求。 错误码13900012,请参考[开发准备](../../media/medialibrary/photoAccessHelper-preparation.md)。 | 错误码ID | 错误信息 | | -------- | ---------------------------------------- | | 202 | Called by non-system application. | | 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types; 3. Parameter verification failed. | | 13900012 | Permission denied. | | 13900020 | Invalid argument. | | 14000001 | Invalid display name. | | 14000011 | System inner fail. | **示例:** phAccessHelper的创建请参考[@ohos.file.photoAccessHelper (相册管理模块)](arkts-apis-photoAccessHelper-f.md)的示例使用。 ```ts async function example(phAccessHelper: photoAccessHelper.PhotoAccessHelper) { console.info('createAssetDemo'); try { let testFileName: string = 'testFile' + Date.now() + '.jpg'; let photoAsset: photoAccessHelper.PhotoAsset = await phAccessHelper.createAsset(testFileName); console.info('createAsset file displayName' + photoAsset.displayName); console.info('createAsset successfully'); } catch (err) { console.error(`createAsset failed, error: ${err.code}, ${err.message}`); } } ``` ### createAsset createAsset(displayName: string, options: PhotoCreateOptions, callback: AsyncCallback<PhotoAsset>): void 指定待创建的图片或者视频的文件名和创建选项,创建图片或视频资源,使用callback方式返回结果。 待创建的文件名参数规格为: - 应包含有效文件主名和图片或视频扩展名。 - 文件名字符串长度为1~255。 - 文件主名中不允许出现的非法英文字符。
API18开始,非法字符包括: \ / : * ? " < > |
API10-17,非法字符包括:. .. \ / : * ? " ' ` < > | { } [ ] **系统接口**:此接口为系统接口。 **系统能力**:SystemCapability.FileManagement.PhotoAccessHelper.Core **需要权限**:ohos.permission.WRITE_IMAGEVIDEO **参数:** | 参数名 | 类型 | 必填 | 说明 | | -------- | ------------------------ | ---- | ------------------------- | | displayName | string | 是 | 创建的图片或者视频文件名。 | | options | [PhotoCreateOptions](#photocreateoptions) | 是 | 图片或视频的创建选项。 | | callback | AsyncCallback<[PhotoAsset](#photoasset)> | 是 | callback返回创建的图片和视频结果。 | **错误码:** 接口抛出错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)和[文件管理错误码](../apis-core-file-kit/errorcode-filemanagement.md)。 错误码14000001,请参考 [PhotoKeys](#photokeys)获取有关文件名的格式和长度要求。 错误码13900012,请参考[开发准备](../../media/medialibrary/photoAccessHelper-preparation.md)。 | 错误码ID | 错误信息 | | -------- | ---------------------------------------- | | 202 | Called by non-system application. | | 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types; 3. Parameter verification failed. | | 13900012 | Permission denied. | | 13900020 | Invalid argument. | | 14000001 | Invalid display name. | | 14000011 | System inner fail. | **示例:** phAccessHelper的创建请参考[@ohos.file.photoAccessHelper (相册管理模块)](arkts-apis-photoAccessHelper-f.md)的示例使用。 ```ts async function example(phAccessHelper: photoAccessHelper.PhotoAccessHelper) { console.info('createAssetDemo'); let testFileName: string = 'testFile' + Date.now() + '.jpg'; let createOption: photoAccessHelper.PhotoCreateOptions = { subtype: photoAccessHelper.PhotoSubtype.DEFAULT } phAccessHelper.createAsset(testFileName, createOption, (err, photoAsset) => { if (photoAsset !== undefined) { console.info('createAsset file displayName' + photoAsset.displayName); console.info('createAsset successfully'); } else { console.error(`createAsset failed, error: ${err.code}, ${err.message}`); } }); } ``` ### createAsset createAsset(displayName: string, options: PhotoCreateOptions): Promise<PhotoAsset> 指定待创建的图片或者视频的文件名和创建选项,创建图片或视频资源,使用Promise方式返回结果。 待创建的文件名参数规格为: - 应包含有效文件主名和图片或视频扩展名。 - 文件名字符串长度为1~255。 - 文件主名中不允许出现的非法英文字符。
API18开始,非法字符包括: \ / : * ? " < > |
API10-17,非法字符包括:. .. \ / : * ? " ' ` < > | { } [ ] **系统接口**:此接口为系统接口。 **系统能力**:SystemCapability.FileManagement.PhotoAccessHelper.Core **需要权限**:ohos.permission.WRITE_IMAGEVIDEO **参数:** | 参数名 | 类型 | 必填 | 说明 | | -------- | ------------------------ | ---- | ------------------------- | | displayName | string | 是 | 创建的图片或者视频文件名。 | | options | [PhotoCreateOptions](#photocreateoptions) | 是 | 图片或视频的创建选项。 | **返回值:** | 类型 | 说明 | | --------------------------- | -------------- | | Promise<[PhotoAsset](#photoasset)> | Promise对象,返回创建的图片和视频结果。 | **错误码:** 接口抛出错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)和[文件管理错误码](../apis-core-file-kit/errorcode-filemanagement.md)。 错误码14000001,请参考 [PhotoKeys](#photokeys)获取有关文件名的格式和长度要求。 错误码13900012,请参考[开发准备](../../media/medialibrary/photoAccessHelper-preparation.md)。 | 错误码ID | 错误信息 | | -------- | ---------------------------------------- | | 202 | Called by non-system application. | | 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types; 3. Parameter verification failed. | | 13900012 | Permission denied. | | 13900020 | Invalid argument. | | 14000001 | Invalid display name. | | 14000011 | System inner fail. | **示例:** phAccessHelper的创建请参考[@ohos.file.photoAccessHelper (相册管理模块)](arkts-apis-photoAccessHelper-f.md)的示例使用。 ```ts async function example(phAccessHelper: photoAccessHelper.PhotoAccessHelper) { console.info('createAssetDemo'); try { let testFileName:string = 'testFile' + Date.now() + '.jpg'; let createOption: photoAccessHelper.PhotoCreateOptions = { subtype: photoAccessHelper.PhotoSubtype.DEFAULT } let photoAsset: photoAccessHelper.PhotoAsset = await phAccessHelper.createAsset(testFileName, createOption); console.info('createAsset file displayName' + photoAsset.displayName); console.info('createAsset successfully'); } catch (err) { console.error(`createAsset failed, error: ${err.code}, ${err.message}`); } } ``` ### createAlbum(deprecated) createAlbum(name: string, callback: AsyncCallback<Album>): void 创建相册,使用callback方式返回结果。 待创建的相册名参数规格为: - 相册名字符串长度为1~255。 - 不允许出现的非法英文字符,包括:
. .. \ / : * ? " ' ` < > | { } [ ] - 相册名不允许重名。 > **说明:** > > 从API version 10开始支持,从API version 11开始废弃。建议使用[MediaAlbumChangeRequest.createAlbumRequest](#createalbumrequest11)替代。 **系统接口**:此接口为系统接口。 **系统能力**:SystemCapability.FileManagement.PhotoAccessHelper.Core **需要权限**:ohos.permission.WRITE_IMAGEVIDEO **参数:** | 参数名 | 类型 | 必填 | 说明 | | -------- | ------------------------ | ---- | ------------------------- | | name | string | 是 | 待创建相册的相册名。 | | callback | AsyncCallback<[Album](#album)> | 是 | callback返回创建的相册实例。 | **错误码:** 接口抛出错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)和[文件管理错误码](../apis-core-file-kit/errorcode-filemanagement.md)。 错误码13900012,请参考[开发准备](../../media/medialibrary/photoAccessHelper-preparation.md)。 | 错误码ID | 错误信息 | | -------- | ---------------------------------------- | | 202 | Called by non-system application. | | 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types; 3. Parameter verification failed. | | 13900012 | Permission denied. | | 13900015 | The file name already exists. | | 13900020 | Invalid argument. | | 14000011 | System inner fail. | **示例:** phAccessHelper的创建请参考[@ohos.file.photoAccessHelper (相册管理模块)](arkts-apis-photoAccessHelper-f.md)的示例使用。 ```ts async function example(phAccessHelper: photoAccessHelper.PhotoAccessHelper) { console.info('createAlbumDemo'); let albumName: string = 'newAlbumName' + new Date().getTime(); phAccessHelper.createAlbum(albumName, (err, album) => { if (err) { console.error(`createAlbumCallback failed with err: ${err.code}, ${err.message}`); return; } console.info('createAlbumCallback successfully, album: ' + album.albumName + ' album uri: ' + album.albumUri); }); } ``` ### createAlbum(deprecated) createAlbum(name: string): Promise<Album> 创建相册,使用Promise方式返回结果。 待创建的相册名参数规格为: - 相册名字符串长度为1~255。 - 不允许出现的非法英文字符,包括:
. .. \ / : * ? " ' ` < > | { } [ ] - 相册名不允许重名。 > **说明:** > > 从API version 10开始支持,从API version 11开始废弃。建议使用[MediaAlbumChangeRequest.createAlbumRequest](#createalbumrequest11)替代。 **系统接口**:此接口为系统接口。 **系统能力**:SystemCapability.FileManagement.PhotoAccessHelper.Core **需要权限**:ohos.permission.WRITE_IMAGEVIDEO **参数:** | 参数名 | 类型 | 必填 | 说明 | | -------- | ------------------------ | ---- | ------------------------- | | name | string | 是 | 待创建相册的相册名。 | **返回值:** | 类型 | 说明 | | --------------------------- | -------------- | | Promise<[Album](#album)> | Promise对象,返回创建的相册实例。 | **错误码:** 接口抛出错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)和[文件管理错误码](../apis-core-file-kit/errorcode-filemanagement.md)。 错误码13900012,请参考[开发准备](../../media/medialibrary/photoAccessHelper-preparation.md)。 | 错误码ID | 错误信息 | | -------- | ---------------------------------------- | | 202 | Called by non-system application. | | 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types; 3. Parameter verification failed. | | 13900012 | Permission denied. | | 13900015 | The file name already exists. | | 13900020 | Invalid argument. | | 14000011 | System inner fail. | **示例:** phAccessHelper的创建请参考[@ohos.file.photoAccessHelper (相册管理模块)](arkts-apis-photoAccessHelper-f.md)的示例使用。 ```ts import { BusinessError } from '@kit.BasicServicesKit'; async function example(phAccessHelper: photoAccessHelper.PhotoAccessHelper) { console.info('createAlbumDemo'); let albumName: string = 'newAlbumName' + new Date().getTime(); phAccessHelper.createAlbum(albumName).then((album) => { console.info('createAlbumPromise successfully, album: ' + album.albumName + ' album uri: ' + album.albumUri); }).catch((err: BusinessError) => { console.error(`createAlbumPromise failed with err: ${err.code}, ${err.message}`); }); } ``` ### deleteAlbums(deprecated) deleteAlbums(albums: Array<Album>, callback: AsyncCallback<void>): void 删除相册,使用callback方式返回结果。 删除相册前需先确保相册存在,只能删除用户相册。 > **说明:** > > 从API version 10开始支持,从API version 11开始废弃。建议使用[MediaAlbumChangeRequest.deleteAlbums](#deletealbums11)替代。 **系统接口**:此接口为系统接口。 **系统能力**:SystemCapability.FileManagement.PhotoAccessHelper.Core **需要权限**:ohos.permission.WRITE_IMAGEVIDEO **参数:** | 参数名 | 类型 | 必填 | 说明 | | -------- | ------------------------ | ---- | ------------------------- | | albums | Array<[Album](#album)> | 是 | 待删除相册的数组。 | | callback | AsyncCallback<void> | 是 | callback返回void。 | **错误码:** 接口抛出错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)和[文件管理错误码](../apis-core-file-kit/errorcode-filemanagement.md)。 错误码13900012,请参考[开发准备](../../media/medialibrary/photoAccessHelper-preparation.md)。 | 错误码ID | 错误信息 | | -------- | ---------------------------------------- | | 202 | Called by non-system application. | | 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types; 3. Parameter verification failed. | | 13900012 | Permission denied. | | 13900020 | Invalid argument. | | 14000011 | System inner fail. | **示例:** phAccessHelper的创建请参考[@ohos.file.photoAccessHelper (相册管理模块)](arkts-apis-photoAccessHelper-f.md)的示例使用。 ```ts import { dataSharePredicates } from '@kit.ArkData'; async function example(phAccessHelper: photoAccessHelper.PhotoAccessHelper) { // 示例代码为删除相册名为newAlbumName的相册。 console.info('deleteAlbumsDemo'); let predicates: dataSharePredicates.DataSharePredicates = new dataSharePredicates.DataSharePredicates(); predicates.equalTo('album_name', 'newAlbumName'); let fetchOptions: photoAccessHelper.FetchOptions = { fetchColumns: [], predicates: predicates }; let fetchResult: photoAccessHelper.FetchResult = await phAccessHelper.getAlbums(photoAccessHelper.AlbumType.USER, photoAccessHelper.AlbumSubtype.USER_GENERIC, fetchOptions); let album: photoAccessHelper.Album = await fetchResult.getFirstObject(); phAccessHelper.deleteAlbums([album], (err) => { if (err) { console.error(`deletePhotoAlbumsCallback failed with err: ${err.code}, ${err.message}`); return; } console.info('deletePhotoAlbumsCallback successfully'); }); fetchResult.close(); } ``` ### deleteAlbums(deprecated) deleteAlbums(albums: Array<Album>): Promise<void> 删除相册,使用Promise方式返回结果。 删除相册前需先确保相册存在,只能删除用户相册。 > **说明:** > > 从API version 10开始支持,从API version 11开始废弃。建议使用[MediaAlbumChangeRequest.deleteAlbums](#deletealbums11)替代。 **系统接口**:此接口为系统接口。 **系统能力**:SystemCapability.FileManagement.PhotoAccessHelper.Core **需要权限**:ohos.permission.WRITE_IMAGEVIDEO **参数:** | 参数名 | 类型 | 必填 | 说明 | | -------- | ------------------------ | ---- | ------------------------- | | albums | Array<[Album](#album)> | 是 | 待删除相册的数组。 | **返回值:** | 类型 | 说明 | | --------------------------- | -------------- | | Promise<void> | Promise对象,返回void。 | **错误码:** 接口抛出错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)和[文件管理错误码](../apis-core-file-kit/errorcode-filemanagement.md)。 错误码13900012,请参考[开发准备](../../media/medialibrary/photoAccessHelper-preparation.md)。 | 错误码ID | 错误信息 | | -------- | ---------------------------------------- | | 202 | Called by non-system application. | | 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types; 3. Parameter verification failed. | | 13900012 | Permission denied. | | 13900020 | Invalid argument. | | 14000011 | System inner fail. | **示例:** phAccessHelper的创建请参考[@ohos.file.photoAccessHelper (相册管理模块)](arkts-apis-photoAccessHelper-f.md)的示例使用。 ```ts import { dataSharePredicates } from '@kit.ArkData'; import { BusinessError } from '@kit.BasicServicesKit'; async function example(phAccessHelper: photoAccessHelper.PhotoAccessHelper) { // 示例代码为删除相册名为newAlbumName的相册。 console.info('deleteAlbumsDemo'); let predicates: dataSharePredicates.DataSharePredicates = new dataSharePredicates.DataSharePredicates(); predicates.equalTo('album_name', 'newAlbumName'); let fetchOptions: photoAccessHelper.FetchOptions = { fetchColumns: [], predicates: predicates }; let fetchResult: photoAccessHelper.FetchResult = await phAccessHelper.getAlbums(photoAccessHelper.AlbumType.USER, photoAccessHelper.AlbumSubtype.USER_GENERIC, fetchOptions); let album: photoAccessHelper.Album = await fetchResult.getFirstObject(); phAccessHelper.deleteAlbums([album]).then(() => { console.info('deletePhotoAlbumsPromise successfully'); }).catch((err: BusinessError) => { console.error(`deletePhotoAlbumsPromise failed with err: ${err.code}, ${err.message}`); }); fetchResult.close(); } ``` ### getHiddenAlbums11+ getHiddenAlbums(mode: HiddenPhotosDisplayMode, options: FetchOptions, callback: AsyncCallback<FetchResult<Album>>): void 根据隐藏文件显示模式和检索选项获取系统中的隐藏相册,使用callback方式返回结果。 **系统接口**:此接口为系统接口。 **需要权限**:ohos.permission.READ_IMAGEVIDEO 和 ohos.permission.MANAGE_PRIVATE_PHOTOS **系统能力**:SystemCapability.FileManagement.PhotoAccessHelper.Core **参数:** | 参数名 | 类型 | 必填 | 说明 | | -------- | ------------------------ | ---- | ------------------------- | | mode | [HiddenPhotosDisplayMode](#hiddenphotosdisplaymode11) | 是 | 隐藏文件显示模式。 | | options | [FetchOptions](arkts-apis-photoAccessHelper-i.md#fetchoptions) | 是 | 检索选项。 | | callback | AsyncCallback<[FetchResult](arkts-apis-photoAccessHelper-FetchResult.md)<[Album](#album)>> | 是 | callback返回获取相册的结果集。 | **错误码:** 接口抛出错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)和[文件管理错误码](../apis-core-file-kit/errorcode-filemanagement.md)。 | 错误码ID | 错误信息 | | -------- | ---------------------------------------- | | 201 | Permission verification failed, usually the result returned by VerifyAccessToken. | | 202 | Permission verification failed, application which is not a system application uses system API. | | 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types; 3. Parameter verification failed. | | 14000011 | System inner fail. | **示例:** phAccessHelper的创建请参考[@ohos.file.photoAccessHelper (相册管理模块)](arkts-apis-photoAccessHelper-f.md)的示例使用。 ```ts import { dataSharePredicates } from '@kit.ArkData'; // 获取系统中包含隐藏文件且相册名为'newAlbumName'的相册 async function getHiddenAlbumsView(phAccessHelper: photoAccessHelper.PhotoAccessHelper) { console.info('getHiddenAlbumsViewDemo'); let predicates: dataSharePredicates.DataSharePredicates = new dataSharePredicates.DataSharePredicates(); predicates.equalTo('album_name', 'newAlbumName'); let fetchOptions: photoAccessHelper.FetchOptions = { fetchColumns: [], predicates: predicates }; phAccessHelper.getHiddenAlbums(photoAccessHelper.HiddenPhotosDisplayMode.ALBUMS_MODE, fetchOptions, async (err, fetchResult) => { if (err !== undefined) { console.error(`getHiddenAlbumsViewCallback failed with error: ${err.code}, ${err.message}`); return; } if (fetchResult === undefined) { console.error('getHiddenAlbumsViewCallback fetchResult is undefined'); return; } let album = await fetchResult.getFirstObject(); if (album === undefined) { console.error('getHiddenAlbumsViewCallback album is undefined'); fetchResult.close(); return; } console.info('getHiddenAlbumsViewCallback successfully, album name: ' + album.albumName); fetchResult.close(); }); } ``` ### getHiddenAlbums11+ getHiddenAlbums(mode: HiddenPhotosDisplayMode, callback: AsyncCallback<FetchResult<Album>>): void 根据隐藏文件显示模式获取系统中的隐藏相册,使用callback方式返回结果 **系统接口**:此接口为系统接口。 **需要权限**:ohos.permission.READ_IMAGEVIDEO 和 ohos.permission.MANAGE_PRIVATE_PHOTOS **系统能力**:SystemCapability.FileManagement.PhotoAccessHelper.Core **参数:** | 参数名 | 类型 | 必填 | 说明 | | -------- | ------------------------ | ---- | ------------------------- | | mode | [HiddenPhotosDisplayMode](#hiddenphotosdisplaymode11) | 是 | 隐藏文件显示模式。 | | callback | AsyncCallback<[FetchResult](arkts-apis-photoAccessHelper-FetchResult.md)<[Album](#album)>> | 是 | callback返回获取相册的结果集。 | **错误码:** 接口抛出错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)和[文件管理错误码](../apis-core-file-kit/errorcode-filemanagement.md)。 | 错误码ID | 错误信息 | | -------- | ---------------------------------------- | | 201 | Permission verification failed, usually the result returned by VerifyAccessToken. | | 202 | Permission verification failed, application which is not a system application uses system API. | | 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types; 3. Parameter verification failed. | | 14000011 | System inner fail. | **示例:** phAccessHelper的创建请参考[@ohos.file.photoAccessHelper (相册管理模块)](arkts-apis-photoAccessHelper-f.md)的示例使用。 ```ts import { dataSharePredicates } from '@kit.ArkData'; // 获取系统预置的隐藏相册 async function getSysHiddenAlbum(phAccessHelper: photoAccessHelper.PhotoAccessHelper) { console.info('getSysHiddenAlbumDemo'); phAccessHelper.getHiddenAlbums(photoAccessHelper.HiddenPhotosDisplayMode.ASSETS_MODE, async (err, fetchResult) => { if (fetchResult === undefined) { console.error('getSysHiddenAlbumCallback fetchResult is undefined'); return; } let hiddenAlbum: photoAccessHelper.Album = await fetchResult.getFirstObject(); if (hiddenAlbum === undefined) { console.error('getSysHiddenAlbumCallback hiddenAlbum is undefined'); fetchResult.close(); return; } console.info('getSysHiddenAlbumCallback successfully, albumUri: ' + hiddenAlbum.albumUri); fetchResult.close(); }); } // 获取隐藏相册-相册视图,即系统中包含隐藏文件的相册(不包含系统预置的隐藏相册本身和回收站相册) async function getHiddenAlbumsView(phAccessHelper: photoAccessHelper.PhotoAccessHelper) { console.info('getHiddenAlbumsViewDemo'); phAccessHelper.getHiddenAlbums(photoAccessHelper.HiddenPhotosDisplayMode.ALBUMS_MODE, async (err, fetchResult) => { if (fetchResult === undefined) { console.error('getHiddenAlbumsViewCallback fetchResult is undefined'); return; } let albums: Array = await fetchResult.getAllObjects(); if (albums === undefined) { console.error('getHiddenAlbumsViewCallback albums is undefined'); fetchResult.close(); return; } console.info('getHiddenAlbumsViewCallback successfully, albums size: ' + albums.length); let predicates: dataSharePredicates.DataSharePredicates = new dataSharePredicates.DataSharePredicates(); let fetchOption: photoAccessHelper.FetchOptions = { fetchColumns: [], predicates: predicates }; for (let i = 0; i < albums.length; i++) { // 获取相册中的隐藏文件。 albums[i].getAssets(fetchOption, (err, assetFetchResult) => { if (assetFetchResult === undefined) { console.error('getHiddenAlbumsViewCallback assetFetchResult is undefined'); return; } console.info('album get hidden assets successfully, getCount: ' + assetFetchResult.getCount()); }); } fetchResult.close(); }); } ``` ### getHiddenAlbums11+ getHiddenAlbums(mode: HiddenPhotosDisplayMode, options?: FetchOptions): Promise<FetchResult<Album>> 根据隐藏文件显示模式和检索选项获取系统中的隐藏相册,使用Promise方式返回结果。 **系统接口**:此接口为系统接口。 **需要权限**:ohos.permission.READ_IMAGEVIDEO 和 ohos.permission.MANAGE_PRIVATE_PHOTOS **系统能力**:SystemCapability.FileManagement.PhotoAccessHelper.Core **参数:** | 参数名 | 类型 | 必填 | 说明 | | -------- | ------------------------ | ---- | ------------------------- | | mode | [HiddenPhotosDisplayMode](#hiddenphotosdisplaymode11) | 是 | 隐藏文件显示模式。 | | options | [FetchOptions](arkts-apis-photoAccessHelper-i.md#fetchoptions) | 否 | 检索选项,不填时默认根据隐藏文件显示模式检索。 | **返回值:** | 类型 | 说明 | | --------------------------- | -------------- | | Promise<[FetchResult](arkts-apis-photoAccessHelper-FetchResult.md)<[Album](#album)>> | Promise对象,返回获取相册的结果集。 **错误码:** 接口抛出错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)和[文件管理错误码](../apis-core-file-kit/errorcode-filemanagement.md)。 | 错误码ID | 错误信息 | | -------- | ---------------------------------------- | | 201 | Permission verification failed, usually the result returned by VerifyAccessToken. | | 202 | Permission verification failed, application which is not a system application uses system API. | | 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types; 3. Parameter verification failed. | | 14000011 | System inner fail. | **示例:** phAccessHelper的创建请参考[@ohos.file.photoAccessHelper (相册管理模块)](arkts-apis-photoAccessHelper-f.md)的示例使用。 ```ts import { dataSharePredicates } from '@kit.ArkData'; import { BusinessError } from '@kit.BasicServicesKit'; // 获取系统预置的隐藏相册 async function getSysHiddenAlbum(phAccessHelper: photoAccessHelper.PhotoAccessHelper) { console.info('getSysHiddenAlbumDemo'); phAccessHelper.getHiddenAlbums(photoAccessHelper.HiddenPhotosDisplayMode.ASSETS_MODE) .then( async (fetchResult) => { if (fetchResult === undefined) { console.error('getSysHiddenAlbumPromise fetchResult is undefined'); return; } let hiddenAlbum: photoAccessHelper.Album = await fetchResult.getFirstObject(); console.info('getAlbumsPromise successfully, albumUri: ' + hiddenAlbum.albumUri); fetchResult.close(); }).catch((err: BusinessError) => { console.error(`getSysHiddenAlbumPromise failed with err: ${err.code}, ${err.message}`); }); } // 获取隐藏相册-相册视图,即系统中包含隐藏文件的相册(不包含系统预置的隐藏相册本身和回收站相册) async function getHiddenAlbumsView(phAccessHelper: photoAccessHelper.PhotoAccessHelper) { console.info('getHiddenAlbumsViewDemo'); phAccessHelper.getHiddenAlbums(photoAccessHelper.HiddenPhotosDisplayMode.ALBUMS_MODE).then( async (fetchResult) => { if (fetchResult === undefined) { console.error('getHiddenAlbumsViewPromise fetchResult is undefined'); return; } let albums: Array = await fetchResult.getAllObjects(); console.info('getHiddenAlbumsViewPromise successfully, albums size: ' + albums.length); let predicates: dataSharePredicates.DataSharePredicates = new dataSharePredicates.DataSharePredicates(); let fetchOption: photoAccessHelper.FetchOptions = { fetchColumns: [], predicates: predicates }; for (let i = 0; i < albums.length; i++) { // 获取相册中的隐藏文件。 albums[i].getAssets(fetchOption).then((assetFetchResult) => { console.info('album get hidden assets successfully, getCount: ' + assetFetchResult.getCount()); }).catch((err: BusinessError) => { console.error(`album get hidden assets failed with error: ${err.code}, ${err.message}`); }); } fetchResult.close(); }).catch((err: BusinessError) => { console.error(`getHiddenAlbumsViewPromise failed with err: ${err.code}, ${err.message}`); }); } ``` ### deleteAssets(deprecated) deleteAssets(uriList: Array<string>, callback: AsyncCallback<void>): void 删除媒体文件,删除的文件进入到回收站,使用callback方式返回结果。 > **说明:** > > 从API version 10开始支持,从API version 11开始废弃。建议使用[MediaAssetChangeRequest.deleteAssets](arkts-apis-photoAccessHelper-MediaAssetChangeRequest.md#deleteassets11)替代。 **系统接口**:此接口为系统接口。 **需要权限**:ohos.permission.WRITE_IMAGEVIDEO **系统能力**:SystemCapability.FileManagement.PhotoAccessHelper.Core **参数:** | 参数名 | 类型 | 必填 | 说明 | | -------- | ------------------------- | ---- | ---------- | | uriList | Array<string> | 是 | 待删除的媒体文件uri数组。 | | callback | AsyncCallback<void> | 是 | callback返回void。 | **错误码:** 接口抛出错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)和[文件管理错误码](../apis-core-file-kit/errorcode-filemanagement.md)。 错误码13900012,请参考[开发准备](../../media/medialibrary/photoAccessHelper-preparation.md)。 | 错误码ID | 错误信息 | | -------- | ---------------------------------------- | | 202 | Called by non-system application. | | 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types; 3. Parameter verification failed. | | 13900012 | Permission denied. | | 13900020 | Invalid argument. | | 14000002 | The uri format is incorrect or does not exist. | | 14000011 | System inner fail. | **示例:** phAccessHelper的创建请参考[@ohos.file.photoAccessHelper (相册管理模块)](arkts-apis-photoAccessHelper-f.md)的示例使用。 ```ts import { dataSharePredicates } from '@kit.ArkData'; async function example(phAccessHelper: photoAccessHelper.PhotoAccessHelper) { console.info('deleteAssetDemo'); let predicates: dataSharePredicates.DataSharePredicates = new dataSharePredicates.DataSharePredicates(); let fetchOptions: photoAccessHelper.FetchOptions = { fetchColumns: [], predicates: predicates }; try { let fetchResult: photoAccessHelper.FetchResult = await phAccessHelper.getAssets(fetchOptions); let asset: photoAccessHelper.PhotoAsset = await fetchResult.getFirstObject(); if (asset === undefined) { console.error('asset not exist'); return; } phAccessHelper.deleteAssets([asset.uri], (err) => { if (err === undefined) { console.info('deleteAssets successfully'); } else { console.error(`deleteAssets failed with error: ${err.code}, ${err.message}`); } }); } catch (err) { console.error(`fetch failed, error: ${err.code}, ${err.message}`); } } ``` ### deleteAssets(deprecated) deleteAssets(uriList: Array<string>): Promise<void> 删除媒体文件,删除的文件进入到回收站,使用Promise方式返回结果。 > **说明:** > > 从API version 10开始支持,从API version 11开始废弃。建议使用[MediaAssetChangeRequest.deleteAssets](arkts-apis-photoAccessHelper-MediaAssetChangeRequest.md#deleteassets11)替代。 **系统接口**:此接口为系统接口。 **需要权限**:ohos.permission.WRITE_IMAGEVIDEO **系统能力**:SystemCapability.FileManagement.PhotoAccessHelper.Core **参数:** | 参数名 | 类型 | 必填 | 说明 | | -------- | ------------------------- | ---- | ---------- | | uriList | Array<string> | 是 | 待删除的媒体文件uri数组。 | **返回值:** | 类型 | 说明 | | --------------------------------------- | ----------------- | | Promise<void>| Promise对象,返回void。 | **错误码:** 接口抛出错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)和[文件管理错误码](../apis-core-file-kit/errorcode-filemanagement.md)。 错误码13900012,请参考[开发准备](../../media/medialibrary/photoAccessHelper-preparation.md)。 | 错误码ID | 错误信息 | | -------- | ---------------------------------------- | | 202 | Called by non-system application. | | 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types; 3. Parameter verification failed. | | 13900012 | Permission denied. | | 13900020 | Invalid argument. | | 14000002 | The uri format is incorrect or does not exist. | | 14000011 | System inner fail. | **示例:** phAccessHelper的创建请参考[@ohos.file.photoAccessHelper (相册管理模块)](arkts-apis-photoAccessHelper-f.md)的示例使用。 ```ts import { dataSharePredicates } from '@kit.ArkData'; async function example(phAccessHelper: photoAccessHelper.PhotoAccessHelper) { console.info('deleteDemo'); let predicates: dataSharePredicates.DataSharePredicates = new dataSharePredicates.DataSharePredicates(); let fetchOptions: photoAccessHelper.FetchOptions = { fetchColumns: [], predicates: predicates }; try { let fetchResult: photoAccessHelper.FetchResult = await phAccessHelper.getAssets(fetchOptions); let asset: photoAccessHelper.PhotoAsset = await fetchResult.getFirstObject(); if (asset === undefined) { console.error('asset not exist'); return; } await phAccessHelper.deleteAssets([asset.uri]); console.info('deleteAssets successfully'); } catch (err) { console.error(`deleteAssets failed with error: ${err.code}, ${err.message}`); } } ``` ### getPhotoIndex getPhotoIndex(photoUri: string, albumUri: string, options: FetchOptions, callback: AsyncCallback<number>): void 获取相册中图片或视频的位置,使用callback方式返回结果。 **系统接口**:此接口为系统接口。 **需要权限**:ohos.permission.READ_IMAGEVIDEO **系统能力**:SystemCapability.FileManagement.PhotoAccessHelper.Core **参数:** | 参数名 | 类型 | 必填 | 说明 | | -------- | ------------------------- | ---- | ---------- | | photoUri | string | 是 | 所查询的图库资源的uri。 | | albumUri | string | 是 | 相册uri,可以为空字符串,为空字符串时默认查询全部图库资源。 | | options | [FetchOptions](arkts-apis-photoAccessHelper-i.md#fetchoptions) | 是 | 检索选项,predicates中必须设置一种检索排序方式,不设置或多设置均会导致接口调用异常。 | | callback | AsyncCallback<number>| 是 | callback返回相册中资源的索引。 | **错误码:** 接口抛出错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)和[文件管理错误码](../apis-core-file-kit/errorcode-filemanagement.md)。 错误码13900012,请参考[开发准备](../../media/medialibrary/photoAccessHelper-preparation.md)。 | 错误码ID | 错误信息 | | -------- | ---------------------------------------- | | 202 | Called by non-system application. | | 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types; 3. Parameter verification failed. | | 13900012 | Permission denied. | | 13900020 | Invalid argument. | | 14000011 | System inner fail. | **示例:** phAccessHelper的创建请参考[@ohos.file.photoAccessHelper (相册管理模块)](arkts-apis-photoAccessHelper-f.md)的示例使用。 ```ts import { dataSharePredicates } from '@kit.ArkData'; async function example(phAccessHelper: photoAccessHelper.PhotoAccessHelper) { try { console.info('getPhotoIndexDemo'); let predicatesForGetAsset: dataSharePredicates.DataSharePredicates = new dataSharePredicates.DataSharePredicates(); let fetchOp: photoAccessHelper.FetchOptions = { fetchColumns: [], predicates: predicatesForGetAsset }; // Obtain the uri of the album. let albumFetchResult: photoAccessHelper.FetchResult = await phAccessHelper.getAlbums(photoAccessHelper.AlbumType.SYSTEM, photoAccessHelper.AlbumSubtype.FAVORITE, fetchOp); let album: photoAccessHelper.Album = await albumFetchResult.getFirstObject(); let predicates: dataSharePredicates.DataSharePredicates = new dataSharePredicates.DataSharePredicates(); predicates.orderByAsc(photoAccessHelper.PhotoKeys.DATE_MODIFIED); let fetchOptions: photoAccessHelper.FetchOptions = { fetchColumns: [photoAccessHelper.PhotoKeys.DATE_MODIFIED], predicates: predicates }; let photoFetchResult: photoAccessHelper.FetchResult = await album.getAssets(fetchOptions); let expectIndex = 1; // Obtain the uri of the second file. let photoAsset: photoAccessHelper.PhotoAsset = await photoFetchResult.getObjectByPosition(expectIndex); phAccessHelper.getPhotoIndex(photoAsset.uri, album.albumUri, fetchOptions, (err, index) => { if (err === undefined) { console.info(`getPhotoIndex successfully and index is : ${index}`); } else { console.error(`getPhotoIndex failed; error: ${err.code}, ${err.message}`); } }); } catch (error) { console.error(`getPhotoIndex failed; error: ${error.code}, ${error.message}`); } } ``` ### getPhotoIndex getPhotoIndex(photoUri: string, albumUri: string, options: FetchOptions): Promise<number> 获取相册中图片或视频的位置,使用Promise方式返回结果。 **系统接口**:此接口为系统接口。 **需要权限**:ohos.permission.READ_IMAGEVIDEO **系统能力**:SystemCapability.FileManagement.PhotoAccessHelper.Core **参数:** | 参数名 | 类型 | 必填 | 说明 | | -------- | ------------------------- | ---- | ---------- | | photoUri | string | 是 | 所查询的图库资源的uri。 | | albumUri | string | 是 | 相册uri,可以为空字符串,为空字符串时默认查询全部图库资源。 | | options | [FetchOptions](arkts-apis-photoAccessHelper-i.md#fetchoptions) | 是 | 检索选项,predicates中必须设置一种检索排序方式,不设置或多设置均会导致接口调用异常。 | **返回值:** | 类型 | 说明 | | --------------------------------------- | ----------------- | | Promise<number>| 返回相册中资源的索引。 | **错误码:** 接口抛出错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)和[文件管理错误码](../apis-core-file-kit/errorcode-filemanagement.md)。 错误码13900012,请参考[开发准备](../../media/medialibrary/photoAccessHelper-preparation.md)。 | 错误码ID | 错误信息 | | -------- | ---------------------------------------- | | 202 | Called by non-system application. | | 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types; 3. Parameter verification failed. | | 13900012 | Permission denied. | | 13900020 | Invalid argument. | | 14000011 | System inner fail. | **示例:** phAccessHelper的创建请参考[@ohos.file.photoAccessHelper (相册管理模块)](arkts-apis-photoAccessHelper-f.md)的示例使用。 ```ts import { dataSharePredicates } from '@kit.ArkData'; import { BusinessError } from '@kit.BasicServicesKit'; async function example(phAccessHelper: photoAccessHelper.PhotoAccessHelper) { try { console.info('getPhotoIndexDemo'); let predicatesForGetAsset: dataSharePredicates.DataSharePredicates = new dataSharePredicates.DataSharePredicates(); let fetchOp: photoAccessHelper.FetchOptions = { fetchColumns: [], predicates: predicatesForGetAsset }; // Obtain the uri of the album. let albumFetchResult: photoAccessHelper.FetchResult = await phAccessHelper.getAlbums(photoAccessHelper.AlbumType.SYSTEM, photoAccessHelper.AlbumSubtype.FAVORITE, fetchOp); let album: photoAccessHelper.Album = await albumFetchResult.getFirstObject(); let predicates: dataSharePredicates.DataSharePredicates = new dataSharePredicates.DataSharePredicates(); predicates.orderByAsc(photoAccessHelper.PhotoKeys.DATE_MODIFIED); let fetchOptions: photoAccessHelper.FetchOptions = { fetchColumns: [photoAccessHelper.PhotoKeys.DATE_MODIFIED], predicates: predicates }; let photoFetchResult: photoAccessHelper.FetchResult = await album.getAssets(fetchOptions); let expectIndex = 1; // Obtain the uri of the second file. let photoAsset: photoAccessHelper.PhotoAsset = await photoFetchResult.getObjectByPosition(expectIndex); phAccessHelper.getPhotoIndex(photoAsset.uri, album.albumUri, fetchOptions).then((index) => { console.info(`getPhotoIndex successfully and index is : ${index}`); }).catch((err: BusinessError) => { console.error(`getPhotoIndex failed; error: ${err.code}, ${err.message}`); }); } catch (error) { console.error(`getPhotoIndex failed; error: ${error.code}, ${error.message}`); } } ``` ### saveFormInfo11+ saveFormInfo(info:FormInfo, callback: AsyncCallback<void>):void 将图库卡片相关信息保存到数据库中,使用callback方式返回结果。 **系统接口**:此接口为系统接口。 **需要权限**:ohos.permission.WRITE_IMAGEVIDEO **系统能力**:SystemCapability.FileManagement.PhotoAccessHelper.Core **参数:** | 参数名 | 类型 | 必填 | 说明 | | -------- | ------------------------ | ---- | ------------------------- | | info | [FormInfo](#forminfo11) | 是 | 图库卡片信息,包括图库卡片的id和卡片绑定的图片的uri。 | | callback | AsyncCallback<void> | 是 | callback返回void。 | **错误码:** 接口抛出错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)和[文件管理错误码](../apis-core-file-kit/errorcode-filemanagement.md)。 | 错误码ID | 错误信息 | | -------- | ---------------------------------------- | | 201 | Permission verification failed, usually the result returned by VerifyAccessToken. | | 202 | Permission verification failed, application which is not a system application uses system API. | | 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types; 3. Parameter verification failed. | | 14000011 | System inner fail. | **示例:** phAccessHelper的创建请参考[@ohos.file.photoAccessHelper (相册管理模块)](arkts-apis-photoAccessHelper-f.md)的示例使用。 ```ts import { dataSharePredicates } from '@kit.ArkData'; import { BusinessError } from '@kit.BasicServicesKit'; async function example(phAccessHelper: photoAccessHelper.PhotoAccessHelper) { console.info('saveFormInfoDemo'); let predicates: dataSharePredicates.DataSharePredicates = new dataSharePredicates.DataSharePredicates(); let fetchOptions: photoAccessHelper.FetchOptions = { fetchColumns: [], predicates: predicates }; let fetchResult: photoAccessHelper.FetchResult = await phAccessHelper.getAssets(fetchOptions); let photoAsset: photoAccessHelper.PhotoAsset = await fetchResult.getFirstObject(); let info: photoAccessHelper.FormInfo = { //formId是一个由纯数字组成的字符串,uri为图库中存在的图片的uri信息,图库中无图片创建卡片时uri需为空字符串。 formId : "20230116123", uri: photoAsset.uri, } phAccessHelper.saveFormInfo(info, async (err: BusinessError) => { if (err == undefined) { console.info('saveFormInfo success'); } else { console.error(`saveFormInfo fail with error: ${err.code}, ${err.message}`); } }); } ``` ### saveFormInfo11+ saveFormInfo(info:FormInfo):Promise<void> 将图库卡片相关信息保存到数据库中,使用Promise方式返回结果。 **系统接口**:此接口为系统接口。 **需要权限**:ohos.permission.WRITE_IMAGEVIDEO **系统能力**:SystemCapability.FileManagement.PhotoAccessHelper.Core **参数:** | 参数名 | 类型 | 必填 | 说明 | | -------- | ------------------------ | ---- | ------------------------- | | info | [FormInfo](#forminfo11) | 是 | 图库卡片信息,包括图库卡片的id和卡片绑定的图片的uri。 | **返回值:** | 类型 | 说明 | | --------------------------------------- | ----------------- | | Promise<void>| Promise对象,返回void。 | **错误码:** 接口抛出错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)和[文件管理错误码](../apis-core-file-kit/errorcode-filemanagement.md)。 | 错误码ID | 错误信息 | | -------- | ---------------------------------------- | | 201 | Permission verification failed, usually the result returned by VerifyAccessToken. | | 202 | Permission verification failed, application which is not a system application uses system API. | | 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types; 3. Parameter verification failed. | | 14000011 | System inner fail. | **示例:** phAccessHelper的创建请参考[@ohos.file.photoAccessHelper (相册管理模块)](arkts-apis-photoAccessHelper-f.md)的示例使用。 ```ts import { dataSharePredicates } from '@kit.ArkData'; import { BusinessError } from '@kit.BasicServicesKit'; async function example(phAccessHelper: photoAccessHelper.PhotoAccessHelper) { console.info('saveFormInfoDemo'); let predicates: dataSharePredicates.DataSharePredicates = new dataSharePredicates.DataSharePredicates(); let fetchOptions: photoAccessHelper.FetchOptions = { fetchColumns: [], predicates: predicates }; let fetchResult: photoAccessHelper.FetchResult = await phAccessHelper.getAssets(fetchOptions); let photoAsset: photoAccessHelper.PhotoAsset = await fetchResult.getFirstObject(); let info: photoAccessHelper.FormInfo = { //formId是一个由纯数字组成的字符串,uri为图库中存在的图片的uri信息,图库中无图片创建卡片时uri需为空字符串。 formId: "20230116123", uri: photoAsset.uri, } phAccessHelper.saveFormInfo(info).then(() => { console.info('saveFormInfo successfully'); }).catch((err: BusinessError) => { console.error(`saveFormInfo failed with error: ${err.code}, ${err.message}`); }); } ``` ### removeFormInfo11+ removeFormInfo(info:FormInfo, callback: AsyncCallback<void>):void 从数据库中删除图库卡片信息,使用callback方式返回结果。 **系统接口**:此接口为系统接口。 **需要权限**:ohos.permission.WRITE_IMAGEVIDEO **系统能力**:SystemCapability.FileManagement.PhotoAccessHelper.Core **参数:** | 参数名 | 类型 | 必填 | 说明 | | -------- | ------------------------ | ---- | ------------------------- | | info | [FormInfo](#forminfo11) | 是 | 图库卡片信息,包括图库卡片的id和卡片绑定的图片的uri。 | | callback | AsyncCallback<void> | 是 | callback返回void。 | **错误码:** 接口抛出错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)和[文件管理错误码](../apis-core-file-kit/errorcode-filemanagement.md)。 | 错误码ID | 错误信息 | | -------- | ---------------------------------------- | | 201 | Permission verification failed, usually the result returned by VerifyAccessToken. | | 202 | Permission verification failed, application which is not a system application uses system API. | | 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types; 3. Parameter verification failed. | | 14000011 | System inner fail. | **示例:** phAccessHelper的创建请参考[@ohos.file.photoAccessHelper (相册管理模块)](arkts-apis-photoAccessHelper-f.md)的示例使用。 ```ts import { BusinessError } from '@kit.BasicServicesKit'; async function example(phAccessHelper: photoAccessHelper.PhotoAccessHelper) { console.info('removeFormInfoDemo'); let info: photoAccessHelper.FormInfo = { //formId是一个由纯数字组成的字符串,移除卡片的时候uri填空即可。 formId: "20230116123", uri: "", } phAccessHelper.removeFormInfo(info, async (err: BusinessError) => { if (err == undefined) { console.info('removeFormInfo success'); } else { console.error(`removeFormInfo fail with error: ${err.code}, ${err.message}`); } }); } ``` ### removeFormInfo11+ removeFormInfo(info:FormInfo):Promise<void> 从数据库中删除图库卡片信息,使用Promise方式返回结果。 **系统接口**:此接口为系统接口。 **需要权限**:ohos.permission.WRITE_IMAGEVIDEO **系统能力**:SystemCapability.FileManagement.PhotoAccessHelper.Core **参数:** | 参数名 | 类型 | 必填 | 说明 | | -------- | ------------------------ | ---- | ------------------------- | | info | [FormInfo](#forminfo11) | 是 | 图库卡片信息,包括图库卡片的id和卡片绑定的图片的uri。 | **返回值:** | 类型 | 说明 | | --------------------------------------- | ----------------- | | Promise<void>| Promise对象,返回void。 | **错误码:** 接口抛出错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)和[文件管理错误码](../apis-core-file-kit/errorcode-filemanagement.md)。 | 错误码ID | 错误信息 | | -------- | ---------------------------------------- | | 201 | Permission verification failed, usually the result returned by VerifyAccessToken. | | 202 | Permission verification failed, application which is not a system application uses system API. | | 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types; 3. Parameter verification failed. | | 14000011 | System inner fail. | **示例:** phAccessHelper的创建请参考[@ohos.file.photoAccessHelper (相册管理模块)](arkts-apis-photoAccessHelper-f.md)的示例使用。 ```ts import { BusinessError } from '@kit.BasicServicesKit'; async function example(phAccessHelper: photoAccessHelper.PhotoAccessHelper) { console.info('removeFormInfoDemo'); let info: photoAccessHelper.FormInfo = { //formId是一个由纯数字组成的字符串,移除卡片的时候uri填空即可。 formId: "20230116123", uri: "", } phAccessHelper.removeFormInfo(info).then(() => { console.info('removeFormInfo successfully'); }).catch((err: BusinessError) => { console.error(`removeFormInfo failed with error: ${err.code}, ${err.message}`); }); } ``` ### createAssetsForApp19+ createAssetsForApp(bundleName: string, appName: string, tokenId: number, photoCreationConfigs: Array<PhotoCreationConfig>): Promise<Array<string>> 调用接口代替应用创建媒体库uri列表。Uri已对tokenId对应的应用授权,支持应用使用uri写入图片/视频。 **系统接口**:此接口为系统接口。 **需要权限**:ohos.permission.WRITE_IMAGEVIDEO **系统能力**:SystemCapability.FileManagement.PhotoAccessHelper.Core **参数:** | 参数名 | 类型 | 必填 | 说明 | | -------- |----------------------------------------------------------------------| ---- | ------------------------- | | bundleName | string | 是 | 需保存图片/视频文件的应用bundle name。 | | appName | string | 是 | 需保存图片/视频文件的应用app name。 | | tokenId | number | 是 | 需保存图片/视频文件的应用tokenId。 | | photoCreationConfigs | Array<[PhotoCreationConfig](arkts-apis-photoAccessHelper-i.md#photocreationconfig12)> | 是 | 保存图片/视频到媒体库的配置。 | **返回值:** | 类型 | 说明 | | --------------------------------------- | ----------------- | | Promise<Array<string>> | Promise对象,返回给接口调用方的媒体库文件uri列表。Uri已对tokenId对应的应用授权,支持应用写入数据。如果生成uri异常,则返回批量创建错误码。
返回-3006表不允许出现非法字符;返回-2004表示图片类型和后缀不符;返回-203表示文件操作异常。 | **错误码:** 接口抛出错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)和[文件管理错误码](../apis-core-file-kit/errorcode-filemanagement.md)。 | 错误码ID | 错误信息 | | -------- | ---------------------------------------- | | 201 | Permission denied. | | 202 | Called by non-system application. | | 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameters types; 3. Parameter verification failed. | | 14000011 | Internal system error. | **示例:** phAccessHelper的创建请参考[@ohos.file.photoAccessHelper (相册管理模块)](arkts-apis-photoAccessHelper-f.md)的示例使用。 ```ts async function example(phAccessHelper: photoAccessHelper.PhotoAccessHelper) { console.info('createAssetsForAppDemo.'); try { let bundleName: string = 'testBundleName'; let appName: string = 'testAppName'; let tokenId: number = 537197950; let photoCreationConfigs: Array = [ { title: 'test', fileNameExtension: 'jpg', photoType: photoAccessHelper.PhotoType.IMAGE, subtype: photoAccessHelper.PhotoSubtype.DEFAULT, } ]; let desFileUris: Array = await phAccessHelper.createAssetsForApp(bundleName, appName, tokenId, photoCreationConfigs); console.info('createAssetsForApp success, data is ' + desFileUris); } catch (err) { console.error(`createAssetsForApp failed with error: ${err.code}, ${err.message}`); } } ``` ### grantPhotoUriPermission19+ grantPhotoUriPermission(tokenId: number, uri: string, photoPermissionType: PhotoPermissionType, hideSensitiveType: HideSensitiveType): Promise<number> 给应用授予uri的访问权限,使用Promise方式返回结果。 **系统接口**:此接口为系统接口。 **系统能力**:SystemCapability.FileManagement.PhotoAccessHelper.Core **需要权限:** ohos.permission.WRITE_IMAGEVIDEO **参数:** | 参数名 | 类型 | 必填 | 说明 | | -------- |----------------------------------------------------------------------| ---- | ------------------------- | | tokenId | number | 是 | 应用标识,将访问权限授予给tokenId标识的应用。 | | uri | string | 是 | 媒体资源的uri,uri表示的资源的访问权限将授予给应用。| | photoPermissionType | [PhotoPermissionType](#photopermissiontype12) | 是 | 权限类型,将photoPermissionType表示的权限授予给应用。权限的覆盖规则参考枚举类。| | hideSensitiveType | [HideSensitiveType](#hidesensitivetype12) | 是 | 脱敏类型,预留参数,目前可传枚举类中任一值。| **返回值:** | 类型 | 说明 | | --------------------------------------- | ----------------- | | Promise<number> | Promise对象,0:授权成功。 1:已有权限。-1:授权失败。| **错误码:** 接口抛出错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)和[文件管理错误码](../apis-core-file-kit/errorcode-filemanagement.md)。 | 错误码ID | 错误信息 | | -------- | ---------------------------------------- | | 201 | Permission denied. | | 202 | Called by non-system application. | | 13900020 | Invalid argument. Possible causes: 1. Incorrect uri format; 2. The value of photoPermissionType or hideSensitiveType is out of range. | | 14000011 | Internal system error. | **示例:** phAccessHelper的创建请参考[@ohos.file.photoAccessHelper (相册管理模块)](arkts-apis-photoAccessHelper-f.md)的示例使用。 ```ts async function example(phAccessHelper: photoAccessHelper.PhotoAccessHelper) { console.info('grantPhotoUriPermissionDemo'); try { let tokenId = 502334412; let result = await phAccessHelper.grantPhotoUriPermission(tokenId, 'file://media/Photo/1/IMG_datetime_0001/displayName.jpg', photoAccessHelper.PhotoPermissionType.TEMPORARY_READ_IMAGEVIDEO, photoAccessHelper.HideSensitiveType.HIDE_LOCATION_AND_SHOOTING_PARAM); console.info('grantPhotoUriPermission success, result=' + result); } catch (err) { console.error('grantPhotoUriPermission failed, error=' + err); } } ``` ### grantPhotoUrisPermission19+ grantPhotoUrisPermission(tokenId: number, uriList: Array<string>, photoPermissionType: PhotoPermissionType, hideSensitiveType: HideSensitiveType): Promise<number> 给应用授予uri列表的访问权限,使用Promise方式返回结果。 **系统接口**:此接口为系统接口。 **系统能力**:SystemCapability.FileManagement.PhotoAccessHelper.Core **需要权限:** ohos.permission.WRITE_IMAGEVIDEO **参数:** | 参数名 | 类型 | 必填 | 说明 | | -------- |----------------------------------------------------------------------| ---- | ------------------------- | | tokenId | number | 是 | 应用标识,将访问权限授予给tokenId标识的应用。 | | uriList | Array<string> | 是 | 媒体资源的uri列表,uri列表中的资源的访问权限将授予给应用。uri列表最多容纳 1000 条uri。| | photoPermissionType | [PhotoPermissionType](#photopermissiontype12) | 是 | 权限类型,将photoPermissionType表示的权限授予给应用。权限的覆盖规则参考枚举类。| | hideSensitiveType | [HideSensitiveType](#hidesensitivetype12) | 是 | 脱敏类型,预留参数,目前可传枚举类中任一值。| **返回值:** | 类型 | 说明 | | --------------------------------------- | ----------------- | | Promise<number> | Promise对象,0: 授权成功。 -1:授权失败。| **错误码:** 接口抛出错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)和[文件管理错误码](../apis-core-file-kit/errorcode-filemanagement.md)。 | 错误码ID | 错误信息 | | -------- | ---------------------------------------- | | 201 | Permission denied. | | 202 | Called by non-system application. | | 13900020 | Invalid argument. Possible causes: 1. Incorrect uri format; 2. The value of photoPermissionType or hideSensitiveType is out of range. | | 14000011 | Internal system error. | **示例:** phAccessHelper的创建请参考[@ohos.file.photoAccessHelper (相册管理模块)](arkts-apis-photoAccessHelper-f.md)的示例使用。 ```ts async function example(phAccessHelper: photoAccessHelper.PhotoAccessHelper) { console.info('grantPhotoUrisPermissionDemo'); try { // 媒体资源的uri列表。 let uris: Array = [ 'file://media/Photo/11/IMG_datetime_0001/displayName1.jpg', 'file://media/Photo/22/IMG_datetime_0002/displayName2.jpg']; let tokenId = 502334412; let result = await phAccessHelper.grantPhotoUrisPermission(tokenId, uris, photoAccessHelper.PhotoPermissionType.TEMPORARY_READ_IMAGEVIDEO, photoAccessHelper.HideSensitiveType.HIDE_LOCATION_AND_SHOOTING_PARAM); console.info('grantPhotoUrisPermission success, result=' + result); } catch (err) { console.error('grantPhotoUrisPermission failed, error=' + err); } } ``` ### cancelPhotoUriPermission19+ cancelPhotoUriPermission(tokenId: number, uri: string, photoPermissionType: PhotoPermissionType): Promise<number> 取消应用对uri的访问权限,使用Promise方式返回结果。 **系统接口**:此接口为系统接口。 **系统能力**:SystemCapability.FileManagement.PhotoAccessHelper.Core **需要权限:** ohos.permission.WRITE_IMAGEVIDEO **参数:** | 参数名 | 类型 | 必填 | 说明 | | -------- |----------------------------------------------------------------------| ---- | ------------------------- | | tokenId | number | 是 | 应用标识,将取消tokenId标识应用对媒体资源的访问权限。 | | uri | string | 是 | 媒体资源的uri,取消应用对uri表示的资源的访问权限。| | photoPermissionType | [PhotoPermissionType](#photopermissiontype12) | 是 | 权限类型,取消应用对媒体资源的访问权限为photoPermissionType。| **返回值:** | 类型 | 说明 | | --------------------------------------- | ----------------- | | Promise<number> | Promise对象,0:取消成功。-1:取消失败。| **错误码:** 接口抛出错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)和[文件管理错误码](../apis-core-file-kit/errorcode-filemanagement.md)。 | 错误码ID | 错误信息 | | -------- | ---------------------------------------- | | 201 | Permission denied. | | 202 | Called by non-system application. | | 13900020 | Invalid argument. Possible causes: 1. Incorrect uri format; 2. The value of photoPermissionType or hideSensitiveType is out of range. | | 14000011 | Internal system error. | **示例:** phAccessHelper的创建请参考[@ohos.file.photoAccessHelper (相册管理模块)](arkts-apis-photoAccessHelper-f.md)的示例使用。 ```ts async function example(phAccessHelper: photoAccessHelper.PhotoAccessHelper) { console.info('cancelPhotoUriPermissionDemo'); try { let tokenId = 502334412; let result = await phAccessHelper.cancelPhotoUriPermission(tokenId, 'file://media/Photo/11/IMG_datetime_0001/displayName.jpg', photoAccessHelper.PhotoPermissionType.TEMPORARY_READ_IMAGEVIDEO); console.info('cancelPhotoUriPermission success, result=' + result); } catch (err) { console.error('cancelPhotoUriPermission failed, error=' + err); } } ``` ### startThumbnailCreationTask13+ startThumbnailCreationTask(predicate: dataSharePredicates.DataSharePredicates, callback: AsyncCallback\): number 按指定规则生成缩略图。 **系统接口**:此接口为系统接口。 **系统能力**: SystemCapability.FileManagement.PhotoAccessHelper.Core **需要权限:** ohos.permission.READ_IMAGEVIDEO **参数:** | 参数名 | 类型 | 必填 | 说明 | | --------- | --------------------------------------- | ---- | --------------- | | predicates | [dataSharePredicates.DataSharePredicates](../apis-arkdata/js-apis-data-dataSharePredicates.md#datasharepredicates) | 是 | 生成缩略图选项。 | | callback | AsyncCallback<void> | 是 | 回调函数。当成功时标识通知任务结束,err为undefined,否则为错误对象。| **返回值:** | 类型 | 说明 | | --------------------- | -------------------- | | Promise<number> | 返回缩略图生成任务id。 | **错误码:** 以下错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)和[文件管理错误码](../apis-core-file-kit/errorcode-filemanagement.md)。 | 错误码ID | 错误信息 | | -------- | ---------------------------------------- | | 201 | Permission denied. | | 202 | Called by non-system application. | | 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameters types; 3. Parameter verification failed. | | 14000011 | Internal system error. | **示例:** phAccessHelper的创建请参考[@ohos.file.photoAccessHelper (相册管理模块)](arkts-apis-photoAccessHelper-f.md)的示例使用。 ```ts import { dataSharePredicates } from '@kit.ArkData' function testCallBack() { } async function example(phAccessHelper: photoAccessHelper.PhotoAccessHelper) { let predicates: dataSharePredicates.DataSharePredicates = new dataSharePredicates.DataSharePredicates(); try { console.info('startThumbnailCreationTask test start'); phAccessHelper.startThumbnailCreationTask(predicates, testCallBack); } catch (err) { console.error(`startThumbnailCreationTask failed, error: ${err.code}, ${err.message}`); } } ``` ### stopThumbnailCreationTask13+ stopThumbnailCreationTask(taskId: number): void 停止生成缩略图。 **系统接口**:此接口为系统接口。 **系统能力**: SystemCapability.FileManagement.PhotoAccessHelper.Core **需要权限:** ohos.permission.READ_IMAGEVIDEO **参数:** | 参数名 | 类型 | 必填 | 说明 | | ----- | ------ | ---- | ------------------------ | | taskId | number | 是 | 需要停止的缩略图生成任务id。 | **错误码:** 以下错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)和[文件管理错误码](../apis-core-file-kit/errorcode-filemanagement.md)。 | 错误码ID | 错误信息 | | -------- | ---------------------------------------- | | 201 | Permission denied. | | 202 | Called by non-system application. | | 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameters types; 3. Parameter verification failed. | | 14000011 | Internal system error. | **示例:** phAccessHelper的创建请参考[@ohos.file.photoAccessHelper (相册管理模块)](arkts-apis-photoAccessHelper-f.md)的示例使用。 ```ts async function example(phAccessHelper: photoAccessHelper.PhotoAccessHelper) { try { console.info('stopThumbnailCreationTask test start'); let taskId: number = 75983; phAccessHelper.stopThumbnailCreationTask(taskId); } catch (err) { console.error(`stopThumbnailCreationTask failed, error: ${err.code}, ${err.message}`); } } ``` ### getIndexConstructProgress12+ getIndexConstructProgress(): Promise<string> 获取索引构建进度。使用Promise异步回调。 **系统接口**:此接口为系统接口。 **系统能力**:SystemCapability.FileManagement.PhotoAccessHelper.Core **需要权限**:ohos.permission.READ_IMAGEVIDEO **返回值:** | 类型 | 说明 | | --------------------------- | -------------- | | Promise<string> | Promise对象,返回一个json格式的字符串。表示已完成智慧分析的图片数量、总数和已经完成智慧分析的视频数量、总数。 | **错误码:** 以下错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)和[文件管理错误码](../apis-core-file-kit/errorcode-filemanagement.md)。 | 错误码ID | 错误信息 | | -------- | ---------------------------------------- | | 201 | Permission denied. | | 202 | Called by non-system application. | | 14000011 | Internal system error. | **示例:** phAccessHelper的创建请参考[photoAccessHelper.getPhotoAccessHelper](arkts-apis-photoAccessHelper-f.md#photoaccesshelpergetphotoaccesshelper)的示例使用。 ```ts async function example(phAccessHelper: photoAccessHelper.PhotoAccessHelper) { class indexProgress { finishedImageCount: number = 0; totalImageCount: number = 0; finishedVideoCount: number = 0; totalVideoCount: number = 0; } try { console.info('getIndexConstructProgress test start'); let result: string = await phAccessHelper.getIndexConstructProgress(); console.info('getIndexProgress:' + result); let jsonObj: indexProgress = JSON.parse(result); // ...使用获取到的索引构建进度数据。 } catch (err) { console.error(`getIndexConstructProgress failed, error: ${err.code}, ${err.message}`); } } ``` ### getDataAnalysisProgress12+ getDataAnalysisProgress(analysisType: AnalysisType): Promise<string> 获取资产的分析进度。使用Promise异步回调。 **系统接口**:此接口为系统接口。 **系统能力**:SystemCapability.FileManagement.PhotoAccessHelper.Core **需要权限**:ohos.permission.READ_IMAGEVIDEO **参数:** | 参数名 | 类型 | 必填 | 说明 | | ---- | -------------- | ---- | ----- | | analysisType | [AnalysisType](#analysistype11) | 是 | 需要获取的智慧分析类型。 | **返回值:** | 类型 | 说明 | | --------------------------- | -------------- | | Promise<string> | Promise对象,返回一个json格式的字符串。表示资产分析的进度。 | **错误码:** 以下错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)和[文件管理错误码](../apis-core-file-kit/errorcode-filemanagement.md)。 | 错误码ID | 错误信息 | | -------- | ---------------------------------------- | | 201 | Permission denied. | | 202 | Called by non-system application. | | 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types; 3. Parameter verification failed. | | 14000011 | Internal system error. | **示例:** phAccessHelper的创建请参考[photoAccessHelper.getPhotoAccessHelper](arkts-apis-photoAccessHelper-f.md#photoaccesshelpergetphotoaccesshelper)的示例使用。 ```ts async function example(phAccessHelper: photoAccessHelper.PhotoAccessHelper) { try { console.info('getDataAnalysisProgress test start'); let result: string = await phAccessHelper.getDataAnalysisProgress(photoAccessHelper.AnalysisType.ANALYSIS_FACE); console.info('getDataAnalysisProgress:' + result); } catch (err) { console.error(`getDataAnalysisProgress failed, error: ${err.code}, ${err.message}`); } } ``` ### getSharedPhotoAssets13+ getSharedPhotoAssets(options: FetchOptions): Array\ 获取共享的照片资产。 **系统接口**:此接口为系统接口。 **系统能力**: SystemCapability.FileManagement.PhotoAccessHelper.Core **需要权限:** ohos.permission.ACCESS_MEDIALIB_THUMB_DB **参数:** | 参数名 | 类型 | 必填 | 说明 | | --------- | ------------ | ---- | ------- | | options | [FetchOptions](arkts-apis-photoAccessHelper-i.md#fetchoptions) | 是 | 获取共享的照片资产选项。 | **返回值:** | 类型 | 说明 | | ----------------------- | ------------------ | | Array\<[SharedPhotoAsset](#sharedphotoasset13)\> | 返回共享的照片资产。 | **错误码:** 以下错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)和[文件管理错误码](../apis-core-file-kit/errorcode-filemanagement.md)。 | 错误码ID | 错误信息 | | -------- | ---------------------------------------- | | 201 | Permission denied. | | 202 | Called by non-system application. | | 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameters types; 3. Parameter verification failed. | | 14000011 | Internal system error. | **示例:** phAccessHelper的创建请参考[@ohos.file.photoAccessHelper (相册管理模块)](arkts-apis-photoAccessHelper-f.md)的示例使用。 ```ts import { dataSharePredicates } from '@kit.ArkData' async function example(phAccessHelper: photoAccessHelper.PhotoAccessHelper) { let predicates: dataSharePredicates.DataSharePredicates = new dataSharePredicates.DataSharePredicates(); let fetchOptions: photoAccessHelper.FetchOptions = { fetchColumns: [], predicates: predicates }; try { console.info('getSharedPhotoAssets test start'); phAccessHelper.getSharedPhotoAssets(fetchOptions); console.info('getSharedPhotoAssets test end'); } catch (err) { console.error(`getSharedPhotoAssets failed, error: ${err.code}, ${err.message}`); } } ``` ### startAssetAnalysis18+ startAssetAnalysis(type: AnalysisType, assetUris?: Array<string>): Promise<number> 启动资产分析服务。 **系统接口**:此接口为系统接口。 **系统能力**:SystemCapability.FileManagement.PhotoAccessHelper.Core **需要权限:** ohos.permission.WRITE_IMAGEVIDEO **参数:** | 参数名 | 类型 | 必填 | 说明 | | --------- | ------------------- | ---- | ------------------------------------------------------------ | | type | [AnalysisType](#analysistype11) | 是 | 需要启动的智慧分析类型。 | | assetUris | Array<string> | 否 | 资产uri的数组。
- 填写:仅分析指定资产。
- 不填:全量分析。 | **返回值:** | 类型 | 说明 | | --------------------- | --------------------------- | | Promise<number> | Promise对象。服务的任务id。 | **错误码:** 以下错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)。 | 错误码ID | 错误信息 | | -------- | ------------------------------------------------------------ | | 201 | Permission denied. | | 202 | Called by non-system application. | | 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameters types; 3. Parameter verification failed. | **示例:** phAccessHelper的创建请参考[@ohos.file.photoAccessHelper (相册管理模块)](arkts-apis-photoAccessHelper-f.md)的示例使用。 ```ts async function example(context: Context) { console.info('startAssetAnalysisDemo'); try { let phAccessHelper = photoAccessHelper.getPhotoAccessHelper(context); let uris = ["file://media/Photo/14/IMG_1729066473_013/IMG_20241016_122253.jpg", "file://media/Photo/68/IMG_1729033213_018/IMG_20241016_100082.jpg"]; let taskId = await phAccessHelper.startAssetAnalysis(photoAccessHelper.AnalysisType.ANALYSIS_SEARCH_INDEX, uris); console.info('startAssetAnalysis success, taskId=' + taskId); } catch (err) { console.error('startAssetAnalysis failed, error=' + err); } } ``` ### createAssetsForAppWithMode12+ createAssetsForAppWithMode(boundleName: string, appName: string, appId: string, tokenId: number, authorizationMode: AuthorizationMode, photoCreationConfigs:Array\): Promise\> 提供给应用保存短时授权,使用Promise方式返回结果。 **系统接口**:此接口为系统接口。 **系统能力**:SystemCapability.FileManagement.PhotoAccessHelper.Core **需要权限:** ohos.permission.WRITE_IMAGEVIDEO **参数:** | 参数名 | 类型 | 必填 | 说明 | | -------- |----------------------------------------------------------------------| ---- | ------------------------- | | boundleName| string | 是 | 需要保存图片/视频文件的应用boundleName。 | | appName| string | 是 | 需要保存图片/视频文件的应用appName。| | appId| string | 是 | 需要保存图片/视频文件的应用app id。 | | tokenId| number| 是 | 需要短时授权应用的唯一标识。 | | authorizationMode| [AuthorizationMode](#authorizationmode12)| 是 | 授权模式。授予应用短期内再次保存无需重复弹框确认。 | | PhotoCreationConfig| Array\<[PhotoCreationConfig](arkts-apis-photoAccessHelper-i.md#photocreationconfig12)> | 是 | 保存图片/视频到媒体库的配置。| **返回值:** | 类型 | 说明 | | --------------------------------------- | ----------------- | | Promise\> | Promise对象,返回给接口调用方的媒体库文件uri列表。Uri已对appId对应的应用授权,支持应用写入数据。如果生成uri异常,则返回批量创建错误码。
返回-3006表不允许出现非法字符;返回-2004表示图片类型和后缀不符;返回-203表示文件操作异常。| **错误码:** 接口抛出错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)和[文件管理错误码](../apis-core-file-kit/errorcode-filemanagement.md)。 | 错误码ID | 错误信息 | | -------- | ---------------------------------------- | | 201 | Permission denied. | | 202 | Called by non-system application. | | 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameters types; 3. Parameter verification failed. | | 14000011 | Internal system error. | **示例:** phAccessHelper的创建请参考[@ohos.file.photoAccessHelper (相册管理模块)](arkts-apis-photoAccessHelper-f.md)的示例使用。 ```ts async function example(phAccessHelper: photoAccessHelper.PhotoAccessHelper) { console.info('createAssetsForAppWithModeDemo.'); try { let photoCreationConfigs: Array = [ { title: '123456', fileNameExtension: 'jpg', photoType: photoAccessHelper.PhotoType.IMAGE, subtype: photoAccessHelper.PhotoSubtype.DEFAULT, } ]; let bundleName: string = 'testBundleName'; let appName: string = 'testAppName'; let appId: string = 'testAppId'; let tokenId: number = 537197950; let authorizationMode: photoAccessHelper.AuthorizationMode = photoAccessHelper.AuthorizationMode.SHORT_TIME_AUTHORIZATION; let result: Array = await phAccessHelper.createAssetsForAppWithMode(bundleName, appName, appId, tokenId, authorizationMode, photoCreationConfigs); console.info(`result: ${JSON.stringify(result)}`); console.info('Photo createAssetsForAppWithMode success.'); } catch (err) { console.error(`createAssetsForAppWithMode failed with error: ${err.code}, ${err.message}`); } } ``` ### getKeyFrameThumbnail18+ getKeyFrameThumbnail(beginFrameTimeMs: number, type: ThumbnailType): Promise 获取视频中关键视频帧位置的指定类型缩略图,使用promise方式返回异步结果。 **系统接口**:此接口为系统接口。 **系统能力**:SystemCapability.FileManagement.PhotoAccessHelper.Core **需要权限**:ohos.permission.READ_IMAGEVIDEO **参数:** | 参数名 | 类型 | 必填 | 说明 | | ---- | -------------- | ---- | ----- | | beginFrameTimeMs | number | 是 | 获取视频帧的时间位置,单位ms,0:封面帧。 | | type | [ThumbnailType](#thumbnailtype13)| 是 | 缩略图类型。 | **返回值:** | 类型 | 说明 | | ----------------------------- | --------------------- | | Promise<[image.PixelMap](../apis-image-kit/arkts-apis-image-PixelMap.md)> | Promise对象,返回缩略图的PixelMap。若获取不到,默认返回封面帧 | **错误码:** 接口抛出错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)和[文件管理错误码](../apis-core-file-kit/errorcode-filemanagement.md)。 | 错误码ID | 错误信息 | | -------- | ---------------------------------------- | | 201 | Permission denied. | | 202 | Called by non-system application. | | 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types; 3. Parameter verification failed. | | 14000011 | Internal system error. **示例:** phAccessHelper的创建请参考[@ohos.file.photoAccessHelper (相册管理模块)](arkts-apis-photoAccessHelper-f.md)的示例使用。 ```ts import { common } from '@kit.AbilityKit'; import { dataSharePredicates } from '@kit.ArkData'; import { image } from '@kit.ImageKit'; async function example(context: Context) { try{ console.info('getKeyFrameThumbnail demo'); let phAccessHelper:photoAccessHelper.PhotoAccessHelper = photoAccessHelper.getPhotoAccessHelper(context); let predicates: dataSharePredicates.DataSharePredicates = new dataSharePredicates.DataSharePredicates(); predicates.equalTo(photoAccessHelper.PhotoKeys.PHOTO_TYPE, photoAccessHelper.PhotoType.VIDEO); let fetchOption: photoAccessHelper.FetchOptions = { fetchColumns: [], predicates: predicates }; let fetchResult: photoAccessHelper.FetchResult = await phAccessHelper.getAssets(fetchOption); let asset: photoAccessHelper.PhotoAsset = await fetchResult.getLastObject(); let pixelMap: image.PixelMap = await asset.getKeyFrameThumbnail(0, photoAccessHelper.ThumbnailType.LCD); console.info('getKeyFrameThumbnail success'); } catch (error) { console.error('getKeyFrameThumbnail failed, error: ' + JSON.stringify(error)); } } ``` ### saveGalleryFormInfo18+ saveGalleryFormInfo(info:GalleryFormInfo):Promise<void> 将图库卡片相关信息保存到数据库中,使用Promise方式返回结果。 **系统接口**:此接口为系统接口。 **需要权限**:ohos.permission.WRITE_IMAGEVIDEO **系统能力**:SystemCapability.FileManagement.PhotoAccessHelper.Core **参数:** | 参数名 | 类型 | 必填 | 说明 | | -------- | ------------------------ | ---- | ------------------------- | | info | [GalleryFormInfo](#galleryforminfo18) | 是 | 图库卡片信息,包括图库卡片的id、卡片绑定的图片或相册的uri集合。 | **返回值:** | 类型 | 说明 | | --------------------------------------- | ----------------- | | Promise<void>| Promise对象,返回void。 | **错误码:** 以下错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)和[文件管理错误码](../apis-core-file-kit/errorcode-filemanagement.md)。 | 错误码ID | 错误信息 | | -------- | ---------------------------------------- | | 201 | Permission verification failed, usually the result returned by VerifyAccessToken. | | 202 | Permission verification failed, application which is not a system application uses system API. | | 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types; 3. Parameter verification failed. | | 14000011 | System inner fail. | **示例:** ```ts import { dataSharePredicates } from '@kit.ArkData'; import { BusinessError } from '@kit.BasicServicesKit'; async function example(phAccessHelper: photoAccessHelper.PhotoAccessHelper) { console.info('saveGalleryFormInfoDemo'); let predicates: dataSharePredicates.DataSharePredicates = new dataSharePredicates.DataSharePredicates(); let fetchOptions: photoAccessHelper.FetchOptions = { fetchColumns: [], predicates: predicates }; let fetchResult: photoAccessHelper.FetchResult = await phAccessHelper.getAssets(fetchOptions); let photoAsset: photoAccessHelper.PhotoAsset = await fetchResult.getFirstObject(); let uriList: Array = [ photoAsset.uri, ]; let info: photoAccessHelper.GalleryFormInfo = { // formId是一个由纯数字组成的字符串,assetUris为图库中存在的图片或者相册的uri信息集合。 formId: "20230116123", assetUris: uriList, } phAccessHelper.saveGalleryFormInfo(info).then(() => { console.info('saveGalleryFormInfo successfully'); }).catch((err: BusinessError) => { console.error(`saveGalleryFormInfo failed with error: ${err.code}, ${err.message}`); }); } ``` ### updateGalleryFormInfo18+ updateGalleryFormInfo(info:GalleryFormInfo):Promise<void> 更新既存的图库卡片的相关信息,并保存到数据库中,使用Promise方式返回结果。 **系统接口**:此接口为系统接口。 **需要权限**:ohos.permission.WRITE_IMAGEVIDEO **系统能力**:SystemCapability.FileManagement.PhotoAccessHelper.Core **参数:** | 参数名 | 类型 | 必填 | 说明 | | -------- | ------------------------ | ---- | ------------------------- | | info | [GalleryFormInfo](#galleryforminfo18) | 是 | 图库卡片信息,包括图库卡片的id、卡片绑定的图片或相册的uri集合。 | **返回值:** | 类型 | 说明 | | --------------------------------------- | ----------------- | | Promise<void>| Promise对象,返回void。 | **错误码:** 以下错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)和[文件管理错误码](../apis-core-file-kit/errorcode-filemanagement.md)。 | 错误码ID | 错误信息 | | -------- | ---------------------------------------- | | 201 | Permission verification failed, usually the result returned by VerifyAccessToken. | | 202 | Permission verification failed, application which is not a system application uses system API. | | 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types; 3. Parameter verification failed. | | 14000011 | System inner fail. | **示例:** ```ts import { dataSharePredicates } from '@kit.ArkData'; import { BusinessError } from '@kit.BasicServicesKit'; async function example(phAccessHelper: photoAccessHelper.PhotoAccessHelper) { console.info('updateGalleryFormInfoDemo'); let predicates: dataSharePredicates.DataSharePredicates = new dataSharePredicates.DataSharePredicates(); let fetchOptions: photoAccessHelper.FetchOptions = { fetchColumns: [], predicates: predicates }; let fetchResult: photoAccessHelper.FetchResult = await phAccessHelper.getAssets(fetchOptions); let photoAsset: photoAccessHelper.PhotoAsset = await fetchResult.getFirstObject(); let photoAssetLast: photoAccessHelper.PhotoAsset = await fetchResult.getLastObject(); let uriList: Array = [ photoAsset.uri, photoAssetLast.uri ]; let info: photoAccessHelper.GalleryFormInfo = { // formId是一个由纯数字组成的字符串,assetUris为图库中存在的图片或者相册的uri信息集合。 formId: "20230116123", assetUris: uriList, } phAccessHelper.updateGalleryFormInfo(info).then(() => { console.info('updateGalleryFormInfo successfully'); }).catch((err: BusinessError) => { console.error(`updateGalleryFormInfo failed with error: ${err.code}, ${err.message}`); }); } ``` ### removeGalleryFormInfo18+ removeGalleryFormInfo(info:GalleryFormInfo):Promise<void> 从数据库中删除图库卡片信息,使用Promise方式返回结果。 **系统接口**:此接口为系统接口。 **需要权限**:ohos.permission.WRITE_IMAGEVIDEO **系统能力**:SystemCapability.FileManagement.PhotoAccessHelper.Core **参数:** | 参数名 | 类型 | 必填 | 说明 | | -------- | ------------------------ | ---- | ------------------------- | | info | [GalleryFormInfo](#galleryforminfo18) | 是 | 图库卡片信息,包括图库卡片的id、卡片绑定的图片或相册的uri集合。 | **返回值:** | 类型 | 说明 | | --------------------------------------- | ----------------- | | Promise<void>| Promise对象,返回void。 | **错误码:** 以下错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)和[文件管理错误码](../apis-core-file-kit/errorcode-filemanagement.md)。 | 错误码ID | 错误信息 | | -------- | ---------------------------------------- | | 201 | Permission verification failed, usually the result returned by VerifyAccessToken. | | 202 | Permission verification failed, application which is not a system application uses system API. | | 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types; 3. Parameter verification failed. | | 14000011 | System inner fail. | **示例:** ```ts import { BusinessError } from '@kit.BasicServicesKit'; async function example(phAccessHelper: photoAccessHelper.PhotoAccessHelper) { console.info('removeGalleryFormInfoDemo'); let info: photoAccessHelper.GalleryFormInfo = { // formId是一个由纯数字组成的字符串,移除卡片时assertUris不填。 formId: "20230116123" } phAccessHelper.removeGalleryFormInfo(info).then(() => { console.info('removeGalleryFormInfo successfully'); }).catch((err: BusinessError) => { console.error(`removeGalleryFormInfo failed with error: ${err.code}, ${err.message}`); }); } ``` ### getAlbumsByIds18+ getAlbumsByIds(albumIds: Array<number>): Promise<Map<number, Album>> 通过相册id查询相册信息。使用Promise异步回调。 **系统接口**:此接口为系统接口。 **系统能力**:SystemCapability.FileManagement.PhotoAccessHelper.Core **需要权限:** ohos.permission.READ_IMAGEVIDEO **参数:** | 参数名 | 类型 | 必填 | 说明 | | --------- | ------------------- | ---- | ------------------------------------------------------------ | | albumIds | Array<number> | 是 | 相册id列表。 | **返回值:** | 类型 | 说明 | | --------------------- | --------------------------- | | Promise<Map<number, Album>> | Promise对象。返回相册信息map对象。 | **错误码:** 以下错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)和[文件管理错误码](../apis-core-file-kit/errorcode-filemanagement.md)。 | 错误码ID | 错误信息 | | -------- | ------------------------------------------------------------ | | 201 | Permission denied. | | 202 | Called by non-system application. | | 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameters types; 3. Parameter verification failed. | | 14000011 | Internal system error. | **示例:** phAccessHelper的创建请参考[@ohos.file.photoAccessHelper (相册管理模块)](arkts-apis-photoAccessHelper-f.md)的示例使用。 ```ts async function example(phAccessHelper: photoAccessHelper.PhotoAccessHelper) { console.info('startGetAlbumsByIdsDemo'); try { // 获取需要保存到媒体库的位于应用沙箱的图片/视频uri。 let albumIds: Array = [ 12 // 实际场景请使用albumId ]; let map: Map = await phAccessHelper.getAlbumsByIds(albumIds); console.info('getAlbumsByIds success, size is ' + map.size); } catch (err) { console.error('getAlbumsByIds failed, errCode is ' + err.code + ', errMsg is ' + err.message); } } ``` ### createAssetsForAppWithAlbum18+ createAssetsForAppWithAlbum(source: PhotoCreationSource, albumUri: string, isAuthorized: boolean, photoCreationConfigs: Array<PhotoCreationConfig>): Promise<Array<string>> 为应用自己或者其他应用创建资产到指定来源或者用户相册。使用Promise异步回调。 **系统接口**:此接口为系统接口。 **系统能力**:SystemCapability.FileManagement.PhotoAccessHelper.Core **需要权限:** ohos.permission.WRITE_IMAGEVIDEO **参数:** | 参数名 | 类型 | 必填 | 说明 | | --------- | ------------------- | ---- | ------------------------------------------------------------ | | source | [PhotoCreationSource](#photocreationsource18) | 是 | 代替应用创建资产传入的应用信息。 | | albumUri | string | 是 | 相册uri。 | | isAuthorized | boolean | 是 | 是否授权其他应用。true表示授权,false表示不授权。 | | PhotoCreationConfigs| Array\<[PhotoCreationConfig](arkts-apis-photoAccessHelper-i.md#photocreationconfig12)> | 是 | 保存图片/视频到媒体库的配置。| **返回值:** | 类型 | 说明 | | --------------------- | --------------------------- | | Promise<Array<string>> | Promise对象,返回接口调用方的媒体库文件uri列表。
uri已对appId对应的应用授权,支持应用写入数据。如果生成uri异常,则返回批量创建错误码。
返回-3006表示不允许出现非法字符;返回-2004表示图片类型和后缀不符;返回-203表示文件操作异常。 | **错误码:** 以下错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)和[文件管理错误码](../apis-core-file-kit/errorcode-filemanagement.md)。 | 错误码ID | 错误信息 | | -------- | ------------------------------------------------------------ | | 201 | Permission denied. | | 202 | Called by non-system application. | | 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameters types; 3. Parameter verification failed. | | 14000011 | Internal system error. | **示例:** phAccessHelper的创建请参考[@ohos.file.photoAccessHelper (相册管理模块)](arkts-apis-photoAccessHelper-f.md)的示例使用。 ```ts async function example(phAccessHelper: photoAccessHelper.PhotoAccessHelper) { console.info('createAssetsForAppWithAlbumDemo.'); try { let source: photoAccessHelper.PhotoCreationSource = { bundleName: 'testBundleName', appName: 'testAppName', appId: 'testAppId', tokenId: 537197950, } let albumUri: string = 'file://media/PhotoAlbum/10'; let isAuthorized: boolean = true; let photoCreationConfigs: Array = [ { title: 'test', fileNameExtension: 'jpg', photoType: photoAccessHelper.PhotoType.IMAGE, subtype: photoAccessHelper.PhotoSubtype.DEFAULT, } ]; let desFileUris: Array = await phAccessHelper.createAssetsForAppWithAlbum(source, albumUri, isAuthorized, photoCreationConfigs); console.info('createAssetsForAppWithAlbum success, data is ' + desFileUris); } catch (err) { console.error(`createAssetsForAppWithAlbum failed with error: ${err.code}, ${err.message}`); } } ``` ### on('hiddenPhotoChange')20+ on(type: 'hiddenPhotoChange', callback: Callback<PhotoAssetChangeInfos>): void 注册'hiddenPhotoChange'监听隐藏的媒体资产,并通过callback方式返回隐藏资产变化结果,可以注册多个callback。 **系统接口**:此接口为系统接口。 **系统能力**:SystemCapability.FileManagement.PhotoAccessHelper.Core **需要权限**:ohos.permission.READ_IMAGEVIDEO 和 ohos.permission.MANAGE_PRIVATE_PHOTOS **参数:** | 参数名 | 类型 | 必填 | 说明 | |-----------|-------------------------|-----------|-----------------| | type | string | 是 | 注册监听隐藏资产,取值为'hiddenPhotoChange'。注册完成后,有隐藏资产发生变化时,通过callback返回变更信息。 | | callback | Callback<[PhotoAssetChangeInfos](arkts-apis-photoAccessHelper-i.md#photoassetchangeinfos20)> | 是 | 返回变更的隐藏媒体资产信息[PhotoAssetChangeInfos](arkts-apis-photoAccessHelper-i.md#photoassetchangeinfos20)。
**注意:** 该接口可以注册多个不同的callback监听,[off('hiddenPhotoChange')](#offhiddenphotochange20)即可以关闭所有监听,也可以关闭指定callback监听。 | **错误码:** 以下错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)和[媒体库错误码](errcode-medialibrary.md)。 | 错误码ID | 错误信息 | | -------- | ---------------------------------------- | | 201 | Permission denied. | | 202 | Called by non-system application. | | 23800151 | The scenario parameter verification fails.
Possible causes: 1. The type is not fixed at 'hiddenPhotoChange'; 2. The same callback is registered repeatedly. | | 23800301 | Internal system error. You are advised to retry and check the logs.
Possible causes: 1. The database is corrupted. 2. The file system is abnormal. 3. The IPC request timed out. | **示例:** phAccessHelper的创建请参考[@ohos.file.photoAccessHelper (相册管理模块)](arkts-apis-photoAccessHelper-f.md)的示例使用。 ```ts import { dataSharePredicates } from '@kit.ArkData' let onCallback1 = (changeData: photoAccessHelper.PhotoAssetChangeInfos) => { console.info('onCallback1 success, changData: ' + JSON.stringify(changeData)); // file had changed, do something. } let onCallback2 = (changeData: photoAccessHelper.PhotoAssetChangeInfos) => { console.info('onCallback2 success, changData: ' + JSON.stringify(changeData)); // file had changed, do something. } async function example(phAccessHelper: photoAccessHelper.PhotoAccessHelper){ console.info('onHiddenPhotoChangeDemo.'); try { // 注册onCallback1监听。 phAccessHelper.on('hiddenPhotoChange', onCallback1); // 注册onCallback2监听。 phAccessHelper.on('hiddenPhotoChange', onCallback2); } catch (error) { console.error('onHiddenPhotoChange failed, errCode is', error); } } ``` ### off('hiddenPhotoChange')20+ off(type: 'hiddenPhotoChange', callback?: Callback<PhotoAssetChangeInfos>): void 取消对'hiddenPhotoChange'隐藏资产的监听。存在多个callback监听时,可以取消指定注册的callback监听;不指定callback时取消所有监听。 **系统接口**:此接口为系统接口。 **系统能力**:SystemCapability.FileManagement.PhotoAccessHelper.Core **需要权限**:ohos.permission.READ_IMAGEVIDEO 和 ohos.permission.MANAGE_PRIVATE_PHOTOS **参数:** | 参数名 | 类型 | 必填 | 说明 | |-----------|-------------------------|-----------|-----------------| | type | string | 是 | 取消监听隐藏资产,取值为'hiddenPhotoChange'。取消监听后,有隐藏资产发生变化时,不再通过callback返回变更信息。 | | callback | Callback<[PhotoAssetChangeInfos](arkts-apis-photoAccessHelper-i.md#photoassetchangeinfos20)> | 否 | 取消[on('hiddenPhotoChange')](#onhiddenphotochange20)注册时指定的callback监听;不填时,则取消对'hiddenPhotoChange'的所有监听。
**注意:** 取消注册的callback后,有隐藏资产发生变化时,不会进入此回调。 | **错误码:** 以下错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)和[媒体库错误码](errcode-medialibrary.md)。 | 错误码ID | 错误信息 | | -------- | ---------------------------------------- | | 201 | Permission denied. | | 202 | Called by non-system application. | | 23800151 | The scenario parameter verification fails.
Possible causes: 1. The type is not fixed at 'hiddenPhotoChange'; 2. The same callback is unregistered repeatedly. | | 23800301 | Internal system error. You are advised to retry and check the logs.
Possible causes: 1. The database is corrupted. 2. The file system is abnormal. 3. The IPC request timed out. | **示例:** phAccessHelper的创建请参考[@ohos.file.photoAccessHelper (相册管理模块)](arkts-apis-photoAccessHelper-f.md)的示例使用。 ```ts import { dataSharePredicates } from '@kit.ArkData' let onCallback1 = (changeData: photoAccessHelper.PhotoAssetChangeInfos) => { console.info('onCallback1 success, changData: ' + JSON.stringify(changeData)); // file had changed, do something. } let onCallback2 = (changeData: photoAccessHelper.PhotoAssetChangeInfos) => { console.info('onCallback2 success, changData: ' + JSON.stringify(changeData)); // file had changed, do something. } async function example(phAccessHelper: photoAccessHelper.PhotoAccessHelper){ console.info('offHiddenPhotoChangeDemo.'); try { // 注册onCallback1监听。 phAccessHelper.on('hiddenPhotoChange', onCallback1); // 注册onCallback2监听。 phAccessHelper.on('hiddenPhotoChange', onCallback2); // 关闭onCallback1监听,onCallback2继续监听。 phAccessHelper.off('hiddenPhotoChange', onCallback1); } catch (error) { console.error('offHiddenPhotoChange failed, errCode is', error); } } ``` ### on('trashedPhotoChange')20+ on(type: 'trashedPhotoChange', callback: Callback<PhotoAssetChangeInfos>): void 注册'trashedPhotoChange'监听回收站的媒体资产,并通过callback方式返回回收站资产变化结果,可以注册多个callback。 **系统接口**:此接口为系统接口。 **系统能力**:SystemCapability.FileManagement.PhotoAccessHelper.Core **需要权限**:ohos.permission.READ_IMAGEVIDEO **参数:** | 参数名 | 类型 | 必填 | 说明 | |-----------|-------------------------|-----------|-----------------| | type | string | 是 | 注册监听回收站资产,取值为'trashedPhotoChange'。注册完成后,有回收站资产发生变化时,通过callback返回变更信息。 | | callback | Callback<[PhotoAssetChangeInfos](arkts-apis-photoAccessHelper-i.md#photoassetchangeinfos20)> | 是 | 返回变更的回收站媒体资产信息[PhotoAssetChangeInfos](arkts-apis-photoAccessHelper-i.md#photoassetchangeinfos20)。
**注意:** 该接口可以注册多个不同的callback监听,[off('trashedPhotoChange')](#offtrashedphotochange20)即可以关闭所有监听,也可以关闭指定callback监听。 | **错误码:** 以下错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)和[媒体库错误码](errcode-medialibrary.md)。 | 错误码ID | 错误信息 | | -------- | ---------------------------------------- | | 201 | Permission denied. | | 202 | Called by non-system application. | | 23800151 | The scenario parameter verification fails.
Possible causes: 1. The type is not fixed at 'trashedPhotoChange'; 2. The same callback is registered repeatedly. | | 23800301 | Internal system error. You are advised to retry and check the logs.
Possible causes: 1. The database is corrupted. 2. The file system is abnormal. 3. The IPC request timed out. | **示例:** phAccessHelper的创建请参考[@ohos.file.photoAccessHelper (相册管理模块)](arkts-apis-photoAccessHelper-f.md)的示例使用。 ```ts import { dataSharePredicates } from '@kit.ArkData' let onCallback1 = (changeData: photoAccessHelper.PhotoAssetChangeInfos) => { console.info('onCallback1 success, changData: ' + JSON.stringify(changeData)); // file had changed, do something. } let onCallback2 = (changeData: photoAccessHelper.PhotoAssetChangeInfos) => { console.info('onCallback2 success, changData: ' + JSON.stringify(changeData)); // file had changed, do something. } async function example(phAccessHelper: photoAccessHelper.PhotoAccessHelper, context: Context){ console.info('onTrashedPhotoChangeDemo.'); try { // 注册onCallback1监听。 phAccessHelper.on('trashedPhotoChange', onCallback1); // 注册onCallback2监听。 phAccessHelper.on('trashedPhotoChange', onCallback2); } catch (error) { console.error('onTrashedPhotoChangeDemo failed, errCode is', error); } } ``` ### off('trashedPhotoChange')20+ off(type: 'trashedPhotoChange', callback?: Callback<PhotoAssetChangeInfos>): void 取消对'trashedPhotoChange'回收站资产的监听。存在多个callback监听时,可以取消指定注册的callback监听;不指定callback时取消所有监听。 **系统接口**:此接口为系统接口。 **系统能力**:SystemCapability.FileManagement.PhotoAccessHelper.Core **需要权限**:ohos.permission.READ_IMAGEVIDEO **参数:** | 参数名 | 类型 | 必填 | 说明 | |-----------|-------------------------|-----------|-----------------| | type | string | 是 | 取消监听回收站资产,取值为'trashedPhotoChange'。取消监听后,有回收站资产发生变化时,不再通过callback返回变更信息。 | | callback | Callback<[PhotoAssetChangeInfos](arkts-apis-photoAccessHelper-i.md#photoassetchangeinfos20)> | 否 | 取消[on('trashedPhotoChange')](#ontrashedphotochange20)注册时指定的callback监听;不填时,则取消对'trashedPhotoChange'的所有监听。
**注意:** 取消注册的callback后,有回收站资产发生变化时,不会进入此回调。 | **错误码:** 以下错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)和[媒体库错误码](errcode-medialibrary.md)。 | 错误码ID | 错误信息 | | -------- | ---------------------------------------- | | 201 | Permission denied. | | 202 | Called by non-system application. | | 23800151 | The scenario parameter verification fails.
Possible causes: 1. The type is not fixed at 'trashedPhotoChange'; 2. The same callback is unregistered repeatedly. | | 23800301 | Internal system error. You are advised to retry and check the logs.
Possible causes: 1. The database is corrupted. 2. The file system is abnormal. 3. The IPC request timed out. | **示例:** phAccessHelper的创建请参考[@ohos.file.photoAccessHelper (相册管理模块)](arkts-apis-photoAccessHelper-f.md)的示例使用。 ```ts import { dataSharePredicates } from '@kit.ArkData' let onCallback1 = (changeData: photoAccessHelper.PhotoAssetChangeInfos) => { console.info('onCallback1 success, changData: ' + JSON.stringify(changeData)); // file had changed, do something. } let onCallback2 = (changeData: photoAccessHelper.PhotoAssetChangeInfos) => { console.info('onCallback2 success, changData: ' + JSON.stringify(changeData)); // file had changed, do something. } async function example(phAccessHelper: photoAccessHelper.PhotoAccessHelper, context: Context){ console.info('offTrashedPhotoChangeDemo.'); try { // 注册onCallback1监听。 phAccessHelper.on('trashedPhotoChange', onCallback1); // 注册onCallback2监听。 phAccessHelper.on('trashedPhotoChange', onCallback2); // 关闭onCallback1监听,onCallback2继续监听。 phAccessHelper.off('trashedPhotoChange', onCallback1); } catch (error) { console.error('offTrashedPhotoChangeDemo failed, errCode is', error); } } ``` ### on('hiddenAlbumChange')20+ on(type: 'hiddenAlbumChange', callback: Callback<AlbumChangeInfos>): void 注册'hiddenAlbumChange'监听隐藏相册,并通过callback方式返回相册变化结果,可以注册多个callback。 **系统接口**:此接口为系统接口。 **系统能力**:SystemCapability.FileManagement.PhotoAccessHelper.Core **需要权限**:ohos.permission.READ_IMAGEVIDEO 和 ohos.permission.MANAGE_PRIVATE_PHOTOS **参数:** | 参数名 | 类型 | 必填 | 说明 | |-----------|-------------------------|-----------|-----------------| | type | string | 是 | 注册监听隐藏相册,取值为'hiddenAlbumChange'。注册完成后,有隐藏相册发生变化时,通过callback返回变更信息。 | | callback | Callback<[AlbumChangeInfos](arkts-apis-photoAccessHelper-i.md#albumchangeinfos20)> | 是 | 返回变更的隐藏相册信息[AlbumChangeInfos](arkts-apis-photoAccessHelper-i.md#albumchangeinfos20)。
**注意:** 该接口可以注册多个不同的callback监听,[off('hiddenAlbumChange')](#offhiddenalbumchange20)即可以关闭所有监听,也可以关闭指定callback监听。 | **错误码:** 以下错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)和[媒体库错误码](errcode-medialibrary.md)。 | 错误码ID | 错误信息 | | -------- | ---------------------------------------- | | 201 | Permission denied. | | 202 | Called by non-system application. | | 23800151 | The scenario parameter verification fails.
Possible causes: 1. The type is not fixed at 'hiddenAlbumChange'; 2. The same callback is registered repeatedly. | | 23800301 | Internal system error. You are advised to retry and check the logs.
Possible causes: 1. The database is corrupted. 2. The file system is abnormal. 3. The IPC request timed out. | **示例:** phAccessHelper的创建请参考[@ohos.file.photoAccessHelper (相册管理模块)](arkts-apis-photoAccessHelper-f.md)的示例使用。 ```ts import { dataSharePredicates } from '@kit.ArkData' let onCallback1 = (changeData: photoAccessHelper.AlbumChangeInfos) => { console.info('onCallback1 success, changData: ' + JSON.stringify(changeData)); // file had changed, do something. } let onCallback2 = (changeData: photoAccessHelper.AlbumChangeInfos) => { console.info('onCallback2 success, changData: ' + JSON.stringify(changeData)); // file had changed, do something. } async function example(phAccessHelper: photoAccessHelper.PhotoAccessHelper){ console.info('onHiddenAlbumChangeDemo.'); try { // 注册onCallback1监听。 phAccessHelper.on('hiddenAlbumChange', onCallback1); // 注册onCallback2监听。 phAccessHelper.on('hiddenAlbumChange', onCallback2); } catch (error) { console.error('onHiddenAlbumChangeDemo failed, errCode is', error); } } ``` ### off('hiddenAlbumChange')20+ off(type: 'hiddenAlbumChange', callback?: Callback<AlbumChangeInfos>): void 取消对'hiddenAlbumChange'隐藏相册的监听。存在多个callback监听时,可以取消指定注册的callback监听;不指定callback时取消所有监听。 **系统接口**:此接口为系统接口。 **系统能力**:SystemCapability.FileManagement.PhotoAccessHelper.Core **需要权限**:ohos.permission.READ_IMAGEVIDEO 和 ohos.permission.MANAGE_PRIVATE_PHOTOS **参数:** | 参数名 | 类型 | 必填 | 说明 | |-----------|-------------------------|-----------|-----------------| | type | string | 是 | 取消监听隐藏相册,取值为'hiddenAlbumChange'。取消监听后,有隐藏相册发生变化时,不再通过callback返回变更信息。 | | callback | Callback<[AlbumChangeInfos](arkts-apis-photoAccessHelper-i.md#albumchangeinfos20)> | 否 | 取消[on('hiddenAlbumChange')](#onhiddenalbumchange20)注册时指定的callback监听;不填时,则取消对'hiddenAlbumChange'的所有监听。
**注意:** 取消注册的callback后,有隐藏相册发生变化时,不会进入此回调。 | **错误码:** 以下错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)和[媒体库错误码](errcode-medialibrary.md)。 | 错误码ID | 错误信息 | | -------- | ---------------------------------------- | | 201 | Permission denied. | | 202 | Called by non-system application. | | 23800151 | The scenario parameter verification fails.
Possible causes: 1. The type is not fixed at 'hiddenAlbumChange'; 2. The same callback is unregistered repeatedly. | | 23800301 | Internal system error. You are advised to retry and check the logs.
Possible causes: 1. The database is corrupted. 2. The file system is abnormal. 3. The IPC request timed out. | **示例:** phAccessHelper的创建请参考[@ohos.file.photoAccessHelper (相册管理模块)](arkts-apis-photoAccessHelper-f.md)的示例使用。 ```ts import { dataSharePredicates } from '@kit.ArkData' let onCallback1 = (changeData: photoAccessHelper.AlbumChangeInfos) => { console.info('onCallback1 success, changData: ' + JSON.stringify(changeData)); // file had changed, do something. } let onCallback2 = (changeData: photoAccessHelper.AlbumChangeInfos) => { console.info('onCallback2 success, changData: ' + JSON.stringify(changeData)); // file had changed, do something. } async function example(phAccessHelper: photoAccessHelper.PhotoAccessHelper){ console.info('onHiddenAlbumChangeDemo.'); try { // 注册onCallback1监听。 phAccessHelper.on('hiddenAlbumChange', onCallback1); // 注册onCallback2监听。 phAccessHelper.on('hiddenAlbumChange', onCallback2); // 关闭onCallback1监听,onCallback2继续监听。 phAccessHelper.off('hiddenAlbumChange', onCallback1); } catch (error) { console.error('onHiddenAlbumChangeDemo failed, errCode is', error); } } ``` ### on('trashedAlbumChange')20+ on(type: 'trashedAlbumChange', callback: Callback<AlbumChangeInfos>): void 注册'trashedAlbumChange'监听回收站相册,并通过callback方式返回相册变化结果,可以注册多个callback。 **系统接口**:此接口为系统接口。 **系统能力**:SystemCapability.FileManagement.PhotoAccessHelper.Core **需要权限**:ohos.permission.READ_IMAGEVIDEO **参数:** | 参数名 | 类型 | 必填 | 说明 | |-----------|-------------------------|-----------|-----------------| | type | string | 是 | 注册监听回收站相册,取值为'trashedAlbumChange'。注册完成后,有回收站相册发生变化时,通过callback返回变更信息。 | | callback | Callback<[AlbumChangeInfos](arkts-apis-photoAccessHelper-i.md#albumchangeinfos20)> | 是 | 返回变更的相册信息[AlbumChangeInfos](arkts-apis-photoAccessHelper-i.md#albumchangeinfos20)。
**注意:** 该接口可以注册多个不同的callback监听,[off('trashedAlbumChange')](#offtrashedalbumchange20)即可以关闭所有监听,也可以关闭指定callback监听。 | **错误码:** 以下错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)和[媒体库错误码](errcode-medialibrary.md)。 | 错误码ID | 错误信息 | | -------- | ---------------------------------------- | | 201 | Permission denied. | | 202 | Called by non-system application. | | 23800151 | The scenario parameter verification fails.
Possible causes: 1. The type is not fixed at 'trashedAlbumChange'; 2. The same callback is registered repeatedly. | | 23800301 | Internal system error. You are advised to retry and check the logs.
Possible causes: 1. The database is corrupted. 2. The file system is abnormal. 3. The IPC request timed out. | **示例:** phAccessHelper的创建请参考[@ohos.file.photoAccessHelper (相册管理模块)](arkts-apis-photoAccessHelper-f.md)的示例使用。 ```ts import { dataSharePredicates } from '@kit.ArkData' let onCallback1 = (changeData: photoAccessHelper.AlbumChangeInfos) => { console.info('onCallback1 success, changData: ' + JSON.stringify(changeData)); // file had changed, do something. } let onCallback2 = (changeData: photoAccessHelper.AlbumChangeInfos) => { console.info('onCallback2 success, changData: ' + JSON.stringify(changeData)); // file had changed, do something. } async function example(phAccessHelper: photoAccessHelper.PhotoAccessHelper, context: Context){ console.info('onTrashedAlbumChangeDemo.'); try { // 注册onCallback1监听。 phAccessHelper.on('trashedAlbumChange', onCallback1); // 注册onCallback2监听。 phAccessHelper.on('trashedAlbumChange', onCallback2); } catch (error) { console.error('onTrashedAlbumChangeDemo failed, errCode is', error); } } ``` ### off('trashedAlbumChange')20+ off(type: 'trashedAlbumChange', callback?: Callback<AlbumChangeInfos>): void 取消对'trashedAlbumChange'回收站相册的监听。存在多个callback监听时,可以取消指定注册的callback监听;不指定callback时取消所有监听。 **系统接口**:此接口为系统接口。 **系统能力**:SystemCapability.FileManagement.PhotoAccessHelper.Core **需要权限**:ohos.permission.READ_IMAGEVIDEO **参数:** | 参数名 | 类型 | 必填 | 说明 | |-----------|-------------------------|-----------|-----------------| | type | string | 是 | 取消监听回收站相册,取值为'trashedAlbumChange'。取消监听后,有回收站相册发生变化时,不再通过callback返回变更信息。 | | callback | Callback<[AlbumChangeInfos](arkts-apis-photoAccessHelper-i.md#albumchangeinfos20)> | 否 | 取消[on('trashedAlbumChange')](#ontrashedalbumchange20)注册时指定的callback监听;不填时,则取消对'trashedAlbumChange'的所有监听。
**注意:** 取消注册的callback后,有回收站相册发生变化时,不会进入此回调。 | **错误码:** 以下错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)和[媒体库错误码](errcode-medialibrary.md)。 | 错误码ID | 错误信息 | | -------- | ---------------------------------------- | | 201 | Permission denied. | | 202 | Called by non-system application. | | 23800151 | The scenario parameter verification fails.
Possible causes: 1. The type is not fixed at 'trashedAlbumChange'; 2. The same callback is unregistered repeatedly. | | 23800301 | Internal system error. You are advised to retry and check the logs.
Possible causes: 1. The database is corrupted. 2. The file system is abnormal. 3. The IPC request timed out. | **示例:** phAccessHelper的创建请参考[@ohos.file.photoAccessHelper (相册管理模块)](arkts-apis-photoAccessHelper-f.md)的示例使用。 ```ts import { dataSharePredicates } from '@kit.ArkData' let onCallback1 = (changeData: photoAccessHelper.AlbumChangeInfos) => { console.info('onCallback1 success, changData: ' + JSON.stringify(changeData)); // file had changed, do something. } let onCallback2 = (changeData: photoAccessHelper.AlbumChangeInfos) => { console.info('onCallback2 success, changData: ' + JSON.stringify(changeData)); // file had changed, do something. } async function example(phAccessHelper: photoAccessHelper.PhotoAccessHelper, context: Context){ console.info('onTrashedAlbumChangeDemo.'); try { // 注册onCallback1监听。 phAccessHelper.on('trashedAlbumChange', onCallback1); // 注册onCallback2监听。 phAccessHelper.on('trashedAlbumChange', onCallback2); // 关闭onCallback1监听,onCallback2继续监听。 phAccessHelper.off('trashedAlbumChange', onCallback1); } catch (error) { console.error('onTrashedAlbumChangeDemo failed, errCode is', error); } } ``` ### getPhotoAlbums20+ getPhotoAlbums(options?: FetchOptions): Promise<FetchResult<Album>> 根据指定的选项获取系统、用户和来源相册。使用Promise异步回调。 在获取相册之前,确保相册已存在。 **系统接口**:此接口为系统接口。 **需要权限:** ohos.permission.READ_IMAGEVIDEO **系统能力**:SystemCapability.FileManagement.PhotoAccessHelper.Core **参数:** | 参数名 | 类型 | 必填 | 说明 | | --------- | ------------------- | ---- | ------------------------------------------------------------ | | options | [FetchOptions](arkts-apis-photoAccessHelper-i.md#fetchoptions) | 否 | 检索选项,不填时默认根据相册类型检索。 | **返回值:** | 类型 | 说明 | | --------------------- | --------------------------- | | Promise<[FetchResult](arkts-apis-photoAccessHelper-FetchResult.md)<[Album](#album)>> | Promise对象,返回获取相册的结果集。 | **错误码:** 以下错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)和[媒体库错误码](errcode-medialibrary.md)。 | 错误码ID | 错误信息 | | -------- | ------------------------------------------------------------ | | 201 | Permission denied. | | 202 | Called by non-system application. | | 23800301 | Internal system error. It is recommended to retry and check the logs.
Possible causes: 1. Database corrupted; 2. The file system is abnormal; 3. The IPC request timed out. | **示例:** phAccessHelper的创建请参考[photoAccessHelper.getPhotoAccessHelper](arkts-apis-photoAccessHelper-f.md#photoaccesshelpergetphotoaccesshelper)的示例使用。 ```ts import { dataSharePredicates } from '@kit.ArkData'; import { BusinessError } from '@kit.BasicServicesKit'; async function example(phAccessHelper: photoAccessHelper.PhotoAccessHelper) { console.info('getPhotoAlbumsDemo'); let predicates: dataSharePredicates.DataSharePredicates = new dataSharePredicates.DataSharePredicates(); let fetchOptions: photoAccessHelper.FetchOptions = { fetchColumns: [], predicates: predicates }; phAccessHelper.getPhotoAlbums(fetchOptions).then( async (fetchResult) => { if (fetchResult === undefined) { console.error('getPhotoAlbumsPromise fetchResult is undefined'); return; } let albums: photoAccessHelper.Album[] = await fetchResult.getAllObjects(); console.info(`getPhotoAlbumsPromise successfully, albums length: ${albums.length}`); fetchResult.close(); }).catch((err: BusinessError) => { console.error(`getPhotoAlbumsPromise failed with err: ${err.code}, ${err.message}`); }); } ``` ### getPhotoAlbumOrder20+ getPhotoAlbumOrder(orderStyle: number, options?: FetchOptions): Promise<FetchResult<AlbumOrder>> 获取系统、用户和来源相册的排序信息。使用Promise异步回调。 **系统接口**:此接口为系统接口。 **需要权限:** ohos.permission.READ_IMAGEVIDEO **系统能力**:SystemCapability.FileManagement.PhotoAccessHelper.Core **参数:** | 参数名 | 类型 | 必填 | 说明 | | --------- | ------------------- | ---- | ------------------------------------------------------------ | | orderStyle | number | 是 | 选择相册的排序风格。
0:Phone风格。1:PC风格。 | | options | [FetchOptions](arkts-apis-photoAccessHelper-i.md#fetchoptions) | 否 | 检索选项,不填时默认根据相册类型检索。 | **返回值:** | 类型 | 说明 | | --------------------- | --------------------------- | | Promise<[FetchResult](arkts-apis-photoAccessHelper-FetchResult.md)<[AlbumOrder](#albumorder20)>> | Promise对象,返回获取相册排序的结果集。 | **错误码:** 以下错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)和[媒体库错误码](errcode-medialibrary.md)。 | 错误码ID | 错误信息 | | -------- | ------------------------------------------------------------ | | 201 | Permission denied. | | 202 | Called by non-system application. | | 23800151 | The scenario parameter verification fails.
Possible causes: 1. The input parameter is not within the valid range. | | 23800301 | Internal system error. It is recommended to retry and check the logs.
Possible causes: 1. Database corrupted; 2. The file system is abnormal; 3. The IPC request timed out. | **示例:** phAccessHelper的创建请参考[photoAccessHelper.getPhotoAccessHelper](arkts-apis-photoAccessHelper-f.md#photoaccesshelpergetphotoaccesshelper)的示例使用。 ```ts import { dataSharePredicates } from '@kit.ArkData'; import { BusinessError } from '@kit.BasicServicesKit'; async function example(phAccessHelper: photoAccessHelper.PhotoAccessHelper) { console.info('getPhotoAlbumOrderDemo'); let predicates: dataSharePredicates.DataSharePredicates = new dataSharePredicates.DataSharePredicates(); let fetchOptions: photoAccessHelper.FetchOptions = { fetchColumns: [], predicates: predicates }; let orderStyle: number = 0; phAccessHelper.getPhotoAlbumOrder(orderStyle, fetchOptions).then( async (fetchResult) => { if (fetchResult === undefined) { console.error('getPhotoAlbumOrderPromise fetchResult is undefined'); return; } let albumOrders: photoAccessHelper.AlbumOrder[] = await fetchResult.getAllObjects(); console.info(`getPhotoAlbumOrderPromise successfully, albumOrders length: ${albumOrders.length}`); fetchResult.close(); }).catch((err: BusinessError) => { console.error(`getPhotoAlbumOrderPromise failed with err: ${err.code}, ${err.message}`); }); } ``` ### setPhotoAlbumOrder20+ setPhotoAlbumOrder(orderStyle: number, albumOrders: Array<AlbumOrder>): Promise<void> 设置系统、用户和来源相册的排序。使用Promise异步回调。 **系统接口**:此接口为系统接口。 **需要权限:** ohos.permission.WRITE_IMAGEVIDEO **系统能力**:SystemCapability.FileManagement.PhotoAccessHelper.Core **参数:** | 参数名 | 类型 | 必填 | 说明 | | --------- | ------------------- | ---- | ------------------------------------------------------------ | | orderStyle | number | 是 | 选择相册的排序风格。
0:Phone风格。1:PC风格。 | | albumOrders | Array<[AlbumOrder](#albumorder20)> | 是 | 待设置的相册排序结果数组。 | **返回值:** | 类型 | 说明 | | --------------------- | --------------------------- | | Promise&lt;void&gt;| Promise对象,无返回结果。 | **错误码:** 以下错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)和[媒体库错误码](errcode-medialibrary.md)。 | 错误码ID | 错误信息 | | -------- | ------------------------------------------------------------ | | 201 | Permission denied. | | 202 | Called by non-system application. | | 23800151 | The scenario parameter verification fails.
Possible causes: 1. The input parameter is not within the valid range. | | 23800301 | Internal system error. It is recommended to retry and check the logs.
Possible causes: 1. Database corrupted; 2. The file system is abnormal; 3. The IPC request timed out. | **示例:** phAccessHelper的创建请参考[photoAccessHelper.getPhotoAccessHelper](arkts-apis-photoAccessHelper-f.md#photoaccesshelpergetphotoaccesshelper)的示例使用。 ```ts import { dataSharePredicates } from '@kit.ArkData'; import { BusinessError } from '@kit.BasicServicesKit'; async function example(phAccessHelper: photoAccessHelper.PhotoAccessHelper) { console.info('setPhotoAlbumOrderDemo'); let predicates: dataSharePredicates.DataSharePredicates = new dataSharePredicates.DataSharePredicates(); let fetchOptions: photoAccessHelper.FetchOptions = { fetchColumns: [], predicates: predicates }; let orderStyle: number = 0; phAccessHelper.getPhotoAlbumOrder(orderStyle, fetchOptions).then( async (fetchResult) => { if (fetchResult === undefined) { console.error('getPhotoAlbumOrderPromise fetchResult is undefined'); return; } let albumOrder: photoAccessHelper.AlbumOrder = await fetchResult.getFirstObject(); albumOrder.albumOrder = 10; albumOrder.orderSection = 0; albumOrder.orderType = 1; albumOrder.orderStatus = 1; await phAccessHelper.setPhotoAlbumOrder(orderStyle, [albumOrder]); console.info('setPhotoAlbumOrderPromise successfully.'); fetchResult.close(); }).catch((err: BusinessError) => { console.error(`setPhotoAlbumOrderPromise failed with err: ${err.code}, ${err.message}`); }); } ``` ## PhotoAsset 提供封装文件属性的方法。 ### open(deprecated) open(mode: string, callback: AsyncCallback<number>): void 打开当前文件,使用callback方式返回异步结果。 > **说明:** > > 从API version 10开始支持,从API version 11开始废弃。出于安全考量,不再提供获取正式媒体文件句柄的接口。 **注意**:当前此(写)操作是互斥的操作,返回的文件描述符在使用完毕后需要调用close进行释放。 **系统接口**:此接口为系统接口。 **需要权限**:ohos.permission.READ_IMAGEVIDEO 或 ohos.permission.WRITE_IMAGEVIDEO **系统能力**:SystemCapability.FileManagement.PhotoAccessHelper.Core **参数:** | 参数名 | 类型 | 必填 | 说明 | | -------- | --------------------------- | ---- | ----------------------------------- | | mode | string | 是 | 打开文件方式,分别为:'r'(只读), 'w'(只写), 'rw'(读写)。 | | callback | AsyncCallback<number> | 是 | callback返回文件描述符。 | **错误码:** 接口抛出错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)和[文件管理错误码](../apis-core-file-kit/errorcode-filemanagement.md)。 错误码13900012,请参考[开发准备](../../media/medialibrary/photoAccessHelper-preparation.md)。 | 错误码ID | 错误信息 | | -------- | ---------------------------------------- | | 202 | Called by non-system application. | | 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types; 3. Parameter verification failed. | | 13900012 | Permission denied. | | 13900020 | Invalid argument. | | 14000011 | System inner fail. Possible causes: 1. The database is corrupted; 2. The file system is abnormal; 3. The IPC request timed out; 4. Permission denied. | **示例:** phAccessHelper的创建请参考[@ohos.file.photoAccessHelper (相册管理模块)](arkts-apis-photoAccessHelper-f.md)的示例使用。 ```ts async function example(phAccessHelper: photoAccessHelper.PhotoAccessHelper) { console.info('Open demo'); let testFileName: string = 'testFile' + Date.now() + '.jpg'; let photoAsset: photoAccessHelper.PhotoAsset = await phAccessHelper.createAsset(testFileName); photoAsset.open('rw', (err, fd) => { if (fd !== undefined) { console.info('File fd' + fd); photoAsset.close(fd); } else { console.error(`Open file err: ${err.code}, ${err.message}`); } }); } ``` ### open(deprecated) open(mode: string): Promise<number> 打开当前文件,使用promise方式返回异步结果。 > **说明:** > > 从API version 10开始支持,从API version 11开始废弃。出于安全考量,不再提供获取正式媒体文件句柄的接口。 **注意**:当前此(写)操作是互斥的操作,返回的文件描述符在使用完毕后需要调用close进行释放。 **系统接口**:此接口为系统接口。 **需要权限**:ohos.permission.READ_IMAGEVIDEO 或 ohos.permission.WRITE_IMAGEVIDEO **系统能力**:SystemCapability.FileManagement.PhotoAccessHelper.Core **参数:** | 参数名 | 类型 | 必填 | 说明 | | ---- | ------ | ---- | ----------------------------------- | | mode | string | 是 | 打开文件方式,分别为:'r'(只读), 'w'(只写), 'rw'(读写)。 | **返回值:** | 类型 | 说明 | | --------------------- | ------------- | | Promise<number> | Promise对象,返回文件描述符。 | **错误码:** 接口抛出错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)和[文件管理错误码](../apis-core-file-kit/errorcode-filemanagement.md)。 错误码13900012,请参考[开发准备](../../media/medialibrary/photoAccessHelper-preparation.md)。 | 错误码ID | 错误信息 | | -------- | ---------------------------------------- | | 202 | Called by non-system application. | | 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types; 3. Parameter verification failed. | | 13900012 | Permission denied. | | 13900020 | Invalid argument. | | 14000011 | System inner fail. Possible causes: 1. The database is corrupted; 2. The file system is abnormal; 3. The IPC request timed out; 4. Permission denied. | **示例:** phAccessHelper的创建请参考[@ohos.file.photoAccessHelper (相册管理模块)](arkts-apis-photoAccessHelper-f.md)的示例使用。 ```ts async function example(phAccessHelper: photoAccessHelper.PhotoAccessHelper) { console.info('Open demo'); try { let testFileName: string = 'testFile' + Date.now() + '.jpg'; let photoAsset: photoAccessHelper.PhotoAsset = await phAccessHelper.createAsset(testFileName); let fd: number = await photoAsset.open('rw'); if (fd !== undefined) { console.info('File fd' + fd); photoAsset.close(fd); } else { console.error('Open file fail'); } } catch (err) { console.error(`Open demo err: ${err.code}, ${err.message}`); } } ``` ### setFavorite(deprecated) setFavorite(favoriteState: boolean, callback: AsyncCallback<void>): void 将文件设置为收藏文件,使用callback方式返回异步结果。 > **说明:** > > 从API version 10开始支持,从API version 11开始废弃。建议使用[MediaAssetChangeRequest.setFavorite](#setfavorite11)替代。 **系统接口**:此接口为系统接口。 **需要权限**:ohos.permission.WRITE_IMAGEVIDEO **系统能力**:SystemCapability.FileManagement.PhotoAccessHelper.Core **参数:** | 参数名 | 类型 | 必填 | 说明 | | ---------- | ------------------------- | ---- | ---------------------------------- | | favoriteState | boolean | 是 | 是否设置为收藏文件, true:设置为收藏文件,false:取消收藏。 | | callback | AsyncCallback<void> | 是 | callback返回void。 | **错误码:** 接口抛出错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)和[文件管理错误码](../apis-core-file-kit/errorcode-filemanagement.md)。 错误码201,请参考[开发准备](../../media/medialibrary/photoAccessHelper-preparation.md)。 | 错误码ID | 错误信息 | | -------- | ---------------------------------------- | | 201 | Permission denied. | | 202 | Called by non-system application. | | 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types; 3. Parameter verification failed. | | 13900020 | Invalid argument. | | 14000011 | System inner fail. | **示例:** phAccessHelper的创建请参考[@ohos.file.photoAccessHelper (相册管理模块)](arkts-apis-photoAccessHelper-f.md)的示例使用。 ```ts import { dataSharePredicates } from '@kit.ArkData'; async function example(phAccessHelper: photoAccessHelper.PhotoAccessHelper) { console.info('setFavoriteDemo'); let predicates: dataSharePredicates.DataSharePredicates = new dataSharePredicates.DataSharePredicates(); let fetchOption: photoAccessHelper.FetchOptions = { fetchColumns: [], predicates: predicates }; let fetchResult: photoAccessHelper.FetchResult = await phAccessHelper.getAssets(fetchOption); let asset = await fetchResult.getFirstObject(); asset.setFavorite(true, (err) => { if (err === undefined) { console.info('favorite successfully'); } else { console.error(`favorite failed with error: ${err.code}, ${err.message}`); } }); } ``` ### setFavorite(deprecated) setFavorite(favoriteState: boolean): Promise<void> 将文件设置为收藏文件,使用promise方式返回异步结果。 > **说明:** > > 从API version 10开始支持,从API version 11开始废弃。建议使用[MediaAssetChangeRequest.setFavorite](#setfavorite11)替代。 **系统接口**:此接口为系统接口。 **需要权限**:ohos.permission.WRITE_IMAGEVIDEO **系统能力**:SystemCapability.FileManagement.PhotoAccessHelper.Core **参数:** | 参数名 | 类型 | 必填 | 说明 | | ---------- | ------- | ---- | ---------------------------------- | | favoriteState | boolean | 是 | 是否设置为收藏文件, true:设置为收藏文件,false:取消收藏。 | **返回值:** | 类型 | 说明 | | ------------------- | ---------- | | Promise<void> | Promise对象,返回void。 | **错误码:** 接口抛出错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)和[文件管理错误码](../apis-core-file-kit/errorcode-filemanagement.md)。 错误码201,请参考[开发准备](../../media/medialibrary/photoAccessHelper-preparation.md)。 | 错误码ID | 错误信息 | | -------- | ---------------------------------------- | | 201 | Permission denied. | | 202 | Called by non-system application. | | 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types; 3. Parameter verification failed. | | 13900020 | Invalid argument. | | 14000011 | System inner fail. | **示例:** phAccessHelper的创建请参考[@ohos.file.photoAccessHelper (相册管理模块)](arkts-apis-photoAccessHelper-f.md)的示例使用。 ```ts import { dataSharePredicates } from '@kit.ArkData'; import { BusinessError } from '@kit.BasicServicesKit'; async function example(phAccessHelper: photoAccessHelper.PhotoAccessHelper) { console.info('setFavoriteDemo'); let predicates: dataSharePredicates.DataSharePredicates = new dataSharePredicates.DataSharePredicates(); let fetchOption: photoAccessHelper.FetchOptions = { fetchColumns: [], predicates: predicates }; let fetchResult: photoAccessHelper.FetchResult = await phAccessHelper.getAssets(fetchOption); let asset = await fetchResult.getFirstObject(); asset.setFavorite(true).then(() => { console.info('setFavorite successfully'); }).catch((err: BusinessError) => { console.error(`setFavorite failed with error: ${err.code}, ${err.message}`); }); } ``` ### setHidden(deprecated) setHidden(hiddenState: boolean, callback: AsyncCallback<void>): void 将文件设置为隐私文件,使用callback方式返回异步结果。 隐私文件存在隐私相册中,用户通过隐私相册去获取隐私文件后可以通过设置hiddenState为false来从隐私相册中移除。 > **说明:** > > 从API version 10开始支持,从API version 11开始废弃。建议使用[MediaAssetChangeRequest.setHidden](#sethidden11)替代。 **系统接口**:此接口为系统接口。 **需要权限**:ohos.permission.WRITE_IMAGEVIDEO **系统能力**:SystemCapability.FileManagement.PhotoAccessHelper.Core **参数:** | 参数名 | 类型 | 必填 | 说明 | | ---------- | ------------------------- | ---- | ---------------------------------- | | hiddenState | boolean | 是 | 是否设置为隐藏文件,true:将文件资产放入隐藏相册;false:从隐藏相册中恢复。 | | callback | AsyncCallback<void> | 是 | callback返回void。 | **错误码:** 接口抛出错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)和[文件管理错误码](../apis-core-file-kit/errorcode-filemanagement.md)。 错误码201,请参考[开发准备](../../media/medialibrary/photoAccessHelper-preparation.md)。 | 错误码ID | 错误信息 | | -------- | ---------------------------------------- | | 201 | Permission denied. | | 202 | Called by non-system application. | | 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types; 3. Parameter verification failed. | | 13900020 | Invalid argument. | | 14000011 | System inner fail. | **示例:** phAccessHelper的创建请参考[@ohos.file.photoAccessHelper (相册管理模块)](arkts-apis-photoAccessHelper-f.md)的示例使用。 ```ts import { dataSharePredicates } from '@kit.ArkData'; async function example(phAccessHelper: photoAccessHelper.PhotoAccessHelper) { console.info('setHiddenDemo'); let predicates: dataSharePredicates.DataSharePredicates = new dataSharePredicates.DataSharePredicates(); let fetchOption: photoAccessHelper.FetchOptions = { fetchColumns: [], predicates: predicates }; let fetchResult: photoAccessHelper.FetchResult = await phAccessHelper.getAssets(fetchOption); let asset = await fetchResult.getFirstObject(); asset.setHidden(true, (err) => { if (err === undefined) { console.info('setHidden successfully'); } else { console.error(`setHidden failed with error: ${err.code}, ${err.message}`); } }); } ``` ### setHidden(deprecated) setHidden(hiddenState: boolean): Promise<void> 将文件设置为隐私文件,使用promise方式返回异步结果。 隐私文件存在隐私相册中,用户通过隐私相册去获取隐私文件后可以通过设置hiddenState为false来从隐私相册中移除。 > **说明:** > > 从API version 10开始支持,从API version 11开始废弃。建议使用[MediaAssetChangeRequest.setHidden](#sethidden11)替代。 **系统接口**:此接口为系统接口。 **需要权限**:ohos.permission.WRITE_IMAGEVIDEO **系统能力**:SystemCapability.FileManagement.PhotoAccessHelper.Core **参数:** | 参数名 | 类型 | 必填 | 说明 | | ---------- | ------- | ---- | ---------------------------------- | | hiddenState | boolean | 是 | 是否设置为隐藏文件,true:将文件资产放入隐藏相册;false:从隐藏相册中恢复。 | **返回值:** | 类型 | 说明 | | ------------------- | ---------- | | Promise<void> | Promise对象,返回void。 | **错误码:** 接口抛出错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)和[文件管理错误码](../apis-core-file-kit/errorcode-filemanagement.md)。 错误码201,请参考[开发准备](../../media/medialibrary/photoAccessHelper-preparation.md)。 | 错误码ID | 错误信息 | | -------- | ---------------------------------------- | | 201 | Permission denied. | | 202 | Called by non-system application. | | 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types; 3. Parameter verification failed. | | 13900020 | Invalid argument. | | 14000011 | System inner fail. | **示例:** phAccessHelper的创建请参考[@ohos.file.photoAccessHelper (相册管理模块)](arkts-apis-photoAccessHelper-f.md)的示例使用。 ```ts import { dataSharePredicates } from '@kit.ArkData'; import { BusinessError } from '@kit.BasicServicesKit'; async function example(phAccessHelper: photoAccessHelper.PhotoAccessHelper) { // 示例代码为将文件从隐藏相册中恢复,需要先在隐藏相册预置资源。 console.info('setHiddenDemo'); let predicates: dataSharePredicates.DataSharePredicates = new dataSharePredicates.DataSharePredicates(); let fetchOption: photoAccessHelper.FetchOptions = { fetchColumns: [], predicates: predicates }; let albumList: photoAccessHelper.FetchResult = await phAccessHelper.getAlbums(photoAccessHelper.AlbumType.SYSTEM, photoAccessHelper.AlbumSubtype.HIDDEN); let album = await albumList.getFirstObject(); let fetchResult: photoAccessHelper.FetchResult = await album.getAssets(fetchOption); let asset = await fetchResult.getFirstObject(); asset.setHidden(false).then(() => { console.info('setHidden successfully'); }).catch((err: BusinessError) => { console.error(`setHidden failed with error: ${err.code}, ${err.message}`); }); } ``` ### getExif getExif(): Promise<string> 返回jpg格式图片Exif标签组成的json格式的字符串,该方法使用Promise方式返回结果。 此接口中获取的Exif标签信息是由[image](../apis-image-kit/arkts-apis-image.md)模块提供。Exif标签详细信息请参考[image.PropertyKey](../apis-image-kit/arkts-apis-image-e.md#propertykey7)。 **注意**:此接口返回的是Exif标签组成的json格式的字符串,完整Exif信息由all_exif与[PhotoKeys.USER_COMMENT](#photokeys)组成,fetchColumns需要传入这两个字段。 **系统接口**:此接口为系统接口。 **需要权限**:ohos.permission.READ_IMAGEVIDEO **系统能力**:SystemCapability.FileManagement.PhotoAccessHelper.Core **返回值:** | 类型 | 说明 | | --------------------------------------- | ----------------- | | Promise<string> | 返回Exif标签组成的json格式的字符串。 | **错误码:** 接口抛出错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)和[文件管理错误码](../apis-core-file-kit/errorcode-filemanagement.md)。 错误码13900012,请参考[开发准备](../../media/medialibrary/photoAccessHelper-preparation.md)。 | 错误码ID | 错误信息 | | -------- | ---------------------------------------- | | 202 | Called by non-system application. | | 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types. | | 13900012 | Permission denied. | | 13900020 | Invalid argument. | | 14000011 | System inner fail. | **示例:** phAccessHelper的创建请参考[@ohos.file.photoAccessHelper (相册管理模块)](arkts-apis-photoAccessHelper-f.md)的示例使用。 ```ts import { dataSharePredicates } from '@kit.ArkData'; async function example(phAccessHelper: photoAccessHelper.PhotoAccessHelper) { try { console.info('getExifDemo'); let predicates: dataSharePredicates.DataSharePredicates = new dataSharePredicates.DataSharePredicates(); let fetchOptions: photoAccessHelper.FetchOptions = { fetchColumns: [ 'all_exif', photoAccessHelper.PhotoKeys.USER_COMMENT], predicates: predicates }; let fetchResult: photoAccessHelper.FetchResult = await phAccessHelper.getAssets(fetchOptions); let photoAsset: photoAccessHelper.PhotoAsset = await fetchResult.getFirstObject(); let exifMessage = await photoAsset.getExif(); let userCommentKey = 'UserComment'; let userComment = JSON.stringify(JSON.parse(exifMessage), [userCommentKey]); console.info('getExifDemo userComment: ' + JSON.stringify(userComment)); fetchResult.close(); } catch (err) { console.error(`getExifDemoCallback failed with error: ${err.code}, ${err.message}`); } } ``` ### getExif getExif(callback: AsyncCallback<string>): void 返回jpg格式图片Exif标签组成的json格式的字符串,使用callback方式返回异步结果。 此接口中获取的Exif标签信息是由[image](../apis-image-kit/arkts-apis-image.md)模块提供。Exif标签详细信息请参考[image.PropertyKey](../apis-image-kit/arkts-apis-image-e.md#propertykey7)。 **注意**:此接口返回的是Exif标签组成的json格式的字符串,完整Exif信息由all_exif与[PhotoKeys.USER_COMMENT](#photokeys)组成,fetchColumns需要传入这两个字段。 **系统接口**:此接口为系统接口。 **需要权限**:ohos.permission.READ_IMAGEVIDEO **系统能力**:SystemCapability.FileManagement.PhotoAccessHelper.Core **参数:** | 参数名 | 类型 | 必填 | 说明 | | -------- | ------------------------- | ---- | ---------- | | callback | AsyncCallback<string> | 是 | 返回Exif字段组成的json格式的字符串。 | **错误码:** 接口抛出错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)和[文件管理错误码](../apis-core-file-kit/errorcode-filemanagement.md)。 错误码13900012,请参考[开发准备](../../media/medialibrary/photoAccessHelper-preparation.md)。 | 错误码ID | 错误信息 | | -------- | ---------------------------------------- | | 202 | Called by non-system application. | | 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types. | | 13900012 | Permission denied. | | 13900020 | Invalid argument. | | 14000011 | System inner fail. | **示例:** phAccessHelper的创建请参考[@ohos.file.photoAccessHelper (相册管理模块)](arkts-apis-photoAccessHelper-f.md)的示例使用。 ```ts import { dataSharePredicates } from '@kit.ArkData'; async function example(phAccessHelper: photoAccessHelper.PhotoAccessHelper) { try { console.info('getExifDemo'); let predicates: dataSharePredicates.DataSharePredicates = new dataSharePredicates.DataSharePredicates(); predicates.isNotNull('all_exif') let fetchOptions: photoAccessHelper.FetchOptions = { fetchColumns: ['all_exif', photoAccessHelper.PhotoKeys.USER_COMMENT], predicates: predicates }; let fetchResult: photoAccessHelper.FetchResult = await phAccessHelper.getAssets(fetchOptions); let photoAsset: photoAccessHelper.PhotoAsset = await fetchResult.getFirstObject(); console.info('getExifDemo photoAsset displayName: ' + JSON.stringify(photoAsset.displayName)); let userCommentKey = 'UserComment'; photoAsset.getExif((err, exifMessage) => { if (exifMessage !== undefined) { let userComment = JSON.stringify(JSON.parse(exifMessage), [userCommentKey]); console.info('getExifDemo userComment: ' + JSON.stringify(userComment)); } else { console.error(`getExif failed, error: ${err.code}, ${err.message}`); } }); fetchResult.close(); } catch (err) { console.error(`getExifDemoCallback failed with error: ${err.code}, ${err.message}`); } } ``` ### setUserComment(deprecated) setUserComment(userComment: string): Promise<void> 修改图片或者视频的备注信息,该方法使用Promise来返回结果。 > **说明:** > > 从API version 10开始支持,从API version 11开始废弃。建议使用[MediaAssetChangeRequest.setUserComment](#setusercomment11)替代。 **注意**:此接口只可修改图片或者视频的备注信息。 **系统接口**:此接口为系统接口。 **需要权限**:ohos.permission.WRITE_IMAGEVIDEO **系统能力**:SystemCapability.FileManagement.PhotoAccessHelper.Core **参数:** | 参数名 | 类型 | 必填 | 说明 | | -------- | ------------------------- | ---- | ---------- | | userComment | string | 是 | 待修改的图片或视频的备注信息,备注信息最长为420字符。 | **返回值:** | 类型 | 说明 | | --------------------------------------- | ----------------- | |Promise<void> | Promise对象,返回void。 | **错误码:** 接口抛出错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)和[文件管理错误码](../apis-core-file-kit/errorcode-filemanagement.md)。 错误码201,请参考[开发准备](../../media/medialibrary/photoAccessHelper-preparation.md)。 | 错误码ID | 错误信息 | | -------- | ---------------------------------------- | | 201 | Permission denied. | | 202 | Called by non-system application. | | 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types; 3. Parameter verification failed. | | 13900020 | Invalid argument. | | 14000011 | System inner fail. | **示例:** phAccessHelper的创建请参考[@ohos.file.photoAccessHelper (相册管理模块)](arkts-apis-photoAccessHelper-f.md)的示例使用。 ```ts import { dataSharePredicates } from '@kit.ArkData'; async function example(phAccessHelper: photoAccessHelper.PhotoAccessHelper) { try { console.info('setUserCommentDemo') let predicates: dataSharePredicates.DataSharePredicates = new dataSharePredicates.DataSharePredicates(); let fetchOptions: photoAccessHelper.FetchOptions = { fetchColumns: [], predicates: predicates }; let fetchResult: photoAccessHelper.FetchResult = await phAccessHelper.getAssets(fetchOptions); let photoAsset: photoAccessHelper.PhotoAsset = await fetchResult.getFirstObject(); let userComment = 'test_set_user_comment'; await photoAsset.setUserComment(userComment); } catch (err) { console.error(`setUserCommentDemoPromise failed with error: ${err.code}, ${err.message}`); } } ``` ### setUserComment(deprecated) setUserComment(userComment: string, callback: AsyncCallback<void>): void 修改图片或者视频的备注信息,该方法使用callback形式来返回结果。 > **说明:** > > 从API version 10开始支持,从API version 11开始废弃。建议使用[MediaAssetChangeRequest.setUserComment](#setusercomment11)替代。 **注意**:此接口只可修改图片或者视频的备注信息。 **系统接口**:此接口为系统接口。 **需要权限**:ohos.permission.WRITE_IMAGEVIDEO **系统能力**:SystemCapability.FileManagement.PhotoAccessHelper.Core **参数:** | 参数名 | 类型 | 必填 | 说明 | | -------- | ------------------------- | ---- | ---------- | | userComment | string | 是 | 待修改的图片或视频的备注信息,备注信息最长为420字符。 | | callback | AsyncCallback<void> | 是 | callback返回void。 | **错误码:** 接口抛出错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)和[文件管理错误码](../apis-core-file-kit/errorcode-filemanagement.md)。 错误码201,请参考[开发准备](../../media/medialibrary/photoAccessHelper-preparation.md)。 | 错误码ID | 错误信息 | | -------- | ---------------------------------------- | | 201 | Permission denied. | | 202 | Called by non-system application. | | 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types; 3. Parameter verification failed. | | 13900020 | Invalid argument. | | 14000011 | System inner fail. | **示例:** phAccessHelper的创建请参考[@ohos.file.photoAccessHelper (相册管理模块)](arkts-apis-photoAccessHelper-f.md)的示例使用。 ```ts import { dataSharePredicates } from '@kit.ArkData'; async function example(phAccessHelper: photoAccessHelper.PhotoAccessHelper) { try { console.info('setUserCommentDemo') let predicates: dataSharePredicates.DataSharePredicates = new dataSharePredicates.DataSharePredicates(); let fetchOptions: photoAccessHelper.FetchOptions = { fetchColumns: [], predicates: predicates }; let fetchResult: photoAccessHelper.FetchResult = await phAccessHelper.getAssets(fetchOptions); let photoAsset: photoAccessHelper.PhotoAsset = await fetchResult.getFirstObject(); let userComment = 'test_set_user_comment'; photoAsset.setUserComment(userComment, (err) => { if (err === undefined) { console.info('setUserComment successfully'); } else { console.error(`setUserComment failed with error: ${err.code}, ${err.message}`); } }); } catch (err) { console.error(`setUserCommentDemoCallback failed with error: ${err.code}, ${err.message}`); } } ``` ### setPending11+ setPending(pendingState: boolean, callback: AsyncCallback<void>): void 为图片或视频资源设置pending状态,该方法使用callback形式来返回结果。 将文件通过`setPending(true)`设置为pending状态后,只能通过`setPending(false)`解除pending状态。可以通过`photoAsset.get(photoAccessHelper.PhotoKeys.PENDING)`的方式获取是否为pending状态,pending状态下返回true,否则返回false。 **注意**:setPending只能在文件的创建期使用,在文件的首次创建流程的close之后,无法通过setPending(true)将文件设置为pending状态。 **系统接口**:此接口为系统接口。 **需要权限**:ohos.permission.WRITE_IMAGEVIDEO **系统能力**:SystemCapability.FileManagement.PhotoAccessHelper.Core **参数:** | 参数名 | 类型 | 必填 | 说明 | | ---------- | ------- | ---- | ---------------------------------- | | pendingState | boolean | 是 | 设置的pending状态,true为设置pending状态,false为解除pending状态。 | | callback | AsyncCallback<void> | 是 | Callback对象,返回void。 | **错误码:** 接口抛出错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)和[文件管理错误码](../apis-core-file-kit/errorcode-filemanagement.md)。 | 错误码ID | 错误信息 | | -------- | ---------------------------------------- | | 201 | Permission denied. | | 202 | Called by non-system application. | | 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types; 3. Parameter verification failed. | | 14000011 | System inner fail. | **示例:** phAccessHelper的创建请参考[@ohos.file.photoAccessHelper (相册管理模块)](arkts-apis-photoAccessHelper-f.md)的示例使用。 ```ts async function example(phAccessHelper: photoAccessHelper.PhotoAccessHelper) { try { console.info('setPendingCallbackDemo'); let testFileName: string = 'testFile' + Date.now() + '.jpg'; let photoAsset = await phAccessHelper.createAsset(testFileName); photoAsset.setPending(true, async (err) => { if (err !== undefined) { console.error(`setPending(true) failed with error: ${err.code}, ${err.message}`); return; } // add asset resource. photoAsset.setPending(false, async (err) => { if (err !== undefined) { console.error(`setPending(false) failed with error: ${err.code}, ${err.message}`); return; } }); }); } catch (err) { console.error(`setPendingCallbackDemo failed with error: ${err.code}, ${err.message}`); } } ``` ### setPending11+ setPending(pendingState: boolean): Promise<void> 为图片或视频资源设置pending状态,该方法使用promise形式来返回结果。 将文件通过`setPending(true)`设置为pending状态后,只能通过`setPending(false)`解除pending状态。可以通过`photoAsset.get(photoAccessHelper.PhotoKeys.PENDING)`的方式获取是否为pending状态,pending状态下返回true,否则返回false。 **注意**:setPending只能在文件的创建期使用,在文件的首次创建流程的close之后,无法通过setPending(true)将文件设置为pending状态。 **系统接口**:此接口为系统接口。 **需要权限**:ohos.permission.WRITE_IMAGEVIDEO **系统能力**:SystemCapability.FileManagement.PhotoAccessHelper.Core **参数:** | 参数名 | 类型 | 必填 | 说明 | | ---------- | ------- | ---- | ---------------------------------- | | pendingState | boolean | 是 | 设置的pending状态,true为设置pending状态,false为解除pending状态。 | **返回值:** | 类型 | 说明 | | --------------------------------------- | ----------------- | |Promise<boolean> | Promise对象,返回void。 | **错误码:** 接口抛出错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)和[文件管理错误码](../apis-core-file-kit/errorcode-filemanagement.md)。 | 错误码ID | 错误信息 | | -------- | ---------------------------------------- | | 201 | Permission denied. | | 202 | Called by non-system application. | | 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types; 3. Parameter verification failed. | | 14000011 | System inner fail. | **示例:** phAccessHelper的创建请参考[@ohos.file.photoAccessHelper (相册管理模块)](arkts-apis-photoAccessHelper-f.md)的示例使用。 ```ts async function example(phAccessHelper: photoAccessHelper.PhotoAccessHelper) { try { console.info('setPendingPromiseDemo'); let testFileName: string = 'testFile' + Date.now() + '.jpg'; let photoAsset = await phAccessHelper.createAsset(testFileName); await photoAsset.setPending(true); // add asset resource. photoAsset.setPending(false); } catch (err) { console.error(`setPendingPromiseDemo failed with error: ${err.code}, ${err.message}`); } } ``` ### isEdited11+ isEdited(callback: AsyncCallback<boolean>): void 查询图片或视频资源是否被编辑过,该方法使用callback形式来返回结果。 **系统接口**:此接口为系统接口。 **需要权限**:ohos.permission.READ_IMAGEVIDEO **系统能力**:SystemCapability.FileManagement.PhotoAccessHelper.Core **参数:** | 参数名 | 类型 | 必填 | 说明 | | ---------- | ------- | ---- | ---------------------------------- | | callback | AsyncCallback<boolean> | 是 | Callback对象,返回图片或视频资源是否被编辑过。true为被编辑过,false为没有被编辑过,默认是false。 | **错误码:** 接口抛出错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)和[文件管理错误码](../apis-core-file-kit/errorcode-filemanagement.md)。 | 错误码ID | 错误信息 | | -------- | ---------------------------------------- | | 201 | Permission denied. | | 202 | Called by non-system application. | | 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types. | | 14000011 | System inner fail. | **示例:** phAccessHelper的创建请参考[@ohos.file.photoAccessHelper (相册管理模块)](arkts-apis-photoAccessHelper-f.md)的示例使用。 ```ts import { dataSharePredicates } from '@kit.ArkData'; async function example(phAccessHelper: photoAccessHelper.PhotoAccessHelper) { try { console.info('isEditedCallbackDemo') let predicates: dataSharePredicates.DataSharePredicates = new dataSharePredicates.DataSharePredicates(); let fetchOptions: photoAccessHelper.FetchOptions = { fetchColumns: [], predicates: predicates }; let fetchResult: photoAccessHelper.FetchResult = await phAccessHelper.getAssets(fetchOptions); let photoAsset: photoAccessHelper.PhotoAsset = await fetchResult.getFirstObject(); photoAsset.isEdited((err, isEdited) => { if (err === undefined) { if (isEdited === true) { console.info('Photo is edited'); } else { console.info('Photo is not edited'); } } else { console.error(`isEdited failed with error: ${err.code}, ${err.message}`); } }); } catch (err) { console.error(`isEditedDemoCallback failed with error: ${err.code}, ${err.message}`); } } ``` ### isEdited11+ isEdited(): Promise<boolean> 查询图片或视频资源是否被编辑过,该方法使用promise形式来返回结果。 **系统接口**:此接口为系统接口。 **需要权限**:ohos.permission.READ_IMAGEVIDEO **系统能力**:SystemCapability.FileManagement.PhotoAccessHelper.Core **返回值:** | 类型 | 说明 | | --------------------------------------- | ----------------- | |Promise<boolean> | Promise对象,返回图片或视频资源是否被编辑过。true为被编辑过,false为没有被编辑过,默认是false。 | **错误码:** 接口抛出错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)和[文件管理错误码](../apis-core-file-kit/errorcode-filemanagement.md)。 | 错误码ID | 错误信息 | | -------- | ---------------------------------------- | | 201 | Permission denied. | | 202 | Called by non-system application. | | 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types. | | 14000011 | System inner fail. | **示例:** phAccessHelper的创建请参考[@ohos.file.photoAccessHelper (相册管理模块)](arkts-apis-photoAccessHelper-f.md)的示例使用。 ```ts import { dataSharePredicates } from '@kit.ArkData'; async function example(phAccessHelper: photoAccessHelper.PhotoAccessHelper) { try { console.info('isEditedPromiseDemo') let predicates: dataSharePredicates.DataSharePredicates = new dataSharePredicates.DataSharePredicates(); let fetchOptions: photoAccessHelper.FetchOptions = { fetchColumns: [], predicates: predicates }; let fetchResult: photoAccessHelper.FetchResult = await phAccessHelper.getAssets(fetchOptions); let photoAsset: photoAccessHelper.PhotoAsset = await fetchResult.getFirstObject(); let isEdited = await photoAsset.isEdited(); if (isEdited === true) { console.info('Photo is edited'); } else { console.info('Photo is not edited'); } } catch (err) { console.error(`isEditedDemoCallback failed with error: ${err.code}, ${err.message}`); } } ``` ### requestEditData11+ requestEditData(callback: AsyncCallback<string>): void 获得图片或视频资源的编辑数据,该方法使用callback形式来返回结果。 如果资源未编辑过,则返回一个空字符串。 **系统接口**:此接口为系统接口。 **需要权限**:ohos.permission.READ_IMAGEVIDEO **系统能力**:SystemCapability.FileManagement.PhotoAccessHelper.Core **参数:** | 参数名 | 类型 | 必填 | 说明 | | ---------- | ------- | ---- | ---------------------------------- | | callback | AsyncCallback<string> | 是 | Callback对象,返回图片或视频资源的编辑数据。 | **错误码:** 接口抛出错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)和[文件管理错误码](../apis-core-file-kit/errorcode-filemanagement.md)。 | 错误码ID | 错误信息 | | -------- | ---------------------------------------- | | 201 | Permission denied. | | 202 | Called by non-system application. | | 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types. | | 14000011 | System inner fail. Possible causes: 1. The database is corrupted; 2. The file system is abnormal; 3. The IPC request timed out; 4. Permission denied. | **示例:** phAccessHelper的创建请参考[@ohos.file.photoAccessHelper (相册管理模块)](arkts-apis-photoAccessHelper-f.md)的示例使用。 ```ts import { dataSharePredicates } from '@kit.ArkData'; async function example(phAccessHelper: photoAccessHelper.PhotoAccessHelper) { try { console.info('requestEditDataCallbackDemo') let predicates: dataSharePredicates.DataSharePredicates = new dataSharePredicates.DataSharePredicates(); let fetchOptions: photoAccessHelper.FetchOptions = { fetchColumns: [], predicates: predicates }; let fetchResult: photoAccessHelper.FetchResult = await phAccessHelper.getAssets(fetchOptions); let photoAsset: photoAccessHelper.PhotoAsset = await fetchResult.getFirstObject(); photoAsset.requestEditData((err, editdata) => { if (err === undefined) { console.info('Editdata is ' + editdata); } else { console.error(`requestEditData failed with error: ${err.code}, ${err.message}`); } }); } catch (err) { console.error(`requestEditDataCallbackDemo failed with error: ${err.code}, ${err.message}`); } } ``` ### requestEditData11+ requestEditData(): Promise<string> 获得图片或视频资源的编辑数据,该方法使用promise形式来返回结果。 如果资源未编辑过,则返回一个空字符串。 **系统接口**:此接口为系统接口。 **需要权限**:ohos.permission.READ_IMAGEVIDEO **系统能力**:SystemCapability.FileManagement.PhotoAccessHelper.Core **返回值:** | 类型 | 说明 | | --------------------------------------- | ----------------- | |Promise<string> | Promise对象,返回图片或视频资源的编辑数据。 | **错误码:** 接口抛出错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)和[文件管理错误码](../apis-core-file-kit/errorcode-filemanagement.md)。 | 错误码ID | 错误信息 | | -------- | ---------------------------------------- | | 201 | Permission denied. | | 202 | Called by non-system application. | | 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types. | | 14000011 | System inner fail. Possible causes: 1. The database is corrupted; 2. The file system is abnormal; 3. The IPC request timed out; 4. Permission denied. | **示例:** phAccessHelper的创建请参考[@ohos.file.photoAccessHelper (相册管理模块)](arkts-apis-photoAccessHelper-f.md)的示例使用。 ```ts import { dataSharePredicates } from '@kit.ArkData'; async function example(phAccessHelper: photoAccessHelper.PhotoAccessHelper) { try { console.info('requestEditDataPromiseDemo') let predicates: dataSharePredicates.DataSharePredicates = new dataSharePredicates.DataSharePredicates(); let fetchOptions: photoAccessHelper.FetchOptions = { fetchColumns: [], predicates: predicates }; let fetchResult: photoAccessHelper.FetchResult = await phAccessHelper.getAssets(fetchOptions); let photoAsset: photoAccessHelper.PhotoAsset = await fetchResult.getFirstObject(); let editdata: string = await photoAsset.requestEditData(); console.info('Editdata is ' + editdata); } catch (err) { console.error(`requestEditDataPromiseDemo failed with error: ${err.code}, ${err.message}`); } } ``` ### getEditData11+ getEditData(): Promise<MediaAssetEditData> 获得资产编辑数据,该方法使用promise形式来返回结果。 如果资源未编辑过,则返回的编辑数据的内容为空字符串。 **系统接口**:此接口为系统接口。 **需要权限**:ohos.permission.READ_IMAGEVIDEO **系统能力**:SystemCapability.FileManagement.PhotoAccessHelper.Core **返回值:** | 类型 | 说明 | | --------------------------------------- | ----------------- | |Promise<[MediaAssetEditData](#mediaasseteditdata11)> | Promise对象,返回资产编辑数据。 | **错误码:** 接口抛出错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)和[文件管理错误码](../apis-core-file-kit/errorcode-filemanagement.md)。 | 错误码ID | 错误信息 | | -------- | ---------------------------------------- | | 201 | Permission denied. | | 202 | Called by non-system application. | | 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types. | | 14000011 | System inner fail. Possible causes: 1. The database is corrupted; 2. The file system is abnormal; 3. The IPC request timed out; 4. Permission denied. | **示例:** phAccessHelper的创建请参考[@ohos.file.photoAccessHelper (相册管理模块)](arkts-apis-photoAccessHelper-f.md)的示例使用。 ```ts import { dataSharePredicates } from '@kit.ArkData'; async function example(phAccessHelper: photoAccessHelper.PhotoAccessHelper) { try { console.info('getEditDataDemo') let predicates: dataSharePredicates.DataSharePredicates = new dataSharePredicates.DataSharePredicates(); let fetchOptions: photoAccessHelper.FetchOptions = { fetchColumns: [], predicates: predicates }; let fetchResult: photoAccessHelper.FetchResult = await phAccessHelper.getAssets(fetchOptions); let photoAsset: photoAccessHelper.PhotoAsset = await fetchResult.getFirstObject(); let assetEditData: photoAccessHelper.MediaAssetEditData = await photoAsset.getEditData(); let data: string = assetEditData.data; console.info('edit data is ' + data); } catch (err) { console.error(`getEditDataDemo failed with error: ${err.code}, ${err.message}`); } } ``` ### requestSource11+ requestSource(callback: AsyncCallback<number>): void 打开源文件并返回fd,该方法使用callback形式来返回结果。 **系统接口**:此接口为系统接口。 **需要权限**:ohos.permission.READ_IMAGEVIDEO **系统能力**:SystemCapability.FileManagement.PhotoAccessHelper.Core **参数:** | 参数名 | 类型 | 必填 | 说明 | | ---------- | ------- | ---- | ---------------------------------- | | callback | AsyncCallback<number> | 是 | Callback对象,返回源文件fd。 | **错误码:** 接口抛出错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)和[文件管理错误码](../apis-core-file-kit/errorcode-filemanagement.md)。 | 错误码ID | 错误信息 | | -------- | ---------------------------------------- | | 201 | Permission denied. | | 202 | Called by non-system application. | | 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types. | | 14000011 | System inner fail. Possible causes: 1. The database is corrupted; 2. The file system is abnormal; 3. The IPC request timed out; 4. Permission denied. | **示例:** phAccessHelper的创建请参考[@ohos.file.photoAccessHelper (相册管理模块)](arkts-apis-photoAccessHelper-f.md)的示例使用。 ```ts import { dataSharePredicates } from '@kit.ArkData'; async function example(phAccessHelper: photoAccessHelper.PhotoAccessHelper) { try { console.info('requestSourceCallbackDemo') let predicates: dataSharePredicates.DataSharePredicates = new dataSharePredicates.DataSharePredicates(); let fetchOptions: photoAccessHelper.FetchOptions = { fetchColumns: [], predicates: predicates }; let fetchResult: photoAccessHelper.FetchResult = await phAccessHelper.getAssets(fetchOptions); let photoAsset: photoAccessHelper.PhotoAsset = await fetchResult.getFirstObject(); photoAsset.requestSource((err, fd) => { if (err === undefined) { console.info('Source fd is ' + fd); } else { console.error(`requestSource failed with error: ${err.code}, ${err.message}`); } }); } catch (err) { console.error(`requestSourceCallbackDemo failed with error: ${err.code}, ${err.message}`); } } ``` ### requestSource11+ requestSource(): Promise<number> 打开源文件并返回fd,该方法使用promise形式来返回结果。 **系统接口**:此接口为系统接口。 **需要权限**:ohos.permission.READ_IMAGEVIDEO **系统能力**:SystemCapability.FileManagement.PhotoAccessHelper.Core **返回值:** | 类型 | 说明 | | --------------------------------------- | ----------------- | |Promise<number> | Promise对象,返回源文件fd。 | **错误码:** 接口抛出错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)和[文件管理错误码](../apis-core-file-kit/errorcode-filemanagement.md)。 | 错误码ID | 错误信息 | | -------- | ---------------------------------------- | | 201 | Permission denied. | | 202 | Called by non-system application. | | 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types. | | 14000011 | System inner fail. Possible causes: 1. The database is corrupted; 2. The file system is abnormal; 3. The IPC request timed out; 4. Permission denied. | **示例:** phAccessHelper的创建请参考[@ohos.file.photoAccessHelper (相册管理模块)](arkts-apis-photoAccessHelper-f.md)的示例使用。 ```ts import { dataSharePredicates } from '@kit.ArkData'; async function example(phAccessHelper: photoAccessHelper.PhotoAccessHelper) { try { console.info('requestSourcePromiseDemo') let predicates: dataSharePredicates.DataSharePredicates = new dataSharePredicates.DataSharePredicates(); let fetchOptions: photoAccessHelper.FetchOptions = { fetchColumns: [], predicates: predicates }; let fetchResult: photoAccessHelper.FetchResult = await phAccessHelper.getAssets(fetchOptions); let photoAsset: photoAccessHelper.PhotoAsset = await fetchResult.getFirstObject(); let fd = await photoAsset.requestSource(); console.info('Source fd is ' + fd); } catch (err) { console.error(`requestSourcePromiseDemo failed with error: ${err.code}, ${err.message}`); } } ``` ### commitEditedAsset11+ commitEditedAsset(editData: string, uri: string, callback: AsyncCallback<void>) 提交编辑数据以及编辑后的图片或视频,该方法使用callback形式来返回结果。 通过uri将编辑后的文件传递给媒体库,uri是编辑后的文件在应用沙箱下的FileUri,可参考[FileUri](../apis-core-file-kit/js-apis-file-fileuri.md)。 **注意**:新的编辑数据提交后,将覆盖掉原来的编辑数据。 **系统接口**:此接口为系统接口。 **需要权限**:ohos.permission.WRITE_IMAGEVIDEO **系统能力**:SystemCapability.FileManagement.PhotoAccessHelper.Core **参数:** | 参数名 | 类型 | 必填 | 说明 | | ---------- | ------- | ---- | ---------------------------------- | | editData | string | 是 | 提交的编辑数据。 | | uri | string | 是 | 提交的编辑后的图片或视频,在应用沙箱下的uri。 | | callback | AsyncCallback<void> | 是 | Callback对象,返回void。 | **错误码:** 接口抛出错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)和[文件管理错误码](../apis-core-file-kit/errorcode-filemanagement.md)。 | 错误码ID | 错误信息 | | -------- | ---------------------------------------- | | 201 | Permission denied. | | 202 | Called by non-system application. | | 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types; 3. Parameter verification failed. | | 14000011 | System inner fail. Possible causes: 1. The database is corrupted; 2. The file system is abnormal; 3. The IPC request timed out; 4. Permission denied. | **示例:** phAccessHelper的创建请参考[@ohos.file.photoAccessHelper (相册管理模块)](arkts-apis-photoAccessHelper-f.md)的示例使用。 ```ts import { dataSharePredicates } from '@kit.ArkData'; async function example(phAccessHelper: photoAccessHelper.PhotoAccessHelper) { try { console.info('commitEditedAssetCallbackDemo') let predicates: dataSharePredicates.DataSharePredicates = new dataSharePredicates.DataSharePredicates(); let fetchOptions: photoAccessHelper.FetchOptions = { fetchColumns: [], predicates: predicates }; let fetchResult: photoAccessHelper.FetchResult = await phAccessHelper.getAssets(fetchOptions); let photoAsset: photoAccessHelper.PhotoAsset = await fetchResult.getFirstObject(); let editData = '123456'; let uri = 'file://com.example.temptest/data/storage/el2/base/haps/entry/files/test.jpg'; photoAsset.commitEditedAsset(editData, uri, (err) => { if (err === undefined) { console.info('commitEditedAsset is successful'); } else { console.error(`commitEditedAsset failed with error: ${err.code}, ${err.message}`); } }); } catch (err) { console.error(`commitEditedAssetCallbackDemo failed with error: ${err.code}, ${err.message}`); } } ``` ### commitEditedAsset11+ commitEditedAsset(editData: string, uri: string): Promise<void> 提交编辑数据以及编辑后的图片或视频,该方法使用promise形式来返回结果。 通过uri将编辑后的文件传递给媒体库,uri是编辑后的文件在应用沙箱下的FileUri,可参考[FileUri](../apis-core-file-kit/js-apis-file-fileuri.md)。 **注意**:新的编辑数据提交后,将覆盖掉原来的编辑数据。 **系统接口**:此接口为系统接口。 **需要权限**:ohos.permission.WRITE_IMAGEVIDEO **系统能力**:SystemCapability.FileManagement.PhotoAccessHelper.Core **参数:** | 参数名 | 类型 | 必填 | 说明 | | ---------- | ------- | ---- | ---------------------------------- | | editData | string | 是 | 提交的编辑数据。 | | uri | string | 是 | 提交的编辑后的图片或视频,在应用沙箱下的uri。 | **返回值:** | 类型 | 说明 | | --------------------------------------- | ----------------- | |Promise<void> | Promise对象,返回void。 | **错误码:** 接口抛出错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)和[文件管理错误码](../apis-core-file-kit/errorcode-filemanagement.md)。 | 错误码ID | 错误信息 | | -------- | ---------------------------------------- | | 201 | Permission denied. | | 202 | Called by non-system application. | | 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types; 3. Parameter verification failed. | | 14000011 | System inner fail. Possible causes: 1. The database is corrupted; 2. The file system is abnormal; 3. The IPC request timed out; 4. Permission denied. | **示例:** phAccessHelper的创建请参考[@ohos.file.photoAccessHelper (相册管理模块)](arkts-apis-photoAccessHelper-f.md)的示例使用。 ```ts import { dataSharePredicates } from '@kit.ArkData'; async function example(phAccessHelper: photoAccessHelper.PhotoAccessHelper) { try { console.info('commitEditedAssetPromiseDemo') let predicates: dataSharePredicates.DataSharePredicates = new dataSharePredicates.DataSharePredicates(); let fetchOptions: photoAccessHelper.FetchOptions = { fetchColumns: [], predicates: predicates }; let fetchResult: photoAccessHelper.FetchResult = await phAccessHelper.getAssets(fetchOptions); let photoAsset: photoAccessHelper.PhotoAsset = await fetchResult.getFirstObject(); let editData = '123456'; let uri = 'file://com.example.temptest/data/storage/el2/base/haps/entry/files/test.jpg'; await photoAsset.commitEditedAsset(editData, uri); console.info('commitEditedAsset is successful'); } catch (err) { console.error(`commitEditedAssetPromiseDemo failed with error: ${err.code}, ${err.message}`); } } ``` ### revertToOriginal11+ revertToOriginal(callback: AsyncCallback<void>) 回退到编辑前的状态,该方法使用callback形式来返回结果。 **注意**:调用该接口后,编辑数据和编辑后的图片或视频资源都将被删除,无法恢复,请谨慎调用。 **系统接口**:此接口为系统接口。 **需要权限**:ohos.permission.WRITE_IMAGEVIDEO **系统能力**:SystemCapability.FileManagement.PhotoAccessHelper.Core **参数:** | 参数名 | 类型 | 必填 | 说明 | | ---------- | ------- | ---- | ---------------------------------- | | callback | AsyncCallback<void> | 是 | Callback对象,返回void。 | **错误码:** 接口抛出错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)和[文件管理错误码](../apis-core-file-kit/errorcode-filemanagement.md)。 | 错误码ID | 错误信息 | | -------- | ---------------------------------------- | | 201 | Permission denied. | | 202 | Called by non-system application. | | 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types. | | 14000011 | System inner fail. | **示例:** phAccessHelper的创建请参考[@ohos.file.photoAccessHelper (相册管理模块)](arkts-apis-photoAccessHelper-f.md)的示例使用。 ```ts import { dataSharePredicates } from '@kit.ArkData'; async function example(phAccessHelper: photoAccessHelper.PhotoAccessHelper) { try { console.info('revertToOriginalCallbackDemo') let predicates: dataSharePredicates.DataSharePredicates = new dataSharePredicates.DataSharePredicates(); let fetchOptions: photoAccessHelper.FetchOptions = { fetchColumns: [], predicates: predicates }; let fetchResult: photoAccessHelper.FetchResult = await phAccessHelper.getAssets(fetchOptions); let photoAsset: photoAccessHelper.PhotoAsset = await fetchResult.getFirstObject(); photoAsset.revertToOriginal((err) => { if (err === undefined) { console.info('revertToOriginal is successful'); } else { console.error(`revertToOriginal failed with error: ${err.code}, ${err.message}`); } }); } catch (err) { console.error(`revertToOriginalCallbackDemo failed with error: ${err.code}, ${err.message}`); } } ``` ### revertToOriginal11+ revertToOriginal(): Promise<void> 回退到编辑前的状态,该方法使用promise形式来返回结果。 **注意**:调用该接口后,编辑数据和编辑后的图片或视频资源都将被删除,无法恢复,请谨慎调用。 **系统接口**:此接口为系统接口。 **需要权限**:ohos.permission.WRITE_IMAGEVIDEO **系统能力**:SystemCapability.FileManagement.PhotoAccessHelper.Core **返回值:** | 类型 | 说明 | | --------------------------------------- | ----------------- | |Promise<string> | Promise对象,返回void。 | **错误码:** 接口抛出错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)和[文件管理错误码](../apis-core-file-kit/errorcode-filemanagement.md)。 | 错误码ID | 错误信息 | | -------- | ---------------------------------------- | | 201 | Permission denied. | | 202 | Called by non-system application. | | 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types. | | 14000011 | System inner fail. | **示例:** phAccessHelper的创建请参考[@ohos.file.photoAccessHelper (相册管理模块)](arkts-apis-photoAccessHelper-f.md)的示例使用。 ```ts import { dataSharePredicates } from '@kit.ArkData'; async function example(phAccessHelper: photoAccessHelper.PhotoAccessHelper) { try { console.info('revertToOriginalPromiseDemo') let predicates: dataSharePredicates.DataSharePredicates = new dataSharePredicates.DataSharePredicates(); let fetchOptions: photoAccessHelper.FetchOptions = { fetchColumns: [], predicates: predicates }; let fetchResult: photoAccessHelper.FetchResult = await phAccessHelper.getAssets(fetchOptions); let photoAsset: photoAccessHelper.PhotoAsset = await fetchResult.getFirstObject(); photoAsset.revertToOriginal(); console.info('revertToOriginal is successful'); } catch (err) { console.error(`revertToOriginalPromiseDemo failed with error: ${err.code}, ${err.message}`); } } ``` ### requestPhoto11+ requestPhoto(callback: AsyncCallback<image.PixelMap>): string 通过callback的形式,获取资源的快速缩略图和普通缩略图。 快速缩略图尺寸为128\*128,普通缩略图尺寸为256\*256。应用调用接口后,callback将返回两次缩略图对象,第一次为快速缩略图,第二次为普通缩略图。 **系统接口**:此接口为系统接口。 **需要权限**:ohos.permission.READ_IMAGEVIDEO **系统能力**:SystemCapability.FileManagement.PhotoAccessHelper.Core **参数:** | 参数名 | 类型 | 必填 | 说明 | | ---------- | ------- | ---- | ---------------------------------- | | callback | AsyncCallback<[image.PixelMap](../apis-image-kit/arkts-apis-image-PixelMap.md)> | 是 | Callback对象,返回获取的缩略图,调用2次。 | **返回值:** | 类型 | 说明 | | --------------------------------------- | ----------------- | | string | 本次获取任务的id。 | **错误码:** 接口抛出错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)和[文件管理错误码](../apis-core-file-kit/errorcode-filemanagement.md)。 | 错误码ID | 错误信息 | | -------- | ---------------------------------------- | | 201 | Permission verification failed, usually the result returned by VerifyAccessToken. | | 202 | Permission verification failed, application which is not a system application uses system API. | | 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types. | | 14000011 | System inner fail. | **示例:** phAccessHelper的创建请参考[@ohos.file.photoAccessHelper (相册管理模块)](arkts-apis-photoAccessHelper-f.md)的示例使用。 ```ts import { dataSharePredicates } from '@kit.ArkData'; import { image } from '@kit.ImageKit'; async function example(phAccessHelper: photoAccessHelper.PhotoAccessHelper) { try { console.info('requestPhotoDemo') let options: photoAccessHelper.FetchOptions = { fetchColumns: [], predicates: new dataSharePredicates.DataSharePredicates() } let fetchResult = await phAccessHelper.getAssets(options); let photoAsset = await fetchResult.getFirstObject(); let taskId: string = photoAsset.requestPhoto(async (err, pixel: image.PixelMap) => { if (err === undefined) { console.info("requestSource in, size: " + JSON.stringify((await pixel.getImageInfo()).size)) } else { console.error(`requestSource failed with error: ${err.code}, ${err.message}`); } }) console.info('requestSource taskId: ' + taskId) } catch (err) { console.error(`requestPhotoDemo failed with error: ${err.code}, ${err.message}`); } } ``` ### requestPhoto11+ requestPhoto(options: RequestPhotoOptions, callback: AsyncCallback<image.PixelMap>): string 通过callback的形式,根据传入的选项,获取资源的缩略图。 **系统接口**:此接口为系统接口。 **需要权限**:ohos.permission.READ_IMAGEVIDEO **系统能力**:SystemCapability.FileManagement.PhotoAccessHelper.Core **参数:** | 参数名 | 类型 | 必填 | 说明 | | ---------- | ------- | ---- | ---------------------------------- | | options | [RequestPhotoOptions](#requestphotooptions11) | 是 | 获取资源缩略图的选项。 | | callback | AsyncCallback<[image.PixelMap](../apis-image-kit/arkts-apis-image-PixelMap.md)> | 是 | Callback对象,返回获取的缩略图,根据选项的设置可能调用超过1次。 | **返回值:** | 类型 | 说明 | | --------------------------------------- | ----------------- | | string | 本次获取任务的id。 | **错误码:** 接口抛出错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)和[文件管理错误码](../apis-core-file-kit/errorcode-filemanagement.md)。 | 错误码ID | 错误信息 | | -------- | ---------------------------------------- | | 201 | Permission verification failed, usually the result returned by VerifyAccessToken. | | 202 | Permission verification failed, application which is not a system application uses system API. | | 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types; 3. Parameter verification failed. | | 14000011 | System inner fail. | **示例:** phAccessHelper的创建请参考[@ohos.file.photoAccessHelper (相册管理模块)](arkts-apis-photoAccessHelper-f.md)的示例使用。 ```ts import { dataSharePredicates } from '@kit.ArkData'; import { image } from '@kit.ImageKit'; async function example(phAccessHelper: photoAccessHelper.PhotoAccessHelper) { try { console.info('requestPhotoDemo') let options: photoAccessHelper.FetchOptions = { fetchColumns: [], predicates: new dataSharePredicates.DataSharePredicates() } let fetchResult = await phAccessHelper.getAssets(options); let photoAsset = await fetchResult.getFirstObject(); let taskId: string = photoAsset.requestPhoto({ "size": { "width": 256, "height": 256 }, "requestPhotoType": photoAccessHelper.RequestPhotoType.REQUEST_ALL_THUMBNAILS }, async (err, pixel: image.PixelMap) => { if (err === undefined) { console.info("requestSource in, size: " + JSON.stringify((await pixel.getImageInfo()).size)) } else { console.error(`requestSource failed with error: ${err.code}, ${err.message}`); } }) console.info('requestSource taskId: ' + taskId) } catch (err) { console.error(`requestPhotoDemo failed with error: ${err.code}, ${err.message}`); } } ``` ### cancelPhotoRequest11+ cancelPhotoRequest(requestId: string): void 根据id取消指定的获取媒体缩略图的任务。 **系统接口**:此接口为系统接口。 **需要权限**:ohos.permission.READ_IMAGEVIDEO **系统能力**:SystemCapability.FileManagement.PhotoAccessHelper.Core **参数:** | 参数名 | 类型 | 必填 | 说明 | | ---------- | ------- | ---- | ---------------------------------- | | requestId | string | 是 | 待取消的获取媒体缩略图的任务id。 | **错误码:** 接口抛出错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)和[文件管理错误码](../apis-core-file-kit/errorcode-filemanagement.md)。 | 错误码ID | 错误信息 | | -------- | ---------------------------------------- | | 201 | Permission verification failed, usually the result returned by VerifyAccessToken. | | 202 | Permission verification failed, application which is not a system application uses system API. | | 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types; 3. Parameter verification failed. | | 14000011 | System inner fail. | **示例:** phAccessHelper的创建请参考[@ohos.file.photoAccessHelper (相册管理模块)](arkts-apis-photoAccessHelper-f.md)的示例使用。 ```ts import { dataSharePredicates } from '@kit.ArkData'; import { image } from '@kit.ImageKit'; async function example(phAccessHelper: photoAccessHelper.PhotoAccessHelper) { try { console.info('cancelPhotoRequestDemo') let options: photoAccessHelper.FetchOptions = { fetchColumns: [], predicates: new dataSharePredicates.DataSharePredicates() } let fetchResult = await phAccessHelper.getAssets(options); let photoAsset = await fetchResult.getFirstObject(); let taskId: string = photoAsset.requestPhoto({ "size": { "width": 256, "height": 256 }, "requestPhotoType": photoAccessHelper.RequestPhotoType.REQUEST_ALL_THUMBNAILS }, async (err, pixel: image.PixelMap) => { if (err === undefined) { console.info("requestSource in, size: " + JSON.stringify((await pixel.getImageInfo()).size)) } else { console.error(`requestSource failed with error: ${err.code}, ${err.message}`); } }) console.info('requestSource taskId: ' + taskId) photoAsset.cancelPhotoRequest(taskId); } catch (err) { console.error(`cancelPhotoRequestDemo failed with error: ${err.code}, ${err.message}`); } } ``` ### getAnalysisData11+ getAnalysisData(analysisType: AnalysisType): Promise\ 根据智慧分析类型获取指定分析结果数据。 **系统接口**:此接口为系统接口。 **需要权限**:ohos.permission.READ\_IMAGEVIDEO **系统能力**:SystemCapability.FileManagement.PhotoAccessHelper.Core **参数:** | 参数名 | 类型 | 必填 | 说明 | | :----------- | :----------- | :- | :----------- | | analysisType | [AnalysisType](#analysistype11) | 是 | 需要获取的智慧分析类型。 | **错误码:** 接口抛出错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)和[文件管理错误码](../apis-core-file-kit/errorcode-filemanagement.md)。 | 错误码ID | 错误信息 | | :------- | :-------------------------------- | | 201 | Permission denied. | | 202 | Called by non-system application. | | 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types; 3. Parameter verification failed. | | 14000011 | System inner fail. | **示例:** phAccessHelper的创建请参考[@ohos.file.photoAccessHelper (相册管理模块)](arkts-apis-photoAccessHelper-f.md)的示例使用。 ```ts import { dataSharePredicates } from '@kit.ArkData'; async function example(phAccessHelper: photoAccessHelper.PhotoAccessHelper) { try { console.info('getAnalysisDataDemo') let fetchOptions: photoAccessHelper.FetchOptions = { fetchColumns: [], predicates: new dataSharePredicates.DataSharePredicates() } let fetchResult: photoAccessHelper.FetchResult = await phAccessHelper.getAssets(fetchOptions); let photoAsset: photoAccessHelper.PhotoAsset = await fetchResult.getFirstObject(); if (photoAsset != undefined) { let analysisData: string = await photoAsset.getAnalysisData( photoAccessHelper.AnalysisType.ANALYSIS_OCR); console.info('get ocr result: ' + JSON.stringify(analysisData)); } fetchResult.close(); } catch (err) { console.error(`getAnalysisDataDemofailed with error: ${err.code}, ${err.message}`); } } ``` ### getThumbnailData18+ getThumbnailData(type: ThumbnailType): Promise<ArrayBuffer> 获取文件缩略图的ArrayBuffer,传入缩略图的类型,使用promise异步回调。 **需要权限**:ohos.permission.READ_IMAGEVIDEO **系统能力**:SystemCapability.FileManagement.PhotoAccessHelper.Core **参数:** | 参数名 | 类型 | 必填 | 说明 | | ---- | -------------- | ---- | ----- | | type | [ThumbnailType](#thumbnailtype13) | 是 | 缩略图类型。 | **返回值:** | 类型 | 说明 | | ----------------------------- | --------------------- | | Promise\ | Promise对象,返回缩略图的ArrayBuffer。 | **错误码:** 以下错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)和[文件管理错误码](../apis-core-file-kit/errorcode-filemanagement.md)。 错误码13900012,请参考[开发准备](../../media/medialibrary/photoAccessHelper-preparation.md)。 | 错误码ID | 错误信息 | | -------- | ---------------------------------------- | | 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types; 3. Parameter verification failed. | | 202 | Called by non-system application. | | 13900012 | Permission denied. | | 13900020 | Invalid argument. | | 14000011 | System inner fail. | **示例:** ```ts import { dataSharePredicates } from '@kit.ArkData'; import { BusinessError } from '@kit.BasicServicesKit'; async function example(phAccessHelper: photoAccessHelper.PhotoAccessHelper) { console.info('getThumbnailDataDemo'); let predicates: dataSharePredicates.DataSharePredicates = new dataSharePredicates.DataSharePredicates(); let fetchOption: photoAccessHelper.FetchOptions = { fetchColumns: [], predicates: predicates }; let fetchResult: photoAccessHelper.FetchResult = await phAccessHelper.getAssets(fetchOption); let asset = await fetchResult.getFirstObject(); console.info('asset displayName = ', asset.displayName); asset.getThumbnailData(photoAccessHelper.ThumbnailType.LCD).then((buffer: ArrayBuffer) => { console.info('getThumbnailData successful, buffer byteLength = ${buffer.byteLength}'); }).catch((err: BusinessError) => { console.error(`getThumbnailData fail with error: ${err.code}, ${err.message}`); }); } ``` ## SharedPhotoAsset13+ 共享图片资产。 **系统接口**:此接口为系统接口。 **系统能力**:SystemCapability.FileManagement.PhotoAccessHelper.Core ### 属性 | 名称 | 类型 | 只读 | 可选 | 说明 | | ---- | --- | ---- | ---- | --- | | fileId | number | 否 | 否 | 图片资产标识id。
**系统接口**:此接口为系统接口。| | uri | string | 否 | 否 | 图片资产uri。
**系统接口**:此接口为系统接口。| | data | string | 否 | 否 | 图片资产的路径数据。
**系统接口**:此接口为系统接口。| | mediaType | [PhotoType](arkts-apis-photoAccessHelper-e.md#phototype) | 否 | 否 | 图片资产的媒体类型。
**系统接口**:此接口为系统接口。| | displayName | string | 否 | 否 | 图片资产的显示名称。
**系统接口**:此接口为系统接口。| | size | number | 否 | 否 | 图片资产文件大小。
**系统接口**:此接口为系统接口。| | dataAdded | number | 否 | 否 | 添加了图片资产数据。
**系统接口**:此接口为系统接口。| | dataModified | number | 否 | 否 | 更改了图片资产数据。
**系统接口**:此接口为系统接口。| | duration | number | 否 | 否 | 视频类型的图片资产时长。
**系统接口**:此接口为系统接口。| | width | number | 否 | 否 | 图片资产的像素宽度。
**系统接口**:此接口为系统接口。| | height | number | 否 | 否 | 图片资产的像素高度。
**系统接口**:此接口为系统接口。| | dataTaken | number | 否 | 否 | 图片资产拍照后存入本地时间。
**系统接口**:此接口为系统接口。| | orientation | number | 否 | 否 | 图片资产的旋转角度。
**系统接口**:此接口为系统接口。| | isFavorite | boolean | 否 | 否 | 是否收藏了此图片。
**系统接口**:此接口为系统接口。| | title | string | 否 | 否 | 图片资产的标题。
**系统接口**:此接口为系统接口。| | position | [PositionType](arkts-apis-photoAccessHelper-e.md#positiontype16) | 否 | 否 | 图片资产存在位置。
**系统接口**:此接口为系统接口。| | dataTrashed | number | 否 | 否 | 图片资产是否在回收站中。
**系统接口**:此接口为系统接口。| | hidden | boolean | 否 | 否 | 图片资产是否隐藏。
**系统接口**:此接口为系统接口。| | userComment | string | 否 | 否 | 图片资产的用户评论信息。
**系统接口**:此接口为系统接口。| | cameraShotKey | string | 否 | 否 | 图片资产相机拍摄信息。
**系统接口**:此接口为系统接口。| | dateYear | string | 否 | 否 | 图片资产创建年份时间。
**系统接口**:此接口为系统接口。| | dateMonth | string | 否 | 否 | 图片资产创建月份时间。
**系统接口**:此接口为系统接口。| | dateDay | string | 否 | 否 | 图片资产创建日时间。
**系统接口**:此接口为系统接口。| | pending | boolean | 否 | 否 | 图片资产等待状态,true为等待。
**系统接口**:此接口为系统接口。| | dateAddedMs | number | 否 | 否 | 图片资产数据添加后经过时间。
**系统接口**:此接口为系统接口。| | dateTrashedMs | number | 否 | 否 | 图片资产数据进回收站后经过时间。
**系统接口**:此接口为系统接口。| | subtype | [PhotoSubtype](#photosubtype) | 否 | 否 | 图片资产子类型。
**系统接口**:此接口为系统接口。| | movingPhotoEffectMode | [MovingPhotoEffectMode](#movingphotoeffectmode12) | 否 | 否 | 动态照片效果模式。
**系统接口**:此接口为系统接口。| | dynamicRangeType | [DynamicRangeType](arkts-apis-photoAccessHelper-e.md#dynamicrangetype12) | 否 | 否 | 媒体文件的动态范围类型。
**系统接口**:此接口为系统接口。| | thumbnailReady | boolean | 否 | 否 | 图片资产的缩略图是否准备好。
**系统接口**:此接口为系统接口。| | lcdSize | string | 否 | 否 | 图片资产的lcd缩略图宽高信息。
**系统接口**:此接口为系统接口。| | thmSize | string | 否 | 否 | 图片资产的thumb缩略图宽高信息。
**系统接口**:此接口为系统接口。| | thumbnailModifiedMs14+ | number | 否 | 是 | 图片资产的缩略图状态改变后经过时间。
**系统接口**:此接口为系统接口。| | thumbnailVisible14+ | [ThumbnailVisibility](#thumbnailvisibility14) | 否 | 否 | 图片资产的缩略图是否可见。
**系统接口**:此接口为系统接口。| ## Album 实体相册 ### 属性 **系统能力**:SystemCapability.FileManagement.PhotoAccessHelper.Core | 名称 | 类型 | 只读 | 可选 | 说明 | | ------------ | ------ | ---- | ---- | ------- | | lpath18+ | string | 是 | 是 | 相册虚拟路径。
**系统接口**:此接口为系统接口。| | dateAdded18+ | number | 是 | 是 | 相册添加时间。
**系统接口**:此接口为系统接口。| | dateModified18+ | number | 是 | 是 | 相册修改时间。
**系统接口**:此接口为系统接口。| | coverUriSource20+ | number | 是 | 是 | 相册封面来源。
**系统接口**:此接口为系统接口。| ### recoverAssets(deprecated) recoverAssets(assets: Array<PhotoAsset>, callback: AsyncCallback<void>): void 从回收站中恢复图片或者视频,需要先在回收站中预置文件资源。该方法使用callback形式来返回结果。 > **说明:** > > 从API version 10开始支持,从API version 11开始废弃。建议使用[MediaAlbumChangeRequest.recoverAssets](#recoverassets11)替代。 **系统接口**:此接口为系统接口。 **需要权限**:ohos.permission.WRITE_IMAGEVIDEO **系统能力**:SystemCapability.FileManagement.PhotoAccessHelper.Core **参数:** | 参数名 | 类型 | 必填 | 说明 | | -------- | ------------------------- | ---- | ---------- | | assets | Array<[PhotoAsset](#photoasset)> | 是 | 回收站中待恢复图片或者视频数组。 | | callback | AsyncCallback<void> | 是 | callback返回void。 | **错误码:** 接口抛出错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)和[文件管理错误码](../apis-core-file-kit/errorcode-filemanagement.md)。 错误码13900012,请参考[开发准备](../../media/medialibrary/photoAccessHelper-preparation.md)。 | 错误码ID | 错误信息 | | -------- | ---------------------------------------- | | 202 | Called by non-system application. | | 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types; 3. Parameter verification failed. | | 13900012 | Permission denied. | | 13900020 | Invalid argument. | | 14000011 | System inner fail. | **示例:** phAccessHelper的创建请参考[@ohos.file.photoAccessHelper (相册管理模块)](arkts-apis-photoAccessHelper-f.md)的示例使用。 ```ts import { dataSharePredicates } from '@kit.ArkData'; async function example(phAccessHelper: photoAccessHelper.PhotoAccessHelper) { try { console.info('recoverAssetsDemoCallback'); let predicates: dataSharePredicates.DataSharePredicates = new dataSharePredicates.DataSharePredicates(); let fetchOption: photoAccessHelper.FetchOptions = { fetchColumns: [], predicates: predicates }; let albumFetchResult: photoAccessHelper.FetchResult = await phAccessHelper.getAlbums(photoAccessHelper.AlbumType.SYSTEM, photoAccessHelper.AlbumSubtype.TRASH); let album: photoAccessHelper.Album = await albumFetchResult.getFirstObject(); let fetchResult: photoAccessHelper.FetchResult = await album.getAssets(fetchOption); let asset: photoAccessHelper.PhotoAsset = await fetchResult.getFirstObject(); album.recoverAssets([asset], (err) => { if (err === undefined) { console.info('album recoverAssets successfully'); } else { console.error(`album recoverAssets failed with error: ${err.code}, ${err.message}`); } }); } catch (err) { console.error(`recoverAssetsDemoCallback failed with error: ${err.code}, ${err.message}`); } } ``` ### recoverAssets(deprecated) recoverAssets(assets: Array<PhotoAsset>): Promise<void> 从回收站中恢复图片或者视频,需要先在回收站中预置文件资源。该方法使用Promise来返回结果。 > **说明:** > > 从API version 10开始支持,从API version 11开始废弃。建议使用[MediaAlbumChangeRequest.recoverAssets](#recoverassets11)替代。 **系统接口**:此接口为系统接口。 **需要权限**:ohos.permission.WRITE_IMAGEVIDEO **系统能力**:SystemCapability.FileManagement.PhotoAccessHelper.Core **参数:** | 参数名 | 类型 | 必填 | 说明 | | -------- | ------------------------- | ---- | ---------- | | assets | Array<[PhotoAsset](#photoasset)> | 是 | 回收站中待恢复图片或者视频数组。 | **返回值:** | 类型 | 说明 | | --------------------------------------- | ----------------- | |Promise<void> | Promise对象,返回void。 | **错误码:** 接口抛出错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)和[文件管理错误码](../apis-core-file-kit/errorcode-filemanagement.md)。 错误码13900012,请参考[开发准备](../../media/medialibrary/photoAccessHelper-preparation.md)。 | 错误码ID | 错误信息 | | -------- | ---------------------------------------- | | 202 | Called by non-system application. | | 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types; 3. Parameter verification failed. | | 13900012 | Permission denied. | | 13900020 | Invalid argument. | | 14000011 | System inner fail. | **示例:** phAccessHelper的创建请参考[@ohos.file.photoAccessHelper (相册管理模块)](arkts-apis-photoAccessHelper-f.md)的示例使用。 ```ts import { dataSharePredicates } from '@kit.ArkData'; import { BusinessError } from '@kit.BasicServicesKit'; async function example(phAccessHelper: photoAccessHelper.PhotoAccessHelper) { try { console.info('recoverAssetsDemoPromise'); let predicates: dataSharePredicates.DataSharePredicates = new dataSharePredicates.DataSharePredicates(); let fetchOption: photoAccessHelper.FetchOptions = { fetchColumns: [], predicates: predicates }; let albumFetchResult: photoAccessHelper.FetchResult = await phAccessHelper.getAlbums(photoAccessHelper.AlbumType.SYSTEM, photoAccessHelper.AlbumSubtype.TRASH); let album: photoAccessHelper.Album = await albumFetchResult.getFirstObject(); let fetchResult: photoAccessHelper.FetchResult = await album.getAssets(fetchOption); let asset: photoAccessHelper.PhotoAsset = await fetchResult.getFirstObject(); album.recoverAssets([asset]).then(() => { console.info('album recoverAssets successfully'); }).catch((err: BusinessError) => { console.error(`album recoverAssets failed with error: ${err.code}, ${err.message}`); }); } catch (err) { console.error(`recoverAssetsDemoPromise failed with error: ${err.code}, ${err.message}`); } } ``` ### deleteAssets(deprecated) deleteAssets(assets: Array<PhotoAsset>, callback: AsyncCallback<void>): void 从回收站中彻底删除图片或者视频,需要先在回收站中预置文件资源。该方法使用callback形式来返回结果。 > **说明:** > > 从API version 10开始支持,从API version 11开始废弃。建议使用[MediaAlbumChangeRequest.deleteAssets](#deleteassets11)替代。 **注意**:此操作不可逆,执行此操作后文件资源将彻底删除,请谨慎操作。 **系统接口**:此接口为系统接口。 **需要权限**:ohos.permission.WRITE_IMAGEVIDEO **系统能力**:SystemCapability.FileManagement.PhotoAccessHelper.Core **参数:** | 参数名 | 类型 | 必填 | 说明 | | -------- | ------------------------- | ---- | ---------- | | assets | Array<[PhotoAsset](#photoasset)> | 是 | 回收站中待彻底删除图片或者视频数组。 | | callback | AsyncCallback<void> | 是 | callback返回void。 | **错误码:** 接口抛出错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)和[文件管理错误码](../apis-core-file-kit/errorcode-filemanagement.md)。 错误码13900012,请参考[开发准备](../../media/medialibrary/photoAccessHelper-preparation.md)。 | 错误码ID | 错误信息 | | -------- | ---------------------------------------- | | 202 | Called by non-system application. | | 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types; 3. Parameter verification failed. | | 13900012 | Permission denied. | | 13900020 | Invalid argument. | | 14000011 | System inner fail. | **示例:** phAccessHelper的创建请参考[@ohos.file.photoAccessHelper (相册管理模块)](arkts-apis-photoAccessHelper-f.md)的示例使用。 ```ts import { dataSharePredicates } from '@kit.ArkData'; async function example(phAccessHelper: photoAccessHelper.PhotoAccessHelper) { try { console.info('deleteAssetsDemoCallback'); let predicates: dataSharePredicates.DataSharePredicates = new dataSharePredicates.DataSharePredicates(); let fetchOption: photoAccessHelper.FetchOptions = { fetchColumns: [], predicates: predicates }; let albumFetchResult: photoAccessHelper.FetchResult = await phAccessHelper.getAlbums(photoAccessHelper.AlbumType.SYSTEM, photoAccessHelper.AlbumSubtype.TRASH); let album: photoAccessHelper.Album = await albumFetchResult.getFirstObject(); let fetchResult: photoAccessHelper.FetchResult = await album.getAssets(fetchOption); let asset: photoAccessHelper.PhotoAsset = await fetchResult.getFirstObject(); album.deleteAssets([asset], (err) => { if (err === undefined) { console.info('album deleteAssets successfully'); } else { console.error(`album deleteAssets failed with error: ${err.code}, ${err.message}`); } }); } catch (err) { console.error(`deleteAssetsDemoCallback failed with error: ${err.code}, ${err.message}`); } } ``` ### deleteAssets(deprecated) deleteAssets(assets: Array<PhotoAsset>): Promise<void> 从回收站中彻底删除图片或者视频,需要先在回收站中预置文件资源,建议删除数量不超过1000张。该方法使用Promise来返回结果。 > **说明:** > > 从API version 10开始支持,从API version 11开始废弃。建议使用[MediaAlbumChangeRequest.deleteAssets](#deleteassets11)替代。 **注意**:此操作不可逆,执行此操作后文件资源将彻底删除,请谨慎操作。 **系统接口**:此接口为系统接口。 **需要权限**:ohos.permission.WRITE_IMAGEVIDEO **系统能力**:SystemCapability.FileManagement.PhotoAccessHelper.Core **参数:** | 参数名 | 类型 | 必填 | 说明 | | -------- | ------------------------- | ---- | ---------- | | assets | Array<[PhotoAsset](#photoasset)> | 是 | 回收站中待彻底删除图片或者视频数组。 | **返回值:** | 类型 | 说明 | | --------------------------------------- | ----------------- | |Promise<void> | Promise对象,返回void。 | **错误码:** 接口抛出错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)和[文件管理错误码](../apis-core-file-kit/errorcode-filemanagement.md)。 错误码13900012,请参考[开发准备](../../media/medialibrary/photoAccessHelper-preparation.md)。 | 错误码ID | 错误信息 | | -------- | ---------------------------------------- | | 202 | Called by non-system application. | | 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types; 3. Parameter verification failed. | | 13900012 | Permission denied. | | 13900020 | Invalid argument. | | 14000011 | System inner fail. | **示例:** phAccessHelper的创建请参考[@ohos.file.photoAccessHelper (相册管理模块)](arkts-apis-photoAccessHelper-f.md)的示例使用。 ```ts import { dataSharePredicates } from '@kit.ArkData'; import { BusinessError } from '@kit.BasicServicesKit'; async function example(phAccessHelper: photoAccessHelper.PhotoAccessHelper) { try { console.info('deleteAssetsDemoPromise'); let predicates: dataSharePredicates.DataSharePredicates = new dataSharePredicates.DataSharePredicates(); let fetchOption: photoAccessHelper.FetchOptions = { fetchColumns: [], predicates: predicates }; let albumFetchResult: photoAccessHelper.FetchResult = await phAccessHelper.getAlbums(photoAccessHelper.AlbumType.SYSTEM, photoAccessHelper.AlbumSubtype.TRASH); let album: photoAccessHelper.Album = await albumFetchResult.getFirstObject(); let fetchResult: photoAccessHelper.FetchResult = await album.getAssets(fetchOption); let asset: photoAccessHelper.PhotoAsset = await fetchResult.getFirstObject(); album.deleteAssets([asset]).then(() => { console.info('album deleteAssets successfully'); }).catch((err: BusinessError) => { console.error(`album deleteAssets failed with error: ${err.code}, ${err.message}`); }); } catch (err) { console.error(`deleteAssetsDemoPromise failed with error: ${err.code}, ${err.message}`); } } ``` ### setCoverUri(deprecated) setCoverUri(uri: string, callback: AsyncCallback<void>): void 设置相册封面,该方法使用callback形式来返回结果。 > **说明:** > > 从API version 10开始支持,从API version 11开始废弃。建议使用[MediaAlbumChangeRequest.setCoverUri](#setcoveruri11)替代。 **注意**:此接口只可修改用户相册封面,不允许修改系统相册封面。 **系统接口**:此接口为系统接口。 **需要权限**:ohos.permission.WRITE_IMAGEVIDEO **系统能力**:SystemCapability.FileManagement.PhotoAccessHelper.Core **参数:** | 参数名 | 类型 | 必填 | 说明 | | -------- | ------------------------- | ---- | ---------- | | uri | string | 是 | 待设置为相册封面文件的uri。 | | callback | AsyncCallback<void> | 是 | callback返回void。 | **错误码:** 接口抛出错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)和[文件管理错误码](../apis-core-file-kit/errorcode-filemanagement.md)。 错误码13900012,请参考[开发准备](../../media/medialibrary/photoAccessHelper-preparation.md)。 | 错误码ID | 错误信息 | | -------- | ---------------------------------------- | | 202 | Called by non-system application. | | 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types; 3. Parameter verification failed. | | 13900012 | Permission denied. | | 13900020 | Invalid argument. | | 14000011 | System inner fail. | **示例:** phAccessHelper的创建请参考[@ohos.file.photoAccessHelper (相册管理模块)](arkts-apis-photoAccessHelper-f.md)的示例使用。 ```ts import { dataSharePredicates } from '@kit.ArkData'; async function example(phAccessHelper: photoAccessHelper.PhotoAccessHelper) { try { console.info('setCoverUriDemoCallback'); let predicates: dataSharePredicates.DataSharePredicates = new dataSharePredicates.DataSharePredicates(); let fetchOption: photoAccessHelper.FetchOptions = { fetchColumns: [], predicates: predicates }; let albumFetchResult: photoAccessHelper.FetchResult = await phAccessHelper.getAlbums(photoAccessHelper.AlbumType.USER, photoAccessHelper.AlbumSubtype.USER_GENERIC); let album: photoAccessHelper.Album = await albumFetchResult.getFirstObject(); let fetchResult: photoAccessHelper.FetchResult = await album.getAssets(fetchOption); let asset: photoAccessHelper.PhotoAsset = await fetchResult.getFirstObject(); album.setCoverUri(asset.uri, (err) => { if (err === undefined) { console.info('album setCoverUri successfully'); } else { console.error(`album setCoverUri failed with error: ${err.code}, ${err.message}`); } }); } catch (err) { console.error(`setCoverUriDemoCallback failed with error: ${err.code}, ${err.message}`); } } ``` ### setCoverUri(deprecated) setCoverUri(uri: string): Promise<void> 设置相册封面,该方法使用Promise来返回结果。 > **说明:** > > 从API version 10开始支持,从API version 11开始废弃。建议使用[MediaAlbumChangeRequest.setCoverUri](#setcoveruri11)替代。 **注意**:此接口只可修改用户相册封面,不允许修改系统相册封面。 **系统接口**:此接口为系统接口。 **需要权限**:ohos.permission.WRITE_IMAGEVIDEO **系统能力**:SystemCapability.FileManagement.PhotoAccessHelper.Core **参数:** | 参数名 | 类型 | 必填 | 说明 | | -------- | ------------------------- | ---- | ---------- | | uri | string | 是 | 待设置为相册封面文件的uri。 | **返回值:** | 类型 | 说明 | | --------------------------------------- | ----------------- | |Promise<void> | Promise对象,返回void。 | **错误码:** 接口抛出错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)和[文件管理错误码](../apis-core-file-kit/errorcode-filemanagement.md)。 错误码13900012,请参考[开发准备](../../media/medialibrary/photoAccessHelper-preparation.md)。 | 错误码ID | 错误信息 | | -------- | ---------------------------------------- | | 202 | Called by non-system application. | | 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types; 3. Parameter verification failed. | | 13900012 | Permission denied. | | 13900020 | Invalid argument. | | 14000011 | System inner fail. | **示例:** phAccessHelper的创建请参考[@ohos.file.photoAccessHelper (相册管理模块)](arkts-apis-photoAccessHelper-f.md)的示例使用。 ```ts import { dataSharePredicates } from '@kit.ArkData'; import { BusinessError } from '@kit.BasicServicesKit'; async function example(phAccessHelper: photoAccessHelper.PhotoAccessHelper) { try { console.info('setCoverUriDemoPromise'); let predicates: dataSharePredicates.DataSharePredicates = new dataSharePredicates.DataSharePredicates(); let fetchOption: photoAccessHelper.FetchOptions = { fetchColumns: [], predicates: predicates }; let albumFetchResult: photoAccessHelper.FetchResult = await phAccessHelper.getAlbums(photoAccessHelper.AlbumType.USER, photoAccessHelper.AlbumSubtype.USER_GENERIC); let album: photoAccessHelper.Album = await albumFetchResult.getFirstObject(); let fetchResult: photoAccessHelper.FetchResult = await album.getAssets(fetchOption); let asset: photoAccessHelper.PhotoAsset = await fetchResult.getFirstObject(); album.setCoverUri(asset.uri).then(() => { console.info('album setCoverUri successfully'); }).catch((err: BusinessError) => { console.error(`album setCoverUri failed with error: ${err.code}, ${err.message}`); }); } catch (err) { console.error(`setCoverUriDemoPromise failed with error: ${err.code}, ${err.message}`); } } ``` ### getFaceId13+ getFaceId(): Promise\ 获取人像相册或合影相册的封面人脸标识。 **系统接口**:此接口为系统接口。 **需要权限**:ohos.permission.READ\_IMAGEVIDEO **系统能力**:SystemCapability.FileManagement.PhotoAccessHelper.Core **返回值:** | 类型 | 说明 | | :------------------ | :---------------------------------- | | Promise<string> | Promise对象,人像相册返回tag_id,合影相册返回group_tag,未找到返回空字符串。 | **错误码:** 接口抛出错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)和[文件管理错误码](../apis-core-file-kit/errorcode-filemanagement.md)。 | 错误码ID | 错误信息 | | :------- | :----------------------------------------------------------- | | 201 | Permission denied. | | 202 | Called by non-system application. | | 14000011 | Internal system error | **示例:** phAccessHelper的创建请参考[@ohos.file.photoAccessHelper (相册管理模块)](arkts-apis-photoAccessHelper-f.md)的示例使用。 ```ts import { dataSharePredicates } from '@kit.ArkData'; async function example(phAccessHelper: photoAccessHelper.PhotoAccessHelper) { try { console.info('getFaceIdDemo'); let predicates: dataSharePredicates.DataSharePredicates = new dataSharePredicates.DataSharePredicates(); predicates.equalTo("user_display_level", 1); let fetchOptions: photoAccessHelper.FetchOptions = { fetchColumns: [], predicates: predicates }; let fetchResult = await phAccessHelper.getAlbums(photoAccessHelper.AlbumType.SMART, photoAccessHelper.AlbumSubtype.PORTRAIT, fetchOptions); let album = await fetchResult?.getFirstObject(); let faceId = await album?.getFaceId(); console.info(`getFaceId successfully, faceId: ${faceId}`); fetchResult.close(); } catch (err) { console.error(`getFaceId failed with err: ${err.code}, ${err.message}`); } } ``` ## MediaAssetEditData11+ 资产编辑数据。 **系统接口**:此接口为系统接口。 **系统能力**:SystemCapability.FileManagement.PhotoAccessHelper.Core ### 属性 | 名称 | 类型 | 可读 | 可写 | 说明 | | ------------ | ------ | ---- | ---- | ------- | | compatibleFormat | string | 是 | 是 | 编辑数据的格式。
**系统接口**:此接口为系统接口。 | | formatVersion | string | 是 | 是 | 编辑数据格式的版本。
**系统接口**:此接口为系统接口。 | | data | string | 是 | 是 | 编辑数据的内容。
**系统接口**:此接口为系统接口。 | ### constructor11+ constructor(compatibleFormat: string, formatVersion: string) 构造函数。 **系统接口**:此接口为系统接口。 **系统能力**:SystemCapability.FileManagement.PhotoAccessHelper.Core **参数:** | 参数名 | 类型 | 必填 | 说明 | | -------- | ------------------------- | ---- | ---------- | | compatibleFormat | string | 是 | 编辑数据的格式。 | | formatVersion | string | 是 | 编辑数据格式的版本。 | **错误码:** 接口抛出错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)和[文件管理错误码](../apis-core-file-kit/errorcode-filemanagement.md)。 | 错误码ID | 错误信息 | | -------- | ---------------------------------------- | | 202 | Called by non-system application. | | 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types; 3. Parameter verification failed. | | 14000011 | System inner fail. | **示例:** ```ts let assetEditData: photoAccessHelper.MediaAssetEditData = new photoAccessHelper.MediaAssetEditData('system', '1.0'); ``` ## MediaAssetChangeRequest11+ 资产变更请求。 **系统能力**:SystemCapability.FileManagement.PhotoAccessHelper.Core ### createAssetRequest11+ static createAssetRequest(context: Context, displayName: string, options?: PhotoCreateOptions): MediaAssetChangeRequest 指定待创建的图片或者视频的文件名,创建资产变更请求。 待创建的文件名参数规格为: - 应包含有效文件主名和图片或视频扩展名。 - 文件名字符串长度为1~255。 - 文件主名中不允许出现的非法英文字符。
API18开始,非法字符包括: \ / : * ? " < > |
API10-17,非法字符包括:. .. \ / : * ? " ' ` < > | { } [ ] **系统接口**:此接口为系统接口。 **系统能力**:SystemCapability.FileManagement.PhotoAccessHelper.Core **参数:** | 参数名 | 类型 | 必填 | 说明 | | ------- | ------- | ---- | -------------------------- | | context | [Context](../apis-ability-kit/js-apis-inner-application-context.md) | 是 | 传入Ability实例的Context。 | | displayName | string | 是 | 待创建的图片或者视频文件名。 | | options | [PhotoCreateOptions](#photocreateoptions) | 否 | 图片或视频的创建选项。 | **返回值:** | 类型 | 说明 | | --------------------------------------- | ----------------- | | [MediaAssetChangeRequest](#mediaassetchangerequest11) | 返回创建资产的变更请求。 | **错误码:** 接口抛出错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)和[文件管理错误码](../apis-core-file-kit/errorcode-filemanagement.md)。 错误码14000001,请参考 [PhotoKeys](#photokeys)获取有关文件名的格式和长度要求。 | 错误码ID | 错误信息 | | -------- | ---------------------------------------- | | 202 | Called by non-system application. | | 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types; 3. Parameter verification failed. | | 14000001 | Invalid display name. | | 14000011 | System inner fail. | **示例:** phAccessHelper的创建请参考[@ohos.file.photoAccessHelper (相册管理模块)](arkts-apis-photoAccessHelper-f.md)的示例使用。 ```ts async function example(phAccessHelper: photoAccessHelper.PhotoAccessHelper, context: Context) { console.info('createAssetRequestDemo'); try { let testFileName: string = 'testFile' + Date.now() + '.jpg'; let assetChangeRequest: photoAccessHelper.MediaAssetChangeRequest = photoAccessHelper.MediaAssetChangeRequest.createAssetRequest(context, testFileName); // 需要确保fileUri对应的资源存在。 let fileUri = 'file://com.example.temptest/data/storage/el2/base/haps/entry/files/test.jpg'; assetChangeRequest.addResource(photoAccessHelper.ResourceType.IMAGE_RESOURCE, fileUri); await phAccessHelper.applyChanges(assetChangeRequest); console.info('apply createAssetRequest successfully'); } catch (err) { console.error(`createAssetRequestDemo failed with error: ${err.code}, ${err.message}`); } } ``` ### setFavorite11+ setFavorite(favoriteState: boolean): void 将文件设置为收藏文件。 **系统接口**:此接口为系统接口。 **系统能力**:SystemCapability.FileManagement.PhotoAccessHelper.Core **参数:** | 参数名 | 类型 | 必填 | 说明 | | ---------- | ------- | ---- | ---------------------------------- | | favoriteState | boolean | 是 | 是否设置为收藏文件, true:设置为收藏文件;false:取消收藏。 | **错误码:** 接口抛出错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)和[文件管理错误码](../apis-core-file-kit/errorcode-filemanagement.md)。 | 错误码ID | 错误信息 | | -------- | ---------------------------------------- | | 202 | Called by non-system application. | | 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types; 3. Parameter verification failed. | | 14000011 | System inner fail. | **示例:** phAccessHelper的创建请参考[@ohos.file.photoAccessHelper (相册管理模块)](arkts-apis-photoAccessHelper-f.md)的示例使用。 ```ts import { dataSharePredicates } from '@kit.ArkData'; import { BusinessError } from '@kit.BasicServicesKit'; async function example(phAccessHelper: photoAccessHelper.PhotoAccessHelper) { console.info('setFavoriteDemo'); let predicates: dataSharePredicates.DataSharePredicates = new dataSharePredicates.DataSharePredicates(); let fetchOption: photoAccessHelper.FetchOptions = { fetchColumns: [], predicates: predicates }; let fetchResult: photoAccessHelper.FetchResult = await phAccessHelper.getAssets(fetchOption); let asset = await fetchResult.getFirstObject(); let assetChangeRequest: photoAccessHelper.MediaAssetChangeRequest = new photoAccessHelper.MediaAssetChangeRequest(asset); assetChangeRequest.setFavorite(true); phAccessHelper.applyChanges(assetChangeRequest).then(() => { console.info('apply setFavorite successfully'); }).catch((err: BusinessError) => { console.error(`apply setFavorite failed with error: ${err.code}, ${err.message}`); }); } ``` ### setHidden11+ setHidden(hiddenState: boolean): void 将文件设置为隐藏文件。 **系统接口**:此接口为系统接口。 **系统能力**:SystemCapability.FileManagement.PhotoAccessHelper.Core **参数:** | 参数名 | 类型 | 必填 | 说明 | | ---------- | ------- | ---- | ---------------------------------- | | hiddenState | boolean | 是 | 是否设置为隐藏文件,true:将文件资产放入隐藏相册;false:从隐藏相册中恢复。 | **错误码:** 接口抛出错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)和[文件管理错误码](../apis-core-file-kit/errorcode-filemanagement.md)。 | 错误码ID | 错误信息 | | -------- | ---------------------------------------- | | 202 | Called by non-system application. | | 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types; 3. Parameter verification failed. | | 14000011 | System inner fail. | **示例:** phAccessHelper的创建请参考[@ohos.file.photoAccessHelper (相册管理模块)](arkts-apis-photoAccessHelper-f.md)的示例使用。 ```ts import { dataSharePredicates } from '@kit.ArkData'; import { BusinessError } from '@kit.BasicServicesKit'; async function example(phAccessHelper: photoAccessHelper.PhotoAccessHelper) { console.info('setHiddenDemo'); let predicates: dataSharePredicates.DataSharePredicates = new dataSharePredicates.DataSharePredicates(); let fetchOption: photoAccessHelper.FetchOptions = { fetchColumns: [], predicates: predicates }; let fetchResult: photoAccessHelper.FetchResult = await phAccessHelper.getAssets(fetchOption); let asset = await fetchResult.getFirstObject(); let assetChangeRequest: photoAccessHelper.MediaAssetChangeRequest = new photoAccessHelper.MediaAssetChangeRequest(asset); assetChangeRequest.setHidden(true); phAccessHelper.applyChanges(assetChangeRequest).then(() => { console.info('apply setHidden successfully'); }).catch((err: BusinessError) => { console.error(`apply setHidden failed with error: ${err.code}, ${err.message}`); }); } ``` ### setUserComment11+ setUserComment(userComment: string): void 修改媒体资产的备注信息。 **系统接口**:此接口为系统接口。 **系统能力**:SystemCapability.FileManagement.PhotoAccessHelper.Core **参数:** | 参数名 | 类型 | 必填 | 说明 | | ---------- | ------- | ---- | ---------------------------------- | | userComment | string | 是 | 待修改的资产备注信息,备注信息最长为420字符。 | **错误码:** 接口抛出错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)和[文件管理错误码](../apis-core-file-kit/errorcode-filemanagement.md)。 | 错误码ID | 错误信息 | | -------- | ---------------------------------------- | | 202 | Called by non-system application. | | 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types; 3. Parameter verification failed. | | 14000011 | System inner fail. | **示例:** phAccessHelper的创建请参考[@ohos.file.photoAccessHelper (相册管理模块)](arkts-apis-photoAccessHelper-f.md)的示例使用。 ```ts import { dataSharePredicates } from '@kit.ArkData'; import { BusinessError } from '@kit.BasicServicesKit'; async function example(phAccessHelper: photoAccessHelper.PhotoAccessHelper) { console.info('setUserCommentDemo'); let predicates: dataSharePredicates.DataSharePredicates = new dataSharePredicates.DataSharePredicates(); let fetchOption: photoAccessHelper.FetchOptions = { fetchColumns: [], predicates: predicates }; let fetchResult: photoAccessHelper.FetchResult = await phAccessHelper.getAssets(fetchOption); let asset = await fetchResult.getFirstObject(); let assetChangeRequest: photoAccessHelper.MediaAssetChangeRequest = new photoAccessHelper.MediaAssetChangeRequest(asset); let userComment: string = 'test_set_user_comment'; assetChangeRequest.setUserComment(userComment); phAccessHelper.applyChanges(assetChangeRequest).then(() => { console.info('apply setUserComment successfully'); }).catch((err: BusinessError) => { console.error(`apply setUserComment failed with error: ${err.code}, ${err.message}`); }); } ``` ### setEditData11+ setEditData(editData: MediaAssetEditData): void 保存资产的编辑数据。 **系统接口**:此接口为系统接口。 **系统能力**:SystemCapability.FileManagement.PhotoAccessHelper.Core **参数:** | 参数名 | 类型 | 必填 | 说明 | | ---------- | ------- | ---- | ---------------------------------- | | editData | [MediaAssetEditData](#mediaasseteditdata11) | 是 | 待保存的资产编辑数据。 | **错误码:** 接口抛出错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)和[文件管理错误码](../apis-core-file-kit/errorcode-filemanagement.md)。 | 错误码ID | 错误信息 | | -------- | ---------------------------------------- | | 202 | Called by non-system application. | | 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types; 3. Parameter verification failed. | | 14000011 | System inner fail. | **示例:** phAccessHelper的创建请参考[@ohos.file.photoAccessHelper (相册管理模块)](arkts-apis-photoAccessHelper-f.md)的示例使用。 ```ts import { dataSharePredicates } from '@kit.ArkData'; import { BusinessError } from '@kit.BasicServicesKit'; async function example(phAccessHelper: photoAccessHelper.PhotoAccessHelper) { console.info('setEditDataDemo'); let predicates: dataSharePredicates.DataSharePredicates = new dataSharePredicates.DataSharePredicates(); let fetchOption: photoAccessHelper.FetchOptions = { fetchColumns: [], predicates: predicates }; let fetchResult: photoAccessHelper.FetchResult = await phAccessHelper.getAssets(fetchOption); let asset = await fetchResult.getFirstObject(); let assetChangeRequest: photoAccessHelper.MediaAssetChangeRequest = new photoAccessHelper.MediaAssetChangeRequest(asset); let assetEditData: photoAccessHelper.MediaAssetEditData = new photoAccessHelper.MediaAssetEditData('system', '1.0'); let fileUri = 'file://com.example.temptest/data/storage/el2/base/haps/entry/files/test.jpg'; assetChangeRequest.addResource(photoAccessHelper.ResourceType.IMAGE_RESOURCE, fileUri); assetEditData.data = '123456'; assetChangeRequest.setEditData(assetEditData); phAccessHelper.applyChanges(assetChangeRequest).then(() => { console.info('apply setEditData successfully'); }).catch((err: BusinessError) => { console.error(`apply setEditData failed with error: ${err.code}, ${err.message}`); }); } ``` ### addResource11+ addResource(type: ResourceType, proxy: PhotoProxy): void 通过PhotoProxy数据添加资源。 **注意**:对于同一个资产变更请求,不支持在成功添加资源后,重复调用该接口。 **系统接口**:此接口为系统接口,仅提供给相机应用使用。 **系统能力**:SystemCapability.FileManagement.PhotoAccessHelper.Core **参数:** | 参数名 | 类型 | 必填 | 说明 | | ------- |---------------------------------| ---- |----------------------| | type | [ResourceType](#resourcetype11) | 是 | 待添加资源的类型。 | | proxy | [PhotoProxy](#photoproxy11) | 是 | 待添加资源的PhotoProxy 数据。 | **错误码:** 接口抛出错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)和[文件管理错误码](../apis-core-file-kit/errorcode-filemanagement.md)。 | 错误码ID | 错误信息 | |----------|-----------------------------------| | 202 | Called by non-system application. | | 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types; 3. Parameter verification failed. | | 14000011 | System inner fail. | | 14000016 | Operation Not Support. | **示例:** phAccessHelper的创建请参考[@ohos.file.photoAccessHelper (相册管理模块)](arkts-apis-photoAccessHelper-f.md)的示例使用。 ```ts class PhotoProxyImpl implements photoAccessHelper.PhotoProxy { // 应用实现PhotoProxy。 } async function example(phAccessHelper: photoAccessHelper.PhotoAccessHelper, asset: photoAccessHelper.PhotoAsset, context: Context) { console.info('addResourceByPhotoProxyDemo'); try { let photoType: photoAccessHelper.PhotoType = photoAccessHelper.PhotoType.IMAGE; let extension: string = 'jpg'; let assetChangeRequest: photoAccessHelper.MediaAssetChangeRequest = photoAccessHelper.MediaAssetChangeRequest.createAssetRequest(context, photoType, extension); let photoProxy: PhotoProxyImpl = new PhotoProxyImpl(); assetChangeRequest.addResource(photoAccessHelper.ResourceType.IMAGE_RESOURCE, photoProxy); await phAccessHelper.applyChanges(assetChangeRequest); console.info('addResourceByPhotoProxy successfully'); } catch (err) { console.error(`addResourceByPhotoProxyDemo failed with error: ${err.code}, ${err.message}`); } } ``` ### setLocation11+ setLocation(longitude: number, latitude: number): void 设置文件的经纬度信息。 **系统接口**:此接口为系统接口 **系统能力**:SystemCapability.FileManagement.PhotoAccessHelper.Core **参数:** | 参数名 | 类型 | 必填 | 说明 | | ------- |-------------| ---- |-------| | longitude | number | 是 | 经度。 | | latitude | number | 是 | 纬度。 | **错误码:** 接口抛出错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)和[文件管理错误码](../apis-core-file-kit/errorcode-filemanagement.md)。 | 错误码ID | 错误信息 | | -------- | ---------------------------------------- | | 202 | Called by non-system application. | | 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types; 3. Parameter verification failed. | | 14000011 | System inner fail. | **示例:** phAccessHelper的创建请参考[@ohos.file.photoAccessHelper (相册管理模块)](arkts-apis-photoAccessHelper-f.md)的示例使用。 ```ts import { dataSharePredicates } from '@kit.ArkData'; import { BusinessError } from '@kit.BasicServicesKit'; async function example(phAccessHelper: photoAccessHelper.PhotoAccessHelper) { console.info('setLocationDemo'); let predicates: dataSharePredicates.DataSharePredicates = new dataSharePredicates.DataSharePredicates(); let fetchOption: photoAccessHelper.FetchOptions = { fetchColumns: [], predicates: predicates }; let fetchResult: photoAccessHelper.FetchResult = await phAccessHelper.getAssets(fetchOption); let asset = await fetchResult.getFirstObject(); let assetChangeRequest: photoAccessHelper.MediaAssetChangeRequest = new photoAccessHelper.MediaAssetChangeRequest(asset); assetChangeRequest.setLocation(120.52, 30.40); phAccessHelper.applyChanges(assetChangeRequest).then(() => { console.info('apply setLocation successfully'); }).catch((err: BusinessError) => { console.error(`apply setLocation failed with error: ${err.code}, ${err.message}`); }); } ``` ### setCameraShotKey12+ setCameraShotKey(cameraShotKey: string): void 设置锁屏相机拍照或录像的标记字段。 **系统接口**:此接口为系统接口。 **系统能力**:SystemCapability.FileManagement.PhotoAccessHelper.Core **参数:** | 参数名 | 类型 | 必填 | 说明 | | ---------- | ------- | ---- | ---------------------------------- | | cameraShotKey | string | 是 | 锁屏相机拍照或录像的标记字段(仅开放给系统相机,其key值由系统相机定义)。 | **错误码:** 接口抛出错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)和[文件管理错误码](../apis-core-file-kit/errorcode-filemanagement.md)。 | 错误码ID | 错误信息 | | -------- | ---------------------------------------- | | 202 | Called by non-system application. | | 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types; 3. Parameter verification failed. | | 14000011 | System inner fail. | **示例:** phAccessHelper的创建请参考[@ohos.file.photoAccessHelper (相册管理模块)](arkts-apis-photoAccessHelper-f.md)的示例使用。 ```ts async function example(phAccessHelper: photoAccessHelper.PhotoAccessHelper, asset: photoAccessHelper.PhotoAsset) { console.info('setCameraShotKeyDemo'); try { let assetChangeRequest: photoAccessHelper.MediaAssetChangeRequest = new photoAccessHelper.MediaAssetChangeRequest(asset); let cameraShotKey: string = 'test_MediaAssetChangeRequest_setCameraShotKey'; assetChangeRequest.setCameraShotKey(cameraShotKey); await phAccessHelper.applyChanges(assetChangeRequest); console.info('apply setCameraShotKey successfully'); } catch (err) { console.error(`apply setCameraShotKey failed with error: ${err.code}, ${err.message}`); } } ``` ### setEffectMode12+ setEffectMode(mode: MovingPhotoEffectMode): void 设置动态照片的效果模式。 **系统接口**:此接口为系统接口。 **系统能力**:SystemCapability.FileManagement.PhotoAccessHelper.Core **参数:** | 参数名 | 类型 | 必填 | 说明 | | ---------- | ------- | ---- | ---------------------------------- | | mode | [MovingPhotoEffectMode](#movingphotoeffectmode12) | 是 | 动态照片效果模式。 | **错误码:** 接口抛出错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)和[文件管理错误码](../apis-core-file-kit/errorcode-filemanagement.md)。 | 错误码ID | 错误信息 | | -------- | ---------------------------------------- | | 202 | Called by non-system application. | | 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types; 3. Parameter verification failed. | | 14000011 | System inner fail. | | 14000016 | Operation Not Support. | **示例:** phAccessHelper的创建请参考[@ohos.file.photoAccessHelper (相册管理模块)](arkts-apis-photoAccessHelper-f.md)的示例使用。 ```ts async function example(phAccessHelper: photoAccessHelper.PhotoAccessHelper, asset: photoAccessHelper.PhotoAsset) { console.info('setEffectModeDemo'); try { let assetChangeRequest: photoAccessHelper.MediaAssetChangeRequest = new photoAccessHelper.MediaAssetChangeRequest(asset); assetChangeRequest.setEffectMode(photoAccessHelper.MovingPhotoEffectMode.LONG_EXPOSURE); // 需要确保fileUri对应的资源存在。 let imageFileUri = 'file://com.example.temptest/data/storage/el2/base/haps/entry/files/long_exposure.jpg'; let videoFileUri = 'file://com.example.temptest/data/storage/el2/base/haps/entry/files/long_exposure.mp4'; assetChangeRequest.addResource(photoAccessHelper.ResourceType.IMAGE_RESOURCE, imageFileUri); assetChangeRequest.addResource(photoAccessHelper.ResourceType.VIDEO_RESOURCE, videoFileUri); await phAccessHelper.applyChanges(assetChangeRequest); console.info('apply setEffectMode successfully'); } catch (err) { console.error(`apply setEffectMode failed with error: ${err.code}, ${err.message}`); } } ``` ### setSupportedWatermarkType14+ setSupportedWatermarkType(watermarkType: WatermarkType): void 设置拍照照片支持的水印类型。 **系统接口**:此接口为系统接口。 **系统能力**:SystemCapability.FileManagement.PhotoAccessHelper.Core **参数:** | 参数名 | 类型 | 必填 | 说明 | | ---------- | ------- | ---- | ---------------------------------- | | watermarkType | [WatermarkType](#watermarktype14) | 是 | 水印可编辑标识。
**注意:** 不支持传入WatermarkType.DEFAULT。 | **错误码:** 接口抛出错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)和[文件管理错误码](../apis-core-file-kit/errorcode-filemanagement.md)。 | 错误码ID | 错误信息 | | -------- | ---------------------------------------- | | 202 | Called by non-system application. | | 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types; 3. Parameter verification failed. | | 14000011 | Internal system error. | **示例:** ```ts import { dataSharePredicates } from '@kit.ArkData'; async function example(phAccessHelper: photoAccessHelper.PhotoAccessHelper) { console.info('setSupportedWatermarkTypeDemo'); let predicates: dataSharePredicates.DataSharePredicates = new dataSharePredicates.DataSharePredicates(); let fetchOption: photoAccessHelper.FetchOptions = { fetchColumns: [], predicates: predicates }; try { let fetchResult: photoAccessHelper.FetchResult = await phAccessHelper.getAssets(fetchOption); let asset = await fetchResult.getFirstObject(); let assetChangeRequest: photoAccessHelper.MediaAssetChangeRequest = new photoAccessHelper.MediaAssetChangeRequest(asset); assetChangeRequest.setSupportedWatermarkType(photoAccessHelper.WatermarkType.BRAND_COMMON); await phAccessHelper.applyChanges(assetChangeRequest); console.info('apply setSupportedWatermarkType successfully'); } catch (err) { console.error(`apply setSupportedWatermarkType failed with error: ${err.code}, ${err.message}`); } } ``` ### deleteLocalAssetsPermanently18+ static deleteLocalAssetsPermanently(context: Context, assets: Array\): Promise<void> 批量彻底删除照片或者视频,使用promise方式返回异步结果。 **注意**:此操作不可逆,执行此操作后文件资源将彻底删除,请谨慎操作。 **系统接口**:此接口为系统接口。 **系统能力**:SystemCapability.FileManagement.PhotoAccessHelper.Core **需要权限**:ohos.permission.WRITE_IMAGEVIDEO **参数:** | 参数名 | 类型 | 必填 | 说明 | | ---- | -------------- | ---- | ----- | | context | [Context](../apis-ability-kit/js-apis-inner-application-context.md) | 是 | 传入Ability实例的Context。 | | assets | Array\<[PhotoAsset](#photoasset)>| 是 | 待彻底删除的图片或者视频数组,数组中元素个数不超过500个。 | **返回值:** | 类型 | 说明 | | ------------------- | ---------- | | Promise<void> | Promise对象,返回void。 | **错误码:** 接口抛出错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)和[文件管理错误码](../apis-core-file-kit/errorcode-filemanagement.md)。 | 错误码ID | 错误信息 | | -------- | ---------------------------------------- | | 201 | Permission denied. | | 202 | Called by non-system application. | | 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types; 3. Parameter verification failed. | | 14000011 | Internal system error. **示例:** ```ts import { dataSharePredicates } from '@kit.ArkData'; import { BusinessError } from '@kit.BasicServicesKit'; async function example(phAccessHelper: photoAccessHelper.PhotoAccessHelper, context: Context) { console.info('deleteAssetsPermanentlyDemo'); let predicates: dataSharePredicates.DataSharePredicates = new dataSharePredicates.DataSharePredicates(); let fetchOptions: photoAccessHelper.FetchOptions = { fetchColumns: [], predicates: predicates }; try { let fetchResult: photoAccessHelper.FetchResult = await phAccessHelper.getAssets(fetchOptions); let photoAssetList: Array = await fetchResult.getAllObjects(); await photoAccessHelper.MediaAssetChangeRequest.deleteLocalAssetsPermanently(context, photoAssetList); } catch (err) { console.error(`deleteAssetsPermanentlyDemo failed with error: ${err.code}, ${err.message}`); } } ``` ### deleteLocalAssetsPermanentlyWithUri19+ static deleteLocalAssetsPermanentlyWithUri(context: Context, assetUris: Array<String>): Promise<void> 通过资产Uri批量彻底删除照片或者视频。使用promise异步回调。 >**注意**: > 此操作不可逆,执行此操作后文件资源将被彻底删除,请谨慎操作。 **系统接口**:此接口为系统接口。 **系统能力**:SystemCapability.FileManagement.PhotoAccessHelper.Core **需要权限**:ohos.permission.WRITE_IMAGEVIDEO **参数:** | 参数名 | 类型 | 必填 | 说明 | | ---- | -------------- | ---- | ----- | | context | [Context](../apis-ability-kit/js-apis-inner-application-context.md) | 是 | 传入Ability实例的Context。 | | assetUris | Array<String> | 是 | 待彻底删除的图片或者视频Uri数组,数组中元素个数不超过500个。 | **返回值:** | 类型 | 说明 | | ------------------- | ---------- | | Promise<void> | Promise对象。无返回结果的Promise对象。 | **错误码:** 以下错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)和[文件管理错误码](../apis-core-file-kit/errorcode-filemanagement.md)。 | 错误码ID | 错误信息 | | -------- | ---------------------------------------- | | 201 | Permission denied. | | 202 | Called by non-system application. | | 13900020 | Invalid argument. | | 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. | **示例:** ```ts import { dataSharePredicates } from '@kit.ArkData'; async function example(phAccessHelper: photoAccessHelper.PhotoAccessHelper, context: Context) { console.info('deleteLocalAssetsPermanentlyWithUriDemo'); let predicates: dataSharePredicates.DataSharePredicates = new dataSharePredicates.DataSharePredicates(); let fetchOptions: photoAccessHelper.FetchOptions = { fetchColumns: [], predicates: predicates }; try { let photoUris: Array = []; let fetchResult: photoAccessHelper.FetchResult = await phAccessHelper.getAssets(fetchOptions); let assets: Array = await fetchResult.getAllObjects(); for (const asset of assets) { if (!asset?.uri) { continue; } let uri:string = asset.uri.trim(); photoUris.push(uri); } await photoAccessHelper.MediaAssetChangeRequest.deleteLocalAssetsPermanentlyWithUri(context, photoUris); } catch (err) { console.error(`deleteLocalAssetsPermanentlyWithUriDemo failed with error: ${err.code}, ${err.message}`); } } ``` ## MediaAssetsChangeRequest11+ 批量资产变更请求。 **系统接口**:此接口为系统接口。 **系统能力**:SystemCapability.FileManagement.PhotoAccessHelper.Core ### constructor11+ constructor(assets: Array<PhotoAsset>) 构造函数。 **系统接口**:此接口为系统接口。 **系统能力**:SystemCapability.FileManagement.PhotoAccessHelper.Core **参数:** | 参数名 | 类型 | 必填 | 说明 | | -------- | ------------------------- | ---- | ---------- | | assets | Array<[PhotoAsset](#photoasset)> | 是 | 需要变更的资产数组。 | **错误码:** 接口抛出错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)和[文件管理错误码](../apis-core-file-kit/errorcode-filemanagement.md)。 | 错误码ID | 错误信息 | | -------- | ---------------------------------------- | | 202 | Called by non-system application. | | 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types; 3. Parameter verification failed. | | 14000011 | System inner fail. | **示例:** phAccessHelper的创建请参考[@ohos.file.photoAccessHelper (相册管理模块)](arkts-apis-photoAccessHelper-f.md)的示例使用。 ```ts import { dataSharePredicates } from '@kit.ArkData'; async function example(phAccessHelper: photoAccessHelper.PhotoAccessHelper) { console.info('MediaAssetsChangeRequest constructorDemo'); let predicates: dataSharePredicates.DataSharePredicates = new dataSharePredicates.DataSharePredicates(); let fetchOption: photoAccessHelper.FetchOptions = { fetchColumns: [], predicates: predicates }; let fetchResult: photoAccessHelper.FetchResult = await phAccessHelper.getAssets(fetchOption); let photoAssetList: Array = await fetchResult.getAllObjects(); let assetsChangeRequest: photoAccessHelper.MediaAssetsChangeRequest = new photoAccessHelper.MediaAssetsChangeRequest(photoAssetList); } ``` ### setFavorite11+ setFavorite(favoriteState: boolean): void 将文件设置为收藏文件。 **系统接口**:此接口为系统接口。 **系统能力**:SystemCapability.FileManagement.PhotoAccessHelper.Core **参数:** | 参数名 | 类型 | 必填 | 说明 | | ---------- | ------- | ---- | ---------------------------------- | | favoriteState | boolean | 是 | 是否设置为收藏文件, true:设置为收藏文件;false:取消收藏。 | **错误码:** 接口抛出错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)和[文件管理错误码](../apis-core-file-kit/errorcode-filemanagement.md)。 | 错误码ID | 错误信息 | | -------- | ---------------------------------------- | | 202 | Called by non-system application. | | 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types; 3. Parameter verification failed. | | 14000011 | System inner fail. | **示例:** phAccessHelper的创建请参考[@ohos.file.photoAccessHelper (相册管理模块)](arkts-apis-photoAccessHelper-f.md)的示例使用。 ```ts import { dataSharePredicates } from '@kit.ArkData'; import { BusinessError } from '@kit.BasicServicesKit'; async function example(phAccessHelper: photoAccessHelper.PhotoAccessHelper) { console.info('setFavoriteDemo'); let predicates: dataSharePredicates.DataSharePredicates = new dataSharePredicates.DataSharePredicates(); let fetchOption: photoAccessHelper.FetchOptions = { fetchColumns: [], predicates: predicates }; let fetchResult: photoAccessHelper.FetchResult = await phAccessHelper.getAssets(fetchOption); let photoAssetList: Array = await fetchResult.getAllObjects(); let assetsChangeRequest: photoAccessHelper.MediaAssetsChangeRequest = new photoAccessHelper.MediaAssetsChangeRequest(photoAssetList); assetsChangeRequest.setFavorite(true); phAccessHelper.applyChanges(assetsChangeRequest).then(() => { console.info('apply setFavorite successfully'); }).catch((err: BusinessError) => { console.error(`apply setFavorite failed with error: ${err.code}, ${err.message}`); }); } ``` ### setHidden11+ setHidden(hiddenState: boolean): void 将文件设置为隐藏文件。 **系统接口**:此接口为系统接口。 **系统能力**:SystemCapability.FileManagement.PhotoAccessHelper.Core **参数:** | 参数名 | 类型 | 必填 | 说明 | | ---------- | ------- | ---- | ---------------------------------- | | hiddenState | boolean | 是 | 是否设置为隐藏文件,true:将文件资产放入隐藏相册;false:从隐藏相册中恢复。 | **错误码:** 接口抛出错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)和[文件管理错误码](../apis-core-file-kit/errorcode-filemanagement.md)。 | 错误码ID | 错误信息 | | -------- | ---------------------------------------- | | 202 | Called by non-system application. | | 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types; 3. Parameter verification failed. | | 14000011 | System inner fail. | **示例:** phAccessHelper的创建请参考[@ohos.file.photoAccessHelper (相册管理模块)](arkts-apis-photoAccessHelper-f.md)的示例使用。 ```ts import { dataSharePredicates } from '@kit.ArkData'; import { BusinessError } from '@kit.BasicServicesKit'; async function example(phAccessHelper: photoAccessHelper.PhotoAccessHelper) { console.info('setHiddenDemo'); let predicates: dataSharePredicates.DataSharePredicates = new dataSharePredicates.DataSharePredicates(); let fetchOption: photoAccessHelper.FetchOptions = { fetchColumns: [], predicates: predicates }; let fetchResult: photoAccessHelper.FetchResult = await phAccessHelper.getAssets(fetchOption); let photoAssetList: Array = await fetchResult.getAllObjects(); let assetsChangeRequest: photoAccessHelper.MediaAssetsChangeRequest = new photoAccessHelper.MediaAssetsChangeRequest(photoAssetList); assetsChangeRequest.setHidden(true); phAccessHelper.applyChanges(assetsChangeRequest).then(() => { console.info('apply setHidden successfully'); }).catch((err: BusinessError) => { console.error(`apply setHidden failed with error: ${err.code}, ${err.message}`); }); } ``` ### setUserComment11+ setUserComment(userComment: string): void 修改媒体资产的备注信息。 **系统接口**:此接口为系统接口。 **系统能力**:SystemCapability.FileManagement.PhotoAccessHelper.Core **参数:** | 参数名 | 类型 | 必填 | 说明 | | ---------- | ------- | ---- | ---------------------------------- | | userComment | string | 是 | 待修改的资产备注信息,备注信息最长为420字符。 | **错误码:** 接口抛出错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)和[文件管理错误码](../apis-core-file-kit/errorcode-filemanagement.md)。 | 错误码ID | 错误信息 | | -------- | ---------------------------------------- | | 202 | Called by non-system application. | | 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types; 3. Parameter verification failed. | | 14000011 | System inner fail. | **示例:** phAccessHelper的创建请参考[@ohos.file.photoAccessHelper (相册管理模块)](arkts-apis-photoAccessHelper-f.md)的示例使用。 ```ts import { dataSharePredicates } from '@kit.ArkData'; import { BusinessError } from '@kit.BasicServicesKit'; async function example(phAccessHelper: photoAccessHelper.PhotoAccessHelper) { console.info('setUserCommentDemo'); let predicates: dataSharePredicates.DataSharePredicates = new dataSharePredicates.DataSharePredicates(); let fetchOption: photoAccessHelper.FetchOptions = { fetchColumns: [], predicates: predicates }; let fetchResult: photoAccessHelper.FetchResult = await phAccessHelper.getAssets(fetchOption); let photoAssetList: Array = await fetchResult.getAllObjects(); let assetsChangeRequest: photoAccessHelper.MediaAssetsChangeRequest = new photoAccessHelper.MediaAssetsChangeRequest(photoAssetList); assetsChangeRequest.setUserComment('test_set_user_comment'); phAccessHelper.applyChanges(assetsChangeRequest).then(() => { console.info('apply setUserComment successfully'); }).catch((err: BusinessError) => { console.error(`apply setUserComment failed with error: ${err.code}, ${err.message}`); }); } ``` ### setIsRecentShow18+ setIsRecentShow(isRencentShow: boolean): void 设置当前资产是否在“最近”列表中显示。 **系统接口**:此接口为系统接口。 **系统能力**:SystemCapability.FileManagement.PhotoAccessHelper.Core **参数:** | 参数名 | 类型 | 必填 | 说明 | | ---------- | ------- | ---- | ---------------------------------- | | isRencentShow | boolean | 是 | 表示当前资产是否在“最近”列表中显示。true表示显示,false表示不显示。 | **错误码:** 接口抛出错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)和[文件管理错误码](../apis-core-file-kit/errorcode-filemanagement.md)。 | 错误码ID | 错误信息 | | -------- | ---------------------------------------- | | 202 | Called by non-system application. | | 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types; 3. Parameter verification failed. | | 14000011 | System inner fail. | **示例:** phAccessHelper的创建请参考[@ohos.file.photoAccessHelper (相册管理模块)](arkts-apis-photoAccessHelper-f.md)的示例使用。 ```ts import { dataSharePredicates } from '@kit.ArkData'; import { BusinessError } from '@kit.BasicServicesKit'; async function example(phAccessHelper: photoAccessHelper.PhotoAccessHelper) { console.info('setIsRecentShowDemo'); let predicates: dataSharePredicates.DataSharePredicates = new dataSharePredicates.DataSharePredicates(); let fetchOption: photoAccessHelper.FetchOptions = { fetchColumns: [], predicates: predicates }; let fetchResult: photoAccessHelper.FetchResult = await phAccessHelper.getAssets(fetchOption); let photoAssetList: Array = await fetchResult.getAllObjects(); let assetsChangeRequest: photoAccessHelper.MediaAssetsChangeRequest = new photoAccessHelper.MediaAssetsChangeRequest(photoAssetList); assetsChangeRequest.setIsRecentShow(true); phAccessHelper.applyChanges(assetsChangeRequest).then(() => { console.info('apply setIsRecentShow successfully'); }).catch((err: BusinessError) => { console.error(`apply setIsRecentShow failed with error: ${err.code}, ${err.message}`); }); } ``` ## MediaAlbumChangeRequest11+ 相册变更请求。 **系统能力**:SystemCapability.FileManagement.PhotoAccessHelper.Core ### createAlbumRequest11+ static createAlbumRequest(context: Context, name: string): MediaAlbumChangeRequest 创建相册变更请求。 相册名的参数规格为: - 相册名字符串长度为1~255。 - 不允许出现的非法英文字符,包括:
. .. \ / : * ? " ' ` < > | { } [ ] - 英文字符大小写不敏感。 - 相册名不允许重名。 **系统接口**:此接口为系统接口。 **系统能力**:SystemCapability.FileManagement.PhotoAccessHelper.Core **参数:** | 参数名 | 类型 | 必填 | 说明 | | ------- | ------- | ---- | -------------------------- | | context | [Context](../apis-ability-kit/js-apis-inner-application-context.md) | 是 | 传入Ability实例的Context。 | | name | string | 是 | 待创建相册的名称。| **返回值:** | 类型 | 说明 | | --------------------------------------- | ----------------- | | [MediaAlbumChangeRequest](#mediaalbumchangerequest11) | 返回创建相册的变更请求。 | **错误码:** 接口抛出错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)和[文件管理错误码](../apis-core-file-kit/errorcode-filemanagement.md)。 | 错误码ID | 错误信息 | | -------- | ---------------------------------------- | | 202 | Called by non-system application. | | 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types; 3. Parameter verification failed. | | 14000011 | System inner fail. | **示例:** phAccessHelper的创建请参考[@ohos.file.photoAccessHelper (相册管理模块)](arkts-apis-photoAccessHelper-f.md)的示例使用。 ```ts async function example(phAccessHelper: photoAccessHelper.PhotoAccessHelper, context: Context) { console.info('createAlbumRequestDemo'); try { let albumName: string = 'newAlbumName' + new Date().getTime(); let albumChangeRequest: photoAccessHelper.MediaAlbumChangeRequest = photoAccessHelper.MediaAlbumChangeRequest.createAlbumRequest(context, albumName); await phAccessHelper.applyChanges(albumChangeRequest); console.info('apply createAlbumRequest successfully'); } catch (err) { console.error(`createAlbumRequestDemo failed with error: ${err.code}, ${err.message}`); } } ``` ### deleteAlbums11+ static deleteAlbums(context: Context, albums: Array<Album>): Promise<void> 删除相册,使用Promise方式返回结果。 删除相册前需先确保相册存在,只能删除用户相册。 **系统接口**:此接口为系统接口。 **需要权限**:ohos.permission.WRITE_IMAGEVIDEO **系统能力**:SystemCapability.FileManagement.PhotoAccessHelper.Core **参数:** | 参数名 | 类型 | 必填 | 说明 | | ------- | ------- | ---- | -------------------------- | | context | [Context](../apis-ability-kit/js-apis-inner-application-context.md) | 是 | 传入Ability实例的Context。 | | albums | Array<[Album](#album)> | 是 | 待删除的相册数组。 | **返回值:** | 类型 | 说明 | | --------------------------------------- | ----------------- | | Promise<void>| Promise对象,返回void。 | **错误码:** 接口抛出错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)和[文件管理错误码](../apis-core-file-kit/errorcode-filemanagement.md)。 | 错误码ID | 错误信息 | | -------- | ---------------------------------------- | | 201 | Permission denied. | | 202 | Called by non-system application. | | 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types; 3. Parameter verification failed. | | 14000011 | System inner fail. | **示例:** phAccessHelper的创建请参考[@ohos.file.photoAccessHelper (相册管理模块)](arkts-apis-photoAccessHelper-f.md)的示例使用。 ```ts import { dataSharePredicates } from '@kit.ArkData'; async function example(phAccessHelper: photoAccessHelper.PhotoAccessHelper, context: Context) { console.info('deleteAlbumsDemo'); let predicates: dataSharePredicates.DataSharePredicates = new dataSharePredicates.DataSharePredicates(); let fetchOptions: photoAccessHelper.FetchOptions = { fetchColumns: [], predicates: predicates }; try { let fetchResult: photoAccessHelper.FetchResult = await phAccessHelper.getAlbums(photoAccessHelper.AlbumType.USER, photoAccessHelper.AlbumSubtype.USER_GENERIC, fetchOptions); let album: photoAccessHelper.Album = await fetchResult.getFirstObject(); await photoAccessHelper.MediaAlbumChangeRequest.deleteAlbums(context, [album]); console.info('deleteAlbums successfully'); } catch (err) { console.error(`deleteAlbumsDemo failed with error: ${err.code}, ${err.message}`); } } ``` ### deleteAlbumsWithUri19+ static deleteAlbumsWithUri(context: Context, albumUris: Array<string>): Promise<void> 删除已存在的用户相册。使用promise异步回调。 **系统接口**:此接口为系统接口。 **需要权限**:ohos.permission.WRITE_IMAGEVIDEO **系统能力**:SystemCapability.FileManagement.PhotoAccessHelper.Core **参数:** | 参数名 | 类型 | 必填 | 说明 | | ------- | ------- | ---- | -------------------------- | | context | [Context](../apis-ability-kit/js-apis-inner-application-context.md) | 是 | 传入Ability实例的Context。 | | albumUris | Array<string> | 是 | 待删除相册Uri的数组。 | **返回值:** | 类型 | 说明 | | --------------------------------------- | ----------------- | | Promise<void>| Promise对象。无返回结果的Promise对象。 | **错误码:** 以下错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)和[文件管理错误码](../apis-core-file-kit/errorcode-filemanagement.md)。 | 错误码ID | 错误信息 | | -------- | ---------------------------------------- | | 201 | Permission denied. | | 202 | Called by non-system application. | | 13900020 | Invalid argument. | | 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; | **示例:** ```ts async function example(context: Context, albumUri: string) { console.info('deleteAlbumsWithUriDemo'); try { await photoAccessHelper.MediaAlbumChangeRequest.deleteAlbumsWithUri(context, [albumUri]); console.info('deleteAlbums successfully'); } catch (err) { console.error(`deleteAlbumsWithUriDemo failed with error: ${err.code}, ${err.message}`); } } ``` ### setCoverUri11+ setCoverUri(coverUri: string): void 设置相册封面。 **系统接口**:此接口为系统接口。 **系统能力**:SystemCapability.FileManagement.PhotoAccessHelper.Core **参数:** | 参数名 | 类型 | 必填 | 说明 | | ---------- | ------- | ---- | ---------------------------------- | | coverUri | string | 是 | 待设置为相册封面文件的uri。 | **错误码:** 接口抛出错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)和[文件管理错误码](../apis-core-file-kit/errorcode-filemanagement.md)。 | 错误码ID | 错误信息 | | -------- | ---------------------------------------- | | 202 | Called by non-system application. | | 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types; 3. Parameter verification failed. | | 14000011 | System inner fail. | **示例:** phAccessHelper的创建请参考[@ohos.file.photoAccessHelper (相册管理模块)](arkts-apis-photoAccessHelper-f.md)的示例使用。 ```ts import { dataSharePredicates } from '@kit.ArkData'; async function example(phAccessHelper: photoAccessHelper.PhotoAccessHelper) { console.info('setCoverUriDemo'); let predicates: dataSharePredicates.DataSharePredicates = new dataSharePredicates.DataSharePredicates(); let fetchOptions: photoAccessHelper.FetchOptions = { fetchColumns: [], predicates: predicates }; try { let albumFetchResult: photoAccessHelper.FetchResult = await phAccessHelper.getAlbums(photoAccessHelper.AlbumType.USER, photoAccessHelper.AlbumSubtype.USER_GENERIC); let album: photoAccessHelper.Album = await albumFetchResult.getFirstObject(); let fetchResult: photoAccessHelper.FetchResult = await album.getAssets(fetchOptions); let asset: photoAccessHelper.PhotoAsset = await fetchResult.getFirstObject(); let albumChangeRequest: photoAccessHelper.MediaAlbumChangeRequest = new photoAccessHelper.MediaAlbumChangeRequest(album); albumChangeRequest.setCoverUri(asset.uri); await phAccessHelper.applyChanges(albumChangeRequest); console.info('setCoverUri successfully'); } catch (err) { console.error(`setCoverUriDemo failed with error: ${err.code}, ${err.message}`); } } ``` ### resetCoverUri20+ resetCoverUri(): void 恢复默认封面。 **系统接口**:此接口为系统接口。 **系统能力**:SystemCapability.FileManagement.PhotoAccessHelper.Core **错误码:** 以下错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)和[媒体库错误码](errcode-medialibrary.md)。 | 错误码ID | 错误信息 | | -------- | ---------------------------------------- | | 202 | Called by non-system application. | | 23800301 | Internal system error.It is recommended to retry and check the logs. Possible causes: 1. Database corrupted. 2. The file system is abnormal. 3. The IPC request timed out. | **示例:** phAccessHelper的创建请参考[@ohos.file.photoAccessHelper (相册管理模块)](js-apis-photoAccessHelper.md)的示例使用。 ```ts import { dataSharePredicates } from '@kit.ArkData'; async function example(phAccessHelper: photoAccessHelper.PhotoAccessHelper) { console.info('resetCoverUriDemo'); let predicates: dataSharePredicates.DataSharePredicates = new dataSharePredicates.DataSharePredicates(); let fetchOptions: photoAccessHelper.FetchOptions = { fetchColumns: [], predicates: predicates }; try { let albumFetchResult: photoAccessHelper.FetchResult = await phAccessHelper.getAlbums(photoAccessHelper.AlbumType.USER, photoAccessHelper.AlbumSubtype.USER_GENERIC); let album: photoAccessHelper.Album = await albumFetchResult.getFirstObject(); let albumChangeRequest: photoAccessHelper.MediaAlbumChangeRequest = new photoAccessHelper.MediaAlbumChangeRequest(album); albumChangeRequest.resetCoverUri(); await phAccessHelper.applyChanges(albumChangeRequest); console.info('resetCoverUri successfully'); } catch (err) { console.error(`resetCoverUriDemo failed with error: ${err.code}, ${err.message}`); } } ``` ### moveAssets11+ moveAssets(assets: Array<PhotoAsset>, targetAlbum: Album): void 从相册中移动资产到另一个目标相册。 **系统接口**:此接口为系统接口。 **系统能力**:SystemCapability.FileManagement.PhotoAccessHelper.Core **参数:** | 参数名 | 类型 | 必填 | 说明 | | ---------- | ------- | ---- | ---------------------------------- | | assets | Array<[PhotoAsset](#photoasset)> | 是 | 待从相册中移出的资产数组。 | | targetAlbum | Album | 是 | 待移入资产的目标相册。 | **错误码:** 接口抛出错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)和[文件管理错误码](../apis-core-file-kit/errorcode-filemanagement.md)。 | 错误码ID | 错误信息 | | -------- | ---------------------------------------- | | 202 | Called by non-system application. | | 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types; 3. Parameter verification failed. | | 14000011 | System inner fail. | | 14000016 | Operation Not Support. | **示例:** phAccessHelper的创建请参考[@ohos.file.photoAccessHelper (相册管理模块)](arkts-apis-photoAccessHelper-f.md)的示例使用。 ```ts import { dataSharePredicates } from '@kit.ArkData'; async function example(phAccessHelper: photoAccessHelper.PhotoAccessHelper) { console.info('moveAssetsDemo'); let predicates: dataSharePredicates.DataSharePredicates = new dataSharePredicates.DataSharePredicates(); let fetchOptions: photoAccessHelper.FetchOptions = { fetchColumns: [], predicates: predicates }; try { let albumFetchResult: photoAccessHelper.FetchResult = await phAccessHelper.getAlbums(photoAccessHelper.AlbumType.USER, photoAccessHelper.AlbumSubtype.USER_GENERIC); let album: photoAccessHelper.Album = await albumFetchResult.getFirstObject(); let fetchResult: photoAccessHelper.FetchResult = await album.getAssets(fetchOptions); let asset: photoAccessHelper.PhotoAsset = await fetchResult.getFirstObject(); if (albumFetchResult.isAfterLast()) { console.error('lack of album to be moved into'); return; } let nextAlbum: photoAccessHelper.Album = await albumFetchResult.getNextObject(); let albumChangeRequest: photoAccessHelper.MediaAlbumChangeRequest = new photoAccessHelper.MediaAlbumChangeRequest(album); albumChangeRequest.moveAssets([asset], nextAlbum); await phAccessHelper.applyChanges(albumChangeRequest); console.info('moveAssets successfully'); } catch (err) { console.error(`moveAssetsDemo failed with error: ${err.code}, ${err.message}`); } } ``` ### moveAssetsWithUri19+ moveAssetsWithUri(assetUris: Array<String>, targetAlbum: Album): void 把相册中的资产移动到另一个目标相册。 **系统接口**:此接口为系统接口。 **系统能力**:SystemCapability.FileManagement.PhotoAccessHelper.Core **参数:** | 参数名 | 类型 | 必填 | 说明 | | ---------- | ------- | ---- | ---------------------------------- | | assetUris | Array<String> | 是 | 待从相册中移出的资产Uri数组。 | | targetAlbum | [Album](#album) | 是 | 待移入资产的目标相册。 | **错误码:** 以下错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)和[文件管理错误码](../apis-core-file-kit/errorcode-filemanagement.md)。 | 错误码ID | 错误信息 | | -------- | ---------------------------------------- | | 202 | Called by non-system application. | | 13900020 | Invalid argument.| | 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. | | 14000016 | Operation Not Support. | **示例:** phAccessHelper的创建请参考[@ohos.file.photoAccessHelper (相册管理模块)](arkts-apis-photoAccessHelper-f.md)的示例使用。 ```ts import { dataSharePredicates } from '@kit.ArkData'; async function example(phAccessHelper: photoAccessHelper.PhotoAccessHelper) { console.info('moveAssetsWithUriDemo'); let predicates: dataSharePredicates.DataSharePredicates = new dataSharePredicates.DataSharePredicates(); let fetchOptions: photoAccessHelper.FetchOptions = { fetchColumns: [], predicates: predicates }; try { let albumFetchResult: photoAccessHelper.FetchResult = await phAccessHelper.getAlbums(photoAccessHelper.AlbumType.USER, photoAccessHelper.AlbumSubtype.USER_GENERIC); let album: photoAccessHelper.Album = await albumFetchResult.getFirstObject(); let fetchResult: photoAccessHelper.FetchResult = await album.getAssets(fetchOptions); let asset: photoAccessHelper.PhotoAsset = await fetchResult.getFirstObject(); if (albumFetchResult.isAfterLast()) { console.error('lack of album to be moved into'); return; } let nextAlbum: photoAccessHelper.Album = await albumFetchResult.getNextObject(); let albumChangeRequest: photoAccessHelper.MediaAlbumChangeRequest = new photoAccessHelper.MediaAlbumChangeRequest(album); albumChangeRequest.moveAssetsWithUri([asset.uri], nextAlbum); await phAccessHelper.applyChanges(albumChangeRequest); console.info('moveAssetsWithUri successfully'); } catch (err) { console.error(`moveAssetsWithUriDemo failed with error: ${err.code}, ${err.message}`); } } ``` ### recoverAssets11+ recoverAssets(assets: Array<PhotoAsset>): void 从回收站中恢复资产。 **系统接口**:此接口为系统接口。 **系统能力**:SystemCapability.FileManagement.PhotoAccessHelper.Core **参数:** | 参数名 | 类型 | 必填 | 说明 | | ---------- | ------- | ---- | ---------------------------------- | | assets | Array<[PhotoAsset](#photoasset)> | 是 | 待从回收站中恢复的资产数组。 | **错误码:** 接口抛出错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)和[文件管理错误码](../apis-core-file-kit/errorcode-filemanagement.md)。 | 错误码ID | 错误信息 | | -------- | ---------------------------------------- | | 202 | Called by non-system application. | | 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types; 3. Parameter verification failed. | | 14000011 | System inner fail. | | 14000016 | Operation Not Support. | **示例:** phAccessHelper的创建请参考[@ohos.file.photoAccessHelper (相册管理模块)](arkts-apis-photoAccessHelper-f.md)的示例使用。 ```ts import { dataSharePredicates } from '@kit.ArkData'; async function example(phAccessHelper: photoAccessHelper.PhotoAccessHelper) { console.info('recoverAssetsDemo'); let predicates: dataSharePredicates.DataSharePredicates = new dataSharePredicates.DataSharePredicates(); let fetchOptions: photoAccessHelper.FetchOptions = { fetchColumns: [], predicates: predicates }; try { let albumFetchResult: photoAccessHelper.FetchResult = await phAccessHelper.getAlbums(photoAccessHelper.AlbumType.SYSTEM, photoAccessHelper.AlbumSubtype.TRASH); let album: photoAccessHelper.Album = await albumFetchResult.getFirstObject(); let fetchResult: photoAccessHelper.FetchResult = await album.getAssets(fetchOptions); let asset: photoAccessHelper.PhotoAsset = await fetchResult.getFirstObject(); let albumChangeRequest: photoAccessHelper.MediaAlbumChangeRequest = new photoAccessHelper.MediaAlbumChangeRequest(album); albumChangeRequest.recoverAssets([asset]); await phAccessHelper.applyChanges(albumChangeRequest); console.info('recoverAssets successfully'); } catch (err) { console.error(`recoverAssetsDemo failed with error: ${err.code}, ${err.message}`); } } ``` ### recoverAssetsWithUri19+ recoverAssetsWithUri(assetUris: Array<String>): void 从回收站中恢复资产。 **系统接口**:此接口为系统接口。 **系统能力**:SystemCapability.FileManagement.PhotoAccessHelper.Core **参数:** | 参数名 | 类型 | 必填 | 说明 | | ---------- | ------- | ---- | ---------------------------------- | | assetUris | Array<String> | 是 | 待从回收站中恢复的资产Uri数组。 | **错误码:** 以下错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)和[文件管理错误码](../apis-core-file-kit/errorcode-filemanagement.md)。 | 错误码ID | 错误信息 | | -------- | ---------------------------------------- | | 202 | Called by non-system application. | | 13900020 | Invalid argument.| | 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. | | 14000016 | Operation Not Support. | **示例:** phAccessHelper的创建请参考[@ohos.file.photoAccessHelper (相册管理模块)](arkts-apis-photoAccessHelper-f.md)的示例使用。 ```ts import { dataSharePredicates } from '@kit.ArkData'; async function example(phAccessHelper: photoAccessHelper.PhotoAccessHelper) { console.info('recoverAssetsWithUriDemo'); let predicates: dataSharePredicates.DataSharePredicates = new dataSharePredicates.DataSharePredicates(); let fetchOptions: photoAccessHelper.FetchOptions = { fetchColumns: [], predicates: predicates }; try { let albumFetchResult: photoAccessHelper.FetchResult = await phAccessHelper.getAlbums(photoAccessHelper.AlbumType.SYSTEM, photoAccessHelper.AlbumSubtype.TRASH); let album: photoAccessHelper.Album = await albumFetchResult.getFirstObject(); let fetchResult: photoAccessHelper.FetchResult = await album.getAssets(fetchOptions); let asset: photoAccessHelper.PhotoAsset = await fetchResult.getFirstObject(); let albumChangeRequest: photoAccessHelper.MediaAlbumChangeRequest = new photoAccessHelper.MediaAlbumChangeRequest(album); albumChangeRequest.recoverAssetsWithUri([asset.uri]); await phAccessHelper.applyChanges(albumChangeRequest); console.info('recoverAssetsWithUri successfully'); } catch (err) { console.error(`recoverAssetsWithUriDemo failed with error: ${err.code}, ${err.message}`); } } ``` ### deleteAssets11+ deleteAssets(assets: Array<PhotoAsset>): void 从回收站中彻底删除资产。 **注意**:此操作不可逆,执行此操作后文件资源将彻底删除,请谨慎操作。 **系统接口**:此接口为系统接口。 **系统能力**:SystemCapability.FileManagement.PhotoAccessHelper.Core **参数:** | 参数名 | 类型 | 必填 | 说明 | | ---------- | ------- | ---- | ---------------------------------- | | assets | Array<[PhotoAsset](#photoasset)> | 是 | 待从回收站中彻底删除的资产数组。 | **错误码:** 接口抛出错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)和[文件管理错误码](../apis-core-file-kit/errorcode-filemanagement.md)。 | 错误码ID | 错误信息 | | -------- | ---------------------------------------- | | 202 | Called by non-system application. | | 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types; 3. Parameter verification failed. | | 14000011 | System inner fail. | | 14000016 | Operation Not Support. | **示例:** phAccessHelper的创建请参考[@ohos.file.photoAccessHelper (相册管理模块)](arkts-apis-photoAccessHelper-f.md)的示例使用。 ```ts import { dataSharePredicates } from '@kit.ArkData'; async function example(phAccessHelper: photoAccessHelper.PhotoAccessHelper) { console.info('deleteAssetsPermanentlyDemo'); let predicates: dataSharePredicates.DataSharePredicates = new dataSharePredicates.DataSharePredicates(); let fetchOptions: photoAccessHelper.FetchOptions = { fetchColumns: [], predicates: predicates }; try { let albumFetchResult: photoAccessHelper.FetchResult = await phAccessHelper.getAlbums(photoAccessHelper.AlbumType.SYSTEM, photoAccessHelper.AlbumSubtype.TRASH); let album: photoAccessHelper.Album = await albumFetchResult.getFirstObject(); let fetchResult: photoAccessHelper.FetchResult = await album.getAssets(fetchOptions); let asset: photoAccessHelper.PhotoAsset = await fetchResult.getFirstObject(); let albumChangeRequest: photoAccessHelper.MediaAlbumChangeRequest = new photoAccessHelper.MediaAlbumChangeRequest(album); albumChangeRequest.deleteAssets([asset]); await phAccessHelper.applyChanges(albumChangeRequest); console.info('succeed to deleteAssets permanently'); } catch (err) { console.error(`deleteAssetsPermanentlyDemo failed with error: ${err.code}, ${err.message}`); } } ``` ### deleteAssetsWithUri19+ deleteAssetsWithUri(assetUris: Array<String>): void 从回收站中彻底删除资产。 >**注意**: > 此操作不可逆,执行此操作后文件资源将被彻底删除,请谨慎操作。 **系统接口**:此接口为系统接口。 **系统能力**:SystemCapability.FileManagement.PhotoAccessHelper.Core **参数:** | 参数名 | 类型 | 必填 | 说明 | | ---------- | ------- | ---- | ---------------------------------- | | assetUris | Array<String> | 是 | 待从回收站中彻底删除的资产Uri数组。 | **错误码:** 以下错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)和[文件管理错误码](../apis-core-file-kit/errorcode-filemanagement.md)。 | 错误码ID | 错误信息 | | -------- | ---------------------------------------- | | 202 | Called by non-system application. | | 13900020 | Invalid argument.| | 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. | | 14000016 | Operation Not Support. | **示例:** phAccessHelper的创建请参考[@ohos.file.photoAccessHelper (相册管理模块)](arkts-apis-photoAccessHelper-f.md)的示例使用。 ```ts import { dataSharePredicates } from '@kit.ArkData'; async function example(phAccessHelper: photoAccessHelper.PhotoAccessHelper) { console.info('deleteAssetsWithUriDemo'); let predicates: dataSharePredicates.DataSharePredicates = new dataSharePredicates.DataSharePredicates(); let fetchOptions: photoAccessHelper.FetchOptions = { fetchColumns: [], predicates: predicates }; try { let albumFetchResult: photoAccessHelper.FetchResult = await phAccessHelper.getAlbums(photoAccessHelper.AlbumType.SYSTEM, photoAccessHelper.AlbumSubtype.TRASH); let album: photoAccessHelper.Album = await albumFetchResult.getFirstObject(); let fetchResult: photoAccessHelper.FetchResult = await album.getAssets(fetchOptions); let asset: photoAccessHelper.PhotoAsset = await fetchResult.getFirstObject(); let albumChangeRequest: photoAccessHelper.MediaAlbumChangeRequest = new photoAccessHelper.MediaAlbumChangeRequest(album); albumChangeRequest.deleteAssetsWithUri([asset.uri]); await phAccessHelper.applyChanges(albumChangeRequest); console.info('succeed to deleteAssets permanently'); } catch (err) { console.error(`deleteAssetsWithUriDemo failed with error: ${err.code}, ${err.message}`); } } ``` ### setDisplayLevel11+ setDisplayLevel(displayLevel: number): void 设置人像相册的显示级别。 **系统接口**:此接口为系统接口。 **系统能力**:SystemCapability.FileManagement.PhotoAccessHelper.Core **参数:** | 参数名 | 类型 | 必填 | 说明 | | ---------- | ------- | ---- | ---------------------------------- | | displayLevel | number | 是 | 设置人像相册的显示级别, 0:取消该人像相册收藏;1:设置人像相册为首届面;2:设置人像相册为更多界面;3:设置人像相册为收藏界面。 | **错误码:** 接口抛出错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)和[文件管理错误码](../apis-core-file-kit/errorcode-filemanagement.md)。 | 错误码ID | 错误信息 | | -------- | ---------------------------------------- | | 202 | Called by non-system application. | | 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types; 3. Parameter verification failed. | | 14000011 | System inner fail. | **示例:** phAccessHelper的创建请参考[@ohos.file.photoAccessHelper (相册管理模块)](arkts-apis-photoAccessHelper-f.md)的示例使用。 ``` ts import { dataSharePredicates } from '@kit.ArkData'; async function example(phAccessHelper: photoAccessHelper.PhotoAccessHelper) { try { console.info('setDisplayLevel Example') let predicates: dataSharePredicates.DataSharePredicates = new dataSharePredicates.DataSharePredicates(); predicates.equalTo('user_display_level', 2); let fetchOptions: photoAccessHelper.FetchOptions = { fetchColumns: [], predicates: predicates }; let fetchResult: photoAccessHelper.FetchResult = await phAccessHelper.getAlbums(photoAccessHelper.AlbumType.SMART, photoAccessHelper.AlbumSubtype.PORTRAIT, fetchOptions); let album: photoAccessHelper.Album = await fetchResult.getFirstObject(); let changeRequest: photoAccessHelper.MediaAlbumChangeRequest = new photoAccessHelper.MediaAlbumChangeRequest(album); changeRequest.setDisplayLevel(1); await phAccessHelper.applyChanges(changeRequest); } catch (err) { console.error(`setDisplayLevel failed with error: ${err.code}, ${err.message}`); } } ``` ### setIsMe11+ setIsMe(): void 将人像相册的人物关系设置为“我”。 **系统接口**:此接口为系统接口。 **系统能力**:SystemCapability.FileManagement.PhotoAccessHelper.Core **错误码:** 接口抛出错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)和[文件管理错误码](../apis-core-file-kit/errorcode-filemanagement.md)。 | 错误码ID | 错误信息 | | -------- | ---------------------------------------- | | 202 | Called by non-system application. | | 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types. | | 14000011 | System inner fail. | **示例:** phAccessHelper的创建请参考[@ohos.file.photoAccessHelper (相册管理模块)](arkts-apis-photoAccessHelper-f.md)的示例使用。 ``` ts import { dataSharePredicates } from '@kit.ArkData'; async function example(phAccessHelper: photoAccessHelper.PhotoAccessHelper) { try { console.info('setIsMe Example') let predicates: dataSharePredicates.DataSharePredicates = new dataSharePredicates.DataSharePredicates(); predicates.equalTo('user_display_level', 2); let fetchOptions: photoAccessHelper.FetchOptions = { fetchColumns: [], predicates: predicates }; let fetchResult: photoAccessHelper.FetchResult = await phAccessHelper.getAlbums(photoAccessHelper.AlbumType.SMART, photoAccessHelper.AlbumSubtype.PORTRAIT, fetchOptions); let album: photoAccessHelper.Album = await fetchResult.getFirstObject(); let changeRequest: photoAccessHelper.MediaAlbumChangeRequest = new photoAccessHelper.MediaAlbumChangeRequest(album); changeRequest.setIsMe(); await phAccessHelper.applyChanges(changeRequest); } catch (err) { console.error(`setIsMe failed with error: ${err.code}, ${err.message}`); } } ``` ### dismissAssets11+ dismissAssets(assets: Array<PhotoAsset>): void 从该人像相册或合影相册中移除指定图片。 **系统接口**:此接口为系统接口。 **系统能力**:SystemCapability.FileManagement.PhotoAccessHelper.Core **参数:** | 参数名 | 类型 | 必填 | 说明 | | ---------- | ------- | ---- | ---------------------------------- | | assets | Array<PhotoAsset> | 是 | 需要移除的文件列表。 | **错误码:** 接口抛出错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)和[文件管理错误码](../apis-core-file-kit/errorcode-filemanagement.md)。 | 错误码ID | 错误信息 | | -------- | ---------------------------------------- | | 202 | Called by non-system application. | | 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types; 3. Parameter verification failed. | | 14000011 | System inner fail. | | 14000016 | Operation Not support. | **示例:** phAccessHelper的创建请参考[@ohos.file.photoAccessHelper (相册管理模块)](arkts-apis-photoAccessHelper-f.md)的示例使用。 ``` ts import { dataSharePredicates } from '@kit.ArkData'; async function example(phAccessHelper: photoAccessHelper.PhotoAccessHelper) { try { console.info('dismissAssets Example') let predicates: dataSharePredicates.DataSharePredicates = new dataSharePredicates.DataSharePredicates(); predicates.equalTo('user_display_level', 2); let fetchOptions: photoAccessHelper.FetchOptions = { fetchColumns: [], predicates: predicates }; let fetchResult: photoAccessHelper.FetchResult = await phAccessHelper.getAlbums(photoAccessHelper.AlbumType.SMART, photoAccessHelper.AlbumSubtype.PORTRAIT, fetchOptions); let album: photoAccessHelper.Album = await fetchResult.getFirstObject(); let predicatesAsset: dataSharePredicates.DataSharePredicates = new dataSharePredicates.DataSharePredicates(); let assetFetchOptions: photoAccessHelper.FetchOptions = { fetchColumns: [], predicates: predicatesAsset }; let assetFetchResult: photoAccessHelper.FetchResult = await phAccessHelper.getAssets(assetFetchOptions); let asset: photoAccessHelper.PhotoAsset = await assetFetchResult.getFirstObject(); let changeRequest: photoAccessHelper.MediaAlbumChangeRequest = new photoAccessHelper.MediaAlbumChangeRequest(album); changeRequest.dismissAssets([asset]); await phAccessHelper.applyChanges(changeRequest); } catch (err) { console.error(`dismissAssets failed with error: ${err.code}, ${err.message}`); } } ``` ### mergeAlbum11+ mergeAlbum(target: Album): void 将两个人像相册合并。 **系统接口**:此接口为系统接口。 **系统能力**:SystemCapability.FileManagement.PhotoAccessHelper.Core **参数:** | 参数名 | 类型 | 必填 | 说明 | | ---------- | ------- | ---- | ---------------------------------- | | target | [Album](#album) | 是 | 需要合并的目标相册,合并相册必须重命名。 | **错误码:** 接口抛出错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)和[文件管理错误码](../apis-core-file-kit/errorcode-filemanagement.md)。 | 错误码ID | 错误信息 | | -------- | ---------------------------------------- | | 202 | Called by non-system application. | | 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types; 3. Parameter verification failed. | | 14000011 | System inner fail. | | 14000016 | Operation Not support. | **示例:** phAccessHelper的创建请参考[@ohos.file.photoAccessHelper (相册管理模块)](arkts-apis-photoAccessHelper-f.md)的示例使用。 ``` ts import { dataSharePredicates } from '@kit.ArkData'; async function example(phAccessHelper: photoAccessHelper.PhotoAccessHelper) { try { console.info('mergeAlbum Example') let predicates: dataSharePredicates.DataSharePredicates = new dataSharePredicates.DataSharePredicates(); predicates.equalTo('user_display_level', 2); let fetchOptions: photoAccessHelper.FetchOptions = { fetchColumns: [], predicates: predicates }; let fetchResult: photoAccessHelper.FetchResult = await phAccessHelper.getAlbums(photoAccessHelper.AlbumType.SMART, photoAccessHelper.AlbumSubtype.PORTRAIT, fetchOptions); let album: photoAccessHelper.Album = await fetchResult.getFirstObject(); if (fetchResult.isAfterLast()) { console.error('lack of album to merge'); return; } let target: photoAccessHelper.Album = await fetchResult.getNextObject(); let changeRequest: photoAccessHelper.MediaAlbumChangeRequest = new photoAccessHelper.MediaAlbumChangeRequest(album); changeRequest.mergeAlbum(target); changeRequest.setAlbumName("testName"); await phAccessHelper.applyChanges(changeRequest); } catch (err) { console.error(`mergeAlbum failed with error: ${err.code}, ${err.message}`); } } ``` ### placeBefore11+ placeBefore(album: Album): void; 将当前相册排序到目标相册之前。 **系统接口**:此接口为系统接口。 **系统能力**:SystemCapability.FileManagement.PhotoAccessHelper.Core **参数:** | 参数名 | 类型 | 必填 | 说明 | | ---------- | ------- | ---- | ---------------------------------- | | album | [Album](#album) | 是 | 目标相册。如果要将当前相册排序到末位,则目标相册传入null。 | **错误码:** 接口抛出错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)和[文件管理错误码](../apis-core-file-kit/errorcode-filemanagement.md)。 | 错误码ID | 错误信息 | | -------- | ---------------------------------------- | | 202 | Called by non-system application. | | 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types; 3. Parameter verification failed. | | 14000011 | System inner fail. | **示例:** phAccessHelper的创建请参考[@ohos.file.photoAccessHelper (相册管理模块)](arkts-apis-photoAccessHelper-f.md)的示例使用。 ```ts async function example(phAccessHelper: photoAccessHelper.PhotoAccessHelper) { console.info('placeBeforeDemo'); try { let albumFetchResult: photoAccessHelper.FetchResult = await phAccessHelper.getAlbums(photoAccessHelper.AlbumType.USER, photoAccessHelper.AlbumSubtype.USER_GENERIC); let firstAlbum: photoAccessHelper.Album = await albumFetchResult.getFirstObject(); if (albumFetchResult.isAfterLast()) { console.error('lack of album to place before'); return; } let secondAlbum: photoAccessHelper.Album = await albumFetchResult.getNextObject(); let albumChangeRequest: photoAccessHelper.MediaAlbumChangeRequest = new photoAccessHelper.MediaAlbumChangeRequest(secondAlbum); albumChangeRequest.placeBefore(firstAlbum); await phAccessHelper.applyChanges(albumChangeRequest); console.info('placeBefore successfully'); } catch (err) { console.error(`placeBeforeDemo failed with error: ${err.code}, ${err.message}`); } } ``` ### dismiss13+ dismiss(): void 删除合影相册。 **系统接口**:此接口为系统接口。 **系统能力**:SystemCapability.FileManagement.PhotoAccessHelper.Core **错误码:** 接口抛出错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)和[文件管理错误码](../apis-core-file-kit/errorcode-filemanagement.md)。 | 错误码ID | 错误信息 | | :------- | :-------------------------------- | | 202 | Called by non-system application. | | 401 | Parameter error. Possible causes: Incorrect parameter types. | | 14000011 | System inner fail. | **示例:** phAccessHelper的创建请参考[@ohos.file.photoAccessHelper (相册管理模块)](arkts-apis-photoAccessHelper-f.md)的示例使用。 ```ts import { dataSharePredicates } from '@kit.ArkData'; async function example(phAccessHelper: photoAccessHelper.PhotoAccessHelper) { console.info('dismissDemo'); try { let albumFetchResult: photoAccessHelper.FetchResult = await phAccessHelper.getAlbums(photoAccessHelper.AlbumType.SMART, photoAccessHelper.AlbumSubtype.GROUP_PHOTO); let album: photoAccessHelper.Album = await albumFetchResult.getFirstObject(); let albumChangeRequest: photoAccessHelper.MediaAlbumChangeRequest = new photoAccessHelper.MediaAlbumChangeRequest(album); albumChangeRequest.dismiss(); await phAccessHelper.applyChanges(albumChangeRequest); console.info('dismiss successfully'); } catch (err) { console.error(`dismissDemo failed with error: ${err.code}, ${err.message}`); } } ``` ## HighlightAlbum12+ 时刻相册。 **系统接口**:此接口为系统接口。 **系统能力**:SystemCapability.FileManagement.PhotoAccessHelper.Core ### constructor12+ constructor(album: Album) 构造函数。 **系统接口**:此接口为系统接口。 **系统能力**:SystemCapability.FileManagement.PhotoAccessHelper.Core **参数:** | 参数名 | 类型 | 必填 | 说明 | | -------- | ------------------------- | ---- | ---------- | | album | [Album](#album) | 是 | 智慧相册。 | **错误码:** 接口抛出错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)和[文件管理错误码](../apis-core-file-kit/errorcode-filemanagement.md)。 | 错误码ID | 错误信息 | | -------- | ---------------------------------------- | | 202 | Called by non-system application. | | 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types; 3. Parameter verification failed. | | 14000011 | Internal system error. | **示例:** ```ts import { dataSharePredicates } from '@kit.ArkData'; async function example(phAccessHelper: photoAccessHelper.PhotoAccessHelper) { console.info('HighlightAlbum constructorDemo'); let predicates: dataSharePredicates.DataSharePredicates = new dataSharePredicates.DataSharePredicates(); let fetchOption: photoAccessHelper.FetchOptions = { fetchColumns: [], predicates: predicates }; let albumFetchResult: photoAccessHelper.FetchResult = await phAccessHelper.getAlbums( photoAccessHelper.AlbumType.SMART, photoAccessHelper.AlbumSubtype.HIGHLIGHT, fetchOption); let album: photoAccessHelper.Album = await albumFetchResult.getFirstObject(); let highlightAlbum: photoAccessHelper.HighlightAlbum = new photoAccessHelper.HighlightAlbum(album); albumFetchResult.close(); } ``` ### getHighlightAlbumInfo12+ getHighlightAlbumInfo(type: HighlightAlbumInfoType): Promise<string> 获取指定时刻相册的特定信息。 **系统接口**:此接口为系统接口。 **需要权限**:ohos.permission.READ\_IMAGEVIDEO **系统能力**:SystemCapability.FileManagement.PhotoAccessHelper.Core **参数:** | 参数名 | 类型 | 必填 | 说明 | | ---------- | ------- | ---- | ---------------------------------- | | type | [HighlightAlbumInfoType](#highlightalbuminfotype12) | 是 | 需要获取的时刻相册信息类型。 | **返回值:** | 类型 | 说明 | | --------------------------- | -------------- | | Promise<string> | Promise对象,返回指定的时刻相册信息。| **错误码:** 接口抛出错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)和[文件管理错误码](../apis-core-file-kit/errorcode-filemanagement.md)。 | 错误码ID | 错误信息 | | :------- | :-------------------------------- | | 201 | Permission denied. | | 202 | Called by non-system application. | | 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types; 3. Parameter verification failed. | | 14000011 | Internal system error. | **示例:** ```ts import { dataSharePredicates } from '@kit.ArkData'; async function example(phAccessHelper: photoAccessHelper.PhotoAccessHelper) { try { console.info('getHighlightAlbumInfoDemo') let fetchOptions: photoAccessHelper.FetchOptions = { fetchColumns: [], predicates: new dataSharePredicates.DataSharePredicates() } let albumFetchResult: photoAccessHelper.FetchResult = await phAccessHelper.getAlbums( photoAccessHelper.AlbumType.SMART, photoAccessHelper.AlbumSubtype.HIGHLIGHT, fetchOptions); let album: photoAccessHelper.Album = await albumFetchResult.getFirstObject(); if (album != undefined) { let highlightAlbum: photoAccessHelper.HighlightAlbum = new photoAccessHelper.HighlightAlbum(album); let coverInfo: string = await highlightAlbum.getHighlightAlbumInfo( photoAccessHelper.HighlightAlbumInfoType.COVER_INFO); console.info('get cover info result: ' + JSON.stringify(coverInfo)); } albumFetchResult.close(); } catch (err) { console.error(`getHighlightAlbumInfoDemofailed with error: ${err.code}, ${err.message}`); } } ``` ### getHighlightResource12+ getHighlightResource(resourceUri: string): Promise<ArrayBuffer> 获取指定时刻缓存资源的ArrayBuffer。 **系统接口**:此接口为系统接口。 **需要权限**:ohos.permission.READ\_IMAGEVIDEO **系统能力**:SystemCapability.FileManagement.PhotoAccessHelper.Core **参数:** | 参数名 | 类型 | 必填 | 说明 | | ---------- | ------- | ---- | ---------------------------------- | | resourceUri | string | 是 | 指定时刻缓存资源uri。 | **返回值:** | 类型 | 说明 | | --------------------------- | -------------- | | Promise<ArrayBuffer> | Promise对象,返回资源的ArrayBuffer。| **错误码:** 接口抛出错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)和[文件管理错误码](../apis-core-file-kit/errorcode-filemanagement.md)。 | 错误码ID | 错误信息 | | :------- | :-------------------------------- | | 201 | Permission denied. | | 202 | Called by non-system application. | | 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types; 3. Parameter verification failed. | | 14000011 | Internal system error. Possible causes: 1. The database is corrupted; 2. The file system is abnormal; 3. The IPC request timed out; 4. Permission denied. | **示例:** ```ts import { dataSharePredicates } from '@kit.ArkData'; async function example(phAccessHelper: photoAccessHelper.PhotoAccessHelper) { try { console.info('getHighlightResourceDemo') let fetchOptions: photoAccessHelper.FetchOptions = { fetchColumns: [], predicates: new dataSharePredicates.DataSharePredicates() } let albumFetchResult: photoAccessHelper.FetchResult = await phAccessHelper.getAlbums( photoAccessHelper.AlbumType.SMART, photoAccessHelper.AlbumSubtype.HIGHLIGHT, fetchOptions); let album: photoAccessHelper.Album = await albumFetchResult.getFirstObject(); if (album != undefined) { let highlightAlbum: photoAccessHelper.HighlightAlbum = new photoAccessHelper.HighlightAlbum(album); let uri: string = 'file://media/highlight/cover/10/1_1/background.png?oper=highlight' let arrayBuffer: ArrayBuffer = await highlightAlbum.getHighlightResource(uri); } albumFetchResult.close(); } catch (err) { console.error(`getHighlightResourceDemofailed with error: ${err.code}, ${err.message}`); } } ``` ### setHighlightUserActionData12+ setHighlightUserActionData(type: HighlightUserActionType, actionData: number): Promise<void> 设置指定时刻用户行为数据。 **系统接口**:此接口为系统接口。 **需要权限**:ohos.permission.WRITE\_IMAGEVIDEO **系统能力**:SystemCapability.FileManagement.PhotoAccessHelper.Core **参数:** | 参数名 | 类型 | 必填 | 说明 | | ---------- | ------- | ---- | ---------------------------------- | | type | [HighlightUserActionType](#highlightuseractiontype12) | 是 | 需要设置的用户行为数据类型。 | | actionData | number | 是 | 行为数据。 | **返回值:** | 类型 | 说明 | | --------------------------- | -------------- | | Promise<void> | Promise对象。无返回结果的Promise对象。| **错误码:** 接口抛出错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)和[文件管理错误码](../apis-core-file-kit/errorcode-filemanagement.md)。 | 错误码ID | 错误信息 | | :------- | :-------------------------------- | | 201 | Permission denied. | | 202 | Called by non-system application. | | 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types; 3. Parameter verification failed. | | 14000011 | Internal system error. | **示例:** ```ts import { dataSharePredicates } from '@kit.ArkData'; async function example(phAccessHelper: photoAccessHelper.PhotoAccessHelper) { try { console.info('setHighlightUserActionDataDemo') let fetchOptions: photoAccessHelper.FetchOptions = { fetchColumns: [], predicates: new dataSharePredicates.DataSharePredicates() } let albumFetchResult: photoAccessHelper.FetchResult = await phAccessHelper.getAlbums( photoAccessHelper.AlbumType.SMART, photoAccessHelper.AlbumSubtype.HIGHLIGHT, fetchOptions); let album: photoAccessHelper.Album = await albumFetchResult.getFirstObject(); if (album != undefined) { let highlightAlbum: photoAccessHelper.HighlightAlbum = new photoAccessHelper.HighlightAlbum(album); highlightAlbum.setHighlightUserActionData(photoAccessHelper.HighlightUserActionType.INSERTED_PIC_COUNT, 1); } albumFetchResult.close(); } catch (err) { console.error(`setHighlightUserActionDataDemofailed with error: ${err.code}, ${err.message}`); } } ``` ### setSubTitle18+ setSubTitle(title: string): void 设置时刻副标题内容。 副标题参数规格为: - 副标题字符串长度为0~255。 - 不允许出现的非法英文字符,包括:
. \ / : * ? " ' ` < > | { } [ ] - 英文字符大小写不敏感。 **系统接口**:此接口为系统接口。 **需要权限**:ohos.permission.WRITE\_IMAGEVIDEO **系统能力**:SystemCapability.FileManagement.PhotoAccessHelper.Core **参数:** | 参数名 | 类型 | 必填 | 说明 | | ---------- | ------- | ---- | ---------------------------------- | | title | string | 是 | 需要设置的时刻副标题内容。 | **错误码:** 以下错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)和[文件管理错误码](../apis-core-file-kit/errorcode-filemanagement.md)。 | 错误码ID | 错误信息 | | :------- | :-------------------------------- | | 201 | Permission denied. | | 202 | Called by non-system application. | | 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types; 3. Parameter verification failed. | | 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. | **示例:** ```ts import { dataSharePredicates } from '@kit.ArkData'; async function example(context: Context) { try { console.info('setSubTitle'); let helper: photoAccessHelper.PhotoAccessHelper = photoAccessHelper.getPhotoAccessHelper(context); let albumFetchOption: photoAccessHelper.FetchOptions = { fetchColumns: [], predicates: new dataSharePredicates.DataSharePredicates() }; let albumFetchResult: photoAccessHelper.FetchResult = await helper.getAlbums(photoAccessHelper.AlbumType.SMART, photoAccessHelper.AlbumSubtype.HIGHLIGHT, albumFetchOption); if (albumFetchResult.getCount() === 0) { console.error('No album'); return; } let highlightAlbum: photoAccessHelper.Album = await albumFetchResult.getFirstObject(); albumFetchResult.close(); let changeHighlightAlbumRequest: photoAccessHelper.HighlightAlbum = new photoAccessHelper.HighlightAlbum(highlightAlbum); changeHighlightAlbumRequest.setSubTitle("testName"); console.info('setSubTitle success'); } catch (err) { console.error(`setSubTitle with error: ${err}`); } } ``` ### deleteHighlightAlbums18+ static deleteHighlightAlbums(context: Context, albums: Array<Album>): Promise<number> 删除指定时刻相册。 **系统接口**:此接口为系统接口。 **需要权限**:ohos.permission.WRITE\_IMAGEVIDEO **系统能力**:SystemCapability.FileManagement.PhotoAccessHelper.Core **参数:** | 参数名 | 类型 | 必填 | 说明 | | ---------- | ------- | ---- | ---------------------------------- | | context | [Context](../apis-ability-kit/js-apis-inner-application-context.md) | 是 | 传入Ability实例的Context。 | | albums | Array<[Album](#album)> | 是 | 需要删除的时刻相册。 | **返回值:** | 类型 | 说明 | | :------------------ | :---------------------------------- | | Promise<number> | 是否成功删除相册。成功返回0,失败返回1。 | **错误码:** 以下错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)和[文件管理错误码](../apis-core-file-kit/errorcode-filemanagement.md)。 | 错误码ID | 错误信息 | | :------- | :-------------------------------- | | 201 | Permission denied. | | 202 | Called by non-system application. | | 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types; 3. Parameter verification failed. | | 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. | **示例:** ```ts import { dataSharePredicates } from '@kit.ArkData'; async function example(context: Context) { try { console.info('deleteHighlightAlbums'); let helper: photoAccessHelper.PhotoAccessHelper = photoAccessHelper.getPhotoAccessHelper(context); let albumFetchOption: photoAccessHelper.FetchOptions = { fetchColumns: [], predicates: new dataSharePredicates.DataSharePredicates() }; let albumFetchResult: photoAccessHelper.FetchResult = await helper.getAlbums(photoAccessHelper.AlbumType.SMART, photoAccessHelper.AlbumSubtype.HIGHLIGHT, albumFetchOption); if (albumFetchResult.getCount() === 0) { console.error('No album'); return; } let highlightAlbum: photoAccessHelper.Album = await albumFetchResult.getFirstObject(); albumFetchResult.close(); let result = await photoAccessHelper.HighlightAlbum.deleteHighlightAlbums(context, [highlightAlbum]); console.info('deleteHighlightAlbums success'); } catch (err) { console.error(`deleteHighlightAlbums with error: ${err}`); } } ``` ## MediaAnalysisAlbumChangeRequest18+ 智慧相册变更请求。 **系统能力**:SystemCapability.FileManagement.PhotoAccessHelper.Core ### constructor18+ constructor(album: Album) 构造函数。 **系统接口**:此接口为系统接口。 **系统能力**:SystemCapability.FileManagement.PhotoAccessHelper.Core **参数:** | 参数名 | 类型 | 必填 | 说明 | | ---------- | ------- | ---- | ---------------------------------- | | album | [Album](#album) | 是 | 智慧相册。 | **错误码:** 以下错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)和[文件管理错误码](../apis-core-file-kit/errorcode-filemanagement.md)。 | 错误码ID | 错误信息 | | -------- | ---------------------------------------- | | 202 | Called by non-system application. | | 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types; 3. Parameter verification failed. | **示例:** ```ts import { dataSharePredicates } from '@kit.ArkData'; async function example(context: Context) { console.info('MediaAnalysisAlbumChangeRequest constructorDemo'); let helper: photoAccessHelper.PhotoAccessHelper = photoAccessHelper.getPhotoAccessHelper(context); let albumFetchOption: photoAccessHelper.FetchOptions = { fetchColumns: [], predicates: new dataSharePredicates.DataSharePredicates() }; let albumFetchResult: photoAccessHelper.FetchResult = await helper.getAlbums(photoAccessHelper.AlbumType.SMART, photoAccessHelper.AlbumSubtype.HIGHLIGHT, albumFetchOption); if (albumFetchResult.getCount() === 0) { console.error('No album'); return; } let highlightAlbum: photoAccessHelper.Album = await albumFetchResult.getFirstObject(); albumFetchResult.close(); let changeRequest: photoAccessHelper.MediaAnalysisAlbumChangeRequest = new photoAccessHelper.MediaAnalysisAlbumChangeRequest(highlightAlbum); } ``` ### setOrderPosition18+ setOrderPosition(assets: Array<PhotoAsset>, position: Array<number>): void 设置智慧相册中资产的顺序位置。 **系统接口**:此接口为系统接口。 **需要权限**:ohos.permission.WRITE\_IMAGEVIDEO **系统能力**:SystemCapability.FileManagement.PhotoAccessHelper.Core **参数:** | 参数名 | 类型 | 必填 | 说明 | | ---------- | ------- | ---- | ---------------------------------- | | assets | Array<[PhotoAsset](#photoasset)> | 是 | 需要设置顺序位置的相册中资产。 | | position | Array<number> | 是 | 相册中资产的顺序位置。 | **错误码:** 以下错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)和[文件管理错误码](../apis-core-file-kit/errorcode-filemanagement.md)。 | 错误码ID | 错误信息 | | :------- | :-------------------------------- | | 201 | Permission denied. | | 202 | Called by non-system application. | | 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types; 3. Parameter verification failed. | | 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. | **示例:** ```ts import { dataSharePredicates } from '@kit.ArkData'; async function example(context: Context) { try { console.info('setOrderPosition'); let helper: photoAccessHelper.PhotoAccessHelper = photoAccessHelper.getPhotoAccessHelper(context); let albumFetchOption: photoAccessHelper.FetchOptions = { fetchColumns: [], predicates: new dataSharePredicates.DataSharePredicates() }; let albumFetchResult: photoAccessHelper.FetchResult = await helper.getAlbums(photoAccessHelper.AlbumType.SMART, photoAccessHelper.AlbumSubtype.HIGHLIGHT, albumFetchOption); if (albumFetchResult.getCount() === 0) { console.error('No album'); return; } let highlightAlbum: photoAccessHelper.Album = await albumFetchResult.getFirstObject(); albumFetchResult.close(); let predicates: dataSharePredicates.DataSharePredicates = new dataSharePredicates.DataSharePredicates(); const fetchOption: photoAccessHelper.FetchOptions = { fetchColumns: [], predicates: predicates }; let fetchResult: photoAccessHelper.FetchResult = await highlightAlbum.getAssets(fetchOption); let assets: photoAccessHelper.PhotoAsset[] = await fetchResult.getAllObjects(); let indexes: number[] = []; for (let i = 0; i < assets.length; i++) { indexes.push(i); } let changeRequest: photoAccessHelper.MediaAnalysisAlbumChangeRequest = new photoAccessHelper.MediaAnalysisAlbumChangeRequest(highlightAlbum); changeRequest.setOrderPosition(assets, indexes); await helper.applyChanges(changeRequest); console.info(`setOrderPosition ${indexes}`); } catch (err) { console.error(`setOrderPosition error: ${err}`); } } ``` ## AnalysisAlbum18+ 智慧相册。 **系统能力**:SystemCapability.FileManagement.PhotoAccessHelper.Core ### constructor18+ constructor(album: Album) 构造函数。 **系统接口**:此接口为系统接口。 **系统能力**:SystemCapability.FileManagement.PhotoAccessHelper.Core **参数:** | 参数名 | 类型 | 必填 | 说明 | | ---------- | ------- | ---- | ---------------------------------- | | album | [Album](#album) | 是 | 智慧相册。 | **错误码:** 以下错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)和[文件管理错误码](../apis-core-file-kit/errorcode-filemanagement.md)。 | 错误码ID | 错误信息 | | -------- | ---------------------------------------- | | 202 | Called by non-system application. | | 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types; 3. Parameter verification failed. | **示例:** ```ts import { dataSharePredicates } from '@kit.ArkData'; async function example(context: Context) { console.info('AnalysisAlbum constructorDemo'); let helper: photoAccessHelper.PhotoAccessHelper = photoAccessHelper.getPhotoAccessHelper(context); let albumFetchOption: photoAccessHelper.FetchOptions = { fetchColumns: [], predicates: new dataSharePredicates.DataSharePredicates() }; let albumFetchResult: photoAccessHelper.FetchResult = await helper.getAlbums(photoAccessHelper.AlbumType.SMART, photoAccessHelper.AlbumSubtype.HIGHLIGHT, albumFetchOption); if (albumFetchResult.getCount() === 0) { console.error('No album'); return; } let highlightAlbum: photoAccessHelper.Album = await albumFetchResult.getFirstObject(); albumFetchResult.close(); let analysisAlbum: photoAccessHelper.AnalysisAlbum = new photoAccessHelper.AnalysisAlbum(highlightAlbum); } ``` ### getOrderPosition18+ getOrderPosition(assets: Array<PhotoAsset>): Promise<Array<number>> 获取智慧相册中资产的顺序位置。 **系统接口**:此接口为系统接口。 **需要权限**:ohos.permission.READ\_IMAGEVIDEO **系统能力**:SystemCapability.FileManagement.PhotoAccessHelper.Core **参数:** | 参数名 | 类型 | 必填 | 说明 | | ---------- | ------- | ---- | ---------------------------------- | | assets | Array<[PhotoAsset](#photoasset)> | 是 | 需要获取顺序位置的相册中资产。 | **返回值:** | 类型 | 说明 | | :------------------ | :---------------------------------- | | Promise<Array<number>> | 相册中资产的顺序位置值。 | **错误码:** 以下错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)和[文件管理错误码](../apis-core-file-kit/errorcode-filemanagement.md)。 | 错误码ID | 错误信息 | | :------- | :-------------------------------- | | 201 | Permission denied. | | 202 | Called by non-system application. | | 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types; 3. Parameter verification failed. | | 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. | **示例:** ```ts import { dataSharePredicates } from '@kit.ArkData'; async function example(context: Context) { try { console.info('getOrderPosition'); let helper: photoAccessHelper.PhotoAccessHelper = photoAccessHelper.getPhotoAccessHelper(context); let albumFetchOption: photoAccessHelper.FetchOptions = { fetchColumns: [], predicates: new dataSharePredicates.DataSharePredicates() }; let albumFetchResult: photoAccessHelper.FetchResult = await helper.getAlbums(photoAccessHelper.AlbumType.SMART, photoAccessHelper.AlbumSubtype.HIGHLIGHT, albumFetchOption); if (albumFetchResult.getCount() === 0) { console.error('No album'); return; } let highlightAlbum: photoAccessHelper.Album = await albumFetchResult.getFirstObject(); albumFetchResult.close(); let predicates: dataSharePredicates.DataSharePredicates = new dataSharePredicates.DataSharePredicates(); let analysisAlbum: photoAccessHelper.AnalysisAlbum = new photoAccessHelper.AnalysisAlbum(highlightAlbum); const fetchOption: photoAccessHelper.FetchOptions = { fetchColumns: [], predicates: predicates }; let fetchResult: photoAccessHelper.FetchResult = await highlightAlbum.getAssets(fetchOption); let assets: photoAccessHelper.PhotoAsset[] = await fetchResult.getAllObjects(); let positions: number[] = await analysisAlbum.getOrderPosition(assets); console.info(`getOrderPosition ${positions}`); } catch (err) { console.error(`getOrderPosition error: ${err}`); } } ``` ## CloudEnhancement13+ 云增强管理类,该类用于生成AI云增强照片任务的管理、获取原照片与AI云增强照片的关联关系。 **系统接口**:此接口为系统接口。 **系统能力**:SystemCapability.FileManagement.PhotoAccessHelper.Core ### getCloudEnhancementInstance13+ static getCloudEnhancementInstance(context: Context): CloudEnhancement 获取云增强类实例。 **系统接口**:此接口为系统接口。 **系统能力**:SystemCapability.FileManagement.PhotoAccessHelper.Core **参数:** | 参数名 | 类型 | 必填 | 说明 | | -------- | ------------------------- | ---- | ---------- | | context | [Context](../apis-ability-kit/js-apis-inner-application-context.md) | 是 | 传入Ability实例的Context。 | **返回值:** | 类型 | 说明 | | --------------------------------------- | ----------------- | | [CloudEnhancement](#cloudenhancement13) | 返回云增强管理类实例。 | **错误码:** 接口抛出错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)和[文件管理错误码](../apis-core-file-kit/errorcode-filemanagement.md)。 | 错误码ID | 错误信息 | | -------- | ---------------------------------------- | | 202 | Called by non-system application. | | 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types; 3. Parameter verification failed. | | 14000011 | Internal system error. | **示例:** ```ts import { dataSharePredicates } from '@kit.ArkData'; async function example(context: Context) { console.info('getCloudEnhancementInstanceDemo'); let photoPredicates: dataSharePredicates.DataSharePredicates = new dataSharePredicates.DataSharePredicates(); let photoFetchOptions: photoAccessHelper.FetchOptions = { fetchColumns: [], predicates: photoPredicates }; let phAccessHelper = photoAccessHelper.getPhotoAccessHelper(context); try { let fetchResult = await phAccessHelper.getAssets(photoFetchOptions); let asset = await fetchResult.getLastObject(); let cloudEnhancementInstance: photoAccessHelper.CloudEnhancement = photoAccessHelper.CloudEnhancement.getCloudEnhancementInstance(context); let hasCloudWatermark = true; await cloudEnhancementInstance.submitCloudEnhancementTasks([asset], hasCloudWatermark); } catch (err) { console.error(`getCloudEnhancementInstanceDemo failed with error: ${err.code}, ${err.message}`); } } ``` ### submitCloudEnhancementTasks13+ submitCloudEnhancementTasks(photoAssets: Array<PhotoAsset>, hasCloudWatermark: boolean): Promise<void> 提交云增强任务。 **系统接口**:此接口为系统接口。 **系统能力**:SystemCapability.FileManagement.PhotoAccessHelper.Core **需要权限**:ohos.permission.WRITE_IMAGEVIDEO **参数:** | 参数名 | 类型 | 必填 | 说明 | | -------- | ------------------------- | ---- | ---------- | | photoAssets | Array<[PhotoAsset](#photoasset)> | 是 | 需要增强照片的[PhotoAsset](#photoasset)集合。 | | hasCloudWatermark | boolean | 是 | 增强后图片是否添加云增强水印。 | **返回值:** | 类型 | 说明 | | ------------------- | ---------- | | Promise<void> | Promise对象,返回void。 | **错误码:** 接口抛出错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)和[文件管理错误码](../apis-core-file-kit/errorcode-filemanagement.md)。 | 错误码ID | 错误信息 | | -------- | ---------------------------------------- | | 201 | Permission denied. | | 202 | Called by non-system application. | | 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types; 3. Parameter verification failed. | | 14000011 | Internal system error. | **示例:** phAccessHelper的创建请参考[@ohos.file.photoAccessHelper (相册管理模块)](arkts-apis-photoAccessHelper-f.md)的示例使用。 ```ts import { dataSharePredicates } from '@kit.ArkData'; async function example(context: Context) { console.info('submitCloudEnhancementTasksDemo'); let photoPredicates: dataSharePredicates.DataSharePredicates = new dataSharePredicates.DataSharePredicates(); let photoFetchOptions: photoAccessHelper.FetchOptions = { fetchColumns: [], predicates: photoPredicates }; let phAccessHelper = photoAccessHelper.getPhotoAccessHelper(context); try { let fetchResult = await phAccessHelper.getAssets(photoFetchOptions); let asset = await fetchResult.getLastObject(); let cloudEnhancementInstance: photoAccessHelper.CloudEnhancement = photoAccessHelper.CloudEnhancement.getCloudEnhancementInstance(context); let hasCloudWatermark = true; await cloudEnhancementInstance.submitCloudEnhancementTasks([asset], hasCloudWatermark); } catch (err) { console.error(`submitCloudEnhancementTasksDemo failed with error: ${err.code}, ${err.message}`); } } ``` ### submitCloudEnhancementTasks18+ submitCloudEnhancementTasks(photoAssets: Array<PhotoAsset>, hasCloudWatermark: boolean, triggerMode?: number): Promise<void> 提交云增强任务。 **系统接口**:此接口为系统接口。 **系统能力**:SystemCapability.FileManagement.PhotoAccessHelper.Core **需要权限**:ohos.permission.WRITE_IMAGEVIDEO **参数:** | 参数名 | 类型 | 必填 | 说明 | | -------- | ------------------------- | ---- | ---------- | | photoAssets | Array<[PhotoAsset](#photoasset)> | 是 | 需要增强照片的[PhotoAsset](#photoasset)集合。 | | hasCloudWatermark | boolean | 是 | 若为true,增强后图片添加云增强水印;若为false,增强后图片不添加云增强水印。 | | triggerMode | number | 否 | 云增强任务触发类型。
- 0:手动触发。
- 1:自动触发。
- 默认值为0。 | **返回值:** | 类型 | 说明 | | ------------------- | ---------- | | Promise<void> | Promise对象,返回void。 | **错误码:** 以下错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)和[文件管理错误码](../apis-core-file-kit/errorcode-filemanagement.md)。 | 错误码ID | 错误信息 | | -------- | ---------------------------------------- | | 201 | Permission denied. | | 202 | Called by non-system application. | | 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types; 3. Parameter verification failed. | | 14000011 | Internal system error. | **示例:** phAccessHelper的创建请参考[@ohos.file.photoAccessHelper (相册管理模块)](arkts-apis-photoAccessHelper-f.md)的示例使用。 ```ts import { dataSharePredicates } from '@kit.ArkData'; async function example(context: Context) { console.info('submitCloudEnhancementTasksDemo'); let photoPredicates: dataSharePredicates.DataSharePredicates = new dataSharePredicates.DataSharePredicates(); let photoFetchOptions: photoAccessHelper.FetchOptions = { fetchColumns: [], predicates: photoPredicates }; let phAccessHelper = photoAccessHelper.getPhotoAccessHelper(context); try { let fetchResult = await phAccessHelper.getAssets(photoFetchOptions); let asset = await fetchResult.getLastObject(); let cloudEnhancementInstance: photoAccessHelper.CloudEnhancement = photoAccessHelper.CloudEnhancement.getCloudEnhancementInstance(context); let hasCloudWatermark = true; let triggerAuto = 1; await cloudEnhancementInstance.submitCloudEnhancementTasks([asset], hasCloudWatermark, triggerAuto); } catch (err) { console.error(`submitCloudEnhancementTasksDemo failed with error: ${err.code}, ${err.message}`); } } ``` ### prioritizeCloudEnhancementTask13+ prioritizeCloudEnhancementTask(photoAsset: PhotoAsset): Promise<void> 提升指定云增强任务的优先级。 **系统接口**:此接口为系统接口。 **系统能力**:SystemCapability.FileManagement.PhotoAccessHelper.Core **需要权限**:ohos.permission.WRITE_IMAGEVIDEO **参数:** | 参数名 | 类型 | 必填 | 说明 | | -------- | ------------------------- | ---- | ---------- | | photoAsset | [PhotoAsset](#photoasset) | 是 | 需要修改云增强优先级照片的[PhotoAsset](#photoasset)。 | **返回值:** | 类型 | 说明 | | ------------------- | ---------- | | Promise<void> | Promise对象,返回void。 | **错误码:** 接口抛出错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)和[文件管理错误码](../apis-core-file-kit/errorcode-filemanagement.md)。 | 错误码ID | 错误信息 | | -------- | ---------------------------------------- | | 201 | Permission denied. | | 202 | Called by non-system application. | | 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types; 3. Parameter verification failed. | | 14000011 | Internal system error. | **示例:** phAccessHelper的创建请参考[@ohos.file.photoAccessHelper (相册管理模块)](arkts-apis-photoAccessHelper-f.md)的示例使用。 ```ts import { dataSharePredicates } from '@kit.ArkData'; async function example(context: Context) { console.info('prioritizeCloudEnhancementTaskDemo'); let photoPredicates: dataSharePredicates.DataSharePredicates = new dataSharePredicates.DataSharePredicates(); // 查询进行中的云增强任务。 photoPredicates.equalTo(photoAccessHelper.PhotoKeys.CE_AVAILABLE, 2); let photoFetchOptions: photoAccessHelper.FetchOptions = { fetchColumns: [], predicates: photoPredicates }; let phAccessHelper = photoAccessHelper.getPhotoAccessHelper(context); try { let fetchResult = await phAccessHelper.getAssets(photoFetchOptions); let asset = await fetchResult.getLastObject(); let cloudEnhancementInstance: photoAccessHelper.CloudEnhancement = photoAccessHelper.CloudEnhancement.getCloudEnhancementInstance(context); let hasCloudWatermark = true; await cloudEnhancementInstance.prioritizeCloudEnhancementTask(asset); } catch (err) { console.error(`prioritizeCloudEnhancementTaskDemo failed with error: ${err.code}, ${err.message}`); } } ``` ### cancelCloudEnhancementTasks13+ cancelCloudEnhancementTasks(photoAssets: Array<PhotoAsset>): Promise<void> 取消指定云增强任务。 **系统接口**:此接口为系统接口。 **系统能力**:SystemCapability.FileManagement.PhotoAccessHelper.Core **需要权限**:ohos.permission.WRITE_IMAGEVIDEO **参数:** | 参数名 | 类型 | 必填 | 说明 | | -------- | ------------------------- | ---- | ---------- | | photoAssets | Array<[PhotoAsset](#photoasset)> | 是 | 需要取消云增强任务的[PhotoAsset](#photoasset)集合。 | **返回值:** | 类型 | 说明 | | ------------------- | ---------- | | Promise<void> | Promise对象,返回void。 | **错误码:** 接口抛出错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)和[文件管理错误码](../apis-core-file-kit/errorcode-filemanagement.md)。 | 错误码ID | 错误信息 | | -------- | ---------------------------------------- | | 201 | Permission denied. | | 202 | Called by non-system application. | | 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types; 3. Parameter verification failed. | | 14000011 | Internal system error. | **示例:** phAccessHelper的创建请参考[@ohos.file.photoAccessHelper (相册管理模块)](arkts-apis-photoAccessHelper-f.md)的示例使用。 ```ts import { dataSharePredicates } from '@kit.ArkData'; async function example(context: Context) { console.info('cancelCloudEnhancementTasksDemo'); let photoPredicates: dataSharePredicates.DataSharePredicates = new dataSharePredicates.DataSharePredicates(); // 查询进行中的云增强任务。 photoPredicates.equalTo(photoAccessHelper.PhotoKeys.CE_AVAILABLE, 2); let photoFetchOptions: photoAccessHelper.FetchOptions = { fetchColumns: [], predicates: photoPredicates }; let phAccessHelper = photoAccessHelper.getPhotoAccessHelper(context); try { let fetchResult = await phAccessHelper.getAssets(photoFetchOptions); let asset = await fetchResult.getLastObject(); let cloudEnhancementInstance: photoAccessHelper.CloudEnhancement = photoAccessHelper.CloudEnhancement.getCloudEnhancementInstance(context); await cloudEnhancementInstance.cancelCloudEnhancementTasks([asset]); } catch (err) { console.error(`cancelCloudEnhancementTasksDemo failed with error: ${err.code}, ${err.message}`); } } ``` ### cancelAllCloudEnhancementTasks13+ cancelAllCloudEnhancementTasks(): Promise<void> 取消全部云增强任务。 **系统接口**:此接口为系统接口。 **系统能力**:SystemCapability.FileManagement.PhotoAccessHelper.Core **需要权限**:ohos.permission.WRITE_IMAGEVIDEO **返回值:** | 类型 | 说明 | | ------------------- | ---------- | | Promise<void> | Promise对象,返回void。 | **错误码:** 接口抛出错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)和[文件管理错误码](../apis-core-file-kit/errorcode-filemanagement.md)。 | 错误码ID | 错误信息 | | -------- | ---------------------------------------- | | 201 | Permission denied. | | 202 | Called by non-system application. | | 14000011 | Internal system error. | **示例:** ```ts import { dataSharePredicates } from '@kit.ArkData'; async function example(context: Context) { console.info('cancelAllCloudEnhancementTasksDemo'); try { let cloudEnhancementInstance: photoAccessHelper.CloudEnhancement = photoAccessHelper.CloudEnhancement.getCloudEnhancementInstance(context); await cloudEnhancementInstance.cancelAllCloudEnhancementTasks(); } catch (err) { console.error(`cancelAllCloudEnhancementTasksDemo failed with error: ${err.code}, ${err.message}`); } } ``` ### queryCloudEnhancementTaskState13+ queryCloudEnhancementTaskState(photoAsset: PhotoAsset): Promise<CloudEnhancementTaskState> 查询云增强任务信息。 **系统接口**:此接口为系统接口。 **系统能力**:SystemCapability.FileManagement.PhotoAccessHelper.Core **需要权限**:ohos.permission.READ_IMAGEVIDEO **参数:** | 参数名 | 类型 | 必填 | 说明 | | -------- | ------------------------- | ---- | ---------- | | photoAsset | [PhotoAsset](#photoasset) | 是 | 需要查询云增强任务信息的[PhotoAsset](#photoasset)。 | **返回值:** | 类型 | 说明 | | --------------------------------------- | ----------------- | | Promise<[CloudEnhancementTaskState](#cloudenhancementtaskstate13)> | 返回云增强任务信息。 | **错误码:** 接口抛出错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)和[文件管理错误码](../apis-core-file-kit/errorcode-filemanagement.md)。 | 错误码ID | 错误信息 | | -------- | ---------------------------------------- | | 201 | Permission denied. | | 202 | Called by non-system application. | | 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types; 3. Parameter verification failed. | | 14000011 | Internal system error. | **示例:** phAccessHelper的创建请参考[@ohos.file.photoAccessHelper (相册管理模块)](arkts-apis-photoAccessHelper-f.md)的示例使用。 ```ts import { dataSharePredicates } from '@kit.ArkData'; async function example(context: Context) { console.info('queryCloudEnhancementTaskStateDemo'); let photoPredicates: dataSharePredicates.DataSharePredicates = new dataSharePredicates.DataSharePredicates(); // 查询进行中的云增强任务。 photoPredicates.equalTo(photoAccessHelper.PhotoKeys.CE_AVAILABLE, 2); let photoFetchOptions: photoAccessHelper.FetchOptions = { fetchColumns: [], predicates: photoPredicates }; let phAccessHelper = photoAccessHelper.getPhotoAccessHelper(context); try { let fetchResult = await phAccessHelper.getAssets(photoFetchOptions); let asset = await fetchResult.getLastObject(); let cloudEnhancementInstance: photoAccessHelper.CloudEnhancement = photoAccessHelper.CloudEnhancement.getCloudEnhancementInstance(context); const cloudEnhancementTaskState: photoAccessHelper.CloudEnhancementTaskState = await cloudEnhancementInstance.queryCloudEnhancementTaskState(asset); let taskStage = cloudEnhancementTaskState.taskStage; if (taskStage == photoAccessHelper.CloudEnhancementTaskStage.TASK_STAGE_EXCEPTION) { console.log("task has exception"); } else if (taskStage == photoAccessHelper.CloudEnhancementTaskStage.TASK_STAGE_PREPARING) { console.log("task is preparing"); } else if (taskStage == photoAccessHelper.CloudEnhancementTaskStage.TASK_STAGE_UPLOADING) { let transferredFileSize = cloudEnhancementTaskState.transferredFileSize; let totalFileSize = cloudEnhancementTaskState.totalFileSize; let message = `task is uploading, transferredFileSize: ${transferredFileSize}, totalFileSize: ${totalFileSize}`; console.log(message); } else if (taskStage == photoAccessHelper.CloudEnhancementTaskStage.TASK_STAGE_EXECUTING) { let expectedDuration = cloudEnhancementTaskState.expectedDuration; let message = `task is executing, expectedDuration: ${expectedDuration}`; console.log(message); } else if (taskStage == photoAccessHelper.CloudEnhancementTaskStage.TASK_STAGE_DOWNLOADING) { let transferredFileSize = cloudEnhancementTaskState.transferredFileSize; let totalFileSize = cloudEnhancementTaskState.totalFileSize; let message = `task is downloading, transferredFileSize: ${transferredFileSize}, totalFileSize: ${totalFileSize}`; console.log(message); } else if (taskStage == photoAccessHelper.CloudEnhancementTaskStage.TASK_STAGE_FAILED) { let errCode = cloudEnhancementTaskState.statusCode; let message = `task is failed, errCode: ${errCode}`; console.log(message); } else if (taskStage == photoAccessHelper.CloudEnhancementTaskStage.TASK_STAGE_COMPLETED) { console.log("task is completed"); } } catch (err) { console.error(`queryCloudEnhancementTaskStateDemo failed with error: ${err.code}, ${err.message}`); } } ``` ### syncCloudEnhancementTaskStatus13+ syncCloudEnhancementTaskStatus(): Promise<void> 同步云增强任务状态。 **系统接口**:此接口为系统接口。 **系统能力**:SystemCapability.FileManagement.PhotoAccessHelper.Core **需要权限**:ohos.permission.READ_IMAGEVIDEO **返回值:** | 类型 | 说明 | | ------------------- | ---------- | | Promise<void> | Promise对象,返回void。 | **错误码:** 接口抛出错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)和[文件管理错误码](../apis-core-file-kit/errorcode-filemanagement.md)。 | 错误码ID | 错误信息 | | -------- | ---------------------------------------- | | 201 | Permission denied. | | 202 | Called by non-system application. | | 14000011 | Internal system error. | **示例:** ```ts import { dataSharePredicates } from '@kit.ArkData'; async function example(context: Context) { console.info('syncCloudEnhancementTaskStatusDemo'); try { let cloudEnhancementInstance: photoAccessHelper.CloudEnhancement = photoAccessHelper.CloudEnhancement.getCloudEnhancementInstance(context); await cloudEnhancementInstance.syncCloudEnhancementTaskStatus(); } catch (err) { console.error(`syncCloudEnhancementTaskStatusDemo failed with error: ${err.code}, ${err.message}`); } } ``` ### getCloudEnhancementPair13+ getCloudEnhancementPair(asset: PhotoAsset): Promise<PhotoAsset> 查询云增强配对照片。 **系统接口**:此接口为系统接口。 **系统能力**:SystemCapability.FileManagement.PhotoAccessHelper.Core **需要权限**:ohos.permission.READ_IMAGEVIDEO **参数:** | 参数名 | 类型 | 必填 | 说明 | | -------- | ------------------------- | ---- | ---------- | | photoAsset | [PhotoAsset](#photoasset) | 是 | 需要查询云增强配对照片的[PhotoAsset](#photoasset)。 | **返回值:** | 类型 | 说明 | | --------------------------------------- | ----------------- | | Promise<[PhotoAsset](#photoasset)> | 返回云增强配对照片。 | **错误码:** 接口抛出错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)和[文件管理错误码](../apis-core-file-kit/errorcode-filemanagement.md)。 | 错误码ID | 错误信息 | | -------- | ---------------------------------------- | | 201 | Permission denied. | | 202 | Called by non-system application. | | 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types; 3. Parameter verification failed. | | 14000011 | Internal system error. | **示例:** phAccessHelper的创建请参考[@ohos.file.photoAccessHelper (相册管理模块)](arkts-apis-photoAccessHelper-f.md)的示例使用。 ```ts import { dataSharePredicates } from '@kit.ArkData'; async function example(context: Context) { console.info('getCloudEnhancementPairDemo'); let photoPredicates: dataSharePredicates.DataSharePredicates = new dataSharePredicates.DataSharePredicates(); // 查询已完成的云增强任务。 photoPredicates.equalTo(photoAccessHelper.PhotoKeys.CE_AVAILABLE, 5); let photoFetchOptions: photoAccessHelper.FetchOptions = { fetchColumns: [], predicates: photoPredicates }; let phAccessHelper = photoAccessHelper.getPhotoAccessHelper(context); try { let fetchResult = await phAccessHelper.getAssets(photoFetchOptions); let asset = await fetchResult.getLastObject(); let cloudEnhancementInstance: photoAccessHelper.CloudEnhancement = photoAccessHelper.CloudEnhancement.getCloudEnhancementInstance(context); let photoAsset: photoAccessHelper.PhotoAsset = await cloudEnhancementInstance.getCloudEnhancementPair(asset); } catch (err) { console.error(`getCloudEnhancementPairDemo failed with error: ${err.code}, ${err.message}`); } } ``` ### setVideoEnhancementAttr13+ setVideoEnhancementAttr(videoEnhancementType: VideoEnhancementType, photoId: string): Promise<void> 设置视频的二阶段增强处理类型。 **系统接口**:此接口为系统接口。 **需要权限**:ohos.permission.WRITE\_IMAGEVIDEO **系统能力**:SystemCapability.FileManagement.PhotoAccessHelper.Core **参数:** | 参数名 | 类型 | 必填 | 说明 | | ---------- | ------- | ---- | ---------------------------------- | | videoEnhancementType | [VideoEnhancementType](#videoenhancementtype13) | 是 | 需要进行分段式视频的处理类型。 | | photoId | string | 是 | 图片的photoId。 | **返回值:** | 类型 | 说明 | | ------------------- | ---------- | | Promise<void> | Promise对象,返回void。 | **错误码:** 接口抛出错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)和[文件管理错误码](../apis-core-file-kit/errorcode-filemanagement.md)。 | 错误码ID | 错误信息 | | :------- | :-------------------------------- | | 202 | Called by non-system application. | | 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types; 3. Parameter verification failed. | | 14000011 | Internal system error. | | 14000016 | Operation Not Support. | **示例:** phAccessHelper的创建请参考[@ohos.file.photoAccessHelper (相册管理模块)](arkts-apis-photoAccessHelper-f.md)的示例使用。 ```ts async function example(phAccessHelper: photoAccessHelper.PhotoAccessHelper, asset: photoAccessHelper.PhotoAsset) { try { let assetChangeRequest: photoAccessHelper.MediaAssetChangeRequest = new photoAccessHelper.MediaAssetChangeRequest(asset); let photoId = "202410011800"; assetChangeRequest.setVideoEnhancementAttr(photoAccessHelper.VideoEnhancementType.QUALITY_ENHANCEMENT_LOCAL, photoId); await phAccessHelper.applyChanges(assetChangeRequest); } catch (err) { console.error(`setVideoEnhancementAttr fail with error: ${err.code}, ${err.message}`); } } ``` ## CloudMediaAssetManager14+ 云端媒体资产管理类,该类用于管理云端资产的下载任务,以及删除云端资产在本地的数据和文件。 **系统接口**:此接口为系统接口。 **系统能力**:SystemCapability.FileManagement.PhotoAccessHelper.Core ### getCloudMediaAssetManagerInstance14+ static getCloudMediaAssetManagerInstance(context: Context): CloudMediaAssetManager 获取云端媒体资产管理类实例。 **系统接口**:此接口为系统接口。 **系统能力**:SystemCapability.FileManagement.PhotoAccessHelper.Core **参数:** | 参数名 | 类型 | 必填 | 说明 | | -------- | ------------------------- | ---- | ---------- | | context | [Context](../apis-ability-kit/js-apis-inner-application-context.md) | 是 | 传入Ability实例的Context。 | **返回值:** | 类型 | 说明 | | --------------------------------------- | ----------------- | | [CloudMediaAssetManager](#cloudmediaassetmanager14) | 返回云端媒体资产管理类实例。 | **错误码:** 接口抛出错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)和[文件管理错误码](../apis-core-file-kit/errorcode-filemanagement.md)。 | 错误码ID | 错误信息 | | -------- | ---------------------------------------- | | 202 | Called by non-system application. | | 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types; 3. Parameter verification failed. | | 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. | **示例:** ```ts async function example(context: Context) { console.info('getCloudMediaAssetManagerInstanceDemo'); try { let cloudMediaAssetManagerInstance: photoAccessHelper.CloudMediaAssetManager = photoAccessHelper.CloudMediaAssetManager.getCloudMediaAssetManagerInstance(context); await cloudMediaAssetManagerInstance.pauseDownloadCloudMedia(); } catch (err) { console.error(`getCloudMediaAssetManagerInstanceDemo failed with error: ${err.code}, ${err.message}`); } } ``` ### startDownloadCloudMedia14+ startDownloadCloudMedia(downloadType: CloudMediaDownloadType): Promise<void> 开始或恢复云端媒体资产下载任务。 **系统接口**:此接口为系统接口。 **系统能力**:SystemCapability.FileManagement.PhotoAccessHelper.Core **需要权限**:ohos.permission.CLOUDFILE_SYNC_MANAGER **参数:** | 参数名 | 类型 | 必填 | 说明 | | -------- | ------------------------- | ---- | ---------- | | downloadType | [CloudMediaDownloadType](#cloudmediadownloadtype14) | 是 | 云端媒体资产的下载方式。 | **返回值:** | 类型 | 说明 | | --------------------------------------- | ----------------- | | Promise<void>| Promise对象,返回void。 | **错误码:** 接口抛出错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)和[文件管理错误码](../apis-core-file-kit/errorcode-filemanagement.md)。 | 错误码ID | 错误信息 | | -------- | ---------------------------------------- | | 201 | Permission denied. | | 202 | Called by non-system application. | | 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types; 3. Parameter verification failed. | | 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. | **示例:** ```ts async function example(context: Context) { console.info('startDownloadCloudMediaDemo'); try { let cloudMediaAssetManagerInstance: photoAccessHelper.CloudMediaAssetManager = photoAccessHelper.CloudMediaAssetManager.getCloudMediaAssetManagerInstance(context); await cloudMediaAssetManagerInstance.startDownloadCloudMedia(photoAccessHelper.CloudMediaDownloadType.DOWNLOAD_FORCE); } catch (err) { console.error(`startDownloadCloudMediaDemo failed with error: ${err.code}, ${err.message}`); } } ``` ### pauseDownloadCloudMedia14+ pauseDownloadCloudMedia(): Promise<void> 暂停云端媒体资产下载任务。 **系统接口**:此接口为系统接口。 **系统能力**:SystemCapability.FileManagement.PhotoAccessHelper.Core **需要权限**:ohos.permission.CLOUDFILE_SYNC_MANAGER **返回值:** | 类型 | 说明 | | --------------------------------------- | ----------------- | | Promise<void>| Promise对象,返回void。 | **错误码:** 接口抛出错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)和[文件管理错误码](../apis-core-file-kit/errorcode-filemanagement.md)。 | 错误码ID | 错误信息 | | -------- | ---------------------------------------- | | 201 | Permission denied. | | 202 | Called by non-system application. | | 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. | **示例:** ```ts async function example(context: Context) { console.info('pauseDownloadCloudMediaDemo'); try { let cloudMediaAssetManagerInstance: photoAccessHelper.CloudMediaAssetManager = photoAccessHelper.CloudMediaAssetManager.getCloudMediaAssetManagerInstance(context); await cloudMediaAssetManagerInstance.pauseDownloadCloudMedia(); } catch (err) { console.error(`pauseDownloadCloudMediaDemo failed with error: ${err.code}, ${err.message}`); } } ``` ### cancelDownloadCloudMedia14+ cancelDownloadCloudMedia(): Promise<void> 取消云端媒体资产下载任务。 **系统接口**:此接口为系统接口。 **系统能力**:SystemCapability.FileManagement.PhotoAccessHelper.Core **需要权限**:ohos.permission.CLOUDFILE_SYNC_MANAGER **返回值:** | 类型 | 说明 | | --------------------------------------- | ----------------- | | Promise<void>| Promise对象,返回void。 | **错误码:** 接口抛出错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)和[文件管理错误码](../apis-core-file-kit/errorcode-filemanagement.md)。 | 错误码ID | 错误信息 | | -------- | ---------------------------------------- | | 201 | Permission denied. | | 202 | Called by non-system application. | | 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. | **示例:** ```ts async function example(context: Context) { console.info('cancelDownloadCloudMediaDemo'); try { let cloudMediaAssetManagerInstance: photoAccessHelper.CloudMediaAssetManager = photoAccessHelper.CloudMediaAssetManager.getCloudMediaAssetManagerInstance(context); await cloudMediaAssetManagerInstance.cancelDownloadCloudMedia(); } catch (err) { console.error(`cancelDownloadCloudMediaDemo failed with error: ${err.code}, ${err.message}`); } } ``` ### retainCloudMediaAsset14+ retainCloudMediaAsset(retainType: CloudMediaRetainType): Promise<void> 删除云端媒体资产在本地的元数据和文件。 **系统接口**:此接口为系统接口。 **系统能力**:SystemCapability.FileManagement.PhotoAccessHelper.Core **需要权限**:ohos.permission.CLOUDFILE_SYNC_MANAGER **参数:** | 参数名 | 类型 | 必填 | 说明 | | -------- | ------------------------- | ---- | ---------- | | retainType | [CloudMediaRetainType](#cloudmediaretaintype14) | 是 | 云端媒体资产的删除方式。 | **返回值:** | 类型 | 说明 | | --------------------------------------- | ----------------- | | Promise<void>| Promise对象,返回void。 | **错误码:** 接口抛出错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)和[文件管理错误码](../apis-core-file-kit/errorcode-filemanagement.md)。 | 错误码ID | 错误信息 | | -------- | ---------------------------------------- | | 201 | Permission denied. | | 202 | Called by non-system application. | | 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types; 3. Parameter verification failed. | | 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. | **示例:** ```ts async function example(context: Context) { console.info('retainCloudMediaAssetDemo'); try { let cloudMediaAssetManagerInstance: photoAccessHelper.CloudMediaAssetManager = photoAccessHelper.CloudMediaAssetManager.getCloudMediaAssetManagerInstance(context); await cloudMediaAssetManagerInstance.retainCloudMediaAsset(photoAccessHelper.CloudMediaRetainType.RETAIN_FORCE); } catch (err) { console.error(`retainCloudMediaAssetDemo failed with error: ${err.code}, ${err.message}`); } } ``` ### getCloudMediaAssetStatus14+ getCloudMediaAssetStatus(): Promise<CloudMediaAssetStatus> 查询云端媒体资产下载任务状态。 **系统接口**:此接口为系统接口。 **系统能力**:SystemCapability.FileManagement.PhotoAccessHelper.Core **需要权限**:ohos.permission.READ_IMAGEVIDEO **返回值:** | 类型 | 说明 | | --------------------------------------- | ----------------- | |Promise<[CloudMediaAssetStatus](#cloudmediaassetstatus14)> | Promise对象,返回云端媒体资产下载任务状态。 | **错误码:** 接口抛出错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)和[文件管理错误码](../apis-core-file-kit/errorcode-filemanagement.md)。 | 错误码ID | 错误信息 | | -------- | ---------------------------------------- | | 201 | Permission denied. | | 202 | Called by non-system application. | | 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. | **示例:** ```ts async function example(context: Context) { console.info('getCloudMediaAssetStatusDemo'); try { let cloudMediaAssetManagerInstance: photoAccessHelper.CloudMediaAssetManager = photoAccessHelper.CloudMediaAssetManager.getCloudMediaAssetManagerInstance(context); const cloudMediaAssetStatus: photoAccessHelper.CloudMediaAssetStatus = await cloudMediaAssetManagerInstance.getCloudMediaAssetStatus(); let taskStatus = cloudMediaAssetStatus.taskStatus; let taskInfo = cloudMediaAssetStatus.taskInfo; let errorCode = cloudMediaAssetStatus.errorCode; let message = `taskStatus: ${taskStatus}, taskInfo: ${taskInfo}, errorCode: ${errorCode}`; console.log(message); } catch (err) { console.error(`getCloudMediaAssetStatusDemo failed with error: ${err.code}, ${err.message}`); } } ``` ## MovingPhoto12+ 动态照片对象。 ### isVideoReady20+ isVideoReady(): Promise<boolean> 查询动态照片的视频是否已生成。使用Promise异步回调。 **系统接口**:此接口为系统接口。 **系统能力**:SystemCapability.FileManagement.PhotoAccessHelper.Core **需要权限**:ohos.permission.READ_IMAGEVIDEO **返回值:** | 类型 | 说明 | | --------------------------------------- | ----------------- | | Promise<boolean> | Promise对象。返回true表示动态照片视频已生成; 返回false表示动态照片视频未生成完成。 | **错误码:** 以下错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)和[媒体库错误码](errcode-medialibrary.md)。 | 错误码ID | 错误信息 | | -------- | ---------------------------------------- | | 201 | Permission denied | | 202 | Called by non-system application | | 23800301 | Internal system error. It is recommended to retry and check the logs. Possible causes: 1. Database corrupted; 2. The file system is abnormal; 3. The IPC request timed out. | **示例:** phAccessHelper的创建请参考[photoAccessHelper.getPhotoAccessHelper](./js-apis-photoAccessHelper.md#photoaccesshelpergetphotoaccesshelper)的示例使用。 ```ts import { dataSharePredicates } from '@kit.ArkData'; class MovingPhotoHandler implements photoAccessHelper.MediaAssetDataHandler { async onDataPrepared(movingPhoto: photoAccessHelper.MovingPhoto) { if (movingPhoto === undefined) { console.error('Error occurred when preparing data'); return; } try { let isVideoReady = await movingPhoto.isVideoReady() console.info("moving photo video ready:" + `${isVideoReady}`); } catch (err) { console.error(`failed to get isVideoReady, error code is ${err.code}, message is ${err.message}`) } } } async function example(phAccessHelper: photoAccessHelper.PhotoAccessHelper, context: Context) { let predicates: dataSharePredicates.DataSharePredicates = new dataSharePredicates.DataSharePredicates(); predicates.equalTo(photoAccessHelper.PhotoKeys.PHOTO_SUBTYPE, photoAccessHelper.PhotoSubtype.MOVING_PHOTO); let fetchOptions: photoAccessHelper.FetchOptions = { fetchColumns: [], predicates: predicates }; // 请确保图库内存在动态照片。 let assetResult: photoAccessHelper.FetchResult = await phAccessHelper.getAssets(fetchOptions); let asset: photoAccessHelper.PhotoAsset = await assetResult.getFirstObject(); let requestOptions: photoAccessHelper.RequestOptions = { deliveryMode: photoAccessHelper.DeliveryMode.FAST_MODE, } const handler = new MovingPhotoHandler(); try { let requestId: string = await photoAccessHelper.MediaAssetManager.requestMovingPhoto(context, asset, requestOptions, handler); console.info("moving photo requested successfully, requestId: " + requestId); } catch (err) { console.error(`failed to request moving photo, error code is ${err.code}, message is ${err.message}`); } } ``` ## PhotoAssetCustomRecordManager20+ 媒体库支持图库自定义用户统计行为接口。 **系统接口**:此接口为系统接口。 ### getCustomRecordManagerInstance20+ static getCustomRecordManagerInstance(context: Context): PhotoAssetCustomRecordManager 获取图库自定义用户统计行为实例。 **系统接口**:此接口为系统接口。 **系统能力**: SystemCapability.FileManagement.PhotoAccessHelper.Core **参数:** | 参数名 | 类型 | 必填 | 说明 | | --- | --- | --- | --- | | context | [Context](../apis-ability-kit/js-apis-inner-application-context.md#context) | 是 | 传入Ability实例的上下文。 | **返回值:** | 类型 | 说明 | | --- | --- | | [PhotoAssetCustomRecordManager](#photoassetcustomrecordmanager20) | 用户自定义行为统计实例。 | **错误码:** 以下错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)和[媒体库错误码](errcode-medialibrary.md)。 | 错误码ID | 错误信息 | | --- | --- | | 202 | Called by non-system application. | | 23800107 | Context is invalid. | **示例:** ```ts import { common } from '@kit.AbilityKit'; import { BusinessError } from '@kit.BasicServicesKit'; async function example(context: Context) { console.info('getCustomRecordManagerInstance'); try { let crManager = photoAccessHelper.PhotoAssetCustomRecordManager.getCustomRecordManagerInstance(context); } catch(err) { console.error(`getCustomRecordManagerInstance failed with error: ${err.code}, ${err.message}`); } } ``` ### createCustomRecords20+ createCustomRecords(customRecords: Array<PhotoAssetCustomRecord>): Promise<void> 新增自定义用户统计行为数据。使用Promise异步回调。 **系统接口**:此接口为系统接口。 **系统能力**: SystemCapability.FileManagement.PhotoAccessHelper.Core **参数:** | 参数名 | 类型 | 必填 | 说明 | | --- | --- | --- | --- | | customRecords | Array<[PhotoAssetCustomRecord](#photoassetcustomrecord20)> | 是 | 新增自定义用户统计行为数据。 | **返回值:** | 类型 | 说明 | | --- | --- | | Promise<void> | Promise对象,无返回结果。 | **错误码:** 以下错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)和[媒体库错误码](errcode-medialibrary.md)。 | 错误码ID | 错误信息 | | --- | --- | | 202 | Called by non-system application. | | 23800151 | Scenario parameters fail to pass the verification. Possible causes: 1. The value range of mandatory parameters in photoAssetCustomRecord does not meet the requirements. 2. The transferred record already exists. 3. The number of transferred records exceeds 200. | | 23800301 | Internal system error. It is recommended to retry and check the logs. Possible causes: 1. Database corrupted; 2. The file system is abnormal; 3. The IPC request timed out. | **示例:** ```ts import { BusinessError } from '@kit.BasicServicesKit'; async function example(context: Context) { console.info('createCustomRecords'); let crManager = photoAccessHelper.PhotoAssetCustomRecordManager.getCustomRecordManagerInstance(context); let crArray:Array = [ {fileId:1,shareCount:1,lcdJumpCount:1} ]; crManager.createCustomRecords(crArray).then(() => { console.info('createCustomRecords successful'); }).catch((err: BusinessError) => { console.error('createCustomRecords fail with error: ${err.code}, ${err.message}'); }); } ``` ### getCustomRecords20+ getCustomRecords(optionCheck: FetchOptions): Promise<FetchResult<PhotoAssetCustomRecord>> 根据检索选项获取自定义用户统计行为数据。使用Promise异步回调。 **系统接口**:此接口为系统接口。 **系统能力**: SystemCapability.FileManagement.PhotoAccessHelper.Core **参数:** | 参数名 | 类型 | 必填 | 说明 | | --- | --- | --- | --- | | optionCheck | [FetchOptions](js-apis-photoAccessHelper.md#fetchoptions) | 是 | 检索选项。 | **返回值:** | 类型 | 说明 | | --- | --- | | Promise<FetchResult<[PhotoAssetCustomRecord](#photoassetcustomrecord20)>> | Promise对象,返回自定义用户统计行为数据集合。 | **错误码:** 以下错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)和[媒体库错误码](errcode-medialibrary.md)。 | 错误码ID | 错误信息 | | --- | --- | | 202 | Called by non-system application. | | 23800151 | Scenario parameters fail to pass the verification. Possible causes: 1. The fileter criteria or fetchColumns that are not supported by options are transferred. | | 23800301 | Internal system error. It is recommended to retry and check the logs. Possible causes: 1. Database corrupted; 2. The file system is abnormal; 3. The IPC request timed out. | **示例:** ```ts import { dataSharePredicates } from '@kit.ArkData'; import { BusinessError } from '@kit.BasicServicesKit'; async function example(context: Context) { console.info('getCustomRecords'); let crManager = photoAccessHelper.PhotoAssetCustomRecordManager.getCustomRecordManagerInstance(context); let predicates: dataSharePredicates.DataSharePredicates = new dataSharePredicates.DataSharePredicates(); predicates.equalTo('file_id', 1); let fetchOption: photoAccessHelper.FetchOptions = { fetchColumns: [], predicates: predicates }; crManager.getCustomRecords(fetchOption).then(async (fetchResult) => { let record = await fetchResult.getFirstObject(); console.info('record file id is ' + record.fileId); }).catch((err: BusinessError) => { console.error('getCustomRecords fail with error: ${err.code}, ${err.message}'); }); } ``` ### setCustomRecords20+ setCustomRecords(customRecords: Array<PhotoAssetCustomRecord>): Promise<Array<number>> 根据自定义用户统计行为数据,更新已存在的数据库字段。使用Promise异步回调。 **系统接口**:此接口为系统接口。 **系统能力**: SystemCapability.FileManagement.PhotoAccessHelper.Core **参数:** | 参数名 | 类型 | 必填 | 说明 | | --- | --- | --- | --- | | customRecords | Array<[PhotoAssetCustomRecord](#photoassetcustomrecord20)> | 是 | 自定义用户统计行为数据。 | **返回值:** | 类型 | 说明 | | --- | --- | | Promise<Array<number>> | 更新失败的自定义用户统计行为数据中的fileId。 | **错误码:** 以下错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)和[媒体库错误码](errcode-medialibrary.md)。 | 错误码ID | 错误信息 | | --- | --- | | 202 | Called by non-system application. | | 23800151 | Scenario parameters fail to pass the verification. Possible causes: 1. The value range of mandatory parameters in photoAssetCustomRecord does not meet the requirements. 2. The number of transferred records exceeds 200. | | 23800301 | Internal system error. It is recommended to retry and check the logs. Possible causes: 1. Database corrupted; 2. The file system is abnormal; 3. The IPC request timed out. | **示例:** ```ts import { BusinessError } from '@kit.BasicServicesKit'; async function example(context: Context) { console.info('setCustomRecords'); let crManager = photoAccessHelper.PhotoAssetCustomRecordManager.getCustomRecordManagerInstance(context); let UpdateArray: Array = [ {fileId:1,shareCount:2,lcdJumpCount:3}, {fileId:2,shareCount:2,lcdJumpCount:3} ]; crManager.setCustomRecords(UpdateArray).then((failIds) => { console.info('setCustomRecords successful'); }).catch((err: BusinessError) => { console.error('setCustomRecords file with err: ${err.code}, ${err.message}'); }); } ``` ### removeCustomRecords20+ removeCustomRecords(optionCheck: FetchOptions): Promise<void> 根据检索选项删除自定义用户统计行为数据。使用Promise异步回调。 **系统接口**:此接口为系统接口。 **系统能力**: SystemCapability.FileManagement.PhotoAccessHelper.Core **参数:** | 参数名 | 类型 | 必填 | 说明 | | --- | --- | --- | --- | | optionCheck | [FetchOptions](js-apis-photoAccessHelper.md#fetchoptions) | 是 | 检索选项。 | **返回值:** | 类型 | 说明 | | --- | --- | | Promise<void> | Promise对象,无返回结果。 | **错误码:** 以下错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)和[媒体库错误码](errcode-medialibrary.md)。 | 错误码ID | 错误信息 | | --- | --- | | 202 | Called by non-system application. | | 23800151 | Scenario parameters fail to pass the verification. Possible causes: 1. The fileter criteria or fetchColumns that are not supported by options are transferred | | 23800301 | Internal system error. It is recommended to retry and check the logs. Possible causes: 1. Database corrupted; 2. The file system is abnormal; 3. The IPC request timed out. | **示例:** ```ts import { dataSharePredicates } from '@kit.ArkData'; import { BusinessError } from '@kit.BasicServicesKit'; async function example(context: Context) { console.info('removeCustomRecords'); let crManager = photoAccessHelper.PhotoAssetCustomRecordManager.getCustomRecordManagerInstance(context); let predicates: dataSharePredicates.DataSharePredicates = new dataSharePredicates.DataSharePredicates(); predicates.equalTo('file_id', 1); let fetchOption: photoAccessHelper.FetchOptions = { fetchColumns: [], predicates: predicates }; crManager.removeCustomRecords(fetchOption).then(() => { console.info('removeCustomRecords successful'); }).catch((err: BusinessError) => { console.error('removeCustomRecords fail with error: ${err.code}, ${err.message}'); }); } ``` ### addShareCount20+ addShareCount(ids: Array<number>): Promise<Array<number>> 根据[PhotoAssetCustomRecord](#photoassetcustomrecord20)中的fileId给数据库中对应数据的shareCount加1。使用Promise异步回调。 **系统接口**:此接口为系统接口。 **系统能力**: SystemCapability.FileManagement.PhotoAccessHelper.Core **参数:** | 参数名 | 类型 | 必填 | 说明 | | --- | --- | --- | --- | | ids | Array<number> | 是 | [PhotoAssetCustomRecord](#photoassetcustomrecord20)中的fileId集合。 | **返回值:** | 类型 | 说明 | | --- | --- | | Promise<Array<number>> | 更新失败的自定义用户统计行为数据中的fileId。 | **错误码:** 以下错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)和[媒体库错误码](errcode-medialibrary.md)。 | 错误码ID | 错误信息 | | --- | --- | | 202 | Called by non-system application. | | 23800151 | Scenario parameters fail to pass the verification. Possible causes: 1. The ids list is empty; 2. The number of ids lists exceeds 500. | | 23800301 | Internal system error. It is recommended to retry and check the logs. Possible causes: 1. Database corrupted; 2. The file system is abnormal; 3. The IPC request timed out. | ```ts import { BusinessError } from '@kit.BasicServicesKit'; async function example(context: Context) { console.info('addShareCount'); let crManager = photoAccessHelper.PhotoAssetCustomRecordManager.getCustomRecordManagerInstance(context); let ids: Array = [1, 2]; crManager.addShareCount(ids).then((failIds) => { console.info('addShareCount successful'); }).catch((err: BusinessError) => { console.error('addShareCount fail with error: ${err.code}, ${err.message}'); }); } ``` ### addLcdJumpCount20+ addLcdJumpCount(ids: Array<number>): Promise<Array<number>> 根据[PhotoAssetCustomRecord](#photoassetcustomrecord20)中的fileId给数据库中对应数据的LcdJumpCount加1。使用Promise异步回调。 **系统接口**:此接口为系统接口。 **系统能力**: SystemCapability.FileManagement.PhotoAccessHelper.Core **参数:** | 参数名 | 类型 | 必填 | 说明 | | --- | --- | --- | --- | | ids | Array<number> | 是 | [PhotoAssetCustomRecord](#photoassetcustomrecord20)中的fileId集合。 | **返回值:** | 类型 | 说明 | | --- | --- | | Promise<Array<number>> | 更新失败的自定义用户统计行为数据中的fileId。 | **错误码:** 以下错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)和[媒体库错误码](errcode-medialibrary.md)。 | 错误码ID | 错误信息 | | --- | --- | | 202 | Called by non-system application. | | 23800151 | Scenario parameters fail to pass the verification. Possible causes: 1. The ids list is empty; 2. The number of ids lists exceeds 500. | | 23800301 | Internal system error. It is recommended to retry and check the logs. Possible causes: 1. Database corrupted; 2. The file system is abnormal; 3. The IPC request timed out. | ```ts import { BusinessError } from '@kit.BasicServicesKit'; async function example(context: Context) { console.info('addLcdJumpCount'); let crManager = photoAccessHelper.PhotoAssetCustomRecordManager.getCustomRecordManagerInstance(context); let ids: Array = [1, 2]; crManager.addLcdJumpCount(ids).then((failIds) => { console.info('addLcdJumpCount successful'); }).catch((err: BusinessError) => { console.error('addLcdJumpCount fail with error: ${err.code}, ${err.message}'); }); } ``` ## PhotoSelectOptions 图库选择选项子类,继承于BaseSelectOptions。用于拉起对应userId空间的picker。 **系统能力**:SystemCapability.FileManagement.PhotoAccessHelper.Core | 参数名 | 类型 | 必填 | 说明 | | -------- | -------- | -------- | -------- | | userId18+ | number | 否 | 指定访问空间的Id。默认值为-1。
当需要作为[PhotoViewPicker.select](arkts-apis-photoAccessHelper-PhotoViewPicker.md#select)的选择参数时,请申请ohos.permission.INTERACTA_CROSS_LOCAL_ACCOUNTS。
**系统接口**:此接口为系统接口。 | **示例:** ```ts async function photoPicker() { let picker = new photoAccessHelper.PhotoViewPicker(); let option = new photoAccessHelper.PhotoSelectOptions(); option.userId = 101; picker.select(option); } ``` ## PhotoSubtype 枚举,不同[PhotoAsset](#photoasset)的类型。 **系统能力**:SystemCapability.FileManagement.PhotoAccessHelper.Core | 名称 | 值 | 说明 | | ----- | ---- | ---- | | SCREENSHOT | 1 | 截屏录屏文件类型。
**系统接口**:此接口为系统接口。 | ## AlbumType 枚举,相册类型,表示是用户相册还是系统预置相册。 **系统能力**:SystemCapability.FileManagement.PhotoAccessHelper.Core | 名称 | 值 | 说明 | | ------------------- | ---- | ------------------------- | | SOURCE18+ | 2048 | 来源相册。
**系统接口**:此接口为系统接口。 | | SMART11+ | 4096 | 智慧分析相册。
**系统接口**:此接口为系统接口。 | ## AlbumSubtype 枚举,相册子类型,表示具体的相册类型。 **系统能力**:SystemCapability.FileManagement.PhotoAccessHelper.Core | 名称 | 值 | 说明 | | --------------------------------- | ---------- | ------------------------------- | | HIDDEN | 1027 | 隐藏相册。**系统接口**:此接口为系统接口。 | | TRASH | 1028 | 回收站。**系统接口**:此接口为系统接口。 | | SCREENSHOT | 1029 | 截屏和录屏相册。**系统接口**:此接口为系统接口。 | | CAMERA | 1030 | 相机拍摄的照片和视频相册。**系统接口**:此接口为系统接口。 | | SOURCE\_GENERIC11+ | 2049 | 来源相册。**系统接口**:此接口为系统接口。 | | CLASSIFY11+ | 4097 | 分类相册。**系统接口**:此接口为系统接口。 | | GEOGRAPHY\_LOCATION11+ | 4099 | 地图相册。**系统接口**:此接口为系统接口。 | | GEOGRAPHY\_CITY11+ | 4100 | 城市相册。**系统接口**:此接口为系统接口。 | | SHOOTING\_MODE11+ | 4101 | 拍摄模式相册。**系统接口**:此接口为系统接口。 | | PORTRAIT11+ | 4102 | 人像相册。**系统接口**:此接口为系统接口。 | | GROUP_PHOTO13+ | 4103 | 合影相册。**系统接口**:此接口为系统接口。 | | HIGHLIGHT12+ | 4104 | 时刻相册。**系统接口**:此接口为系统接口。 | | HIGHLIGHT_SUGGESTIONS12+ | 4105 | 时刻建议相册。**系统接口**:此接口为系统接口。 | | CLOUD_ENHANCEMENT13+ | 1032 | AI云增强相册。**系统接口**:此接口为系统接口。 | ## RequestPhotoType11+ 枚举,获取图片或视频缩略图的操作类型。 **系统接口**:此接口为系统接口。 **系统能力**:SystemCapability.FileManagement.PhotoAccessHelper.Core | 名称 | 值 | 说明 | | ----- | ---- | ---- | | REQUEST_ALL_THUMBNAILS | 0 | 即获取快速缩略图,又获取质量缩略图。 | | REQUEST_FAST_THUMBNAIL | 1 | 只获取快速缩略图。 | | REQUEST_QUALITY_THUMBNAIL | 2 | 只获取质量缩略图。 | ## PhotoKeys 枚举,图片和视频文件关键信息。 **系统能力**:SystemCapability.FileManagement.PhotoAccessHelper.Core | 名称 | 值 | 说明 | | ------------- | ------------------- | ---------------------------------------------------------- | | DATE_TRASHED | 'date_trashed' | 删除日期(删除文件时间距1970年1月1日的秒数值)。**系统接口**:此接口为系统接口。 | | HIDDEN | 'hidden' | 文件的隐藏状态。**系统接口**:此接口为系统接口。 | | CAMERA_SHOT_KEY | 'camera_shot_key' | 锁屏相机拍照或录像的标记字段(仅开放给系统相机,其key值由系统相机定义)。**系统接口**:此接口为系统接口。 | | USER_COMMENT10+ | 'user_comment' | 用户注释信息。**系统接口**:此接口为系统接口。 | | DATE_YEAR11+ | 'date_year' | 创建文件的年份。**系统接口**:此接口为系统接口。 | | DATE_MONTH11+ | 'date_month' | 创建文件的月份。**系统接口**:此接口为系统接口。 | | DATE_DAY11+ | 'date_day' | 创建文件的日期。**系统接口**:此接口为系统接口。 | | PENDING11+ | 'pending' | pending状态。**系统接口**:此接口为系统接口。 | | DATE_TRASHED_MS12+ | 'date_trashed_ms' | 删除日期(删除文件时间距1970年1月1日的毫秒数值)。**系统接口**:此接口为系统接口。
注意:查询照片时,不支持基于该字段排序。 | | MOVING_PHOTO_EFFECT_MODE12+ | 'moving_photo_effect_mode' | 动态照片效果模式。**系统接口**:此接口为系统接口。 | | CE_AVAILABLE13+ | 'ce_available' | 云增强任务标识。**系统接口**:此接口为系统接口。 | | SUPPORTED_WATERMARK_TYPE14+ | 'supported_watermark_type' | 水印可编辑标识。**系统接口**:此接口为系统接口。 | | IS_CE_AUTO18+ | 'is_auto' | 是否支持自动云增强。**系统接口**:此接口为系统接口。 | | OWNER_ALBUM_ID18+ | 'owner_album_id' | 照片所属的相册id。**系统接口**:此接口为系统接口。 | | IS_RECENT_SHOW18+ | 'is_recent_show' | 是否设置为最近显示。**系统接口**:此接口为系统接口。 | | SUM_SIZE19+ | 'sum(size)' | 文件大小总和。在fetchColumns中填入SUM_SIZE属性时,仅获取到第一个资产,并且属性中带有所有资产的总大小。**系统接口**:此接口为系统接口。 | | EXIF_ROTATE20+ | 'exif_rotate' | 文件的旋转角度信息。**系统接口**:此接口为系统接口。 | ## AlbumKeys 枚举,相册关键信息。 **系统能力**:SystemCapability.FileManagement.PhotoAccessHelper.Core | 名称 | 值 | 说明 | | --------------------------------- | -------------------- | ----------------------------------------------------- | | ALBUM_LPATH18+ | 'lpath' | 相册的虚拟路径。
**系统接口**:此接口为系统接口。 | | BUNDLE_NAME18+ | 'bundle_name' | 相册的包名。
**系统接口**:此接口为系统接口。 | | DATE_MODIFIED18+ | 'date_modified' | 相册修改的时间戳(单位:毫秒)。
**系统接口**:此接口为系统接口。 | | COVER_URI_SOURCE20+ | 'cover_uri_source' | 相册封面的来源。
**系统接口**:此接口为系统接口。 | ## HiddenPhotosDisplayMode11+ 枚举,系统中隐藏文件显示模式。 **系统接口**:此接口为系统接口。 **系统能力**:SystemCapability.FileManagement.PhotoAccessHelper.Core | 名称 | 值 | 说明 | | ------------- | ------------------- | ---------------------------------------------------------- | | ASSETS_MODE | 0 | 按系统预置的隐藏相册显示隐藏文件,即显示系统中所有的隐藏文件。 | | ALBUMS_MODE | 1 | 按相册显示隐藏文件(即显示系统中所有包含隐藏文件的相册,除系统预置的隐藏相册本身和回收站相册以外)。 | ## PhotoCreateOptions 图片或视频的创建选项。 **系统接口**:此接口为系统接口。 **系统能力**:SystemCapability.FileManagement.PhotoAccessHelper.Core | 名称 | 类型 | 必填 | 说明 | | ---------------------- | ------------------- | ---- | ------------------------------------------------ | | subtype | [PhotoSubtype](#photosubtype) | 否 | 图片或者视频的子类型。 | | cameraShotKey | string | 否 | 锁屏相机拍照或录像的标记字段(仅开放给系统相机,其key值由系统相机定义)。 | | userId19+ | number | 否 | 用户id。 | ## RequestPhotoOptions11+ 获取图片或视频缩略图的选项。 **系统接口**:此接口为系统接口。 **系统能力**:SystemCapability.FileManagement.PhotoAccessHelper.Core | 名称 | 类型 | 必填 | 说明 | | ---------------------- | ------------------- | ---- | ------------------------------------------------ | | size | [image.Size](../apis-image-kit/arkts-apis-image-i.md#size) | 否 | 获取缩略图的尺寸。 | | requestPhotoType | [RequestPhotoType](#requestphototype11) | 否 | 获取的操作类型。 | ## PhotoCreationSource18+ 代替应用创建资产传入的应用信息。 **系统接口**:此接口为系统接口。 **系统能力**:SystemCapability.FileManagement.PhotoAccessHelper.Core | 名称 | 类型 | 只读 | 可选 | 说明 | | ---------------------- | ------------------- | ---- | ---- | ------------------------------------------------ | | bundleName | string | 是 | 是 |需保存图片/视频文件的应用bundle name。 | | appName | string | 是 | 是 |需保存图片/视频文件的app name。 | | appId | string | 是 | 是 |需保存图片/视频文件的app id。 | | tokenId | number | 是 | 是 |应用标识,将访问权限授予tokenId标识的应用。 | ## RequestOptions11+ 请求策略。 **系统能力**:SystemCapability.FileManagement.PhotoAccessHelper.Core | 名称 | 类型 | 可读 | 可写 | 说明 | | ---------------------- |---------------------------------| ---- |---- | ------------------------------------------------ | | sourceMode | [SourceMode](#sourcemode11) | 是 | 是 | 资源文件的读取类型,可以指定当前请求获取的是源文件,或是编辑后的文件。**系统接口**:此接口为系统接口。 | ## PhotoProxy11+ 照片代理,相机应用通过该对象写入图片数据。 **系统接口**:此接口为系统接口。 **系统能力**:SystemCapability.FileManagement.PhotoAccessHelper.Core ## MediaChangeRequest11+ 媒体变更请求,资产变更请求和相册变更请求的父类型。 **注意**:媒体变更请求需要在调用[applyChanges](arkts-apis-photoAccessHelper-PhotoAccessHelper.md#applychanges11)后才会提交生效。 **系统能力**:SystemCapability.FileManagement.PhotoAccessHelper.Core ## FormInfo11+ 图库卡片相关信息。 **系统接口**:此接口为系统接口。 **系统能力**:SystemCapability.FileManagement.PhotoAccessHelper.Core | 名称 | 类型 | 必填 | 说明 | | ---------------------- | ------------------- | ---- | ------------------------------------------------ | |formId |string |是 | 卡片的ID,由图库创建卡片时提供。 | |uri |string |是 | 卡片绑定的图片的uri。创建卡片时uri可为空或图片的uri,移除卡片时uri不做校验,传空即可。 | ## GalleryFormInfo18+ 图库卡片相关信息。 **系统接口**:此接口为系统接口。 **系统能力**:SystemCapability.FileManagement.PhotoAccessHelper.Core | 名称 | 类型 | 必填 | 说明 | | ---------------------- | ------------------- | ---- | ------------------------------------------------ | |formId |string |是 | 卡片的ID,由图库创建卡片时提供。 | |assetUris |Array<string> |是 | 卡片绑定的图片或相册的uri集合。
创建和更新卡片时,assetUris不可为空。
单次创建或更新卡片时,assetUris中的uri个数如果超出500个,则只创建或更新500个uri的监听,超出500个后的uri不会被注册。
移除卡片时,assetUris可省略。 | ## ResourceType11+ 枚举,写入资源的类型。 **系统能力**:SystemCapability.FileManagement.PhotoAccessHelper.Core | 名称 | 值 | 说明 | | ----- | ---- | ---- | | PHOTO_PROXY | 3 | 表示照片代理资源。**系统接口**:此接口为系统接口。 | | PRIVATE_MOVING_PHOTO_RESOURCE13+ | 4 | 表示私有动态照片资源。**系统接口**:此接口为系统接口。 | | PRIVATE_MOVING_PHOTO_METADATA18+ | 5 | 表示私有动态照片元数据资源。**系统接口**:此接口为系统接口。 | ## DefaultChangeUri 枚举,DefaultChangeUri子类型。 **系统能力**:SystemCapability.FileManagement.PhotoAccessHelper.Core | 名称 | 值 | 说明 | | ----------------- | ----------------------- | ------------------------------------------------------------ | | DEFAULT_HIDDEN_ALBUM_URI11+ | 'file://media/HiddenAlbum' | 隐藏相册-相册视图中相册的Uri,即系统中包含隐藏文件的相册(不包含系统预置隐藏相册和回收站相册)的Uri,仅用于隐藏相册-相册视图场景的通知。**系统接口**:此接口为系统接口。 | ## SourceMode11+ 枚举,资源文件的读取类型。 **系统接口**:此接口为系统接口。 **系统能力**:SystemCapability.FileManagement.PhotoAccessHelper.Core | 名称 | 值 | 说明 | | ----- | ---- | ---- | | ORIGINAL_MODE | 0 | 读取源文件。 | | EDITED_MODE | 1 | 读取编辑后的文件。| ## AuthorizationMode12+ 枚举,授权模式。 **系统接口**:此接口为系统接口。 **系统能力**:SystemCapability.FileManagement.PhotoAccessHelper.Core | 名称 | 值 | 说明 | | ----- | ---- | ---- | | SHORT_TIME_AUTHORIZATION| 0 | 短时授权。 | ## AnalysisType11+ 枚举,智慧分析类型。 **系统能力**:SystemCapability.FileManagement.PhotoAccessHelper.Core | 名称 | 值 | 说明 | | :---------------------------- | :- | :------- | | ANALYSIS\_AESTHETICS\_SCORE | 0 | 美学评分分析类别。**系统接口**:此接口为系统接口。 | | ANALYSIS\_LABEL | 1 | 分类标签分析类别。**系统接口**:此接口为系统接口。 | | ANALYSIS\_OCR | 2 | 文字识别分析类别。**系统接口**:此接口为系统接口。 | | ANALYSIS\_FACE | 3 | 人脸检测分析类别。**系统接口**:此接口为系统接口。 | | ANALYSIS\_OBJECT | 4 | 目标检测分析类别。**系统接口**:此接口为系统接口。 | | ANALYSIS\_RECOMMENDATION | 5 | 推荐构图分析类别。**系统接口**:此接口为系统接口。 | | ANALYSIS\_SEGMENTATION | 6 | 抠图分析类别。**系统接口**:此接口为系统接口。 | | ANALYSIS\_COMPOSITION | 7 | 美学构图分析类别。**系统接口**:此接口为系统接口。 | | ANALYSIS\_SALIENCY | 8 | 最佳呈现主体中心分析类别。**系统接口**:此接口为系统接口。 | | ANALYSIS\_DETAIL\_ADDRESS | 9 | 详细地址分析类别。**系统接口**:此接口为系统接口。 | | ANALYSIS\_HUMAN\_FACE\_TAG12+ | 10 | 人像聚类信息分析类别。**系统接口**:此接口为系统接口。 | | ANALYSIS\_HEAD\_POSITION12+ | 11 | 人头、宠物头位置分析类别。**系统接口**:此接口为系统接口。 | | ANALYSIS\_BONE\_POSE12+ | 12 | 人体骨骼点信息分析类别。**系统接口**:此接口为系统接口。 | | ANALYSIS\_VIDEO\_LABEL12+ | 13 | 视频标签。**系统接口**:此接口为系统接口。 | | ANALYSIS\_HIGHLIGHT12+ | 14 | 时刻标签。**系统接口**:此接口为系统接口。 | ## HighlightAlbumInfoType12+ 枚举,时刻相册信息类型。 **系统接口**:此接口为系统接口。 **系统能力**:SystemCapability.FileManagement.PhotoAccessHelper.Core | 名称 | 值 | 说明 | | :------------ | :- | :------- | | COVER\_INFO | 0 | 封面信息类别。 | | PLAY\_INFO | 1 | 音乐信息类别。 | ## HighlightUserActionType12+ 枚举,时刻用户行为类型。 **系统接口**:此接口为系统接口。 **系统能力**:SystemCapability.FileManagement.PhotoAccessHelper.Core | 名称 | 值 | 说明 | | :---------------------------- | :- | :------- | | INSERTED\_PIC\_COUNT | 0 | 新增图片数量类别。 | | REMOVED\_PIC\_COUNT | 1 | 移除图片数量类别。 | | SHARED\_SCREENSHOT\_COUNT | 2 | 分享二级界面长图次数类别。 | | SHARED\_COVER\_COUNT | 3 | 分享时刻封面次数类别。 | | RENAMED\_COUNT | 4 | 重命名次数类别。 | | CHANGED\_COVER\_COUNT | 5 | 修改封面次数类别。 | | RENDER\_VIEWED\_TIMES | 100 | 轮播观看次数类别。 | | RENDER\_VIEWED\_DURATION | 101 | 轮播观看总时长类别。 | | ART\_LAYOUT\_VIEWED\_TIMES | 102 | 二级界面观看次数类别。 | | ART\_LAYOUT\_VIEWED\_DURATION | 103 | 二级界面观看总时长类别。 | ## ThumbnailVisibility14+ 枚举,缩略图是否可访问。 **系统接口**:此接口为系统接口。 **系统能力**:SystemCapability.FileManagement.PhotoAccessHelper.Core | 名称 | 值 | 说明 | | :---------------------------- | :- | :------- | | INVISIBLE | 0 | 缩略图不可访问。 | | VISIBLE | 1 | 缩略图可访问。 | ## MovingPhotoEffectMode12+ 枚举,动态照片效果模式。 **系统接口**:此接口为系统接口。 **系统能力**:SystemCapability.FileManagement.PhotoAccessHelper.Core | 名称 | 值 | 说明 | | :---------------------------- | :- | :------- | | DEFAULT | 0 | 默认模式。| | BOUNCE\_PLAY | 1 | 来回播放。| | LOOP\_PLAY | 2 | 循环播放。| | LONG\_EXPOSURE | 3 | 长曝光。 | | MULTI\_EXPOSURE | 4 | 多曝光。 | | CINEMA\_GRAPH13+ | 5 | 微动瞬间。 | | IMAGE\_ONLY13+ | 10 | 关闭模式。 | ## PhotoPermissionType12+ 枚举,应用对媒体资源不同访问权限的类型。 包括临时读权限和永久读权限,临时读权限会随着应用的死亡而删除,永久读权限不会。 同一个应用对同一个媒体资源的权限覆盖规则:永久读会覆盖临时读,而临时读不会覆盖永久读。 **系统接口**:此接口为系统接口。 **系统能力**:SystemCapability.FileManagement.PhotoAccessHelper.Core | 名称 | 值 | 说明 | | ----- | ---- | ---- | | TEMPORARY_READ_IMAGEVIDEO | 0 | 临时读权限类型。 | | PERSISTENT_READ_IMAGEVIDEO | 1 | 永久读权限类型。 | ## HideSensitiveType12+ 枚举,应用访问媒体资源时,对媒体资源进行信息脱敏的类型。 **系统接口**:此接口为系统接口。 **系统能力**:SystemCapability.FileManagement.PhotoAccessHelper.Core | 名称 | 值 | 说明 | | ----- | ---- | ---- | | HIDE_LOCATION_AND_SHOOTING_PARAM | 0 | 脱敏地理位置和拍摄参数。 | | HIDE_LOCATION_ONLY | 1 | 脱敏地理位置信息。 | | HIDE_SHOOTING_PARAM_ONLY | 2 | 脱敏拍摄参数。 | | NO_HIDE_SENSITIVE_TYPE | 3 | 不脱敏。 | ## CloudEnhancementTaskStage13+ 枚举,应用查询云增强任务状态时,在[CloudEnhancementTaskState](#cloudenhancement13)接口中返回,表示云增强任务状态。 **系统接口**:此接口为系统接口。 **系统能力**:SystemCapability.FileManagement.PhotoAccessHelper.Core | 名称 | 值 | 说明 | | ----- | ---- | ---- | | TASK_STAGE_EXCEPTION | -1 | 云增强任务异常。 | | TASK_STAGE_PREPARING | 0 | 云增强任务准备中。 | | TASK_STAGE_UPLOADING | 1 | 云增强任务上传中。 | | TASK_STAGE_EXECUTING | 2 | 云增强任务执行中。 | | TASK_STAGE_DOWNLOADING | 3 | 云增强任务下载中。 | | TASK_STAGE_FAILED | 4 | 云增强任务失败。 | | TASK_STAGE_COMPLETED | 5 | 云增强任务已完成。 | ## CloudEnhancementState13+ 枚举,表示云增强状态。 **系统接口**:此接口为系统接口。 **系统能力**:SystemCapability.FileManagement.PhotoAccessHelper.Core | 名称 | 值 | 说明 | | ----- | ---- | ---- | | UNAVAILABLE | 0 | 云增强不可用。 | | AVAILABLE | 1 | 云增强可用。 | | EXECUTING | 2 | 云增强执行中。 | | COMPLETED | 3 | 云增强已完成。 | ## CloudEnhancementTaskState13+ 云增强任务状态,应用调用调用云增强任务查询接口的返回类型,包含云增强任务状态及部分状态下的额外信息。 **系统接口**:此接口为系统接口。 **系统能力**:SystemCapability.FileManagement.PhotoAccessHelper.Core | 名称 | 类型 | 必定提供 | 说明 | | ---------------------- | ------------------- | ---- | ------------------------------------------------ | |taskStage |[CloudEnhancementTaskStage](#cloudenhancementtaskstage13) |是 | 云增强任务状态。 | |transferredFileSize |number |否 | 已传输的文件大小。当taskStage为CloudEnhancementTaskStage.TASK_STAGE_UPLOADING或者CloudEnhancementTaskStage.TASK_STAGE_DOWNLOADING时提供。 | |totalFileSize |number |否 | 总文件大小。当taskStage为CloudEnhancementTaskStage.TASK_STAGE_UPLOADING或者CloudEnhancementTaskStage.TASK_STAGE_DOWNLOADING时提供。 | |expectedDuration |number |否 | 排队时间。当taskStage为CloudEnhancementTaskStage.TASK_STAGE_EXECUTING时提供。 | |statusCode |number |否 | 状态码。当taskStage为CloudEnhancementTaskStage.TASK_STAGE_FAILED时提供。 | ## VideoEnhancementType13+ 枚举,分段式视频的二段式触发类型。 **系统接口**:此接口为系统接口。 **系统能力**:SystemCapability.FileManagement.PhotoAccessHelper.Core | 名称 | 值 | 说明 | | ----- | ---- | ---- | | QUALITY_ENHANCEMENT_LOCAL | 0 | 在端侧增强处理。 | | QUALITY_ENHANCEMENT_CLOUD | 1 | 在云侧增强处理。 | | QUALITY_ENHANCEMENT_LOCAL_AND_CLOUD | 2 | 在端侧和云侧同时增强处理。 | ## ThumbnailType13+ 枚举,缩略图类型。 **系统接口**:此接口为系统接口。 **系统能力**:SystemCapability.FileManagement.PhotoAccessHelper.Core | 名称 | 值 | 说明 | | :---------------------------- | :- | :------- | | LCD | 1 | 获取LCD缩略图 | | THM | 2 | 获取THM缩略图 | ## WatermarkType14+ 枚举,水印可编辑标识。 **系统接口**:此接口为系统接口。 **系统能力**:SystemCapability.FileManagement.PhotoAccessHelper.Core | 名称 | 值 | 说明 | | ----- | ---- | ---- | | DEFAULT | 0 | 不支持水印可编辑。 | | BRAND_COMMON | 1 | 支持品牌和通用水印可编辑。 | | COMMON | 2 | 支持通用水印可编辑。 | | BRAND | 3 | 支持品牌水印可编辑。 | ## CloudMediaDownloadType14+ 枚举,表示云端媒体资产的下载方式。 **系统接口**:此接口为系统接口。 **系统能力**:SystemCapability.FileManagement.PhotoAccessHelper.Core | 名称 | 值 | 说明 | | ----- | ---- | ---- | | DOWNLOAD_FORCE | 0 | 高优先级下载,无需进入息屏充电模式。 | | DOWNLOAD_GENTLE | 1 | 低优先级下载,需要进入息屏充电模式。 | ## CloudMediaRetainType14+ 枚举,表示云端媒体资产的删除方式。 **系统接口**:此接口为系统接口。 **系统能力**:SystemCapability.FileManagement.PhotoAccessHelper.Core | 名称 | 值 | 说明 | | ----- | ---- | ---- | | RETAIN_FORCE | 0 | 删除原文件在云端的本地元数据和缩略图。 | ## CloudMediaAssetTaskStatus14+ 枚举,表示云端媒体资产的下载任务状态。 **系统接口**:此接口为系统接口。 **系统能力**:SystemCapability.FileManagement.PhotoAccessHelper.Core | 名称 | 值 | 说明 | | ----- | ---- | ---- | | DOWNLOADING | 0 | 当前任务下载中。 | | PAUSED | 1 | 当前任务已暂停。 | | IDLE | 2 | 当前无下载任务。 | ## CloudMediaTaskPauseCause14+ 枚举,表示云端媒体资产下载任务暂停的类型。 **系统接口**:此接口为系统接口。 **系统能力**:SystemCapability.FileManagement.PhotoAccessHelper.Core | 名称 | 值 | 说明 | | ----- | ---- | ---- | | NO_PAUSE | 0 | 正常下载,无暂停。 | | TEMPERATURE_LIMIT | 1 | 温度过高。 | | ROM_LIMIT | 2 | 本地磁盘空间不足。 | | NETWORK_FLOW_LIMIT | 3 | 流量使用有限制,且没有Wi-Fi。 | | WIFI_UNAVAILABLE | 4 | 网络异常。 | | POWER_LIMIT | 5 | 功耗限制。 | | BACKGROUND_TASK_UNAVAILABLE | 6 | 充电息屏未启动。 | | FREQUENT_USER_REQUESTS | 7 | 用户请求频繁。 | | CLOUD_ERROR | 8 | 端云错误。 | | USER_PAUSED | 9 | 用户暂停。 | ## CloudMediaAssetStatus14+ 云端媒体资产下载任务的详细信息,应用调用云端资产下载任务查询接口的返回类型。 **系统接口**:此接口为系统接口。 **系统能力**:SystemCapability.FileManagement.PhotoAccessHelper.Core | 名称 | 类型 | 必定提供 | 说明 | | ---------------------- | ------------------- | ---- | ------------------------------------------------ | |taskStatus |[CloudMediaAssetTaskStatus](#cloudmediaassettaskstatus14) |是 | 云端媒体资产下载任务状态。 | |taskInfo |string |是 | 下载资产的总个数和总大小(byte),以及未下载的总个数和总大小(byte)。 | |errorCode |[CloudMediaTaskPauseCause](#cloudmediataskpausecause14) |是 | 云端媒体资产下载任务暂停类型。 | ## RecommendationType11+ 枚举,推荐的图片类型。 **系统能力**:SystemCapability.FileManagement.PhotoAccessHelper.Core | 名称 | 值 | 说明 | | ----- | ---- | ---- | | COLOR_STYLE_PHOTO18+ | 12 | 推荐风格 **系统接口**:此接口为系统接口。| ## ThumbnailChangeStatus20+ 枚举,表示缩略图(包括图片/视频)更新的状态。 **系统接口**:此接口为系统接口。 **系统能力**:SystemCapability.FileManagement.PhotoAccessHelper.Core | 名称 | 值 | 说明 | | ------------------------- | ---- | -------------------------------- | | THUMBNAIL_NOT_EXISTS | 0 | 缩略图不存在。 | | THUMBNAIL_ADD | 1 | 缩略图已重新创建。 | | THUMBNAIL_UPDATE | 2 | 缩略图已更新。 | | THUMBNAIL_NOT_CHANGE | 3 | 缩略图没有变化。 | ## StrongAssociationType20+ 枚举,表示图片的强关联类型。 **系统接口**:此接口为系统接口。 **系统能力**:SystemCapability.FileManagement.PhotoAccessHelper.Core | 名称 | 值 | 说明 | | ------------------------- | ---- | -------------------------------- | | NORMAL | 0 | 普通图片类型。 | | CLOUD_ENHANCEMENT | 1 | 云增强图片类型。 | ## PhotoAssetChangeInfo20+ 媒体资产(图片/视频)信息。 **系统能力**:SystemCapability.FileManagement.PhotoAccessHelper.Core | 名称 | 类型 | 只读 | 可选 | 说明 | | ---- | ------- | ---- | ---- | ----- | | fileId | number | 否 | 否 | 媒体资产(图片/视频)的id。
**系统接口**:此接口为系统接口。 | | dateDay | string | 否 | 否 | 创建媒体文件的日期。
**系统接口**:此接口为系统接口。 | | isFavorite | boolean | 否 | 否 | 表示媒体资产(图片/视频)的收藏状态。true表示资产已收藏,false表示资产未收藏。
**系统接口**:此接口为系统接口。 | | isHidden | boolean | 否 | 否 | 表示媒体资产(图片/视频)的隐藏状态。true表示资产已隐藏,false表示资产未隐藏。
**系统接口**:此接口为系统接口。 | | strongAssociation | [StrongAssociationType](#strongassociationtype20) | 否 | 否 | 图片的强关联类型。
**系统接口**:此接口为系统接口。 | | thumbnailVisible | [ThumbnailVisibility](#thumbnailvisibility14) | 否 | 否 | 缩略图的可访问性。
**系统接口**:此接口为系统接口。 | | dateTrashedMs |number |否 | 否 | 文件删除时的Unix时间戳(单位:毫秒)。
**系统接口**:此接口为系统接口。 | | dateAddedMs | number | 否 | 否 | 文件创建时的Unix时间戳(单位:毫秒)。
**系统接口**:此接口为系统接口。 | | dateTakenMs | number | 否 | 否 | 文件拍摄时的Unix时间戳(单位:毫秒)。
**系统接口**:此接口为系统接口。 | | position | [PositionType](arkts-apis-photoAccessHelper-e.md#positiontype16) | 否 | 是 | 媒体资产(图片/视频)的所在位置。
**系统接口**:此接口为系统接口。 | | displayName | string | 否 | 是 | 媒体资产(图片/视频)的显示名称。
**系统接口**:此接口为系统接口。 | | size | number | 否 | 是 | 媒体资产(图片/视频)的文件大小(单位:字节)。动态照片的size包括图片和视频的总大小。
**系统接口**:此接口为系统接口。 | ## PhotoAssetChangeData20+ 媒体资产(图片/视频)的具体变更数据。 **系统能力**:SystemCapability.FileManagement.PhotoAccessHelper.Core | 名称 | 类型 | 只读 | 可选 | 说明 | | ---- | ------- | ---- | ---- | ----- | | thumbnailChangeStatus | [ThumbnailChangeStatus](#thumbnailchangestatus20) | 否 | 否 | 缩略图(图片/视频)更新的状态。
**系统接口**:此接口为系统接口。 | | version | number | 否 | 否 | 媒体资产(图片/视频)信息通知的版本号,用于确定通知的顺序。
**系统接口**:此接口为系统接口。 | ## AlbumChangeInfo20+ 相册信息。 **系统能力**:SystemCapability.FileManagement.PhotoAccessHelper.Core | 名称 | 类型 | 只读 | 可选 | 说明 | | ---- | ------- | ---- | ---- | ----- | | hiddenCount | number | 否 | 否 | 相册中的隐藏资产数量。
**系统接口**:此接口为系统接口。 | | hiddenCoverUri | string | 否 | 否 | 相册中隐藏封面资产的uri。
**系统接口**:此接口为系统接口。 | | isCoverChanged | boolean | 否 | 否 | 相册封面文件内容是否变化。true表示封面文件内容发生变化,false表示封面文件内容未发生变化。
**系统接口**:此接口为系统接口。 | | isHiddenCoverChanged | boolean | 否 | 否 | 相册隐藏封面文件内容是否变化。true表示隐藏封面文件内容发生变化,false表示隐藏封面文件内容未发生变化。
**系统接口**:此接口为系统接口。 | | coverInfo | [PhotoAssetChangeInfo](#photoassetchangeinfo20) | 否 | 是 | 相册封面资产的信息。
**系统接口**:此接口为系统接口。 | | hiddenCoverInfo | [PhotoAssetChangeInfo](#photoassetchangeinfo20) | 否 | 是 | 相册隐藏封面资产的信息。
**系统接口**:此接口为系统接口。 | | orderSection | number | 否 | 是 | 相册的排序区域,用于确认相册在图库中的展示区域。
**系统接口**:此接口为系统接口。 | | albumOrder | number | 否 | 是 | 相册的排序值。
**系统接口**:此接口为系统接口。 | ## AlbumChangeData20+ 相册的具体变更数据。 **系统能力**:SystemCapability.FileManagement.PhotoAccessHelper.Core | 名称 | 类型 | 只读 | 可选 | 说明 | | ---- | ------- | ---- | ---- | ----- | | version | number | 否 | 否 | 相册信息通知的版本号,用于确定通知的顺序。
**系统接口**:此接口为系统接口。 | ## PhotoAssetCustomRecord20+ 媒体库支持图库自定义用户统计行为。 **系统接口**:此接口为系统接口。 **系统能力**:SystemCapability.FileManagement.PhotoAccessHelper.Core | 名称 | 类型 | 只读 | 可选 | 说明 | | --- | --- | --- | --- | --- | | fileId | number | 是 | 否 | 图片id,必须为大于0的整数。 | | shareCount | number | 是 | 否 | 图片和视频被分享的次数,必须为大于0的整数。 | | lcdJumpCount | number | 是 | 否 | 大图跳转分享等次数,必须为大于0的整数。 | ## CoverUriSource20+ 枚举,表示相册封面的来源。 **系统接口**:此接口为系统接口。 **系统能力**:SystemCapability.FileManagement.PhotoAccessHelper.Core | 名称 | 值 | 说明 | | ------------------------- | ---- | -------------------------------- | | DEFAULT_COVER | 0 | 默认封面。 | | MANUAL_COVER | 1 | 手动设置的封面。 | ## AlbumOrder20+ 相册排序信息。 ### 属性 **系统接口**:此接口为系统接口。 **系统能力**:SystemCapability.FileManagement.PhotoAccessHelper.Core | 名称 | 类型 | 只读 | 可选 | 说明 | | ------------ | ------ | ---- | ---- | ------- | | albumId | number | 否 | 否 | 相册ID。 | | albumOrder | number | 否 | 否 | 相册排序值。 | | orderSection | number | 否 | 否 | 相册排序区域。| | orderType | number | 否 | 否 | 相册排序类型。| | orderStatus | number | 否 | 否 | 相册排序状态。|