• 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 properties of the text content. Both the key and value of the object are of the string type. 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
31let plainTextDetails : Record<string, string> = {
32  'attr1': 'value1',
33  'attr2': 'value2',
34}
35let plainText : uniformDataStruct.PlainText = {
36  uniformDataType: 'general.plain-text',
37  textContent : 'This is plainText textContent example',
38  abstract : 'this is abstract',
39  details : plainTextDetails,
40}
41console.info('plainText.uniformDataType: ' + plainText.uniformDataType);
42if(plainText.details != undefined){
43  let plainTextDetailsObj : Record<string, string> = plainText.details;
44  for(let kv of Object.entries(plainTextDetailsObj)) {
45    console.info('plainText.details.attr: ' + kv[0] + ', value:' + kv[1]);
46  }
47}
48```
49
50## Hyperlink
51
52Represents data of the hyperlink type.
53
54**System capability**: SystemCapability.DistributedDataManager.UDMF.Core
55
56| Name       | Type  | Read-Only| Optional| Description          |
57| ----------- | ------ | ---- | ---- |--------------|
58| 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).|
59| url         | string | No  | No  | URL.      |
60| description | string | No  | Yes  | Description of the linked content. This parameter is optional. By default, it is an empty string.|
61| details | Record<string, string> | No  | Yes | Object of the dictionary type used to describe the properties of the hyperlink. Both the key and value of the object are of the string type. <br/>Example:<br>{<br>"title":"Title of the hyperlink",<br>"content":"Content"<br>}<br> By default, it is an empty dictionary object.|
62
63**Example**
64
65```ts
66let hyperlinkDetails : Record<string, string> = {
67  'attr1': 'value1',
68  'attr2': 'value2',
69}
70let hyperlink : uniformDataStruct.Hyperlink = {
71  uniformDataType:'general.hyperlink',
72  url : 'www.XXX.com',
73  description : 'This is the description of this hyperlink',
74  details : hyperlinkDetails,
75}
76console.info('hyperlink.uniformDataType: ' + hyperlink.uniformDataType);
77```
78
79## HTML
80
81Represents data of the HTML type.
82
83**System capability**: SystemCapability.DistributedDataManager.UDMF.Core
84
85| Name        | Type  | Read-Only| Optional| Description                   |
86| ------------ | ------ | ---- | ---- |-----------------------|
87| 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).|
88| htmlContent  | string | No  | No  | Content in HTML format.            |
89| plainContent | string | No  | Yes  | Plaintext without HTML tags. This parameter is optional. By default, it is an empty string.|
90| details | Record<string, string> | No  | Yes  | Object of the dictionary type used to describe the properties of the HTML content. Both the key and value of the object are of the string type. <br/>Example:<br>{<br>"title":"Title of the HTML content",<br>"content":"Content"<br>}<br> By default, it is an empty dictionary object.|
91
92**Example**
93
94```ts
95let htmlObjDetails : Record<string, string> = {
96  'attr1': 'value1',
97  'attr2': 'value2',
98}
99let htmlObj : uniformDataStruct.HTML = {
100  uniformDataType :'general.html',
101  htmlContent: '<div><p>Title</p></div>',
102  plainContent : 'this is plainContent',
103  details : htmlObjDetails,
104}
105console.info('htmlObj.uniformDataType: ' + htmlObj.uniformDataType);
106```
107
108## OpenHarmonyAppItem
109
110Represents data of the home screen icon type defined by the system.
111
112**System capability**: SystemCapability.DistributedDataManager.UDMF.Core
113
114| Name       | Type  | Read-Only| Optional| Description             |
115| ----------- | ------ | ---- | ---- |-----------------|
116| 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).|
117| appId       | string | No  | No  | ID of the application, for which the icon is used.     |
118| appName     | string | No  | No  | Name of the application, for which the icon is used.      |
119| appIconId   | string | No  | No  | Image ID of the icon.       |
120| appLabelId  | string | No  | No  | Label ID corresponding to the icon name.   |
121| bundleName  | string | No  | No  | Bundle name corresponding to the icon.|
122| abilityName | string | No  | No  | Application ability name corresponding to the icon.|
123| 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.|
124
125
126**Example**
127
128```ts
129let u8Array = new Uint8Array([1, 2, 3, 4, 5, 6, 7, 8, 9, 10]);
130let appItemDetails : Record<string, number | string | Uint8Array> = {
131  'appItemKey1': 123,
132  'appItemKey2': 'appItemValue',
133  'appItemKey3': u8Array,
134}
135let appItem : uniformDataStruct.OpenHarmonyAppItem = {
136  uniformDataType:'openharmony.app-item',
137  appId : 'MyAppId',
138  appName : 'MyAppName',
139  appIconId : 'MyAppIconId',
140  appLabelId : 'MyAppLabelId',
141  bundleName : 'MyBundleName',
142  abilityName : 'MyAbilityName',
143  details : appItemDetails,
144}
145console.info('appItem.uniformDataType: ' + appItem.uniformDataType);
146```
147
148## ContentForm<sup>14+</sup>
149
150Represents data of the content widget type.
151
152**System capability**: SystemCapability.DistributedDataManager.UDMF.Core
153
154| Name        | Type  | Read-Only| Optional| Description                                                                                                                            |
155|------------| ------ | ---- |----|--------------------------------------------------------------------------------------------------------------------------------|
156| uniformDataType | 'general.content-form'| Yes  | No | Uniform data type, which has a fixed value of **general.content-form**.
157| title      | string | No  | No | Title of the content widget.|
158| thumbData  | Uint8Array | No  | Yes | Image data in the content widget.|
159| description| string | No  | Yes | Description of the content widget.|
160| appIcon    | Uint8Array | No  | Yes | Application icon data in the content widget.|
161| appName    | string | No  | Yes | Application name in the content widget.|
162| linkUri    | string | No  | Yes | Hyperlink in the content widget.|
163
164
165**Example**
166
167```ts
168let thumbDataU8Array = new Uint8Array([1, 2, 3, 4, 5]);
169let appIconU8Array = new Uint8Array([6, 7, 8, 9, 10]);
170let contentForm : uniformDataStruct.ContentForm = {
171    uniformDataType : 'general.content-form',
172    title : 'MyTitle',
173    thumbData : thumbDataU8Array,
174    description : 'MyDescription',
175    appName : 'MyAppName',
176    linkUri : 'MyLinkUri',
177    appIcon : appIconU8Array
178}
179console.info('contentForm.uniformDataType: ' + contentForm.uniformDataType);
180```
181
182## Form<sup>15+</sup>
183
184Represents data of the widget type defined by the system.
185
186**System capability**: SystemCapability.DistributedDataManager.UDMF.Core
187
188| Name        | Type  | Read-Only| Optional| Description                                                                                                                            |
189|------------| ------ | ---- |----|--------------------------------------------------------------------------------------------------------------------------------|
190| 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).
191| formId     | number | No  | No | Widget ID.|
192| formName   | string | No  | No | Widget name.|
193| bundleName | string | No  | No | Bundle to which the widget belongs.|
194| abilityName| string | No  | No | Ability name corresponding to the widget.|
195| module     | string | No  | No | Module to which the widget belongs.|
196| 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.|
197
198
199**Example**
200
201```ts
202let u8Array = new Uint8Array([1, 2, 3, 4, 5, 6, 7, 8, 9, 10]);
203let formDetails : Record<string, number | string | Uint8Array> = {
204  'formKey1': 123,
205  'formKey2': 'formValue',
206  'formKey3': u8Array,
207}
208let form : uniformDataStruct.Form = {
209  uniformDataType : 'openharmony.form',
210  formId : 1,
211  formName : 'formName',
212  bundleName : 'com.xx.app',
213  abilityName : 'abilityName',
214  module : 'module',
215  details : formDetails
216}
217console.info('form.uniformDataType: ' + form.uniformDataType);
218```
219
220## FileUri<sup>15+</sup>
221
222Represents data of the file URI type.
223
224**System capability**: SystemCapability.DistributedDataManager.UDMF.Core
225
226| Name        | Type  | Read-Only| Optional| Description                                                                                                                            |
227|------------| ------ | ---- |----|--------------------------------------------------------------------------------------------------------------------------------|
228| 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).
229| oriUri     | string | No  | No | File URI.|
230| fileType   | string | No  | No | File type.|
231| 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.|
232
233
234**Example**
235
236```ts
237let u8Array = new Uint8Array([1, 2, 3, 4, 5, 6, 7, 8, 9, 10]);
238let fileUriDetails : Record<string, number | string | Uint8Array> = {
239  'fileUriKey1': 123,
240  'fileUriKey2': 'fileUriValue',
241  'fileUriKey3': u8Array,
242}
243let fileUri : uniformDataStruct.FileUri = {
244  uniformDataType : 'general.file-uri',
245  oriUri : 'www.xx.com',
246  fileType : 'general.image',
247  details : fileUriDetails
248}
249console.info('fileUri.uniformDataType: ' + fileUri.uniformDataType);
250```
251
252## PixelMap<sup>15+</sup>
253
254Represents data of the pixel map type defined by the system.
255
256**System capability**: SystemCapability.DistributedDataManager.UDMF.Core
257
258| Name        | Type  | Read-Only| Optional| Description                                                                                                                            |
259|------------| ------ | ---- |----|--------------------------------------------------------------------------------------------------------------------------------|
260| 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).
261| pixelMap     | image.PixelMap | No  | No | Binary data of the pixel map.|
262| 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.|
263
264
265**Example**
266
267```ts
268import image from '@ohos.multimedia.image';
269
270let u8Array = new Uint8Array([1, 2, 3, 4, 5, 6, 7, 8, 9, 10]);
271let arrayBuffer = new ArrayBuffer(4*200*200);
272let opt : image.InitializationOptions = { editable: true, pixelFormat: 3, size: { height: 200, width: 200 }, alphaType: 3 };
273let pixelMapDetails : Record<string, number | string | Uint8Array> = {
274  'pixelMapKey1': 123,
275  'pixelMapKey2': 'pixelMapValue',
276  'pixelMapKey3': u8Array,
277}
278let pixelMap : uniformDataStruct.PixelMap = {
279  uniformDataType : 'openharmony.pixel-map',
280  pixelMap : image.createPixelMapSync(arrayBuffer, opt),
281  details : pixelMapDetails
282}
283console.info('pixelMap.uniformDataType: ' + pixelMap.uniformDataType);
284```
285