| details | { [key: string]: string } | Yes | Yes | A dictionary type object, where both the key and value are of the string type and are used to describe the text content. For example, a data object with the following content can be created to describe a text file:<br>{<br>title: 'Title',<br>"content":"Content"<br>}<br>This parameter is optional. The default value is an empty dictionary object.|
| details | { [key: string]: string } | Yes | Yes | A dictionary type object, where both the key and value are of the string type and are used to describe the text content. For example, a data object with the following content can be created to describe a text file:<br>{<br>"title":"Title",<br>"content":"Content"<br>}<br>This parameter is optional. The default value is an empty dictionary object.|
**Example**
...
...
@@ -257,7 +258,7 @@ Represents the file data. It is a child class of [UnifiedRecord](#unifiedrecord)
| details | { [key: string]: string } | Yes | Yes | A dictionary type object, where Both the key and value are of the string type and are used to describe file information. For example, a data object with the following content can be created to describe a file:<br>{<br>"name":"File name",<br>"type":"File type"<br>}<br>This parameter is optional. The default value is an empty dictionary object.|
| details | { [key: string]: string } | Yes | Yes | A dictionary type object, where both the key and value are of the string type and are used to describe file information. For example, a data object with the following content can be created to describe a file:<br>{<br>"name":"File name",<br>"type":"File type"<br>}<br>This parameter is optional. The default value is an empty dictionary object.|
| uri | string | Yes | Yes | URI of the file data. |
**Example**
...
...
@@ -305,6 +306,23 @@ let video = new UDMF.Video();
| details | { [key: string]: number \| string \| Uint8Array } | Yes | Yes | A dictionary type object, where the key is of the string type, and the value can be a number, a string, or a Uint8Array.<br/>This parameter is optional. The default value is an empty dictionary object.|
| details | { [key: string]: number \| string \| Uint8Array } | Yes | Yes | A dictionary type object, where the key is of the string type, and the value can be a number, a string, or a Uint8Array.<br/>This parameter is optional. The default value is an empty dictionary object.|
**Example**
...
...
@@ -430,9 +448,9 @@ const color = new ArrayBuffer(96); // Create a PixelMap object.
Enumerates the types of the system abilities connected to the UDMF. It identifies the purpose of the data written by the user to the UDMF and the system abilities connected to the UDMF to implement data transmission between applications.
Defines the data operation performed by the UDMF. It includes two optional parameters: **intention** and **key**. The two parameters have no default value, and can be left unspecified. For details, see the parameter description of the specific API.
| intention | [Intention](#intention) | Yes | Yes | No | Service tag related to the data operation. |
| key | string | Yes | Yes | No | Unique identifier of a data object in the UDMF, which can be obtained from the return value of [insertData](#udmfinsertdata).<br>The key consists of **udmf:/**, **intention**, **bundleName**, and **groupId** with a (/) in between, for example, **udmf://DataHub/com.ohos.test/0123456789**.<br>**udmf:/** is fixed, **DataHub** is an enum of **intention**, **com.ohos.test** is the bundle name, and **0123456789** is a group ID randomly generated.|
| options | [Options](#options) | Yes | Configuration parameters. Only the value of **key** is required. |
| data | [UnifiedData](#unifieddata) | Yes | New data. |
| callback | AsyncCallback<void> | Yes | Callback invoked to return the result. If the data is updated successfully, **err** is **undefined**. Otherwise, **err** is an error object.|
**Example**
```ts
importUDMFfrom'@ohos.data.UDMF';
letplainText=newUDMF.PlainText();
plainText.textContent='hello world!';
letunifiedData=newUDMF.UnifiedData(plainText);
letoptions={
key:'udmf://DataHub/com.ohos.test/0123456789'
};
try{
UDMF.updateData(options,unifiedData,(err)=>{
if(err===undefined){
console.info('Succeeded in updating data.');
}else{
console.error('Failed to update data. code is ${err.code},message is ${err.message} `);
}
});
} catch(e) {
console.error(`Update data throws an exception. code is ${e.code},message is ${e.message} `);
| options | [Options](#options) | Yes | Configuration parameters. Both the **key** and **intention** are optional, and the return value varies depending on the parameters passed in. |
| callback | AsyncCallback<Array<[UnifiedData](#unifieddata)>> | Yes | Callback invoked to return the queried data.<br>If only the **key** is specified in **options**, the data corresponding to the key is returned.<br>If only the **intention** is specified in **options**, all data in the **intention** is returned.<br>If both **intention** and **key** are specified, the intersection of the two is returned, which is the result obtained when only **key** is specified. If there is no intersection between the specified **intention** and **key**, an error object is returned.|
**Example**
```ts
importUDMFfrom'@ohos.data.UDMF';
letoptions={
intention:UDMF.Intention.DATA_HUB
};
try{
UDMF.queryData(options,(err,data)=>{
if(err===undefined){
console.info(`Succeeded in querying data. size = ${data.length}`);
| options | [Options](#options) | Yes | Configuration parameters. Both the **key** and **intention** are optional, and the return value varies depending on the parameters passed in.|
| Promise<Array<[UnifiedData](#unifieddata)>> | Promise used to return the result.<br>If only the **key** is specified in **options**, the data corresponding to the key is returned.<br>If only the **intention** is specified in **options**, all data in the **intention** is returned.<br>If both **intention** and **key** are specified, the intersection of the two is returned, which is the result obtained when only **key** is specified. If there is no intersection between the specified **intention** and **key**, an error object is returned.|
**Example**
```ts
importUDMFfrom'@ohos.data.UDMF';
letoptions={
key:'udmf://DataHub/com.ohos.test/0123456789'
};
try{
UDMF.queryData(options).then((data)=>{
console.info(`Succeeded in querying data. size = ${data.length}`);
| options | [Options](#options) | Yes | Configuration parameters. Both the **key** and **intention** are optional, and the return value varies depending on the parameters passed in. |
| callback | AsyncCallback<Array<[UnifiedData](#unifieddata)>> | Yes | Callback invoked to return the data deleted.<br>If only the **key** is specified in **options**, the data corresponding to the key deleted is returned.<br>If only the **intention** is specified in **options**, all data in the **intention** deleted is returned.<br>If both **intention** and **key** are specified, the intersection of the two deleted is returned. If there is no intersection between the two, an error object is returned.|
**Example**
```ts
importUDMFfrom'@ohos.data.UDMF';
letoptions={
intention:UDMF.Intention.DATA_HUB
};
try{
UDMF.deleteData(options,(err,data)=>{
if(err===undefined){
console.info(`Succeeded in deleting data. size = ${data.length}`);
| options | [Options](#options) | Yes | Configuration parameters. Both the **key** and **intention** are optional, and the return value varies depending on the parameters passed in.|
| Promise<Array<[UnifiedData](#unifieddata)>> | Promise used to return the data deleted.<br>If only the **key** is specified in **options**, the data corresponding to the key deleted is returned.<br>If only the **intention** is specified in **options**, all data in the **intention** deleted is returned.<br>If both **intention** and **key** are specified, the intersection of the two deleted is returned. If there is no intersection between the two, an error object is returned.|
**Example**
```ts
importUDMFfrom'@ohos.data.UDMF';
letoptions={
key:'udmf://DataHub/com.ohos.test/0123456789'
};
try{
UDMF.deleteData(options).then((data)=>{
console.info(`Succeeded in deleting data. size = ${data.length}`);
The **photoAccessHelper** module provides APIs for album management, including creating an album and accessing and modifying media data 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.
// The phAccessHelper instance obtained is a global object. It is used by default in subsequent operations. If the code snippet is not added, an error will be reported indicating that phAccessHelper is not defined.
| options | [FetchOptions](#fetchoptions) | Yes | Options for fetching the image and video assets. |
| callback | AsyncCallback<[FetchResult](#fetchresult)<[PhotoAsset](#photoasset)>> | Yes | Callback invoked to return the image and video assets obtained.|
**Error codes**
For details about the error codes, see [Universal Error Codes](../errorcodes/errorcode-universal.md).
| displayName | string | Yes | File name of the image or video to create. |
| callback | AsyncCallback<[PhotoAsset](#photoasset)> | Yes | Callback invoked to return the image or video created.|
**Error codes**
For details about the error codes, see [File Management Error Codes](../errorcodes/errorcode-filemanagement.md) and [Universal Error Codes](../errorcodes/errorcode-universal.md).
| displayName | string | Yes | File name of the image or video to create. |
**Return value**
| Type | Description |
| --------------------------- | -------------- |
| Promise<[PhotoAsset](#photoasset)> | Promise used to return the created image and video asset.|
**Error codes**
For details about the error codes, see [File Management Error Codes](../errorcodes/errorcode-filemanagement.md) and [Universal Error Codes](../errorcodes/errorcode-universal.md).
| displayName | string | Yes | File name of the image or video to create. |
| options | [PhotoCreateOptions](#photocreateoptions) | Yes | Options for creating an image or video asset. |
| callback | AsyncCallback<[PhotoAsset](#photoasset)> | Yes | Callback invoked to return the image or video created.|
**Error codes**
For details about the error codes, see [File Management Error Codes](../errorcodes/errorcode-filemanagement.md) and [Universal Error Codes](../errorcodes/errorcode-universal.md).
| displayName | string | Yes | File name of the image or video to create. |
| options | [PhotoCreateOptions](#photocreateoptions) | Yes | Options for creating an image or video asset. |
**Return value**
| Type | Description |
| --------------------------- | -------------- |
| Promise<[PhotoAsset](#photoasset)> | Promise used to return the created image and video asset.|
**Error codes**
For details about the error codes, see [File Management Error Codes](../errorcodes/errorcode-filemanagement.md) and [Universal Error Codes](../errorcodes/errorcode-universal.md).
Creates an image or video asset with the specified file type, file name extension, and options. This API uses an asynchronous callback to return the result.
| type | [AlbumType](#albumtype) | Yes | Type of the album to obtain. |
| subtype | [AlbumSubtype](#albumsubtype) | Yes | Subtype of the album. |
| options | [FetchOptions](#fetchoptions) | No | Options for fetching the albums. If this parameter is not specified, the albums are obtained based on the album type by default. |
**Return value**
| Type | Description |
| --------------------------- | -------------- |
| Promise<[FetchResult](#fetchresult)<[Album](#album)>> | Promise used to return the result.|
**Error codes**
For details about the error codes, see [Universal Error Codes](../errorcodes/errorcode-universal.md).
| uri | string | Yes | URI of the photo asset, URI of the album, or [DefaultChangeUri](#defaultchangeuri).|
| forChildUris | boolean | Yes | Whether to perform fuzzy listening.<br>If **uri** is the URI of an album, the value **true** means to listen for the changes of the files in the album; the value **false** means to listen for the changes of the album only. <br>If **uri** is the URI of a **photoAsset**, there is no difference between **true** and **false** for **forChildUris**.<br>If **uri** is **DefaultChangeUri**, **forChildUris** must be set to **true**. If **forChildUris** is **false**, the URI cannot be found and no message can be received.|
| callback | Callback<[ChangeData](#changedata)> | Yes | Callback invoked to return the [ChangeData](#changedata). <br>**NOTE**<br>Multiple callback listeners can be registered for a URI. You can use [unRegisterChange](#unregisterchange) to unregister all listeners for the URI or a specified callback listener.|
**Error codes**
For details about the error codes, see [Universal Error Codes](../errorcodes/errorcode-universal.md).
Unregisters listening for the specified URI. Multiple callbacks can be registered for a URI for listening. You can use this API to unregister the listening of the specified callbacks or all callbacks.
| uri | string | Yes | URI of the photo asset, URI of the album, or [DefaultChangeUri](#defaultchangeuri).|
| callback | Callback<[ChangeData](#changedata)> | No | Callback to unregister. If this parameter is not specified, all the callbacks for listening for the URI will be canceled. <br>**NOTE**: The specified callback unregistered will not be invoked when the data changes.|
**Error codes**
For details about the error codes, see [Universal Error Codes](../errorcodes/errorcode-universal.md).
Creates a dialog box for deleting photos. This API uses an asynchronous callback to return the result. The deleted photos are moved to the recycle bin.
| member | string | Yes | Name of the member parameter to obtain. Except **uri**, **photoType**, and **displayName**, you need to pass in [PhotoKeys](#photokeys) in **fetchColumns** in **get()**. For example, to obtain the title attribute, set **fetchColumns: ['title']**.|
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.
| 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](../errorcodes/errorcode-universal.md).
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.
| 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](../errorcodes/errorcode-universal.md).
| options | [FetchOptions](#fetchoptions) | Yes | Options for fetching the album files.|
| callback | AsyncCallback<[FetchResult](#fetchresult)<[PhotoAsset](#photoasset)>> | Yes | Callback invoked to return the image and video assets obtained.|
**Error codes**
For details about the error codes, see [Universal Error Codes](../errorcodes/errorcode-universal.md).
Adds image and video assets to an album. Before the operation, ensure that the image and video assets to add and the album exist. This API uses an asynchronous callback to return the result.
Adds image and video assets to an album. Before the operation, ensure that the image and video assets to add and the album exist. This API uses a promise to return the result.
Recovers image or video assets from the recycle bin. Before the operation, ensure that the image or video assets exist in the recycle bin. This API uses an asynchronous callback to return the result.
Recovers image or video assets from the recycle bin. Before the operation, ensure that the image or video assets exist in the recycle bin. This API uses a promise to return the result.
Deletes image or video assets from the recycle bin. Before the operation, ensure that the image or video assets exist in the recycle bin. This API uses an asynchronous callback to return the result.
**CAUTION**<br>This operation is irreversible. The file assets deleted cannot be restored. Exercise caution when performing this operation.
Deletes image or video assets from the recycle bin. Before the operation, ensure that the image or video assets exist in the recycle bin. This API uses a promise to return the result.
**CAUTION**<br>This operation is irreversible. The file assets deleted cannot be restored. Exercise caution when performing this operation.
| DISPLAY_NAME | 'display_name' | File name displayed. |
| SIZE | 'size' | File size. |
| DATE_ADDED | 'date_added' | Date when the file was added. The value is the number of seconds elapsed since the Epoch time. |
| DATE_MODIFIED | 'date_modified' | Date when the file content (not the file name) was last modified. The value is the number of seconds elapsed since the Epoch time.|
| DURATION | 'duration' | Duration, in ms. |
| WIDTH | 'width' | Image width, in pixels. |
| HEIGHT | 'height' | Image height, in pixels. |
| DATE_TAKEN | 'date_taken' | Date when the file (photo) was taken. The value is the number of seconds elapsed since the Epoch time. |
| ORIENTATION | 'orientation' | Orientation of the image file. |
| FAVORITE | 'is_favorite' | Whether the file is added to favorites. |
| TITLE | 'title' | Title in the file. |
| 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 between the time when the file is deleted and January 1, 1970. **System API**: This is a system API. |
| HIDDEN | 'hidden' | Whether the file is hidden. **System API**: This is a system API. |
| fetchColumns | Array<string> | Yes | Yes | Column names used for retrieval. If this parameter is left empty, the media files are fetched by **uri**, **name**, and **photoType** by default. The specific field names are subject to the definition of the search object. Example:<br>fetchColumns: ['uri', 'title']|
| predicates | [dataSharePredicates.DataSharePredicates](js-apis-data-dataSharePredicates.md) | Yes | Yes | Predicates that specify the fetch criteria.|
## ChangeData
Defines the return value of the listener callback.
| DEFAULT_PHOTO_URI | 'file://media/Photo' | Default **PhotoAsset** URI. The **PhotoAsset** change notifications are received based on this parameter and **forSubUri{true}**.|
| DEFAULT_ALBUM_URI | 'file://media/PhotoAlbum' | Default album URI. Album change notifications are received based on this parameter and **forSubUri{true}**. |