# @ohos.file.photoAccessHelper (Album Management) (System API)
The module provides APIs for album management, including creating an album and accessing and modifying media data in an album.
> **NOTE**
>
> - The initial APIs of this module are supported since API version 10. Newly added APIs will be marked with a superscript to indicate their earliest API version.
> - This topic describes only the system APIs provided by the module. For details about its public APIs, see [@ohos.file.photoAccessHelper (Album Management)](arkts-apis-photoAccessHelper.md).
## Modules to Import
```ts
import { photoAccessHelper } from '@kit.MediaLibraryKit';
```
## photoAccessHelper.getPhotoAccessHelper19+
getPhotoAccessHelper(context: Context, userId: number): PhotoAccessHelper
Obtains a PhotoAccessHelper instance for the specified user, letting you access and modify media files in an album.
**Model restriction**: This API can be used only in the stage model.
**System API**: This is a system API.
**System capability**: SystemCapability.FileManagement.PhotoAccessHelper.Core
**Parameters**
| Name | Type | Mandatory| Description |
| ------- | ------- | ---- | -------------------------- |
| context | [Context](../apis-ability-kit/js-apis-inner-application-context.md) | Yes | Context of the ability instance.|
| userId | number | Yes | ID of the user.|
**Return value**
| Type | Description |
| ----------------------------- | :---- |
| [PhotoAccessHelper](#photoaccesshelper) | PhotoAccessHelper instance obtained.|
**Error codes**
For details about the error codes, see [Universal Error Codes](../errorcode-universal.md).
| ID| Error Message|
| -------- | ---------------------------------------- |
| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types; 3. Parameter verification failed. |
**Example**
```ts
// The phAccessHelper instance obtained is a global object. It is used by default in subsequent operations. If the code snippet is not added, an error will be reported indicating that phAccessHelper is not defined.
// Obtain the context from the component and ensure that the return value of this.getUiContext().getHostContext() is 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 indicates the user ID of another user space.
let phAccessHelper = photoAccessHelper.getPhotoAccessHelper(context, 101);
}).width('100%')
}
.height('90%')
}
}
```
## PhotoAccessHelper
### createAsset
createAsset(displayName: string, callback: AsyncCallback<PhotoAsset>): void
Creates an image or video asset with the specified file name. This API uses an asynchronous callback to return the result.
The file name must comply with the following specifications:
- The file name consists of a valid file name and an image or video file name extension.
- The file name cannot exceed 255 characters.
- The file name cannot contain any of the following characters:
API version 18 and later: \ / : * ? " < > |
API versions 10 to 17: . .. \ / : * ? " ' ` < > | { } [ ]
**System API**: This is a system API.
**System capability**: SystemCapability.FileManagement.PhotoAccessHelper.Core
**Required permissions**: ohos.permission.WRITE_IMAGEVIDEO
**Parameters**
| Name | Type | Mandatory| Description |
| -------- | ------------------------ | ---- | ------------------------- |
| displayName | string | Yes | File name of the image or video to create. |
| callback | AsyncCallback<[PhotoAsset](#photoasset)> | Yes | Callback used to return the image or video created.|
**Error codes**
For details about the error codes, see [Universal Error Codes](../errorcode-universal.md) and [File Management Error Codes](../apis-core-file-kit/errorcode-filemanagement.md).
If error code 14000001 is returned, refer to [PhotoKeys](#photokeys) to learn about the format and length requirements of the file name.
If error code 13900012 is returned, follow the instructions provided in [Before You Start](../../media/medialibrary/photoAccessHelper-preparation.md).
| ID| Error Message|
| -------- | ---------------------------------------- |
| 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. |
**Example**
For details about how to create a phAccessHelper instance, see the example provided in [@ohos.file.photoAccessHelper (Album Management)](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>
Creates an image or video asset with the specified file name. This API uses a promise to return the result.
The file name must comply with the following specifications:
- The file name consists of a valid file name and an image or video file name extension.
- The file name cannot exceed 255 characters.
- The file name cannot contain any of the following characters:
API version 18 and later: \ / : * ? " < > |
API versions 10 to 17: . .. \ / : * ? " ' ` < > | { } [ ]
**System API**: This is a system API.
**System capability**: SystemCapability.FileManagement.PhotoAccessHelper.Core
**Required permissions**: ohos.permission.WRITE_IMAGEVIDEO
**Parameters**
| Name | Type | Mandatory| Description |
| -------- | ------------------------ | ---- | ------------------------- |
| displayName | string | Yes | File name of the image or video to create. |
**Return value**
| Type | Description |
| --------------------------- | -------------- |
| Promise<[PhotoAsset](#photoasset)> | Promise used to return the created image and video asset.|
**Error codes**
For details about the error codes, see [Universal Error Codes](../errorcode-universal.md) and [File Management Error Codes](../apis-core-file-kit/errorcode-filemanagement.md).
If error code 14000001 is returned, refer to [PhotoKeys](#photokeys) to learn about the format and length requirements of the file name.
If error code 13900012 is returned, follow the instructions provided in [Before You Start](../../media/medialibrary/photoAccessHelper-preparation.md).
| ID| Error Message|
| -------- | ---------------------------------------- |
| 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. |
**Example**
For details about how to create a phAccessHelper instance, see the example provided in [@ohos.file.photoAccessHelper (Album Management)](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
Creates an image or video asset with the specified file name and options. This API uses an asynchronous callback to return the result.
The file name must comply with the following specifications:
- The file name consists of a valid file name and an image or video file name extension.
- The file name cannot exceed 255 characters.
- The file name cannot contain any of the following characters:
API version 18 and later: \ / : * ? " < > |
API versions 10 to 17: . .. \ / : * ? " ' ` < > | { } [ ]
**System API**: This is a system API.
**System capability**: SystemCapability.FileManagement.PhotoAccessHelper.Core
**Required permissions**: ohos.permission.WRITE_IMAGEVIDEO
**Parameters**
| Name | Type | Mandatory| Description |
| -------- | ------------------------ | ---- | ------------------------- |
| displayName | string | Yes | File name of the image or video to create. |
| options | [PhotoCreateOptions](#photocreateoptions) | Yes | Options for creating an image or video asset. |
| callback | AsyncCallback<[PhotoAsset](#photoasset)> | Yes | Callback used to return the image or video created.|
**Error codes**
For details about the error codes, see [Universal Error Codes](../errorcode-universal.md) and [File Management Error Codes](../apis-core-file-kit/errorcode-filemanagement.md).
If error code 14000001 is returned, refer to [PhotoKeys](#photokeys) to learn about the format and length requirements of the file name.
If error code 13900012 is returned, follow the instructions provided in [Before You Start](../../media/medialibrary/photoAccessHelper-preparation.md).
| ID| Error Message|
| -------- | ---------------------------------------- |
| 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. |
**Example**
For details about how to create a phAccessHelper instance, see the example provided in [@ohos.file.photoAccessHelper (Album Management)](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>
Creates an image or video asset with the specified file name and options. This API uses a promise to return the result.
The file name must comply with the following specifications:
- The file name consists of a valid file name and an image or video file name extension.
- The file name cannot exceed 255 characters.
- The file name cannot contain any of the following characters:
API version 18 and later: \ / : * ? " < > |
API versions 10 to 17: . .. \ / : * ? " ' ` < > | { } [ ]
**System API**: This is a system API.
**System capability**: SystemCapability.FileManagement.PhotoAccessHelper.Core
**Required permissions**: ohos.permission.WRITE_IMAGEVIDEO
**Parameters**
| Name | Type | Mandatory| Description |
| -------- | ------------------------ | ---- | ------------------------- |
| displayName | string | Yes | File name of the image or video to create. |
| options | [PhotoCreateOptions](#photocreateoptions) | Yes | Options for creating an image or video asset. |
**Return value**
| Type | Description |
| --------------------------- | -------------- |
| Promise<[PhotoAsset](#photoasset)> | Promise used to return the created image and video asset.|
**Error codes**
For details about the error codes, see [Universal Error Codes](../errorcode-universal.md) and [File Management Error Codes](../apis-core-file-kit/errorcode-filemanagement.md).
If error code 14000001 is returned, refer to [PhotoKeys](#photokeys) to learn about the format and length requirements of the file name.
If error code 13900012 is returned, follow the instructions provided in [Before You Start](../../media/medialibrary/photoAccessHelper-preparation.md).
| ID| Error Message|
| -------- | ---------------------------------------- |
| 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. |
**Example**
For details about how to create a phAccessHelper instance, see the example provided in [@ohos.file.photoAccessHelper (Album Management)](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
Creates an album. This API uses an asynchronous callback to return the result.
The album name must meet the following requirements:
- The album name cannot exceed 255 characters.
- The album name cannot contain any of the following characters:
. .. \ / : * ? " ' ` < > | { } [ ]
- Duplicate album names are not allowed.
> **NOTE**
>
> This API is supported since API version 10 and deprecated since API version 11. Use [MediaAlbumChangeRequest.createAlbumRequest](#createalbumrequest11) instead.
**System API**: This is a system API.
**System capability**: SystemCapability.FileManagement.PhotoAccessHelper.Core
**Required permissions**: ohos.permission.WRITE_IMAGEVIDEO
**Parameters**
| Name | Type | Mandatory| Description |
| -------- | ------------------------ | ---- | ------------------------- |
| name | string | Yes | Name of the album to create. |
| callback | AsyncCallback<[Album](#album)> | Yes | Callback used to return the created album instance.|
**Error codes**
For details about the error codes, see [Universal Error Codes](../errorcode-universal.md) and [File Management Error Codes](../apis-core-file-kit/errorcode-filemanagement.md).
If error code 13900012 is returned, follow the instructions provided in [Before You Start](../../media/medialibrary/photoAccessHelper-preparation.md).
| ID| Error Message|
| -------- | ---------------------------------------- |
| 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. |
**Example**
For details about how to create a phAccessHelper instance, see the example provided in [@ohos.file.photoAccessHelper (Album Management)](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>
Creates an album. This API uses a promise to return the result.
The album name must meet the following requirements:
- The album name cannot exceed 255 characters.
- The album name cannot contain any of the following characters:
. .. \ / : * ? " ' ` < > | { } [ ]
- Duplicate album names are not allowed.
> **NOTE**
>
> This API is supported since API version 10 and deprecated since API version 11. Use [MediaAlbumChangeRequest.createAlbumRequest](#createalbumrequest11) instead.
**System API**: This is a system API.
**System capability**: SystemCapability.FileManagement.PhotoAccessHelper.Core
**Required permissions**: ohos.permission.WRITE_IMAGEVIDEO
**Parameters**
| Name | Type | Mandatory| Description |
| -------- | ------------------------ | ---- | ------------------------- |
| name | string | Yes | Name of the album to create. |
**Return value**
| Type | Description |
| --------------------------- | -------------- |
| Promise<[Album](#album)> | Promise used to return the created album instance.|
**Error codes**
For details about the error codes, see [Universal Error Codes](../errorcode-universal.md) and [File Management Error Codes](../apis-core-file-kit/errorcode-filemanagement.md).
If error code 13900012 is returned, follow the instructions provided in [Before You Start](../../media/medialibrary/photoAccessHelper-preparation.md).
| ID| Error Message|
| -------- | ---------------------------------------- |
| 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. |
**Example**
For details about how to create a phAccessHelper instance, see the example provided in [@ohos.file.photoAccessHelper (Album Management)](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
Deletes albums. This API uses an asynchronous callback to return the result.
Ensure that the albums to be deleted exist. Only user albums can be deleted.
> **NOTE**
>
> This API is supported since API version 10 and deprecated since API version 11. Use [MediaAlbumChangeRequest.deleteAlbums](#deletealbums11) instead.
**System API**: This is a system API.
**System capability**: SystemCapability.FileManagement.PhotoAccessHelper.Core
**Required permissions**: ohos.permission.WRITE_IMAGEVIDEO
**Parameters**
| Name | Type | Mandatory| Description |
| -------- | ------------------------ | ---- | ------------------------- |
| albums | Array<[Album](#album)> | Yes | Albums to delete. |
| callback | AsyncCallback<void> | Yes | Callback that returns no value.|
**Error codes**
For details about the error codes, see [Universal Error Codes](../errorcode-universal.md) and [File Management Error Codes](../apis-core-file-kit/errorcode-filemanagement.md).
If error code 13900012 is returned, follow the instructions provided in [Before You Start](../../media/medialibrary/photoAccessHelper-preparation.md).
| ID| Error Message|
| -------- | ---------------------------------------- |
| 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. |
**Example**
For details about how to create a phAccessHelper instance, see the example provided in [@ohos.file.photoAccessHelper (Album Management)](arkts-apis-photoAccessHelper-f.md).
```ts
import { dataSharePredicates } from '@kit.ArkData';
async function example(phAccessHelper: photoAccessHelper.PhotoAccessHelper) {
// Delete the album named 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>
Deletes albums. This API uses a promise to return the result.
Ensure that the albums to be deleted exist. Only user albums can be deleted.
> **NOTE**
>
> This API is supported since API version 10 and deprecated since API version 11. Use [MediaAlbumChangeRequest.deleteAlbums](#deletealbums11) instead.
**System API**: This is a system API.
**System capability**: SystemCapability.FileManagement.PhotoAccessHelper.Core
**Required permissions**: ohos.permission.WRITE_IMAGEVIDEO
**Parameters**
| Name | Type | Mandatory| Description |
| -------- | ------------------------ | ---- | ------------------------- |
| albums | Array<[Album](#album)> | Yes | Albums to delete. |
**Return value**
| Type | Description |
| --------------------------- | -------------- |
| Promise<void> | Promise that returns no value.|
**Error codes**
For details about the error codes, see [Universal Error Codes](../errorcode-universal.md) and [File Management Error Codes](../apis-core-file-kit/errorcode-filemanagement.md).
If error code 13900012 is returned, follow the instructions provided in [Before You Start](../../media/medialibrary/photoAccessHelper-preparation.md).
| ID| Error Message|
| -------- | ---------------------------------------- |
| 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. |
**Example**
For details about how to create a phAccessHelper instance, see the example provided in [@ohos.file.photoAccessHelper (Album Management)](arkts-apis-photoAccessHelper-f.md).
```ts
import { dataSharePredicates } from '@kit.ArkData';
import { BusinessError } from '@kit.BasicServicesKit';
async function example(phAccessHelper: photoAccessHelper.PhotoAccessHelper) {
// Delete the album named 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
Obtains hidden albums based on the specified display mode and retrieval options. This API uses an asynchronous callback to return the result.
**System API**: This is a system API.
**Required permissions**: ohos.permission.READ_IMAGEVIDEO and ohos.permission.MANAGE_PRIVATE_PHOTOS
**System capability**: SystemCapability.FileManagement.PhotoAccessHelper.Core
**Parameters**
| Name | Type | Mandatory| Description |
| -------- | ------------------------ | ---- | ------------------------- |
| mode | [HiddenPhotosDisplayMode](#hiddenphotosdisplaymode11) | Yes | Display mode of hidden albums. |
| options | [FetchOptions](arkts-apis-photoAccessHelper-i.md#fetchoptions) | Yes | Retrieval options. |
| callback | AsyncCallback<[FetchResult](arkts-apis-photoAccessHelper-FetchResult.md)<[Album](#album)>> | Yes | Callback used to return the result.|
**Error codes**
For details about the error codes, see [Universal Error Codes](../errorcode-universal.md) and [File Management Error Codes](../apis-core-file-kit/errorcode-filemanagement.md).
| ID| Error Message|
| -------- | ---------------------------------------- |
| 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. |
**Example**
For details about how to create a phAccessHelper instance, see the example provided in [@ohos.file.photoAccessHelper (Album Management)](arkts-apis-photoAccessHelper-f.md).
```ts
import { dataSharePredicates } from '@kit.ArkData';
// Obtain the album newAlbumName that contains hidden files.
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
Obtains hidden albums based on the specified display mode. This API uses an asynchronous callback to return the result.
**System API**: This is a system API.
**Required permissions**: ohos.permission.READ_IMAGEVIDEO and ohos.permission.MANAGE_PRIVATE_PHOTOS
**System capability**: SystemCapability.FileManagement.PhotoAccessHelper.Core
**Parameters**
| Name | Type | Mandatory| Description |
| -------- | ------------------------ | ---- | ------------------------- |
| mode | [HiddenPhotosDisplayMode](#hiddenphotosdisplaymode11) | Yes | Display mode of hidden albums. |
| callback | AsyncCallback<[FetchResult](arkts-apis-photoAccessHelper-FetchResult.md)<[Album](#album)>> | Yes | Callback used to return the result.|
**Error codes**
For details about the error codes, see [Universal Error Codes](../errorcode-universal.md) and [File Management Error Codes](../apis-core-file-kit/errorcode-filemanagement.md).
| ID| Error Message|
| -------- | ---------------------------------------- |
| 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. |
**Example**
For details about how to create a phAccessHelper instance, see the example provided in [@ohos.file.photoAccessHelper (Album Management)](arkts-apis-photoAccessHelper-f.md).
```ts
import { dataSharePredicates } from '@kit.ArkData';
// Obtain the preset hidden album.
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();
});
}
// Obtain the hidden albums displayed by album, that is, the albums with hidden files. Such albums do not include the preset hidden album and the albums in the trash.
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++) {
// Obtain hidden files in the album.
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>>
Obtains hidden albums based on the specified display mode and retrieval options. This API uses a promise to return the result.
**System API**: This is a system API.
**Required permissions**: ohos.permission.READ_IMAGEVIDEO and ohos.permission.MANAGE_PRIVATE_PHOTOS
**System capability**: SystemCapability.FileManagement.PhotoAccessHelper.Core
**Parameters**
| Name | Type | Mandatory| Description |
| -------- | ------------------------ | ---- | ------------------------- |
| mode | [HiddenPhotosDisplayMode](#hiddenphotosdisplaymode11) | Yes | Display mode of hidden albums. |
| options | [FetchOptions](arkts-apis-photoAccessHelper-i.md#fetchoptions) | No | Options for retrieving the files. If this parameter is not specified, the files are retrieved based on the display mode of hidden files. |
**Return value**
| Type | Description |
| --------------------------- | -------------- |
| Promise<[FetchResult](arkts-apis-photoAccessHelper-FetchResult.md)<[Album](#album)>> | Promise used to return the result.
**Error codes**
For details about the error codes, see [Universal Error Codes](../errorcode-universal.md) and [File Management Error Codes](../apis-core-file-kit/errorcode-filemanagement.md).
| ID| Error Message|
| -------- | ---------------------------------------- |
| 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. |
**Example**
For details about how to create a phAccessHelper instance, see the example provided in [@ohos.file.photoAccessHelper (Album Management)](arkts-apis-photoAccessHelper-f.md).
```ts
import { dataSharePredicates } from '@kit.ArkData';
import { BusinessError } from '@kit.BasicServicesKit';
// Obtain the preset hidden album.
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}`);
});
}
// Obtain the hidden albums displayed by album, that is, the albums with hidden files. Such albums do not include the preset hidden album and the albums in the trash.
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++) {
// Obtain hidden files in the album.
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
Deletes media assets. This API uses an asynchronous callback to return the result. The deleted assets are moved to the trash.
> **NOTE**
>
> This API is supported since API version 10 and deprecated since API version 11. You are advised to use [MediaAssetChangeRequest.deleteAssets](arkts-apis-photoAccessHelper-MediaAssetChangeRequest.md#deleteassets11) instead.
**System API**: This is a system API.
**Required permissions**: ohos.permission.WRITE_IMAGEVIDEO
**System capability**: SystemCapability.FileManagement.PhotoAccessHelper.Core
**Parameters**
| Name | Type | Mandatory| Description |
| -------- | ------------------------- | ---- | ---------- |
| uriList | Array<string> | Yes | URIs of the media files to delete.|
| callback | AsyncCallback<void> | Yes | Callback that returns no value.|
**Error codes**
For details about the error codes, see [Universal Error Codes](../errorcode-universal.md) and [File Management Error Codes](../apis-core-file-kit/errorcode-filemanagement.md).
If error code 13900012 is returned, follow the instructions provided in [Before You Start](../../media/medialibrary/photoAccessHelper-preparation.md).
| ID| Error Message|
| -------- | ---------------------------------------- |
| 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. |
**Example**
For details about how to create a phAccessHelper instance, see the example provided in [@ohos.file.photoAccessHelper (Album Management)](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>
Deletes media assets. This API uses a promise to return the result. The deleted assets are moved to the trash.
> **NOTE**
>
> This API is supported since API version 10 and deprecated since API version 11. You are advised to use [MediaAssetChangeRequest.deleteAssets](arkts-apis-photoAccessHelper-MediaAssetChangeRequest.md#deleteassets11) instead.
**System API**: This is a system API.
**Required permissions**: ohos.permission.WRITE_IMAGEVIDEO
**System capability**: SystemCapability.FileManagement.PhotoAccessHelper.Core
**Parameters**
| Name | Type | Mandatory| Description |
| -------- | ------------------------- | ---- | ---------- |
| uriList | Array<string> | Yes | URIs of the media files to delete.|
**Return value**
| Type | Description |
| --------------------------------------- | ----------------- |
| Promise<void>| Promise that returns no value.|
**Error codes**
For details about the error codes, see [Universal Error Codes](../errorcode-universal.md) and [File Management Error Codes](../apis-core-file-kit/errorcode-filemanagement.md).
If error code 13900012 is returned, follow the instructions provided in [Before You Start](../../media/medialibrary/photoAccessHelper-preparation.md).
| ID| Error Message|
| -------- | ---------------------------------------- |
| 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. |
**Example**
For details about how to create a phAccessHelper instance, see the example provided in [@ohos.file.photoAccessHelper (Album Management)](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
Obtains the index of an image or video in an album. This API uses an asynchronous callback to return the result.
**System API**: This is a system API.
**Required permissions**: ohos.permission.READ_IMAGEVIDEO
**System capability**: SystemCapability.FileManagement.PhotoAccessHelper.Core
**Parameters**
| Name | Type | Mandatory| Description |
| -------- | ------------------------- | ---- | ---------- |
| photoUri | string | Yes | URI of the media asset whose index is to be obtained.|
| albumUri | string | Yes | Album URI, which can be an empty string. If it is an empty string, all the media assets in the Gallery are obtained by default. |
| options | [FetchOptions](arkts-apis-photoAccessHelper-i.md#fetchoptions) | Yes | Retrieval options. Only one search condition or sorting mode must be set in **predicates**. If no value is set or multiple search criteria or sorting modes are set, the API cannot be called successfully. |
| callback | AsyncCallback<number>| Yes | Callback used to return the index obtained.|
**Error codes**
For details about the error codes, see [Universal Error Codes](../errorcode-universal.md) and [File Management Error Codes](../apis-core-file-kit/errorcode-filemanagement.md).
If error code 13900012 is returned, follow the instructions provided in [Before You Start](../../media/medialibrary/photoAccessHelper-preparation.md).
| ID| Error Message|
| -------- | ---------------------------------------- |
| 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. |
**Example**
For details about how to create a phAccessHelper instance, see the example provided in [@ohos.file.photoAccessHelper (Album Management)](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>
Obtains the index of an image or video in an album. This API uses a promise to return the result.
**System API**: This is a system API.
**Required permissions**: ohos.permission.READ_IMAGEVIDEO
**System capability**: SystemCapability.FileManagement.PhotoAccessHelper.Core
**Parameters**
| Name | Type | Mandatory| Description |
| -------- | ------------------------- | ---- | ---------- |
| photoUri | string | Yes | URI of the media asset whose index is to be obtained.|
| albumUri | string | Yes | Album URI, which can be an empty string. If it is an empty string, all the media assets in the Gallery are obtained by default. |
| options | [FetchOptions](arkts-apis-photoAccessHelper-i.md#fetchoptions) | Yes | Retrieval options. Only one search condition or sorting mode must be set in **predicates**. If no value is set or multiple search criteria or sorting modes are set, the API cannot be called successfully. |
**Return value**
| Type | Description |
| --------------------------------------- | ----------------- |
| Promise<number>| Promise used to return the index obtained.|
**Error codes**
For details about the error codes, see [Universal Error Codes](../errorcode-universal.md) and [File Management Error Codes](../apis-core-file-kit/errorcode-filemanagement.md).
If error code 13900012 is returned, follow the instructions provided in [Before You Start](../../media/medialibrary/photoAccessHelper-preparation.md).
| ID| Error Message|
| -------- | ---------------------------------------- |
| 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. |
**Example**
For details about how to create a phAccessHelper instance, see the example provided in [@ohos.file.photoAccessHelper (Album Management)](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
Saves a Gallery widget. This API uses an asynchronous callback to return the result.
**System API**: This is a system API.
**Required permissions**: ohos.permission.WRITE_IMAGEVIDEO
**System capability**: SystemCapability.FileManagement.PhotoAccessHelper.Core
**Parameters**
| Name | Type | Mandatory| Description |
| -------- | ------------------------ | ---- | ------------------------- |
| info | [FormInfo](#forminfo11) | Yes | Information about the Gallery widget to save, which includes the ID of the widget and the URI of the image bound to the widget. |
| callback | AsyncCallback<void> | Yes | Callback that returns no value.|
**Error codes**
For details about the error codes, see [Universal Error Codes](../errorcode-universal.md) and [File Management Error Codes](../apis-core-file-kit/errorcode-filemanagement.md).
| ID| Error Message|
| -------- | ---------------------------------------- |
| 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. |
**Example**
For details about how to create a phAccessHelper instance, see the example provided in [@ohos.file.photoAccessHelper (Album Management)](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 is a string consisting of only digits. uri indicates the URI of the image in Gallery. If there is no image in Gallery, uri must be an empty string.
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>
Saves a Gallery widget. This API uses a promise to return the result.
**System API**: This is a system API.
**Required permissions**: ohos.permission.WRITE_IMAGEVIDEO
**System capability**: SystemCapability.FileManagement.PhotoAccessHelper.Core
**Parameters**
| Name | Type | Mandatory| Description |
| -------- | ------------------------ | ---- | ------------------------- |
| info | [FormInfo](#forminfo11) | Yes | Information about the Gallery widget to save, which includes the ID of the widget and the URI of the image bound to the widget. |
**Return value**
| Type | Description |
| --------------------------------------- | ----------------- |
| Promise<void>| Promise that returns no value.|
**Error codes**
For details about the error codes, see [Universal Error Codes](../errorcode-universal.md) and [File Management Error Codes](../apis-core-file-kit/errorcode-filemanagement.md).
| ID| Error Message|
| -------- | ---------------------------------------- |
| 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. |
**Example**
For details about how to create a phAccessHelper instance, see the example provided in [@ohos.file.photoAccessHelper (Album Management)](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 is a string consisting of only digits. uri indicates the URI of the image in Gallery. If there is no image in Gallery, uri must be an empty string.
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
Removes a Gallery widget. This API uses an asynchronous callback to return the result.
**System API**: This is a system API.
**Required permissions**: ohos.permission.WRITE_IMAGEVIDEO
**System capability**: SystemCapability.FileManagement.PhotoAccessHelper.Core
**Parameters**
| Name | Type | Mandatory| Description |
| -------- | ------------------------ | ---- | ------------------------- |
| info | [FormInfo](#forminfo11) | Yes | Information about the Gallery widget to save, which includes the ID of the widget and the URI of the image bound to the widget. |
| callback | AsyncCallback<void> | Yes | Callback that returns no value.|
**Error codes**
For details about the error codes, see [Universal Error Codes](../errorcode-universal.md) and [File Management Error Codes](../apis-core-file-kit/errorcode-filemanagement.md).
| ID| Error Message|
| -------- | ---------------------------------------- |
| 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. |
**Example**
For details about how to create a phAccessHelper instance, see the example provided in [@ohos.file.photoAccessHelper (Album Management)](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 is a string consisting of only digits. When removing a widget, leave uri empty.
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>
Removes a Gallery widget. This API uses a promise to return the result.
**System API**: This is a system API.
**Required permissions**: ohos.permission.WRITE_IMAGEVIDEO
**System capability**: SystemCapability.FileManagement.PhotoAccessHelper.Core
**Parameters**
| Name | Type | Mandatory| Description |
| -------- | ------------------------ | ---- | ------------------------- |
| info | [FormInfo](#forminfo11) | Yes | Information about the Gallery widget to save, which includes the ID of the widget and the URI of the image bound to the widget. |
**Return value**
| Type | Description |
| --------------------------------------- | ----------------- |
| Promise<void>| Promise that returns no value.|
**Error codes**
For details about the error codes, see [Universal Error Codes](../errorcode-universal.md) and [File Management Error Codes](../apis-core-file-kit/errorcode-filemanagement.md).
| ID| Error Message|
| -------- | ---------------------------------------- |
| 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. |
**Example**
For details about how to create a phAccessHelper instance, see the example provided in [@ohos.file.photoAccessHelper (Album Management)](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 is a string consisting of only digits. When removing a widget, leave uri empty.
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>>
Creates media assets for an application with the specified token ID. The returned URIs has been granted with the permission for writing the media assets (images or videos).
**System API**: This is a system API.
**Required permissions**: ohos.permission.WRITE_IMAGEVIDEO
**System capability**: SystemCapability.FileManagement.PhotoAccessHelper.Core
**Parameters**
| Name | Type | Mandatory| Description |
| -------- |----------------------------------------------------------------------| ---- | ------------------------- |
| bundleName | string | Yes| Bundle name of the target application.|
| appName | string | Yes| Name of the target application.|
| tokenId | number | Yes| Token ID of the target application.|
| photoCreationConfigs | Array<[PhotoCreationConfig](arkts-apis-photoAccessHelper-i.md#photocreationconfig12)> | Yes| Configuration for creating (saving) the media assets in the media library.|
**Return value**
| Type | Description |
| --------------------------------------- | ----------------- |
| Promise<Array<string>> | Promise used to return the URIs of the media asset files in the media library. The target application (identified by **tokenId**) can write the media assets based on the URIs without requesting the write permission. If the URIs fail to be generated, a batch creation error code will be returned.
The error code **-3006** means that there are invalid characters; **-2004** means that the image type does not match the file name extension; **-203** means that the file operation is abnormal.|
**Error codes**
For details about the error codes, see [Universal Error Codes](../errorcode-universal.md) and [File Management Error Codes](../apis-core-file-kit/errorcode-filemanagement.md).
| ID| Error Message|
| -------- | ---------------------------------------- |
| 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. |
**Example**
For details about how to create a phAccessHelper instance, see the example provided in [@ohos.file.photoAccessHelper (Album Management)](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>
Grants an application the permission to access a URI. This API uses a promise to return the result.
**System API**: This is a system API.
**System capability**: SystemCapability.FileManagement.PhotoAccessHelper.Core
**Required permissions**: ohos.permission.WRITE_IMAGEVIDEO
**Parameters**
| Name | Type | Mandatory| Description |
| -------- |----------------------------------------------------------------------| ---- | ------------------------- |
| tokenId | number | Yes| ID of the target application.|
| uri | string | Yes| URI of the media asset.|
| photoPermissionType | [PhotoPermissionType](#photopermissiontype12) | Yes| Type of the permission to be granted. For details, see the enum.|
| hideSensitiveType | [HideSensitiveType](#hidesensitivetype12) | Yes| Type of the information to hide. This parameter is reserved. Currently, any enumerated value of **HideSensitiveType** can be passed in.|
**Return value**
| Type | Description |
| --------------------------------------- | ----------------- |
| Promise<number> | Promise used to return the result. The value **0** means the permission is granted to the application. The value **1** means the application already has the permission. The value **-1** means the permission fails to be granted.|
**Error codes**
For details about the error codes, see [Universal Error Codes](../errorcode-universal.md) and [File Management Error Codes](../apis-core-file-kit/errorcode-filemanagement.md).
| ID| Error Message|
| -------- | ---------------------------------------- |
| 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. |
**Example**
For details about how to create a phAccessHelper instance, see the example provided in [@ohos.file.photoAccessHelper (Album Management)](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>
Grants an application the permission to access multiple URIs. This API uses a promise to return the result.
**System API**: This is a system API.
**System capability**: SystemCapability.FileManagement.PhotoAccessHelper.Core
**Required permissions**: ohos.permission.WRITE_IMAGEVIDEO
**Parameters**
| Name | Type | Mandatory| Description |
| -------- |----------------------------------------------------------------------| ---- | ------------------------- |
| tokenId | number | Yes| ID of the target application.|
| uriList | Array<string> | Yes| A list of URIs, which cannot exceed 1000.|
| photoPermissionType | [PhotoPermissionType](#photopermissiontype12) | Yes| Type of the permission to be granted. For details, see the enum.|
| hideSensitiveType | [HideSensitiveType](#hidesensitivetype12) | Yes| Type of the information to hide. This parameter is reserved. Currently, any enumerated value of **HideSensitiveType** can be passed in.|
**Return value**
| Type | Description |
| --------------------------------------- | ----------------- |
| Promise<number> | Promise used to return the result. The value **0** means the operation is successful; the value **-1** means the opposite.|
**Error codes**
For details about the error codes, see [Universal Error Codes](../errorcode-universal.md) and [File Management Error Codes](../apis-core-file-kit/errorcode-filemanagement.md).
| ID| Error Message|
| -------- | ---------------------------------------- |
| 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. |
**Example**
For details about how to create a phAccessHelper instance, see the example provided in [@ohos.file.photoAccessHelper (Album Management)](arkts-apis-photoAccessHelper-f.md).
```ts
async function example(phAccessHelper: photoAccessHelper.PhotoAccessHelper) {
console.info('grantPhotoUrisPermissionDemo');
try {
// URIs of the media assets.
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>
Cancels the permission for accessing an URI from an application. This API uses a promise to return the result.
**System API**: This is a system API.
**System capability**: SystemCapability.FileManagement.PhotoAccessHelper.Core
**Required permissions**: ohos.permission.WRITE_IMAGEVIDEO
**Parameters**
| Name | Type | Mandatory| Description |
| -------- |----------------------------------------------------------------------| ---- | ------------------------- |
| tokenId | number | Yes| ID of the target application.|
| uri | string | Yes| URI of the media asset.|
| photoPermissionType | [PhotoPermissionType](#photopermissiontype12) | Yes| Permission type.|
**Return value**
| Type | Description |
| --------------------------------------- | ----------------- |
| Promise<number> | Promise used to return the result. The value **0** means the operation is successful, and the value **-1** means the opposite.|
**Error codes**
For details about the error codes, see [Universal Error Codes](../errorcode-universal.md) and [File Management Error Codes](../apis-core-file-kit/errorcode-filemanagement.md).
| ID| Error Message|
| -------- | ---------------------------------------- |
| 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. |
**Example**
For details about how to create a phAccessHelper instance, see the example provided in [@ohos.file.photoAccessHelper (Album Management)](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
Generates a thumbnail based on the specified rule.
**System API**: This is a system API.
**System capability**: SystemCapability.FileManagement.PhotoAccessHelper.Core
**Required permissions**: ohos.permission.READ_IMAGEVIDEO
**Parameters**
| Name | Type | Mandatory| Description |
| --------- | --------------------------------------- | ---- | --------------- |
| predicates | [dataSharePredicates.DataSharePredicates](../apis-arkdata/js-apis-data-dataSharePredicates.md#datasharepredicates) | Yes | Rule for generating the thumbnail. |
| callback | AsyncCallback<void> | Yes | Callback used to return the result. If the operation is successful, the notification task ends, and **err** is undefined. If the task fails, **err** is an error object.|
**Return value**
| Type | Description |
| --------------------- | -------------------- |
| Promise<number> | Promise used to return the ID of the thumbnail generation task.|
**Error codes**
For details about the error codes, see [Universal Error Codes](../errorcode-universal.md) and [File Management Error Codes](../apis-core-file-kit/errorcode-filemanagement.md).
| ID| Error Message|
| -------- | ---------------------------------------- |
| 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. |
**Example**
For details about how to create a phAccessHelper instance, see the example provided in [@ohos.file.photoAccessHelper (Album Management)](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
Stops generating a thumbnail.
**System API**: This is a system API.
**System capability**: SystemCapability.FileManagement.PhotoAccessHelper.Core
**Required permissions**: ohos.permission.READ_IMAGEVIDEO
**Parameters**
| Name | Type | Mandatory| Description |
| ----- | ------ | ---- | ------------------------ |
| taskId | number | Yes | ID of the thumbnail generation task to stop.|
**Error codes**
For details about the error codes, see [Universal Error Codes](../errorcode-universal.md) and [File Management Error Codes](../apis-core-file-kit/errorcode-filemanagement.md).
| ID| Error Message|
| -------- | ---------------------------------------- |
| 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. |
**Example**
For details about how to create a phAccessHelper instance, see the example provided in [@ohos.file.photoAccessHelper (Album Management)](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>
Obtains the index construction progress. This API uses a promise to return the result.
**System API**: This is a system API.
**System capability**: SystemCapability.FileManagement.PhotoAccessHelper.Core
**Required permissions**: ohos.permission.READ_IMAGEVIDEO
**Return value**
| Type | Description |
| --------------------------- | -------------- |
| Promise<string> | Promise used to return a string in JSON format. The string indicates the number of images that have been analyzed, the total number of images, the number of videos that have been analyzed, and the total number of videos.|
**Error codes**
For details about the error codes, see [Universal Error Codes](../errorcode-universal.md) and [File Management Error Codes](../apis-core-file-kit/errorcode-filemanagement.md).
| ID| Error Message|
| -------- | ---------------------------------------- |
| 201 | Permission denied. |
| 202 | Called by non-system application. |
| 14000011 | Internal system error. |
**Example**
For details about how to create a phAccessHelper instance, see the example provided in [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);
//...Use the obtained index construction progress data.
} catch (err) {
console.error(`getIndexConstructProgress failed, error: ${err.code}, ${err.message}`);
}
}
```
### getDataAnalysisProgress12+
getDataAnalysisProgress(analysisType: AnalysisType): Promise<string>
Obtains the asset analysis progress. This API uses a promise to return the result.
**System API**: This is a system API.
**System capability**: SystemCapability.FileManagement.PhotoAccessHelper.Core
**Required permissions**: ohos.permission.READ_IMAGEVIDEO
**Parameters**
| Name | Type | Mandatory | Description |
| ---- | -------------- | ---- | ----- |
| analysisType | [AnalysisType](#analysistype11) | Yes | Smart analysis type.|
**Return value**
| Type | Description |
| --------------------------- | -------------- |
| Promise<string> | Promise used to return a string in JSON format. The string indicates the asset analysis progress.|
**Error codes**
For details about the error codes, see [Universal Error Codes](../errorcode-universal.md) and [File Management Error Codes](../apis-core-file-kit/errorcode-filemanagement.md).
| ID| Error Message|
| -------- | ---------------------------------------- |
| 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. |
**Example**
For details about how to create a phAccessHelper instance, see the example provided in [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\
Obtains the shared photo assets.
**System API**: This is a system API.
**System capability**: SystemCapability.FileManagement.PhotoAccessHelper.Core
**Required permission**: ohos.permission.ACCESS_MEDIALIB_THUMB_DB
**Parameters**
| Name | Type | Mandatory| Description |
| --------- | ------------ | ---- | ------- |
| options | [FetchOptions](arkts-apis-photoAccessHelper-i.md#fetchoptions) | Yes | Options for obtaining the shared photo assets.|
**Return value**
| Type | Description |
| ----------------------- | ------------------ |
| Array\<[SharedPhotoAsset](#sharedphotoasset13)\> | Shared photo assets obtained.|
**Error codes**
For details about the error codes, see [Universal Error Codes](../errorcode-universal.md) and [File Management Error Codes](../apis-core-file-kit/errorcode-filemanagement.md).
| ID| Error Message|
| -------- | ---------------------------------------- |
| 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. |
**Example**
For details about how to create a phAccessHelper instance, see the example provided in [@ohos.file.photoAccessHelper (Album Management)](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>
Starts asset analysis.
**System API**: This is a system API.
**System capability**: SystemCapability.FileManagement.PhotoAccessHelper.Core
**Required permissions**: ohos.permission.WRITE_IMAGEVIDEO
**Parameters**
| Name | Type | Mandatory| Description |
| --------- | ------------------- | ---- | ------------------------------------------------------------ |
| type | [AnalysisType](#analysistype11) | Yes | Smart analysis type. |
| assetUris | Array<string> | No | Array of asset URIs.
- If this parameter is specified, only the given assets are analyzed.
- If this parameter is left blank, full analysis is performed.|
**Return value**
| Type | Description |
| --------------------- | --------------------------- |
| Promise<number> | Promise used to return the task ID of the service.|
**Error codes**
For details about the error codes, see [Universal Error Codes](../errorcode-universal.md).
| ID| Error Message |
| -------- | ------------------------------------------------------------ |
| 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. |
**Example**
For details about how to create a phAccessHelper instance, see the example provided in [@ohos.file.photoAccessHelper (Album Management)](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\>
Creates assets with a temporary permission. This API uses a promise to return the result.
**System API**: This is a system API.
**System capability**: SystemCapability.FileManagement.PhotoAccessHelper.Core
**Required permissions**: ohos.permission.WRITE_IMAGEVIDEO
**Parameters**
| Name | Type | Mandatory| Description |
| -------- |----------------------------------------------------------------------| ---- | ------------------------- |
| boundleName| string | Yes| Bundle name of the target application.|
| appName| string | Yes| Name of the target application.|
| appId| string | Yes| ID of the target application.|
| tokenId| number| Yes| Unique identifier for the temporary authorization.|
| authorizationMode| [AuthorizationMode](#authorizationmode12)| Yes| Authorization mode. No confirmation dialog box is displayed when the application with the temporary permission saves media assets in the give period of time.|
| PhotoCreationConfig| Array\<[PhotoCreationConfig](arkts-apis-photoAccessHelper-i.md#photocreationconfig12)> | Yes| Configuration for creating (saving) the media assets in the media library.|
**Return value**
| Type | Description |
| --------------------------------------- | ----------------- |
| Promise\> | Promise used to return the URIs of the media asset files in the media library. The target application (identified by **appid**) can write the assets based on the URIs without has been authorized to the application specified by appId to allow the application to write data. If the URIs fail to be generated, a batch creation error code will be returned.
The error code **-3006** means that there are invalid characters; **-2004** means that the image type does not match the file name extension; **-203** means that the file operation is abnormal.|
**Error codes**
For details about the error codes, see [Universal Error Codes](../errorcode-universal.md) and [File Management Error Codes](../apis-core-file-kit/errorcode-filemanagement.md).
| ID| Error Message|
| -------- | ---------------------------------------- |
| 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. |
**Example**
For details about how to create a phAccessHelper instance, see the example provided in [@ohos.file.photoAccessHelper (Album Management)](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
Obtains the thumbnail of the specified type for the key frame. This API uses a promise to return the result.
**System API**: This is a system API.
**System capability**: SystemCapability.FileManagement.PhotoAccessHelper.Core
**Required permissions**: ohos.permission.READ_IMAGEVIDEO
**Parameters**
| Name | Type | Mandatory | Description |
| ---- | -------------- | ---- | ----- |
| beginFrameTimeMs | number | Yes | Time of the start frame, in ms. The value **0** indicates the cover frame.|
| type | [ThumbnailType](#thumbnailtype13)| Yes | Type of the thumbnail.|
**Return value**
| Type | Description |
| ----------------------------- | --------------------- |
| Promise<[image.PixelMap](../apis-image-kit/arkts-apis-image-PixelMap.md)> | Promise used to return the PixelMap of the thumbnail obtained. The cover frame is returned by default if no thumbnail is obtained.|
**Error codes**
For details about the error codes, see [Universal Error Codes](../errorcode-universal.md) and [File Management Error Codes](../apis-core-file-kit/errorcode-filemanagement.md).
| ID| Error Message|
| -------- | ---------------------------------------- |
| 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.
**Example**
For details about how to create a phAccessHelper instance, see the example provided in [@ohos.file.photoAccessHelper (Album Management)](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>
Saves a Gallery widget. This API uses a promise to return the result.
**System API**: This is a system API.
**Required permissions**: ohos.permission.WRITE_IMAGEVIDEO
**System capability**: SystemCapability.FileManagement.PhotoAccessHelper.Core
**Parameters**
| Name | Type | Mandatory| Description |
| -------- | ------------------------ | ---- | ------------------------- |
| info | [GalleryFormInfo](#galleryforminfo18) | Yes | Information about the Gallery widget, which includes the ID of the widget and the URIs of the image or album bound to the widget. |
**Return value**
| Type | Description |
| --------------------------------------- | ----------------- |
| Promise<void>| Promise that returns no value.|
**Error codes**
For details about the error codes, see [Universal Error Codes](../errorcode-universal.md) and [File Management Error Codes](../apis-core-file-kit/errorcode-filemanagement.md).
| ID| Error Message|
| -------- | ---------------------------------------- |
| 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. |
**Example**
```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 is a string consisting of only digits. assetUris indicates the URIs of the images or albums in Gallery.
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>
Updates the information about a Gallery widget and saves the information to the database. This API uses a promise to return the result.
**System API**: This is a system API.
**Required permissions**: ohos.permission.WRITE_IMAGEVIDEO
**System capability**: SystemCapability.FileManagement.PhotoAccessHelper.Core
**Parameters**
| Name | Type | Mandatory| Description |
| -------- | ------------------------ | ---- | ------------------------- |
| info | [GalleryFormInfo](#galleryforminfo18) | Yes | Information about the Gallery widget, which includes the ID of the widget and the URIs of the image or album bound to the widget. |
**Return value**
| Type | Description |
| --------------------------------------- | ----------------- |
| Promise<void>| Promise that returns no value.|
**Error codes**
For details about the error codes, see [Universal Error Codes](../errorcode-universal.md) and [File Management Error Codes](../apis-core-file-kit/errorcode-filemanagement.md).
| ID| Error Message|
| -------- | ---------------------------------------- |
| 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. |
**Example**
```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 is a string consisting of only digits. assetUris indicates the URIs of the images or albums in Gallery.
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>
Removes a Gallery widget. This API uses a promise to return the result.
**System API**: This is a system API.
**Required permissions**: ohos.permission.WRITE_IMAGEVIDEO
**System capability**: SystemCapability.FileManagement.PhotoAccessHelper.Core
**Parameters**
| Name | Type | Mandatory| Description |
| -------- | ------------------------ | ---- | ------------------------- |
| info | [GalleryFormInfo](#galleryforminfo18) | Yes | Information about the Gallery widget, which includes the ID of the widget and the URIs of the image or album bound to the widget. |
**Return value**
| Type | Description |
| --------------------------------------- | ----------------- |
| Promise<void>| Promise that returns no value.|
**Error codes**
For details about the error codes, see [Universal Error Codes](../errorcode-universal.md) and [File Management Error Codes](../apis-core-file-kit/errorcode-filemanagement.md).
| ID| Error Message|
| -------- | ---------------------------------------- |
| 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. |
**Example**
```ts
import { BusinessError } from '@kit.BasicServicesKit';
async function example(phAccessHelper: photoAccessHelper.PhotoAccessHelper) {
console.info('removeGalleryFormInfoDemo');
let info: photoAccessHelper.GalleryFormInfo = {
// formId is a string consisting of only digits. When removing a widget, leave assertUris empty.
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>>
Obtains album information by album IDs. This API uses a promise to return the result.
**System API**: This is a system API.
**System capability**: SystemCapability.FileManagement.PhotoAccessHelper.Core
**Required permissions**: ohos.permission.READ_IMAGEVIDEO
**Parameters**
| Name | Type | Mandatory| Description |
| --------- | ------------------- | ---- | ------------------------------------------------------------ |
| albumIds | Array<number> | Yes | Array of album IDs. |
**Return value**
| Type | Description |
| --------------------- | --------------------------- |
| Promise<Map<number, Album>> | Promise used to return the map object that contains the album information.|
**Error codes**
For details about the error codes, see [Universal Error Codes](../errorcode-universal.md) and [File Management Error Codes](../apis-core-file-kit/errorcode-filemanagement.md).
| ID| Error Message |
| -------- | ------------------------------------------------------------ |
| 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. |
**Example**
For details about how to create a phAccessHelper instance, see the example provided in [@ohos.file.photoAccessHelper (Album Management)](arkts-apis-photoAccessHelper-f.md).
```ts
async function example(phAccessHelper: photoAccessHelper.PhotoAccessHelper) {
console.info('startGetAlbumsByIdsDemo');
try {
// Obtain the sandbox URIs of the images or videos to be saved to the media library.
let albumIds: Array = [
12 //Use the actual album ID.
];
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>>
Creates assets for the current application or other applications in the specified source or user album. This API uses a promise to return the result.
**System API**: This is a system API.
**System capability**: SystemCapability.FileManagement.PhotoAccessHelper.Core
**Required permissions**: ohos.permission.WRITE_IMAGEVIDEO
**Parameters**
| Name | Type | Mandatory| Description |
| --------- | ------------------- | ---- | ------------------------------------------------------------ |
| source | [PhotoCreationSource](#photocreationsource18) | Yes | Application information provided to create assets on behalf of the application. |
| albumUri | string | Yes | URI of the album. |
| isAuthorized | boolean | Yes | Whether to authorize other applications. **true** to authorize, **false** otherwise. |
| PhotoCreationConfigs| Array\<[PhotoCreationConfig](arkts-apis-photoAccessHelper-i.md#photocreationconfig12)> | Yes| Configuration for creating (saving) the media assets in the media library.|
**Return value**
| Type | Description |
| --------------------- | --------------------------- |
| Promise<Array<string>> | Promise used to return the URIs of the media asset files in the media library.
The target application (identified by **appid**) can write the media assets based on the URIs without requesting the write permission. If the URIs fail to be generated, a batch creation error code will be returned.
The error code **-3006** means that there are invalid characters; **-2004** means that the image type does not match the file name extension; **-203** means that the file operation is abnormal.|
**Error codes**
For details about the error codes, see [Universal Error Codes](../errorcode-universal.md) and [File Management Error Codes](../apis-core-file-kit/errorcode-filemanagement.md).
| ID| Error Message |
| -------- | ------------------------------------------------------------ |
| 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. |
**Example**
For details about how to create a phAccessHelper instance, see the example provided in [@ohos.file.photoAccessHelper (Album Management)](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
Registers a listener for the **'hiddenPhotoChange'** event to monitor hidden media asset changes. This API uses a callback to return the result, and it accepts multiple callbacks.
**System API**: This is a system API.
**System capability**: SystemCapability.FileManagement.PhotoAccessHelper.Core
**Required permissions**: ohos.permission.READ_IMAGEVIDEO and ohos.permission.MANAGE_PRIVATE_PHOTOS
**Parameters**
| Name | Type | Mandatory| Description |
|-----------|-------------------------|-----------|-----------------|
| type | string | Yes | Event type. The value is fixed at **'hiddenPhotoChange'**. After the registration is complete, any change to the hidden media assets is returned through the callback.|
| callback | Callback<[PhotoAssetChangeInfos](arkts-apis-photoAccessHelper-i.md#photoassetchangeinfos20)> | Yes | Callback used to return the hidden media asset information after change, which is [PhotoAssetChangeInfos](arkts-apis-photoAccessHelper-i.md#photoassetchangeinfos20).
**NOTE**: You can register multiple listeners using this API, and you can call [off('hiddenPhotoChange')](#offhiddenphotochange20) to unregister all listeners or a specific one.|
**Error codes**
For details about the error codes, see [Universal Error Codes](../errorcode-universal.md) and [Media Library Error Codes](errcode-medialibrary.md).
| ID| Error Message|
| -------- | ---------------------------------------- |
| 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. |
**Example**
For details about how to create a phAccessHelper instance, see the example provided in [@ohos.file.photoAccessHelper (Album Management)](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 {
// Register onCallback1.
phAccessHelper.on('hiddenPhotoChange', onCallback1);
// Register onCallback2.
phAccessHelper.on('hiddenPhotoChange', onCallback2);
} catch (error) {
console.error('onHiddenPhotoChange failed, errCode is', error);
}
}
```
### off('hiddenPhotoChange')20+
off(type: 'hiddenPhotoChange', callback?: Callback<PhotoAssetChangeInfos>): void
Unregisters a listener for the **'hiddenPhotoChange'** event to stop monitoring hidden media asset changes. If multiple listeners are registered, you can unregister a specific listener by specifying **callback**. Alternatively, you can unregister all of them without specifying **callback**.
**System API**: This is a system API.
**System capability**: SystemCapability.FileManagement.PhotoAccessHelper.Core
**Required permissions**: ohos.permission.READ_IMAGEVIDEO and ohos.permission.MANAGE_PRIVATE_PHOTOS
**Parameters**
| Name | Type | Mandatory| Description |
|-----------|-------------------------|-----------|-----------------|
| type | string | Yes | Event type. The value is fixed at **'hiddenPhotoChange'**. After the unregistration is complete, any change to the hidden media assets is no longer returned through the callback.|
| callback | Callback<[PhotoAssetChangeInfos](arkts-apis-photoAccessHelper-i.md#photoassetchangeinfos20)> | No | Exact callback you previously registered with [on('hiddenPhotoChange')](#onhiddenphotochange20). If this parameter is left unspecified, all listeners for the **'hiddenPhotoChange'** event are unregistered.
**NOTE**: Once a specific callback is unregistered, it will not be invoked when a hidden media asset changes.|
**Error codes**
For details about the error codes, see [Universal Error Codes](../errorcode-universal.md) and [Media Library Error Codes](errcode-medialibrary.md).
| ID| Error Message|
| -------- | ---------------------------------------- |
| 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. |
**Example**
For details about how to create a phAccessHelper instance, see the example provided in [@ohos.file.photoAccessHelper (Album Management)](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 {
// Register onCallback1.
phAccessHelper.on('hiddenPhotoChange', onCallback1);
// Register onCallback2.
phAccessHelper.on('hiddenPhotoChange', onCallback2);
// Unregister the listening of onCallback1.
phAccessHelper.off('hiddenPhotoChange', onCallback1);
} catch (error) {
console.error('offHiddenPhotoChange failed, errCode is', error);
}
}
```
### on('trashedPhotoChange')20+
on(type: 'trashedPhotoChange', callback: Callback<PhotoAssetChangeInfos>): void
Registers a listener for the **'trashedPhotoChange'** event to monitor media asset changes in the trash. This API uses a callback to return the result, and it accepts multiple callbacks.
**System API**: This is a system API.
**System capability**: SystemCapability.FileManagement.PhotoAccessHelper.Core
**Required permissions**: ohos.permission.READ_IMAGEVIDEO
**Parameters**
| Name | Type | Mandatory| Description |
|-----------|-------------------------|-----------|-----------------|
| type | string | Yes | Event type. The value is fixed at **'trashedPhotoChange'**. After the registration is complete, any change to the trashed media assets is returned through the callback.|
| callback | Callback<[PhotoAssetChangeInfos](arkts-apis-photoAccessHelper-i.md#photoassetchangeinfos20)> | Yes | Callback used to return the trashed media asset information after change, which is [PhotoAssetChangeInfos](arkts-apis-photoAccessHelper-i.md#photoassetchangeinfos20).
**NOTE**: You can register multiple listeners using this API, and you can call [off('hiddenPhotoChange')](#offhiddenphotochange20) to unregister all listeners or a specific one.|
**Error codes**
For details about the error codes, see [Universal Error Codes](../errorcode-universal.md) and [Media Library Error Codes](errcode-medialibrary.md).
| ID| Error Message|
| -------- | ---------------------------------------- |
| 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. |
**Example**
For details about how to create a phAccessHelper instance, see the example provided in [@ohos.file.photoAccessHelper (Album Management)](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 {
// Register onCallback1.
phAccessHelper.on('trashedPhotoChange', onCallback1);
// Register onCallback2.
phAccessHelper.on('trashedPhotoChange', onCallback2);
} catch (error) {
console.error('onTrashedPhotoChangeDemo failed, errCode is', error);
}
}
```
### off('trashedPhotoChange')20+
off(type: 'trashedPhotoChange', callback?: Callback<PhotoAssetChangeInfos>): void
Unregisters a listener for the **'trashedPhotoChange'** event to stop monitoring media asset changes in the trash. If multiple listeners are registered, you can unregister a specific listener by specifying **callback**. Alternatively, you can unregister all of them without specifying **callback**.
**System API**: This is a system API.
**System capability**: SystemCapability.FileManagement.PhotoAccessHelper.Core
**Required permissions**: ohos.permission.READ_IMAGEVIDEO
**Parameters**
| Name | Type | Mandatory| Description |
|-----------|-------------------------|-----------|-----------------|
| type | string | Yes | Event type. The value is fixed at **'trashedPhotoChange'**. After the unregistration is complete, any change to the trashed media assets is no longer returned through the callback.|
| callback | Callback<[PhotoAssetChangeInfos](arkts-apis-photoAccessHelper-i.md#photoassetchangeinfos20)> | No | Exact callback you previously registered with [on('trashedPhotoChange')](#ontrashedphotochange20). If this parameter is left unspecified, all listeners for the **'trashedPhotoChange'** event are unregistered.
**NOTE**: Once a specific callback is unregistered, it will not be invoked when a trashed media asset changes.|
**Error codes**
For details about the error codes, see [Universal Error Codes](../errorcode-universal.md) and [Media Library Error Codes](errcode-medialibrary.md).
| ID| Error Message|
| -------- | ---------------------------------------- |
| 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. |
**Example**
For details about how to create a phAccessHelper instance, see the example provided in [@ohos.file.photoAccessHelper (Album Management)](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 {
// Register onCallback1.
phAccessHelper.on('trashedPhotoChange', onCallback1);
// Register onCallback2.
phAccessHelper.on('trashedPhotoChange', onCallback2);
// Unregister the listening of onCallback1.
phAccessHelper.off('trashedPhotoChange', onCallback1);
} catch (error) {
console.error('offTrashedPhotoChangeDemo failed, errCode is', error);
}
}
```
### on('hiddenAlbumChange')20+
on(type: 'hiddenAlbumChange', callback: Callback<AlbumChangeInfos>): void
Registers a listener for the **'hiddenAlbumChange'** event to monitor hidden album changes. This API uses a callback to return the result, and it accepts multiple callbacks.
**System API**: This is a system API.
**System capability**: SystemCapability.FileManagement.PhotoAccessHelper.Core
**Required permissions**: ohos.permission.READ_IMAGEVIDEO and ohos.permission.MANAGE_PRIVATE_PHOTOS
**Parameters**
| Name | Type | Mandatory| Description |
|-----------|-------------------------|-----------|-----------------|
| type | string | Yes | Event type. The value is fixed at **'hiddenAlbumChange'**. After the registration is complete, any change to the hidden albums is returned through the callback.|
| callback | Callback<[AlbumChangeInfos](arkts-apis-photoAccessHelper-i.md#albumchangeinfos20)> | Yes | Callback used to return the hidden album information after change, which is [AlbumChangeInfos](arkts-apis-photoAccessHelper-i.md#albumchangeinfos20).
**NOTE**: You can register multiple listeners using this API, and you can call [off('hiddenAlbumChange')](#offhiddenalbumchange20) to unregister all listeners or a specific one.|
**Error codes**
For details about the error codes, see [Universal Error Codes](../errorcode-universal.md) and [Media Library Error Codes](errcode-medialibrary.md).
| ID| Error Message|
| -------- | ---------------------------------------- |
| 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. |
**Example**
For details about how to create a phAccessHelper instance, see the example provided in [@ohos.file.photoAccessHelper (Album Management)](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 {
// Register onCallback1.
phAccessHelper.on('hiddenAlbumChange', onCallback1);
// Register onCallback2.
phAccessHelper.on('hiddenAlbumChange', onCallback2);
} catch (error) {
console.error('onHiddenAlbumChangeDemo failed, errCode is', error);
}
}
```
### off('hiddenAlbumChange')20+
off(type: 'hiddenAlbumChange', callback?: Callback<AlbumChangeInfos>): void
Unregisters a listener for the **'hiddenAlbumChange'** event to stop monitoring hidden album changes. If multiple listeners are registered, you can unregister a specific listener by specifying **callback**. Alternatively, you can unregister all of them without specifying **callback**.
**System API**: This is a system API.
**System capability**: SystemCapability.FileManagement.PhotoAccessHelper.Core
**Required permissions**: ohos.permission.READ_IMAGEVIDEO and ohos.permission.MANAGE_PRIVATE_PHOTOS
**Parameters**
| Name | Type | Mandatory| Description |
|-----------|-------------------------|-----------|-----------------|
| type | string | Yes | Event type. The value is fixed at **'hiddenAlbumChange'**. After the unregistration is complete, any change to the hidden albums is no longer returned through the callback.|
| callback | Callback<[AlbumChangeInfos](arkts-apis-photoAccessHelper-i.md#albumchangeinfos20)> | No | Exact callback you previously registered with [on('hiddenAlbumChange')](#onhiddenalbumchange20). If this parameter is left unspecified, all listeners for the **'hiddenAlbumChange'** event are unregistered.
**NOTE**: Once a specific callback is unregistered, it will not be invoked when a hidden album changes.|
**Error codes**
For details about the error codes, see [Universal Error Codes](../errorcode-universal.md) and [Media Library Error Codes](errcode-medialibrary.md).
| ID| Error Message|
| -------- | ---------------------------------------- |
| 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. |
**Example**
For details about how to create a phAccessHelper instance, see the example provided in [@ohos.file.photoAccessHelper (Album Management)](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 {
// Register onCallback1.
phAccessHelper.on('hiddenAlbumChange', onCallback1);
// Register onCallback2.
phAccessHelper.on('hiddenAlbumChange', onCallback2);
// Unregister the listening of onCallback1.
phAccessHelper.off('hiddenAlbumChange', onCallback1);
} catch (error) {
console.error('onHiddenAlbumChangeDemo failed, errCode is', error);
}
}
```
### on('trashedAlbumChange')20+
on(type: 'trashedAlbumChange', callback: Callback<AlbumChangeInfos>): void
Registers a listener for the **'trashedAlbumChange'** event to monitor album changes in the trash. This API uses a callback to return the result, and it accepts multiple callbacks.
**System API**: This is a system API.
**System capability**: SystemCapability.FileManagement.PhotoAccessHelper.Core
**Required permissions**: ohos.permission.READ_IMAGEVIDEO
**Parameters**
| Name | Type | Mandatory| Description |
|-----------|-------------------------|-----------|-----------------|
| type | string | Yes | Event type. The value is fixed at **'trashedAlbumChange'**. After the registration is complete, any change to the trashed albums is returned through the callback.|
| callback | Callback<[AlbumChangeInfos](arkts-apis-photoAccessHelper-i.md#albumchangeinfos20)> | Yes | Callback used to return the trashed album information after change, which is [AlbumChangeInfos](arkts-apis-photoAccessHelper-i.md#albumchangeinfos20).
**NOTE**: You can register multiple listeners using this API, and you can call [off('trashedAlbumChange')](#offtrashedalbumchange20) to unregister all listeners or a specific one.|
**Error codes**
For details about the error codes, see [Universal Error Codes](../errorcode-universal.md) and [Media Library Error Codes](errcode-medialibrary.md).
| ID| Error Message|
| -------- | ---------------------------------------- |
| 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. |
**Example**
For details about how to create a phAccessHelper instance, see the example provided in [@ohos.file.photoAccessHelper (Album Management)](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 {
// Register onCallback1.
phAccessHelper.on('trashedAlbumChange', onCallback1);
// Register onCallback2.
phAccessHelper.on('trashedAlbumChange', onCallback2);
} catch (error) {
console.error('onTrashedAlbumChangeDemo failed, errCode is', error);
}
}
```
### off('trashedAlbumChange')20+
off(type: 'trashedAlbumChange', callback?: Callback<AlbumChangeInfos>): void
Unregisters a listener for the **'trashedAlbumChange'** event to stop monitoring album changes in the trash. If multiple listeners are registered, you can unregister a specific listener by specifying **callback**. Alternatively, you can unregister all of them without specifying **callback**.
**System API**: This is a system API.
**System capability**: SystemCapability.FileManagement.PhotoAccessHelper.Core
**Required permissions**: ohos.permission.READ_IMAGEVIDEO
**Parameters**
| Name | Type | Mandatory| Description |
|-----------|-------------------------|-----------|-----------------|
| type | string | Yes | Event type. The value is fixed at **'trashedAlbumChange'**. After the unregistration is complete, any change to the trashed albums is no longer returned through the callback.|
| callback | Callback<[AlbumChangeInfos](arkts-apis-photoAccessHelper-i.md#albumchangeinfos20)> | No | Exact callback you previously registered with [on('trashedAlbumChange')](#ontrashedalbumchange20). If this parameter is left unspecified, all listeners for the **'trashedAlbumChange'** event are unregistered.
**NOTE**: Once a specific callback is unregistered, it will not be invoked when an album in the trash changes.|
**Error codes**
For details about the error codes, see [Universal Error Codes](../errorcode-universal.md) and [Media Library Error Codes](errcode-medialibrary.md).
| ID| Error Message|
| -------- | ---------------------------------------- |
| 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. |
**Example**
For details about how to create a phAccessHelper instance, see the example provided in [@ohos.file.photoAccessHelper (Album Management)](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 {
// Register onCallback1.
phAccessHelper.on('trashedAlbumChange', onCallback1);
// Register onCallback2.
phAccessHelper.on('trashedAlbumChange', onCallback2);
// Unregister the listening of onCallback1.
phAccessHelper.off('trashedAlbumChange', onCallback1);
} catch (error) {
console.error('onTrashedAlbumChangeDemo failed, errCode is', error);
}
}
```
### getPhotoAlbums20+
getPhotoAlbums(options?: FetchOptions): Promise<FetchResult<Album>>
Obtains system, user, and source albums based on the specified options. This API uses a promise to return the result.
Before the operation, ensure that the albums to obtain exist.
**System API**: This is a system API.
**Required permissions**: ohos.permission.READ_IMAGEVIDEO
**System capability**: SystemCapability.FileManagement.PhotoAccessHelper.Core
**Parameters**
| Name | Type | Mandatory| Description |
| --------- | ------------------- | ---- | ------------------------------------------------------------ |
| options | [FetchOptions](arkts-apis-photoAccessHelper-i.md#fetchoptions) | No | Retrieval options. If this parameter is not specified, the albums are obtained based on the album type by default. |
**Return value**
| Type | Description |
| --------------------- | --------------------------- |
| Promise<[FetchResult](arkts-apis-photoAccessHelper-FetchResult.md)<[Album](#album)>> | Promise used to return the result.|
**Error codes**
For details about the error codes, see [Universal Error Codes](../errorcode-universal.md) and [Media Library Error Codes](errcode-medialibrary.md).
| ID| Error Message |
| -------- | ------------------------------------------------------------ |
| 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. |
**Example**
For details about how to create a phAccessHelper instance, see the example provided in [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>>
Obtains the sorting order for system, user, and source albums. This API uses a promise to return the result.
**System API**: This is a system API.
**Required permissions**: ohos.permission.READ_IMAGEVIDEO
**System capability**: SystemCapability.FileManagement.PhotoAccessHelper.Core
**Parameters**
| Name | Type | Mandatory| Description |
| --------- | ------------------- | ---- | ------------------------------------------------------------ |
| orderStyle | number | Yes | Sorting style for albums.
The value **0** means the phone style, and **1** means the PC style. |
| options | [FetchOptions](arkts-apis-photoAccessHelper-i.md#fetchoptions) | No | Retrieval options. If this parameter is not specified, the albums are obtained based on the album type by default. |
**Return value**
| Type | Description |
| --------------------- | --------------------------- |
| Promise<[FetchResult](arkts-apis-photoAccessHelper-FetchResult.md)<[AlbumOrder](#albumorder20)>> | Promise used to return the sorting order.|
**Error codes**
For details about the error codes, see [Universal Error Codes](../errorcode-universal.md) and [Media Library Error Codes](errcode-medialibrary.md).
| ID| Error Message |
| -------- | ------------------------------------------------------------ |
| 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. |
**Example**
For details about how to create a phAccessHelper instance, see the example provided in [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>
Sets the sorting order for system, user, and source albums. This API uses a promise to return the result.
**System API**: This is a system API.
**Required permissions**: ohos.permission.WRITE_IMAGEVIDEO
**System capability**: SystemCapability.FileManagement.PhotoAccessHelper.Core
**Parameters**
| Name | Type | Mandatory| Description |
| --------- | ------------------- | ---- | ------------------------------------------------------------ |
| orderStyle | number | Yes | Sorting style for albums.
The value **0** means the phone style, and **1** means the PC style. |
| albumOrders | Array<[AlbumOrder](#albumorder20)> | Yes | Array of album sorting orders.|
**Return value**
| Type | Description |
| --------------------- | --------------------------- |
| Promise<void>| Promise that returns no value.|
**Error codes**
For details about the error codes, see [Universal Error Codes](../errorcode-universal.md) and [Media Library Error Codes](errcode-medialibrary.md).
| ID| Error Message |
| -------- | ------------------------------------------------------------ |
| 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. |
**Example**
For details about how to create a phAccessHelper instance, see the example provided in [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
Provides APIs for encapsulating file asset attributes.
### open(deprecated)
open(mode: string, callback: AsyncCallback<number>): void
Opens this file asset. This API uses an asynchronous callback to return the result.
> **NOTE**
>
> This API is supported since API version 10 and deprecated since API version 11. For security purposes, the API for obtaining the media file handle is no longer provided.
**NOTE**: A file can be opened in only one mode at a time. Use **close()** to close the FD returned when it is not required.
**System API**: This is a system API.
**Required permissions**: ohos.permission.READ_IMAGEVIDEO or ohos.permission.WRITE_IMAGEVIDEO
**System capability**: SystemCapability.FileManagement.PhotoAccessHelper.Core
**Parameters**
| Name | Type | Mandatory | Description |
| -------- | --------------------------- | ---- | ----------------------------------- |
| mode | string | Yes | Mode for opening the file, which can be **'r'** (read-only), **'w'** (write-only), or **'rw'** (read/write).|
| callback | AsyncCallback<number> | Yes | Callback used to return the file descriptor (FD) of the file opened. |
**Error codes**
For details about the error codes, see [Universal Error Codes](../errorcode-universal.md) and [File Management Error Codes](../apis-core-file-kit/errorcode-filemanagement.md).
If error code 13900012 is returned, follow the instructions provided in [Before You Start](../../media/medialibrary/photoAccessHelper-preparation.md).
| ID| Error Message|
| -------- | ---------------------------------------- |
| 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. |
**Example**
For details about how to create a phAccessHelper instance, see the example provided in [@ohos.file.photoAccessHelper (Album Management)](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>
Opens this file asset. This API uses a promise to return the result.
> **NOTE**
>
> This API is supported since API version 10 and deprecated since API version 11. For security purposes, the API for obtaining the media file handle is no longer provided.
**NOTE**: A file can be opened in only one mode at a time. Use **close()** to close the FD returned when it is not required.
**System API**: This is a system API.
**Required permissions**: ohos.permission.READ_IMAGEVIDEO or ohos.permission.WRITE_IMAGEVIDEO
**System capability**: SystemCapability.FileManagement.PhotoAccessHelper.Core
**Parameters**
| Name | Type | Mandatory | Description |
| ---- | ------ | ---- | ----------------------------------- |
| mode | string | Yes | Mode for opening the file, which can be **'r'** (read-only), **'w'** (write-only), or **'rw'** (read/write).|
**Return value**
| Type | Description |
| --------------------- | ------------- |
| Promise<number> | Promise used to return the FD of the file opened.|
**Error codes**
For details about the error codes, see [Universal Error Codes](../errorcode-universal.md) and [File Management Error Codes](../apis-core-file-kit/errorcode-filemanagement.md).
If error code 13900012 is returned, follow the instructions provided in [Before You Start](../../media/medialibrary/photoAccessHelper-preparation.md).
| ID| Error Message|
| -------- | ---------------------------------------- |
| 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. |
**Example**
For details about how to create a phAccessHelper instance, see the example provided in [@ohos.file.photoAccessHelper (Album Management)](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
Favorites or unfavorites this file. This API uses an asynchronous callback to return the result.
> **NOTE**
>
> This API is supported since API version 10 and deprecated since API version 11. Use [MediaAssetChangeRequest.setFavorite](#setfavorite11) instead.
**System API**: This is a system API.
**Required permissions**: ohos.permission.WRITE_IMAGEVIDEO
**System capability**: SystemCapability.FileManagement.PhotoAccessHelper.Core
**Parameters**
| Name | Type | Mandatory | Description |
| ---------- | ------------------------- | ---- | ---------------------------------- |
| favoriteState | boolean | Yes | Whether to favorite the file asset. **true** to favorite, **false** otherwise.|
| callback | AsyncCallback<void> | Yes | Callback that returns no value. |
**Error codes**
For details about the error codes, see [Universal Error Codes](../errorcode-universal.md) and [File Management Error Codes](../apis-core-file-kit/errorcode-filemanagement.md).
If error code 201 is returned, follow the instructions provided in [Before You Start](../../media/medialibrary/photoAccessHelper-preparation.md).
| ID| Error Message|
| -------- | ---------------------------------------- |
| 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. |
**Example**
For details about how to create a phAccessHelper instance, see the example provided in [@ohos.file.photoAccessHelper (Album Management)](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>
Favorites or unfavorites this file asset. This API uses a promise to return the result.
> **NOTE**
>
> This API is supported since API version 10 and deprecated since API version 11. Use [MediaAssetChangeRequest.setFavorite](#setfavorite11) instead.
**System API**: This is a system API.
**Required permissions**: ohos.permission.WRITE_IMAGEVIDEO
**System capability**: SystemCapability.FileManagement.PhotoAccessHelper.Core
**Parameters**
| Name | Type | Mandatory | Description |
| ---------- | ------- | ---- | ---------------------------------- |
| favoriteState | boolean | Yes | Whether to favorite the file asset. **true** to favorite, **false** otherwise.|
**Return value**
| Type | Description |
| ------------------- | ---------- |
| Promise<void> | Promise that returns no value.|
**Error codes**
For details about the error codes, see [Universal Error Codes](../errorcode-universal.md) and [File Management Error Codes](../apis-core-file-kit/errorcode-filemanagement.md).
If error code 201 is returned, follow the instructions provided in [Before You Start](../../media/medialibrary/photoAccessHelper-preparation.md).
| ID| Error Message|
| -------- | ---------------------------------------- |
| 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. |
**Example**
For details about how to create a phAccessHelper instance, see the example provided in [@ohos.file.photoAccessHelper (Album Management)](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
Sets this file to hidden state. This API uses an asynchronous callback to return the result.
Private files are stored in the private album. After obtaining private files from the private album, users can set **hiddenState** to **false** to remove them from the private album.
> **NOTE**
>
> This API is supported since API version 10 and deprecated since API version 11. Use [MediaAssetChangeRequest.setHidden](#sethidden11) instead.
**System API**: This is a system API.
**Required permissions**: ohos.permission.WRITE_IMAGEVIDEO
**System capability**: SystemCapability.FileManagement.PhotoAccessHelper.Core
**Parameters**
| Name | Type | Mandatory | Description |
| ---------- | ------------------------- | ---- | ---------------------------------- |
| hiddenState | boolean | Yes | Whether to set a file to hidden state. **true** to hide, **false** otherwise.|
| callback | AsyncCallback<void> | Yes | Callback that returns no value. |
**Error codes**
For details about the error codes, see [Universal Error Codes](../errorcode-universal.md) and [File Management Error Codes](../apis-core-file-kit/errorcode-filemanagement.md).
If error code 201 is returned, follow the instructions provided in [Before You Start](../../media/medialibrary/photoAccessHelper-preparation.md).
| ID| Error Message|
| -------- | ---------------------------------------- |
| 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. |
**Example**
For details about how to create a phAccessHelper instance, see the example provided in [@ohos.file.photoAccessHelper (Album Management)](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>
Sets this file asset to hidden state. This API uses a promise to return the result.
Private files are stored in the private album. After obtaining private files from the private album, users can set **hiddenState** to **false** to remove them from the private album.
> **NOTE**
>
> This API is supported since API version 10 and deprecated since API version 11. Use [MediaAssetChangeRequest.setHidden](#sethidden11) instead.
**System API**: This is a system API.
**Required permissions**: ohos.permission.WRITE_IMAGEVIDEO
**System capability**: SystemCapability.FileManagement.PhotoAccessHelper.Core
**Parameters**
| Name | Type | Mandatory | Description |
| ---------- | ------- | ---- | ---------------------------------- |
| hiddenState | boolean | Yes | Whether to set a file to hidden state. **true** to hide, **false** otherwise.|
**Return value**
| Type | Description |
| ------------------- | ---------- |
| Promise<void> | Promise that returns no value.|
**Error codes**
For details about the error codes, see [Universal Error Codes](../errorcode-universal.md) and [File Management Error Codes](../apis-core-file-kit/errorcode-filemanagement.md).
If error code 201 is returned, follow the instructions provided in [Before You Start](../../media/medialibrary/photoAccessHelper-preparation.md).
| ID| Error Message|
| -------- | ---------------------------------------- |
| 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. |
**Example**
For details about how to create a phAccessHelper instance, see the example provided in [@ohos.file.photoAccessHelper (Album Management)](arkts-apis-photoAccessHelper-f.md).
```ts
import { dataSharePredicates } from '@kit.ArkData';
import { BusinessError } from '@kit.BasicServicesKit';
async function example(phAccessHelper: photoAccessHelper.PhotoAccessHelper) {
// Restore a file from a hidden album. Before the operation, ensure that the file exists in the hidden album.
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>
Obtains the exchangeable image file format (EXIF) data from a JPG image. This API uses a promise to return the result.
The EXIF information obtained are provided by the [image](../apis-image-kit/arkts-apis-image.md) module. For details about the EXIF information, see [image.PropertyKey](../apis-image-kit/arkts-apis-image-e.md#propertykey7).
**NOTE**: This API returns a JSON string consisting of EXIF tags. The complete EXIF information consists of **all_exif** and [PhotoKeys.USER_COMMENT](#photokeys). These two fields must be passed in via **fetchColumns**.
**System API**: This is a system API.
**Required permissions**: ohos.permission.READ_IMAGEVIDEO
**System capability**: SystemCapability.FileManagement.PhotoAccessHelper.Core
**Return value**
| Type | Description |
| --------------------------------------- | ----------------- |
| Promise<string> | Promise used to return the EXIF data, in JSON strings.|
**Error codes**
For details about the error codes, see [Universal Error Codes](../errorcode-universal.md) and [File Management Error Codes](../apis-core-file-kit/errorcode-filemanagement.md).
If error code 13900012 is returned, follow the instructions provided in [Before You Start](../../media/medialibrary/photoAccessHelper-preparation.md).
| ID| Error Message|
| -------- | ---------------------------------------- |
| 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. |
**Example**
For details about how to create a phAccessHelper instance, see the example provided in [@ohos.file.photoAccessHelper (Album Management)](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
Obtains the exchangeable image file format (EXIF) data from a JPG image. This API uses an asynchronous callback to return the result.
The EXIF information obtained are provided by the [image](../apis-image-kit/arkts-apis-image.md) module. For details about the EXIF information, see [image.PropertyKey](../apis-image-kit/arkts-apis-image-e.md#propertykey7).
**NOTE**: This API returns a JSON string consisting of EXIF tags. The complete EXIF information consists of **all_exif** and [PhotoKeys.USER_COMMENT](#photokeys). These two fields must be passed in via **fetchColumns**.
**System API**: This is a system API.
**Required permissions**: ohos.permission.READ_IMAGEVIDEO
**System capability**: SystemCapability.FileManagement.PhotoAccessHelper.Core
**Parameters**
| Name | Type | Mandatory| Description |
| -------- | ------------------------- | ---- | ---------- |
| callback | AsyncCallback<string> | Yes | Callback used to return the EXIF data, in JSON strings.|
**Error codes**
For details about the error codes, see [Universal Error Codes](../errorcode-universal.md) and [File Management Error Codes](../apis-core-file-kit/errorcode-filemanagement.md).
If error code 13900012 is returned, follow the instructions provided in [Before You Start](../../media/medialibrary/photoAccessHelper-preparation.md).
| ID| Error Message|
| -------- | ---------------------------------------- |
| 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. |
**Example**
For details about how to create a phAccessHelper instance, see the example provided in [@ohos.file.photoAccessHelper (Album Management)](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>
Sets user comment information of an image or video. This API uses a promise to return the result.
> **NOTE**
>
> This API is supported since API version 10 and deprecated since API version 11. Use [MediaAssetChangeRequest.setUserComment](#setusercomment11) instead.
**NOTE**: This API can be used to modify the comment information of only images or videos.
**System API**: This is a system API.
**Required permissions**: ohos.permission.WRITE_IMAGEVIDEO
**System capability**: SystemCapability.FileManagement.PhotoAccessHelper.Core
**Parameters**
| Name | Type | Mandatory| Description |
| -------- | ------------------------- | ---- | ---------- |
| userComment | string | Yes | User comment information to set, which cannot exceed 420 characters.|
**Return value**
| Type | Description |
| --------------------------------------- | ----------------- |
|Promise<void> | Promise that returns no value.|
**Error codes**
For details about the error codes, see [Universal Error Codes](../errorcode-universal.md) and [File Management Error Codes](../apis-core-file-kit/errorcode-filemanagement.md).
If error code 201 is returned, follow the instructions provided in [Before You Start](../../media/medialibrary/photoAccessHelper-preparation.md).
| ID| Error Message|
| -------- | ---------------------------------------- |
| 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. |
**Example**
For details about how to create a phAccessHelper instance, see the example provided in [@ohos.file.photoAccessHelper (Album Management)](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
Sets user comment information of an image or video. This API uses an asynchronous callback to return the result.
> **NOTE**
>
> This API is supported since API version 10 and deprecated since API version 11. Use [MediaAssetChangeRequest.setUserComment](#setusercomment11) instead.
**NOTE**: This API can be used to modify the comment information of only images or videos.
**System API**: This is a system API.
**Required permissions**: ohos.permission.WRITE_IMAGEVIDEO
**System capability**: SystemCapability.FileManagement.PhotoAccessHelper.Core
**Parameters**
| Name | Type | Mandatory| Description |
| -------- | ------------------------- | ---- | ---------- |
| userComment | string | Yes | User comment information to set, which cannot exceed 420 characters.|
| callback | AsyncCallback<void> | Yes | Callback that returns no value.|
**Error codes**
For details about the error codes, see [Universal Error Codes](../errorcode-universal.md) and [File Management Error Codes](../apis-core-file-kit/errorcode-filemanagement.md).
If error code 201 is returned, follow the instructions provided in [Before You Start](../../media/medialibrary/photoAccessHelper-preparation.md).
| ID| Error Message|
| -------- | ---------------------------------------- |
| 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. |
**Example**
For details about how to create a phAccessHelper instance, see the example provided in [@ohos.file.photoAccessHelper (Album Management)](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
Sets the pending state for this image or video asset. This API uses an asynchronous callback to return the result.
The pending state can be removed only through **setPending(false)**. You can use **photoAsset.get(photoAccessHelper.PhotoKeys.PENDING)** to check whether the asset state is pending. If the asset is in pending state, **true** is returned. Otherwise, **false** is returned.
**NOTE**: **setPending** can be used only during the file creation process. Once the FD is closed, **setPending(true)** cannot be used to set the pending state for the file.
**System API**: This is a system API.
**Required permissions**: ohos.permission.WRITE_IMAGEVIDEO
**System capability**: SystemCapability.FileManagement.PhotoAccessHelper.Core
**Parameters**
| Name | Type | Mandatory | Description |
| ---------- | ------- | ---- | ---------------------------------- |
| pendingState | boolean | Yes | Whether to set the file to pending state. **true** to pend, **false** otherwise.|
| callback | AsyncCallback<void> | Yes | Callback that returns no value.|
**Error codes**
For details about the error codes, see [Universal Error Codes](../errorcode-universal.md) and [File Management Error Codes](../apis-core-file-kit/errorcode-filemanagement.md).
| ID| Error Message|
| -------- | ---------------------------------------- |
| 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. |
**Example**
For details about how to create a phAccessHelper instance, see the example provided in [@ohos.file.photoAccessHelper (Album Management)](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>
Sets the pending state for this image or video asset. This API uses a promise to return the result.
The pending state can be removed only through **setPending(false)**. You can use **photoAsset.get(photoAccessHelper.PhotoKeys.PENDING)** to check whether the asset state is pending. If the asset is in pending state, **true** is returned. Otherwise, **false** is returned.
**NOTE**: **setPending** can be used only during the file creation process. Once the FD is closed, **setPending(true)** cannot be used to set the pending state for the file.
**System API**: This is a system API.
**Required permissions**: ohos.permission.WRITE_IMAGEVIDEO
**System capability**: SystemCapability.FileManagement.PhotoAccessHelper.Core
**Parameters**
| Name | Type | Mandatory | Description |
| ---------- | ------- | ---- | ---------------------------------- |
| pendingState | boolean | Yes | Whether to set the file to pending state. **true** to pend, **false** otherwise.|
**Return value**
| Type | Description |
| --------------------------------------- | ----------------- |
|Promise<boolean> | Promise that returns no value.|
**Error codes**
For details about the error codes, see [Universal Error Codes](../errorcode-universal.md) and [File Management Error Codes](../apis-core-file-kit/errorcode-filemanagement.md).
| ID| Error Message|
| -------- | ---------------------------------------- |
| 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. |
**Example**
For details about how to create a phAccessHelper instance, see the example provided in [@ohos.file.photoAccessHelper (Album Management)](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
Checks whether this image or video asset is edited. This API uses an asynchronous callback to return the result.
**System API**: This is a system API.
**Required permissions**: ohos.permission.READ_IMAGEVIDEO
**System capability**: SystemCapability.FileManagement.PhotoAccessHelper.Core
**Parameters**
| Name | Type | Mandatory | Description |
| ---------- | ------- | ---- | ---------------------------------- |
| callback | AsyncCallback<boolean> | Yes | Callback used to return the result indicating whether the image or video asset is edited. **true** if edited, **false** otherwise. The default value is **false**.|
**Error codes**
For details about the error codes, see [Universal Error Codes](../errorcode-universal.md) and [File Management Error Codes](../apis-core-file-kit/errorcode-filemanagement.md).
| ID| Error Message|
| -------- | ---------------------------------------- |
| 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. |
**Example**
For details about how to create a phAccessHelper instance, see the example provided in [@ohos.file.photoAccessHelper (Album Management)](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>
Checks whether this image or video asset is edited. This API uses a promise to return the result.
**System API**: This is a system API.
**Required permissions**: ohos.permission.READ_IMAGEVIDEO
**System capability**: SystemCapability.FileManagement.PhotoAccessHelper.Core
**Return value**
| Type | Description |
| --------------------------------------- | ----------------- |
|Promise<boolean> | Promise used to return the result indicating whether the image or video asset is edited. **true** if edited, **false** otherwise. The default value is **false**.|
**Error codes**
For details about the error codes, see [Universal Error Codes](../errorcode-universal.md) and [File Management Error Codes](../apis-core-file-kit/errorcode-filemanagement.md).
| ID| Error Message|
| -------- | ---------------------------------------- |
| 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. |
**Example**
For details about how to create a phAccessHelper instance, see the example provided in [@ohos.file.photoAccessHelper (Album Management)](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
Obtains the edit data of this image or video asset. This API uses an asynchronous callback to return the result.
If the asset has never been edited, an empty string is returned.
**System API**: This is a system API.
**Required permissions**: ohos.permission.READ_IMAGEVIDEO
**System capability**: SystemCapability.FileManagement.PhotoAccessHelper.Core
**Parameters**
| Name | Type | Mandatory | Description |
| ---------- | ------- | ---- | ---------------------------------- |
| callback | AsyncCallback<string> | Yes | Callback used to return the edit data obtained.|
**Error codes**
For details about the error codes, see [Universal Error Codes](../errorcode-universal.md) and [File Management Error Codes](../apis-core-file-kit/errorcode-filemanagement.md).
| ID| Error Message|
| -------- | ---------------------------------------- |
| 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. |
**Example**
For details about how to create a phAccessHelper instance, see the example provided in [@ohos.file.photoAccessHelper (Album Management)](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>
Obtains the edit data of this image or video asset. This API uses a promise to return the result.
If the asset has never been edited, an empty string is returned.
**System API**: This is a system API.
**Required permissions**: ohos.permission.READ_IMAGEVIDEO
**System capability**: SystemCapability.FileManagement.PhotoAccessHelper.Core
**Return value**
| Type | Description |
| --------------------------------------- | ----------------- |
|Promise<string> | Promise used to return the edit data obtained.|
**Error codes**
For details about the error codes, see [Universal Error Codes](../errorcode-universal.md) and [File Management Error Codes](../apis-core-file-kit/errorcode-filemanagement.md).
| ID| Error Message|
| -------- | ---------------------------------------- |
| 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. |
**Example**
For details about how to create a phAccessHelper instance, see the example provided in [@ohos.file.photoAccessHelper (Album Management)](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>
Obtains the edited data of this asset. This API uses a promise to return the result.
If the asset has never been edited, an empty string is returned.
**System API**: This is a system API.
**Required permissions**: ohos.permission.READ_IMAGEVIDEO
**System capability**: SystemCapability.FileManagement.PhotoAccessHelper.Core
**Return value**
| Type | Description |
| --------------------------------------- | ----------------- |
|Promise<[MediaAssetEditData](#mediaasseteditdata11)> | Promise used to return the edited asset data.|
**Error codes**
For details about the error codes, see [Universal Error Codes](../errorcode-universal.md) and [File Management Error Codes](../apis-core-file-kit/errorcode-filemanagement.md).
| ID| Error Message|
| -------- | ---------------------------------------- |
| 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. |
**Example**
For details about how to create a phAccessHelper instance, see the example provided in [@ohos.file.photoAccessHelper (Album Management)](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
Opens the source file to obtain the FD. This API uses an asynchronous callback to return the result.
**System API**: This is a system API.
**Required permissions**: ohos.permission.READ_IMAGEVIDEO
**System capability**: SystemCapability.FileManagement.PhotoAccessHelper.Core
**Parameters**
| Name | Type | Mandatory | Description |
| ---------- | ------- | ---- | ---------------------------------- |
| callback | AsyncCallback<number> | Yes | Callback used to return the FD.|
**Error codes**
For details about the error codes, see [Universal Error Codes](../errorcode-universal.md) and [File Management Error Codes](../apis-core-file-kit/errorcode-filemanagement.md).
| ID| Error Message|
| -------- | ---------------------------------------- |
| 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. |
**Example**
For details about how to create a phAccessHelper instance, see the example provided in [@ohos.file.photoAccessHelper (Album Management)](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>
Opens the source file to obtain the FD. This API uses a promise to return the result.
**System API**: This is a system API.
**Required permissions**: ohos.permission.READ_IMAGEVIDEO
**System capability**: SystemCapability.FileManagement.PhotoAccessHelper.Core
**Return value**
| Type | Description |
| --------------------------------------- | ----------------- |
|Promise<number> | Promise used to return the FD.|
**Error codes**
For details about the error codes, see [Universal Error Codes](../errorcode-universal.md) and [File Management Error Codes](../apis-core-file-kit/errorcode-filemanagement.md).
| ID| Error Message|
| -------- | ---------------------------------------- |
| 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. |
**Example**
For details about how to create a phAccessHelper instance, see the example provided in [@ohos.file.photoAccessHelper (Album Management)](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>)
Commits the edited image or video asset. This API uses an asynchronous callback to return the result.
The edited file is transferred to the media library based on the URI, which is **FileUri** of the edited file in the application sandbox directory. For details, see [File URI](../apis-core-file-kit/js-apis-file-fileuri.md).
**NOTE**: The commit operation overwrites the previous edited data.
**System API**: This is a system API.
**Required permissions**: ohos.permission.WRITE_IMAGEVIDEO
**System capability**: SystemCapability.FileManagement.PhotoAccessHelper.Core
**Parameters**
| Name | Type | Mandatory | Description |
| ---------- | ------- | ---- | ---------------------------------- |
| editData | string | Yes | New data to commit.|
| uri | string | Yes | URI of the committed image or video in the application sandbox.|
| callback | AsyncCallback<void> | Yes | Callback that returns no value.|
**Error codes**
For details about the error codes, see [Universal Error Codes](../errorcode-universal.md) and [File Management Error Codes](../apis-core-file-kit/errorcode-filemanagement.md).
| ID| Error Message|
| -------- | ---------------------------------------- |
| 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. |
**Example**
For details about how to create a phAccessHelper instance, see the example provided in [@ohos.file.photoAccessHelper (Album Management)](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>
Commits the edited image or video asset. This API uses a promise to return the result.
The edited file is transferred to the media library based on the URI, which is **FileUri** of the edited file in the application sandbox directory. For details, see [File URI](../apis-core-file-kit/js-apis-file-fileuri.md).
**NOTE**: The commit operation overwrites the previous edited data.
**System API**: This is a system API.
**Required permissions**: ohos.permission.WRITE_IMAGEVIDEO
**System capability**: SystemCapability.FileManagement.PhotoAccessHelper.Core
**Parameters**
| Name | Type | Mandatory | Description |
| ---------- | ------- | ---- | ---------------------------------- |
| editData | string | Yes | New data to commit.|
| uri | string | Yes | URI of the committed image or video in the application sandbox.|
**Return value**
| Type | Description |
| --------------------------------------- | ----------------- |
|Promise<void> | Promise that returns no value.|
**Error codes**
For details about the error codes, see [Universal Error Codes](../errorcode-universal.md) and [File Management Error Codes](../apis-core-file-kit/errorcode-filemanagement.md).
| ID| Error Message|
| -------- | ---------------------------------------- |
| 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. |
**Example**
For details about how to create a phAccessHelper instance, see the example provided in [@ohos.file.photoAccessHelper (Album Management)](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>)
Reverts to the state of the file before being edited. This API uses an asynchronous callback to return the result.
**NOTE**: This API deletes the edited data and edited image or video asset, and the deleted data cannot be restored. Exercise caution when using this API.
**System API**: This is a system API.
**Required permissions**: ohos.permission.WRITE_IMAGEVIDEO
**System capability**: SystemCapability.FileManagement.PhotoAccessHelper.Core
**Parameters**
| Name | Type | Mandatory | Description |
| ---------- | ------- | ---- | ---------------------------------- |
| callback | AsyncCallback<void> | Yes | Callback that returns no value.|
**Error codes**
For details about the error codes, see [Universal Error Codes](../errorcode-universal.md) and [File Management Error Codes](../apis-core-file-kit/errorcode-filemanagement.md).
| ID| Error Message|
| -------- | ---------------------------------------- |
| 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. |
**Example**
For details about how to create a phAccessHelper instance, see the example provided in [@ohos.file.photoAccessHelper (Album Management)](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>
Reverts to the state of the file before being edited. This API uses a promise to return the result.
**NOTE**: This API deletes the edited data and edited image or video asset, and the deleted data cannot be restored. Exercise caution when using this API.
**System API**: This is a system API.
**Required permissions**: ohos.permission.WRITE_IMAGEVIDEO
**System capability**: SystemCapability.FileManagement.PhotoAccessHelper.Core
**Return value**
| Type | Description |
| --------------------------------------- | ----------------- |
|Promise<string> | Promise that returns no value.|
**Error codes**
For details about the error codes, see [Universal Error Codes](../errorcode-universal.md) and [File Management Error Codes](../apis-core-file-kit/errorcode-filemanagement.md).
| ID| Error Message|
| -------- | ---------------------------------------- |
| 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. |
**Example**
For details about how to create a phAccessHelper instance, see the example provided in [@ohos.file.photoAccessHelper (Album Management)](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
Obtains the quick thumbnail and quality thumbnail of this asset. This API uses an asynchronous callback to return the result.
The size of a quick thumbnail is 128 x 128, and the size of a quality thumbnail is 256 x 256. After this API is called, the callback will be invoked twice to return a quick thumbnail and a quality thumbnail in sequence.
**System API**: This is a system API.
**Required permissions**: ohos.permission.READ_IMAGEVIDEO
**System capability**: SystemCapability.FileManagement.PhotoAccessHelper.Core
**Parameters**
| Name | Type | Mandatory | Description |
| ---------- | ------- | ---- | ---------------------------------- |
| callback | AsyncCallback<[image.PixelMap](../apis-image-kit/arkts-apis-image-PixelMap.md)> | Yes | Callback invoked twice to return the quick and quality thumbnails obtained.|
**Return value**
| Type | Description |
| --------------------------------------- | ----------------- |
| string | ID of the task for obtaining thumbnails.|
**Error codes**
For details about the error codes, see [Universal Error Codes](../errorcode-universal.md) and [File Management Error Codes](../apis-core-file-kit/errorcode-filemanagement.md).
| ID| Error Message|
| -------- | ---------------------------------------- |
| 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. |
**Example**
For details about how to create a phAccessHelper instance, see the example provided in [@ohos.file.photoAccessHelper (Album Management)](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
Obtains the thumbnails of an asset based on the specified options. This API uses an asynchronous callback to return the result.
**System API**: This is a system API.
**Required permissions**: ohos.permission.READ_IMAGEVIDEO
**System capability**: SystemCapability.FileManagement.PhotoAccessHelper.Core
**Parameters**
| Name | Type | Mandatory | Description |
| ---------- | ------- | ---- | ---------------------------------- |
| options | [RequestPhotoOptions](#requestphotooptions11) | Yes | Options for obtaining the asset thumbnail.|
| callback | AsyncCallback<[image.PixelMap](../apis-image-kit/arkts-apis-image-PixelMap.md)> | Yes | Callback used to return the thumbnails obtained. The callback may be invoked more than once, depending on **options**.|
**Return value**
| Type | Description |
| --------------------------------------- | ----------------- |
| string | ID of the task for obtaining thumbnails.|
**Error codes**
For details about the error codes, see [Universal Error Codes](../errorcode-universal.md) and [File Management Error Codes](../apis-core-file-kit/errorcode-filemanagement.md).
| ID| Error Message|
| -------- | ---------------------------------------- |
| 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. |
**Example**
For details about how to create a phAccessHelper instance, see the example provided in [@ohos.file.photoAccessHelper (Album Management)](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
Cancels a task for obtaining media thumbnails.
**System API**: This is a system API.
**Required permissions**: ohos.permission.READ_IMAGEVIDEO
**System capability**: SystemCapability.FileManagement.PhotoAccessHelper.Core
**Parameters**
| Name | Type | Mandatory | Description |
| ---------- | ------- | ---- | ---------------------------------- |
| requestId | string | Yes | ID of the task to cancel.|
**Error codes**
For details about the error codes, see [Universal Error Codes](../errorcode-universal.md) and [File Management Error Codes](../apis-core-file-kit/errorcode-filemanagement.md).
| ID| Error Message|
| -------- | ---------------------------------------- |
| 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. |
**Example**
For details about how to create a phAccessHelper instance, see the example provided in [@ohos.file.photoAccessHelper (Album Management)](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\
Obtains analysis data. This API uses a promise to return the result.
**System API**: This is a system API.
**Required permissions**: ohos.permission.READ\_IMAGEVIDEO
**System capability**: SystemCapability.FileManagement.PhotoAccessHelper.Core
**Parameters**
| Name | Type | Mandatory| Description |
| :----------- | :----------- | :- | :----------- |
| analysisType | [AnalysisType](#analysistype11) | Yes | Smart analysis type.|
**Error codes**
For details about the error codes, see [Universal Error Codes](../errorcode-universal.md) and [File Management Error Codes](../apis-core-file-kit/errorcode-filemanagement.md).
| ID | Error Message |
| :------- | :-------------------------------- |
| 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. |
**Example**
For details about how to create a phAccessHelper instance, see the example provided in [@ohos.file.photoAccessHelper (Album Management)](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>
Obtains the ArrayBuffer of a file thumbnail by specifying its type. This API uses a promise to return the result.
**Required permissions**: ohos.permission.READ_IMAGEVIDEO
**System capability**: SystemCapability.FileManagement.PhotoAccessHelper.Core
**Parameters**
| Name | Type | Mandatory | Description |
| ---- | -------------- | ---- | ----- |
| type | [ThumbnailType](#thumbnailtype13) | Yes | Type of the thumbnail.|
**Return value**
| Type | Description |
| ----------------------------- | --------------------- |
| Promise\ | Promise used to return the ArrayBuffer of the thumbnail.|
**Error codes**
For details about the error codes, see [Universal Error Codes](../errorcode-universal.md) and [File Management Error Codes](../apis-core-file-kit/errorcode-filemanagement.md).
If error code 13900012 is returned, follow the instructions provided in [Before You Start](../../media/medialibrary/photoAccessHelper-preparation.md).
| ID| Error Message|
| -------- | ---------------------------------------- |
| 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. |
**Example**
```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+
Describes the information about a shared media asset.
**System API**: This is a system API.
**System capability**: SystemCapability.FileManagement.PhotoAccessHelper.Core
### Properties
| Name| Type| Read-Only| Optional| Description|
| ---- | --- | ---- | ---- | --- |
| fileId | number | No| No| ID of the media asset.
**System API**: This is a system API.|
| uri | string | No| No| URI of the media asset.
**System API**: This is a system API.|
| data | string | No| No| Path data of the media asset.
**System API**: This is a system API.|
| mediaType | [PhotoType](arkts-apis-photoAccessHelper-e.md#phototype) | No| No| Media type of the media asset.
**System API**: This is a system API.|
| displayName | string | No| No| Display name of the media asset.
**System API**: This is a system API.|
| size | number | No| No| File size of the media asset.
**System API**: This is a system API.|
| dataAdded | number | No| No| Data added to the media asset.
**System API**: This is a system API.|
| dataModified | number | No| No| Data modified in the media asset.
**System API**: This is a system API.|
| duration | number | No| No| Duration of the media asset if it is a video.
**System API**: This is a system API.|
| width | number | No| No| Pixel width of the media asset.
**System API**: This is a system API.|
| height | number | No| No| Pixel height of the media asset.
**System API**: This is a system API.|
| dataTaken | number | No| No| Timestamp when the media asset was taken and stored locally.
**System API**: This is a system API.|
| orientation | number | No| No| Rotation angle of the media asset.
**System API**: This is a system API.|
| isFavorite | boolean | No| No| Whether the media asset is marked as a favorite.
**System API**: This is a system API.|
| title | string | No| No| Title of the media asset.
**System API**: This is a system API.|
| position | [PositionType](arkts-apis-photoAccessHelper-e.md#positiontype16) | No| No| Location of the media asset.
**System API**: This is a system API.|
| dataTrashed | number | No| No| Whether the media asset is moved to the trash.
**System API**: This is a system API.|
| hidden | boolean | No| No| Whether the media asset is hidden.
**System API**: This is a system API.|
| userComment | string | No| No| User comments on the media asset.
**System API**: This is a system API.|
| cameraShotKey | string | No| No| Camera shot information of the media asset.
**System API**: This is a system API.|
| dateYear | string | No| No| Year when the media asset was created.
**System API**: This is a system API.|
| dateMonth | string | No| No| Month when the media asset was created.
**System API**: This is a system API.|
| dateDay | string | No| No| Time when the media asset was created.
**System API**: This is a system API.|
| pending | boolean | No| No| Whether the media asset is in a pending state. **true** if pending.
**System API**: This is a system API.|
| dateAddedMs | number | No| No| Time elapsed after the media asset was added.
**System API**: This is a system API.|
| dateTrashedMs | number | No| No| Time elapsed since the media asset was trashed.
**System API**: This is a system API.|
| subtype | [PhotoSubtype](#photosubtype) | No| No| Subtype of the media asset.
**System API**: This is a system API.|
| movingPhotoEffectMode | [MovingPhotoEffectMode](#movingphotoeffectmode12) | No| No| Effect of the moving photo.
**System API**: This is a system API.|
| dynamicRangeType | [DynamicRangeType](arkts-apis-photoAccessHelper-e.md#dynamicrangetype12) | No| No| Dynamic range type of the media asset.
**System API**: This is a system API.|
| thumbnailReady | boolean | No| No| Whether the thumbnail of the media asset is ready.
**System API**: This is a system API.|
| lcdSize | string | No| No| Width and height of the LCD thumbnail of the media asset.
**System API**: This is a system API.|
| thmSize | string | No| No| Width and height of the thumb thumbnail of the media asset.
**System API**: This is a system API.|
| thumbnailModifiedMs14+ | number | No| Yes| Time elapsed since the thumbnail status of the media asset changed.
**System API**: This is a system API.|
| thumbnailVisible14+ | [ThumbnailVisibility](#thumbnailvisibility14) | No| No| Whether the thumbnail of the media asset is visible.
**System API**: This is a system API.|
## Album
Provides APIs to manage albums.
### Properties
**System capability**: SystemCapability.FileManagement.PhotoAccessHelper.Core
| Name | Type | Read-Only | Optional | Description |
| ------------ | ------ | ---- | ---- | ------- |
| lpath18+ | string | Yes | Yes | Virtual path of the album.
**System API**: This is a system API.|
| dateAdded18+ | number | Yes | Yes | Time when the album was added.
**System API**: This is a system API.|
| dateModified18+ | number | Yes | Yes | Time when the album was modified.
**System API**: This is a system API.|
| coverUriSource20+ | number | Yes | Yes | Source URI of the album cover.
**System API**: This is a system API.|
### recoverAssets(deprecated)
recoverAssets(assets: Array<PhotoAsset>, callback: AsyncCallback<void>): void
Recovers image or video assets from the trash. Before the operation, ensure that the image or video assets exist in the trash. This API uses an asynchronous callback to return the result.
> **NOTE**
>
> This API is supported since API version 10 and deprecated since API version 11. Use [MediaAlbumChangeRequest.recoverAssets](#recoverassets11) instead.
**System API**: This is a system API.
**Required permissions**: ohos.permission.WRITE_IMAGEVIDEO
**System capability**: SystemCapability.FileManagement.PhotoAccessHelper.Core
**Parameters**
| Name | Type | Mandatory| Description |
| -------- | ------------------------- | ---- | ---------- |
| assets | Array<[PhotoAsset](#photoasset)> | Yes | Array of the image or video assets to recover.|
| callback | AsyncCallback<void> | Yes | Callback that returns no value.|
**Error codes**
For details about the error codes, see [Universal Error Codes](../errorcode-universal.md) and [File Management Error Codes](../apis-core-file-kit/errorcode-filemanagement.md).
If error code 13900012 is returned, follow the instructions provided in [Before You Start](../../media/medialibrary/photoAccessHelper-preparation.md).
| ID| Error Message|
| -------- | ---------------------------------------- |
| 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. |
**Example**
For details about how to create a phAccessHelper instance, see the example provided in [@ohos.file.photoAccessHelper (Album Management)](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>
Recovers image or video assets from the trash. Before the operation, ensure that the image or video assets exist in the trash. This API uses a promise to return the result.
> **NOTE**
>
> This API is supported since API version 10 and deprecated since API version 11. Use [MediaAlbumChangeRequest.recoverAssets](#recoverassets11) instead.
**System API**: This is a system API.
**Required permissions**: ohos.permission.WRITE_IMAGEVIDEO
**System capability**: SystemCapability.FileManagement.PhotoAccessHelper.Core
**Parameters**
| Name | Type | Mandatory| Description |
| -------- | ------------------------- | ---- | ---------- |
| assets | Array<[PhotoAsset](#photoasset)> | Yes | Array of the image or video assets to recover.|
**Return value**
| Type | Description |
| --------------------------------------- | ----------------- |
|Promise<void> | Promise that returns no value.|
**Error codes**
For details about the error codes, see [Universal Error Codes](../errorcode-universal.md) and [File Management Error Codes](../apis-core-file-kit/errorcode-filemanagement.md).
If error code 13900012 is returned, follow the instructions provided in [Before You Start](../../media/medialibrary/photoAccessHelper-preparation.md).
| ID| Error Message|
| -------- | ---------------------------------------- |
| 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. |
**Example**
For details about how to create a phAccessHelper instance, see the example provided in [@ohos.file.photoAccessHelper (Album Management)](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
Deletes image or video assets from the trash. Before the operation, ensure that the image or video assets exist in the trash. This API uses an asynchronous callback to return the result.
> **NOTE**
>
> This API is supported since API version 10 and deprecated since API version 11. Use [MediaAlbumChangeRequest.deleteAssets](#deleteassets11) instead.
**NOTE**: This operation is irreversible. The file assets deleted cannot be restored. Exercise caution when performing this operation.
**System API**: This is a system API.
**Required permissions**: ohos.permission.WRITE_IMAGEVIDEO
**System capability**: SystemCapability.FileManagement.PhotoAccessHelper.Core
**Parameters**
| Name | Type | Mandatory| Description |
| -------- | ------------------------- | ---- | ---------- |
| assets | Array<[PhotoAsset](#photoasset)> | Yes | Array of the image or video assets to delete.|
| callback | AsyncCallback<void> | Yes | Callback that returns no value.|
**Error codes**
For details about the error codes, see [Universal Error Codes](../errorcode-universal.md) and [File Management Error Codes](../apis-core-file-kit/errorcode-filemanagement.md).
If error code 13900012 is returned, follow the instructions provided in [Before You Start](../../media/medialibrary/photoAccessHelper-preparation.md).
| ID| Error Message|
| -------- | ---------------------------------------- |
| 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. |
**Example**
For details about how to create a phAccessHelper instance, see the example provided in [@ohos.file.photoAccessHelper (Album Management)](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>
Deletes image or video assets from the trash. Before the operation, ensure that the image or video assets exist in the trash. It is recommended that the number of images or videos to be deleted be less than or equal to 1000. This API uses a promise to return the result.
> **NOTE**
>
> This API is supported since API version 10 and deprecated since API version 11. Use [MediaAlbumChangeRequest.deleteAssets](#deleteassets11) instead.
**NOTE**: This operation is irreversible. The file assets deleted cannot be restored. Exercise caution when performing this operation.
**System API**: This is a system API.
**Required permissions**: ohos.permission.WRITE_IMAGEVIDEO
**System capability**: SystemCapability.FileManagement.PhotoAccessHelper.Core
**Parameters**
| Name | Type | Mandatory| Description |
| -------- | ------------------------- | ---- | ---------- |
| assets | Array<[PhotoAsset](#photoasset)> | Yes | Array of the image or video assets to delete.|
**Return value**
| Type | Description |
| --------------------------------------- | ----------------- |
|Promise<void> | Promise that returns no value.|
**Error codes**
For details about the error codes, see [Universal Error Codes](../errorcode-universal.md) and [File Management Error Codes](../apis-core-file-kit/errorcode-filemanagement.md).
If error code 13900012 is returned, follow the instructions provided in [Before You Start](../../media/medialibrary/photoAccessHelper-preparation.md).
| ID| Error Message|
| -------- | ---------------------------------------- |
| 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. |
**Example**
For details about how to create a phAccessHelper instance, see the example provided in [@ohos.file.photoAccessHelper (Album Management)](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
Sets the album cover. This API uses an asynchronous callback to return the result.
> **NOTE**
>
> This API is supported since API version 10 and deprecated since API version 11. Use [MediaAlbumChangeRequest.setCoverUri](#setcoveruri11) instead.
**NOTE**: This API can be used to set the user album cover, but not the system album cover.
**System API**: This is a system API.
**Required permissions**: ohos.permission.WRITE_IMAGEVIDEO
**System capability**: SystemCapability.FileManagement.PhotoAccessHelper.Core
**Parameters**
| Name | Type | Mandatory| Description |
| -------- | ------------------------- | ---- | ---------- |
| uri | string | Yes | URI of the file to be set as the album cover.|
| callback | AsyncCallback<void> | Yes | Callback that returns no value.|
**Error codes**
For details about the error codes, see [Universal Error Codes](../errorcode-universal.md) and [File Management Error Codes](../apis-core-file-kit/errorcode-filemanagement.md).
If error code 13900012 is returned, follow the instructions provided in [Before You Start](../../media/medialibrary/photoAccessHelper-preparation.md).
| ID| Error Message|
| -------- | ---------------------------------------- |
| 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. |
**Example**
For details about how to create a phAccessHelper instance, see the example provided in [@ohos.file.photoAccessHelper (Album Management)](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>
Sets the album cover. This API uses a promise to return the result.
> **NOTE**
>
> This API is supported since API version 10 and deprecated since API version 11. Use [MediaAlbumChangeRequest.setCoverUri](#setcoveruri11) instead.
**NOTE**: This API can be used to set the user album cover, but not the system album cover.
**System API**: This is a system API.
**Required permissions**: ohos.permission.WRITE_IMAGEVIDEO
**System capability**: SystemCapability.FileManagement.PhotoAccessHelper.Core
**Parameters**
| Name | Type | Mandatory| Description |
| -------- | ------------------------- | ---- | ---------- |
| uri | string | Yes | URI of the file to be set as the album cover.|
**Return value**
| Type | Description |
| --------------------------------------- | ----------------- |
|Promise<void> | Promise that returns no value.|
**Error codes**
For details about the error codes, see [Universal Error Codes](../errorcode-universal.md) and [File Management Error Codes](../apis-core-file-kit/errorcode-filemanagement.md).
If error code 13900012 is returned, follow the instructions provided in [Before You Start](../../media/medialibrary/photoAccessHelper-preparation.md).
| ID| Error Message|
| -------- | ---------------------------------------- |
| 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. |
**Example**
For details about how to create a phAccessHelper instance, see the example provided in [@ohos.file.photoAccessHelper (Album Management)](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\
Obtains the face identifier on the cover of a portrait album or group photo album.
**System API**: This is a system API.
**Required permissions**: ohos.permission.READ\_IMAGEVIDEO
**System capability**: SystemCapability.FileManagement.PhotoAccessHelper.Core
**Return value**
| Type | Description |
| :------------------ | :---------------------------------- |
| Promise<string> | Promise used to return **tag_id** of the portrait album, **group_tag** of the group photo album, or an empty string if no face identifier is found.|
**Error codes**
For details about the error codes, see [Universal Error Codes](../errorcode-universal.md) and [File Management Error Codes](../apis-core-file-kit/errorcode-filemanagement.md).
| ID| Error Message |
| :------- | :----------------------------------------------------------- |
| 201 | Permission denied. |
| 202 | Called by non-system application. |
| 14000011 | Internal system error |
**Example**
For details about how to create a phAccessHelper instance, see the example provided in [@ohos.file.photoAccessHelper (Album Management)](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+
Represents the edited media asset data.
**System API**: This is a system API.
**System capability**: SystemCapability.FileManagement.PhotoAccessHelper.Core
### Properties
| Name | Type | Readable | Writable | Description |
| ------------ | ------ | ---- | ---- | ------- |
| compatibleFormat | string | Yes | Yes | Format of the edited data.
**System API**: This is a system API. |
| formatVersion | string | Yes | Yes | Version of the data format.
**System API**: This is a system API. |
| data | string | Yes | Yes | Content edited.
**System API**: This is a system API. |
### constructor11+
constructor(compatibleFormat: string, formatVersion: string)
Constructor.
**System API**: This is a system API.
**System capability**: SystemCapability.FileManagement.PhotoAccessHelper.Core
**Parameters**
| Name | Type | Mandatory| Description |
| -------- | ------------------------- | ---- | ---------- |
| compatibleFormat | string | Yes | Format of the edited data.|
| formatVersion | string | Yes | Version of the data format.|
**Error codes**
For details about the error codes, see [Universal Error Codes](../errorcode-universal.md) and [File Management Error Codes](../apis-core-file-kit/errorcode-filemanagement.md).
| ID| Error Message|
| -------- | ---------------------------------------- |
| 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. |
**Example**
```ts
let assetEditData: photoAccessHelper.MediaAssetEditData = new photoAccessHelper.MediaAssetEditData('system', '1.0');
```
## MediaAssetChangeRequest11+
Represents a media asset change request.
**System capability**: SystemCapability.FileManagement.PhotoAccessHelper.Core
### createAssetRequest11+
static createAssetRequest(context: Context, displayName: string, options?: PhotoCreateOptions): MediaAssetChangeRequest
Creates an asset change request with the specified file name.
The file name must comply with the following specifications:
- The file name consists of a valid file name and an image or video file name extension.
- The file name cannot exceed 255 characters.
- The file name cannot contain any of the following characters:
API version 18 and later: \ / : * ? " < > |
API versions 10 to 17: . .. \ / : * ? " ' ` < > | { } [ ]
**System API**: This is a system API.
**System capability**: SystemCapability.FileManagement.PhotoAccessHelper.Core
**Parameters**
| Name | Type | Mandatory| Description |
| ------- | ------- | ---- | -------------------------- |
| context | [Context](../apis-ability-kit/js-apis-inner-application-context.md) | Yes | Context of the ability instance.|
| displayName | string | Yes | File name of the image or video to create. |
| options | [PhotoCreateOptions](#photocreateoptions) | No | Options for creating an image or video asset. |
**Return value**
| Type | Description |
| --------------------------------------- | ----------------- |
| [MediaAssetChangeRequest](#mediaassetchangerequest11) | **MediaAssetChangeRequest** created.|
**Error codes**
For details about the error codes, see [Universal Error Codes](../errorcode-universal.md) and [File Management Error Codes](../apis-core-file-kit/errorcode-filemanagement.md).
If error code 14000001 is returned, refer to [PhotoKeys](#photokeys) to learn about the format and length requirements of the file name.
| ID| Error Message|
| -------- | ---------------------------------------- |
| 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. |
**Example**
For details about how to create a phAccessHelper instance, see the example provided in [@ohos.file.photoAccessHelper (Album Management)](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);
// Ensure that the asset specified by fileUri exists.
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
Favorites or unfavorites this file.
**System API**: This is a system API.
**System capability**: SystemCapability.FileManagement.PhotoAccessHelper.Core
**Parameters**
| Name | Type | Mandatory | Description |
| ---------- | ------- | ---- | ---------------------------------- |
| favoriteState | boolean | Yes | Whether to favorite the file. **true** to favorite, **false** otherwise.|
**Error codes**
For details about the error codes, see [Universal Error Codes](../errorcode-universal.md) and [File Management Error Codes](../apis-core-file-kit/errorcode-filemanagement.md).
| ID| Error Message|
| -------- | ---------------------------------------- |
| 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. |
**Example**
For details about how to create a phAccessHelper instance, see the example provided in [@ohos.file.photoAccessHelper (Album Management)](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
Hides this file.
**System API**: This is a system API.
**System capability**: SystemCapability.FileManagement.PhotoAccessHelper.Core
**Parameters**
| Name | Type | Mandatory | Description |
| ---------- | ------- | ---- | ---------------------------------- |
| hiddenState | boolean | Yes | Whether to hide the file. **true** to hide, **false** otherwise.|
**Error codes**
For details about the error codes, see [Universal Error Codes](../errorcode-universal.md) and [File Management Error Codes](../apis-core-file-kit/errorcode-filemanagement.md).
| ID| Error Message|
| -------- | ---------------------------------------- |
| 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. |
**Example**
For details about how to create a phAccessHelper instance, see the example provided in [@ohos.file.photoAccessHelper (Album Management)](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
Sets the user comment information of this media asset.
**System API**: This is a system API.
**System capability**: SystemCapability.FileManagement.PhotoAccessHelper.Core
**Parameters**
| Name | Type | Mandatory | Description |
| ---------- | ------- | ---- | ---------------------------------- |
| userComment | string | Yes | Comment information to set, which cannot exceed 420 characters.|
**Error codes**
For details about the error codes, see [Universal Error Codes](../errorcode-universal.md) and [File Management Error Codes](../apis-core-file-kit/errorcode-filemanagement.md).
| ID| Error Message|
| -------- | ---------------------------------------- |
| 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. |
**Example**
For details about how to create a phAccessHelper instance, see the example provided in [@ohos.file.photoAccessHelper (Album Management)](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
Saves the edited data of an asset.
**System API**: This is a system API.
**System capability**: SystemCapability.FileManagement.PhotoAccessHelper.Core
**Parameters**
| Name | Type | Mandatory | Description |
| ---------- | ------- | ---- | ---------------------------------- |
| editData | [MediaAssetEditData](#mediaasseteditdata11) | Yes | Edited data to save.|
**Error codes**
For details about the error codes, see [Universal Error Codes](../errorcode-universal.md) and [File Management Error Codes](../apis-core-file-kit/errorcode-filemanagement.md).
| ID| Error Message|
| -------- | ---------------------------------------- |
| 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. |
**Example**
For details about how to create a phAccessHelper instance, see the example provided in [@ohos.file.photoAccessHelper (Album Management)](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
Adds resources using **PhotoProxy** data.
**NOTE**: For the same asset change request, this API cannot be repeatedly called after resources are successfully added.
**System API**: This is a system API available only for camera applications.
**System capability**: SystemCapability.FileManagement.PhotoAccessHelper.Core
**Parameters**
| Name | Type | Mandatory| Description |
| ------- |---------------------------------| ---- |----------------------|
| type | [ResourceType](#resourcetype11) | Yes | Type of the resource to add. |
| proxy | [PhotoProxy](#photoproxy11) | Yes | PhotoProxy data of the resource to add.|
**Error codes**
For details about the error codes, see [Universal Error Codes](../errorcode-universal.md) and [File Management Error Codes](../apis-core-file-kit/errorcode-filemanagement.md).
| ID | Error Message |
|----------|-----------------------------------|
| 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. |
**Example**
For details about how to create a phAccessHelper instance, see the example provided in [@ohos.file.photoAccessHelper (Album Management)](arkts-apis-photoAccessHelper-f.md).
```ts
class PhotoProxyImpl implements photoAccessHelper.PhotoProxy {
// Implement 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
Sets location information.
**System API**: This is a system API.
**System capability**: SystemCapability.FileManagement.PhotoAccessHelper.Core
**Parameters**
| Name | Type | Mandatory| Description |
| ------- |-------------| ---- |-------|
| longitude | number | Yes | Longitude.|
| latitude | number | Yes | Latitude. |
**Error codes**
For details about the error codes, see [Universal Error Codes](../errorcode-universal.md) and [File Management Error Codes](../apis-core-file-kit/errorcode-filemanagement.md).
| ID| Error Message|
| -------- | ---------------------------------------- |
| 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. |
**Example**
For details about how to create a phAccessHelper instance, see the example provided in [@ohos.file.photoAccessHelper (Album Management)](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
Sets the Key for the Ultra Snapshot feature, which allows the camera to take photos or record videos with the screen off.
**System API**: This is a system API.
**System capability**: SystemCapability.FileManagement.PhotoAccessHelper.Core
**Parameters**
| Name | Type | Mandatory | Description |
| ---------- | ------- | ---- | ---------------------------------- |
| cameraShotKey | string | Yes | Key for the Ultra Snapshot feature. This parameter is available only for the system camera, and the key value is defined by the system camera.|
**Error codes**
For details about the error codes, see [Universal Error Codes](../errorcode-universal.md) and [File Management Error Codes](../apis-core-file-kit/errorcode-filemanagement.md).
| ID| Error Message|
| -------- | ---------------------------------------- |
| 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. |
**Example**
For details about how to create a phAccessHelper instance, see the example provided in [@ohos.file.photoAccessHelper (Album Management)](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
Sets the effect of this moving photo.
**System API**: This is a system API.
**System capability**: SystemCapability.FileManagement.PhotoAccessHelper.Core
**Parameters**
| Name | Type | Mandatory | Description |
| ---------- | ------- | ---- | ---------------------------------- |
| mode | [MovingPhotoEffectMode](#movingphotoeffectmode12) | Yes | Effect to set.|
**Error codes**
For details about the error codes, see [Universal Error Codes](../errorcode-universal.md) and [File Management Error Codes](../apis-core-file-kit/errorcode-filemanagement.md).
| ID| Error Message|
| -------- | ---------------------------------------- |
| 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. |
**Example**
For details about how to create a phAccessHelper instance, see the example provided in [@ohos.file.photoAccessHelper (Album Management)](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);
// Ensure that the asset specified by fileUri exists.
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
Sets the watermark type supported by photos.
**System API**: This is a system API.
**System capability**: SystemCapability.FileManagement.PhotoAccessHelper.Core
**Parameters**
| Name | Type | Mandatory | Description |
| ---------- | ------- | ---- | ---------------------------------- |
| watermarkType | [WatermarkType](#watermarktype14) | Yes | Watermark type to set. |
**Error codes**
For details about the error codes, see [Universal Error Codes](../errorcode-universal.md) and [File Management Error Codes](../apis-core-file-kit/errorcode-filemanagement.md).
| ID| Error Message|
| -------- | ---------------------------------------- |
| 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. |
**Example**
```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>
Permanently deletes photos or videos in batches. This API uses a promise to return the result.
**NOTE**: This operation is irreversible. The file assets deleted cannot be restored. Exercise caution when performing this operation.
**System API**: This is a system API.
**System capability**: SystemCapability.FileManagement.PhotoAccessHelper.Core
**Required permissions**: ohos.permission.WRITE_IMAGEVIDEO
**Parameters**
| Name | Type | Mandatory | Description |
| ---- | -------------- | ---- | ----- |
| context | [Context](../apis-ability-kit/js-apis-inner-application-context.md) | Yes | Context of the ability instance.|
| assets | Array\<[PhotoAsset](#photoasset)>| Yes | Array of images or videos to be permanently deleted.|
**Return value**
| Type | Description |
| ------------------- | ---------- |
| Promise<void> | Promise that returns no value.|
**Error codes**
For details about the error codes, see [Universal Error Codes](../errorcode-universal.md) and [File Management Error Codes](../apis-core-file-kit/errorcode-filemanagement.md).
| ID| Error Message|
| -------- | ---------------------------------------- |
| 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.
**Example**
```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>
Permanently deletes images or video assets in batches by URI. This API uses a promise to return the result.
>**NOTE**
>
> This operation is irreversible. The assets deleted cannot be restored. Exercise caution when performing this operation.
**System API**: This is a system API.
**System capability**: SystemCapability.FileManagement.PhotoAccessHelper.Core
**Required permissions**: ohos.permission.WRITE_IMAGEVIDEO
**Parameters**
| Name | Type | Mandatory | Description |
| ---- | -------------- | ---- | ----- |
| context | [Context](../apis-ability-kit/js-apis-inner-application-context.md) | Yes | Context of the ability instance.|
| assetUris | Array<String> | Yes | Array of URIs of the images or videos to be permanently deleted.|
**Return value**
| Type | Description |
| ------------------- | ---------- |
| Promise<void> | Promise that returns no value.|
**Error codes**
For details about the error codes, see [Universal Error Codes](../errorcode-universal.md) and [File Management Error Codes](../apis-core-file-kit/errorcode-filemanagement.md).
| ID| Error Message|
| -------- | ---------------------------------------- |
| 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. |
**Example**
```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+
Represents a request for changing multiple assets.
**System API**: This is a system API.
**System capability**: SystemCapability.FileManagement.PhotoAccessHelper.Core
### constructor11+
constructor(assets: Array<PhotoAsset>)
Constructor.
**System API**: This is a system API.
**System capability**: SystemCapability.FileManagement.PhotoAccessHelper.Core
**Parameters**
| Name | Type | Mandatory| Description |
| -------- | ------------------------- | ---- | ---------- |
| assets | Array<[PhotoAsset](#photoasset)> | Yes | Assets to change.|
**Error codes**
For details about the error codes, see [Universal Error Codes](../errorcode-universal.md) and [File Management Error Codes](../apis-core-file-kit/errorcode-filemanagement.md).
| ID| Error Message|
| -------- | ---------------------------------------- |
| 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. |
**Example**
For details about how to create a phAccessHelper instance, see the example provided in [@ohos.file.photoAccessHelper (Album Management)](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
Favorites or unfavorites this file.
**System API**: This is a system API.
**System capability**: SystemCapability.FileManagement.PhotoAccessHelper.Core
**Parameters**
| Name | Type | Mandatory | Description |
| ---------- | ------- | ---- | ---------------------------------- |
| favoriteState | boolean | Yes | Whether to favorite the file. **true** to favorite, **false** otherwise.|
**Error codes**
For details about the error codes, see [Universal Error Codes](../errorcode-universal.md) and [File Management Error Codes](../apis-core-file-kit/errorcode-filemanagement.md).
| ID| Error Message|
| -------- | ---------------------------------------- |
| 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. |
**Example**
For details about how to create a phAccessHelper instance, see the example provided in [@ohos.file.photoAccessHelper (Album Management)](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
Hides this file.
**System API**: This is a system API.
**System capability**: SystemCapability.FileManagement.PhotoAccessHelper.Core
**Parameters**
| Name | Type | Mandatory | Description |
| ---------- | ------- | ---- | ---------------------------------- |
| hiddenState | boolean | Yes | Whether to hide the file. **true** to hide, **false** otherwise.|
**Error codes**
For details about the error codes, see [Universal Error Codes](../errorcode-universal.md) and [File Management Error Codes](../apis-core-file-kit/errorcode-filemanagement.md).
| ID| Error Message|
| -------- | ---------------------------------------- |
| 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. |
**Example**
For details about how to create a phAccessHelper instance, see the example provided in [@ohos.file.photoAccessHelper (Album Management)](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
Sets the user comment information of this media asset.
**System API**: This is a system API.
**System capability**: SystemCapability.FileManagement.PhotoAccessHelper.Core
**Parameters**
| Name | Type | Mandatory | Description |
| ---------- | ------- | ---- | ---------------------------------- |
| userComment | string | Yes | Comment information to set, which cannot exceed 420 characters.|
**Error codes**
For details about the error codes, see [Universal Error Codes](../errorcode-universal.md) and [File Management Error Codes](../apis-core-file-kit/errorcode-filemanagement.md).
| ID| Error Message|
| -------- | ---------------------------------------- |
| 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. |
**Example**
For details about how to create a phAccessHelper instance, see the example provided in [@ohos.file.photoAccessHelper (Album Management)](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
Sets whether this asset is displayed in the **Recent** list.
**System API**: This is a system API.
**System capability**: SystemCapability.FileManagement.PhotoAccessHelper.Core
**Parameters**
| Name | Type | Mandatory | Description |
| ---------- | ------- | ---- | ---------------------------------- |
| isRencentShow | boolean | Yes | Whether this asset is displayed in the **Recent** list. **true** if displayed, **false** otherwise.|
**Error codes**
For details about the error codes, see [Universal Error Codes](../errorcode-universal.md) and [File Management Error Codes](../apis-core-file-kit/errorcode-filemanagement.md).
| ID| Error Message|
| -------- | ---------------------------------------- |
| 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. |
**Example**
For details about how to create a phAccessHelper instance, see the example provided in [@ohos.file.photoAccessHelper (Album Management)](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+
Provides APIs for managing the media album change request.
**System capability**: SystemCapability.FileManagement.PhotoAccessHelper.Core
### createAlbumRequest11+
static createAlbumRequest(context: Context, name: string): MediaAlbumChangeRequest
Creates a MediaAlbumChangeRequest instance.
The album name must comply with the following specifications:
- The album name cannot exceed 255 characters.
- The album name cannot contain any of the following characters:
. .. \ / : * ? " ' ` < > | { } [ ]
- The album name is case-insensitive.
- Duplicate album names are not allowed.
**System API**: This is a system API.
**System capability**: SystemCapability.FileManagement.PhotoAccessHelper.Core
**Parameters**
| Name | Type | Mandatory| Description |
| ------- | ------- | ---- | -------------------------- |
| context | [Context](../apis-ability-kit/js-apis-inner-application-context.md) | Yes | Context of the ability instance.|
| name | string | Yes | Name of the album.|
**Return value**
| Type | Description |
| --------------------------------------- | ----------------- |
| [MediaAlbumChangeRequest](#mediaalbumchangerequest11) | MediaAlbumChangeRequest instance created.|
**Error codes**
For details about the error codes, see [Universal Error Codes](../errorcode-universal.md) and [File Management Error Codes](../apis-core-file-kit/errorcode-filemanagement.md).
| ID| Error Message|
| -------- | ---------------------------------------- |
| 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. |
**Example**
For details about how to create a phAccessHelper instance, see the example provided in [@ohos.file.photoAccessHelper (Album Management)](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>
Deletes albums. This API uses a promise to return the result.
Ensure that the albums to be deleted exist. Only user albums can be deleted.
**System API**: This is a system API.
**Required permissions**: ohos.permission.WRITE_IMAGEVIDEO
**System capability**: SystemCapability.FileManagement.PhotoAccessHelper.Core
**Parameters**
| Name | Type | Mandatory| Description |
| ------- | ------- | ---- | -------------------------- |
| context | [Context](../apis-ability-kit/js-apis-inner-application-context.md) | Yes | Context of the ability instance.|
| albums | Array<[Album](#album)> | Yes | Albums to delete. |
**Return value**
| Type | Description |
| --------------------------------------- | ----------------- |
| Promise<void>| Promise that returns no value.|
**Error codes**
For details about the error codes, see [Universal Error Codes](../errorcode-universal.md) and [File Management Error Codes](../apis-core-file-kit/errorcode-filemanagement.md).
| ID| Error Message|
| -------- | ---------------------------------------- |
| 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. |
**Example**
For details about how to create a phAccessHelper instance, see the example provided in [@ohos.file.photoAccessHelper (Album Management)](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>
Deletes user albums by URI. This API uses a promise to return the result.
**System API**: This is a system API.
**Required permissions**: ohos.permission.WRITE_IMAGEVIDEO
**System capability**: SystemCapability.FileManagement.PhotoAccessHelper.Core
**Parameters**
| Name | Type | Mandatory| Description |
| ------- | ------- | ---- | -------------------------- |
| context | [Context](../apis-ability-kit/js-apis-inner-application-context.md) | Yes | Context of the ability instance.|
| albumUris | Array<string> | Yes | Array of URIs of the albums to be deleted. |
**Return value**
| Type | Description |
| --------------------------------------- | ----------------- |
| Promise<void>| Promise that returns no value.|
**Error codes**
For details about the error codes, see [Universal Error Codes](../errorcode-universal.md) and [File Management Error Codes](../apis-core-file-kit/errorcode-filemanagement.md).
| ID| Error Message|
| -------- | ---------------------------------------- |
| 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; |
**Example**
```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
Sets the album cover.
**System API**: This is a system API.
**System capability**: SystemCapability.FileManagement.PhotoAccessHelper.Core
**Parameters**
| Name | Type | Mandatory | Description |
| ---------- | ------- | ---- | ---------------------------------- |
| coverUri | string | Yes | URI of the file to be set as the album cover.|
**Error codes**
For details about the error codes, see [Universal Error Codes](../errorcode-universal.md) and [File Management Error Codes](../apis-core-file-kit/errorcode-filemanagement.md).
| ID| Error Message|
| -------- | ---------------------------------------- |
| 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. |
**Example**
For details about how to create a phAccessHelper instance, see the example provided in [@ohos.file.photoAccessHelper (Album Management)](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
Resets the cover.
**System API**: This is a system API.
**System capability**: SystemCapability.FileManagement.PhotoAccessHelper.Core
**Error codes**
For details about the error codes, see [Universal Error Codes](../errorcode-universal.md) and [Media Library Error Codes](errcode-medialibrary.md).
| ID| Error Message|
| -------- | ---------------------------------------- |
| 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. |
**Example**
For details about how to create a phAccessHelper instance, see the example provided in [@ohos.file.photoAccessHelper (Album Management)](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
Moves assets to another album.
**System API**: This is a system API.
**System capability**: SystemCapability.FileManagement.PhotoAccessHelper.Core
**Parameters**
| Name | Type | Mandatory | Description |
| ---------- | ------- | ---- | ---------------------------------- |
| assets | Array<[PhotoAsset](#photoasset)> | Yes | Assets to move.|
| targetAlbum | Album | Yes | Album to which the assets are to be moved.|
**Error codes**
For details about the error codes, see [Universal Error Codes](../errorcode-universal.md) and [File Management Error Codes](../apis-core-file-kit/errorcode-filemanagement.md).
| ID| Error Message|
| -------- | ---------------------------------------- |
| 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. |
**Example**
For details about how to create a phAccessHelper instance, see the example provided in [@ohos.file.photoAccessHelper (Album Management)](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
Moves assets in an album to another album.
**System API**: This is a system API.
**System capability**: SystemCapability.FileManagement.PhotoAccessHelper.Core
**Parameters**
| Name | Type | Mandatory | Description |
| ---------- | ------- | ---- | ---------------------------------- |
| assetUris | Array<String> | Yes | Array of URIs of the assets to move.|
| targetAlbum | [Album](#album) | Yes | Album to which the assets are to be moved.|
**Error codes**
For details about the error codes, see [Universal Error Codes](../errorcode-universal.md) and [File Management Error Codes](../apis-core-file-kit/errorcode-filemanagement.md).
| ID| Error Message|
| -------- | ---------------------------------------- |
| 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. |
**Example**
For details about how to create a phAccessHelper instance, see the example provided in [@ohos.file.photoAccessHelper (Album Management)](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
Recovers assets from the trash.
**System API**: This is a system API.
**System capability**: SystemCapability.FileManagement.PhotoAccessHelper.Core
**Parameters**
| Name | Type | Mandatory | Description |
| ---------- | ------- | ---- | ---------------------------------- |
| assets | Array<[PhotoAsset](#photoasset)> | Yes | Assets to recover.|
**Error codes**
For details about the error codes, see [Universal Error Codes](../errorcode-universal.md) and [File Management Error Codes](../apis-core-file-kit/errorcode-filemanagement.md).
| ID| Error Message|
| -------- | ---------------------------------------- |
| 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. |
**Example**
For details about how to create a phAccessHelper instance, see the example provided in [@ohos.file.photoAccessHelper (Album Management)](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
Recovers assets from the trash.
**System API**: This is a system API.
**System capability**: SystemCapability.FileManagement.PhotoAccessHelper.Core
**Parameters**
| Name | Type | Mandatory | Description |
| ---------- | ------- | ---- | ---------------------------------- |
| assetUris | Array<String> | Yes | Array of URIs of the assets to recover.|
**Error codes**
For details about the error codes, see [Universal Error Codes](../errorcode-universal.md) and [File Management Error Codes](../apis-core-file-kit/errorcode-filemanagement.md).
| ID| Error Message|
| -------- | ---------------------------------------- |
| 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. |
**Example**
For details about how to create a phAccessHelper instance, see the example provided in [@ohos.file.photoAccessHelper (Album Management)](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
Permanently deletes assets from the trash.
**NOTE**: This operation is irreversible. The file assets deleted cannot be restored. Exercise caution when performing this operation.
**System API**: This is a system API.
**System capability**: SystemCapability.FileManagement.PhotoAccessHelper.Core
**Parameters**
| Name | Type | Mandatory | Description |
| ---------- | ------- | ---- | ---------------------------------- |
| assets | Array<[PhotoAsset](#photoasset)> | Yes | Assets to be permanently deleted.|
**Error codes**
For details about the error codes, see [Universal Error Codes](../errorcode-universal.md) and [File Management Error Codes](../apis-core-file-kit/errorcode-filemanagement.md).
| ID| Error Message|
| -------- | ---------------------------------------- |
| 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. |
**Example**
For details about how to create a phAccessHelper instance, see the example provided in [@ohos.file.photoAccessHelper (Album Management)](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
Permanently deletes assets from the trash.
> **NOTE**
>
> This operation is irreversible. The assets deleted cannot be restored. Exercise caution when performing this operation.
**System API**: This is a system API.
**System capability**: SystemCapability.FileManagement.PhotoAccessHelper.Core
**Parameters**
| Name | Type | Mandatory | Description |
| ---------- | ------- | ---- | ---------------------------------- |
| assetUris | Array<String> | Yes | Array of URIs of the assets to be permanently deleted.|
**Error codes**
For details about the error codes, see [Universal Error Codes](../errorcode-universal.md) and [File Management Error Codes](../apis-core-file-kit/errorcode-filemanagement.md).
| ID| Error Message|
| -------- | ---------------------------------------- |
| 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. |
**Example**
For details about how to create a phAccessHelper instance, see the example provided in [@ohos.file.photoAccessHelper (Album Management)](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
Sets the display level of the portrait album.
**System API**: This is a system API.
**System capability**: SystemCapability.FileManagement.PhotoAccessHelper.Core
**Parameters**
| Name | Type | Mandatory | Description |
| ---------- | ------- | ---- | ---------------------------------- |
| displayLevel | number | Yes | Display level to set. The options are as follows:
**0**: unfavorite the portrait album.
**1**: set the portrait album as the first to display.
**2**: do not display the portrait album as the first one.
**3**: favorite the portrait album.|
**Error codes**
For details about the error codes, see [Universal Error Codes](../errorcode-universal.md) and [File Management Error Codes](../apis-core-file-kit/errorcode-filemanagement.md).
| ID| Error Message|
| -------- | ---------------------------------------- |
| 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. |
**Example**
For details about how to create a phAccessHelper instance, see the example provided in [@ohos.file.photoAccessHelper (Album Management)](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
Sets the relationship between people in the portrait album to **Me**.
**System API**: This is a system API.
**System capability**: SystemCapability.FileManagement.PhotoAccessHelper.Core
**Error codes**
For details about the error codes, see [Universal Error Codes](../errorcode-universal.md) and [File Management Error Codes](../apis-core-file-kit/errorcode-filemanagement.md).
| ID| Error Message|
| -------- | ---------------------------------------- |
| 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. |
**Example**
For details about how to create a phAccessHelper instance, see the example provided in [@ohos.file.photoAccessHelper (Album Management)](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
Removes assets from this portrait album or group photo album.
**System API**: This is a system API.
**System capability**: SystemCapability.FileManagement.PhotoAccessHelper.Core
**Parameters**
| Name | Type | Mandatory | Description |
| ---------- | ------- | ---- | ---------------------------------- |
| assets | Array<PhotoAsset> | Yes | Assets to remove.|
**Error codes**
For details about the error codes, see [Universal Error Codes](../errorcode-universal.md) and [File Management Error Codes](../apis-core-file-kit/errorcode-filemanagement.md).
| ID| Error Message|
| -------- | ---------------------------------------- |
| 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. |
**Example**
For details about how to create a phAccessHelper instance, see the example provided in [@ohos.file.photoAccessHelper (Album Management)](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
Merges two portrait albums.
**System API**: This is a system API.
**System capability**: SystemCapability.FileManagement.PhotoAccessHelper.Core
**Parameters**
| Name | Type | Mandatory | Description |
| ---------- | ------- | ---- | ---------------------------------- |
| target | [Album](#album) | Yes | Album generated after the merge. The album must be renamed.|
**Error codes**
For details about the error codes, see [Universal Error Codes](../errorcode-universal.md) and [File Management Error Codes](../apis-core-file-kit/errorcode-filemanagement.md).
| ID| Error Message|
| -------- | ---------------------------------------- |
| 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. |
**Example**
For details about how to create a phAccessHelper instance, see the example provided in [@ohos.file.photoAccessHelper (Album Management)](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;
Places this album before an album.
**System API**: This is a system API.
**System capability**: SystemCapability.FileManagement.PhotoAccessHelper.Core
**Parameters**
| Name | Type | Mandatory | Description |
| ---------- | ------- | ---- | ---------------------------------- |
| album | [Album](#album) | Yes | Target album. To place this album to the end, set **album** to null.|
**Error codes**
For details about the error codes, see [Universal Error Codes](../errorcode-universal.md) and [File Management Error Codes](../apis-core-file-kit/errorcode-filemanagement.md).
| ID| Error Message|
| -------- | ---------------------------------------- |
| 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. |
**Example**
For details about how to create a phAccessHelper instance, see the example provided in [@ohos.file.photoAccessHelper (Album Management)](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
Removes this group photo album.
**System API**: This is a system API.
**System capability**: SystemCapability.FileManagement.PhotoAccessHelper.Core
**Error codes**
For details about the error codes, see [Universal Error Codes](../errorcode-universal.md) and [File Management Error Codes](../apis-core-file-kit/errorcode-filemanagement.md).
| ID | Error Message |
| :------- | :-------------------------------- |
| 202 | Called by non-system application. |
| 401 | Parameter error. Possible causes: Incorrect parameter types. |
| 14000011 | System inner fail. |
**Example**
For details about how to create a phAccessHelper instance, see the example provided in [@ohos.file.photoAccessHelper (Album Management)](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+
Provides APIs for managing the **Highlights** album, which is an automatically generated collection of memorable photos or videos.
**System API**: This is a system API.
**System capability**: SystemCapability.FileManagement.PhotoAccessHelper.Core
### constructor12+
constructor(album: Album)
A constructor used to create a **Highlights** album instance.
**System API**: This is a system API.
**System capability**: SystemCapability.FileManagement.PhotoAccessHelper.Core
**Parameters**
| Name | Type | Mandatory| Description |
| -------- | ------------------------- | ---- | ---------- |
| album | [Album](#album) | Yes | **Highlights** album to create.|
**Error codes**
For details about the error codes, see [Universal Error Codes](../errorcode-universal.md) and [File Management Error Codes](../apis-core-file-kit/errorcode-filemanagement.md).
| ID| Error Message|
| -------- | ---------------------------------------- |
| 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. |
**Example**
```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>
Obtains specific information about the **Highlights** album.
**System API**: This is a system API.
**Required permissions**: ohos.permission.READ\_IMAGEVIDEO
**System capability**: SystemCapability.FileManagement.PhotoAccessHelper.Core
**Parameters**
| Name | Type | Mandatory | Description |
| ---------- | ------- | ---- | ---------------------------------- |
| type | [HighlightAlbumInfoType](#highlightalbuminfotype12) | Yes | Type of the album information to obtain.|
**Return value**
| Type | Description |
| --------------------------- | -------------- |
| Promise<string> | Promise used to return the album information.|
**Error codes**
For details about the error codes, see [Universal Error Codes](../errorcode-universal.md) and [File Management Error Codes](../apis-core-file-kit/errorcode-filemanagement.md).
| ID | Error Message |
| :------- | :-------------------------------- |
| 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. |
**Example**
```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>
Obtains the ArrayBuffer for caching the specified asset.
**System API**: This is a system API.
**Required permissions**: ohos.permission.READ\_IMAGEVIDEO
**System capability**: SystemCapability.FileManagement.PhotoAccessHelper.Core
**Parameters**
| Name | Type | Mandatory | Description |
| ---------- | ------- | ---- | ---------------------------------- |
| resourceUri | string | Yes | URI of the asset to cache.|
**Return value**
| Type | Description |
| --------------------------- | -------------- |
| Promise<ArrayBuffer> | Promise used to return the ArrayBuffer.|
**Error codes**
For details about the error codes, see [Universal Error Codes](../errorcode-universal.md) and [File Management Error Codes](../apis-core-file-kit/errorcode-filemanagement.md).
| ID | Error Message |
| :------- | :-------------------------------- |
| 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. |
**Example**
```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>
Sets the user behavior data for the **Highlights** album.
**System API**: This is a system API.
**Required permissions**: ohos.permission.WRITE\_IMAGEVIDEO
**System capability**: SystemCapability.FileManagement.PhotoAccessHelper.Core
**Parameters**
| Name | Type | Mandatory | Description |
| ---------- | ------- | ---- | ---------------------------------- |
| type | [HighlightUserActionType](#highlightuseractiontype12) | Yes | Type of the user behavior data to set.|
| actionData | number | Yes | Behavior data.|
**Return value**
| Type | Description |
| --------------------------- | -------------- |
| Promise<void> | Promise that returns no value.|
**Error codes**
For details about the error codes, see [Universal Error Codes](../errorcode-universal.md) and [File Management Error Codes](../apis-core-file-kit/errorcode-filemanagement.md).
| ID | Error Message |
| :------- | :-------------------------------- |
| 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. |
**Example**
```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
Sets the subtitle for this **Highlights** album instance.
The subtitle must meet the following requirements:
- The subtitle string contains 0 to 255 characters.
- The subtitle cannot contain any of the following characters:
. \ / : * ? " ' ` < > | { } [ ]
- The subtitle is case-insensitive.
**System API**: This is a system API.
**Required permissions**: ohos.permission.WRITE\_IMAGEVIDEO
**System capability**: SystemCapability.FileManagement.PhotoAccessHelper.Core
**Parameters**
| Name | Type | Mandatory | Description |
| ---------- | ------- | ---- | ---------------------------------- |
| title | string | Yes | Subtitle to set.|
**Error codes**
For details about the error codes, see [Universal Error Codes](../errorcode-universal.md) and [File Management Error Codes](../apis-core-file-kit/errorcode-filemanagement.md).
| ID | Error Message |
| :------- | :-------------------------------- |
| 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. |
**Example**
```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>
Deletes highlight albums.
**System API**: This is a system API.
**Required permissions**: ohos.permission.WRITE\_IMAGEVIDEO
**System capability**: SystemCapability.FileManagement.PhotoAccessHelper.Core
**Parameters**
| Name | Type | Mandatory | Description |
| ---------- | ------- | ---- | ---------------------------------- |
| context | [Context](../apis-ability-kit/js-apis-inner-application-context.md) | Yes | Context of the ability instance.|
| albums | Array<[Album](#album)> | Yes | Array of highlight albums to delete.|
**Return value**
| Type | Description |
| :------------------ | :---------------------------------- |
| Promise<number> | Promise used to return the operation result. The value **0** means that the operation is successful, and **1** means the opposite.|
**Error codes**
For details about the error codes, see [Universal Error Codes](../errorcode-universal.md) and [File Management Error Codes](../apis-core-file-kit/errorcode-filemanagement.md).
| ID | Error Message |
| :------- | :-------------------------------- |
| 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. |
**Example**
```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+
Provides APIs for managing the analysis album change request.
**System capability**: SystemCapability.FileManagement.PhotoAccessHelper.Core
### constructor18+
constructor(album: Album)
A constructor used to create an **Analysis** album instance.
**System API**: This is a system API.
**System capability**: SystemCapability.FileManagement.PhotoAccessHelper.Core
**Parameters**
| Name | Type | Mandatory | Description |
| ---------- | ------- | ---- | ---------------------------------- |
| album | [Album](#album) | Yes | **Analysis** album to create.|
**Error codes**
For details about the error codes, see [Universal Error Codes](../errorcode-universal.md) and [File Management Error Codes](../apis-core-file-kit/errorcode-filemanagement.md).
| ID| Error Message|
| -------- | ---------------------------------------- |
| 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. |
**Example**
```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
Sets the sequence of assets in the **Analysis** album.
**System API**: This is a system API.
**Required permissions**: ohos.permission.WRITE\_IMAGEVIDEO
**System capability**: SystemCapability.FileManagement.PhotoAccessHelper.Core
**Parameters**
| Name | Type | Mandatory | Description |
| ---------- | ------- | ---- | ---------------------------------- |
| assets | Array<[PhotoAsset](#photoasset)> | Yes | Assets in the album for which the sequence needs to be set.|
| position | Array<number> | Yes | Sequence of assets in the album.|
**Error codes**
For details about the error codes, see [Universal Error Codes](../errorcode-universal.md) and [File Management Error Codes](../apis-core-file-kit/errorcode-filemanagement.md).
| ID | Error Message |
| :------- | :-------------------------------- |
| 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. |
**Example**
```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+
**Analysis** album to create.
**System capability**: SystemCapability.FileManagement.PhotoAccessHelper.Core
### constructor18+
constructor(album: Album)
A constructor used to create an **Analysis** album instance.
**System API**: This is a system API.
**System capability**: SystemCapability.FileManagement.PhotoAccessHelper.Core
**Parameters**
| Name | Type | Mandatory | Description |
| ---------- | ------- | ---- | ---------------------------------- |
| album | [Album](#album) | Yes | **Analysis** album to create.|
**Error codes**
For details about the error codes, see [Universal Error Codes](../errorcode-universal.md) and [File Management Error Codes](../apis-core-file-kit/errorcode-filemanagement.md).
| ID| Error Message|
| -------- | ---------------------------------------- |
| 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. |
**Example**
```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>>
Obtains the sequence of assets in the **Analysis** album.
**System API**: This is a system API.
**Required permissions**: ohos.permission.READ\_IMAGEVIDEO
**System capability**: SystemCapability.FileManagement.PhotoAccessHelper.Core
**Parameters**
| Name | Type | Mandatory | Description |
| ---------- | ------- | ---- | ---------------------------------- |
| assets | Array<[PhotoAsset](#photoasset)> | Yes | Assets in the album whose sequence needs to be obtained.|
**Return value**
| Type | Description |
| :------------------ | :---------------------------------- |
| Promise<Array<number>> | Sequence number of an asset in the album.|
**Error codes**
For details about the error codes, see [Universal Error Codes](../errorcode-universal.md) and [File Management Error Codes](../apis-core-file-kit/errorcode-filemanagement.md).
| ID | Error Message |
| :------- | :-------------------------------- |
| 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. |
**Example**
```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+
Provides APIs for cloud enhancement management, including managing the tasks of generating AI-powered cloud-enhanced photos and obtaining the association between the original photos and AI cloud-enhanced photos.
**System API**: This is a system API.
**System capability**: SystemCapability.FileManagement.PhotoAccessHelper.Core
### getCloudEnhancementInstance13+
static getCloudEnhancementInstance(context: Context): CloudEnhancement
Obtains a cloud enhancement instance.
**System API**: This is a system API.
**System capability**: SystemCapability.FileManagement.PhotoAccessHelper.Core
**Parameters**
| Name | Type | Mandatory| Description |
| -------- | ------------------------- | ---- | ---------- |
| context | [Context](../apis-ability-kit/js-apis-inner-application-context.md) | Yes | Context of the ability instance.|
**Return value**
| Type | Description |
| --------------------------------------- | ----------------- |
| [CloudEnhancement](#cloudenhancement13) | A cloud enhancement instance.|
**Error codes**
For details about the error codes, see [Universal Error Codes](../errorcode-universal.md) and [File Management Error Codes](../apis-core-file-kit/errorcode-filemanagement.md).
| ID| Error Message|
| -------- | ---------------------------------------- |
| 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. |
**Example**
```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>
Submits cloud enhancement tasks.
**System API**: This is a system API.
**System capability**: SystemCapability.FileManagement.PhotoAccessHelper.Core
**Required permissions**: ohos.permission.WRITE_IMAGEVIDEO
**Parameters**
| Name | Type | Mandatory| Description |
| -------- | ------------------------- | ---- | ---------- |
| photoAssets | Array<[PhotoAsset](#photoasset)> | Yes | [PhotoAsset](#photoasset) to enhance.|
| hasCloudWatermark | boolean | Yes | Whether to add a cloud enhancement watermark to the enhanced images.|
**Return value**
| Type | Description |
| ------------------- | ---------- |
| Promise<void> | Promise that returns no value.|
**Error codes**
For details about the error codes, see [Universal Error Codes](../errorcode-universal.md) and [File Management Error Codes](../apis-core-file-kit/errorcode-filemanagement.md).
| ID| Error Message|
| -------- | ---------------------------------------- |
| 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. |
**Example**
For details about how to create a phAccessHelper instance, see the example provided in [@ohos.file.photoAccessHelper (Album Management)](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>
Submits cloud enhancement tasks.
**System API**: This is a system API.
**System capability**: SystemCapability.FileManagement.PhotoAccessHelper.Core
**Required permissions**: ohos.permission.WRITE_IMAGEVIDEO
**Parameters**
| Name | Type | Mandatory| Description |
| -------- | ------------------------- | ---- | ---------- |
| photoAssets | Array<[PhotoAsset](#photoasset)> | Yes | [PhotoAsset](#photoasset) to enhance.|
| hasCloudWatermark | boolean | Yes | Whether to add a cloud watermark to the enhanced image. **true** to add, **false** otherwise.|
| triggerMode | number | No | Trigger mode of the cloud enhancement task.
**- 0**: manually triggered.
**- 1**: automatically triggered.
The default value is **0**.|
**Return value**
| Type | Description |
| ------------------- | ---------- |
| Promise<void> | Promise that returns no value.|
**Error codes**
For details about the error codes, see [Universal Error Codes](../errorcode-universal.md) and [File Management Error Codes](../apis-core-file-kit/errorcode-filemanagement.md).
| ID| Error Message|
| -------- | ---------------------------------------- |
| 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. |
**Example**
For details about how to create a phAccessHelper instance, see the example provided in [@ohos.file.photoAccessHelper (Album Management)](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>
Prioritizes a cloud enhancement task.
**System API**: This is a system API.
**System capability**: SystemCapability.FileManagement.PhotoAccessHelper.Core
**Required permissions**: ohos.permission.WRITE_IMAGEVIDEO
**Parameters**
| Name | Type | Mandatory| Description |
| -------- | ------------------------- | ---- | ---------- |
| photoAsset | [PhotoAsset](#photoasset) | Yes | [PhotoAsset](#photoasset) whose cloud enhancement priority needs to be escalated.|
**Return value**
| Type | Description |
| ------------------- | ---------- |
| Promise<void> | Promise that returns no value.|
**Error codes**
For details about the error codes, see [Universal Error Codes](../errorcode-universal.md) and [File Management Error Codes](../apis-core-file-kit/errorcode-filemanagement.md).
| ID| Error Message|
| -------- | ---------------------------------------- |
| 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. |
**Example**
For details about how to create a phAccessHelper instance, see the example provided in [@ohos.file.photoAccessHelper (Album Management)](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();
// Obtain the cloud enhancement tasks in progress.
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>
Cancels cloud enhancement tasks.
**System API**: This is a system API.
**System capability**: SystemCapability.FileManagement.PhotoAccessHelper.Core
**Required permissions**: ohos.permission.WRITE_IMAGEVIDEO
**Parameters**
| Name | Type | Mandatory| Description |
| -------- | ------------------------- | ---- | ---------- |
| photoAssets | Array<[PhotoAsset](#photoasset)> | Yes | Array of [PhotoAssets](#photoasset) whose cloud enhancement tasks are to be canceled.|
**Return value**
| Type | Description |
| ------------------- | ---------- |
| Promise<void> | Promise that returns no value.|
**Error codes**
For details about the error codes, see [Universal Error Codes](../errorcode-universal.md) and [File Management Error Codes](../apis-core-file-kit/errorcode-filemanagement.md).
| ID| Error Message|
| -------- | ---------------------------------------- |
| 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. |
**Example**
For details about how to create a phAccessHelper instance, see the example provided in [@ohos.file.photoAccessHelper (Album Management)](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();
// Obtain the cloud enhancement tasks in progress.
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>
Cancels all cloud enhancement tasks.
**System API**: This is a system API.
**System capability**: SystemCapability.FileManagement.PhotoAccessHelper.Core
**Required permissions**: ohos.permission.WRITE_IMAGEVIDEO
**Return value**
| Type | Description |
| ------------------- | ---------- |
| Promise<void> | Promise that returns no value.|
**Error codes**
For details about the error codes, see [Universal Error Codes](../errorcode-universal.md) and [File Management Error Codes](../apis-core-file-kit/errorcode-filemanagement.md).
| ID| Error Message|
| -------- | ---------------------------------------- |
| 201 | Permission denied. |
| 202 | Called by non-system application. |
| 14000011 | Internal system error. |
**Example**
```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>
Queries information about a cloud enhancement task.
**System API**: This is a system API.
**System capability**: SystemCapability.FileManagement.PhotoAccessHelper.Core
**Required permissions**: ohos.permission.READ_IMAGEVIDEO
**Parameters**
| Name | Type | Mandatory| Description |
| -------- | ------------------------- | ---- | ---------- |
| photoAsset | [PhotoAsset](#photoasset) | Yes | [PhotoAsset](#photoasset) whose cloud enhancement task information is to be queried.|
**Return value**
| Type | Description |
| --------------------------------------- | ----------------- |
| Promise<[CloudEnhancementTaskState](#cloudenhancementtaskstate13)> | Promise used to return the information about the cloud enhancement task.|
**Error codes**
For details about the error codes, see [Universal Error Codes](../errorcode-universal.md) and [File Management Error Codes](../apis-core-file-kit/errorcode-filemanagement.md).
| ID| Error Message|
| -------- | ---------------------------------------- |
| 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. |
**Example**
For details about how to create a phAccessHelper instance, see the example provided in [@ohos.file.photoAccessHelper (Album Management)](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();
// Obtain the cloud enhancement tasks in progress.
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>
Synchronizes the cloud enhancement task status.
**System API**: This is a system API.
**System capability**: SystemCapability.FileManagement.PhotoAccessHelper.Core
**Required permissions**: ohos.permission.READ_IMAGEVIDEO
**Return value**
| Type | Description |
| ------------------- | ---------- |
| Promise<void> | Promise that returns no value.|
**Error codes**
For details about the error codes, see [Universal Error Codes](../errorcode-universal.md) and [File Management Error Codes](../apis-core-file-kit/errorcode-filemanagement.md).
| ID| Error Message|
| -------- | ---------------------------------------- |
| 201 | Permission denied. |
| 202 | Called by non-system application. |
| 14000011 | Internal system error. |
**Example**
```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>
Obtains the photo after cloud enhancement.
**System API**: This is a system API.
**System capability**: SystemCapability.FileManagement.PhotoAccessHelper.Core
**Required permissions**: ohos.permission.READ_IMAGEVIDEO
**Parameters**
| Name | Type | Mandatory| Description |
| -------- | ------------------------- | ---- | ---------- |
| photoAsset | [PhotoAsset](#photoasset) | Yes | [PhotoAsset](#photoasset) for which the cloud-enhanced photo is to be obtained.|
**Return value**
| Type | Description |
| --------------------------------------- | ----------------- |
| Promise<[PhotoAsset](#photoasset)> | Promise used to return the photo after cloud enhancement.|
**Error codes**
For details about the error codes, see [Universal Error Codes](../errorcode-universal.md) and [File Management Error Codes](../apis-core-file-kit/errorcode-filemanagement.md).
| ID| Error Message|
| -------- | ---------------------------------------- |
| 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. |
**Example**
For details about how to create a phAccessHelper instance, see the example provided in [@ohos.file.photoAccessHelper (Album Management)](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();
// Query the completed cloud enhancement tasks.
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>
Sets the attributes for deferred video enhancement.
**System API**: This is a system API.
**Required permissions**: ohos.permission.WRITE\_IMAGEVIDEO
**System capability**: SystemCapability.FileManagement.PhotoAccessHelper.Core
**Parameters**
| Name | Type | Mandatory | Description |
| ---------- | ------- | ---- | ---------------------------------- |
| videoEnhancementType | [VideoEnhancementType](#videoenhancementtype13) | Yes | Type of video enhancement.|
| photoId | string | Yes | Photo ID of the image.|
**Return value**
| Type | Description |
| ------------------- | ---------- |
| Promise<void> | Promise that returns no value.|
**Error codes**
For details about the error codes, see [Universal Error Codes](../errorcode-universal.md) and [File Management Error Codes](../apis-core-file-kit/errorcode-filemanagement.md).
| ID | Error Message |
| :------- | :-------------------------------- |
| 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. |
**Example**
For details about how to create a phAccessHelper instance, see the example provided in [@ohos.file.photoAccessHelper (Album Management)](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+
A class used for cloud media asset management. It is used to manage download tasks for media assets stored in the cloud and delete local data and files pertaining to these cloud-based assets.
**System API**: This is a system API.
**System capability**: SystemCapability.FileManagement.PhotoAccessHelper.Core
### getCloudMediaAssetManagerInstance14+
static getCloudMediaAssetManagerInstance(context: Context): CloudMediaAssetManager
Obtains a CloudMediaAssetManager instance.
**System API**: This is a system API.
**System capability**: SystemCapability.FileManagement.PhotoAccessHelper.Core
**Parameters**
| Name | Type | Mandatory| Description |
| -------- | ------------------------- | ---- | ---------- |
| context | [Context](../apis-ability-kit/js-apis-inner-application-context.md) | Yes | Context of the ability instance.|
**Return value**
| Type | Description |
| --------------------------------------- | ----------------- |
| [CloudMediaAssetManager](#cloudmediaassetmanager14) | CloudMediaAssetManager instance.|
**Error codes**
For details about the error codes, see [Universal Error Codes](../errorcode-universal.md) and [File Management Error Codes](../apis-core-file-kit/errorcode-filemanagement.md).
| ID| Error Message|
| -------- | ---------------------------------------- |
| 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. |
**Example**
```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>
Starts or resumes a task to download cloud media assets.
**System API**: This is a system API.
**System capability**: SystemCapability.FileManagement.PhotoAccessHelper.Core
**Required permissions**: ohos.permission.CLOUDFILE_SYNC_MANAGER
**Parameters**
| Name | Type | Mandatory| Description |
| -------- | ------------------------- | ---- | ---------- |
| downloadType | [CloudMediaDownloadType](#cloudmediadownloadtype14) | Yes | Type of the download task.|
**Return value**
| Type | Description |
| --------------------------------------- | ----------------- |
| Promise<void>| Promise that returns no value.|
**Error codes**
For details about the error codes, see [Universal Error Codes](../errorcode-universal.md) and [File Management Error Codes](../apis-core-file-kit/errorcode-filemanagement.md).
| ID| Error Message|
| -------- | ---------------------------------------- |
| 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. |
**Example**
```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>
Suspends a task that downloads cloud media assets.
**System API**: This is a system API.
**System capability**: SystemCapability.FileManagement.PhotoAccessHelper.Core
**Required permissions**: ohos.permission.CLOUDFILE_SYNC_MANAGER
**Return value**
| Type | Description |
| --------------------------------------- | ----------------- |
| Promise<void>| Promise that returns no value.|
**Error codes**
For details about the error codes, see [Universal Error Codes](../errorcode-universal.md) and [File Management Error Codes](../apis-core-file-kit/errorcode-filemanagement.md).
| ID| Error Message|
| -------- | ---------------------------------------- |
| 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. |
**Example**
```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>
Cancels a task that downloads cloud media assets.
**System API**: This is a system API.
**System capability**: SystemCapability.FileManagement.PhotoAccessHelper.Core
**Required permissions**: ohos.permission.CLOUDFILE_SYNC_MANAGER
**Return value**
| Type | Description |
| --------------------------------------- | ----------------- |
| Promise<void>| Promise that returns no value.|
**Error codes**
For details about the error codes, see [Universal Error Codes](../errorcode-universal.md) and [File Management Error Codes](../apis-core-file-kit/errorcode-filemanagement.md).
| ID| Error Message|
| -------- | ---------------------------------------- |
| 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. |
**Example**
```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>
Deletes local metadata and files of cloud media assets.
**System API**: This is a system API.
**System capability**: SystemCapability.FileManagement.PhotoAccessHelper.Core
**Required permissions**: ohos.permission.CLOUDFILE_SYNC_MANAGER
**Parameters**
| Name | Type | Mandatory| Description |
| -------- | ------------------------- | ---- | ---------- |
| retainType | [CloudMediaRetainType](#cloudmediaretaintype14) | Yes | Mode for deleting cloud media assets.|
**Return value**
| Type | Description |
| --------------------------------------- | ----------------- |
| Promise<void>| Promise that returns no value.|
**Error codes**
For details about the error codes, see [Universal Error Codes](../errorcode-universal.md) and [File Management Error Codes](../apis-core-file-kit/errorcode-filemanagement.md).
| ID| Error Message|
| -------- | ---------------------------------------- |
| 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. |
**Example**
```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>
Obtains the status of a task that downloads cloud media assets.
**System API**: This is a system API.
**System capability**: SystemCapability.FileManagement.PhotoAccessHelper.Core
**Required permissions**: ohos.permission.READ_IMAGEVIDEO
**Return value**
| Type | Description |
| --------------------------------------- | ----------------- |
|Promise<[CloudMediaAssetStatus](#cloudmediaassetstatus14)> | Promise used to return the task status.|
**Error codes**
For details about the error codes, see [Universal Error Codes](../errorcode-universal.md) and [File Management Error Codes](../apis-core-file-kit/errorcode-filemanagement.md).
| ID| Error Message|
| -------- | ---------------------------------------- |
| 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. |
**Example**
```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+
Provides APIs for managing a moving photo instance.
### isVideoReady20+
isVideoReady(): Promise<boolean>
Checks whether the video of the moving photo is ready. This API uses a promise to return the result.
**System API**: This is a system API.
**System capability**: SystemCapability.FileManagement.PhotoAccessHelper.Core
**Required permissions**: ohos.permission.READ_IMAGEVIDEO
**Return value**
| Type | Description |
| --------------------------------------- | ----------------- |
| Promise<boolean> | Promise used to return the result. **true** if the video of the moving photo is ready, **false** otherwise.|
**Error codes**
For details about the error codes, see [Universal Error Codes](../errorcode-universal.md) and [Media Library Error Codes](errcode-medialibrary.md).
| ID| Error Message|
| -------- | ---------------------------------------- |
| 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. |
**Example**
For details about how to create a phAccessHelper instance, see the example provided in [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
};
// Ensure that there are moving photos in Gallery.
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+
Provides APIs for custom user behavior recording for Gallery.
**System API**: This is a system API.
### getCustomRecordManagerInstance20+
static getCustomRecordManagerInstance(context: Context): PhotoAssetCustomRecordManager
Obtains an instance of custom user behavior recording for Gallery.
**System API**: This is a system API.
**System capability**: SystemCapability.FileManagement.PhotoAccessHelper.Core
**Parameters**
| Name| Type| Mandatory| Description|
| --- | --- | --- | --- |
| context | [Context](../apis-ability-kit/js-apis-inner-application-context.md#context) | Yes| Context of the ability instance.|
**Return value**
| Type| Description|
| --- | --- |
| [PhotoAssetCustomRecordManager](#photoassetcustomrecordmanager20) | Custom user behavior recording instance.|
**Error codes**
For details about the error codes, see [Universal Error Codes](../errorcode-universal.md) and [Media Library Error Codes](errcode-medialibrary.md).
| ID| Error Message|
| --- | --- |
| 202 | Called by non-system application. |
| 23800107 | Context is invalid. |
**Example**
```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>
Adds custom user behavior recordings. This API uses a promise to return the result.
**System API**: This is a system API.
**System capability**: SystemCapability.FileManagement.PhotoAccessHelper.Core
**Parameters**
| Name| Type| Mandatory| Description|
| --- | --- | --- | --- |
| customRecords | Array<[PhotoAssetCustomRecord](#photoassetcustomrecord20)> | Yes| Custom user behavior recordings.|
**Return value**
| Type| Description|
| --- | --- |
| Promise<void> | Promise that returns no value.|
**Error codes**
For details about the error codes, see [Universal Error Codes](../errorcode-universal.md) and [Media Library Error Codes](errcode-medialibrary.md).
| ID| Error Message|
| --- | --- |
| 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. |
**Example**
```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>>
Obtains custom user behavior recordings based on retrieval options. This API uses a promise to return the result.
**System API**: This is a system API.
**System capability**: SystemCapability.FileManagement.PhotoAccessHelper.Core
**Parameters**
| Name| Type| Mandatory| Description|
| --- | --- | --- | --- |
| optionCheck | [FetchOptions](js-apis-photoAccessHelper.md#fetchoptions) | Yes| Retrieval options.|
**Return value**
| Type| Description|
| --- | --- |
| Promise<FetchResult<[PhotoAssetCustomRecord](#photoassetcustomrecord20)>> | Promise used to return the collection of custom user behavior recordings.|
**Error codes**
For details about the error codes, see [Universal Error Codes](../errorcode-universal.md) and [Media Library Error Codes](errcode-medialibrary.md).
| ID| Error Message|
| --- | --- |
| 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. |
**Example**
```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>>
Updates the existing database fields based on custom user behavior recordings. This API uses a promise to return the result.
**System API**: This is a system API.
**System capability**: SystemCapability.FileManagement.PhotoAccessHelper.Core
**Parameters**
| Name| Type| Mandatory| Description|
| --- | --- | --- | --- |
| customRecords | Array<[PhotoAssetCustomRecord](#photoassetcustomrecord20)> | Yes| Custom user behavior recordings.|
**Return value**
| Type| Description|
| --- | --- |
| Promise<Array<number>> | Promise used to return the file ID in the custom user behavior recordings that fail to be updated.|
**Error codes**
For details about the error codes, see [Universal Error Codes](../errorcode-universal.md) and [Media Library Error Codes](errcode-medialibrary.md).
| ID| Error Message|
| --- | --- |
| 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. |
**Example**
```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>
Removes custom user behavior recordings based on retrieval options. This API uses a promise to return the result.
**System API**: This is a system API.
**System capability**: SystemCapability.FileManagement.PhotoAccessHelper.Core
**Parameters**
| Name| Type| Mandatory| Description|
| --- | --- | --- | --- |
| optionCheck | [FetchOptions](js-apis-photoAccessHelper.md#fetchoptions) | Yes| Retrieval options.|
**Return value**
| Type| Description|
| --- | --- |
| Promise<void> | Promise that returns no value.|
**Error codes**
For details about the error codes, see [Universal Error Codes](../errorcode-universal.md) and [Media Library Error Codes](errcode-medialibrary.md).
| ID| Error Message|
| --- | --- |
| 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. |
**Example**
```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>>
Increases the value of **shareCount** by 1 for the data in the database based on **fileId** in [PhotoAssetCustomRecord](#photoassetcustomrecord20). This API uses a promise to return the result.
**System API**: This is a system API.
**System capability**: SystemCapability.FileManagement.PhotoAccessHelper.Core
**Parameters**
| Name| Type| Mandatory| Description|
| --- | --- | --- | --- |
| ids | Array<number> | Yes| Array of file IDs in [PhotoAssetCustomRecord](#photoassetcustomrecord20).|
**Return value**
| Type| Description|
| --- | --- |
| Promise<Array<number>> | Promise used to return the file ID in the custom user behavior recordings that fail to be updated.|
**Error codes**
For details about the error codes, see [Universal Error Codes](../errorcode-universal.md) and [Media Library Error Codes](errcode-medialibrary.md).
| ID| Error Message|
| --- | --- |
| 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>>
Increases the value of **LcdJumpCount** by 1 for the data in the database based on **fileId** in [PhotoAssetCustomRecord](#photoassetcustomrecord20). This API uses a promise to return the result.
**System API**: This is a system API.
**System capability**: SystemCapability.FileManagement.PhotoAccessHelper.Core
**Parameters**
| Name| Type| Mandatory| Description|
| --- | --- | --- | --- |
| ids | Array<number> | Yes| Array of file IDs in [PhotoAssetCustomRecord](#photoassetcustomrecord20).|
**Return value**
| Type| Description|
| --- | --- |
| Promise<Array<number>> | Promise used to return the file ID in the custom user behavior recordings that fail to be updated.|
**Error codes**
For details about the error codes, see [Universal Error Codes](../errorcode-universal.md) and [Media Library Error Codes](errcode-medialibrary.md).
| ID| Error Message|
| --- | --- |
| 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
Defines additional options for selecting media assets from Gallery. It inherits from **BaseSelectOptions**. It is used to start the picker of the corresponding user ID space.
**System capability**: SystemCapability.FileManagement.PhotoAccessHelper.Core
| Name| Type| Mandatory| Description|
| -------- | -------- | -------- | -------- |
| userId18+ | number | No | ID of the user space to access. The default value is **-1**.
To use it as a parameter of [PhotoViewPicker.select](arkts-apis-photoAccessHelper-PhotoViewPicker.md#select), request the permission ohos.permission.INTERACTA_CROSS_LOCAL_ACCOUNTS.
**System API**: This is a system API.|
**Example**
```ts
async function photoPicker() {
let picker = new photoAccessHelper.PhotoViewPicker();
let option = new photoAccessHelper.PhotoSelectOptions();
option.userId = 101;
picker.select(option);
}
```
## PhotoSubtype
Enumerates the [PhotoAsset](#photoasset) types.
**System capability**: SystemCapability.FileManagement.PhotoAccessHelper.Core
| Name | Value| Description|
| ----- | ---- | ---- |
| SCREENSHOT | 1 | Screenshot and screen recording file.
**System API**: This is a system API.|
## AlbumType
Enumerates the album types.
**System capability**: SystemCapability.FileManagement.PhotoAccessHelper.Core
| Name | Value | Description |
| ------------------- | ---- | ------------------------- |
| SOURCE18+ | 2048 | Source album.
**System API**: This is a system API.|
| SMART11+ | 4096 | Smart analysis album.
**System API**: This is a system API.|
## AlbumSubtype
Enumerate the album subtypes.
**System capability**: SystemCapability.FileManagement.PhotoAccessHelper.Core
| Name | Value | Description |
| --------------------------------- | ---------- | ------------------------------- |
| HIDDEN | 1027 | Hidden album. **System API**: This is a system API. |
| TRASH | 1028 | Trash. **System API**: This is a system API. |
| SCREENSHOT | 1029 | Album for screenshots and screen recording files. **System API**: This is a system API. |
| CAMERA | 1030 | Album for photos and videos taken by the camera. **System API**: This is a system API.|
| SOURCE\_GENERIC11+ | 2049 | Source album. **System API**: This is a system API. |
| CLASSIFY11+ | 4097 | Classified album. **System API**: This is a system API. |
| GEOGRAPHY\_LOCATION11+ | 4099 | Geographic location album. **System API**: This is a system API. |
| GEOGRAPHY\_CITY11+ | 4100 | City album. **System API**: This is a system API. |
| SHOOTING\_MODE11+ | 4101 | Shooting mode album. **System API**: This is a system API. |
| PORTRAIT11+ | 4102 | Portrait album. **System API**: This is a system API. |
| GROUP_PHOTO13+ | 4103 | Group photo album. **System API**: This is a system API. |
| HIGHLIGHT12+ | 4104 | Highlights album. **System API**: This is a system API. |
| HIGHLIGHT_SUGGESTIONS12+ | 4105 | Highlights suggestion album. **System API**: This is a system API. |
| CLOUD_ENHANCEMENT13+ | 1032 | AI-powered cloud enhanced album. **System API**: This is a system API. |
## RequestPhotoType11+
Enumerates the types of the operation for obtaining image or video thumbnails.
**System API**: This is a system API.
**System capability**: SystemCapability.FileManagement.PhotoAccessHelper.Core
| Name | Value| Description|
| ----- | ---- | ---- |
| REQUEST_ALL_THUMBNAILS | 0 | Obtain both the quick thumbnail and the quality thumbnail.|
| REQUEST_FAST_THUMBNAIL | 1 | Obtain only the quick thumbnail.|
| REQUEST_QUALITY_THUMBNAIL | 2 | Obtain only the quality thumbnail.|
## PhotoKeys
Defines the key information about an image or video file.
**System capability**: SystemCapability.FileManagement.PhotoAccessHelper.Core
| Name | Value | Description |
| ------------- | ------------------- | ---------------------------------------------------------- |
| DATE_TRASHED | 'date_trashed' | Date when the file was deleted. The value is the number of seconds elapsed since the Epoch time. **System API**: This is a system API. |
| HIDDEN | 'hidden' | Whether the file is hidden. **System API**: This is a system API. |
| CAMERA_SHOT_KEY | 'camera_shot_key' | Key for the Ultra Snapshot feature, which allows the camera to take photos or record videos with the screen off. (This parameter is available only for the system camera, and the key value is defined by the system camera.) **System API**: This is a system API. |
| USER_COMMENT10+ | 'user_comment' | User comment information. **System API**: This is a system API. |
| DATE_YEAR11+ | 'date_year' | Year when the file was created. **System API**: This is a system API. |
| DATE_MONTH11+ | 'date_month' | Month when the file was created. **System API**: This is a system API. |
| DATE_DAY11+ | 'date_day' | Date when the file was created. **System API**: This is a system API. |
| PENDING11+ | 'pending' | Pending state. **System API**: This is a system API. |
| DATE_TRASHED_MS12+ | 'date_trashed_ms' | Date when the file was deleted. The value is the number of milliseconds elapsed since the Epoch time. **System API**: This is a system API.
**NOTE**: The photos queried cannot be sorted based on this field.|
| MOVING_PHOTO_EFFECT_MODE12+ | 'moving_photo_effect_mode' | Effect of the moving photo. **System API**: This is a system API.|
| CE_AVAILABLE13+ | 'ce_available' | Cloud enhancement identifier. **System API**: This is a system API.|
| SUPPORTED_WATERMARK_TYPE14+ | 'supported_watermark_type' | Editable watermark identifier. **System API**: This is a system API.|
| IS_CE_AUTO18+ | 'is_auto' | Specifies whether automatic cloud enhancement is supported. **System API**: This is a system API.|
| OWNER_ALBUM_ID18+ | 'owner_album_id' | ID of the album to which the photo belongs. **System API**: This is a system API.|
| IS_RECENT_SHOW18+ | 'is_recent_show' | Whether the asset is displayed in the **Recent** list. **System API**: This is a system API.|
| SUM_SIZE19+ | 'sum(size)' | Total size of files. When **SUM_SIZE** is filled in **fetchColumns**, only the first asset is obtained, and the property includes the total size of all assets. **System API**: This is a system API.|
| EXIF_ROTATE20+ | 'exif_rotate' | Rotational angle of the file. **System API**: This is a system API.|
## AlbumKeys
Enumerates the album keys.
**System capability**: SystemCapability.FileManagement.PhotoAccessHelper.Core
| Name | Value | Description |
| --------------------------------- | -------------------- | ----------------------------------------------------- |
| ALBUM_LPATH18+ | 'lpath' | Virtual path of the album.
**System API**: This is a system API. |
| BUNDLE_NAME18+ | 'bundle_name' | Bundle name of the album.
**System API**: This is a system API. |
| DATE_MODIFIED18+ | 'date_modified' | Timestamp when the album was modified, in milliseconds.
**System API**: This is a system API. |
| COVER_URI_SOURCE20+ | 'cover_uri_source' | Source URI of the album cover.
**System API**: This is a system API. |
## HiddenPhotosDisplayMode11+
Enumerates the display modes of hidden files in the system.
**System API**: This is a system API.
**System capability**: SystemCapability.FileManagement.PhotoAccessHelper.Core
| Name | Value | Description |
| ------------- | ------------------- | ---------------------------------------------------------- |
| ASSETS_MODE | 0 | Display all hidden files in the system. |
| ALBUMS_MODE | 1 | Display hidden files by album (display all albums that contain hidden files in the system, excluding the preset hidden album and the albums in the trash). |
## PhotoCreateOptions
Options for creating an image or video asset.
**System API**: This is a system API.
**System capability**: SystemCapability.FileManagement.PhotoAccessHelper.Core
| Name | Type | Mandatory| Description |
| ---------------------- | ------------------- | ---- | ------------------------------------------------ |
| subtype | [PhotoSubtype](#photosubtype) | No | Subtype of the image or video. |
| cameraShotKey | string | No | Key for the Ultra Snapshot feature, which allows the camera to take photos or record videos with the screen off. (This parameter is available only for the system camera, and the key value is defined by the system camera.) |
| userId19+ | number | No | User ID. |
## RequestPhotoOptions11+
Defines the options for obtaining the thumbnail of an image or video.
**System API**: This is a system API.
**System capability**: SystemCapability.FileManagement.PhotoAccessHelper.Core
| Name | Type | Mandatory| Description |
| ---------------------- | ------------------- | ---- | ------------------------------------------------ |
| size | [image.Size](../apis-image-kit/arkts-apis-image-i.md#size) | No | Size of the thumbnail to obtain. |
| requestPhotoType | [RequestPhotoType](#requestphototype11) | No | Operation to perform. |
## PhotoCreationSource18+
Defines the application information provided to create assets on behalf of the application.
**System API**: This is a system API.
**System capability**: SystemCapability.FileManagement.PhotoAccessHelper.Core
| Name | Type | Read-Only| Optional| Description |
| ---------------------- | ------------------- | ---- | ---- | ------------------------------------------------ |
| bundleName | string | Yes | Yes |Bundle name of the target application. |
| appName | string | Yes | Yes |Name of the target application. |
| appId | string | Yes | Yes |ID of the target application. |
| tokenId | number | Yes | Yes |Token ID of the target application. |
## RequestOptions11+
Represents request options.
**System capability**: SystemCapability.FileManagement.PhotoAccessHelper.Core
| Name | Type | Readable| Writable| Description |
| ---------------------- |---------------------------------| ---- |---- | ------------------------------------------------ |
| sourceMode | [SourceMode](#sourcemode11) | Yes | Yes | Type of the asset file requested, which can be the original file or edited file. **System API**: This is a system API.|
## PhotoProxy11+
Photo proxy object, which is used by the camera application to write image data.
**System API**: This is a system API.
**System capability**: SystemCapability.FileManagement.PhotoAccessHelper.Core
## MediaChangeRequest11+
Media change request, which is the parent class of the asset change request and album change request.
**NOTE**: The media change request takes effect only after [applyChanges](arkts-apis-photoAccessHelper-PhotoAccessHelper.md#applychanges11) is called.
**System capability**: SystemCapability.FileManagement.PhotoAccessHelper.Core
## FormInfo11+
Defines the Gallery widget information.
**System API**: This is a system API.
**System capability**: SystemCapability.FileManagement.PhotoAccessHelper.Core
| Name | Type | Mandatory| Description |
| ---------------------- | ------------------- | ---- | ------------------------------------------------ |
|formId |string |Yes| Widget ID, which is provided when a widget is created in Gallery.|
|uri |string |Yes| URI of the image bound to the widget. When a widget is created, **uri** can be empty or the URI of an image. When a widget is removed, **uri** is not verified and can be empty. |
## GalleryFormInfo18+
Defines the Gallery widget information.
**System API**: This is a system API.
**System capability**: SystemCapability.FileManagement.PhotoAccessHelper.Core
| Name | Type | Mandatory| Description |
| ---------------------- | ------------------- | ---- | ------------------------------------------------ |
|formId |string |Yes| Widget ID, which is provided when a widget is created in Gallery.|
|assetUris |Array<string> |Yes| URIs of the images or albums bound to the widget.
This parameter cannot be empty when creating or updating a widget.
If you attempt to create or update a widget with more than 500 URIs in **assetUris**, only the first 500 URIs are registered for listening. Any URIs beyond the first 500 are not registered.
When deleting a widget, this parameter can be omitted. |
## ResourceType11+
Enumerates the types of the resources to write.
**System capability**: SystemCapability.FileManagement.PhotoAccessHelper.Core
| Name | Value| Description|
| ----- | ---- | ---- |
| PHOTO_PROXY | 3 | Photo proxy. **System API**: This is a system API.|
| PRIVATE_MOVING_PHOTO_RESOURCE13+ | 4 | Private moving photo. **System API**: This is a system API.|
| PRIVATE_MOVING_PHOTO_METADATA18+ | 5 | Metadata resource of the private moving photo. **System API**: This is a system API.|
## DefaultChangeUri
Enumerates the **DefaultChangeUri** subtypes.
**System capability**: SystemCapability.FileManagement.PhotoAccessHelper.Core
| Name | Value | Description |
| ----------------- | ----------------------- | ------------------------------------------------------------ |
| DEFAULT_HIDDEN_ALBUM_URI11+ | 'file://media/HiddenAlbum' | URI of an album in the hidden albums that are displayed by album, that is, the URI of an album with hidden files. Such albums do not include the preset hidden album and the albums in the trash. This URI is used to subscribe to the change notifications of the hidden albums displayed by album. **System API**: This is a system API.|
## SourceMode11+
Enumerates the types of the file to read.
**System API**: This is a system API.
**System capability**: SystemCapability.FileManagement.PhotoAccessHelper.Core
| Name | Value| Description|
| ----- | ---- | ---- |
| ORIGINAL_MODE | 0 | Original file.|
| EDITED_MODE | 1 | Edited file.|
## AuthorizationMode12+
Enumerates the authorization modes.
**System API**: This is a system API.
**System capability**: SystemCapability.FileManagement.PhotoAccessHelper.Core
| Name | Value| Description|
| ----- | ---- | ---- |
| SHORT_TIME_AUTHORIZATION| 0 | Temporary authorization.|
## AnalysisType11+
Enumerates the smart analysis types.
**System capability**: SystemCapability.FileManagement.PhotoAccessHelper.Core
| Name | Value | Description |
| :---------------------------- | :- | :------- |
| ANALYSIS\_AESTHETICS\_SCORE | 0 | Aesthetics score. **System API**: This is a system API. |
| ANALYSIS\_LABEL | 1 | Label. **System API**: This is a system API. |
| ANALYSIS\_OCR | 2 | Optical character recognition (OCR) analysis. **System API**: This is a system API. |
| ANALYSIS\_FACE | 3 | Facial detection analysis. **System API**: This is a system API. |
| ANALYSIS\_OBJECT | 4 | Object detection analysis. **System API**: This is a system API. |
| ANALYSIS\_RECOMMENDATION | 5 | Recommendation analysis. **System API**: This is a system API. |
| ANALYSIS\_SEGMENTATION | 6 | Segmentation analysis. **System API**: This is a system API. |
| ANALYSIS\_COMPOSITION | 7 | Aesthetic composition analysis. **System API**: This is a system API. |
| ANALYSIS\_SALIENCY | 8 | Salience analysis. **System API**: This is a system API. |
| ANALYSIS\_DETAIL\_ADDRESS | 9 | Detailed address analysis. **System API**: This is a system API. |
| ANALYSIS\_HUMAN\_FACE\_TAG12+ | 10 | Face clustering analysis. **System API**: This is a system API. |
| ANALYSIS\_HEAD\_POSITION12+ | 11 | Analysis of the position of a person's or pet's head. **System API**: This is a system API. |
| ANALYSIS\_BONE\_POSE12+ | 12 | Analysis of the position of skeletal elements (bones) in a human body. **System API**: This is a system API. |
| ANALYSIS\_VIDEO\_LABEL12+ | 13 | Video label analysis. **System API**: This is a system API. |
| ANALYSIS\_HIGHLIGHT12+ | 14 | Highlight label. **System API**: This is a system API. |
## HighlightAlbumInfoType12+
Enumerates the types of the highlights album information.
**System API**: This is a system API.
**System capability**: SystemCapability.FileManagement.PhotoAccessHelper.Core
| Name | Value | Description |
| :------------ | :- | :------- |
| COVER\_INFO | 0 | Cover information. |
| PLAY\_INFO | 1 | Music information. |
## HighlightUserActionType12+
Enumerates the user behavior types of the highlights album.
**System API**: This is a system API.
**System capability**: SystemCapability.FileManagement.PhotoAccessHelper.Core
| Name | Value | Description |
| :---------------------------- | :- | :------- |
| INSERTED\_PIC\_COUNT | 0 | Number of inserted pictures. |
| REMOVED\_PIC\_COUNT | 1 | Number of removed pictures. |
| SHARED\_SCREENSHOT\_COUNT | 2 | Number of times that a full-length image in a highlights album is shared. |
| SHARED\_COVER\_COUNT | 3 | Number of times that a highlights cover is shared. |
| RENAMED\_COUNT | 4 | Number of times that a highlights album is renamed. |
| CHANGED\_COVER\_COUNT | 5 | Number of times that a cover is changed. |
| RENDER\_VIEWED\_TIMES | 100 | Number of times that the pictures in a highlights album are played. |
| RENDER\_VIEWED\_DURATION | 101 | Time used to play the pictures in a highlights album. |
| ART\_LAYOUT\_VIEWED\_TIMES | 102 | Number of times that a highlights album is viewed. |
| ART\_LAYOUT\_VIEWED\_DURATION | 103 | Time used to view a highlights album. |
## ThumbnailVisibility14+
Enumerates the visibility statuses of thumbnails.
**System API**: This is a system API.
**System capability**: SystemCapability.FileManagement.PhotoAccessHelper.Core
| Name | Value | Description |
| :---------------------------- | :- | :------- |
| INVISIBLE | 0 | The thumbnail is inaccessible. |
| VISIBLE | 1 | The thumbnail is accessible. |
## MovingPhotoEffectMode12+
Enumerates the effects of a moving photo.
**System API**: This is a system API.
**System capability**: SystemCapability.FileManagement.PhotoAccessHelper.Core
| Name | Value | Description |
| :---------------------------- | :- | :------- |
| DEFAULT | 0 | Default effect.|
| BOUNCE\_PLAY | 1 | Back-and-forth motion.|
| LOOP\_PLAY | 2 | Continuously repeated animation.|
| LONG\_EXPOSURE | 3 | Long exposure. |
| MULTI\_EXPOSURE | 4 | Multiple exposures. |
| CINEMA\_GRAPH13+ | 5 | Cinemagraph. |
| IMAGE\_ONLY13+ | 10 | Image only. |
## PhotoPermissionType12+
Enumerates the types of permissions for accessing media assets.
The permissions include temporary read permission and persistent read permission. The temporary read permission will be removed when the application is dead, while the persistent read permission will not.
For the same media asset and application, the persistent read permission overwrites the temporary read permission. The temporary read permission does not overwrite the persistent read permission.
**System API**: This is a system API.
**System capability**: SystemCapability.FileManagement.PhotoAccessHelper.Core
| Name | Value| Description|
| ----- | ---- | ---- |
| TEMPORARY_READ_IMAGEVIDEO | 0 | Temporary read permission.|
| PERSISTENT_READ_IMAGEVIDEO | 1 | Persistent read permission.|
## HideSensitiveType12+
Enumerates the types of media resource information to be hidden from an application.
**System API**: This is a system API.
**System capability**: SystemCapability.FileManagement.PhotoAccessHelper.Core
| Name | Value| Description|
| ----- | ---- | ---- |
| HIDE_LOCATION_AND_SHOOTING_PARAM | 0 | Geographical location and shooting parameters.|
| HIDE_LOCATION_ONLY | 1 | Geographical location information.|
| HIDE_SHOOTING_PARAM_ONLY | 2 | Shooting parameters.|
| NO_HIDE_SENSITIVE_TYPE | 3 | Do not hide any information.|
## CloudEnhancementTaskStage13+
Enumerates the cloud enhancement task states, which are returned by [CloudEnhancementTaskState](#cloudenhancement13).
**System API**: This is a system API.
**System capability**: SystemCapability.FileManagement.PhotoAccessHelper.Core
| Name | Value| Description|
| ----- | ---- | ---- |
| TASK_STAGE_EXCEPTION | -1 | The cloud enhancement task is abnormal.|
| TASK_STAGE_PREPARING | 0 | The cloud enhancement task is being prepared.|
| TASK_STAGE_UPLOADING | 1 | The cloud enhancement task is uploading data.|
| TASK_STAGE_EXECUTING | 2 | The cloud enhancement task is being executed.|
| TASK_STAGE_DOWNLOADING | 3 | The cloud enhancement task is downloading data.|
| TASK_STAGE_FAILED | 4 | The cloud enhancement task failed.|
| TASK_STAGE_COMPLETED | 5 | The cloud enhancement task is complete.|
## CloudEnhancementState13+
Enumerates the cloud enhancement states.
**System API**: This is a system API.
**System capability**: SystemCapability.FileManagement.PhotoAccessHelper.Core
| Name | Value| Description|
| ----- | ---- | ---- |
| UNAVAILABLE | 0 | Cloud enhancement is unavailable.|
| AVAILABLE | 1 | Cloud enhancement is available.|
| EXECUTING | 2 | Cloud enhancement is being executed.|
| COMPLETED | 3 | Cloud enhancement has been completed.|
## CloudEnhancementTaskState13+
Represents the cloud enhancement task information, which includes the cloud enhancement task state and other information related to certain states.
**System API**: This is a system API.
**System capability**: SystemCapability.FileManagement.PhotoAccessHelper.Core
| Name | Type | Mandatory| Description |
| ---------------------- | ------------------- | ---- | ------------------------------------------------ |
|taskStage |[CloudEnhancementTaskStage](#cloudenhancementtaskstage13) |Yes| Cloud enhancement task state.|
|transferredFileSize |number |No| Size of the file transferred. This parameter is mandatory when **taskStage** is **CloudEnhancementTaskStage.TASK_STAGE_UPLOADING** or **CloudEnhancementTaskStage.TASK_STAGE_DOWNLOADING**. |
|totalFileSize |number |No| Total file size. This parameter is mandatory when **taskStage** is **CloudEnhancementTaskStage.TASK_STAGE_UPLOADING** or **CloudEnhancementTaskStage.TASK_STAGE_DOWNLOADING**. |
|expectedDuration |number |No| Queuing time. This parameter is mandatory when **taskStage** is **CloudEnhancementTaskStage.TASK_STAGE_EXECUTING**. |
|statusCode |number |No| Status code. This parameter is mandatory when **taskStage** is **CloudEnhancementTaskStage.TASK_STAGE_FAILED**. |
## VideoEnhancementType13+
Enumerates the types of segmented video enhancement.
**System API**: This is a system API.
**System capability**: SystemCapability.FileManagement.PhotoAccessHelper.Core
| Name | Value| Description|
| ----- | ---- | ---- |
| QUALITY_ENHANCEMENT_LOCAL | 0 | Apply enhancement on the device.|
| QUALITY_ENHANCEMENT_CLOUD | 1 | Apply enhancement on the cloud.|
| QUALITY_ENHANCEMENT_LOCAL_AND_CLOUD | 2 | Apply enhancement on both the device and cloud.|
## ThumbnailType13+
Enumerates thumbnail types.
**System API**: This is a system API.
**System capability**: SystemCapability.FileManagement.PhotoAccessHelper.Core
| Name | Value | Description |
| :---------------------------- | :- | :------- |
| LCD | 1 | LCD thumbnail. |
| THM | 2 | THM thumbnail. |
## WatermarkType14+
Enumerates the watermark editable flags.
**System API**: This is a system API.
**System capability**: SystemCapability.FileManagement.PhotoAccessHelper.Core
| Name | Value| Description|
| ----- | ---- | ---- |
| DEFAULT | 0 | Watermarks are not editable.|
| BRAND_COMMON | 1 | Brand and common watermarks are editable.|
| COMMON | 2 | Common watermarks are editable.|
| BRAND | 3 | Brand watermarks are editable.|
## CloudMediaDownloadType14+
Enumerates the types of download tasks.
**System API**: This is a system API.
**System capability**: SystemCapability.FileManagement.PhotoAccessHelper.Core
| Name | Value| Description|
| ----- | ---- | ---- |
| DOWNLOAD_FORCE | 0 | High-priority download, without the need for the device to switch to screen-off charging mode.|
| DOWNLOAD_GENTLE | 1 | Low-priority download, demanding that device be in screen-off charging mode.|
## CloudMediaRetainType14+
Enumerates the modes used for deleting cloud media assets.
**System API**: This is a system API.
**System capability**: SystemCapability.FileManagement.PhotoAccessHelper.Core
| Name | Value| Description|
| ----- | ---- | ---- |
| RETAIN_FORCE | 0 | Deletes the local metadata and thumbnail of the original files from the cloud.|
## CloudMediaAssetTaskStatus14+
Enumerates the statuses of tasks used for downloading cloud media assets.
**System API**: This is a system API.
**System capability**: SystemCapability.FileManagement.PhotoAccessHelper.Core
| Name | Value| Description|
| ----- | ---- | ---- |
| DOWNLOADING | 0 | The task is in progress.|
| PAUSED | 1 | The task is paused.|
| IDLE | 2 | There is no download task.|
## CloudMediaTaskPauseCause14+
Enumerates the reasons why a cloud media asset download task is paused.
**System API**: This is a system API.
**System capability**: SystemCapability.FileManagement.PhotoAccessHelper.Core
| Name | Value| Description|
| ----- | ---- | ---- |
| NO_PAUSE | 0 | Downloading is proceeding normally without any pauses.|
| TEMPERATURE_LIMIT | 1 | The device temperature is excessively high.|
| ROM_LIMIT | 2 | The local disk space is insufficient.|
| NETWORK_FLOW_LIMIT | 3 | Network traffic is restricted, and Wi-Fi is not available.|
| WIFI_UNAVAILABLE | 4 | The network is abnormal.|
| POWER_LIMIT | 5 | Power usage is restricted.|
| BACKGROUND_TASK_UNAVAILABLE | 6 | The device is not in charging screen-off mode.|
| FREQUENT_USER_REQUESTS | 7 | The user is making requests too frequently.|
| CLOUD_ERROR | 8 | There is an error with the cloud service.|
| USER_PAUSED | 9 | The download has been paused by the user.|
## CloudMediaAssetStatus14+
Describes the details of a cloud media asset download task. It is the return value of the API used by applications to obtain the cloud asset download task status.
**System API**: This is a system API.
**System capability**: SystemCapability.FileManagement.PhotoAccessHelper.Core
| Name | Type | Mandatory| Description |
| ---------------------- | ------------------- | ---- | ------------------------------------------------ |
|taskStatus |[CloudMediaAssetTaskStatus](#cloudmediaassettaskstatus14) |Yes| Status of the download task.|
|taskInfo |string |Yes| Total number of and size (measured in bytes) of the assets that have been downloaded, and the total number and size (also measured in bytes) of the assets remaining to be downloaded. |
|errorCode |[CloudMediaTaskPauseCause](#cloudmediataskpausecause14) |Yes| Reason why the download task is suspended.|
## RecommendationType11+
Enumerates the types of recommended images.
**System capability**: SystemCapability.FileManagement.PhotoAccessHelper.Core
| Name | Value| Description|
| ----- | ---- | ---- |
| COLOR_STYLE_PHOTO18+ | 12 | Recommended style. **System API**: This is a system API.|
## ThumbnailChangeStatus20+
Enumerates the change statuses of thumbnails (including images and videos).
**System API**: This is a system API.
**System capability**: SystemCapability.FileManagement.PhotoAccessHelper.Core
| Name | Value | Description |
| ------------------------- | ---- | -------------------------------- |
| THUMBNAIL_NOT_EXISTS | 0 | The thumbnail does not exist. |
| THUMBNAIL_ADD | 1 | The thumbnail has been re-created. |
| THUMBNAIL_UPDATE | 2 | The thumbnail has been updated. |
| THUMBNAIL_NOT_CHANGE | 3 | The thumbnail has not changed. |
## StrongAssociationType20+
Enumerates the strong association types of photos.
**System API**: This is a system API.
**System capability**: SystemCapability.FileManagement.PhotoAccessHelper.Core
| Name | Value | Description |
| ------------------------- | ---- | -------------------------------- |
| NORMAL | 0 | Common photo. |
| CLOUD_ENHANCEMENT | 1 | Cloud-enhanced photo. |
## PhotoAssetChangeInfo20+
Describes the information about a media asset.
**System capability**: SystemCapability.FileManagement.PhotoAccessHelper.Core
| Name | Type | Read-Only| Optional| Description |
| ---- | ------- | ---- | ---- | ----- |
| fileId | number | No| No| ID of the media asset.
**System API**: This is a system API. |
| dateDay | string | No| No| Date when the media asset was created.
**System API**: This is a system API. |
| isFavorite | boolean | No| No| Whether the media asset is marked as a favorite. **true** if marked, **false** otherwise.
**System API**: This is a system API. |
| isHidden | boolean | No| No| Whether the media asset is hidden. **true** if hidden, **false** otherwise.
**System API**: This is a system API. |
| strongAssociation | [StrongAssociationType](#strongassociationtype20) | No| No| Strong association type of the media asset.
**System API**: This is a system API. |
| thumbnailVisible | [ThumbnailVisibility](#thumbnailvisibility14) | No| No| Accessibility status of the thumbnail.
**System API**: This is a system API. |
| dateTrashedMs |number |No| No| Unix timestamp when the media asset was deleted, in milliseconds.
**System API**: This is a system API. |
| dateAddedMs | number | No| No| Unix timestamp when the media asset was created, in milliseconds.
**System API**: This is a system API. |
| dateTakenMs | number | No| No| Unix timestamp when the media asset was captured, in milliseconds.
**System API**: This is a system API. |
## PhotoAssetChangeData20+
Describes the change data of a media asset.
**System capability**: SystemCapability.FileManagement.PhotoAccessHelper.Core
| Name | Type | Read-Only| Optional| Description |
| ---- | ------- | ---- | ---- | ----- |
| thumbnailChangeStatus | [ThumbnailChangeStatus](#thumbnailchangestatus20) | No| No| Change status of the thumbnail (image/video).
**System API**: This is a system API.|
| version | number | No| No| Version number of the media asset notification, which is used to determine the order of notifications.
**System API**: This is a system API. |
## AlbumChangeInfo20+
Describes the information about an album.
**System capability**: SystemCapability.FileManagement.PhotoAccessHelper.Core
| Name | Type | Read-Only| Optional| Description |
| ---- | ------- | ---- | ---- | ----- |
| hiddenCount | number | No| No| Number of hidden assets in the album.
**System API**: This is a system API.|
| hiddenCoverUri | string | No| No| URI of the hidden cover asset in the album.
**System API**: This is a system API.|
| isCoverChanged | boolean | No| No| Whether the file content of the album cover has changed. **true** if changed, **false** otherwise.
**System API**: This is a system API.|
| isHiddenCoverChanged | boolean | No| No| Whether the file content of the hidden album cover has changed. **true** if changed, **false** otherwise.
**System API**: This is a system API.|
| coverInfo | [PhotoAssetChangeInfo](#photoassetchangeinfo20) | No| Yes| Information of the album cover asset.
**System API**: This is a system API.|
| hiddenCoverInfo | [PhotoAssetChangeInfo](#photoassetchangeinfo20) | No| Yes| Information of the hidden album cover asset.
**System API**: This is a system API.|
## AlbumChangeData20+
Describes the change data of an album.
**System capability**: SystemCapability.FileManagement.PhotoAccessHelper.Core
| Name | Type | Read-Only| Optional| Description |
| ---- | ------- | ---- | ---- | ----- |
| version | number | No| No| Version number of the album notification, which is used to determine the order of notifications.
**System API**: This is a system API.|
## PhotoAssetCustomRecord20+
Provides APIs for custom user behavior recording for Gallery.
**System API**: This is a system API.
**System capability**: SystemCapability.FileManagement.PhotoAccessHelper.Core
| Name| Type| Read-Only| Optional| Description|
| --- | --- | --- | --- | --- |
| fileId | number | Yes| No| File ID, which must be an integer greater than 0.|
| shareCount | number | Yes| No| Number of times that image or video was shared. The value must be an integer greater than 0.|
| lcdJumpCount | number | Yes| No| Number of times the image or video was jumped to in large view. The value must be an integer greater than 0.|
## CoverUriSource20+
Enumerates the sources of the album covers.
**System API**: This is a system API.
**System capability**: SystemCapability.FileManagement.PhotoAccessHelper.Core
| Name | Value | Description |
| ------------------------- | ---- | -------------------------------- |
| DEFAULT_COVER | 0 | Default cover. |
| MANUAL_COVER | 1 | Cover manually set. |
## AlbumOrder20+
Describes the album sorting order.
### Properties
**System API**: This is a system API.
**System capability**: SystemCapability.FileManagement.PhotoAccessHelper.Core
| Name | Type | Read-Only | Optional | Description |
| ------------ | ------ | ---- | ---- | ------- |
| albumId | number | No | No | Album ID. |
| albumOrder | number | No | No | Sorting value of the album. |
| orderSection | number | No | No | Sorting section of the album.|
| orderType | number | No | No | Sorting type of the album.|
| orderStatus | number | No | No | Sorting status of the album.|