• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1# @ohos.data.unifiedDataChannel (标准化数据通路)
2<!--Kit: ArkData-->
3<!--Subsystem: DistributedDataManager-->
4<!--Owner: @jcwen-->
5<!--Designer: @junathuawei1; @zph000-->
6<!--Tester: @lj_liujing; @yippo; @logic42-->
7<!--Adviser: @ge-yafang-->
8
9本模块为统一数据管理框架(Unified Data Management Framework,UDMF)的组成部分,针对多对多跨应用数据共享的不同业务场景提供了标准化的数据通路,提供了标准化的数据接入与读取接口。同时对文本、图片等数据类型提供了标准化定义,方便不同应用间进行数据交互,减少数据类型适配的工作量。UDMF处理数据时,不会解析用户数据的内容,存储路径安全性较低,不建议传输个人敏感数据和隐私数据。
10
11> **说明:**
12>
13> 本模块首批接口从API version 10开始支持。后续版本的新增接口,采用上角标单独标记接口的起始版本。
14
15## 导入模块
16
17```ts
18import { unifiedDataChannel } from '@kit.ArkData';
19```
20
21## ShareOptions<sup>12+</sup>
22
23UDMF支持的设备内使用范围类型枚举。
24
25**原子化服务API:** 从API version 12开始,该接口支持在原子化服务中使用。
26
27**系统能力:** SystemCapability.DistributedDataManager.UDMF.Core
28
29| 名称          | 值 | 说明                |
30|-------------|---|-------------------|
31| IN_APP       | 0 | 表示允许在本设备同应用内使用。 |
32| CROSS_APP | 1 | 表示允许在本设备内跨应用使用。 |
33
34## GetDelayData<sup>12+</sup>
35
36type GetDelayData = (type: string) => UnifiedData
37
38对UnifiedData的延迟封装,支持延迟获取数据。当前只支持同设备剪贴板场景,后续场景待开发。
39
40**原子化服务API:** 从API version 12开始,该接口支持在原子化服务中使用。
41
42**系统能力:** SystemCapability.DistributedDataManager.UDMF.Core
43
44**参数:**
45
46| 参数名 | 类型 | 必填 | 说明 |
47| -------- | -------- | -------- | -------- |
48| type | string | 是 | 作为延迟数据类型的标识。 |
49
50**返回值:**
51
52| 类型                                     | 说明                      |
53| ---------------------------------------- |-------------------------|
54| [UnifiedData](#unifieddata) | 当延迟回调触发时,返回一个UnifiedData对象。 |
55
56**示例:**
57
58```ts
59import { uniformDataStruct, uniformTypeDescriptor } from '@kit.ArkData';
60
61let getDelayData: unifiedDataChannel.GetDelayData = ((type: string) => {
62  if (type == uniformTypeDescriptor.UniformDataType.PLAIN_TEXT) {
63    let plainTextDetails : Record<string, string> = {
64      'attr1': 'value1',
65      'attr2': 'value2'
66    }
67    let plainText : uniformDataStruct.PlainText = {
68      uniformDataType: 'general.plain-text',
69      textContent : 'This is a plain text example',
70      abstract : 'This is abstract',
71      details : plainTextDetails
72    }
73    let text = new unifiedDataChannel.UnifiedRecord(uniformTypeDescriptor.UniformDataType.PLAIN_TEXT, plainText);
74    let textData = new unifiedDataChannel.UnifiedData(text);
75    return textData;
76  }
77  return new unifiedDataChannel.UnifiedData();
78});
79```
80
81## ValueType<sup>12+</sup>
82
83type ValueType = number | string | boolean | image.PixelMap | Want | ArrayBuffer | object | null | undefined
84
85用于表示统一数据记录允许的数据字段类型。
86
87**原子化服务API:** 从API version 12开始,该接口支持在原子化服务中使用。
88
89**系统能力:** SystemCapability.DistributedDataManager.UDMF.Core
90
91| 类型 | 说明 |
92| -------- | -------- |
93| number | 表示number的类型。 |
94| string | 表示string的类型。 |
95| boolean | 表示boolean的类型。 |
96| image.PixelMap | 表示[image.PixelMap](../apis-image-kit/arkts-apis-image-PixelMap.md)的类型。 |
97| Want | 表示[Want](../apis-ability-kit/js-apis-app-ability-want.md)的类型。 |
98| ArrayBuffer | 表示ArrayBuffer的类型。 |
99| object | 表示object的类型。 |
100| null | 表示null。 |
101| undefined | 表示undefined。 |
102
103## UnifiedDataProperties<sup>12+</sup>
104
105定义统一数据对象中所有数据记录的属性,包含时间戳、标签、粘贴范围以及一些附加数据等。
106
107**原子化服务API:** 从API version 12开始,该接口支持在原子化服务中使用。
108
109**系统能力:** SystemCapability.DistributedDataManager.UDMF.Core
110
111| 名称 | 类型 | 只读 | 可选 | 说明 |
112| -------- | -------- | -------- | -------- | -------- |
113| extras<sup>12+</sup> | Record<string, object> | 否 | 是 | 是一个字典类型对象,用于设置其他附加属性数据。非必填字段,默认值为空字典对象。 |
114| tag<sup>12+</sup> | string | 否 | 是 | 用户自定义标签。非必填字段,默认值为空字符串。 |
115| timestamp<sup>12+</sup> | Date | 是 | 是 | [UnifiedData](#unifieddata)的生成时间戳。默认值为1970年1月1日(UTC)。 |
116| shareOptions<sup>12+</sup> | [ShareOptions](#shareoptions12) | 否 | 是 | 指示[UnifiedData](#unifieddata)支持的设备内使用范围,非必填字段,默认值为CROSS_APP。 |
117| getDelayData<sup>12+</sup> | [GetDelayData](#getdelaydata12) | 否 | 是 | 延迟获取数据回调。当前只支持同设备剪贴板场景,后续场景待开发。非必填字段,默认值为undefined。 |
118
119**示例:**
120
121```ts
122import { uniformDataStruct, uniformTypeDescriptor } from '@kit.ArkData';
123
124let properties = new unifiedDataChannel.UnifiedDataProperties();
125properties.extras = {
126  key: {
127    title: 'MyTitle',
128    content: 'MyContent'
129  }
130};
131properties.tag = "This is a tag of properties";
132properties.shareOptions = unifiedDataChannel.ShareOptions.CROSS_APP;
133properties.getDelayData = ((type: string) => {
134  if (type == uniformTypeDescriptor.UniformDataType.PLAIN_TEXT) {
135    let plainTextDetails : Record<string, string> = {
136      'attr1': 'value1',
137      'attr2': 'value2'
138    }
139    let plainText : uniformDataStruct.PlainText = {
140      uniformDataType: 'general.plain-text',
141      textContent : 'This is a plain text example',
142      abstract : 'This is abstract',
143      details : plainTextDetails
144    }
145    let text = new unifiedDataChannel.UnifiedRecord(uniformTypeDescriptor.UniformDataType.PLAIN_TEXT, plainText);
146    let textData = new unifiedDataChannel.UnifiedData(text);
147    return textData;
148  }
149  return new unifiedDataChannel.UnifiedData();
150});
151```
152
153## UnifiedData
154
155表示UDMF统一数据对象,提供封装一组数据记录的方法。
156
157**系统能力:** SystemCapability.DistributedDataManager.UDMF.Core
158
159### 属性
160
161| 名称 | 类型 | 只读 | 可选 | 说明                                                                                              |
162| -------- | -------- | -------- | -------- |-------------------------------------------------------------------------------------------------|
163| properties<sup>12+</sup> | [UnifiedDataProperties](#unifieddataproperties12) | 否 | 否 | 当前统一数据对象中所有数据记录的属性,包含时间戳、标签、粘贴范围以及一些附加数据等。<br/>**原子化服务API:** 从API version 12开始,该接口支持在原子化服务中使用。 |
164
165### constructor<sup>12+</sup>
166
167constructor()
168
169用于创建统一数据对象。
170
171**原子化服务API:** 从API version 12开始,该接口支持在原子化服务中使用。
172
173**系统能力:** SystemCapability.DistributedDataManager.UDMF.Core
174
175**示例:**
176
177```ts
178let unifiedData = new unifiedDataChannel.UnifiedData();
179```
180
181### constructor
182
183constructor(record: UnifiedRecord)
184
185用于创建带有一条数据记录的统一数据对象。
186
187**原子化服务API:** 从API version 11开始,该接口支持在原子化服务中使用。
188
189**系统能力:** SystemCapability.DistributedDataManager.UDMF.Core
190
191**参数:**
192
193| 参数名 | 类型                            | 必填 | 说明                                      |
194| ------ | ------------------------------- | ---- |-----------------------------------------|
195| record | [UnifiedRecord](#unifiedrecord) | 是   | 要添加到统一数据对象中的数据记录,该记录为UnifiedRecord或其子类对象。 |
196
197**错误码:**
198
199以下错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)。
200
201| **错误码ID** | **错误信息**                                |
202| ------------ | ------------------------------------------- |
203| 401          | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameters types.  |
204
205**示例:**
206
207```ts
208import { uniformDataStruct, uniformTypeDescriptor } from '@kit.ArkData';
209let plainText : uniformDataStruct.PlainText = {
210  uniformDataType: 'general.plain-text',
211  textContent : 'This is a plain text example',
212  abstract : 'This is abstract'
213}
214let text = new unifiedDataChannel.UnifiedRecord(uniformTypeDescriptor.UniformDataType.PLAIN_TEXT, plainText);
215let unifiedData = new unifiedDataChannel.UnifiedData(text);
216```
217
218### addRecord
219
220addRecord(record: UnifiedRecord): void
221
222在当前统一数据对象中添加一条数据记录。
223
224**原子化服务API:** 从API version 11开始,该接口支持在原子化服务中使用。
225
226**系统能力:** SystemCapability.DistributedDataManager.UDMF.Core
227
228**参数:**
229
230| 参数名 | 类型                            | 必填 | 说明                                          |
231| ------ | ------------------------------- | ---- |---------------------------------------------|
232| record | [UnifiedRecord](#unifiedrecord) | 是   | 要添加到统一数据对象中的数据记录,该记录为UnifiedRecord子类对象。|
233
234**错误码:**
235
236以下错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)。
237
238| **错误码ID** | **错误信息**                                |
239| ------------ | ------------------------------------------- |
240| 401          | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameters types.  |
241
242**示例:**
243
244```ts
245import { uniformDataStruct, uniformTypeDescriptor } from '@kit.ArkData';
246let plainText : uniformDataStruct.PlainText = {
247  uniformDataType: 'general.plain-text',
248  textContent : 'This is a plain text example',
249  abstract : 'This is abstract'
250}
251let text = new unifiedDataChannel.UnifiedRecord(uniformTypeDescriptor.UniformDataType.PLAIN_TEXT, plainText);
252let unifiedData = new unifiedDataChannel.UnifiedData(text);
253
254let hyperlink : uniformDataStruct.Hyperlink = {
255  uniformDataType:'general.hyperlink',
256  url : 'www.XXX.com',
257  description : 'This is the description of the hyperlink'
258}
259let link = new unifiedDataChannel.UnifiedRecord(uniformTypeDescriptor.UniformDataType.HYPERLINK, hyperlink);
260unifiedData.addRecord(link);
261```
262
263### getRecords
264
265getRecords(): Array\<UnifiedRecord\>
266
267将当前统一数据对象中的所有数据记录取出。通过本接口取出的数据为UnifiedRecord类型,需通过[getType](#gettype)获取数据类型后转为子类再使用。
268
269**原子化服务API:** 从API version 11开始,该接口支持在原子化服务中使用。
270
271**系统能力** :SystemCapability.DistributedDataManager.UDMF.Core
272
273**返回值:**
274
275| 类型                                     | 说明                      |
276| ---------------------------------------- |-------------------------|
277| Array\<[UnifiedRecord](#unifiedrecord)\> | 当前统一数据对象内所添加的记录。 |
278
279**示例:**
280
281```ts
282import { uniformDataStruct, uniformTypeDescriptor } from '@kit.ArkData';
283
284let plainText : uniformDataStruct.PlainText = {
285  uniformDataType: 'general.plain-text',
286  textContent : 'This is a plain text example',
287  abstract : 'This is abstract'
288}
289let text = new unifiedDataChannel.UnifiedRecord(uniformTypeDescriptor.UniformDataType.PLAIN_TEXT, plainText);
290let unifiedData = new unifiedDataChannel.UnifiedData(text);
291
292let hyperlink : uniformDataStruct.Hyperlink = {
293  uniformDataType:'general.hyperlink',
294  url : 'www.XXX.com',
295  description : 'This is the description of the hyperlink'
296}
297let link = new unifiedDataChannel.UnifiedRecord(uniformTypeDescriptor.UniformDataType.HYPERLINK, hyperlink);
298unifiedData.addRecord(link);
299
300let records = unifiedData.getRecords();
301for (let i = 0; i < records.length; i++) {
302  let record = records[i];
303  let types = record.getTypes();
304  if (types.includes(uniformTypeDescriptor.UniformDataType.PLAIN_TEXT)) {
305    let plainText = record.getEntry(uniformTypeDescriptor.UniformDataType.PLAIN_TEXT) as unifiedDataChannel.PlainText;
306    console.info(`textContent: ${plainText.textContent}`);
307  } else if (types.includes(uniformTypeDescriptor.UniformDataType.HYPERLINK)) {
308    let hyperlink = record.getEntry(uniformTypeDescriptor.UniformDataType.HYPERLINK) as unifiedDataChannel.Hyperlink;
309    console.info(`linkUrl: ${hyperlink.url}`);
310  }
311}
312```
313
314### hasType<sup>12+</sup>
315
316hasType(type: string): boolean
317
318检查当前统一数据对象中是否有指定的数据类型,检查范围包括使用[addEntry](#addentry15)函数添加的数据类型。
319
320针对文件类型,若UnifiedData的类型集合中包含"general.jpeg",在调用hasType接口判断是否包括"general.image"类型时,结果返回true(类型"general.jpeg"归属于类型"general.image")。
321
322**原子化服务API:** 从API version 12开始,该接口支持在原子化服务中使用。
323
324**系统能力** :SystemCapability.DistributedDataManager.UDMF.Core
325
326**参数:**
327
328| 参数名 | 类型                            | 必填 | 说明                                          |
329| ------ | ------------------------------- | ---- |---------------------------------------------|
330| type | string | 是   | 要查询的数据类型,见[UniformDataType](js-apis-data-uniformTypeDescriptor.md#uniformdatatype)。|
331
332**返回值:**
333
334| 类型                                     | 说明                      |
335| ---------------------------------------- |-------------------------|
336| boolean | 有指定的数据类型返回true,否则返回false。 |
337
338**错误码:**
339
340以下错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)。
341
342| **错误码ID** | **错误信息**                                |
343| ------------ | ------------------------------------------- |
344| 401          | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameters types.  |
345
346**示例:**
347
348```ts
349import { uniformDataStruct, uniformTypeDescriptor } from '@kit.ArkData';
350
351let plainText : uniformDataStruct.PlainText = {
352  uniformDataType: 'general.plain-text',
353  textContent : 'This is a plain text example',
354  abstract : 'This is abstract'
355}
356let text = new unifiedDataChannel.UnifiedRecord(uniformTypeDescriptor.UniformDataType.PLAIN_TEXT, plainText);
357let unifiedData = new unifiedDataChannel.UnifiedData(text);
358
359let hyperlink : uniformDataStruct.Hyperlink = {
360  uniformDataType:'general.hyperlink',
361  url : 'www.XXX.com',
362  description : 'This is the description of the hyperlink'
363}
364let link = new unifiedDataChannel.UnifiedRecord(uniformTypeDescriptor.UniformDataType.HYPERLINK, hyperlink);
365unifiedData.addRecord(link);
366
367let hasPlainText = unifiedData.hasType(uniformTypeDescriptor.UniformDataType.PLAIN_TEXT);
368let hasLink = unifiedData.hasType(uniformTypeDescriptor.UniformDataType.HYPERLINK);
369```
370
371### getTypes<sup>12+</sup>
372
373getTypes(): Array\<string\>
374
375获取当前统一数据对象所有数据记录的类型。
376
377**原子化服务API:** 从API version 12开始,该接口支持在原子化服务中使用。
378
379**系统能力** :SystemCapability.DistributedDataManager.UDMF.Core
380
381**返回值:**
382
383| 类型                                     | 说明                      |
384| ---------------------------------------- |-------------------------|
385| Array\<string\> | [UniformDataType](js-apis-data-uniformTypeDescriptor.md#uniformdatatype)类型的数组,表示当前统一数据对象所有数据记录对应的数据类型。 |
386
387**示例:**
388
389```ts
390import { uniformDataStruct, uniformTypeDescriptor } from '@kit.ArkData';
391
392let plainText : uniformDataStruct.PlainText = {
393  uniformDataType: 'general.plain-text',
394  textContent : 'This is a plain text example',
395  abstract : 'This is abstract'
396}
397let text = new unifiedDataChannel.UnifiedRecord(uniformTypeDescriptor.UniformDataType.PLAIN_TEXT, plainText);
398let unifiedData = new unifiedDataChannel.UnifiedData(text);
399
400let hyperlink : uniformDataStruct.Hyperlink = {
401  uniformDataType:'general.hyperlink',
402  url : 'www.XXX.com',
403  description : 'This is the description of the hyperlink'
404}
405let link = new unifiedDataChannel.UnifiedRecord(uniformTypeDescriptor.UniformDataType.HYPERLINK, hyperlink);
406unifiedData.addRecord(link);
407
408let types = unifiedData.getTypes();
409```
410
411## Summary
412
413描述统一数据对象的数据摘要,包括数据类型和大小。
414
415**原子化服务API:** 从API version 11开始,该接口支持在原子化服务中使用。
416
417**系统能力:** SystemCapability.DistributedDataManager.UDMF.Core
418
419| 名称 | 类型 | 只读 | 可选 | 说明 |
420| -------- | -------- | -------- | -------- | -------- |
421| summary   | Record<string, number> | 否 | 否 | 是一个字典类型对象,key表示数据类型(见[UniformDataType](js-apis-data-uniformTypeDescriptor.md#uniformdatatype)),value为统一数据对象中该类型记录大小总和(单位:Byte)。 |
422| totalSize | number | 否 | 否 | 统一数据对象内记录总大小(单位:Byte)。 |
423
424**示例:**
425
426```ts
427function parseSummary(summary : unifiedDataChannel.Summary) {
428  let summaryRecord = summary.summary as Record<string, number>;
429  if (summaryRecord) {
430    for (let item of Object.entries(summaryRecord)) {
431      if (item && item.length <= 1) {
432        continue;
433      }
434      let summaryStr : string = String(item[1]);
435      let info : string[] = summaryStr.split(",");
436      if (info.length <= 1) {
437        continue;
438      }
439      let key : string = info[0];
440      let value : string = info[1];
441    }
442  }
443}
444```
445
446## UnifiedRecord
447
448对UDMF支持的数据内容的抽象定义,称为数据记录。一个统一数据对象内包含一条或多条数据记录,例如一条文本记录、一条图片记录、一条HTML记录等。从API version 15开始,支持往数据记录中增加同一内容的不同表现样式,数据使用方根据业务需要获取对应的样式。
449
450### constructor<sup>12+</sup>
451
452constructor()
453
454用于创建数据记录。
455
456**原子化服务API:** 从API version 12开始,该接口支持在原子化服务中使用。
457
458**系统能力:** SystemCapability.DistributedDataManager.UDMF.Core
459
460**示例:**
461
462```ts
463let unifiedRecord = new unifiedDataChannel.UnifiedRecord();
464```
465
466### constructor<sup>12+</sup>
467
468constructor(type: string, value: ValueType)
469
470用于创建指定类型和值的数据记录。<br/>当参数value为[image.PixelMap](../apis-image-kit/arkts-apis-image-PixelMap.md)类型时,参数type必须对应为[UniformDataType](js-apis-data-uniformTypeDescriptor.md#uniformdatatype)中OPENHARMONY_PIXEL_MAP的值;<br/>当参数value为[Want](../apis-ability-kit/js-apis-app-ability-want.md)类型时,参数type必须对应为[UniformDataType](js-apis-data-uniformTypeDescriptor.md#uniformdatatype)中OPENHARMONY_WANT的值。
471
472**原子化服务API:** 从API version 12开始,该接口支持在原子化服务中使用。
473
474**系统能力:** SystemCapability.DistributedDataManager.UDMF.Core
475
476**参数:**
477
478| 参数名 | 类型                            | 必填 | 说明                                      |
479| ------ | ------------------------------- | ---- |-----------------------------------------|
480| type | string | 是   | 要创建的数据记录的类型。 |
481| value | [ValueType](#valuetype12) | 是   | 要创建的数据记录的值。 |
482
483**错误码:**
484
485以下错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)。
486
487| **错误码ID** | **错误信息**                                |
488| ------------ | ------------------------------------------- |
489| 401          | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameters types; 3. Parameter verification failed.  |
490
491**示例:**
492
493```ts
494import { uniformDataStruct, uniformTypeDescriptor } from '@kit.ArkData';
495import { image } from '@kit.ImageKit';
496
497let hyperlink : uniformDataStruct.Hyperlink = {
498  uniformDataType:'general.hyperlink',
499  url : 'www.XXX.com',
500  description : 'This is the description of the hyperlink'
501}
502let hyperlinkRecord = new unifiedDataChannel.UnifiedRecord(uniformTypeDescriptor.UniformDataType.HYPERLINK, hyperlink);
503
504let plainText : uniformDataStruct.PlainText = {
505  uniformDataType: 'general.plain-text',
506  textContent : 'This is a plain text example',
507  abstract : 'This is abstract'
508}
509let text = new unifiedDataChannel.UnifiedRecord(uniformTypeDescriptor.UniformDataType.PLAIN_TEXT, plainText);
510
511let arrayBuffer = new ArrayBuffer(4 * 200 * 200);
512let opt : image.InitializationOptions = { editable: true, pixelFormat: 3, size: { height: 200, width: 200 }, alphaType: 3 };
513let pixelMap : uniformDataStruct.PixelMap = {
514  uniformDataType : 'openharmony.pixel-map',
515  pixelMap : image.createPixelMapSync(arrayBuffer, opt)
516}
517let pixelMapRecord = new unifiedDataChannel.UnifiedRecord(uniformTypeDescriptor.UniformDataType.OPENHARMONY_PIXEL_MAP, pixelMap);
518```
519
520### getType
521
522getType(): string
523
524获取当前数据记录的类型。由于从统一数据对象中调用[getRecords](#getrecords)所取出的数据是UnifiedRecord对象,因此需要通过本接口查询此记录的具体类型,再将该UnifiedRecord对象转换为其子类,调用子类接口。
525
526**原子化服务API:** 从API version 11开始,该接口支持在原子化服务中使用。
527
528**系统能力** :SystemCapability.DistributedDataManager.UDMF.Core
529
530**返回值:**
531
532| 类型   | 说明                                                   |
533| ------ |------------------------------------------------------|
534| string | 当前数据记录对应的具体数据类型,见[UniformDataType](js-apis-data-uniformTypeDescriptor.md#uniformdatatype)。|
535
536**示例:**
537
538```ts
539import { uniformDataStruct, uniformTypeDescriptor } from '@kit.ArkData';
540
541let plainText : uniformDataStruct.PlainText = {
542  uniformDataType: 'general.plain-text',
543  textContent : 'This is a plain text example',
544  abstract : 'This is abstract'
545}
546let text = new unifiedDataChannel.UnifiedRecord(uniformTypeDescriptor.UniformDataType.PLAIN_TEXT, plainText);
547let unifiedData = new unifiedDataChannel.UnifiedData(text);
548
549let records = unifiedData.getRecords();
550if (records[0].getType() == uniformTypeDescriptor.UniformDataType.PLAIN_TEXT) {
551  let plainText = records[0] as unifiedDataChannel.PlainText;
552  console.info(`textContent: ${plainText.textContent}`);
553}
554```
555
556### getValue<sup>12+</sup>
557
558getValue(): ValueType
559
560获取当前数据记录的值。
561
562**原子化服务API:** 从API version 12开始,该接口支持在原子化服务中使用。
563
564**系统能力** :SystemCapability.DistributedDataManager.UDMF.Core
565
566**返回值:**
567
568| 类型   | 说明                                                   |
569| ------ |------------------------------------------------------|
570| [ValueType](#valuetype12) | 当前数据记录对应的值。 |
571
572**示例:**
573
574```ts
575import { uniformDataStruct, uniformTypeDescriptor } from '@kit.ArkData';
576
577let text = new unifiedDataChannel.UnifiedRecord(uniformTypeDescriptor.UniformDataType.PLAIN_TEXT, 'this is value of text');
578let value = text.getValue();
579
580let hyperlinkDetails : Record<string, string> = {
581  'attr1': 'value1',
582  'attr2': 'value2'
583}
584let hyperlink : uniformDataStruct.Hyperlink = {
585  uniformDataType:'general.hyperlink',
586  url : 'www.XXX.com',
587  description : 'This is the description of the hyperlink',
588  details : hyperlinkDetails
589}
590let hyperlinkRecord = new unifiedDataChannel.UnifiedRecord(uniformTypeDescriptor.UniformDataType.HYPERLINK, hyperlink);
591let hyperlinkValue = hyperlinkRecord.getValue();
592```
593
594### addEntry<sup>15+</sup>
595
596addEntry(type: string, value: ValueType): void
597
598在当前数据记录中添加一条指定数据类型和内容的数据,通过该方法增加的数据类型和内容为同一内容的不同表现样式.
599
600**原子化服务API:** 从API version 15开始,该接口支持在原子化服务中使用。
601
602**系统能力:** SystemCapability.DistributedDataManager.UDMF.Core
603
604**参数:**
605
606| 参数名 | 类型                            | 必填 | 说明                                      |
607| ------ | ------------------------------- | ---- |-----------------------------------------|
608| type | string | 是   | 要创建的数据类型,见[UniformDataType](js-apis-data-uniformTypeDescriptor.md#uniformdatatype)。 |
609| value | [ValueType](#valuetype12) | 是   | 要创建的数据的值。 |
610
611**错误码:**
612
613以下错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)。
614
615| **错误码ID** | **错误信息**                                |
616| ------------ | ------------------------------------------- |
617| 401          | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameters types.  |
618
619**示例:**
620
621```ts
622import { uniformDataStruct, uniformTypeDescriptor } from '@kit.ArkData';
623
624let fileUriDetails : Record<string, string> = {
625  'attr1': 'value1',
626  'attr2': 'value2'
627}
628let fileUri : uniformDataStruct.FileUri = {
629  uniformDataType : 'general.file-uri',
630  oriUri : 'file://data/image/1.png',
631  fileType : 'general.image',
632  details : fileUriDetails
633}
634let hyperlink : uniformDataStruct.Hyperlink = {
635  uniformDataType:'general.hyperlink',
636  url : 'file://data/image/1.png',
637  description : 'This is the description of the hyperlink'
638}
639
640let unifiedData = new unifiedDataChannel.UnifiedData();
641let record = new unifiedDataChannel.UnifiedRecord(uniformTypeDescriptor.UniformDataType.HYPERLINK, hyperlink);
642record.addEntry(uniformTypeDescriptor.UniformDataType.FILE_URI, fileUri);
643unifiedData.addRecord(record);
644```
645
646### getEntry<sup>15+</sup>
647
648getEntry(type: string): ValueType
649
650通过数据类型获取数据记录中的数据内容。
651
652**原子化服务API:** 从API version 15开始,该接口支持在原子化服务中使用。
653
654**系统能力:** SystemCapability.DistributedDataManager.UDMF.Core
655
656**参数:**
657
658| 参数名 | 类型                            | 必填 | 说明                                      |
659| ------ | ------------------------------- | ---- |-----------------------------------------|
660| type | string | 是   | 要获取数据的类型,见[UniformDataType](js-apis-data-uniformTypeDescriptor.md#uniformdatatype)。 |
661
662**返回值:**
663
664| 类型   | 说明                                                   |
665| ------ |------------------------------------------------------|
666| [ValueType](#valuetype12) | 当前数据记录对应的值。 |
667
668**错误码:**
669
670以下错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)。
671
672| **错误码ID** | **错误信息**                                |
673| ------------ | ------------------------------------------- |
674| 401          | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameters types.  |
675
676**示例:**
677
678```ts
679import { uniformDataStruct, uniformTypeDescriptor } from '@kit.ArkData';
680
681let fileUriDetails : Record<string, string> = {
682  'attr1': 'value1',
683  'attr2': 'value2'
684}
685let fileUri : uniformDataStruct.FileUri = {
686  uniformDataType : 'general.file-uri',
687  oriUri : 'file://data/image/1.png',
688  fileType : 'general.image',
689  details : fileUriDetails
690}
691let formDetails : Record<string, string> = {
692  'attr1': 'value1',
693  'attr2': 'value2'
694}
695let form : uniformDataStruct.Form = {
696  uniformDataType : 'openharmony.form',
697  formId : 1,
698  formName : 'form',
699  bundleName : 'com.xx.app',
700  abilityName : 'ability',
701  module : 'module',
702  details : formDetails
703}
704
705let unifiedData = new unifiedDataChannel.UnifiedData();
706let record = new unifiedDataChannel.UnifiedRecord(uniformTypeDescriptor.UniformDataType.OPENHARMONY_FORM, form);
707record.addEntry(uniformTypeDescriptor.UniformDataType.FILE_URI, fileUri);
708unifiedData.addRecord(record);
709
710let records = unifiedData.getRecords();
711for (let i = 0; i < records.length; i++) {
712  let unifiedDataRecord = records[i] as unifiedDataChannel.UnifiedRecord;
713  let fileUriRead : uniformDataStruct.FileUri = unifiedDataRecord.getEntry(uniformTypeDescriptor.UniformDataType.FILE_URI) as uniformDataStruct.FileUri;
714  if (fileUriRead != undefined) {
715    console.info(`oriUri: ${fileUriRead.oriUri}`);
716  }
717  let formRead = unifiedDataRecord.getEntry(uniformTypeDescriptor.UniformDataType.OPENHARMONY_FORM) as uniformDataStruct.Form;
718  if (formRead != undefined) {
719    console.info(`formName: ${formRead.formName}`);
720  }
721}
722```
723
724### getEntries<sup>15+</sup>
725
726getEntries(): Record<string, ValueType>
727
728获取当前数据记录中所有数据的类型和内容。
729
730**原子化服务API:** 从API version 15开始,该接口支持在原子化服务中使用。
731
732**系统能力:** SystemCapability.DistributedDataManager.UDMF.Core
733
734**返回值:**
735
736| 类型   | 说明                                                   |
737| ------ |------------------------------------------------------|
738| Record<string, [ValueType](#valuetype12)> | 当前数据记录对应的类型和内容。 |
739
740**示例:**
741
742```ts
743import { uniformDataStruct, uniformTypeDescriptor } from '@kit.ArkData';
744
745let fileUriDetails : Record<string, string> = {
746  'attr1': 'value1',
747  'attr2': 'value2'
748}
749let fileUri : uniformDataStruct.FileUri = {
750  uniformDataType : 'general.file-uri',
751  oriUri : 'file://data/image/1.png',
752  fileType : 'general.image',
753  details : fileUriDetails
754}
755let formDetails : Record<string, string> = {
756  'attr1': 'value1',
757  'attr2': 'value2'
758}
759let form : uniformDataStruct.Form = {
760  uniformDataType : 'openharmony.form',
761  formId : 1,
762  formName : 'form',
763  bundleName : 'com.xx.app',
764  abilityName : 'ability',
765  module : 'module',
766  details : formDetails
767}
768
769let unifiedData = new unifiedDataChannel.UnifiedData();
770let record = new unifiedDataChannel.UnifiedRecord(uniformTypeDescriptor.UniformDataType.OPENHARMONY_FORM, form);
771record.addEntry(uniformTypeDescriptor.UniformDataType.FILE_URI, fileUri);
772unifiedData.addRecord(record);
773
774let records = unifiedData.getRecords();
775for (let i = 0; i < records.length; i++) {
776  let unifiedDataRecord = records[i] as unifiedDataChannel.UnifiedRecord;
777  let entries : Record<string, unifiedDataChannel.ValueType> = unifiedDataRecord.getEntries();
778  let formRead : uniformDataStruct.Form = entries[uniformTypeDescriptor.UniformDataType.OPENHARMONY_FORM] as uniformDataStruct.Form;
779  if (formRead != undefined) {
780    console.info(`formName: ${formRead.formName}`);
781  }
782  let fileUriRead : uniformDataStruct.FileUri = entries[uniformTypeDescriptor.UniformDataType.FILE_URI] as uniformDataStruct.FileUri;
783  if (fileUriRead != undefined) {
784    console.info(`oriUri: ${fileUriRead.oriUri}`);
785  }
786}
787```
788
789### getTypes<sup>15+</sup>
790
791getTypes(): Array\<string\>
792
793获取数据记录中数据的所有类型集合。可通过UnifiedRecord数据记录对象调用本接口,查询出此记录中数据的所有类型集合,包括使用[addEntry](#addentry15)函数添加的数据类型。
794
795**原子化服务API:** 从API version 15开始,该接口支持在原子化服务中使用。
796
797**系统能力** :SystemCapability.DistributedDataManager.UDMF.Core
798
799**返回值:**
800
801| 类型                                     | 说明                      |
802| ---------------------------------------- |-------------------------|
803| Array\<string\> | [UniformDataType](js-apis-data-uniformTypeDescriptor.md#uniformdatatype)类型的数组,表示当前记录的数据类型集合。 |
804
805**示例:**
806
807```ts
808import { uniformDataStruct, uniformTypeDescriptor } from '@kit.ArkData';
809
810let fileUriDetails : Record<string, string> = {
811  'attr1': 'value1',
812  'attr2': 'value2'
813}
814let fileUri : uniformDataStruct.FileUri = {
815  uniformDataType : 'general.file-uri',
816  oriUri : 'file://data/image/1.png',
817  fileType : 'general.image',
818  details : fileUriDetails
819}
820let formDetails : Record<string, string> = {
821  'attr1': 'value1',
822  'attr2': 'value2'
823}
824let form : uniformDataStruct.Form = {
825  uniformDataType : 'openharmony.form',
826  formId : 1,
827  formName : 'form',
828  bundleName : 'com.xx.app',
829  abilityName : 'ability',
830  module : 'module',
831  details : formDetails
832}
833
834let unifiedData = new unifiedDataChannel.UnifiedData();
835let record = new unifiedDataChannel.UnifiedRecord(uniformTypeDescriptor.UniformDataType.OPENHARMONY_FORM, form);
836record.addEntry(uniformTypeDescriptor.UniformDataType.FILE_URI, fileUri);
837unifiedData.addRecord(record);
838
839let records = unifiedData.getRecords();
840for (let i = 0; i < records.length; i++) {
841  let unifiedDataRecord = records[i] as unifiedDataChannel.UnifiedRecord;
842  let types : Array<string> = unifiedDataRecord.getTypes();
843  if (types.includes(uniformTypeDescriptor.UniformDataType.OPENHARMONY_FORM)) {
844    console.info(`Types include: ${uniformTypeDescriptor.UniformDataType.OPENHARMONY_FORM}`);
845  }
846}
847```
848
849## Text
850
851文本类型数据,是[UnifiedRecord](#unifiedrecord)的子类,也是文本类型数据的基类,用于描述文本类数据,推荐开发者优先使用Text的子类描述数据,如[PlainText](#plaintext)、[Hyperlink](#hyperlink)、[HTML](#html)等具体子类。
852
853**原子化服务API:** 从API version 11开始,该接口支持在原子化服务中使用。
854
855**系统能力**: SystemCapability.DistributedDataManager.UDMF.Core
856
857| 名称 | 类型 | 只读 | 可选 | 说明 |
858| -------- | -------- | -------- | -------- | -------- |
859| details | Record<string, string> | 否 | 是 | 是一个字典类型对象,key和value都是string类型,用于描述文本内容。例如,可生成一个details内容为<br/>{<br/>"title":"标题",<br/>"content":"内容"<br/>}<br/>的数据对象,用于描述一篇文章。非必填字段,默认值为空字典对象。 |
860
861**示例:**
862
863```ts
864let text = new unifiedDataChannel.Text();
865text.details = {
866  title: 'MyTitle',
867  content: 'This is content'
868};
869let unifiedData = new unifiedDataChannel.UnifiedData(text);
870```
871
872## PlainText
873
874纯文本类型数据,是[Text](#text)的子类,用于描述纯文本类数据。
875
876**原子化服务API:** 从API version 11开始,该接口支持在原子化服务中使用。
877
878**系统能力**: SystemCapability.DistributedDataManager.UDMF.Core
879
880| 名称 | 类型 | 只读 | 可选 | 说明 |
881| -------- | -------- | -------- | -------- | -------- |
882| textContent | string | 否 | 否 | 纯文本内容。                |
883| abstract    | string | 否 | 是 | 纯文本摘要,非必填字段,默认值为空字符串。 |
884
885**示例:**
886
887```ts
888let text = new unifiedDataChannel.PlainText();
889text.textContent = 'this is textContent';
890text.abstract = 'This is abstract';
891```
892
893## Hyperlink
894
895超链接类型数据,是[Text](#text)的子类,用于描述超链接类型数据。
896
897**原子化服务API:** 从API version 11开始,该接口支持在原子化服务中使用。
898
899**系统能力**: SystemCapability.DistributedDataManager.UDMF.Core
900
901| 名称 | 类型 | 只读 | 可选 | 说明 |
902| -------- | -------- | -------- | -------- | -------- |
903| url         | string | 否 | 否 | 链接url。       |
904| description | string | 否 | 是 | 链接内容描述,非必填字段,默认值为空字符串。 |
905
906**示例:**
907
908```ts
909let link = new unifiedDataChannel.Hyperlink();
910link.url = 'www.XXX.com';
911link.description = 'This is description';
912```
913
914## HTML
915
916HTML类型数据,是[Text](#text)的子类,用于描述超文本标记语言数据。
917
918**原子化服务API:** 从API version 11开始,该接口支持在原子化服务中使用。
919
920**系统能力**: SystemCapability.DistributedDataManager.UDMF.Core
921
922| 名称 | 类型 | 只读 | 可选 | 说明 |
923| -------- | -------- | -------- | -------- | -------- |
924| htmlContent  | string | 否 | 否 | html格式内容。             |
925| plainContent | string | 否 | 是 | 去除html标签后的纯文本内容,非必填字段,默认值为空字符串。 |
926
927**示例:**
928
929```ts
930let html = new unifiedDataChannel.HTML();
931html.htmlContent = '<div><p>标题</p></div>';
932html.plainContent = 'This is plainContent';
933```
934
935## File
936
937File类型数据,是[UnifiedRecord](#unifiedrecord)的子类,也是文件类型数据的基类,用于描述文件类型数据,推荐开发者优先使用File的子类描述数据,如[Image](#image)、[Video](#video)、[Folder](#folder)等具体子类。
938
939**原子化服务API:** 从API version 11开始,该接口支持在原子化服务中使用。
940
941**系统能力**: SystemCapability.DistributedDataManager.UDMF.Core
942
943| 名称 | 类型 | 只读 | 可选 | 说明 |
944| -------- | -------- | -------- | -------- | -------- |
945| details | Record<string, string> | 否 | 是 | 是一个字典类型对象,key和value都是string类型,用于描述文件相关信息。例如,可生成一个details内容为<br/>{<br/>"name":"文件名",<br/>"type":"文件类型"<br/>}<br/>的数据对象,用于描述一个文件。非必填字段,默认值为空字典对象。 |
946| uri     | string                    | 否 | 否 | 本地文件数据uri或网络文件uri,本地文件数据uri可通过[getUriFromPath](../apis-core-file-kit/js-apis-file-fileuri.md#fileurigeturifrompath)函数获取。                                                                                                                                            |
947
948**示例:**
949
950```ts
951import { unifiedDataChannel } from '@kit.ArkData';
952import { fileUri } from '@kit.CoreFileKit'
953import { UIAbility } from '@kit.AbilityKit';
954import { window } from '@kit.ArkUI';
955
956export default class EntryAbility extends UIAbility {
957  onWindowStageCreate(windowStage: window.WindowStage) {
958    let context = this.context;
959    let pathDir = context.filesDir;
960    let file = new unifiedDataChannel.File();
961    file.details = {
962        name: 'test',
963        type: 'txt'
964    };
965    let filePath = pathDir + '/test.txt';
966    file.uri = fileUri.getUriFromPath(filePath);
967  }
968}
969```
970
971## Image
972
973图片类型数据,是[File](#file)的子类,用于描述图片文件。
974
975**原子化服务API:** 从API version 11开始,该接口支持在原子化服务中使用。
976
977**系统能力**: SystemCapability.DistributedDataManager.UDMF.Core
978
979| 名称 | 类型 | 只读 | 可选 | 说明 |
980| -------- | -------- | -------- | -------- | -------- |
981| imageUri | string | 否 | 否 | 本地图片数据uri或网络图片uri,本地图片数据uri可通过[getUriFromPath](../apis-core-file-kit/js-apis-file-fileuri.md#fileurigeturifrompath)函数获取。 |
982
983**示例:**
984
985```ts
986import { unifiedDataChannel } from '@kit.ArkData';
987import { fileUri } from '@kit.CoreFileKit'
988import { UIAbility } from '@kit.AbilityKit';
989import { window } from '@kit.ArkUI';
990
991export default class EntryAbility extends UIAbility {
992  onWindowStageCreate(windowStage: window.WindowStage) {
993    let context = this.context;
994    let pathDir = context.filesDir;
995    let image = new unifiedDataChannel.Image();
996    let filePath = pathDir + '/test.jpg';
997    image.imageUri = fileUri.getUriFromPath(filePath);
998  }
999}
1000```
1001
1002## Video
1003
1004视频类型数据,是[File](#file)的子类,用于描述视频文件。
1005
1006**原子化服务API:** 从API version 11开始,该接口支持在原子化服务中使用。
1007
1008**系统能力**: SystemCapability.DistributedDataManager.UDMF.Core
1009
1010| 名称 | 类型 | 只读 | 可选 | 说明 |
1011| -------- | -------- | -------- | -------- | -------- |
1012| videoUri | string | 否 | 否 | 本地视频数据uri或网络视频uri,本地视频数据uri可通过[getUriFromPath](../apis-core-file-kit/js-apis-file-fileuri.md#fileurigeturifrompath)函数获取。 |
1013
1014**示例:**
1015
1016```ts
1017import { unifiedDataChannel } from '@kit.ArkData';
1018import { fileUri } from '@kit.CoreFileKit'
1019import { UIAbility } from '@kit.AbilityKit';
1020import { window } from '@kit.ArkUI';
1021
1022export default class EntryAbility extends UIAbility {
1023  onWindowStageCreate(windowStage: window.WindowStage) {
1024    let context = this.context;
1025    let pathDir = context.filesDir;
1026    let video = new unifiedDataChannel.Video();
1027    let filePath = pathDir + '/test.mp4';
1028    video.videoUri =fileUri.getUriFromPath(filePath);
1029  }
1030}
1031```
1032
1033## Audio
1034
1035音频类型数据,是[File](#file)的子类,用于描述音频文件。
1036
1037**原子化服务API:** 从API version 11开始,该接口支持在原子化服务中使用。
1038
1039**系统能力**: SystemCapability.DistributedDataManager.UDMF.Core
1040
1041| 名称 | 类型 | 只读 | 可选 | 说明 |
1042| -------- | -------- | -------- | -------- | -------- |
1043| audioUri | string | 否 | 否 | 本地音频数据uri或网络音频uri,本地音频数据uri可通过[getUriFromPath](../apis-core-file-kit/js-apis-file-fileuri.md#fileurigeturifrompath)函数获取。 |
1044
1045**示例:**
1046
1047```ts
1048import { unifiedDataChannel } from '@kit.ArkData';
1049import { fileUri } from '@kit.CoreFileKit'
1050import { UIAbility } from '@kit.AbilityKit';
1051import { window } from '@kit.ArkUI';
1052
1053export default class EntryAbility extends UIAbility {
1054  onWindowStageCreate(windowStage: window.WindowStage) {
1055    let context = this.context;
1056    let pathDir = context.filesDir;
1057    let audio = new unifiedDataChannel.Audio();
1058    let filePath = pathDir + '/test.mp3';
1059    audio.audioUri = fileUri.getUriFromPath(filePath);
1060  }
1061}
1062```
1063
1064## Folder
1065
1066文件夹类型数据,是[File](#file)的子类,用于描述文件夹。
1067
1068**原子化服务API:** 从API version 11开始,该接口支持在原子化服务中使用。
1069
1070**系统能力**: SystemCapability.DistributedDataManager.UDMF.Core
1071
1072| 名称 | 类型 | 只读 | 可选 | 说明 |
1073| -------- | -------- | -------- | -------- | -------- |
1074| folderUri | string | 否 | 否 | 本地文件夹数据uri或网络文件夹uri,本地文件夹数据uri可通过[getUriFromPath](../apis-core-file-kit/js-apis-file-fileuri.md#fileurigeturifrompath)函数获取。 |
1075
1076**示例:**
1077
1078```ts
1079import { unifiedDataChannel } from '@kit.ArkData';
1080import { fileUri } from '@kit.CoreFileKit'
1081import { UIAbility } from '@kit.AbilityKit';
1082import { window } from '@kit.ArkUI';
1083
1084export default class EntryAbility extends UIAbility {
1085  onWindowStageCreate(windowStage: window.WindowStage) {
1086    let context = this.context;
1087    let pathDir = context.filesDir;
1088    let folder = new unifiedDataChannel.Folder();
1089    let filePath = pathDir + '/folder';
1090    folder.folderUri = fileUri.getUriFromPath(filePath);
1091  }
1092}
1093```
1094
1095## SystemDefinedRecord
1096
1097SystemDefinedRecord是[UnifiedRecord](#unifiedrecord)的子类,也是OpenHarmony系统特有数据类型的基类,用于描述仅在OpenHarmony系统范围内流通的特有数据类型,推荐开发者优先使用SystemDefinedRecord的子类描述数据,如[SystemDefinedForm](#systemdefinedform)、[SystemDefinedAppItem](#systemdefinedappitem)、[SystemDefinedPixelMap](#systemdefinedpixelmap)等具体子类。
1098
1099**原子化服务API:** 从API version 11开始,该接口支持在原子化服务中使用。
1100
1101**系统能力**: SystemCapability.DistributedDataManager.UDMF.Core
1102
1103| 名称 | 类型 | 只读 | 可选 | 说明 |
1104| -------- | -------- | -------- | -------- | -------- |
1105| details | Record<string, number \| string \| Uint8Array> | 否 | 是 | 是一个字典类型对象,key是string类型,value可以写入number(数值类型)、string(字符串类型)、Uint8Array(二进制字节数组)类型数据。非必填字段,默认值为空字典对象。|
1106
1107**示例:**
1108
1109```ts
1110let sdr = new unifiedDataChannel.SystemDefinedRecord();
1111let u8Array = new Uint8Array([1, 2, 3, 4, 5, 6, 7, 8, 9, 10]);
1112sdr.details = {
1113    title: 'recordTitle',
1114    version: 1,
1115    content: u8Array
1116};
1117let unifiedData = new unifiedDataChannel.UnifiedData(sdr);
1118```
1119
1120## SystemDefinedForm
1121
1122系统定义的桌面卡片类型数据,是[SystemDefinedRecord](#systemdefinedrecord)的子类。
1123
1124**原子化服务API:** 从API version 11开始,该接口支持在原子化服务中使用。
1125
1126**系统能力**: SystemCapability.DistributedDataManager.UDMF.Core
1127
1128| 名称 | 类型 | 只读 | 可选 | 说明 |
1129| -------- | -------- | -------- | -------- | -------- |
1130| formId      | number | 否 | 否 | 卡片id。          |
1131| formName    | string | 否 | 否 | 卡片名称。          |
1132| bundleName  | string | 否 | 否 | 卡片所属的bundle名。   |
1133| abilityName | string | 否 | 否 | 卡片对应的ability名。 |
1134| module      | string | 否 | 否 | 卡片所属的module名。   |
1135
1136**示例:**
1137
1138```ts
1139let form = new unifiedDataChannel.SystemDefinedForm();
1140form.formId = 123456;
1141form.formName = 'MyFormName';
1142form.bundleName = 'MyBundleName';
1143form.abilityName = 'MyAbilityName';
1144form.module = 'MyModule';
1145let u8Array = new Uint8Array([1, 2, 3, 4, 5, 6, 7, 8, 9, 10]);
1146form.details = {
1147  formKey1: 123,
1148  formKey2: 'formValue',
1149  formKey3: u8Array
1150};
1151let unifiedData = new unifiedDataChannel.UnifiedData(form);
1152```
1153
1154## SystemDefinedAppItem
1155
1156系统定义的桌面图标类型数据,是[SystemDefinedRecord](#systemdefinedrecord)的子类。
1157
1158**原子化服务API:** 从API version 11开始,该接口支持在原子化服务中使用。
1159
1160**系统能力**: SystemCapability.DistributedDataManager.UDMF.Core
1161
1162| 名称 | 类型 | 只读 | 可选 | 说明 |
1163| -------- | -------- | -------- | -------- | -------- |
1164| appId       | string | 否 | 否 | 图标对应的应用id。      |
1165| appName     | string | 否 | 否 | 图标对应的应用名。       |
1166| appIconId   | string | 否 | 否 | 图标的图片id。        |
1167| appLabelId  | string | 否 | 否 | 图标名称对应的标签id。    |
1168| bundleName  | string | 否 | 否 | 图标对应的应用bundle名。 |
1169| abilityName | string | 否 | 否 | 图标对应的应用ability名。 |
1170
1171**示例:**
1172
1173```ts
1174let appItem = new unifiedDataChannel.SystemDefinedAppItem();
1175appItem.appId = 'MyAppId';
1176appItem.appName = 'MyAppName';
1177appItem.appIconId = 'MyAppIconId';
1178appItem.appLabelId = 'MyAppLabelId';
1179appItem.bundleName = 'MyBundleName';
1180appItem.abilityName = 'MyAbilityName';
1181let u8Array = new Uint8Array([1, 2, 3, 4, 5, 6, 7, 8, 9, 10]);
1182appItem.details = {
1183    appItemKey1: 123,
1184    appItemKey2: 'appItemValue',
1185    appItemKey3: u8Array
1186};
1187let unifiedData = new unifiedDataChannel.UnifiedData(appItem);
1188```
1189
1190## SystemDefinedPixelMap
1191
1192与系统侧定义的[PixelMap](../apis-image-kit/arkts-apis-image-PixelMap.md)数据类型对应的图片数据类型,是[SystemDefinedRecord](#systemdefinedrecord)的子类,仅保存PixelMap的二进制数据。
1193
1194**原子化服务API:** 从API version 11开始,该接口支持在原子化服务中使用。
1195
1196**系统能力**: SystemCapability.DistributedDataManager.UDMF.Core
1197
1198| 名称 | 类型 | 只读 | 可选 | 说明 |
1199| -------- | -------- | -------- | -------- | -------- |
1200| rawData | Uint8Array | 否 | 否 | PixelMap对象的二进制数据。 |
1201
1202**示例:**
1203
1204```ts
1205import { image } from '@kit.ImageKit'; // PixelMap类定义所在模块
1206import { unifiedDataChannel, uniformTypeDescriptor } from '@kit.ArkData';
1207import { BusinessError } from '@kit.BasicServicesKit';
1208
1209const color = new ArrayBuffer(96); // 创建pixelMap对象
1210let opts: image.InitializationOptions = {
1211  editable: true, pixelFormat: 3, size: {
1212    height: 4, width: 6
1213  }
1214}
1215image.createPixelMap(color, opts, (error, pixelMap) => {
1216  if (error) {
1217    console.error('Failed to create pixelMap.');
1218  } else {
1219    console.info('Succeeded in creating pixelMap.');
1220    let arrayBuf = new ArrayBuffer(pixelMap.getPixelBytesNumber());
1221    pixelMap.readPixelsToBuffer(arrayBuf);
1222    let u8Array = new Uint8Array(arrayBuf);
1223    let sdPixel = new unifiedDataChannel.SystemDefinedPixelMap();
1224    sdPixel.rawData = u8Array;
1225    let unifiedData = new unifiedDataChannel.UnifiedData(sdPixel);
1226
1227    // 从unifiedData中读取pixelMap类型的record
1228    let records = unifiedData.getRecords();
1229    for (let i = 0; i < records.length; i++) {
1230      if (records[i].getType() === uniformTypeDescriptor.UniformDataType.OPENHARMONY_PIXEL_MAP) {
1231        let pixelMapRecord = records[i] as unifiedDataChannel.SystemDefinedPixelMap;
1232        let newArrayBuf = pixelMapRecord.rawData.buffer;
1233        pixelMap.writeBufferToPixels(newArrayBuf).then(() => {
1234          console.info('Succeeded in writing data from buffer to a pixelMap');
1235        }).catch((error: BusinessError) => {
1236          console.error(`Failed to write data from a buffer to a PixelMap. code is ${error.code}, message is ${error.message}`);
1237        })
1238      }
1239    }
1240  }
1241})
1242```
1243
1244## ApplicationDefinedRecord
1245
1246ApplicationDefinedRecord是[UnifiedRecord](#unifiedrecord)的子类,也是应用自定义数据类型的基类,用于描述仅在应用生态内部流通的自定义数据类型,应用可基于此类进行自定义数据类型的扩展。
1247
1248**原子化服务API:** 从API version 11开始,该接口支持在原子化服务中使用。
1249
1250**系统能力**: SystemCapability.DistributedDataManager.UDMF.Core
1251
1252| 名称 | 类型 | 只读 | 可选 | 说明 |
1253| -------- | -------- | -------- | -------- | -------- |
1254| applicationDefinedType | string     | 否 | 否 | 应用自定义类型标识符,必须以'ApplicationDefined'开头。 |
1255| rawData                | Uint8Array | 否 | 否 | 应用自定义数据类型的二进制数据。                      |
1256
1257**示例:**
1258
1259```ts
1260let record = new unifiedDataChannel.ApplicationDefinedRecord();
1261let u8Array = new Uint8Array([1, 2, 3, 4, 5, 6, 7, 8, 9, 10]);
1262record.applicationDefinedType = 'ApplicationDefinedType';
1263record.rawData = u8Array;
1264let unifiedData = new unifiedDataChannel.UnifiedData(record);
1265```
1266
1267## Intention
1268
1269UDMF已经支持的数据通路枚举类型。其主要用途是标识各种UDMF数据通路所面向的不同业务场景。
1270
1271**系统能力:** SystemCapability.DistributedDataManager.UDMF.Core
1272
1273| 名称       | 值         | 说明      |
1274|----------|-----------|---------|
1275| DATA_HUB | 'DataHub' | 公共数据通路。<br/>**原子化服务API:** 从API version 11开始,该接口支持在原子化服务中使用。|
1276| DRAG<sup>14+</sup> | 'Drag' | 拖拽类型数据通道。<br/>**模型约束:** 此接口仅可在Stage模型下使用。<br/>**适用场景:** 适用于在拖拽场景下使用UDMF来跨应用数据共享。 |
1277| SYSTEM_SHARE<sup>20+</sup> | 'SystemShare' | 系统分享类型数据通道。<br/>**模型约束:** 此接口仅可在Stage模型下使用。<br/>**适用场景:** 适用于在系统分享场景下使用UDMF来跨应用数据共享。 |
1278| PICKER<sup>20+</sup> | 'Picker' | Picker类型数据通道。<br/>**模型约束:** 此接口仅可在Stage模型下使用。<br/>**适用场景:** 适用于在Picker选择器场景下使用UDMF来跨应用数据共享。 |
1279| MENU<sup>20+</sup> | 'Menu' | 菜单类型数据通道。<br/>**模型约束:** 此接口仅可在Stage模型下使用。<br/>**适用场景:** 适用于在右键菜单场景下使用UDMF来跨应用数据共享。 |
1280
1281## Visibility<sup>20+</sup>
1282
1283表示数据的可见性等级枚举。
1284
1285**系统能力:** SystemCapability.DistributedDataManager.UDMF.Core
1286
1287| 名称          | 值   | 说明                          |
1288| ------------- | ---- |------------------------------|
1289| ALL           | 0    | 可见性等级,所有应用可见。<br/>**模型约束:** 此接口仅可在Stage模型下使用。     |
1290| OWN_PROCESS   | 1    | 可见性等级,仅数据提供者可见。<br/>**模型约束:** 此接口仅可在Stage模型下使用。  |
1291
1292## Options
1293
1294UDMF提供的数据操作接口包含三个可选参数:intention、key和visibility。如果接口不需要这些参数,可以不填,具体要求请参阅该接口的参数说明。
1295
1296**系统能力:** SystemCapability.DistributedDataManager.UDMF.Core
1297
1298| 名称      | 类型                    | 必填 | 说明                                                         |
1299| --------- | ----------------------- | ---- | ------------------------------------------------------------ |
1300| intention | [Intention](#intention) | 否   | 表示数据操作相关的数据通路类型。<br/>**原子化服务API:** 从API version 11开始,该接口支持在原子化服务中使用。                             |
1301| key       | string                  | 否   | UDMF中数据对象的唯一标识符,可通过[insertData](#unifieddatachannelinsertdata)接口的返回值获取。<br>由udmf:/、intention、bundleName和groupId四部分组成,以'/'连接,比如:udmf://DataHub/com.ohos.test/0123456789。<br>其中udmf:/固定,DataHub为对应枚举的取值,com.ohos.test为包名,0123456789为随机生成的groupId。<br/>**原子化服务API:** 从API version 11开始,该接口支持在原子化服务中使用。 |
1302| visibility<sup>20+</sup> | [Visibility](#visibility20) | 否   | 表示数据的可见性等级。只在写入数据的时候填写才生效,若不填写默认是Visibility.ALL。<br/>**原子化服务API:** 从API version 20开始,该接口支持在原子化服务中使用。  |
1303
1304## FileConflictOptions<sup>15+</sup>
1305
1306表示文件拷贝冲突时的可选策略的枚举。
1307
1308**原子化服务API:** 从API version 15开始,该接口支持在原子化服务中使用。
1309
1310**系统能力:** SystemCapability.DistributedDataManager.UDMF.Core
1311
1312| 名称      | 值   | 说明             |
1313| --------- | ---- |----------------|
1314| OVERWRITE | 0    | 目标路径存在同文件名时覆盖。 |
1315| SKIP      | 1    | 目标路径存在同文件名时跳过。 |
1316
1317## ProgressIndicator<sup>15+</sup>
1318
1319表示进度条指示选项的枚举,可选择是否采用系统默认进度显示。
1320
1321**原子化服务API:** 从API version 15开始,该接口支持在原子化服务中使用。
1322
1323**系统能力:** SystemCapability.DistributedDataManager.UDMF.Core
1324
1325| 名称    | 值   | 说明                                 |
1326| ------- | ---- |------------------------------------|
1327| NONE    | 0    | 不采用系统默认进度显示。                       |
1328| DEFAULT | 1    | 采用系统默认进度显示,500ms内获取数据完成将不会拉起默认进度条。 |
1329
1330## ListenerStatus<sup>15+</sup>
1331
1332表示从UDMF获取数据时的状态码的枚举。
1333
1334**原子化服务API:** 从API version 15开始,该接口支持在原子化服务中使用。
1335
1336**系统能力:** SystemCapability.DistributedDataManager.UDMF.Core
1337
1338| 名称    | 值   | 说明                                           |
1339| ------- |-----|----------------------------------------------|
1340| FINISHED | 0   | 表示已完成。                                       |
1341| PROCESSING | 1   | 表示正在处理中。                                     |
1342| CANCELED | 2   | 表明本次处理已被取消。                                  |
1343| INNER_ERROR  | 200 | 表明发生了内部错误。                                   |
1344| INVALID_PARAMETERS | 201 | 表示 [GetDataParams](#getdataparams15) 包含无效参数。 |
1345| DATA_NOT_FOUND | 202 | 表示没有获取到数据。                                   |
1346| SYNC_FAILED | 203 | 表示同步过程中出现错误。                                 |
1347| COPY_FILE_FAILED | 204 | 表示文件拷贝过程中出现错误。                               |
1348
1349## ProgressInfo<sup>15+</sup>
1350
1351定义进度上报的数据。
1352
1353**原子化服务API:** 从API version 15开始,该接口支持在原子化服务中使用。
1354
1355**系统能力:** SystemCapability.DistributedDataManager.UDMF.Core
1356
1357| 名称     | 类型                                  | 只读 | 可选 | 说明                                                             |
1358| -------- |-------------------------------------| ---- | ---- |----------------------------------------------------------------|
1359| progress | number                              | 否   | 否   | 系统上报拖拽任务进度百分比。取值范围为[-1-100]的整数,其中-1时代表本次获取数据失败,100时表示本次获取数据完成。 |
1360| status | [ListenerStatus](#listenerstatus15) | 否   | 否   | 系统上报拖拽任务的状态码。                                                  |
1361
1362## DataProgressListener<sup>15+</sup>
1363
1364type DataProgressListener = (progressInfo: ProgressInfo, data: UnifiedData | null) => void
1365
1366定义获取进度信息和数据的监听回调函数。
1367
1368**原子化服务API:** 从API version 15开始,该接口支持在原子化服务中使用。
1369
1370**系统能力:** SystemCapability.DistributedDataManager.UDMF.Core
1371
1372**参数:**
1373
1374| 参数名      | 类型                            | 必填    | 说明           |
1375|----------|-------------------------------|-------|--------------|
1376| progressInfo| [ProgressInfo](#progressinfo15) | 是     | 定义进度上报的进度信息。 |
1377| data        | [UnifiedData](#unifieddata)  \| null  |  是    | 进度达到100时获取的数据,进度未到100时返回null。 |
1378
1379## GetDataParams<sup>15+</sup>
1380
1381表示从UDMF获取数据时的参数,包含目标路径、文件冲突选项、进度条类型等。
1382
1383具体使用示例可见[拖拽异步获取数据](../apis-arkui/arkui-ts/ts-universal-events-drag-drop.md#示例3拖拽异步获取数据)。
1384
1385**系统能力:** SystemCapability.DistributedDataManager.UDMF.Core
1386
1387**参数:**
1388
1389| 名称                   | 类型                                              | 只读 | 可选 | 说明                                                                                                                                                 |
1390|----------------------|-------------------------------------------------| ---- | ---- |----------------------------------------------------------------------------------------------------------------------------------------------------|
1391| progressIndicator    | [ProgressIndicator](#progressindicator15)       | 否   | 否   | 定义进度条指示选项,可选择是否采用系统默认进度显示。<br>**原子化服务API:** 从API version 15开始,该接口支持在原子化服务中使用。                                                                                                                         |
1392| dataProgressListener | [DataProgressListener](#dataprogresslistener15) | 否   | 否   | 表示获取统一数据时的进度和数据监听器。<br>**原子化服务API:** 从API version 15开始,该接口支持在原子化服务中使用。                                                                                                                                |
1393| destUri              | string                                          | 否   | 是   | 拷贝文件的目标路径。若不支持文件处理,则不需要设置此参数,默认为空;若支持文件处理,须设置一个已经存在的目录。若应用涉及复杂文件处理策略或需要区分文件多路径存储,建议不设置此参数,由应用自行完成文件copy处理。不填写时获取到到的uri为源端路径URI,填写后获取到的uri为目标路径uri。<br>**原子化服务API:** 从API version 15开始,该接口支持在原子化服务中使用。|
1394| fileConflictOptions  | [FileConflictOptions](#fileconflictoptions15)   | 否   | 是   | 定义文件拷贝冲突时的选项,默认为OVERWRITE。<br>**原子化服务API:** 从API version 15开始,该接口支持在原子化服务中使用。                                                                                                                         |
1395| acceptableInfo<sup>20+</sup>  | [DataLoadInfo](#dataloadinfo20)   | 否   | 是   | 定义接收方对数据类型和数据记录数量的接收能力。延迟加载场景下,发送方可根据此信息生成并返回更合适的数据内容。默认为空,不提供接收方数据接收能力。<br>**原子化服务API:** 从API version 20开始,该接口支持在原子化服务中使用。   |
1396
1397## DataLoadInfo<sup>20+</sup>
1398
1399用于描述被加载数据的类型与数量。
1400
1401- 在**数据发送方**中使用,表示实际可提供的数据范围,必须设置该字段。
1402- 在**数据接收方**中使用,表示期望加载的数据类型与数量,可根据需要设置该字段。
1403
1404**原子化服务API:** 从API version 20开始,该接口支持在原子化服务中使用。
1405
1406**系统能力:** SystemCapability.DistributedDataManager.UDMF.Core
1407
1408**参数:**
1409
1410| 名称                   | 类型                                              | 必填 | 说明                                                                                                                                                 |
1411|----------------------|-------------------------------------------------| ---- |----------------------------------------------------------------------------------------------------------------------------------------------------|
1412| types    | Set\<string\>       | 否 | 表示数据类型集合,默认为空集合。                                                                                                                         |
1413| recordCount | number | 否 | 表示期望或可提供的最大数据记录数,默认值为0,取值范围为[0, 2<sup>32</sup>-1]。超过取值范围时会按默认值处理。设置为浮点数时,仅使用整数部分。当用于拖拽时,会作为角标数量显示,最大支持2<sup>31</sup>-1,超过此数值时不显示角标。作为角标数量时,优先级低于[DragPreviewOptions](../apis-arkui/arkui-ts/ts-universal-attributes-drag-drop.md#dragpreviewoptions11)中的numberBadge方法。                            |
1414
1415## DataLoadHandler<sup>20+</sup>
1416
1417type DataLoadHandler = (acceptableInfo?: DataLoadInfo) => UnifiedData | null
1418
1419用于延迟加载数据的处理函数。支持数据发送方根据接收方传入的信息,动态生成数据,实现更灵活、精准的数据交互策略。
1420
1421**原子化服务API:** 从API version 20开始,该接口支持在原子化服务中使用。
1422
1423**系统能力:** SystemCapability.DistributedDataManager.UDMF.Core
1424
1425**参数:**
1426
1427| 参数名      | 类型                            | 必填    | 说明           |
1428|----------|-------------------------------|-------|--------------|
1429| acceptableInfo | [DataLoadInfo](#dataloadinfo20) | 否     | 表示数据接收方可以接收的数据类型和数量,默认为空。 |
1430
1431**返回值:**
1432
1433| 类型                    | 说明                                |
1434|-----------------------|-----------------------------------|
1435| [UnifiedData](#unifieddata) \| null | 当延迟处理函数触发时,返回UnifiedData或null。 |
1436
1437## DataLoadParams<sup>20+</sup>
1438
1439用于在延迟加载场景下描述发送方的数据加载策略。
1440
1441**原子化服务API:** 从API version 20开始,该接口支持在原子化服务中使用。
1442
1443**系统能力:** SystemCapability.DistributedDataManager.UDMF.Core
1444
1445**参数:**
1446
1447| 名称                   | 类型                                              | 必填 | 说明                                                                                                                                                 |
1448|----------------------|-------------------------------------------------| ---- |----------------------------------------------------------------------------------------------------------------------------------------------------|
1449| loadHandler    | [DataLoadHandler](#dataloadhandler20)       | 是 | 表示用于延迟加载数据的处理函数。             |
1450| dataLoadInfo | [DataLoadInfo](#dataloadinfo20) | 是 | 用于描述当前发送方可生成的数据类型及数量信息。              |
1451
1452## unifiedDataChannel.insertData
1453
1454insertData(options: Options, data: UnifiedData, callback: AsyncCallback&lt;string&gt;): void
1455
1456将数据写入UDMF的公共数据通路中,并生成数据的唯一标识符,使用callback异步回调。
1457
1458**原子化服务API:** 从API version 11开始,该接口支持在原子化服务中使用。
1459
1460**系统能力:** SystemCapability.DistributedDataManager.UDMF.Core
1461
1462**参数:**
1463
1464| 参数名      | 类型                         | 必填 | 说明                           |
1465|----------|----------------------------|----|------------------------------|
1466| options  | [Options](#options)        | 是  | 配置项参数,参数中intention字段必填,不填时会返回401错误码;其他字段是否填写均不影响接口的使用。        |
1467| data     | [UnifiedData](#unifieddata) | 是  | 目标数据。                        |
1468| callback | AsyncCallback&lt;string&gt; | 是  | 回调函数,返回写入UDMF的数据的唯一标识符key的值。 |
1469
1470**错误码:**
1471
1472以下错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)。
1473
1474| **错误码ID** | **错误信息**                                |
1475| ------------ | ------------------------------------------- |
1476| 401          | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameters types.  |
1477
1478**示例:**
1479
1480```ts
1481import { uniformDataStruct, uniformTypeDescriptor } from '@kit.ArkData';
1482import { BusinessError } from '@kit.BasicServicesKit';
1483
1484let plainText : uniformDataStruct.PlainText = {
1485  uniformDataType: 'general.plain-text',
1486  textContent : 'This is a plain text example',
1487  abstract : 'This is abstract'
1488}
1489let text = new unifiedDataChannel.UnifiedRecord(uniformTypeDescriptor.UniformDataType.PLAIN_TEXT, plainText);
1490let unifiedData = new unifiedDataChannel.UnifiedData(text);
1491
1492let options: unifiedDataChannel.Options = {
1493  intention: unifiedDataChannel.Intention.DATA_HUB
1494}
1495try {
1496  unifiedDataChannel.insertData(options, unifiedData, (err, key) => {
1497    if (err === undefined) {
1498      console.info(`Succeeded in inserting data. key = ${key}`);
1499    } else {
1500      console.error(`Failed to insert data. code is ${err.code}, message is ${err.message} `);
1501    }
1502  });
1503} catch (e) {
1504  let error: BusinessError = e as BusinessError;
1505  console.error(`Insert data throws an exception. code is ${error.code}, message is ${error.message} `);
1506}
1507```
1508
1509## unifiedDataChannel.insertData
1510
1511insertData(options: Options, data: UnifiedData): Promise&lt;string&gt;
1512
1513将数据写入UDMF的公共数据通路中,并生成数据的唯一标识符,使用Promise异步回调。
1514
1515**原子化服务API:** 从API version 11开始,该接口支持在原子化服务中使用。
1516
1517**系统能力:** SystemCapability.DistributedDataManager.UDMF.Core
1518
1519**参数:**
1520
1521| 参数名     | 类型                          | 必填 | 说明                    |
1522|---------|-----------------------------|----|-----------------------|
1523| options | [Options](#options)         | 是  | 配置项参数,参数中intention字段必填,不填时会返回401错误码;其他字段是否填写均不影响接口的使用。 |
1524| data    | [UnifiedData](#unifieddata) | 是  | 目标数据。                 |
1525
1526**返回值:**
1527
1528| 类型                    | 说明                                |
1529|-----------------------|-----------------------------------|
1530| Promise&lt;string&gt; | Promise对象,返回写入UDMF的数据的唯一标识符key的值。 |
1531
1532**错误码:**
1533
1534以下错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)。
1535
1536| **错误码ID** | **错误信息**                                |
1537| ------------ | ------------------------------------------- |
1538| 401          | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameters types.  |
1539
1540**示例:**
1541
1542```ts
1543import { uniformDataStruct, uniformTypeDescriptor } from '@kit.ArkData';
1544import { BusinessError } from '@kit.BasicServicesKit';
1545
1546let plainText : uniformDataStruct.PlainText = {
1547  uniformDataType: 'general.plain-text',
1548  textContent : 'This is a plain text example',
1549  abstract : 'This is abstract'
1550}
1551let text = new unifiedDataChannel.UnifiedRecord(uniformTypeDescriptor.UniformDataType.PLAIN_TEXT, plainText);
1552let unifiedData = new unifiedDataChannel.UnifiedData(text);
1553
1554let options: unifiedDataChannel.Options = {
1555  intention: unifiedDataChannel.Intention.DATA_HUB
1556}
1557try {
1558  unifiedDataChannel.insertData(options, unifiedData).then((key) => {
1559    console.info(`Succeeded in inserting data. key = ${key}`);
1560  }).catch((err: BusinessError) => {
1561    console.error(`Failed to insert data. code is ${err.code}, message is ${err.message} `);
1562  });
1563} catch (e) {
1564  let error: BusinessError = e as BusinessError;
1565  console.error(`Insert data throws an exception. code is ${error.code}, message is ${error.message} `);
1566}
1567```
1568
1569## unifiedDataChannel.updateData
1570
1571updateData(options: Options, data: UnifiedData, callback: AsyncCallback&lt;void&gt;): void
1572
1573更新已写入UDMF的公共数据通路的数据,使用callback异步回调。
1574
1575**原子化服务API:** 从API version 11开始,该接口支持在原子化服务中使用。
1576
1577**系统能力:** SystemCapability.DistributedDataManager.UDMF.Core
1578
1579**参数:**
1580
1581| 参数名      | 类型                          | 必填 | 说明                                  |
1582|----------|-----------------------------|----|-------------------------------------|
1583| options  | [Options](#options)         | 是  | 配置项参数,参数中key字段必填,不填时会返回401错误码;其他字段是否填写均不影响接口的使用。                     |
1584| data     | [UnifiedData](#unifieddata) | 是  | 目标数据。                               |
1585| callback | AsyncCallback&lt;void&gt;   | 是  | 回调函数。当更新数据成功,err为undefined,否则为错误对象。 |
1586
1587**错误码:**
1588
1589以下错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)。
1590
1591| **错误码ID** | **错误信息**                                |
1592| ------------ | ------------------------------------------- |
1593| 401          | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameters types.  |
1594
1595**示例:**
1596
1597```ts
1598import { uniformDataStruct, uniformTypeDescriptor } from '@kit.ArkData';
1599import { BusinessError } from '@kit.BasicServicesKit';
1600
1601let plainText : uniformDataStruct.PlainText = {
1602  uniformDataType: 'general.plain-text',
1603  textContent : 'This is a plain text example',
1604  abstract : 'This is abstract'
1605}
1606let text = new unifiedDataChannel.UnifiedRecord(uniformTypeDescriptor.UniformDataType.PLAIN_TEXT, plainText);
1607let unifiedData = new unifiedDataChannel.UnifiedData(text);
1608let options: unifiedDataChannel.Options = {
1609  intention: unifiedDataChannel.Intention.DATA_HUB
1610}
1611try {
1612  unifiedDataChannel.insertData(options, unifiedData).then((key) => {
1613    console.info(`Succeeded in inserting data. key = ${key}`);
1614    let updateOptions: unifiedDataChannel.Options = {
1615      intention: unifiedDataChannel.Intention.DATA_HUB,
1616      key: key
1617    }
1618    let plainTextUpdate : uniformDataStruct.PlainText = {
1619      uniformDataType: 'general.plain-text',
1620      textContent : 'This is plainText textContent for update',
1621      abstract : 'This is abstract for update'
1622    }
1623    let textUpdate = new unifiedDataChannel.UnifiedRecord(uniformTypeDescriptor.UniformDataType.PLAIN_TEXT, plainTextUpdate);
1624    let unifiedDataUpdate = new unifiedDataChannel.UnifiedData(textUpdate);
1625    try {
1626      unifiedDataChannel.updateData(updateOptions, unifiedDataUpdate, (err) => {
1627        if (err === undefined) {
1628          console.info('Succeeded in updating data.');
1629        } else {
1630          console.error(`Failed to update data. code is ${err.code}, message is ${err.message} `);
1631        }
1632      });
1633    } catch (e) {
1634      let error: BusinessError = e as BusinessError;
1635      console.error(`Update data throws an exception. code is ${error.code}, message is ${error.message} `);
1636    }
1637  }).catch((err: BusinessError) => {
1638    console.error(`Failed to insert data. code is ${err.code}, message is ${err.message} `);
1639  });
1640} catch (e) {
1641  let error: BusinessError = e as BusinessError;
1642  console.error(`Insert data throws an exception. code is ${error.code}, message is ${error.message} `);
1643}
1644```
1645
1646## unifiedDataChannel.updateData
1647
1648updateData(options: Options, data: UnifiedData): Promise&lt;void&gt;
1649
1650更新已写入UDMF的公共数据通路的数据,使用Promise异步回调。
1651
1652**原子化服务API:** 从API version 11开始,该接口支持在原子化服务中使用。
1653
1654**系统能力:** SystemCapability.DistributedDataManager.UDMF.Core
1655
1656**参数:**
1657
1658| 参数名     | 类型                          | 必填 | 说明              |
1659|---------|-----------------------------|----|-----------------|
1660| options | [Options](#options)         | 是  | 配置项参数,参数中key字段必填,不填时会返回401错误码;其他字段是否填写均不影响接口的使用。 |
1661| data    | [UnifiedData](#unifieddata) | 是  | 目标数据。           |
1662
1663**返回值:**
1664
1665| 类型                  | 说明                         |
1666|---------------------|----------------------------|
1667| Promise&lt;void&gt; | Promise对象。无返回结果的Promise对象。 |
1668
1669**错误码:**
1670
1671以下错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)。
1672
1673| **错误码ID** | **错误信息**                                |
1674| ------------ | ------------------------------------------- |
1675| 401          | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameters types.  |
1676
1677**示例:**
1678
1679```ts
1680import { uniformDataStruct, uniformTypeDescriptor } from '@kit.ArkData';
1681import { BusinessError } from '@kit.BasicServicesKit';
1682
1683let plainText : uniformDataStruct.PlainText = {
1684  uniformDataType: 'general.plain-text',
1685  textContent : 'This is a plain text example',
1686  abstract : 'This is abstract'
1687}
1688let text = new unifiedDataChannel.UnifiedRecord(uniformTypeDescriptor.UniformDataType.PLAIN_TEXT, plainText);
1689let unifiedData = new unifiedDataChannel.UnifiedData(text);
1690let options: unifiedDataChannel.Options = {
1691  intention: unifiedDataChannel.Intention.DATA_HUB
1692}
1693try {
1694  unifiedDataChannel.insertData(options, unifiedData).then((key) => {
1695    console.info(`Succeeded in inserting data. key = ${key}`);
1696    let updateOptions: unifiedDataChannel.Options = {
1697      intention: unifiedDataChannel.Intention.DATA_HUB,
1698      key: key
1699    }
1700    let plainTextUpdate : uniformDataStruct.PlainText = {
1701      uniformDataType: 'general.plain-text',
1702      textContent : 'This is plainText textContent for update',
1703      abstract : 'This is abstract for update'
1704    }
1705    let textUpdate = new unifiedDataChannel.UnifiedRecord(uniformTypeDescriptor.UniformDataType.PLAIN_TEXT, plainTextUpdate);
1706    let unifiedDataUpdate = new unifiedDataChannel.UnifiedData(textUpdate);
1707    try {
1708      unifiedDataChannel.updateData(updateOptions, unifiedDataUpdate).then(() => {
1709        console.info('Succeeded in updating data.');
1710      }).catch((err: BusinessError) => {
1711        console.error(`Failed to update data. code is ${err.code}, message is ${err.message} `);
1712      });
1713    } catch (e) {
1714      let error: BusinessError = e as BusinessError;
1715      console.error(`Update data throws an exception. code is ${error.code}, message is ${error.message} `);
1716    }
1717  }).catch((err: BusinessError) => {
1718    console.error(`Failed to insert data. code is ${err.code}, message is ${err.message} `);
1719  });
1720} catch (e) {
1721  let error: BusinessError = e as BusinessError;
1722  console.error(`Insert data throws an exception. code is ${error.code}, message is ${error.message} `);
1723}
1724```
1725
1726## unifiedDataChannel.queryData
1727
1728queryData(options: Options, callback: AsyncCallback&lt;Array&lt;UnifiedData&gt;&gt;): void
1729
1730查询UDMF公共数据通路的数据,使用callback异步回调。
1731
1732**原子化服务API:** 从API version 11开始,该接口支持在原子化服务中使用。
1733
1734**系统能力:** SystemCapability.DistributedDataManager.UDMF.Core
1735
1736**参数:**
1737
1738| 参数名      | 类型                                                            | 必填 | 说明                                                                                                                                                               |
1739|----------|---------------------------------------------------------------|----|------------------------------------------------------------------------------------------------------------------------------------------------------------------|
1740| options  | [Options](#options)                                           | 是  | 配置项参数,key和intention均为可选,根据传入的参数做相应的校验以返回不同的值。                                                                                                                    |
1741| callback | AsyncCallback&lt;Array&lt;[UnifiedData](#unifieddata)&gt;&gt; | 是  | 回调函数,返回查询到的所有数据。<br>如果options中填入的是key,则返回key对应的数据;<br>如果options中填入的是intention,则返回intention下所有数据。<br>如intention和key均填写了,取两者查询数据的交集,与options只填入key的获取结果一致;如没有交集报错。 |
1742
1743**错误码:**
1744
1745以下错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)。
1746
1747| **错误码ID** | **错误信息**                                |
1748| ------------ | ------------------------------------------- |
1749| 401          | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameters types.  |
1750
1751**示例:**
1752
1753```ts
1754import { uniformDataStruct, uniformTypeDescriptor } from '@kit.ArkData';
1755import { BusinessError } from '@kit.BasicServicesKit';
1756
1757let options: unifiedDataChannel.Options = {
1758  intention: unifiedDataChannel.Intention.DATA_HUB
1759};
1760
1761try {
1762  unifiedDataChannel.queryData(options, (err, data) => {
1763    if (err === undefined) {
1764      console.info(`Succeeded in querying data. size = ${data.length}`);
1765      for (let i = 0; i < data.length; i++) {
1766        let records = data[i].getRecords();
1767        for (let j = 0; j < records.length; j++) {
1768          if (records[j].getTypes().includes(uniformTypeDescriptor.UniformDataType.PLAIN_TEXT)) {
1769            let text = records[j].getEntry(uniformTypeDescriptor.UniformDataType.PLAIN_TEXT) as uniformDataStruct.PlainText;
1770            console.info(`${i + 1}.${text.textContent}`);
1771          }
1772        }
1773      }
1774    } else {
1775      console.error(`Failed to query data. code is ${err.code}, message is ${err.message} `);
1776    }
1777  });
1778} catch (e) {
1779  let error: BusinessError = e as BusinessError;
1780  console.error(`Query data throws an exception. code is ${error.code}, message is ${error.message} `);
1781}
1782```
1783
1784## unifiedDataChannel.queryData
1785
1786queryData(options: Options): Promise&lt;Array&lt;UnifiedData&gt;&gt;
1787
1788查询UDMF公共数据通路的数据,使用Promise异步回调。
1789
1790**原子化服务API:** 从API version 11开始,该接口支持在原子化服务中使用。
1791
1792**系统能力:** SystemCapability.DistributedDataManager.UDMF.Core
1793
1794**参数:**
1795
1796| 参数名     | 类型                  | 必填 | 说明                                            |
1797|---------|---------------------|----|-----------------------------------------------|
1798| options | [Options](#options) | 是  | 配置项参数,key和intention均为可选,根据传入的参数做相应的校验以返回不同的值。 |
1799
1800**返回值:**
1801
1802| 类型                                                      | 说明                                                                                                                                  |
1803|---------------------------------------------------------|-------------------------------------------------------------------------------------------------------------------------------------|
1804| Promise&lt;Array&lt;[UnifiedData](#unifieddata)&gt;&gt; | Promise对象,返回查询到的所有数据。<br>如果options中填入的是key,则返回key对应的数据。<br>如果options中填入的是intention,则返回intention下所有数据。<br>如intention和key均填写了,取两者查询数据的交集,与options只填入key的获取结果一致;如没有交集报错。 |
1805
1806**错误码:**
1807
1808以下错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)。
1809
1810| **错误码ID** | **错误信息**                                |
1811| ------------ | ------------------------------------------- |
1812| 401          | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameters types.  |
1813
1814**示例:**
1815
1816```ts
1817import { uniformDataStruct, uniformTypeDescriptor } from '@kit.ArkData';
1818import { BusinessError } from '@kit.BasicServicesKit';
1819
1820let options: unifiedDataChannel.Options = {
1821  key: 'udmf://DataHub/com.ohos.test/0123456789'
1822};
1823
1824try {
1825  unifiedDataChannel.queryData(options).then((data) => {
1826    console.info(`Succeeded in querying data. size = ${data.length}`);
1827    for (let i = 0; i < data.length; i++) {
1828      let records = data[i].getRecords();
1829      for (let j = 0; j < records.length; j++) {
1830        if (records[j].getTypes().includes(uniformTypeDescriptor.UniformDataType.PLAIN_TEXT)) {
1831          let text = records[j].getEntry(uniformTypeDescriptor.UniformDataType.PLAIN_TEXT) as uniformDataStruct.PlainText;
1832          console.info(`${i + 1}.${text.textContent}`);
1833        }
1834      }
1835    }
1836  }).catch((err: BusinessError) => {
1837    console.error(`Failed to query data. code is ${err.code}, message is ${err.message} `);
1838  });
1839} catch (e) {
1840  let error: BusinessError = e as BusinessError;
1841  console.error(`Query data throws an exception. code is ${error.code}, message is ${error.message} `);
1842}
1843```
1844
1845## unifiedDataChannel.deleteData
1846
1847deleteData(options: Options, callback: AsyncCallback&lt;Array&lt;UnifiedData&gt;&gt;): void
1848
1849删除UDMF公共数据通路的数据,返回删除的数据集,使用callback异步回调。
1850
1851**原子化服务API:** 从API version 11开始,该接口支持在原子化服务中使用。
1852
1853**系统能力:** SystemCapability.DistributedDataManager.UDMF.Core
1854
1855**参数:**
1856
1857| 参数名      | 类型                                                            | 必填 | 说明                                                                                                                                                                                     |
1858|----------|---------------------------------------------------------------|----|----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
1859| options  | [Options](#options)                                           | 是  | 配置项参数,key和intention均为可选,根据传入的参数做相应的校验以返回不同的值。                                                                                                                                          |
1860| callback | AsyncCallback&lt;Array&lt;[UnifiedData](#unifieddata)&gt;&gt; | 是  | 回调函数,返回删除的所有数据。<br>如果options中填入的是key,则删除key对应的数据并返回该数据。<br>如果options中填入的是intention,则删除intention下所有数据并返回删除的数据。<br>如intention和key均填写了,取两者数据的交集进行删除,并返回删除的数据,与options只填入key的结果一致;如没有交集报错。 |
1861
1862**错误码:**
1863
1864以下错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)。
1865
1866| **错误码ID** | **错误信息**                                |
1867| ------------ | ------------------------------------------- |
1868| 401          | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameters types.  |
1869
1870**示例:**
1871
1872```ts
1873import { uniformDataStruct, uniformTypeDescriptor } from '@kit.ArkData';
1874import { BusinessError } from '@kit.BasicServicesKit';
1875
1876let options: unifiedDataChannel.Options = {
1877  intention: unifiedDataChannel.Intention.DATA_HUB
1878};
1879
1880try {
1881  unifiedDataChannel.deleteData(options, (err, data) => {
1882    if (err === undefined) {
1883      console.info(`Succeeded in deleting data. size = ${data.length}`);
1884      for (let i = 0; i < data.length; i++) {
1885        let records = data[i].getRecords();
1886        for (let j = 0; j < records.length; j++) {
1887          if (records[j].getTypes().includes(uniformTypeDescriptor.UniformDataType.PLAIN_TEXT)) {
1888            let text = records[j].getEntry(uniformTypeDescriptor.UniformDataType.PLAIN_TEXT) as uniformDataStruct.PlainText;
1889            console.info(`${i + 1}.${text.textContent}`);
1890          }
1891        }
1892      }
1893    } else {
1894      console.error(`Failed to delete data. code is ${err.code}, message is ${err.message} `);
1895    }
1896  });
1897} catch (e) {
1898  let error: BusinessError = e as BusinessError;
1899  console.error(`Delete data throws an exception. code is ${error.code}, message is ${error.message} `);
1900}
1901```
1902
1903## unifiedDataChannel.deleteData
1904
1905deleteData(options: Options): Promise&lt;Array&lt;UnifiedData&gt;&gt;
1906
1907删除UDMF公共数据通路的数据,返回删除的数据集,使用Promise异步回调。
1908
1909**原子化服务API:** 从API version 11开始,该接口支持在原子化服务中使用。
1910
1911**系统能力:** SystemCapability.DistributedDataManager.UDMF.Core
1912
1913**参数:**
1914
1915| 参数名     | 类型                  | 必填 | 说明     |
1916|---------|---------------------|----|--------|
1917| options | [Options](#options) | 是  | 配置项参数,key和intention均为可选,根据传入的参数做相应的校验以返回不同的值。 |
1918
1919**返回值:**
1920
1921| 类型                                                      | 说明                                                                                                                                                          |
1922|---------------------------------------------------------|-------------------------------------------------------------------------------------------------------------------------------------------------------------|
1923| Promise&lt;Array&lt;[UnifiedData](#unifieddata)&gt;&gt; | Promise对象,返回删除的所有数据。<br>如果options中填入的是key,则删除key对应的数据并返回该数据。<br>如果options中填入的是intention,则删除intention下所有数据并返回删除的数据。<br>如intention和key均填写了,取两者数据的交集进行删除,并返回删除的数据,与options只填入key的结果一致;如没有交集报错。 |
1924
1925**错误码:**
1926
1927以下错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)。
1928
1929| **错误码ID** | **错误信息**                                |
1930| ------------ | ------------------------------------------- |
1931| 401          | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameters types.  |
1932
1933**示例:**
1934
1935```ts
1936import { uniformDataStruct, uniformTypeDescriptor } from '@kit.ArkData';
1937import { BusinessError } from '@kit.BasicServicesKit';
1938
1939let options: unifiedDataChannel.Options = {
1940  key: 'udmf://DataHub/com.ohos.test/0123456789'
1941};
1942
1943try {
1944  unifiedDataChannel.deleteData(options).then((data) => {
1945    console.info(`Succeeded in deleting data. size = ${data.length}`);
1946    for (let i = 0; i < data.length; i++) {
1947      let records = data[i].getRecords();
1948      for (let j = 0; j < records.length; j++) {
1949        if (records[j].getTypes().includes(uniformTypeDescriptor.UniformDataType.PLAIN_TEXT)) {
1950          let text = records[j].getEntry(uniformTypeDescriptor.UniformDataType.PLAIN_TEXT) as uniformDataStruct.PlainText;
1951          console.info(`${i + 1}.${text.textContent}`);
1952        }
1953      }
1954    }
1955  }).catch((err: BusinessError) => {
1956    console.error(`Failed to delete data. code is ${err.code}, message is ${err.message} `);
1957  });
1958} catch (e) {
1959  let error: BusinessError = e as BusinessError;
1960  console.error(`Query data throws an exception. code is ${error.code}, message is ${error.message} `);
1961}
1962```
1963
1964## unifiedDataChannel.setAppShareOptions<sup>14+</sup>
1965
1966setAppShareOptions(intention: Intention, shareOptions: ShareOptions): void
1967
1968设置应用内拖拽通道数据可使用的范围[ShareOptions](#shareoptions12),目前仅支持DRAG类型数据通道的管控设置。
1969
1970**需要权限:** ohos.permission.MANAGE_UDMF_APP_SHARE_OPTION
1971
1972**模型约束:** 此接口仅可在Stage模型下使用。
1973
1974**系统能力:** SystemCapability.DistributedDataManager.UDMF.Core
1975
1976**参数:**
1977
1978| 参数名      | 类型                         | 必填 | 说明                           |
1979|----------|----------------------------|----|------------------------------|
1980| intention | [Intention](#intention) | 是  | 表示数据操作相关的数据通路类型,目前仅支持DRAG类型数据通道。 |
1981| shareOptions | [ShareOptions](#shareoptions12) | 是  | 指示[UnifiedData](#unifieddata)支持的设备内使用范围。 |
1982
1983**错误码:**
1984
1985以下错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)和[统一数据管理框架错误码](errorcode-udmf.md)。
1986
1987| **错误码ID** | **错误信息**                                                 |
1988| ------------ | ------------------------------------------------------------ |
1989| 201          | Permission verification failed. The application does not have the permission required to call the API. |
1990| 401          | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types; 3. Parameter verification failed. |
1991| 20400001     | Settings already exist. To reconfigure, remove the existing sharing options.       |
1992
1993**示例:**
1994
1995```ts
1996import { BusinessError } from '@kit.BasicServicesKit';
1997try {
1998  unifiedDataChannel.setAppShareOptions(unifiedDataChannel.Intention.DRAG, unifiedDataChannel.ShareOptions.IN_APP);
1999  console.info(`[UDMF]setAppShareOptions success. `);
2000}catch (e){
2001  let error: BusinessError = e as BusinessError;
2002  console.error(`[UDMF]setAppShareOptions throws an exception. code is ${error.code}, message is ${error.message} `);
2003}
2004```
2005
2006## unifiedDataChannel.removeAppShareOptions<sup>14+</sup>
2007
2008removeAppShareOptions(intention: Intention): void
2009
2010清除[setAppShareOptions](#unifieddatachannelsetappshareoptions14)设置的管控信息。
2011
2012**需要权限:** ohos.permission.MANAGE_UDMF_APP_SHARE_OPTION
2013
2014**模型约束:** 此接口仅可在Stage模型下使用。
2015
2016**系统能力:** SystemCapability.DistributedDataManager.UDMF.Core
2017
2018**参数:**
2019
2020| 参数名    | 类型                    | 必填 | 说明                                                         |
2021| --------- | ----------------------- | ---- | ------------------------------------------------------------ |
2022| intention | [Intention](#intention) | 是   | 表示数据操作相关的数据通路类型,目前仅支持DRAG类型数据通道。 |
2023
2024**错误码:**
2025
2026以下错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)。
2027
2028| **错误码ID** | **错误信息**                                                 |
2029| ------------ | ------------------------------------------------------------ |
2030| 201          | Permission verification failed. The application does not have the permission required to call the API. |
2031| 401          | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types; 3. Parameter verification failed. |
2032
2033**示例:**
2034
2035```ts
2036import { BusinessError } from '@kit.BasicServicesKit';
2037try {
2038  unifiedDataChannel.removeAppShareOptions(unifiedDataChannel.Intention.DRAG);
2039  console.info(`[UDMF]removeAppShareOptions success. `);
2040}catch (e){
2041  let error: BusinessError = e as BusinessError;
2042  console.error(`[UDMF]removeAppShareOptions throws an exception. code is ${error.code}, message is ${error.message} `);
2043}
2044```
2045
2046## unifiedDataChannel.convertRecordsToEntries<sup>17+</sup>
2047
2048convertRecordsToEntries(data: UnifiedData): void
2049
2050本接口用于将传入的data转换成多样式数据结构。若原data使用多个record去承载同一份数据的不同样式,则可以使用此接口将原data转换为多样式数据结构。
2051
2052当满足以下规则时进行转换,传入的data经转换后变为多样式数据结构:
20531. data中的record数量大于1;
20542. data中的properties中的tag值为"records_to_entries_data_format"。
2055
2056否则不会产生任何行为。
2057
2058**原子化服务API:** 从API version 17开始,该接口支持在原子化服务中使用。
2059
2060**模型约束:** 此接口仅可在Stage模型下使用。
2061
2062**系统能力:** SystemCapability.DistributedDataManager.UDMF.Core
2063
2064**参数:**
2065
2066| 参数名    | 类型                    | 必填 | 说明                                                         |
2067| --------- | ----------------------- | ---- | ------------------------------------------------------------ |
2068| data    | [UnifiedData](#unifieddata) | 是  | 目标数据。           |
2069
2070**错误码:**
2071
2072以下错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)。
2073
2074| **错误码ID** | **错误信息**                                                 |
2075| ------------ | ------------------------------------------------------------ |
2076| 401          | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types. |
2077
2078**示例:**
2079
2080```ts
2081import { unifiedDataChannel } from '@kit.ArkData';
2082import { uniformDataStruct, uniformTypeDescriptor } from '@kit.ArkData';
2083import { BusinessError } from '@kit.BasicServicesKit';
2084
2085let details : Record<string, string> = {
2086  'attr1': 'value1',
2087  'attr2': 'value2'
2088}
2089let plainTextObj : uniformDataStruct.PlainText = {
2090  uniformDataType: 'general.plain-text',
2091  textContent : 'The weather is very good today',
2092  abstract : 'The weather is very good today',
2093  details : details
2094}
2095let htmlObj : uniformDataStruct.HTML = {
2096  uniformDataType :'general.html',
2097  htmlContent : '<div><p>The weather is very good today</p></div>',
2098  plainContent : 'The weather is very good today',
2099  details : details
2100}
2101let plainText = new unifiedDataChannel.UnifiedRecord(uniformTypeDescriptor.UniformDataType.PLAIN_TEXT, plainTextObj);
2102let html = new unifiedDataChannel.UnifiedRecord(uniformTypeDescriptor.UniformDataType.HTML, htmlObj);
2103let unifiedData = new unifiedDataChannel.UnifiedData(plainText);
2104unifiedData.addRecord(html);
2105unifiedData.properties.tag = 'records_to_entries_data_format';
2106
2107try {
2108  unifiedDataChannel.convertRecordsToEntries(unifiedData);
2109  let records: Array<unifiedDataChannel.UnifiedRecord> = unifiedData.getRecords();
2110  console.info(`Records size is ${records.length}`); // After conversion, its length must be less than 1
2111  if (records.length == 1) {
2112    let plainTextObjRead: uniformDataStruct.PlainText = records[0].getEntry(uniformTypeDescriptor.UniformDataType.PLAIN_TEXT) as uniformDataStruct.PlainText;
2113    console.info(`TextContent is ${plainTextObjRead.textContent}`);
2114    let htmlObjRead: uniformDataStruct.HTML = records[0].getEntry(uniformTypeDescriptor.UniformDataType.HTML) as uniformDataStruct.HTML;
2115    console.info(`HtmlContent is ${htmlObjRead.htmlContent}`);
2116  }
2117} catch (e) {
2118  let error: BusinessError = e as BusinessError;
2119  console.error(`Convert data throws an exception. code is ${error.code}, message is ${error.message} `);
2120}
2121```