• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1# @ohos.data.uniformDataStruct (Uniform Data Structs)
2
3As a part of the Unified Data Management Framework (UDMF), the **uniformDataStruct** module provides data structs corresponding to certain [UniformDataTypes](js-apis-data-uniformTypeDescriptor.md#uniformdatatype) for service scenarios of many-to-many data sharing across applications. It helps simplify data interaction and reduce the data type adaptation workload.
4
5> **NOTE**
6>
7> The initial APIs of this module are supported since API version 12. Newly added APIs will be marked with a superscript to indicate their earliest API version.
8
9## Modules to Import
10
11```js
12import { uniformDataStruct } from '@kit.ArkData';
13```
14
15## PlainText
16
17Represents data of the plain text type.
18
19**System capability**: SystemCapability.DistributedDataManager.UDMF.Core
20
21| Name       | Type  | Read-Only| Optional| Description                   |
22| ----------- | ------ | ---- | ---- |-----------------------|
23| uniformDataType | 'general.plain-text'| Yes  | No  | Uniform data type, which has a fixed value of **general.plain-text**. For details, see [UniformDataType](js-apis-data-uniformTypeDescriptor.md#uniformdatatype).               |
24| textContent | string | No  | No  | Plaintext content.               |
25| abstract    | string | No  | Yes  | Text abstract. It is an empty string by default.|
26| details | Record<string, string> | No  | Yes| Object of the dictionary type used to describe the attributes of the text content. Both the key and value of the object are of the string type. For example, the following is a **details** object used to describe the properties of a file:<br>{<br>"title":"Title of the file",<br>"content":"Content of the file"<br>}<br>By default, it is an empty dictionary object. |
27
28**Example**
29
30```ts
31import { unifiedDataChannel, uniformTypeDescriptor } from '@kit.ArkData';
32let plainTextDetails : Record<string, string> = {
33  'attr1': 'value1',
34  'attr2': 'value2'
35}
36let plainText : uniformDataStruct.PlainText = {
37  uniformDataType: 'general.plain-text',
38  textContent : 'This is plainText textContent example',
39  abstract : 'this is abstract',
40  details : plainTextDetails
41}
42console.info('plainText.uniformDataType: ' + plainText.uniformDataType);
43if(plainText.details != undefined){
44  let plainTextDetailsObj : Record<string, string> = plainText.details;
45  for(let kv of Object.entries(plainTextDetailsObj)) {
46    console.info('plainText.details.attr: ' + kv[0] + ', value:' + kv[1]);
47  }
48}
49let record = new unifiedDataChannel.UnifiedRecord(uniformTypeDescriptor.UniformDataType.PLAIN_TEXT, plainText);
50```
51
52## Hyperlink
53
54Represents data of the hyperlink type.
55
56**System capability**: SystemCapability.DistributedDataManager.UDMF.Core
57
58| Name       | Type  | Read-Only| Optional| Description          |
59| ----------- | ------ | ---- | ---- |--------------|
60| uniformDataType | 'general.hyperlink'| Yes  | No  | Uniform data type, which has a fixed value of **general.hyperlink**. For details, see [UniformDataType](js-apis-data-uniformTypeDescriptor.md#uniformdatatype). |
61| url         | string | No  | No  | URL.      |
62| description | string | No  | Yes  | Description of the linked content. This parameter is optional. By default, it is an empty string.|
63| details | Record<string, string> | No  | Yes | Object of the dictionary type used to describe the attributes of the hyperlink. Both the key and value of the object are of the string type. For example, the following is a **details** object used to describe the properties of a file:<br>{<br>"title":"Title of the file",<br>"content":"Content of the file"<br>}<br>By default, it is an empty dictionary object. |
64
65**Example**
66
67```ts
68import { unifiedDataChannel, uniformTypeDescriptor } from '@kit.ArkData';
69let hyperlinkDetails : Record<string, string> = {
70  'attr1': 'value1',
71  'attr2': 'value2'
72}
73let hyperlink : uniformDataStruct.Hyperlink = {
74  uniformDataType:'general.hyperlink',
75  url : 'www.XXX.com',
76  description : 'This is the description of this hyperlink',
77  details : hyperlinkDetails
78}
79console.info('hyperlink.uniformDataType: ' + hyperlink.uniformDataType);
80let record = new unifiedDataChannel.UnifiedRecord(uniformTypeDescriptor.UniformDataType.HYPERLINK, hyperlink);
81```
82
83## HTML
84
85Represents data of the HTML type.
86
87**System capability**: SystemCapability.DistributedDataManager.UDMF.Core
88
89| Name        | Type  | Read-Only| Optional| Description                   |
90| ------------ | ------ | ---- | ---- |-----------------------|
91| uniformDataType | 'general.html'| Yes  | No  | Uniform data type, which has a fixed value of **general.html**. For details, see [UniformDataType](js-apis-data-uniformTypeDescriptor.md#uniformdatatype). |
92| htmlContent  | string | No  | No  | Content in HTML format.            |
93| plainContent | string | No  | Yes  | Plaintext without HTML tags. This parameter is optional. By default, it is an empty string.|
94| details | Record<string, string> | No  | Yes  | Object of the dictionary type used to describe the attributes of the HTML content. Both the key and value of the object are of the string type. For example, the following is a **details** object used to describe the properties of a file:<br>{<br>"title":"Title of the file",<br>"content":"Content of the file"<br>}<br>By default, it is an empty dictionary object. |
95
96**Example**
97
98```ts
99import { unifiedDataChannel, uniformTypeDescriptor } from '@kit.ArkData';
100let htmlObjDetails : Record<string, string> = {
101  'attr1': 'value1',
102  'attr2': 'value2'
103}
104let htmlObj : uniformDataStruct.HTML = {
105  uniformDataType :'general.html',
106  htmlContent: '<div><p>Title</p></div>',
107  plainContent : 'this is plainContent',
108  details : htmlObjDetails
109}
110console.info('htmlObj.uniformDataType: ' + htmlObj.uniformDataType);
111let record = new unifiedDataChannel.UnifiedRecord(uniformTypeDescriptor.UniformDataType.HTML, htmlObj);
112```
113
114## OpenHarmonyAppItem
115
116Represents data of the home screen icon type defined by the system.
117
118**System capability**: SystemCapability.DistributedDataManager.UDMF.Core
119
120| Name       | Type  | Read-Only| Optional| Description             |
121| ----------- | ------ | ---- | ---- |-----------------|
122| uniformDataType | 'openharmony.app-item'| Yes  | No  | Uniform data type, which has a fixed value of **openharmony.app-item**. For details, see [UniformDataType](js-apis-data-uniformTypeDescriptor.md#uniformdatatype). |
123| appId       | string | No  | No  | ID of the application, for which the icon is used.     |
124| appName     | string | No  | No  | Name of the application, for which the icon is used.      |
125| appIconId   | string | No  | No  | Image ID of the icon.       |
126| appLabelId  | string | No  | No  | Label ID corresponding to the icon name.   |
127| bundleName  | string | No  | No  | Bundle name corresponding to the icon.|
128| abilityName | string | No  | No  | Application ability name corresponding to the icon.|
129| details | Record<string, number \| string \| Uint8Array> | No  | Yes  | Object of the dictionary type used to describe the icon. The key is of the string type, and the value can be a number, a string, or a Uint8Array. By default, it is an empty dictionary object.|
130
131**Example**
132
133```ts
134import { unifiedDataChannel, uniformTypeDescriptor } from '@kit.ArkData';
135let u8Array = new Uint8Array([1, 2, 3, 4, 5, 6, 7, 8, 9, 10]);
136let appItemDetails : Record<string, number | string | Uint8Array> = {
137  'appItemKey1': 123,
138  'appItemKey2': 'appItemValue',
139  'appItemKey3': u8Array
140}
141let appItem : uniformDataStruct.OpenHarmonyAppItem = {
142  uniformDataType:'openharmony.app-item',
143  appId : 'MyAppId',
144  appName : 'MyAppName',
145  appIconId : 'MyAppIconId',
146  appLabelId : 'MyAppLabelId',
147  bundleName : 'MyBundleName',
148  abilityName : 'MyAbilityName',
149  details : appItemDetails
150}
151console.info('appItem.uniformDataType: ' + appItem.uniformDataType);
152let record = new unifiedDataChannel.UnifiedRecord(uniformTypeDescriptor.UniformDataType.OPENHARMONY_APP_ITEM, appItem);
153```
154
155## ContentForm<sup>14+</sup>
156
157Represents data of the content widget type.
158
159**System capability**: SystemCapability.DistributedDataManager.UDMF.Core
160
161| Name        | Type  | Read-Only| Optional| Description                                                                                                                            |
162|------------| ------ | ---- |----|--------------------------------------------------------------------------------------------------------------------------------|
163| uniformDataType | 'general.content-form'| Yes  | No | Uniform data type, which has a fixed value of **general.content-form**. |
164| title      | string | No  | No | Title of the content widget.|
165| thumbData  | Uint8Array | No  | Yes | Image data in the content widget.|
166| description| string | No  | Yes | Description of the content widget.|
167| appIcon    | Uint8Array | No  | Yes | Application icon data in the content widget.|
168| appName    | string | No  | Yes | Application name in the content widget.|
169| linkUri    | string | No  | Yes | Hyperlink in the content widget.|
170
171**Example**
172
173```ts
174import { unifiedDataChannel, uniformTypeDescriptor } from '@kit.ArkData';
175let thumbDataU8Array = new Uint8Array([1, 2, 3, 4, 5]);
176let appIconU8Array = new Uint8Array([6, 7, 8, 9, 10]);
177let contentForm : uniformDataStruct.ContentForm = {
178  uniformDataType : 'general.content-form',
179  title : 'MyTitle',
180  thumbData : thumbDataU8Array,
181  description : 'MyDescription',
182  appName : 'MyAppName',
183  linkUri : 'MyLinkUri',
184  appIcon : appIconU8Array
185}
186console.info('contentForm.uniformDataType: ' + contentForm.uniformDataType);
187let record = new unifiedDataChannel.UnifiedRecord(uniformTypeDescriptor.UniformDataType.CONTENT_FORM, contentForm);
188```
189
190## Form<sup>15+</sup>
191
192Represents data of the widget type defined by the system.
193
194**System capability**: SystemCapability.DistributedDataManager.UDMF.Core
195
196| Name        | Type  | Read-Only| Optional| Description                                                                                                                            |
197|------------| ------ | ---- |----|--------------------------------------------------------------------------------------------------------------------------------|
198| uniformDataType | 'openharmony.form'| Yes  | No | Uniform data type, which has a fixed value of **openharmony.form**. For details, see [UniformDataType](js-apis-data-uniformTypeDescriptor.md#uniformdatatype). |
199| formId     | number | No  | No | Widget ID.|
200| formName   | string | No  | No | Widget name.|
201| bundleName | string | No  | No | Bundle to which the widget belongs.|
202| abilityName| string | No  | No | Ability name corresponding to the widget.|
203| module     | string | No  | No | Module to which the widget belongs.|
204| details | Record<string, number \| string \| Uint8Array> | No  | Yes  | Object of the dictionary type used to describe the icon. The key is of the string type, and the value can be a number, a string, or a Uint8Array. By default, it is an empty dictionary object.|
205
206**Example**
207
208```ts
209import { unifiedDataChannel, uniformTypeDescriptor } from '@kit.ArkData';
210let u8Array = new Uint8Array([1, 2, 3, 4, 5, 6, 7, 8, 9, 10]);
211let formDetails : Record<string, number | string | Uint8Array> = {
212  'formKey1': 123,
213  'formKey2': 'formValue',
214  'formKey3': u8Array
215}
216let form : uniformDataStruct.Form = {
217  uniformDataType : 'openharmony.form',
218  formId : 1,
219  formName : 'formName',
220  bundleName : 'com.xx.app',
221  abilityName : 'abilityName',
222  module : 'module',
223  details : formDetails
224}
225console.info('form.uniformDataType: ' + form.uniformDataType);
226let record = new unifiedDataChannel.UnifiedRecord(uniformTypeDescriptor.UniformDataType.OPENHARMONY_FORM, form);
227```
228
229## FileUri<sup>15+</sup>
230
231Represents data of the file URI type.
232
233**System capability**: SystemCapability.DistributedDataManager.UDMF.Core
234
235| Name        | Type  | Read-Only| Optional| Description                                                                                                                            |
236|------------| ------ | ---- |----|--------------------------------------------------------------------------------------------------------------------------------|
237| uniformDataType | 'general.file-uri'| Yes  | No | Uniform data type, which has a fixed value of **general.file-uri**. For details, see [UniformDataType](js-apis-data-uniformTypeDescriptor.md#uniformdatatype). |
238| oriUri     | string | No  | No | File path.|
239| fileType   | string | No  | No | File type, which must be UTD. For details, see [Prebuilt UTDs](../../database/uniform-data-type-list.md). The maximum length of the value is 1024 bytes.|
240| details | Record<string, number \| string \| Uint8Array> | No  | Yes  | Object of the dictionary type used to describe the icon. The key is of the string type, and the value can be a number, a string, or a Uint8Array. By default, it is an empty dictionary object.|
241
242**Example**
243
244```ts
245import { unifiedDataChannel, uniformTypeDescriptor } from '@kit.ArkData';
246let u8Array = new Uint8Array([1, 2, 3, 4, 5, 6, 7, 8, 9, 10]);
247let fileUriDetails : Record<string, number | string | Uint8Array> = {
248  'fileUriKey1': 123,
249  'fileUriKey2': 'fileUriValue',
250  'fileUriKey3': u8Array
251}
252let fileUri : uniformDataStruct.FileUri = {
253  uniformDataType : 'general.file-uri',
254  oriUri : 'www.xx.com',
255  fileType : 'general.image',
256  details : fileUriDetails
257}
258console.info('fileUri.uniformDataType: ' + fileUri.uniformDataType);
259// You are advised to set type to uniformTypeDescriptor.UniformDataType.FILE_URI to use the uniform data struct of FileUri type to construct records.
260let record = new unifiedDataChannel.UnifiedRecord(uniformTypeDescriptor.UniformDataType.FILE_URI, fileUri);
261```
262
263## PixelMap<sup>15+</sup>
264
265Represents data of the pixel map type defined by the system.
266
267**System capability**: SystemCapability.DistributedDataManager.UDMF.Core
268
269| Name        | Type  | Read-Only| Optional| Description                                                                                                                            |
270|------------| ------ | ---- |----|--------------------------------------------------------------------------------------------------------------------------------|
271| uniformDataType | 'openharmony.pixel-map'| Yes  | No | Uniform data type, which has a fixed value of **openharmony.pixel-map**. For details, see [UniformDataType](js-apis-data-uniformTypeDescriptor.md#uniformdatatype). |
272| pixelMap     | image.PixelMap | No  | No | Binary data of the pixel map.|
273| details | Record<string, number \| string \| Uint8Array> | No  | Yes  | Object of the dictionary type used to describe the icon. The key is of the string type, and the value can be a number, a string, or a Uint8Array. By default, it is an empty dictionary object.|
274
275**Example**
276
277```ts
278import { unifiedDataChannel, uniformTypeDescriptor } from '@kit.ArkData';
279import { image } from '@kit.ImageKit';
280
281let u8Array = new Uint8Array([1, 2, 3, 4, 5, 6, 7, 8, 9, 10]);
282let arrayBuffer = new ArrayBuffer(4*200*200);
283let opt : image.InitializationOptions = { editable: true, pixelFormat: 3, size: { height: 200, width: 200 }, alphaType: 3 };
284let pixelMapDetails : Record<string, number | string | Uint8Array> = {
285  'pixelMapKey1': 123,
286  'pixelMapKey2': 'pixelMapValue',
287  'pixelMapKey3': u8Array
288}
289let pixelMap : uniformDataStruct.PixelMap = {
290  uniformDataType : 'openharmony.pixel-map',
291  pixelMap : image.createPixelMapSync(arrayBuffer, opt),
292  details : pixelMapDetails
293}
294console.info('pixelMap.uniformDataType: ' + pixelMap.uniformDataType);
295let record = new unifiedDataChannel.UnifiedRecord(uniformTypeDescriptor.UniformDataType.OPENHARMONY_PIXEL_MAP, pixelMap);
296```
297