@ohos.file.photoAccessHelper (Album Management) (System API)
The photoAccessHelper 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).
Modules to Import
import photoAccessHelper from '@ohos.file.photoAccessHelper';
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:
. .. \ / : * ? " ' ` < > | { } [ ]
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> | Yes | Callback invoked to return the image or video created. |
Error codes
For details about the error codes, see Universal Error Codes and File Management Error Codes.
ID | Error Message |
---|---|
202 | Called by non-system application. |
401 | if parameter is invalid. |
13900012 | Permission denied. |
13900020 | Invalid argument. |
14000001 | Invalid display name. |
14000011 | System inner fail. |
Example
async function example() {
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:
. .. \ / : * ? " ' ` < > | { } [ ]
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> | Promise used to return the created image and video asset. |
Error codes
For details about the error codes, see Universal Error Codes and File Management Error Codes.
ID | Error Message |
---|---|
202 | Called by non-system application. |
401 | if parameter is invalid. |
13900012 | Permission denied. |
13900020 | Invalid argument. |
14000001 | Invalid display name. |
14000011 | System inner fail. |
Example
async function example() {
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:
. .. \ / : * ? " ' ` < > | { } [ ]
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 | Yes | Options for creating an image or video asset. |
callback | AsyncCallback<PhotoAsset> | Yes | Callback invoked to return the image or video created. |
Error codes
For details about the error codes, see Universal Error Codes and File Management Error Codes.
ID | Error Message |
---|---|
202 | Called by non-system application. |
401 | if parameter is invalid. |
13900012 | Permission denied. |
13900020 | Invalid argument. |
14000001 | Invalid display name. |
14000011 | System inner fail. |
Example
async function example() {
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:
. .. \ / : * ? " ' ` < > | { } [ ]
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 | Yes | Options for creating an image or video asset. |
Return value
Type | Description |
---|---|
Promise<PhotoAsset> | Promise used to return the created image and video asset. |
Error codes
For details about the error codes, see Universal Error Codes and File Management Error Codes.
ID | Error Message |
---|---|
202 | Called by non-system application. |
401 | if parameter is invalid. |
13900012 | Permission denied. |
13900020 | Invalid argument. |
14000001 | Invalid display name. |
14000011 | System inner fail. |
Example
async function example() {
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:
. .. \ / : * ? " ' ` < > | { } [ ] - The album name is case-insensitive.
- Duplicate album names are not allowed.
NOTE
This API is supported since API version 10 and deprecated since API version 11. Use MediaAlbumChangeRequest.createAlbumRequest 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> | Yes | Callback invoked to return the created album instance. |
Error codes
For details about the error codes, see Universal Error Codes and File Management Error Codes.
ID | Error Message |
---|---|
202 | Called by non-system application. |
401 | if parameter is invalid. |
13900012 | Permission denied. |
13900015 | File exists. |
13900020 | Invalid argument. |
14000011 | System inner fail. |
Example
async function example() {
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:
. .. \ / : * ? " ' ` < > | { } [ ] - The album name is case-insensitive.
- Duplicate album names are not allowed.
NOTE
This API is supported since API version 10 and deprecated since API version 11. Use MediaAlbumChangeRequest.createAlbumRequest 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> | Promise used to return the created album instance. |
Error codes
For details about the error codes, see Universal Error Codes and File Management Error Codes.
ID | Error Message |
---|---|
202 | Called by non-system application. |
401 | if parameter is invalid. |
13900012 | Permission denied. |
13900015 | File exists. |
13900020 | Invalid argument. |
14000011 | System inner fail. |
Example
import { BusinessError } from '@ohos.base';
async function example() {
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 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> | 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 and File Management Error Codes.
ID | Error Message |
---|---|
202 | Called by non-system application. |
401 | if parameter is invalid. |
13900012 | Permission denied. |
13900020 | Invalid argument. |
14000011 | System inner fail. |
Example
import dataSharePredicates from '@ohos.data.dataSharePredicates';
async function example() {
// 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<photoAccessHelper.Album> = 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 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> | 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 and File Management Error Codes.
ID | Error Message |
---|---|
202 | Called by non-system application. |
401 | if parameter is invalid. |
13900012 | Permission denied. |
13900020 | Invalid argument. |
14000011 | System inner fail. |
Example
import dataSharePredicates from '@ohos.data.dataSharePredicates';
import { BusinessError } from '@ohos.base';
async function example() {
// 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<photoAccessHelper.Album> = 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 | Yes | Display mode of hidden files. |
options | FetchOptions | Yes | Options for retrieving the hidden files. |
callback | AsyncCallback<FetchResult<Album>> | Yes | Callback invoked to return the result. |
Error codes
For details about the error codes, see Universal Error Codes and File Management Error Codes.
ID | Error Message |
---|---|
201 | Permission denied. |
202 | Called by non-system application. |
401 | if parameter is invalid. |
14000011 | System inner fail. |
Example
import dataSharePredicates from '@ohos.data.dataSharePredicates';
// Obtain the album newAlbumName that contains hidden files.
async function getHiddenAlbumsView() {
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 (fetchResult === undefined) {
console.error('getHiddenAlbumsViewCallback fetchResult is undefined');
return;
}
let album = await fetchResult.getFirstObject();
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 | Yes | Display mode of hidden files. |
callback | AsyncCallback<FetchResult<Album>> | Yes | Callback invoked to return the result. |
Error codes
For details about the error codes, see Universal Error Codes and File Management Error Codes.
ID | Error Message |
---|---|
201 | Permission denied. |
202 | Called by non-system application. |
401 | if parameter is invalid. |
14000011 | System inner fail. |
Example
import dataSharePredicates from '@ohos.data.dataSharePredicates';
// Obtain the preset hidden album.
async function getSysHiddenAlbum() {
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();
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() {
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<photoAccessHelper.Album> = await fetchResult.getAllObjects();
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) => {
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 | Yes | Display mode of hidden files. |
options | 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<Album>> | Promise used to return the result. |
Example
import dataSharePredicates from '@ohos.data.dataSharePredicates';
import { BusinessError } from '@ohos.base';
// Obtain the preset hidden album.
async function getSysHiddenAlbum() {
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() {
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<photoAccessHelper.Album> = 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. Use MediaAssetChangeRequest.deleteAssets 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 and File Management Error Codes.
ID | Error Message |
---|---|
202 | Called by non-system application. |
401 | if parameter is invalid. |
13900012 | Permission denied. |
13900020 | Invalid argument. |
14000002 | Invalid uri. |
14000011 | System inner fail. |
Example
import dataSharePredicates from '@ohos.data.dataSharePredicates';
async function example() {
console.info('deleteAssetDemo');
let predicates: dataSharePredicates.DataSharePredicates = new dataSharePredicates.DataSharePredicates();
let fetchOptions: photoAccessHelper.FetchOptions = {
fetchColumns: [],
predicates: predicates
};
try {
let fetchResult: photoAccessHelper.FetchResult<photoAccessHelper.PhotoAsset> = 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. Use MediaAssetChangeRequest.deleteAssets 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 and File Management Error Codes.
ID | Error Message |
---|---|
202 | Called by non-system application. |
401 | if parameter is invalid. |
13900012 | Permission denied. |
13900020 | Invalid argument. |
14000002 | Invalid uri. |
14000011 | System inner fail. |
Example
import dataSharePredicates from '@ohos.data.dataSharePredicates';
async function example() {
console.info('deleteDemo');
let predicates: dataSharePredicates.DataSharePredicates = new dataSharePredicates.DataSharePredicates();
let fetchOptions: photoAccessHelper.FetchOptions = {
fetchColumns: [],
predicates: predicates
};
try {
let fetchResult: photoAccessHelper.FetchResult<photoAccessHelper.PhotoAsset> = 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 | Yes | Fetch 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 invoked to return the index obtained. |
Error codes
For details about the error codes, see Universal Error Codes and File Management Error Codes.
ID | Error Message |
---|---|
202 | Called by non-system application. |
401 | if parameter is invalid. |
13900012 | Permission denied. |
13900020 | Invalid argument. |
14000011 | System inner fail. |
Example
import dataSharePredicates from '@ohos.data.dataSharePredicates';
async function example() {
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<photoAccessHelper.Album> = 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<photoAccessHelper.PhotoAsset> = 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 | Yes | Fetch 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 and File Management Error Codes.
ID | Error Message |
---|---|
202 | Called by non-system application. |
401 | if parameter is invalid. |
13900012 | Permission denied. |
13900020 | Invalid argument. |
14000011 | System inner fail. |
Example
import dataSharePredicates from '@ohos.data.dataSharePredicates';
import { BusinessError } from '@ohos.base';
async function example() {
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<photoAccessHelper.Album> = 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<photoAccessHelper.PhotoAsset> = 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 | 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 and File Management Error Codes.
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 | if the argument is invalid. |
14000011 | System inner fail. |
Example
import dataSharePredicates from '@ohos.data.dataSharePredicates';
import { BusinessError } from '@ohos.base';
async function example() {
console.info('saveFormInfoDemo');
let predicates: dataSharePredicates.DataSharePredicates = new dataSharePredicates.DataSharePredicates();
let fetchOptions: photoAccessHelper.FetchOptions = {
fetchColumns: [],
predicates: predicates
};
let fetchResult: photoAccessHelper.FetchResult<photoAccessHelper.PhotoAsset> = 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 | 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 and File Management Error Codes.
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 | if the argument is invalid. |
14000011 | System inner fail. |
Example
import dataSharePredicates from '@ohos.data.dataSharePredicates';
import { BusinessError } from '@ohos.base';
async function example() {
console.info('saveFormInfoDemo');
let predicates: dataSharePredicates.DataSharePredicates = new dataSharePredicates.DataSharePredicates();
let fetchOptions: photoAccessHelper.FetchOptions = {
fetchColumns: [],
predicates: predicates
};
let fetchResult: photoAccessHelper.FetchResult<photoAccessHelper.PhotoAsset> = 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 | Yes | Information about the Gallery widget to remove, 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 and File Management Error Codes.
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 | if the argument is invalid. |
14000011 | System inner fail. |
Example
import { BusinessError } from '@ohos.base';
async function example() {
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 | Yes | Information about the Gallery widget to remove, 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 and File Management Error Codes.
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 | if the argument is invalid. |
14000011 | System inner fail. |
Example
import { BusinessError } from '@ohos.base';
async function example() {
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}`);
});
}
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.
- 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 invoked to return the file descriptor (FD) of the file opened. |
Error codes
For details about the error codes, see Universal Error Codes and File Management Error Codes.
ID | Error Message |
---|---|
202 | Called by non-system application. |
401 | if parameter is invalid. |
13900012 | Permission denied. |
13900020 | Invalid argument. |
14000011 | System inner fail. |
Example
async function example() {
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.
- 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 and File Management Error Codes.
ID | Error Message |
---|---|
202 | Called by non-system application. |
401 | if parameter is invalid. |
13900012 | Permission denied. |
13900020 | Invalid argument. |
14000011 | System inner fail. |
Example
async function example() {
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 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 | Operation to perform. The value true means to favorite the file asset, and false means the opposite. |
callback | AsyncCallback<void> | Yes | Callback that returns no value. |
Error codes
For details about the error codes, see Universal Error Codes and File Management Error Codes.
ID | Error Message |
---|---|
202 | Called by non-system application. |
401 | if parameter is invalid. |
13900012 | Permission denied. |
13900020 | Invalid argument. |
14000011 | System inner fail. |
Example
import dataSharePredicates from '@ohos.data.dataSharePredicates';
async function example() {
console.info('setFavoriteDemo');
let predicates: dataSharePredicates.DataSharePredicates = new dataSharePredicates.DataSharePredicates();
let fetchOption: photoAccessHelper.FetchOptions = {
fetchColumns: [],
predicates: predicates
};
let fetchResult: photoAccessHelper.FetchResult<photoAccessHelper.PhotoAsset> = 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 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 | Operation to perform. The value true means to favorite the file asset, and false means the opposite. |
Return value
Type | Description |
---|---|
Promise<void> | Promise that returns no value. |
Error codes
For details about the error codes, see Universal Error Codes and File Management Error Codes.
ID | Error Message |
---|---|
202 | Called by non-system application. |
401 | if parameter is invalid. |
13900012 | Permission denied. |
13900020 | Invalid argument. |
14000011 | System inner fail. |
Example
import dataSharePredicates from '@ohos.data.dataSharePredicates';
import { BusinessError } from '@ohos.base';
async function example() {
console.info('setFavoriteDemo');
let predicates: dataSharePredicates.DataSharePredicates = new dataSharePredicates.DataSharePredicates();
let fetchOption: photoAccessHelper.FetchOptions = {
fetchColumns: [],
predicates: predicates
};
let fetchResult: photoAccessHelper.FetchResult<photoAccessHelper.PhotoAsset> = 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 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. The value true means to hide the file; the value false means the opposite. |
callback | AsyncCallback<void> | Yes | Callback that returns no value. |
Error codes
For details about the error codes, see Universal Error Codes and File Management Error Codes.
ID | Error Message |
---|---|
202 | Called by non-system application. |
401 | if parameter is invalid. |
13900012 | Permission denied. |
13900020 | Invalid argument. |
14000011 | System inner fail. |
Example
import dataSharePredicates from '@ohos.data.dataSharePredicates';
async function example() {
console.info('setHiddenDemo');
let predicates: dataSharePredicates.DataSharePredicates = new dataSharePredicates.DataSharePredicates();
let fetchOption: photoAccessHelper.FetchOptions = {
fetchColumns: [],
predicates: predicates
};
let fetchResult: photoAccessHelper.FetchResult<photoAccessHelper.PhotoAsset> = 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 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. The value true means to hide the file; the value false means the opposite. |
Return value
Type | Description |
---|---|
Promise<void> | Promise that returns no value. |
Error codes
For details about the error codes, see Universal Error Codes and File Management Error Codes.
ID | Error Message |
---|---|
202 | Called by non-system application. |
401 | if parameter is invalid. |
13900012 | Permission denied. |
13900020 | Invalid argument. |
14000011 | System inner fail. |
Example
import dataSharePredicates from '@ohos.data.dataSharePredicates';
import { BusinessError } from '@ohos.base';
async function example() {
// 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<photoAccessHelper.Album> = await phAccessHelper.getAlbums(photoAccessHelper.AlbumType.SYSTEM, photoAccessHelper.AlbumSubtype.HIDDEN);
let album = await albumList.getFirstObject();
let fetchResult: photoAccessHelper.FetchResult<photoAccessHelper.PhotoAsset> = 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 module. For details about the EXIF information, see image.PropertyKey.
NOTE
This API returns a JSON string consisting of EXIF tags. The complete EXIF information consists of all_exif and PhotoKeys.USER_COMMENT. 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 and File Management Error Codes.
ID | Error Message |
---|---|
202 | Called by non-system application. |
401 | if parameter is invalid. |
13900012 | Permission denied. |
13900020 | Invalid argument. |
14000011 | System inner fail. |
Example
import dataSharePredicates from '@ohos.data.dataSharePredicates';
async function example() {
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<photoAccessHelper.PhotoAsset> = 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 EXIF data from a JPG image. This API uses an asynchronous callback to return the result.
The EXIF data obtained are provided by the image module. For details about the EXIF data, see image.PropertyKey.
NOTE
This API returns a JSON string consisting of EXIF tags. The complete EXIF information consists of all_exif and PhotoKeys.USER_COMMENT. 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 invoked to return the EXIF data, in JSON strings. |
Error codes
For details about the error codes, see Universal Error Codes and File Management Error Codes.
ID | Error Message |
---|---|
202 | Called by non-system application. |
401 | if parameter is invalid. |
13900012 | Permission denied. |
13900020 | Invalid argument. |
14000011 | System inner fail. |
Example
import dataSharePredicates from '@ohos.data.dataSharePredicates';
async function example() {
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<photoAccessHelper.PhotoAsset> = 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 instead.
- 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 and File Management Error Codes.
ID | Error Message |
---|---|
202 | Called by non-system application. |
401 | if parameter is invalid. |
13900012 | Permission denied. |
13900020 | Invalid argument. |
14000011 | System inner fail. |
Example
import dataSharePredicates from '@ohos.data.dataSharePredicates';
async function example() {
try {
console.info('setUserCommentDemo')
let predicates: dataSharePredicates.DataSharePredicates = new dataSharePredicates.DataSharePredicates();
let fetchOptions: photoAccessHelper.FetchOptions = {
fetchColumns: [],
predicates: predicates
};
let fetchResult: photoAccessHelper.FetchResult<photoAccessHelper.PhotoAsset> = 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 instead.
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 and File Management Error Codes.
ID | Error Message |
---|---|
202 | Called by non-system application. |
401 | if parameter is invalid. |
13900012 | Permission denied. |
13900020 | Invalid argument. |
14000011 | System inner fail. |
Example
import dataSharePredicates from '@ohos.data.dataSharePredicates';
async function example() {
try {
console.info('setUserCommentDemo')
let predicates: dataSharePredicates.DataSharePredicates = new dataSharePredicates.DataSharePredicates();
let fetchOptions: photoAccessHelper.FetchOptions = {
fetchColumns: [],
predicates: predicates
};
let fetchResult: photoAccessHelper.FetchResult<photoAccessHelper.PhotoAsset> = 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. The value true means to set the file to pending state, and the value false means to remove the pending state. |
callback | AsyncCallback<void> | Yes | Callback that returns no value. |
Error codes
For details about the error codes, see Universal Error Codes and File Management Error Codes.
ID | Error Message |
---|---|
201 | Permission denied. |
202 | Called by non-system application. |
401 | if parameter is invalid. |
14000011 | System inner fail. |
Example
async function example() {
try {
console.info('setPendingCallbackDemo');
let testFileName: string = 'testFile' + Date.now() + '.jpg';
let photoAsset = await phAccessHelper.createAsset(testFileName);
let fd = await photoAsset.open('rw');
photoAsset.setPending(true, async (err) => {
if (err !== undefined) {
console.error(`setPending(true) failed with error: ${err.code}, ${err.message}`);
return;
}
// write photo buffer in fd
photoAsset.setPending(false, async (err) => {
if (err !== undefined) {
console.error(`setPending(false) failed with error: ${err.code}, ${err.message}`);
return;
}
await photoAsset.close(fd);
});
});
} 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. The value true means to set the file to pending state, and the value false means to remove the pending state. |
Return value
Type | Description |
---|---|
Promise<boolean> | Promise that returns no value. |
Error codes
For details about the error codes, see Universal Error Codes and File Management Error Codes.
ID | Error Message |
---|---|
201 | Permission denied. |
202 | Called by non-system application. |
401 | if parameter is invalid. |
14000011 | System inner fail. |
Example
async function example() {
try {
console.info('setPendingPromiseDemo');
let testFileName: string = 'testFile' + Date.now() + '.jpg';
let photoAsset = await phAccessHelper.createAsset(testFileName);
let fd = await photoAsset.open('rw');
await photoAsset.setPending(true);
// write photo buffer in fd
photoAsset.setPending(false);
await photoAsset.close(fd);
} 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 invoked to return the result. |
Error codes
For details about the error codes, see Universal Error Codes and File Management Error Codes.
ID | Error Message |
---|---|
201 | Permission denied. |
202 | Called by non-system application. |
401 | if parameter is invalid. |
14000011 | System inner fail. |
Example
import dataSharePredicates from '@ohos.data.dataSharePredicates';
async function example() {
try {
console.info('isEditedCallbackDemo')
let predicates: dataSharePredicates.DataSharePredicates = new dataSharePredicates.DataSharePredicates();
let fetchOptions: photoAccessHelper.FetchOptions = {
fetchColumns: [],
predicates: predicates
};
let fetchResult: photoAccessHelper.FetchResult<photoAccessHelper.PhotoAsset> = 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. |
Error codes
For details about the error codes, see Universal Error Codes and File Management Error Codes.
ID | Error Message |
---|---|
201 | Permission denied. |
202 | Called by non-system application. |
401 | if parameter is invalid. |
14000011 | System inner fail. |
Example
import dataSharePredicates from '@ohos.data.dataSharePredicates';
async function example() {
try {
console.info('isEditedPromiseDemo')
let predicates: dataSharePredicates.DataSharePredicates = new dataSharePredicates.DataSharePredicates();
let fetchOptions: photoAccessHelper.FetchOptions = {
fetchColumns: [],
predicates: predicates
};
let fetchResult: photoAccessHelper.FetchResult<photoAccessHelper.PhotoAsset> = 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 invoked to return the edit data obtained. |
Error codes
For details about the error codes, see Universal Error Codes and File Management Error Codes.
ID | Error Message |
---|---|
201 | Permission denied. |
202 | Called by non-system application. |
401 | if parameter is invalid. |
14000011 | System inner fail. |
Example
import dataSharePredicates from '@ohos.data.dataSharePredicates';
async function example() {
try {
console.info('requestEditDataCallbackDemo')
let predicates: dataSharePredicates.DataSharePredicates = new dataSharePredicates.DataSharePredicates();
let fetchOptions: photoAccessHelper.FetchOptions = {
fetchColumns: [],
predicates: predicates
};
let fetchResult: photoAccessHelper.FetchResult<photoAccessHelper.PhotoAsset> = 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 and File Management Error Codes.
ID | Error Message |
---|---|
201 | Permission denied. |
202 | Called by non-system application. |
401 | if parameter is invalid. |
14000011 | System inner fail. |
Example
import dataSharePredicates from '@ohos.data.dataSharePredicates';
async function example() {
try {
console.info('requestEditDataPromiseDemo')
let predicates: dataSharePredicates.DataSharePredicates = new dataSharePredicates.DataSharePredicates();
let fetchOptions: photoAccessHelper.FetchOptions = {
fetchColumns: [],
predicates: predicates
};
let fetchResult: photoAccessHelper.FetchResult<photoAccessHelper.PhotoAsset> = 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> | Promise used to return the edited asset data. |
Error codes
For details about the error codes, see Universal Error Codes and File Management Error Codes.
ID | Error Message |
---|---|
201 | Permission denied. |
202 | Called by non-system application. |
401 | if parameter is invalid. |
14000011 | System inner fail. |
Example
import dataSharePredicates from '@ohos.data.dataSharePredicates';
async function example() {
try {
console.info('getEditDataDemo')
let predicates: dataSharePredicates.DataSharePredicates = new dataSharePredicates.DataSharePredicates();
let fetchOptions: photoAccessHelper.FetchOptions = {
fetchColumns: [],
predicates: predicates
};
let fetchResult: photoAccessHelper.FetchResult<photoAccessHelper.PhotoAsset> = 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 invoked to return the FD. |
Error codes
For details about the error codes, see Universal Error Codes and File Management Error Codes.
ID | Error Message |
---|---|
201 | Permission denied. |
202 | Called by non-system application. |
401 | if parameter is invalid. |
14000011 | System inner fail. |
Example
import dataSharePredicates from '@ohos.data.dataSharePredicates';
async function example() {
try {
console.info('requsetSourceCallbackDemo')
let predicates: dataSharePredicates.DataSharePredicates = new dataSharePredicates.DataSharePredicates();
let fetchOptions: photoAccessHelper.FetchOptions = {
fetchColumns: [],
predicates: predicates
};
let fetchResult: photoAccessHelper.FetchResult<photoAccessHelper.PhotoAsset> = 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(`requsetSourceCallbackDemo 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 and File Management Error Codes.
ID | Error Message |
---|---|
201 | Permission denied. |
202 | Called by non-system application. |
401 | if parameter is invalid. |
14000011 | System inner fail. |
Example
import dataSharePredicates from '@ohos.data.dataSharePredicates';
async function example() {
try {
console.info('requsetSourcePromiseDemo')
let predicates: dataSharePredicates.DataSharePredicates = new dataSharePredicates.DataSharePredicates();
let fetchOptions: photoAccessHelper.FetchOptions = {
fetchColumns: [],
predicates: predicates
};
let fetchResult: photoAccessHelper.FetchResult<photoAccessHelper.PhotoAsset> = 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(`requsetSourcePromiseDemo 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.
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 and File Management Error Codes.
ID | Error Message |
---|---|
201 | Permission denied. |
202 | Called by non-system application. |
401 | if parameter is invalid. |
14000011 | System inner fail. |
Example
import dataSharePredicates from '@ohos.data.dataSharePredicates';
async function example() {
try {
console.info('commitEditedAssetCallbackDemo')
let predicates: dataSharePredicates.DataSharePredicates = new dataSharePredicates.DataSharePredicates();
let fetchOptions: photoAccessHelper.FetchOptions = {
fetchColumns: [],
predicates: predicates
};
let fetchResult: photoAccessHelper.FetchResult<photoAccessHelper.PhotoAsset> = 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.
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 and File Management Error Codes.
ID | Error Message |
---|---|
201 | Permission denied. |
202 | Called by non-system application. |
401 | if parameter is invalid. |
14000011 | System inner fail. |
Example
import dataSharePredicates from '@ohos.data.dataSharePredicates';
async function example() {
try {
console.info('commitEditedAssetPromiseDemo')
let predicates: dataSharePredicates.DataSharePredicates = new dataSharePredicates.DataSharePredicates();
let fetchOptions: photoAccessHelper.FetchOptions = {
fetchColumns: [],
predicates: predicates
};
let fetchResult: photoAccessHelper.FetchResult<photoAccessHelper.PhotoAsset> = 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 and File Management Error Codes.
ID | Error Message |
---|---|
201 | Permission denied. |
202 | Called by non-system application. |
401 | if parameter is invalid. |
14000011 | System inner fail. |
Example
import dataSharePredicates from '@ohos.data.dataSharePredicates';
async function example() {
try {
console.info('revertToOriginalCallbackDemo')
let predicates: dataSharePredicates.DataSharePredicates = new dataSharePredicates.DataSharePredicates();
let fetchOptions: photoAccessHelper.FetchOptions = {
fetchColumns: [],
predicates: predicates
};
let fetchResult: photoAccessHelper.FetchResult<photoAccessHelper.PhotoAsset> = 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 and File Management Error Codes.
ID | Error Message |
---|---|
201 | Permission denied. |
202 | Called by non-system application. |
401 | if parameter is invalid. |
14000011 | System inner fail. |
Example
import dataSharePredicates from '@ohos.data.dataSharePredicates';
async function example() {
try {
console.info('revertToOriginalPromiseDemo')
let predicates: dataSharePredicates.DataSharePredicates = new dataSharePredicates.DataSharePredicates();
let fetchOptions: photoAccessHelper.FetchOptions = {
fetchColumns: [],
predicates: predicates
};
let fetchResult: photoAccessHelper.FetchResult<photoAccessHelper.PhotoAsset> = 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> | 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 and File Management Error Codes.
ID | Error Message |
---|---|
201 | Permission denied. |
202 | Called by non-system application. |
401 | if parameter is invalid. |
14000011 | System inner fail. |
Example
import dataSharePredicates from '@ohos.data.dataSharePredicates';
import image from '@ohos.multimedia.image'
async function example() {
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 | Yes | Options for obtaining the asset thumbnail. |
callback | AsyncCallback<image.PixelMap> | Yes | Callback invoked 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 and File Management Error Codes.
ID | Error Message |
---|---|
201 | Permission denied. |
202 | Called by non-system application. |
401 | if parameter is invalid. |
14000011 | System inner fail. |
Example
import dataSharePredicates from '@ohos.data.dataSharePredicates';
import image from '@ohos.multimedia.image'
async function example() {
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 and File Management Error Codes.
ID | Error Message |
---|---|
201 | Permission denied. |
202 | Called by non-system application. |
401 | if parameter is invalid. |
14000011 | System inner fail. |
Example
import dataSharePredicates from '@ohos.data.dataSharePredicates';
import image from '@ohos.multimedia.image'
async function example() {
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<string>
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 | Yes | Smart analysis type. |
Error codes
For details about the error codes, see Universal Error Codes and File Management Error Codes.
ID | Error Message |
---|---|
201 | Permission denied. |
202 | Called by non-system application. |
401 | if parameter is invalid. |
14000011 | System inner fail. |
Example
import dataSharePredicates from '@ohos.data.dataSharePredicates';
async function example() {
try {
console.info('getAnalysisDataDemo')
let fetchOptions: photoAccessHelper.FetchOptions = {
fetchColumns: [],
predicates: new dataSharePredicates.DataSharePredicates()
}
let fetchResult: photoAccessHelper.FetchResult<photoAccessHelper.PhotoAsset> =
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}`);
}
}
Album
Provides APIs to manage albums.
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 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> | 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 and File Management Error Codes.
ID | Error Message |
---|---|
202 | Called by non-system application. |
401 | if parameter is invalid. |
13900012 | Permission denied. |
13900020 | Invalid argument. |
14000011 | System inner fail. |
Example
import dataSharePredicates from '@ohos.data.dataSharePredicates';
async function example() {
try {
console.info('recoverAssetsDemoCallback');
let predicates: dataSharePredicates.DataSharePredicates = new dataSharePredicates.DataSharePredicates();
let fetchOption: photoAccessHelper.FetchOptions = {
fetchColumns: [],
predicates: predicates
};
let albumFetchResult: photoAccessHelper.FetchResult<photoAccessHelper.Album> = await phAccessHelper.getAlbums(photoAccessHelper.AlbumType.SYSTEM, photoAccessHelper.AlbumSubtype.TRASH);
let album: photoAccessHelper.Album = await albumFetchResult.getFirstObject();
let fetchResult: photoAccessHelper.FetchResult<photoAccessHelper.PhotoAsset> = 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 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> | 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 and File Management Error Codes.
ID | Error Message |
---|---|
202 | Called by non-system application. |
401 | if parameter is invalid. |
13900012 | Permission denied. |
13900020 | Invalid argument. |
14000011 | System inner fail. |
Example
import dataSharePredicates from '@ohos.data.dataSharePredicates';
import { BusinessError } from '@ohos.base';
async function example() {
try {
console.info('recoverAssetsDemoPromise');
let predicates: dataSharePredicates.DataSharePredicates = new dataSharePredicates.DataSharePredicates();
let fetchOption: photoAccessHelper.FetchOptions = {
fetchColumns: [],
predicates: predicates
};
let albumFetchResult: photoAccessHelper.FetchResult<photoAccessHelper.Album> = await phAccessHelper.getAlbums(photoAccessHelper.AlbumType.SYSTEM, photoAccessHelper.AlbumSubtype.TRASH);
let album: photoAccessHelper.Album = await albumFetchResult.getFirstObject();
let fetchResult: photoAccessHelper.FetchResult<photoAccessHelper.PhotoAsset> = 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 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> | 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 and File Management Error Codes.
ID | Error Message |
---|---|
202 | Called by non-system application. |
401 | if parameter is invalid. |
13900012 | Permission denied. |
13900020 | Invalid argument. |
14000011 | System inner fail. |
Example
import dataSharePredicates from '@ohos.data.dataSharePredicates';
async function example() {
try {
console.info('deleteAssetsDemoCallback');
let predicates: dataSharePredicates.DataSharePredicates = new dataSharePredicates.DataSharePredicates();
let fetchOption: photoAccessHelper.FetchOptions = {
fetchColumns: [],
predicates: predicates
};
let albumFetchResult: photoAccessHelper.FetchResult<photoAccessHelper.Album> = await phAccessHelper.getAlbums(photoAccessHelper.AlbumType.SYSTEM, photoAccessHelper.AlbumSubtype.TRASH);
let album: photoAccessHelper.Album = await albumFetchResult.getFirstObject();
let fetchResult: photoAccessHelper.FetchResult<photoAccessHelper.PhotoAsset> = 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. 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 instead.
- 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> | 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 and File Management Error Codes.
ID | Error Message |
---|---|
202 | Called by non-system application. |
401 | if parameter is invalid. |
13900012 | Permission denied. |
13900020 | Invalid argument. |
14000011 | System inner fail. |
Example
import dataSharePredicates from '@ohos.data.dataSharePredicates';
import { BusinessError } from '@ohos.base';
async function example() {
try {
console.info('deleteAssetsDemoPromise');
let predicates: dataSharePredicates.DataSharePredicates = new dataSharePredicates.DataSharePredicates();
let fetchOption: photoAccessHelper.FetchOptions = {
fetchColumns: [],
predicates: predicates
};
let albumFetchResult: photoAccessHelper.FetchResult<photoAccessHelper.Album> = await phAccessHelper.getAlbums(photoAccessHelper.AlbumType.SYSTEM, photoAccessHelper.AlbumSubtype.TRASH);
let album: photoAccessHelper.Album = await albumFetchResult.getFirstObject();
let fetchResult: photoAccessHelper.FetchResult<photoAccessHelper.PhotoAsset> = 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 instead.
- 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 and File Management Error Codes.
ID | Error Message |
---|---|
202 | Called by non-system application. |
401 | if parameter is invalid. |
13900012 | Permission denied. |
13900020 | Invalid argument. |
14000011 | System inner fail. |
Example
import dataSharePredicates from '@ohos.data.dataSharePredicates';
async function example() {
try {
console.info('setCoverUriDemoCallback');
let predicates: dataSharePredicates.DataSharePredicates = new dataSharePredicates.DataSharePredicates();
let fetchOption: photoAccessHelper.FetchOptions = {
fetchColumns: [],
predicates: predicates
};
let albumFetchResult: photoAccessHelper.FetchResult<photoAccessHelper.Album> = await phAccessHelper.getAlbums(photoAccessHelper.AlbumType.USER, photoAccessHelper.AlbumSubtype.USER_GENERIC);
let album: photoAccessHelper.Album = await albumFetchResult.getFirstObject();
let fetchResult: photoAccessHelper.FetchResult<photoAccessHelper.PhotoAsset> = 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 instead.
- 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 and File Management Error Codes.
ID | Error Message |
---|---|
202 | Called by non-system application. |
401 | if parameter is invalid. |
13900012 | Permission denied. |
13900020 | Invalid argument. |
14000011 | System inner fail. |
Example
import dataSharePredicates from '@ohos.data.dataSharePredicates';
import { BusinessError } from '@ohos.base';
async function example() {
try {
console.info('setCoverUriDemoPromise');
let predicates: dataSharePredicates.DataSharePredicates = new dataSharePredicates.DataSharePredicates();
let fetchOption: photoAccessHelper.FetchOptions = {
fetchColumns: [],
predicates: predicates
};
let albumFetchResult: photoAccessHelper.FetchResult<photoAccessHelper.Album> = await phAccessHelper.getAlbums(photoAccessHelper.AlbumType.USER, photoAccessHelper.AlbumSubtype.USER_GENERIC);
let album: photoAccessHelper.Album = await albumFetchResult.getFirstObject();
let fetchResult: photoAccessHelper.FetchResult<photoAccessHelper.PhotoAsset> = 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}`);
}
}
MediaAssetEditData11+
Represents the edited media asset data.
System API: This is a system API.
System capability: SystemCapability.FileManagement.PhotoAccessHelper.Core
Attributes
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 and File Management Error Codes.
ID | Error Message |
---|---|
202 | Called by non-system application. |
401 | if parameter is invalid. |
14000011 | System inner fail. |
Example
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:
. .. \ / : * ? " ' ` < > | { } [ ]
System API: This is a system API.
System capability: SystemCapability.FileManagement.PhotoAccessHelper.Core
Parameters
Name | Type | Mandatory | Description |
---|---|---|---|
context | Context | Yes | Context of the ability instance. |
displayName | string | Yes | File name of the image or video to create. |
options | PhotoCreateOptions | No | Options for creating an image or video asset. |
Return value
Type | Description |
---|---|
MediaAssetChangeRequest | MediaAssetChangeRequest created. |
Error codes
For details about the error codes, see Universal Error Codes and File Management Error Codes.
ID | Error Message |
---|---|
202 | Called by non-system application. |
401 | if parameter is invalid. |
14000001 | Invalid display name. |
14000011 | System inner fail. |
Example
async function example() {
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 | Operation to perform. The value true means to favorite the file, and false means the opposite. |
Error codes
For details about the error codes, see Universal Error Codes and File Management Error Codes.
ID | Error Message |
---|---|
202 | Called by non-system application. |
401 | if parameter is invalid. |
14000011 | System inner fail. |
Example
import dataSharePredicates from '@ohos.data.dataSharePredicates';
import { BusinessError } from '@ohos.base';
async function example() {
console.info('setFavoriteDemo');
let predicates: dataSharePredicates.DataSharePredicates = new dataSharePredicates.DataSharePredicates();
let fetchOption: photoAccessHelper.FetchOptions = {
fetchColumns: [],
predicates: predicates
};
let fetchResult: photoAccessHelper.FetchResult<photoAccessHelper.PhotoAsset> = 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. The value true means to hide the file; the value false means the opposite. |
Error codes
For details about the error codes, see Universal Error Codes and File Management Error Codes.
ID | Error Message |
---|---|
202 | Called by non-system application. |
401 | if parameter is invalid. |
14000011 | System inner fail. |
Example
import dataSharePredicates from '@ohos.data.dataSharePredicates';
import { BusinessError } from '@ohos.base';
async function example() {
console.info('setHiddenDemo');
let predicates: dataSharePredicates.DataSharePredicates = new dataSharePredicates.DataSharePredicates();
let fetchOption: photoAccessHelper.FetchOptions = {
fetchColumns: [],
predicates: predicates
};
let fetchResult: photoAccessHelper.FetchResult<photoAccessHelper.PhotoAsset> = 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 and File Management Error Codes.
ID | Error Message |
---|---|
202 | Called by non-system application. |
401 | if parameter is invalid. |
14000011 | System inner fail. |
Example
import dataSharePredicates from '@ohos.data.dataSharePredicates';
import { BusinessError } from '@ohos.base';
async function example() {
console.info('setUserCommentDemo');
let predicates: dataSharePredicates.DataSharePredicates = new dataSharePredicates.DataSharePredicates();
let fetchOption: photoAccessHelper.FetchOptions = {
fetchColumns: [],
predicates: predicates
};
let fetchResult: photoAccessHelper.FetchResult<photoAccessHelper.PhotoAsset> = 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 | Yes | Edited data to save. |
Error codes
For details about the error codes, see Universal Error Codes and File Management Error Codes.
ID | Error Message |
---|---|
202 | Called by non-system application. |
401 | if parameter is invalid. |
14000011 | System inner fail. |
Example
import dataSharePredicates from '@ohos.data.dataSharePredicates';
import { BusinessError } from '@ohos.base';
async function example() {
console.info('setEditDataDemo');
let predicates: dataSharePredicates.DataSharePredicates = new dataSharePredicates.DataSharePredicates();
let fetchOption: photoAccessHelper.FetchOptions = {
fetchColumns: [],
predicates: predicates
};
let fetchResult: photoAccessHelper.FetchResult<photoAccessHelper.PhotoAsset> = 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 | Yes | Type of the resource to add. |
proxy | PhotoProxy | Yes | PhotoProxy data of the resource to add. |
Error codes
For details about the error codes, see Universal Error Codes and File Management Error Codes.
ID | Error Message |
---|---|
202 | Called by non-system application. |
401 | if parameter is invalid. |
14000011 | System inner fail. |
14000016 | Operation Not Support. |
Example
class PhotoProxyImpl implements photoAccessHelper.PhotoProxy {
// Implement PhotoProxy.
}
async function example() {
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 and File Management Error Codes.
ID | Error Message |
---|---|
202 | Called by non-system application. |
401 | if parameter is invalid. |
14000011 | System inner fail. |
Example
import dataSharePredicates from '@ohos.data.dataSharePredicates';
import { BusinessError } from '@ohos.base';
async function example() {
console.info('setLocationDemo');
let predicates: dataSharePredicates.DataSharePredicates = new dataSharePredicates.DataSharePredicates();
let fetchOption: photoAccessHelper.FetchOptions = {
fetchColumns: [],
predicates: predicates
};
let fetchResult: photoAccessHelper.FetchResult<photoAccessHelper.PhotoAsset> = 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}`);
});
}
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> | Yes | Assets to change. |
Error codes
For details about the error codes, see Universal Error Codes and File Management Error Codes.
ID | Error Message |
---|---|
202 | Called by non-system application. |
401 | if parameter is invalid. |
14000011 | System inner fail. |
Example
import dataSharePredicates from '@ohos.data.dataSharePredicates';
async function example() {
console.info('MediaAssetsChangeRequest constructorDemo');
let predicates: dataSharePredicates.DataSharePredicates = new dataSharePredicates.DataSharePredicates();
let fetchOption: photoAccessHelper.FetchOptions = {
fetchColumns: [],
predicates: predicates
};
let fetchResult: photoAccessHelper.FetchResult<photoAccessHelper.PhotoAsset> = await phAccessHelper.getAssets(fetchOption);
let photoAssetList: Array<photoAccessHelper.PhotoAsset> = 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 | Operation to perform. The value true means to favorite the file, and false means the opposite. |
Error codes
For details about the error codes, see Universal Error Codes and File Management Error Codes.
ID | Error Message |
---|---|
202 | Called by non-system application. |
401 | if parameter is invalid. |
14000011 | System inner fail. |
Example
import dataSharePredicates from '@ohos.data.dataSharePredicates';
import { BusinessError } from '@ohos.base';
async function example() {
console.info('setFavoriteDemo');
let predicates: dataSharePredicates.DataSharePredicates = new dataSharePredicates.DataSharePredicates();
let fetchOption: photoAccessHelper.FetchOptions = {
fetchColumns: [],
predicates: predicates
};
let fetchResult: photoAccessHelper.FetchResult<photoAccessHelper.PhotoAsset> = await phAccessHelper.getAssets(fetchOption);
let photoAssetList: Array<photoAccessHelper.PhotoAsset> = 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. The value true means to hide the file; the value false means the opposite. |
Error codes
For details about the error codes, see Universal Error Codes and File Management Error Codes.
ID | Error Message |
---|---|
202 | Called by non-system application. |
401 | if parameter is invalid. |
14000011 | System inner fail. |
Example
import dataSharePredicates from '@ohos.data.dataSharePredicates';
import { BusinessError } from '@ohos.base';
async function example() {
console.info('setHiddenDemo');
let predicates: dataSharePredicates.DataSharePredicates = new dataSharePredicates.DataSharePredicates();
let fetchOption: photoAccessHelper.FetchOptions = {
fetchColumns: [],
predicates: predicates
};
let fetchResult: photoAccessHelper.FetchResult<photoAccessHelper.PhotoAsset> = await phAccessHelper.getAssets(fetchOption);
let photoAssetList: Array<photoAccessHelper.PhotoAsset> = 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 and File Management Error Codes.
ID | Error Message |
---|---|
202 | Called by non-system application. |
401 | if parameter is invalid. |
14000011 | System inner fail. |
Example
import dataSharePredicates from '@ohos.data.dataSharePredicates';
import { BusinessError } from '@ohos.base';
async function example() {
console.info('setUserCommentDemo');
let predicates: dataSharePredicates.DataSharePredicates = new dataSharePredicates.DataSharePredicates();
let fetchOption: photoAccessHelper.FetchOptions = {
fetchColumns: [],
predicates: predicates
};
let fetchResult: photoAccessHelper.FetchResult<photoAccessHelper.PhotoAsset> = await phAccessHelper.getAssets(fetchOption);
let photoAssetList: Array<photoAccessHelper.PhotoAsset> = 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}`);
});
}
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 | Yes | Context of the ability instance. |
name | string | Yes | Name of the album. |
Return value
Type | Description |
---|---|
MediaAlbumChangeRequest | MediaAlbumChangeRequest instance created. |
Error codes
For details about the error codes, see Universal Error Codes and File Management Error Codes.
ID | Error Message |
---|---|
202 | Called by non-system application. |
401 | if parameter is invalid. |
14000011 | System inner fail. |
Example
async function example() {
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 | Yes | Context of the ability instance. |
albums | Array<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 and File Management Error Codes.
ID | Error Message |
---|---|
201 | Permission denied. |
202 | Called by non-system application. |
401 | if parameter is invalid. |
14000011 | System inner fail. |
Example
import dataSharePredicates from '@ohos.data.dataSharePredicates';
async function example() {
console.info('deleteAlbumsDemo');
let predicates: dataSharePredicates.DataSharePredicates = new dataSharePredicates.DataSharePredicates();
let fetchOptions: photoAccessHelper.FetchOptions = {
fetchColumns: [],
predicates: predicates
};
try {
let fetchResult: photoAccessHelper.FetchResult<photoAccessHelper.Album> = 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}`);
}
}
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 and File Management Error Codes.
ID | Error Message |
---|---|
202 | Called by non-system application. |
401 | if parameter is invalid. |
14000011 | System inner fail. |
Example
import dataSharePredicates from '@ohos.data.dataSharePredicates';
async function example() {
console.info('setCoverUriDemo');
let predicates: dataSharePredicates.DataSharePredicates = new dataSharePredicates.DataSharePredicates();
let fetchOptions: photoAccessHelper.FetchOptions = {
fetchColumns: [],
predicates: predicates
};
try {
let albumFetchResult: photoAccessHelper.FetchResult<photoAccessHelper.Album> = await phAccessHelper.getAlbums(photoAccessHelper.AlbumType.USER, photoAccessHelper.AlbumSubtype.USER_GENERIC);
let album: photoAccessHelper.Album = await albumFetchResult.getFirstObject();
let fetchResult: photoAccessHelper.FetchResult<photoAccessHelper.PhotoAsset> = 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}`);
}
}
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> | 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 and File Management Error Codes.
ID | Error Message |
---|---|
202 | Called by non-system application. |
401 | if parameter is invalid. |
14000011 | System inner fail. |
14000016 | Operation Not Support. |
Example
import dataSharePredicates from '@ohos.data.dataSharePredicates';
async function example() {
console.info('moveAssetsDemo');
let predicates: dataSharePredicates.DataSharePredicates = new dataSharePredicates.DataSharePredicates();
let fetchOptions: photoAccessHelper.FetchOptions = {
fetchColumns: [],
predicates: predicates
};
try {
let albumFetchResult: photoAccessHelper.FetchResult<photoAccessHelper.Album> = await phAccessHelper.getAlbums(photoAccessHelper.AlbumType.USER, photoAccessHelper.AlbumSubtype.USER_GENERIC);
let album: photoAccessHelper.Album = await albumFetchResult.getFirstObject();
let fetchResult: photoAccessHelper.FetchResult<photoAccessHelper.PhotoAsset> = 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}`);
}
}
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> | Yes | Assets to recover. |
Error codes
For details about the error codes, see Universal Error Codes and File Management Error Codes.
ID | Error Message |
---|---|
202 | Called by non-system application. |
401 | if parameter is invalid. |
14000011 | System inner fail. |
14000016 | Operation Not Support. |
Example
import dataSharePredicates from '@ohos.data.dataSharePredicates';
async function example() {
console.info('recoverAssetsDemo');
let predicates: dataSharePredicates.DataSharePredicates = new dataSharePredicates.DataSharePredicates();
let fetchOptions: photoAccessHelper.FetchOptions = {
fetchColumns: [],
predicates: predicates
};
try {
let albumFetchResult: photoAccessHelper.FetchResult<photoAccessHelper.Album> = await phAccessHelper.getAlbums(photoAccessHelper.AlbumType.SYSTEM, photoAccessHelper.AlbumSubtype.TRASH);
let album: photoAccessHelper.Album = await albumFetchResult.getFirstObject();
let fetchResult: photoAccessHelper.FetchResult<photoAccessHelper.PhotoAsset> = 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}`);
}
}
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> | Yes | Assets to be permanently deleted. |
Error codes
For details about the error codes, see Universal Error Codes and File Management Error Codes.
ID | Error Message |
---|---|
202 | Called by non-system application. |
401 | if parameter is invalid. |
14000011 | System inner fail. |
14000016 | Operation Not Support. |
Example
import dataSharePredicates from '@ohos.data.dataSharePredicates';
async function example() {
console.info('deleteAssetsPermanentlyDemo');
let predicates: dataSharePredicates.DataSharePredicates = new dataSharePredicates.DataSharePredicates();
let fetchOptions: photoAccessHelper.FetchOptions = {
fetchColumns: [],
predicates: predicates
};
try {
let albumFetchResult: photoAccessHelper.FetchResult<photoAccessHelper.Album> = await phAccessHelper.getAlbums(photoAccessHelper.AlbumType.SYSTEM, photoAccessHelper.AlbumSubtype.TRASH);
let album: photoAccessHelper.Album = await albumFetchResult.getFirstObject();
let fetchResult: photoAccessHelper.FetchResult<photoAccessHelper.PhotoAsset> = 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}`);
}
}
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 and File Management Error Codes.
ID | Error Message |
---|---|
202 | Called by non-system application. |
401 | if parameter is invalid. |
14000011 | System inner fail. |
Example
import dataSharePredicates from '@ohos.data.dataSharePredicates';
async function example() {
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<photoAccessHelper.Album> = 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 and File Management Error Codes.
ID | Error Message |
---|---|
202 | Called by non-system application. |
401 | if parameter is invalid. |
14000011 | System inner fail. |
Example
import dataSharePredicates from '@ohos.data.dataSharePredicates';
async function example() {
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<photoAccessHelper.Album> = 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 the portrait 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 and File Management Error Codes.
ID | Error Message |
---|---|
202 | Called by non-system application. |
401 | if parameter is invalid. |
14000011 | System inner fail. |
14000016 | Operation Not support. |
Example
import dataSharePredicates from '@ohos.data.dataSharePredicates';
async function example() {
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<photoAccessHelper.Album> = 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<photoAccessHelper.PhotoAsset> = 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 | Yes | Album generated after the merge. The album must be renamed. |
Error codes
For details about the error codes, see Universal Error Codes and File Management Error Codes.
ID | Error Message |
---|---|
202 | Called by non-system application. |
401 | if parameter is invalid. |
14000011 | System inner fail. |
14000016 | Operation Not support. |
Example
import dataSharePredicates from '@ohos.data.dataSharePredicates';
async function example() {
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<photoAccessHelper.Album> = 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 | 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 and File Management Error Codes.
ID | Error Message |
---|---|
202 | Called by non-system application. |
401 | if parameter is invalid. |
14000011 | System inner fail. |
Example
async function example() {
console.info('placeBeforeDemo');
try {
let albumFetchResult: photoAccessHelper.FetchResult<photoAccessHelper.Album> = 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}`);
}
}
PhotoSubtype
Enumerates the PhotoAsset types.
System API: This is a system API.
System capability: SystemCapability.FileManagement.PhotoAccessHelper.Core
Name | Value | Description |
---|---|---|
DEFAULT | 0 | Default (photo) type. |
SCREENSHOT | 1 | Screenshot and screen recording file. |
PositionType
Enumerates the file locations.
System API: This is a system API.
System capability: SystemCapability.FileManagement.PhotoAccessHelper.Core
Name | Value | Description |
---|---|---|
LOCAL | 1 << 0 | Stored only on a local device. |
CLOUD | 1 << 1 | Stored only on the cloud. |
AlbumType
Enumerates the album types.
System capability: SystemCapability.FileManagement.PhotoAccessHelper.Core
Name | Value | Description |
---|---|---|
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. |
IMAGE11+ | 1031 | Album for images. 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. |
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 |
---|---|---|
POSITION | 'position' | File location type. System API: This is a system API. |
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. |
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 | 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.) |
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 | No | Size of the thumbnail to obtain. |
requestPhotoType | RequestPhotoType | No | Operation to perform. |
RequestOptions11+
Represents request options.
System capability: SystemCapability.FileManagement.PhotoAccessHelper.Core
Name | Type | Readable | Writable | Description |
---|---|---|---|---|
sourceMode | SourceMode | 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 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 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. |
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. |
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. |
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. |