提交 2d0f5386 编写于 作者: A Annie_wang

update docs

Signed-off-by: NAnnie_wang <annie.wangli@huawei.com>
上级 ffacc4bf
......@@ -29,7 +29,7 @@ Currently, the UDMF provides the public data channel for cross-application data
## Available APIs
The following table lists the UDMF APIs. All of them are executed asynchronously in callback or promise mode. In the following table, callback-based APIs are used as an example. For more information about the APIs, see [UDMF](../reference/apis/js-apis-data-udmf.md).
The following table lists the UDMF APIs. All of them are executed asynchronously in callback or promise mode. In the following table, callback-based APIs are used as an example. For more information about the APIs, see [Unified Data Channel](../reference/apis/js-apis-data-unifiedDataChannel.md) and [Standard Data Definition and Description](../reference/apis/js-apis-data-uniformTypeDescriptor.md).
| API | Description |
|-----------------------------------------------------------------------------------------|---------------------------------------------|
......@@ -45,121 +45,131 @@ The following example describes how to implement many-to-many data sharing. The
### Data Provider
1. Import the **@ohos.data.UDMF** module.
1. Import the **@ohos.data.unifiedDataChannel** and **@ohos.data.uniformTypeDescriptor** modules.
```ts
import UDMF from '@ohos.data.UDMF';
import unifiedDataChannel from '@ohos.data.unifiedDataChannel';
import uniformTypeDescriptor from '@ohos.data.uniformTypeDescriptor';
```
2. Create a **UnifiedData** object and insert it into the UDMF public data channel.
```ts
let plainText = new UDMF.PlainText();
import { BusinessError } from '@ohos.base';
let plainText = new unifiedDataChannel.PlainText();
plainText.textContent = 'hello world!';
let unifiedData = new UDMF.UnifiedData(plainText);
let unifiedData = new unifiedDataChannel.UnifiedData(plainText);
// Specify the type of the data channel to which the data is to be inserted.
let options = {
intention: UDMF.Intention.DATA_HUB
let options: unifiedDataChannel.Options = {
intention: unifiedDataChannel.Intention.DATA_HUB
}
try {
UDMF.insertData(options, unifiedData, (err, data) => {
if (err === undefined) {
console.info(`Succeeded in inserting data. key = ${data}`);
} else {
console.error(`Failed to insert data. code is ${err.code},message is ${err.message} `);
}
});
} catch(e) {
console.error(`Insert data throws an exception. code is ${e.code},message is ${e.message} `);
unifiedDataChannel.insertData(options, unifiedData, (err, data) => {
if (err === undefined) {
console.info(`Succeeded in inserting data. key = ${data}`);
} else {
console.error(`Failed to insert data. code is ${err.code},message is ${err.message} `);
}
});
} catch (e) {
let error: BusinessError = e as BusinessError;
console.error(`Insert data throws an exception. code is ${error.code},message is ${error.message} `);
}
```
3. Update the **UnifiedData** object inserted.
```ts
let plainText = new UDMF.PlainText();
import { BusinessError } from '@ohos.base';
let plainText = new unifiedDataChannel.PlainText();
plainText.textContent = 'How are you!';
let unifiedData = new UDMF.UnifiedData(plainText);
let unifiedData = new unifiedDataChannel.UnifiedData(plainText);
// Specify the URI of the UnifiedData object to update.
let options = {
key: 'udmf://DataHub/com.ohos.test/0123456789'
let options: unifiedDataChannel.Options = {
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} `);
unifiedDataChannel.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) {
let error: BusinessError = e as BusinessError;
console.error(`Update data throws an exception. code is ${error.code},message is ${error.message} `);
}
```
4. Delete the **UnifiedData** object from the UDMF public data channel.
```ts
import { BusinessError } from '@ohos.base';
// Specify the type of the data channel whose data is to be deleted.
let options = {
intention: UDMF.Intention.DATA_HUB
let options: unifiedDataChannel.Options = {
intention: unifiedDataChannel.Intention.DATA_HUB
};
try {
UDMF.deleteData(options, (err, data) => {
if (err === undefined) {
console.info(`Succeeded in deleting data. size = ${data.length}`);
for (let i = 0; i < data.length; i++) {
let records = data[i].getRecords();
for (let j = 0; j < records.length; j++) {
if (records[j].getType() === UDMF.UnifiedDataType.PLAIN_TEXT) {
let text = <UDMF.PlainText>(records[j]);
console.info(`${i + 1}.${text.textContent}`);
}
}
}
} else {
console.error(`Failed to delete data. code is ${err.code},message is ${err.message} `);
unifiedDataChannel.deleteData(options, (err, data) => {
if (err === undefined) {
console.info(`Succeeded in deleting data. size = ${data.length}`);
for (let i = 0; i < data.length; i++) {
let records = data[i].getRecords();
for (let j = 0; j < records.length; j++) {
if (records[j].getType() === uniformTypeDescriptor.UniformDataType.PLAIN_TEXT) {
let text = records[j] as unifiedDataChannel.PlainText;
console.info(`${i + 1}.${text.textContent}`);
}
}
});
} catch(e) {
console.error(`Delete data throws an exception. code is ${e.code},message is ${e.message} `);
}
} else {
console.error(`Failed to delete data. code is ${err.code},message is ${err.message} `);
}
});
} catch (e) {
let error: BusinessError = e as BusinessError;
console.error(`Delete data throws an exception. code is ${error.code},message is ${error.message} `);
}
```
### Data Consumer
1. Import the **@ohos.data.UDMF** module.
1. Import the **@ohos.data.unifiedDataChannel** and **@ohos.data.uniformTypeDescriptor** modules.
```ts
import UDMF from '@ohos.data.UDMF';
import unifiedDataChannel from '@ohos.data.unifiedDataChannel';
import uniformTypeDescriptor from '@ohos.data.uniformTypeDescriptor';
```
2. Query the **UnifiedData** object in the UDMF public data channel.
```ts
import { BusinessError } from '@ohos.base';
// Specify the type of the data channel whose data is to be queried.
let options = {
intention: UDMF.Intention.DATA_HUB
let options: unifiedDataChannel.Options = {
intention: unifiedDataChannel.Intention.DATA_HUB
};
try {
UDMF.queryData(options, (err, data) => {
if (err === undefined) {
console.info(`Succeeded in querying data. size = ${data.length}`);
for (let i = 0; i < data.length; i++) {
let records = data[i].getRecords();
for (let j = 0; j < records.length; j++) {
if (records[j].getType() === UDMF.UnifiedDataType.PLAIN_TEXT) {
let text = <UDMF.PlainText>(records[j]);
console.info(`${i + 1}.${text.textContent}`);
}
}
}
} else {
console.error(`Failed to query data. code is ${err.code},message is ${err.message} `);
unifiedDataChannel.queryData(options, (err, data) => {
if (err === undefined) {
console.info(`Succeeded in querying data. size = ${data.length}`);
for (let i = 0; i < data.length; i++) {
let records = data[i].getRecords();
for (let j = 0; j < records.length; j++) {
if (records[j].getType() === uniformTypeDescriptor.UniformDataType.PLAIN_TEXT) {
let text = records[j] as unifiedDataChannel.PlainText;
console.info(`${i + 1}.${text.textContent}`);
}
}
});
}
} else {
console.error(`Failed to query data. code is ${err.code},message is ${err.message} `);
}
});
} catch(e) {
console.error(`Query data throws an exception. code is ${e.code},message is ${e.message} `);
let error: BusinessError = e as BusinessError;
console.error(`Query data throws an exception. code is ${error.code},message is ${error.message} `);
}
```
......@@ -5,28 +5,35 @@
To streamline cross-application data interaction of OpenHarmony and minimize the application/service data interaction costs, the Unified Data Management Framework (UDMF) provides standard data definitions to define common data types. Applications can use the APIs provided by the UDMF to create and use these data types.
For example, in the cross-application drag scenario, the application of the drag source writes the data to be dragged to a [drag event](../reference/arkui-ts/ts-universal-events-drag-drop.md#dragevent) based on the standard data definitions. The application of the drop target reads the dragged data from the drag event and parses the data based on the standard data definitions. The data dragged between different applications complies with the same standard definitions, which avoids exhaustive data type adaptation and effectively reduces the development workload.
## Unified Data Types
The UDMF provides the following unified data types:
**Basic data types**<br>Basic data types include File and Text, which can be used for cross-application and cross-platform data interaction. Figure 1 and Figure 2 illustrate the basic data types.
**Basic data types**
Basic data types include File and Text, which can be used for cross-application and cross-platform data interaction. Figure 1 and Figure 2 illustrate the basic data types.
**Figure 1** UDMF File
![UDMF_FILE](figures/udmf_type_File.png)
Figure 2 UDMF Text
**Figure 2** UDMF Text
![UDMF_TEXT](figures/udmf_type_Text.png)
**System Defined Types (SDTs)**<br>The SDTs are specific to the platform or operating system, such as Form (UI card information), AppItem (app description information), and PixelMap (thumbnail). This type of data can be used for cross-application data interaction in a system or platform. Figure 3 illustrates the SDT data.
**System Defined Types (SDTs)**
The SDTs are specific to the platform or operating system, such as Form (UI card information), AppItem (app description information), and PixelMap (thumbnail). This type of data can be used for cross-application data interaction in a system or platform. Figure 3 illustrates the SDT data.
**Figure 3** UDMF SDT data
![UDMF_SDT](figures/udmf_type_SDT.png)
**App Defined Type (ADT)**<br>The SDT data is application-specific. This type of data can be used for across-platform data interaction for an application. As shown in Figure 4, the MyFile file format can be defined for use in an application ecosystem.
**App Defined Type (ADT)**
The SDT data is application-specific. This type of data can be used for across-platform data interaction for an application. As shown in Figure 4, the MyFile file format can be defined for use in an application ecosystem.
**Figure 4** UDMF ADT data
......@@ -39,11 +46,11 @@ Figure 2 UDMF Text
## Available APIs
The UDMF provides the unified data object **UnifiedData** to encapsulate a group of data records **UnifiedRecord**. **UnifiedRecord** is an abstract definition of data content supported by the UDMF, for example, a text record or an image record. The data content type in a data record corresponds to **UnifiedDataType**.
The UDMF provides the unified data object **UnifiedData** to encapsulate a group of data records **UnifiedRecord**. **UnifiedRecord** is an abstract definition of data content supported by the UDMF, for example, a text record or an image record. The data content type in a data record corresponds to **UniformDataType**.
The following table describes common UDMF APIs. For more information, see [UDMF](../reference/apis/js-apis-data-udmf.md).
The following table describes common UDMF APIs. For more information about the APIs, see [Unified Data Channel](../reference/apis/js-apis-data-unifiedDataChannel.md) and [Standard Data Definition and Description](../reference/apis/js-apis-data-uniformTypeDescriptor.md).
| Class | API | Description |
| Class | API | Description |
|---------------|-------------------|-----------------------------------------------------------------------------------------------|
| UnifiedRecord | getType(): string | Obtains the data type of this data record.|
| UnifiedData | constructor(record: UnifiedRecord) | A constructor used to create a **UnifiedData** object with a data record. |
......@@ -55,17 +62,19 @@ The following table describes common UDMF APIs. For more information, see [UDMF]
The following describes how to create a **UnifiedData** object containing two data records: image and plain text.
1. Import the **@ohos.data.UDMF** module.
1. Import the **@ohos.data.unifiedDataChannel** and **@ohos.data.uniformTypeDescriptor** modules.
```ts
import UDMF from '@ohos.data.UDMF';
import unifiedDataChannel from '@ohos.data.unifiedDataChannel';
import uniformTypeDescriptor from '@ohos.data.uniformTypeDescriptor';
```
2. Create an image data record and initialize the **UnifiedData** object with the image data record.
(1) Create an image data record.
```ts
let image = new UDMF.Image();
let image = new unifiedDataChannel.Image();
```
(2) Modify object attributes.
......@@ -84,12 +93,13 @@ The following describes how to create a **UnifiedData** object containing two da
(4) Create a **UnifiedData** instance.
```ts
let unifiedData = new UDMF.UnifiedData(image);
let unifiedData = new unifiedDataChannel.UnifiedData(image);
```
3. Create a plain text data record and add it to the **UnifiedData** instance created.
3. Create a plain text data record and add it to the **UnifiedData** instance created.
```ts
let plainText = new UDMF.PlainText();
let plainText = new unifiedDataChannel.PlainText();
plainText.textContent = 'this is textContent of plainText';
plainText.abstract = 'abstract of plainText';
plainText.details = {
......@@ -98,25 +108,27 @@ The following describes how to create a **UnifiedData** object containing two da
};
unifiedData.addRecord(plainText);
```
4. Obtain all data records in this **UnifiedData** instance.
```ts
let records = unifiedData.getRecords();
```
5. Traverse each record, determine the data type of the record, and convert the record into a child class object to obtain the original data record.
```ts
for (let i = 0; i < records.length; i ++) {
// Read the type of the data record.
let type = records[i].getType();
switch (type) {
case UDMF.UnifiedDataType.IMAGE:
case uniformTypeDescriptor.UniformDataType.IMAGE:
// Convert the data to obtain the original image data record.
let image = <UDMF.Image>(records[i]);
let image = records[i] as unifiedDataChannel.Image;
break;
case UDMF.UnifiedDataType.PLAIN_TEXT:
case uniformTypeDescriptor.UniformDataType.PLAIN_TEXT:
// Convert the data to obtain the original text record.
let plainText = <UDMF.PlainText>(records[i]);
let plainText = records[i] as unifiedDataChannel.PlainText;
break;
default:
break;
......
......@@ -279,7 +279,8 @@
- [@ohos.data.distributedKVStore (Distributed KV Store)](js-apis-distributedKVStore.md)
- [@ohos.data.preferences (User Preferences)](js-apis-data-preferences.md)
- [@ohos.data.relationalStore (RDB Store)](js-apis-data-relationalStore.md)
- [@ohos.data.UDMF (Unfied Data Management Framework)](js-apis-data-udmf.md)
- [@ohos.data.unifiedDataChannel (Unified Data Channel)](js-apis-data-unifiedDataChannel.md)
- [@ohos.data.uniformTypeDescriptor (Standard Data Definition)](js-apis-data-uniformTypeDescriptor.md)
- [@ohos.data.ValuesBucket (Value Bucket)](js-apis-data-valuesBucket.md)
- File Management
......
# @ohos.data.UDMF (Unified Data Management Framework)
# @ohos.data.unifiedDataChannel (Unified Data Channel)
The **UDMF** module provides unified data management capabilities, including standard definition of data types, such as text and image. By calling the APIs provided by this module, applications can encapsulate a variety of data into unified data objects.
As a part of the Unified Data Management Framework (UDMF), the **unifiedDataChannel** module provides unified data channels and standard data access interfaces for many-to-many data sharing across applications. It also provides standard definitions for data types, such as text and image, to streamline data interaction between different applications and minimize the workload of data type adaptation.
> **NOTE**
>
......@@ -9,32 +9,9 @@ The **UDMF** module provides unified data management capabilities, including sta
## Modules to Import
```js
import UDMF from '@ohos.data.UDMF';
import unifiedDataChannel from '@ohos.data.unifiedDataChannel';
```
## UnifiedDataType
Enumerates the types of the [data records](#unifiedrecord) in the [unifiedData](#unifieddata) object.
**System capability**: SystemCapability.DistributedDataManager.UDMF.Core
| Name | Value | Description |
|----------------------------|------------------------------|-----------|
| TEXT | 'Text' | Text. |
| PLAIN_TEXT | 'Text.PlainText' | Plaintext. |
| HYPERLINK | 'Text.Hyperlink' | Hyperlink. |
| HTML | 'Text.HTML' | HyperText Markup Language (HTML). |
| FILE | 'File' | File. |
| IMAGE | 'File.Media.Image' | Image. |
| VIDEO | 'File.Media.Video' | Video. |
| AUDIO | 'File.Media.Audio' | Audio. |
| FOLDER | 'File.Folder' | Folder. |
| SYSTEM_DEFINED_RECORD | 'SystemDefinedType' | System ability data.|
| SYSTEM_DEFINED_FORM | 'SystemDefinedType.Form' | Widget. |
| SYSTEM_DEFINED_APP_ITEM | 'SystemDefinedType.AppItem' | Icon. |
| SYSTEM_DEFINED_PIXEL_MAP | 'SystemDefinedType.PixelMap' | Pixel map. |
| APPLICATION_DEFINED_RECORD | 'ApplicationDefinedType' | Application-defined type. |
## UnifiedData
Provides APIs for encapsulating a set of data records.
......@@ -58,9 +35,9 @@ A constructor used to create a **UnifiedData** object with a data record.
**Example**
```js
let text = new UDMF.PlainText();
let text = new unifiedDataChannel.PlainText();
text.textContent = 'this is textContent of text';
let unifiedData = new UDMF.UnifiedData(text);
let unifiedData = new unifiedDataChannel.UnifiedData(text);
```
### addRecord
......@@ -80,11 +57,11 @@ Adds a data record to this **UnifiedRecord** object.
**Example**
```js
let text1 = new UDMF.PlainText();
let text1 = new unifiedDataChannel.PlainText();
text1.textContent = 'this is textContent of text1';
let unifiedData = new UDMF.UnifiedData(text1);
let unifiedData = new unifiedDataChannel.UnifiedData(text1);
let text2 = new UDMF.PlainText();
let text2 = new unifiedDataChannel.PlainText();
text2.textContent = 'this is textContent of text2';
unifiedData.addRecord(text2);
```
......@@ -106,22 +83,24 @@ Obtains all data records from this **UnifiedData** object. The data obtained is
**Example**
```js
let text = new UDMF.PlainText();
import uniformTypeDescriptor from '@ohos.data.uniformTypeDescriptor';
let text = new unifiedDataChannel.PlainText();
text.textContent = 'this is textContent of text';
let unifiedData = new UDMF.UnifiedData(text);
let unifiedData = new unifiedDataChannel.UnifiedData(text);
let link = new UDMF.Hyperlink();
let link = new unifiedDataChannel.Hyperlink();
link.url = 'www.XXX.com';
unifiedData.addRecord(link);
let records = unifiedData.getRecords();
for (let i = 0; i < records.length; i++) {
let record = records[i];
if (record.getType() == UDMF.UnifiedDataType.PLAIN_TEXT) {
let plainText = <UDMF.PlainText> (record);
if (record.getType() == uniformTypeDescriptor.UniformDataType.PLAIN_TEXT) {
let plainText = record as unifiedDataChannel.PlainText;
console.info(`textContent: ${plainText.textContent}`);
} else if (record.getType() == UDMF.UnifiedDataType.HYPERLINK) {
let hyperlink = <UDMF.Hyperlink> (record);
} else if (record.getType() == uniformTypeDescriptor.UniformDataType.HYPERLINK) {
let hyperlink = record as unifiedDataChannel.Hyperlink;
console.info(`linkUrl: ${hyperlink.url}`);
}
}
......@@ -135,7 +114,7 @@ Defines the summary of a **UnifiedData object**, including the data types and si
| Name | Type | Readable| Writable| Description |
| --------- | ------------------------- | ---- | ---- |-----------------------------------------------------------------------------------|
| summary | { [key: string]: number } | Yes | No | A directory type object, where **key** indicates the data type (see [UnifiedDataType](#unifieddatatype)), and the value indicates the total size (in bytes) of this type of records in the **UnifiedData** object.|
| summary | { [key: string]: number } | Yes | No | Dictionary type object, where the key indicates the data type (see [UniformDataType](js-apis-data-uniformTypeDescriptor.md#uniformdatatype)), and the value indicates the total size (in bytes) of this type of records in the **UnifiedData** object.|
| totalSize | number | Yes | No | Total size of all the records in the **UnifiedData** object, in bytes. |
## UnifiedRecord
......@@ -156,19 +135,21 @@ Obtains the type of this **UnfiedRecord**. The data obtained by [getRecords](#ge
| Type | Description |
| ------ |------------------------------------------------------|
| string | Data type obtained. For details, see [UnifiedDataType](#unifieddatatype).|
| string | Data type obtained. For details, see [UniformDataType](js-apis-data-uniformTypeDescriptor.md#uniformdatatype).|
**Example**
```js
let text = new UDMF.PlainText();
import uniformTypeDescriptor from '@ohos.data.uniformTypeDescriptor';
let text = new unifiedDataChannel.PlainText();
text.textContent = 'this is textContent of text';
let unifiedData = new UDMF.UnifiedData(text);
let unifiedData = new unifiedDataChannel.UnifiedData(text);
let records = unifiedData.getRecords();
if (records[0].getType() == UDMF.UnifiedDataType.PLAIN_TEXT) {
let plainText = <UDMF.PlainText> (records[0]);
console.info(`textContent: ${plainText.textContent}`);
if (records[0].getType() == uniformTypeDescriptor.UniformDataType.PLAIN_TEXT) {
let plainText = records[0] as unifiedDataChannel.PlainText;
console.info(`textContent: ${plainText.textContent}`);
}
```
......@@ -185,12 +166,12 @@ Represents the text data. It is a child class of [UnifiedRecord](#unifiedrecord)
**Example**
```js
let text = new UDMF.Text();
let text = new unifiedDataChannel.Text();
text.details = {
title: 'MyTitle',
content: 'this is content',
};
let unifiedData = new UDMF.UnifiedData(text);
let unifiedData = new unifiedDataChannel.UnifiedData(text);
```
## PlainText
......@@ -207,7 +188,7 @@ Represents the plaintext data. It is a child class of [Text](#text) and is used
**Example**
```js
let text = new UDMF.PlainText();
let text = new unifiedDataChannel.PlainText();
text.textContent = 'this is textContent';
text.abstract = 'this is abstract';
```
......@@ -226,7 +207,7 @@ Represents hyperlink data. It is a child class of [Text](#text) and is used to d
**Example**
```js
let link = new UDMF.Hyperlink();
let link = new unifiedDataChannel.Hyperlink();
link.url = 'www.XXX.com';
link.description = 'this is description';
```
......@@ -245,7 +226,7 @@ Represents the HTML data. It is a child class of [Text](#text) and is used to de
**Example**
```js
let html = new UDMF.HTML();
let html = new unifiedDataChannel.HTML();
html.htmlContent = '<div><p>Title</p></div>';
html.plainContent = 'this is plainContent';
```
......@@ -264,7 +245,7 @@ Represents the file data. It is a child class of [UnifiedRecord](#unifiedrecord)
**Example**
```js
let file = new UDMF.File();
let file = new unifiedDataChannel.File();
file.details = {
name: 'test',
type: 'txt',
......@@ -285,7 +266,7 @@ Represents the image data. It is a child class of [File](#file) and is used to d
**Example**
```js
let image = new UDMF.Image();
let image = new unifiedDataChannel.Image();
image.imageUri = 'schema://com.samples.test/files/test.jpg';
```
......@@ -302,7 +283,7 @@ Represents video data. It is a child class of [File](#file) and is used to descr
**Example**
```js
let video = new UDMF.Video();
let video = new unifiedDataChannel.Video();
video.videoUri = 'schema://com.samples.test/files/test.mp4';
```
......@@ -319,7 +300,7 @@ Represents video data. It is a child class of [File](#file) and is used to descr
**Example**
```js
let audio = new UDMF.Audio();
let audio = new unifiedDataChannel.Audio();
audio.audioUri = 'schema://com.samples.test/files/test.mp3';
```
......@@ -336,7 +317,7 @@ Represents the folder data. It is a child class of [File](#file) and is used to
**Example**
```js
let folder = new UDMF.Folder();
let folder = new unifiedDataChannel.Folder();
folder.folderUri = 'schema://com.samples.test/files/folder/';
```
......@@ -353,14 +334,14 @@ Represents specific data types defined by OpenHarmony. It is a child class of [U
**Example**
```js
let sdr = new UDMF.SystemDefinedRecord();
let sdr = new unifiedDataChannel.SystemDefinedRecord();
let u8Array = new Uint8Array([1, 2, 3, 4, 5, 6, 7, 8, 9, 10]);
sdr.details = {
title: 'recordTitle',
version: 1,
content: u8Array,
};
let unifiedData = new UDMF.UnifiedData(sdr);
let unifiedData = new unifiedDataChannel.UnifiedData(sdr);
```
## SystemDefinedForm
......@@ -380,7 +361,7 @@ Represents the widget data. It is a child class of [SystemDefinedRecord](#system
**Example**
```js
let form = new UDMF.SystemDefinedForm();
let form = new unifiedDataChannel.SystemDefinedForm();
form.formId = 123456;
form.formName = 'MyFormName';
form.bundleName = 'MyBundleName';
......@@ -392,7 +373,7 @@ form.details = {
formKey2: 'formValue',
formKey3: u8Array,
};
let unifiedData = new UDMF.UnifiedData(form);
let unifiedData = new unifiedDataChannel.UnifiedData(form);
```
## SystemDefinedAppItem
......@@ -413,7 +394,7 @@ Represents the icon data. It is a child class of [SystemDefinedRecord](#systemde
**Example**
```js
let appItem = new UDMF.SystemDefinedAppItem();
let appItem = new unifiedDataChannel.SystemDefinedAppItem();
appItem.appId = 'MyAppId';
appItem.appName = 'MyAppName';
appItem.appIconId = 'MyAppIconId';
......@@ -426,7 +407,7 @@ appItem.details = {
appItemKey2: 'appItemValue',
appItemKey3: u8Array,
};
let unifiedData = new UDMF.UnifiedData(appItem);
let unifiedData = new unifiedDataChannel.UnifiedData(appItem);
```
## SystemDefinedPixelMap
......@@ -445,19 +426,23 @@ Represents the image data corresponding to the [PixelMap](js-apis-image.md#pixel
import image from '@ohos.multimedia.image'; // Module where the PixelMap class is defined.
const color = new ArrayBuffer(96); // Create a PixelMap object.
let opts = { editable: true, pixelFormat: 3, size: { height: 4, width: 6 } }
let opts: image.InitializationOptions = {
editable: true, pixelFormat: 3, size: {
height: 4, width: 6
}
}
image.createPixelMap(color, opts, (error, pixelmap) => {
if(error) {
console.error('Failed to create pixelmap.');
} else {
console.info('Succeeded in creating pixelmap.');
let arrayBuf = new ArrayBuffer(pixelmap.getPixelBytesNumber());
pixelmap.readPixelsToBuffer(arrayBuf);
let u8Array = new Uint8Array(arrayBuf);
let sdpixel = new UDMF.SystemDefinedPixelMap();
sdpixel.rawData = u8Array;
let unifiedData = new UDMF.UnifiedData(sdpixel);
}
if (error) {
console.error('Failed to create pixelmap.');
} else {
console.info('Succeeded in creating pixelmap.');
let arrayBuf = new ArrayBuffer(pixelmap.getPixelBytesNumber());
pixelmap.readPixelsToBuffer(arrayBuf);
let u8Array = new Uint8Array(arrayBuf);
let sdpixel = new unifiedDataChannel.SystemDefinedPixelMap();
sdpixel.rawData = u8Array;
let unifiedData = new unifiedDataChannel.UnifiedData(sdpixel);
}
})
```
......@@ -475,11 +460,11 @@ Represents the custom data type for applications only. It is a child class of [U
**Example**
```js
let record = new UDMF.ApplicationDefinedRecord();
let record = new unifiedDataChannel.ApplicationDefinedRecord();
let u8Array = new Uint8Array([1, 2, 3, 4, 5, 6, 7, 8, 9, 10]);
record.applicationDefinedType = 'ApplicationDefinedType';
record.rawData = u8Array;
let unifiedData = new UDMF.UnifiedData(record);
let unifiedData = new unifiedDataChannel.UnifiedData(record);
```
## Intention
......@@ -502,11 +487,11 @@ Defines the data operation performed by the UDMF. It includes two optional param
| Name | Type | Readable| Writable| Mandatory| Description |
|-----------|-------------------------|----|----|----|-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
| intention | [Intention](#intention) | Yes | Yes | No | Type of the data channel 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.|
| key | string | Yes | Yes | No | Unique identifier of the data object in the UDMF, which can be obtained from the value returned by [insertData](#unifieddatachannelinsertdata).<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.|
## UDMF.insertData
## unifiedDataChannel.insertData
insertData(options: Options, data: UnifiedData, callback: AsyncCallback&lt;string&gt;): void
......@@ -525,30 +510,32 @@ Inserts data to the UDMF public data channel. This API uses an asynchronous call
**Example**
```ts
import UDMF from '@ohos.data.UDMF';
import unifiedDataChannel from '@ohos.data.unifiedDataChannel';
import { BusinessError } from '@ohos.base';
let plainText = new UDMF.PlainText();
let plainText = new unifiedDataChannel.PlainText();
plainText.textContent = 'hello world!';
let unifiedData = new UDMF.UnifiedData(plainText);
let unifiedData = new unifiedDataChannel.UnifiedData(plainText);
let options = {
intention: UDMF.Intention.DATA_HUB
let options: unifiedDataChannel.Options = {
intention: unifiedDataChannel.Intention.DATA_HUB
}
try {
UDMF.insertData(options, unifiedData, (err, data) => {
if (err === undefined) {
console.info(`Succeeded in inserting data. key = ${data}`);
} else {
console.error(`Failed to insert data. code is ${err.code},message is ${err.message} `);
}
});
} catch(e) {
console.error(`Insert data throws an exception. code is ${e.code},message is ${e.message} `);
unifiedDataChannel.insertData(options, unifiedData, (err, data) => {
if (err === undefined) {
console.info(`Succeeded in inserting data. key = ${data}`);
} else {
console.error(`Failed to insert data. code is ${err.code},message is ${err.message} `);
}
});
} catch (e) {
let error: BusinessError = e as BusinessError;
console.error(`Insert data throws an exception. code is ${error.code},message is ${error.message} `);
}
```
## UDMF.insertData
## unifiedDataChannel.insertData
insertData(options: Options, data: UnifiedData): Promise&lt;string&gt;
......@@ -572,27 +559,29 @@ Inserts data to the UDMF public data channel. This API uses a promise to return
**Example**
```ts
import UDMF from '@ohos.data.UDMF';
import unifiedDataChannel from '@ohos.data.unifiedDataChannel';
import { BusinessError } from '@ohos.base';
let plainText = new UDMF.PlainText();
let plainText = new unifiedDataChannel.PlainText();
plainText.textContent = 'hello world!';
let unifiedData = new UDMF.UnifiedData(plainText);
let unifiedData = new unifiedDataChannel.UnifiedData(plainText);
let options = {
intention: UDMF.Intention.DATA_HUB
let options: unifiedDataChannel.Options = {
intention: unifiedDataChannel.Intention.DATA_HUB
}
try {
UDMF.insertData(options, unifiedData).then((data) => {
console.info(`Succeeded in inserting data. key = ${data}`);
}).catch((err) => {
console.error(`Failed to insert data. code is ${err.code},message is ${err.message} `);
});
} catch(e) {
console.error(`Insert data throws an exception. code is ${e.code},message is ${e.message} `);
unifiedDataChannel.insertData(options, unifiedData).then((data) => {
console.info(`Succeeded in inserting data. key = ${data}`);
}).catch((err: BusinessError) => {
console.error(`Failed to insert data. code is ${err.code},message is ${err.message} `);
});
} catch (e) {
let error: BusinessError = e as BusinessError;
console.error(`Insert data throws an exception. code is ${error.code},message is ${error.message} `);
}
```
## UDMF.updateData
## unifiedDataChannel.updateData
updateData(options: Options, data: UnifiedData, callback: AsyncCallback&lt;void&gt;): void
......@@ -611,30 +600,32 @@ Updates the data in the UDMF public data channel. This API uses an asynchronous
**Example**
```ts
import UDMF from '@ohos.data.UDMF';
import unifiedDataChannel from '@ohos.data.unifiedDataChannel';
import { BusinessError } from '@ohos.base';
let plainText = new UDMF.PlainText();
let plainText = new unifiedDataChannel.PlainText();
plainText.textContent = 'hello world!';
let unifiedData = new UDMF.UnifiedData(plainText);
let unifiedData = new unifiedDataChannel.UnifiedData(plainText);
let options = {
key: 'udmf://DataHub/com.ohos.test/0123456789'
let options: unifiedDataChannel.Options = {
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} `);
unifiedDataChannel.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) {
let error: BusinessError = e as BusinessError;
console.error(`Update data throws an exception. code is ${error.code},message is ${error.message} `);
}
```
## UDMF.updateData
## unifiedDataChannel.updateData
updateData(options: Options, data: UnifiedData): Promise&lt;void&gt;
......@@ -658,28 +649,30 @@ Updates the data in the UDMF public data channel. This API uses a promise to ret
**Example**
```ts
import UDMF from '@ohos.data.UDMF';
import unifiedDataChannel from '@ohos.data.unifiedDataChannel';
import { BusinessError } from '@ohos.base';
let plainText = new UDMF.PlainText();
let plainText = new unifiedDataChannel.PlainText();
plainText.textContent = 'hello world!';
let unifiedData = new UDMF.UnifiedData(plainText);
let unifiedData = new unifiedDataChannel.UnifiedData(plainText);
let options = {
key: 'udmf://DataHub/com.ohos.test/0123456789'
let options: unifiedDataChannel.Options = {
key: 'udmf://DataHub/com.ohos.test/0123456789'
};
try {
UDMF.updateData(options, unifiedData).then(() => {
console.info('Succeeded in updating data.');
}).catch((err) => {
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} `);
unifiedDataChannel.updateData(options, unifiedData).then(() => {
console.info('Succeeded in updating data.');
}).catch((err: BusinessError) => {
console.error(`Failed to update data. code is ${err.code},message is ${err.message} `);
});
} catch (e) {
let error: BusinessError = e as BusinessError;
console.error(`Update data throws an exception. code is ${error.code},message is ${error.message} `);
}
```
## UDMF.queryData
## unifiedDataChannel.queryData
queryData(options: Options, callback: AsyncCallback&lt;Array&lt;UnifiedData&gt;&gt;): void
......@@ -697,35 +690,38 @@ Queries data in the UDMF public data channel. This API uses an asynchronous call
**Example**
```ts
import UDMF from '@ohos.data.UDMF';
import unifiedDataChannel from '@ohos.data.unifiedDataChannel';
import uniformTypeDescriptor from '@ohos.data.uniformTypeDescriptor';
import { BusinessError } from '@ohos.base';
let options = {
intention: UDMF.Intention.DATA_HUB
let options: unifiedDataChannel.Options = {
intention: unifiedDataChannel.Intention.DATA_HUB
};
try {
UDMF.queryData(options, (err, data) => {
if (err === undefined) {
console.info(`Succeeded in querying data. size = ${data.length}`);
for (let i = 0; i < data.length; i++) {
let records = data[i].getRecords();
for (let j = 0; j < records.length; j++) {
if (records[j].getType() === UDMF.UnifiedDataType.PLAIN_TEXT) {
let text = <UDMF.PlainText>(records[j]);
console.info(`${i + 1}.${text.textContent}`);
}
}
}
} else {
console.error(`Failed to query data. code is ${err.code},message is ${err.message} `);
unifiedDataChannel.queryData(options, (err, data) => {
if (err === undefined) {
console.info(`Succeeded in querying data. size = ${data.length}`);
for (let i = 0; i < data.length; i++) {
let records = data[i].getRecords();
for (let j = 0; j < records.length; j++) {
if (records[j].getType() === uniformTypeDescriptor.UniformDataType.PLAIN_TEXT) {
let text = records[j] as unifiedDataChannel.PlainText;
console.info(`${i + 1}.${text.textContent}`);
}
}
});
} catch(e) {
console.error(`Query data throws an exception. code is ${e.code},message is ${e.message} `);
}
} else {
console.error(`Failed to query data. code is ${err.code},message is ${err.message} `);
}
});
} catch (e) {
let error: BusinessError = e as BusinessError;
console.error(`Query data throws an exception. code is ${error.code},message is ${error.message} `);
}
```
## UDMF.queryData
## unifiedDataChannel.queryData
queryData(options: Options): Promise&lt;Array&lt;UnifiedData&gt;&gt;
......@@ -748,33 +744,36 @@ Queries data in the UDMF public data channel. This API uses a promise to return
**Example**
```ts
import UDMF from '@ohos.data.UDMF';
import unifiedDataChannel from '@ohos.data.unifiedDataChannel';
import uniformTypeDescriptor from '@ohos.data.uniformTypeDescriptor';
import { BusinessError } from '@ohos.base';
let options = {
key: 'udmf://DataHub/com.ohos.test/0123456789'
let options: unifiedDataChannel.Options = {
key: 'udmf://DataHub/com.ohos.test/0123456789'
};
try {
UDMF.queryData(options).then((data) => {
console.info(`Succeeded in querying data. size = ${data.length}`);
for (let i = 0; i < data.length; i++) {
let records = data[i].getRecords();
for (let j = 0; j < records.length; j++) {
if (records[j].getType() === UDMF.UnifiedDataType.PLAIN_TEXT) {
let text = <UDMF.PlainText>(records[j]);
console.info(`${i + 1}.${text.textContent}`);
}
}
unifiedDataChannel.queryData(options).then((data) => {
console.info(`Succeeded in querying data. size = ${data.length}`);
for (let i = 0; i < data.length; i++) {
let records = data[i].getRecords();
for (let j = 0; j < records.length; j++) {
if (records[j].getType() === uniformTypeDescriptor.UniformDataType.PLAIN_TEXT) {
let text = records[j] as unifiedDataChannel.PlainText;
console.info(`${i + 1}.${text.textContent}`);
}
}).catch((err) => {
console.error(`Failed to query data. code is ${err.code},message is ${err.message} `);
});
} catch(e) {
console.error(`Query data throws an exception. code is ${e.code},message is ${e.message} `);
}
}
}).catch((err: BusinessError) => {
console.error(`Failed to query data. code is ${err.code},message is ${err.message} `);
});
} catch (e) {
let error: BusinessError = e as BusinessError;
console.error(`Query data throws an exception. code is ${error.code},message is ${error.message} `);
}
```
## UDMF.deleteData
## unifiedDataChannel.deleteData
deleteData(options: Options, callback: AsyncCallback&lt;Array&lt;UnifiedData&gt;&gt;): void
......@@ -792,35 +791,38 @@ Deletes data from the UDMF public data channel. This API uses an asynchronous ca
**Example**
```ts
import UDMF from '@ohos.data.UDMF';
import unifiedDataChannel from '@ohos.data.unifiedDataChannel';
import uniformTypeDescriptor from '@ohos.data.uniformTypeDescriptor';
import { BusinessError } from '@ohos.base';
let options = {
intention: UDMF.Intention.DATA_HUB
let options: unifiedDataChannel.Options = {
intention: unifiedDataChannel.Intention.DATA_HUB
};
try {
UDMF.deleteData(options, (err, data) => {
if (err === undefined) {
console.info(`Succeeded in deleting data. size = ${data.length}`);
for (let i = 0; i < data.length; i++) {
let records = data[i].getRecords();
for (let j = 0; j < records.length; j++) {
if (records[j].getType() === UDMF.UnifiedDataType.PLAIN_TEXT) {
let text = <UDMF.PlainText>(records[j]);
console.info(`${i + 1}.${text.textContent}`);
}
}
}
} else {
console.error(`Failed to delete data. code is ${err.code},message is ${err.message} `);
unifiedDataChannel.deleteData(options, (err, data) => {
if (err === undefined) {
console.info(`Succeeded in deleting data. size = ${data.length}`);
for (let i = 0; i < data.length; i++) {
let records = data[i].getRecords();
for (let j = 0; j < records.length; j++) {
if (records[j].getType() === uniformTypeDescriptor.UniformDataType.PLAIN_TEXT) {
let text = records[j] as unifiedDataChannel.PlainText;
console.info(`${i + 1}.${text.textContent}`);
}
}
});
} catch(e) {
console.error(`Delete data throws an exception. code is ${e.code},message is ${e.message} `);
}
} else {
console.error(`Failed to delete data. code is ${err.code},message is ${err.message} `);
}
});
} catch (e) {
let error: BusinessError = e as BusinessError;
console.error(`Delete data throws an exception. code is ${error.code},message is ${error.message} `);
}
```
## UDMF.deleteData
## unifiedDataChannel.deleteData
deleteData(options: Options): Promise&lt;Array&lt;UnifiedData&gt;&gt;
......@@ -843,28 +845,31 @@ Deletes data from the UDMF public data channel. This API uses a promise to retur
**Example**
```ts
import UDMF from '@ohos.data.UDMF';
import unifiedDataChannel from '@ohos.data.unifiedDataChannel';
import uniformTypeDescriptor from '@ohos.data.uniformTypeDescriptor';
import { BusinessError } from '@ohos.base';
let options = {
key: 'udmf://DataHub/com.ohos.test/0123456789'
let options: unifiedDataChannel.Options = {
key: 'udmf://DataHub/com.ohos.test/0123456789'
};
try {
UDMF.deleteData(options).then((data) => {
console.info(`Succeeded in deleting data. size = ${data.length}`);
for (let i = 0; i < data.length; i++) {
let records = data[i].getRecords();
for (let j = 0; j < records.length; j++) {
if (records[j].getType() === UDMF.UnifiedDataType.PLAIN_TEXT) {
let text = <UDMF.PlainText>(records[j]);
console.info(`${i + 1}.${text.textContent}`);
}
}
unifiedDataChannel.deleteData(options).then((data) => {
console.info(`Succeeded in deleting data. size = ${data.length}`);
for (let i = 0; i < data.length; i++) {
let records = data[i].getRecords();
for (let j = 0; j < records.length; j++) {
if (records[j].getType() === uniformTypeDescriptor.UniformDataType.PLAIN_TEXT) {
let text = records[j] as unifiedDataChannel.PlainText;
console.info(`${i + 1}.${text.textContent}`);
}
}).catch((err) => {
console.error(`Failed to delete data. code is ${err.code},message is ${err.message} `);
});
} catch(e) {
console.error(`Delete data throws an exception. code is ${e.code},message is ${e.message} `);
}
}
}).catch((err: BusinessError) => {
console.error(`Failed to delete data. code is ${err.code},message is ${err.message} `);
});
} catch (e) {
let error: BusinessError = e as BusinessError;
console.error(`Query data throws an exception. code is ${error.code},message is ${error.message} `);
}
```
# @ohos.data.uniformTypeDescriptor (Standard Data Definition)
The **uniformTypeDescriptor** module provides abstract definitions of OpenHarmony standardized data types.
> **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.
## Modules to Import
```js
import uniformTypeDescriptor from '@ohos.data.uniformTypeDescriptor';
```
## UniformDataType
Enumerates the types of OpenHarmony standard data.
**System capability**: SystemCapability.DistributedDataManager.UDMF.Core
| Name | Value | Description |
|----------------------------|------------------------------|-----------|
| TEXT | 'general.text' | Text. |
| PLAIN_TEXT | 'general.plain-text' | Plaintext. |
| HYPERLINK | 'general.hyperlink' | Hyperlink. |
| HTML | 'general.html' | HyperText Markup Language (HTML). |
| FILE | 'general.file' | File. |
| IMAGE | 'general.image' | Image. |
| VIDEO | 'general.video' | Video. |
| AUDIO | 'general.audio' | Audio. |
| FOLDER | 'general.folder' | Folder. |
| OPENHARMONY_FORM | 'openharmony.form' | Widget. |
| OPENHARMONY_APP_ITEM | 'openharmony.app-item' | Icon. |
| OPENHARMONY_PIXEL_MAP | 'openharmony.pixel-map' | Pixel map. |
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册