1# @ohos.data.unifiedDataChannel (Unified Data Channel)
2
3As a part of the Unified Data Management Framework (UDMF), the **unifiedDataChannel** module provides unified data channels and standard data access interfaces for many-to-many data sharing across applications. It also provides definitions for uniform data types, such as text and image, to streamline data interaction between different applications and minimize the workload of data type adaptation.
4
5> **NOTE**
6>
7> The initial APIs of this module are supported since API version 10. Newly added APIs will be marked with a superscript to indicate their earliest API version.
8
9## Modules to Import
10
11```ts
12import { unifiedDataChannel } from '@kit.ArkData';
13```
14
15## ShareOptions<sup>12+</sup>
16
17Enumerates the options for using **UnifiedData** in a device.
18
19**Atomic service API**: This API can be used in atomic services since API version 12.
20
21**System capability**: SystemCapability.DistributedDataManager.UDMF.Core
22
23| Name         | Value| Description               |
24|-------------|---|-------------------|
25| IN_APP       | 0 | **UnifiedData** can be used only in the same application of a device.|
26| CROSS_APP | 1 | **UnifiedData** can be used across applications of a device.|
27
28## GetDelayData<sup>12+</sup>
29
30type GetDelayData = (type: string) => UnifiedData
31
32A type that defines a function used to obtain a deferred **UnifiedData** object. Currently, it can be used only in the pasteboard application of the same device.
33
34**Atomic service API**: This API can be used in atomic services since API version 12.
35
36**System capability**: SystemCapability.DistributedDataManager.UDMF.Core
37
38**Parameters**
39
40| Name| Type| Mandatory| Description|
41| -------- | -------- | -------- | -------- |
42| type | string | Yes| Identifier of the deferred encapsulation.|
43
44**Return value**
45
46| Type                                    | Description                     |
47| ---------------------------------------- |-------------------------|
48| [UnifiedData](#unifieddata) | **UnifiedData** object.|
49
50**Example**
51
52```ts
53import { uniformTypeDescriptor } from '@kit.ArkData';
54
55let getDelayData: unifiedDataChannel.GetDelayData = ((type: string) => {
56  if (type == uniformTypeDescriptor.UniformDataType.PLAIN_TEXT) {
57    let text = new unifiedDataChannel.Text();
58    text.details = {
59      Key: 'textKey',
60      Value: 'textValue',
61    };
62    let textData = new unifiedDataChannel.UnifiedData(text);
63    return textData;
64  }
65  return new unifiedDataChannel.UnifiedData();
66});
67```
68
69## ValueType<sup>12+</sup>
70
71type ValueType = number | string | boolean | image.PixelMap | Want | ArrayBuffer | object | null | undefined
72
73Enumerates the data field types allowed in a unified data record.
74
75**Atomic service API**: This API can be used in atomic services since API version 12.
76
77**System capability**: SystemCapability.DistributedDataManager.UDMF.Core
78
79| Type| Description|
80| -------- | -------- |
81| number | Number.|
82| string | String.|
83| boolean | Boolean.|
84| image.PixelMap | [image.PixelMap](../apis-image-kit/js-apis-image.md#pixelmap7).|
85| Want | [Want](../apis-ability-kit/js-apis-app-ability-want.md).|
86| ArrayBuffer | ArrayBuffer.|
87| object | Object.|
88| null | Null.|
89| undefined | Undefined.|
90
91## UnifiedDataProperties<sup>12+</sup>
92
93Defines the properties of the data records in the unified data object, including the timestamp, tag, pasting range, and additional data.
94
95**Atomic service API**: This API can be used in atomic services since API version 12.
96
97**System capability**: SystemCapability.DistributedDataManager.UDMF.Core
98
99| Name| Type| Read-Only| Optional| Description|
100| -------- | -------- | -------- | -------- | -------- |
101| extras<sup>12+</sup> | Record<string, object> | No| Yes| Object of the dictionary type used to set other properties. The default value is an empty dictionary object.|
102| tag<sup>12+</sup> | string | No| Yes| Customized tag. The default value is an empty string.|
103| timestamp<sup>12+</sup> | Date | Yes| Yes| Timestamp when [UnifiedData](#unifieddata) is generated. The default value is January 1, 1970 (UTC).|
104| shareOptions<sup>12+</sup> | [ShareOptions](#shareoptions12) | No| Yes| Range, in which [UnifiedData](#unifieddata) can be used. The default value is **CROSS_APP**.|
105| getDelayData<sup>12+</sup> | [GetDelayData](#getdelaydata12) | No| Yes| Callback for obtaining the deferred data. Currently, it can be used only in the pasteboard application of the same device. The default value is **undefined**.|
106
107**Example**
108
109```ts
110import { uniformTypeDescriptor } from '@kit.ArkData';
111
112let properties = new unifiedDataChannel.UnifiedDataProperties();
113properties.extras = {
114  key: {
115    title: 'MyTitle',
116    content: 'MyContent'
117  }
118};
119properties.tag = "this is tag of properties";
120properties.shareOptions = unifiedDataChannel.ShareOptions.CROSS_APP;
121properties.getDelayData = ((type: string) => {
122  if (type == uniformTypeDescriptor.UniformDataType.PLAIN_TEXT) {
123    let text = new unifiedDataChannel.Text();
124    text.details = {
125      Key: 'textKey',
126      Value: 'textValue',
127    };
128    let textData = new unifiedDataChannel.UnifiedData(text);
129    return textData;
130  }
131  return new unifiedDataChannel.UnifiedData();
132});
133```
134
135## UnifiedData
136
137Provides APIs for encapsulating a set of data records.
138
139**System capability**: SystemCapability.DistributedDataManager.UDMF.Core
140
141### Properties
142
143| Name| Type| Read-Only| Optional| Description                                                                                             |
144| -------- | -------- | -------- | -------- |-------------------------------------------------------------------------------------------------|
145| properties<sup>12+</sup> | [UnifiedDataProperties](#unifieddataproperties12) | No| No| Properties of all the data records in a unified data object, including the timestamp, tag, application range, and additional data.<br>**Atomic service API**: This API can be used in atomic services since API version 12.|
146
147### constructor<sup>12+</sup>
148
149constructor()
150
151A constructor used to create a **UnifiedData** object.
152
153**Atomic service API**: This API can be used in atomic services since API version 12.
154
155**System capability**: SystemCapability.DistributedDataManager.UDMF.Core
156
157**Example**
158
159```ts
160let unifiedData = new unifiedDataChannel.UnifiedData();
161```
162
163### constructor
164
165constructor(record: UnifiedRecord)
166
167A constructor used to create a **UnifiedData** object with a data record.
168
169**Atomic service API**: This API can be used in atomic services since API version 11.
170
171**System capability**: SystemCapability.DistributedDataManager.UDMF.Core
172
173**Parameters**
174
175| Name| Type                           | Mandatory| Description                                     |
176| ------ | ------------------------------- | ---- |-----------------------------------------|
177| record | [UnifiedRecord](#unifiedrecord) | Yes  | Data record in the **UnifiedData** object. It is a **UnifiedRecord** object or its child class object.|
178
179**Error codes**
180
181For details about the error codes, see [Universal Error Codes](../errorcode-universal.md).
182
183| **ID**| **Error Message**                               |
184| ------------ | ------------------------------------------- |
185| 401          | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameters types.  |
186
187**Example**
188
189```ts
190let text = new unifiedDataChannel.PlainText();
191text.textContent = 'this is textContent of text';
192let unifiedData = new unifiedDataChannel.UnifiedData(text);
193```
194
195### addRecord
196
197addRecord(record: UnifiedRecord): void
198
199Adds a data record to this **UnifiedRecord** object.
200
201**Atomic service API**: This API can be used in atomic services since API version 11.
202
203**System capability**: SystemCapability.DistributedDataManager.UDMF.Core
204
205**Parameters**
206
207| Name| Type                           | Mandatory| Description                                         |
208| ------ | ------------------------------- | ---- |---------------------------------------------|
209| record | [UnifiedRecord](#unifiedrecord) | Yes  | Data record to add. It is a **UnifiedRecord** child class object.|
210
211**Error codes**
212
213For details about the error codes, see [Universal Error Codes](../errorcode-universal.md).
214
215| **ID**| **Error Message**                               |
216| ------------ | ------------------------------------------- |
217| 401          | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameters types.  |
218
219**Example**
220
221```ts
222let text1 = new unifiedDataChannel.PlainText();
223text1.textContent = 'this is textContent of text1';
224let unifiedData = new unifiedDataChannel.UnifiedData(text1);
225
226let text2 = new unifiedDataChannel.PlainText();
227text2.textContent = 'this is textContent of text2';
228unifiedData.addRecord(text2);
229```
230
231### getRecords
232
233getRecords(): Array\<UnifiedRecord\>
234
235Obtains all data records from this **UnifiedData** object. The data obtained is of the **UnifiedRecord** type. Before using the data, you need to use [getType](#gettype) to obtain the data type and convert the data type to a child class.
236
237**Atomic service API**: This API can be used in atomic services since API version 11.
238
239**System capability**: SystemCapability.DistributedDataManager.UDMF.Core
240
241**Return value**
242
243| Type                                    | Description                     |
244| ---------------------------------------- |-------------------------|
245| Array\<[UnifiedRecord](#unifiedrecord)\> | Records in the **UnifiedData** object obtained.|
246
247**Example**
248
249```ts
250import { uniformTypeDescriptor } from '@kit.ArkData';
251
252let text = new unifiedDataChannel.PlainText();
253text.textContent = 'this is textContent of text';
254let unifiedData = new unifiedDataChannel.UnifiedData(text);
255
256let link = new unifiedDataChannel.Hyperlink();
257link.url = 'www.XXX.com';
258unifiedData.addRecord(link);
259
260let records = unifiedData.getRecords();
261for (let i = 0; i < records.length; i++) {
262  let record = records[i];
263  if (record.getType() == uniformTypeDescriptor.UniformDataType.PLAIN_TEXT) {
264    let plainText = record as unifiedDataChannel.PlainText;
265    console.info(`textContent: ${plainText.textContent}`);
266  } else if (record.getType() == uniformTypeDescriptor.UniformDataType.HYPERLINK) {
267    let hyperlink = record as unifiedDataChannel.Hyperlink;
268    console.info(`linkUrl: ${hyperlink.url}`);
269  }
270}
271```
272
273### hasType<sup>12+</sup>
274
275hasType(type: string): boolean
276
277Checks whether this **UnifiedData** object has the specified data type.
278
279**Atomic service API**: This API can be used in atomic services since API version 12.
280
281**System capability**: SystemCapability.DistributedDataManager.UDMF.Core
282
283| Name| Type                           | Mandatory| Description                                         |
284| ------ | ------------------------------- | ---- |---------------------------------------------|
285| type | string | Yes  | Data type to check. For details, see [UniformDataType](js-apis-data-uniformTypeDescriptor.md#uniformdatatype).|
286
287**Return value**
288
289| Type                                    | Description                     |
290| ---------------------------------------- |-------------------------|
291| boolean | Returns **true** if the specified data type exists; returns **false** otherwise.|
292
293**Error codes**
294
295For details about the error codes, see [Universal Error Codes](../errorcode-universal.md).
296
297| **ID**| **Error Message**                               |
298| ------------ | ------------------------------------------- |
299| 401          | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameters types.  |
300
301**Example**
302
303```ts
304import { uniformTypeDescriptor } from '@kit.ArkData';
305
306let text = new unifiedDataChannel.PlainText();
307text.textContent = 'this is textContent of text';
308let unifiedData = new unifiedDataChannel.UnifiedData(text);
309
310let link = new unifiedDataChannel.Hyperlink();
311link.url = 'www.XXX.com';
312unifiedData.addRecord(link);
313
314let hasPlainText = unifiedData.hasType(uniformTypeDescriptor.UniformDataType.PLAIN_TEXT);
315let hasLink = unifiedData.hasType(uniformTypeDescriptor.UniformDataType.HYPERLINK);
316```
317
318### getTypes<sup>12+</sup>
319
320getTypes(): Array\<string\>
321
322Obtains the types of all data records in this **UnifiedData** object.
323
324**Atomic service API**: This API can be used in atomic services since API version 12.
325
326**System capability**: SystemCapability.DistributedDataManager.UDMF.Core
327
328**Return value**
329
330| Type                                    | Description                     |
331| ---------------------------------------- |-------------------------|
332| Array\<string\> | Array of the [UniformDataType](js-apis-data-uniformTypeDescriptor.md#uniformdatatype) types obtained.|
333
334**Example**
335
336```ts
337let text = new unifiedDataChannel.PlainText();
338text.textContent = 'this is textContent of text';
339let unifiedData = new unifiedDataChannel.UnifiedData(text);
340
341let link = new unifiedDataChannel.Hyperlink();
342link.url = 'www.XXX.com';
343unifiedData.addRecord(link);
344
345let types = unifiedData.getTypes();
346```
347
348## Summary
349
350Represents the abstract of a uniform data object, including the data type and size.
351
352**Atomic service API**: This API can be used in atomic services since API version 11.
353
354**System capability**: SystemCapability.DistributedDataManager.UDMF.Core
355
356| Name| Type| Read-Only| Optional| Description|
357| -------- | -------- | -------- | -------- | -------- |
358| summary   | Record<string, number> | No| No| Dictionary type object, where the key indicates the data type (see [UniformDataType](js-apis-data-uniformTypeDescriptor.md#uniformdatatype)), and the value indicates the total size (in bytes) of this type of records in the unified data object.|
359| totalSize | number | No| No| Total size of all the records in the **UnifiedData** object, in bytes.|
360
361## UnifiedRecord
362
363An abstract definition of the data content supported by the UDMF. A **UnifiedRecord** object contains one or more data records, for example, a text record, an image record, or an HTML record.
364
365### constructor<sup>12+</sup>
366
367constructor()
368
369A constructor used to create a **UnfiedRecord** object.
370
371**Atomic service API**: This API can be used in atomic services since API version 12.
372
373**System capability**: SystemCapability.DistributedDataManager.UDMF.Core
374
375**Example**
376
377```ts
378let unifiedRecord = new unifiedDataChannel.UnifiedRecord();
379```
380
381### constructor<sup>12+</sup>
382
383constructor(type: string, value: ValueType)
384
385A constructor used to create a data record with the specified type and value.<br>If **value** is of the [image.PixelMap](../apis-image-kit/js-apis-image.md#pixelmap7) type, **type** must be the value of **OPENHARMONY_PIXEL_MAP** in [UniformDataType](js-apis-data-uniformTypeDescriptor.md#uniformdatatype).<br>If **value** is of the [Want](../apis-ability-kit/js-apis-app-ability-want.md) type, **type** must be the value of **OPENHARMONY_WANT** in [UniformDataType](js-apis-data-uniformTypeDescriptor.md#uniformdatatype).
386
387**Atomic service API**: This API can be used in atomic services since API version 12.
388
389**System capability**: SystemCapability.DistributedDataManager.UDMF.Core
390
391**Parameters**
392
393| Name| Type                           | Mandatory| Description                                     |
394| ------ | ------------------------------- | ---- |-----------------------------------------|
395| type | string | Yes  | Type of the data record to create.|
396| value | [ValueType](#valuetype12) | Yes  | Value of the data record to create.|
397
398**Error codes**
399
400For details about the error codes, see [Universal Error Codes](../errorcode-universal.md).
401
402| **ID**| **Error Message**                               |
403| ------------ | ------------------------------------------- |
404| 401          | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameters types; 3. Parameter verification failed.  |
405
406**Example**
407
408```ts
409import { image } from '@kit.ImageKit';
410import { uniformDataStruct, uniformTypeDescriptor } from '@kit.ArkData';
411import { Want } from '@kit.AbilityKit';
412
413let text = new unifiedDataChannel.UnifiedRecord(uniformTypeDescriptor.UniformDataType.PLAIN_TEXT, 'this is value of text');
414let link = new unifiedDataChannel.UnifiedRecord(uniformTypeDescriptor.UniformDataType.HYPERLINK, 'www.XXX.com');
415let object: Want = {
416  bundleName: 'com.example.myapplication',
417  abilityName: 'entryAbility',
418};
419let wantRecord = new unifiedDataChannel.UnifiedRecord(uniformTypeDescriptor.UniformDataType.OPENHARMONY_WANT, object);
420
421const color = new ArrayBuffer(96);
422let opts: image.InitializationOptions = { editable: true, pixelFormat: 3, size: { height: 4, width: 6 } };
423let pixelMap = image.createPixelMapSync(color, opts);
424let pixelMapRecord = new unifiedDataChannel.UnifiedRecord(uniformTypeDescriptor.UniformDataType.OPENHARMONY_PIXEL_MAP, pixelMap);
425
426let hyperlinkDetails : Record<string, string> = {
427  'attr1': 'value1',
428  'attr2': 'value2',
429}
430let hyperlink : uniformDataStruct.Hyperlink = {
431  uniformDataType:'general.hyperlink',
432  url : 'www.XXX.com',
433  description : 'This is the description of this hyperlink',
434  details : hyperlinkDetails,
435}
436let hyperlinkRecord = new unifiedDataChannel.UnifiedRecord(uniformTypeDescriptor.UniformDataType.HYPERLINK, hyperlink);
437```
438
439### getType
440
441getType(): string
442
443Obtains the type of this **UnfiedRecord**. The data obtained by [getRecords](#getrecords) from the **UnifiedData** object is a **UnifiedRecord** object. You need to use this API to obtain the specific type of the record, convert the **UnifiedRecord** object to its child class, and call the child class interfaces.
444
445**Atomic service API**: This API can be used in atomic services since API version 11.
446
447**System capability**: SystemCapability.DistributedDataManager.UDMF.Core
448
449**Return value**
450
451| Type  | Description                                                  |
452| ------ |------------------------------------------------------|
453| string | Data type obtained. For details, see [UniformDataType](js-apis-data-uniformTypeDescriptor.md#uniformdatatype).|
454
455**Example**
456
457```ts
458import { uniformTypeDescriptor } from '@kit.ArkData';
459
460let text = new unifiedDataChannel.PlainText();
461text.textContent = 'this is textContent of text';
462let unifiedData = new unifiedDataChannel.UnifiedData(text);
463
464let records = unifiedData.getRecords();
465if (records[0].getType() == uniformTypeDescriptor.UniformDataType.PLAIN_TEXT) {
466  let plainText = records[0] as unifiedDataChannel.PlainText;
467  console.info(`textContent: ${plainText.textContent}`);
468}
469```
470
471### getValue<sup>12+</sup>
472
473getValue(): ValueType
474
475Obtains the value of this data record.
476
477**Atomic service API**: This API can be used in atomic services since API version 12.
478
479**System capability**: SystemCapability.DistributedDataManager.UDMF.Core
480
481**Return value**
482
483| Type  | Description                                                  |
484| ------ |------------------------------------------------------|
485| [ValueType](#valuetype12) | Value obtained.|
486
487**Example**
488
489```ts
490import { uniformDataStruct, uniformTypeDescriptor } from '@kit.ArkData';
491
492let text = new unifiedDataChannel.UnifiedRecord(uniformTypeDescriptor.UniformDataType.PLAIN_TEXT, 'this is value of text');
493let value = text.getValue();
494
495let hyperlinkDetails : Record<string, string> = {
496  'attr1': 'value1',
497  'attr2': 'value2',
498}
499let hyperlink : uniformDataStruct.Hyperlink = {
500  uniformDataType:'general.hyperlink',
501  url : 'www.XXX.com',
502  description : 'This is the description of this hyperlink',
503  details : hyperlinkDetails,
504}
505let hyperlinkRecord = new unifiedDataChannel.UnifiedRecord(uniformTypeDescriptor.UniformDataType.HYPERLINK, hyperlink);
506let hyperlinkValue = hyperlinkRecord.getValue();
507```
508
509## Text
510
511Represents the text data. It is a child class of [UnifiedRecord](#unifiedrecord) and a base class of text data. You are advised to use the child class of **Text**, for example, [PlainText](#plaintext), [Hyperlink](#hyperlink), and [HTML](#html), to describe data.
512
513**Atomic service API**: This API can be used in atomic services since API version 11.
514
515**System capability**: SystemCapability.DistributedDataManager.UDMF.Core
516
517| Name| Type| Read-Only| Optional| Description|
518| -------- | -------- | -------- | -------- | -------- |
519| details | Record<string, string> | No| Yes| A dictionary type object, where both the key and value are of the string type and are used to describe the text content. For example, a data object with the following content can be created to describe a text file:<br>{<br>"title":"Title",<br>"content":"Content"<br>}<br> The default value is an empty dictionary object.|
520
521**Example**
522
523```ts
524let text = new unifiedDataChannel.Text();
525text.details = {
526  title: 'MyTitle',
527  content: 'this is content',
528};
529let unifiedData = new unifiedDataChannel.UnifiedData(text);
530```
531
532## PlainText
533
534Represents the plaintext data. It is a child class of [Text](#text) and is used to describe plaintext data.
535
536**Atomic service API**: This API can be used in atomic services since API version 11.
537
538**System capability**: SystemCapability.DistributedDataManager.UDMF.Core
539
540| Name| Type| Read-Only| Optional| Description|
541| -------- | -------- | -------- | -------- | -------- |
542| textContent | string | No| No| Plaintext content.               |
543| abstract    | string | No| Yes| Text abstract. This parameter is optional. The default value is an empty string.|
544
545**Example**
546
547```ts
548let text = new unifiedDataChannel.PlainText();
549text.textContent = 'this is textContent';
550text.abstract = 'this is abstract';
551```
552
553## Hyperlink
554
555Represents hyperlink data. It is a child class of [Text](#text) and is used to describe data of the hyperlink type.
556
557**Atomic service API**: This API can be used in atomic services since API version 11.
558
559**System capability**: SystemCapability.DistributedDataManager.UDMF.Core
560
561| Name| Type| Read-Only| Optional| Description|
562| -------- | -------- | -------- | -------- | -------- |
563| url         | string | No| No| URL.      |
564| description | string | No| Yes| Description of the linked content. This parameter is optional. The default value is an empty string.|
565
566**Example**
567
568```ts
569let link = new unifiedDataChannel.Hyperlink();
570link.url = 'www.XXX.com';
571link.description = 'this is description';
572```
573
574## HTML
575
576Represents the HTML data. It is a child class of [Text](#text) and is used to describe HTML data.
577
578**Atomic service API**: This API can be used in atomic services since API version 11.
579
580**System capability**: SystemCapability.DistributedDataManager.UDMF.Core
581
582| Name| Type| Read-Only| Optional| Description|
583| -------- | -------- | -------- | -------- | -------- |
584| htmlContent  | string | No| No| Content in HTML format.            |
585| plainContent | string | No| Yes| Plaintext without HTML tags. This parameter is optional. The default value is an empty string.|
586
587**Example**
588
589```ts
590let html = new unifiedDataChannel.HTML();
591html.htmlContent = '<div><p>Title</p></div>';
592html.plainContent = 'this is plainContent';
593```
594
595## File
596
597Represents the file data. It is a child class of [UnifiedRecord](#unifiedrecord) and a base class of the data of the file type. You are advised to use the child class of **File**, for example, [Image](#image), [Video](#video), and [Folder](#folder), to describe data.
598
599**Atomic service API**: This API can be used in atomic services since API version 11.
600
601**System capability**: SystemCapability.DistributedDataManager.UDMF.Core
602
603| Name| Type| Read-Only| Optional| Description|
604| -------- | -------- | -------- | -------- | -------- |
605| details | Record<string, string> | No| Yes| A dictionary type object, where both the key and value are of the string type and are used to describe file information. For example, a data object with the following content can be created to describe a file:<br>{<br>"name":"File name",<br>"type":"File type"<br>}<br> The default value is an empty dictionary object.|
606| uri     | string                    | No| No| URI of the file data.                                                                                                                                            |
607
608**Example**
609
610```ts
611let file = new unifiedDataChannel.File();
612file.details = {
613    name: 'test',
614    type: 'txt',
615};
616file.uri = 'schema://com.samples.test/files/test.txt';
617```
618
619## Image
620
621Represents the image data. It is a child class of [File](#file) and is used to describe images.
622
623**Atomic service API**: This API can be used in atomic services since API version 11.
624
625**System capability**: SystemCapability.DistributedDataManager.UDMF.Core
626
627| Name| Type| Read-Only| Optional| Description|
628| -------- | -------- | -------- | -------- | -------- |
629| imageUri | string | No| No| URI of the image.|
630
631**Example**
632
633```ts
634let image = new unifiedDataChannel.Image();
635image.imageUri = 'schema://com.samples.test/files/test.jpg';
636```
637
638## Video
639
640Represents video data. It is a child class of [File](#file) and is used to describe a video file.
641
642**Atomic service API**: This API can be used in atomic services since API version 11.
643
644**System capability**: SystemCapability.DistributedDataManager.UDMF.Core
645
646| Name| Type| Read-Only| Optional| Description|
647| -------- | -------- | -------- | -------- | -------- |
648| videoUri | string | No| No| URI of the video file.|
649
650**Example**
651
652```ts
653let video = new unifiedDataChannel.Video();
654video.videoUri = 'schema://com.samples.test/files/test.mp4';
655```
656
657## Audio
658
659Represents audio data. It is a child class of [File](#file) and is used to describe an audio file.
660
661**Atomic service API**: This API can be used in atomic services since API version 11.
662
663**System capability**: SystemCapability.DistributedDataManager.UDMF.Core
664
665| Name| Type| Read-Only| Optional| Description|
666| -------- | -------- | -------- | -------- | -------- |
667| audioUri | string | No| No| Audio data URI.|
668
669**Example**
670
671```ts
672let audio = new unifiedDataChannel.Audio();
673audio.audioUri = 'schema://com.samples.test/files/test.mp3';
674```
675
676## Folder
677
678Represents the folder data. It is a child class of [File](#file) and is used to describe a folder.
679
680**Atomic service API**: This API can be used in atomic services since API version 11.
681
682**System capability**: SystemCapability.DistributedDataManager.UDMF.Core
683
684| Name| Type| Read-Only| Optional| Description|
685| -------- | -------- | -------- | -------- | -------- |
686| folderUri | string | No| No| URI of the folder.|
687
688**Example**
689
690```ts
691let folder = new unifiedDataChannel.Folder();
692folder.folderUri = 'schema://com.samples.test/files/folder/';
693```
694
695## SystemDefinedRecord
696
697Represents specific data types defined by OpenHarmony. It is a child class of [UnifiedRecord](#unifiedrecord) and a base class of OpenHarmony-specific data types. You are advised to use the child class of **SystemDefinedRecord**, for example, [SystemDefinedForm](#systemdefinedform), [SystemDefinedAppItem](#systemdefinedappitem), and [SystemDefinedPixelMap](#systemdefinedpixelmap), to describe OpenHarmony-specific data.
698
699**Atomic service API**: This API can be used in atomic services since API version 11.
700
701**System capability**: SystemCapability.DistributedDataManager.UDMF.Core
702
703| Name| Type| Read-Only| Optional| Description|
704| -------- | -------- | -------- | -------- | -------- |
705| details | Record<string, number \| string \| Uint8Array> | No| Yes| A dictionary type object, where the key is of the string type, and the value can be a number, a string, or a Uint8Array. The default value is an empty dictionary object.|
706
707**Example**
708
709```ts
710let sdr = new unifiedDataChannel.SystemDefinedRecord();
711let u8Array = new Uint8Array([1, 2, 3, 4, 5, 6, 7, 8, 9, 10]);
712sdr.details = {
713    title: 'recordTitle',
714    version: 1,
715    content: u8Array,
716};
717let unifiedData = new unifiedDataChannel.UnifiedData(sdr);
718```
719
720## SystemDefinedForm
721
722Represents the service widget data defined by the system. It is a child class of [SystemDefinedRecord](#systemdefinedrecord).
723
724**Atomic service API**: This API can be used in atomic services since API version 11.
725
726**System capability**: SystemCapability.DistributedDataManager.UDMF.Core
727
728| Name| Type| Read-Only| Optional| Description|
729| -------- | -------- | -------- | -------- | -------- |
730| formId      | number | No| No| Service widget ID.         |
731| formName    | string | No| No| Widget name.         |
732| bundleName  | string | No| No| Name of the bundle to which the widget belongs.  |
733| abilityName | string | No| No| Ability name corresponding to the widget.|
734| module      | string | No| No| Name of the module to which the widget belongs.  |
735
736**Example**
737
738```ts
739let form = new unifiedDataChannel.SystemDefinedForm();
740form.formId = 123456;
741form.formName = 'MyFormName';
742form.bundleName = 'MyBundleName';
743form.abilityName = 'MyAbilityName';
744form.module = 'MyModule';
745let u8Array = new Uint8Array([1, 2, 3, 4, 5, 6, 7, 8, 9, 10]);
746form.details = {
747  formKey1: 123,
748  formKey2: 'formValue',
749  formKey3: u8Array,
750};
751let unifiedData = new unifiedDataChannel.UnifiedData(form);
752```
753
754## SystemDefinedAppItem
755
756Represents the data of the home screen icon defined by the system. It is a child class of [SystemDefinedRecord](#systemdefinedrecord).
757
758**Atomic service API**: This API can be used in atomic services since API version 11.
759
760**System capability**: SystemCapability.DistributedDataManager.UDMF.Core
761
762| Name| Type| Read-Only| Optional| Description|
763| -------- | -------- | -------- | -------- | -------- |
764| appId       | string | No| No| ID of the application, for which the icon is used.     |
765| appName     | string | No| No| Name of the application, for which the icon is used.      |
766| appIconId   | string | No| No| Image ID of the icon.       |
767| appLabelId  | string | No| No| Label ID corresponding to the icon name.   |
768| bundleName  | string | No| No| Bundle name corresponding to the icon.|
769| abilityName | string | No| No| Application ability name corresponding to the icon.|
770
771**Example**
772
773```ts
774let appItem = new unifiedDataChannel.SystemDefinedAppItem();
775appItem.appId = 'MyAppId';
776appItem.appName = 'MyAppName';
777appItem.appIconId = 'MyAppIconId';
778appItem.appLabelId = 'MyAppLabelId';
779appItem.bundleName = 'MyBundleName';
780appItem.abilityName = 'MyAbilityName';
781let u8Array = new Uint8Array([1, 2, 3, 4, 5, 6, 7, 8, 9, 10]);
782appItem.details = {
783    appItemKey1: 123,
784    appItemKey2: 'appItemValue',
785    appItemKey3: u8Array,
786};
787let unifiedData = new unifiedDataChannel.UnifiedData(appItem);
788```
789
790## SystemDefinedPixelMap
791
792Represents the image data type corresponding to [PixelMap](../apis-image-kit/js-apis-image.md#pixelmap7) defined by the system. It is a child class of [SystemDefinedRecord](#systemdefinedrecord) and holds only binary data of PixelMap.
793
794**Atomic service API**: This API can be used in atomic services since API version 11.
795
796**System capability**: SystemCapability.DistributedDataManager.UDMF.Core
797
798| Name| Type| Read-Only| Optional| Description|
799| -------- | -------- | -------- | -------- | -------- |
800| rawData | Uint8Array | No| No| Binary data of the **PixelMap** object.|
801
802**Example**
803
804```ts
805import { image } from '@kit.ImageKit';  // Module where the PixelMap class is defined.
806
807const color = new ArrayBuffer(96); // Create a PixelMap object.
808let opts: image.InitializationOptions = {
809  editable: true, pixelFormat: 3, size: {
810    height: 4, width: 6
811  }
812}
813image.createPixelMap(color, opts, (error, pixelmap) => {
814  if (error) {
815    console.error('Failed to create pixelmap.');
816  } else {
817    console.info('Succeeded in creating pixelmap.');
818    let arrayBuf = new ArrayBuffer(pixelmap.getPixelBytesNumber());
819    pixelmap.readPixelsToBuffer(arrayBuf);
820    let u8Array = new Uint8Array(arrayBuf);
821    let sdpixel = new unifiedDataChannel.SystemDefinedPixelMap();
822    sdpixel.rawData = u8Array;
823    let unifiedData = new unifiedDataChannel.UnifiedData(sdpixel);
824  }
825})
826```
827
828## ApplicationDefinedRecord
829
830Represents the custom data type for applications only. It is a child class of [UnifiedRecord](#unifiedrecord) and a base class of custom data types of applications. Applications can extend custom data types based on this class.
831
832**Atomic service API**: This API can be used in atomic services since API version 11.
833
834**System capability**: SystemCapability.DistributedDataManager.UDMF.Core
835
836| Name| Type| Read-Only| Optional| Description|
837| -------- | -------- | -------- | -------- | -------- |
838| applicationDefinedType | string     | No| No| Application's custom data type identifier, which must start with **ApplicationDefined**.|
839| rawData                | Uint8Array | No| No| Binary data of the custom data type.                     |
840
841**Example**
842
843```ts
844let record = new unifiedDataChannel.ApplicationDefinedRecord();
845let u8Array = new Uint8Array([1, 2, 3, 4, 5, 6, 7, 8, 9, 10]);
846record.applicationDefinedType = 'ApplicationDefinedType';
847record.rawData = u8Array;
848let unifiedData = new unifiedDataChannel.UnifiedData(record);
849```
850
851## Intention
852
853Enumerates the data channel types supported by the UDMF. It is used to identify different service scenarios, to which the UDMF data channels apply.
854
855**System capability**: SystemCapability.DistributedDataManager.UDMF.Core
856
857| Name      | Value        | Description     |
858|----------|-----------|---------|
859| DATA_HUB | 'DataHub' | Public data channel.<br>**Atomic service API**: This API can be used in atomic services since API version 11.|
860
861## Options
862
863Defines the data operation performed by the UDMF. It includes two optional parameters: **intention** and **key**. The two parameters have no default value, and can be left unspecified. For details, see the parameter description of the specific API.
864
865**Atomic service API**: This API can be used in atomic services since API version 11.
866
867**System capability**: SystemCapability.DistributedDataManager.UDMF.Core
868
869
870| Name      | Type                   | Read-Only| Optional| Description                                                                                                                                                                                                                               |
871|-----------|-------------------------|----|----|-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
872| intention | [Intention](#intention) | No | Yes | Type of the data channel related to the data operation.                                                                                                                                                                                                                 |
873| key       | string                  | No | Yes | Unique identifier of the data object in the UDMF, which can be obtained from the value returned by [insertData](#unifieddatachannelinsertdata).<br>The key consists of **udmf:/**, **intention**, **bundleName**, and **groupId** with a (/) in between, for example, **udmf://DataHub/com.ohos.test/0123456789**.<br>**udmf:/** is fixed, **DataHub** is an enum of **intention**, **com.ohos.test** is the bundle name, and **0123456789** is a group ID randomly generated.|
874
875
876
877## unifiedDataChannel.insertData
878
879insertData(options: Options, data: UnifiedData, callback: AsyncCallback&lt;string&gt;): void
880
881Inserts data to the UDMF public data channel. This API uses an asynchronous callback to return the unique identifier of the data inserted.
882
883**Atomic service API**: This API can be used in atomic services since API version 11.
884
885**System capability**: SystemCapability.DistributedDataManager.UDMF.Core
886
887**Parameters**
888
889| Name     | Type                        | Mandatory| Description                          |
890|----------|----------------------------|----|------------------------------|
891| options  | [Options](#options)        | Yes | Configuration parameters. Only the **intention** is required.       |
892| data     | [UnifiedData](#unifieddata) | Yes | Data to insert.                       |
893| callback | AsyncCallback&lt;string&gt; | Yes | Callback used to return the key (unique identifier) of the data inserted.|
894
895**Error codes**
896
897For details about the error codes, see [Universal Error Codes](../errorcode-universal.md).
898
899| **ID**| **Error Message**                               |
900| ------------ | ------------------------------------------- |
901| 401          | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameters types.  |
902
903**Example**
904
905```ts
906import { unifiedDataChannel } from '@kit.ArkData';
907import { BusinessError } from '@kit.BasicServicesKit';
908
909let plainText = new unifiedDataChannel.PlainText();
910plainText.textContent = 'hello world!';
911let unifiedData = new unifiedDataChannel.UnifiedData(plainText);
912
913let options: unifiedDataChannel.Options = {
914  intention: unifiedDataChannel.Intention.DATA_HUB
915}
916try {
917  unifiedDataChannel.insertData(options, unifiedData, (err, data) => {
918    if (err === undefined) {
919      console.info(`Succeeded in inserting data. key = ${data}`);
920    } else {
921      console.error(`Failed to insert data. code is ${err.code},message is ${err.message} `);
922    }
923  });
924  } catch (e) {
925    let error: BusinessError = e as BusinessError;
926    console.error(`Insert data throws an exception. code is ${error.code},message is ${error.message} `);
927}
928
929```
930
931## unifiedDataChannel.insertData
932
933insertData(options: Options, data: UnifiedData): Promise&lt;string&gt;
934
935Inserts data to the UDMF public data channel. This API uses a promise to return the unique identifier of the data inserted.
936
937**Atomic service API**: This API can be used in atomic services since API version 11.
938
939**System capability**: SystemCapability.DistributedDataManager.UDMF.Core
940
941**Parameters**
942
943| Name    | Type                         | Mandatory| Description                   |
944|---------|-----------------------------|----|-----------------------|
945| options | [Options](#options)         | Yes | Configuration parameters. Only the **intention** is required.|
946| data    | [UnifiedData](#unifieddata) | Yes | Data to insert.                |
947
948**Return value**
949
950| Type                   | Description                               |
951|-----------------------|-----------------------------------|
952| Promise&lt;string&gt; | Promise used to return the key of the data inserted.|
953
954**Error codes**
955
956For details about the error codes, see [Universal Error Codes](../errorcode-universal.md).
957
958| **ID**| **Error Message**                               |
959| ------------ | ------------------------------------------- |
960| 401          | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameters types.  |
961
962**Example**
963
964```ts
965import { unifiedDataChannel } from '@kit.ArkData';
966import { BusinessError } from '@kit.BasicServicesKit';
967
968let plainText = new unifiedDataChannel.PlainText();
969plainText.textContent = 'hello world!';
970let unifiedData = new unifiedDataChannel.UnifiedData(plainText);
971
972let options: unifiedDataChannel.Options = {
973  intention: unifiedDataChannel.Intention.DATA_HUB
974}
975try {
976  unifiedDataChannel.insertData(options, unifiedData).then((data) => {
977    console.info(`Succeeded in inserting data. key = ${data}`);
978  }).catch((err: BusinessError) => {
979    console.error(`Failed to insert data. code is ${err.code},message is ${err.message} `);
980  });
981} catch (e) {
982  let error: BusinessError = e as BusinessError;
983  console.error(`Insert data throws an exception. code is ${error.code},message is ${error.message} `);
984}
985```
986
987## unifiedDataChannel.updateData
988
989updateData(options: Options, data: UnifiedData, callback: AsyncCallback&lt;void&gt;): void
990
991Updates the data in the UDMF public data channel. This API uses an asynchronous callback to return the result.
992
993**Atomic service API**: This API can be used in atomic services since API version 11.
994
995**System capability**: SystemCapability.DistributedDataManager.UDMF.Core
996
997**Parameters**
998
999| Name     | Type                         | Mandatory| Description                                 |
1000|----------|-----------------------------|----|-------------------------------------|
1001| options  | [Options](#options)         | Yes | Configuration parameters. Only the value of **key** is required.                    |
1002| data     | [UnifiedData](#unifieddata) | Yes | New data.                              |
1003| callback | AsyncCallback&lt;void&gt;   | Yes | Callback used to return the result. If the data is updated successfully, **err** is **undefined**. Otherwise, **err** is an error object.|
1004
1005**Error codes**
1006
1007For details about the error codes, see [Universal Error Codes](../errorcode-universal.md).
1008
1009| **ID**| **Error Message**                               |
1010| ------------ | ------------------------------------------- |
1011| 401          | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameters types.  |
1012
1013**Example**
1014
1015```ts
1016import { unifiedDataChannel } from '@kit.ArkData';
1017import { BusinessError } from '@kit.BasicServicesKit';
1018
1019let plainText = new unifiedDataChannel.PlainText();
1020plainText.textContent = 'hello world!';
1021let unifiedData = new unifiedDataChannel.UnifiedData(plainText);
1022
1023let options: unifiedDataChannel.Options = {
1024  key: 'udmf://DataHub/com.ohos.test/0123456789'
1025};
1026
1027try {
1028  unifiedDataChannel.updateData(options, unifiedData, (err) => {
1029    if (err === undefined) {
1030      console.info('Succeeded in updating data.');
1031    } else {
1032      console.error(`Failed to update data. code is ${err.code},message is ${err.message} `);
1033    }
1034  });
1035} catch (e) {
1036  let error: BusinessError = e as BusinessError;
1037  console.error(`Update data throws an exception. code is ${error.code},message is ${error.message} `);
1038}
1039```
1040
1041## unifiedDataChannel.updateData
1042
1043updateData(options: Options, data: UnifiedData): Promise&lt;void&gt;
1044
1045Updates the data in the UDMF public data channel. This API uses a promise to return the result.
1046
1047**Atomic service API**: This API can be used in atomic services since API version 11.
1048
1049**System capability**: SystemCapability.DistributedDataManager.UDMF.Core
1050
1051**Parameters**
1052
1053| Name    | Type                         | Mandatory| Description             |
1054|---------|-----------------------------|----|-----------------|
1055| options | [Options](#options)         | Yes | Configuration parameters. Only the value of **key** is required.|
1056| data    | [UnifiedData](#unifieddata) | Yes | New data.          |
1057
1058**Return value**
1059
1060| Type                 | Description                        |
1061|---------------------|----------------------------|
1062| Promise&lt;void&gt; | Promise that returns no value.|
1063
1064**Error codes**
1065
1066For details about the error codes, see [Universal Error Codes](../errorcode-universal.md).
1067
1068| **ID**| **Error Message**                               |
1069| ------------ | ------------------------------------------- |
1070| 401          | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameters types.  |
1071
1072**Example**
1073
1074```ts
1075import { unifiedDataChannel } from '@kit.ArkData';
1076import { BusinessError } from '@kit.BasicServicesKit';
1077
1078let plainText = new unifiedDataChannel.PlainText();
1079plainText.textContent = 'hello world!';
1080let unifiedData = new unifiedDataChannel.UnifiedData(plainText);
1081
1082let options: unifiedDataChannel.Options = {
1083  key: 'udmf://DataHub/com.ohos.test/0123456789'
1084};
1085
1086try {
1087  unifiedDataChannel.updateData(options, unifiedData).then(() => {
1088    console.info('Succeeded in updating data.');
1089  }).catch((err: BusinessError) => {
1090    console.error(`Failed to update data. code is ${err.code},message is ${err.message} `);
1091  });
1092} catch (e) {
1093  let error: BusinessError = e as BusinessError;
1094  console.error(`Update data throws an exception. code is ${error.code},message is ${error.message} `);
1095}
1096```
1097
1098## unifiedDataChannel.queryData
1099
1100queryData(options: Options, callback: AsyncCallback&lt;Array&lt;UnifiedData&gt;&gt;): void
1101
1102Queries data in the UDMF public data channel. This API uses an asynchronous callback to return the result.
1103
1104**Atomic service API**: This API can be used in atomic services since API version 11.
1105
1106**System capability**: SystemCapability.DistributedDataManager.UDMF.Core
1107
1108**Parameters**
1109
1110| Name     | Type                                                           | Mandatory| Description                                                                                                                                                              |
1111|----------|---------------------------------------------------------------|----|------------------------------------------------------------------------------------------------------------------------------------------------------------------|
1112| options  | [Options](#options)                                           | Yes | Configuration parameters. Both the **key** and **intention** are optional, and the return value varies depending on the parameters passed in.                                                                                                                   |
1113| callback | AsyncCallback&lt;Array&lt;[UnifiedData](#unifieddata)&gt;&gt; | Yes | Callback used to return the queried data.<br>If only the **key** is specified in **options**, the data corresponding to the key is returned.<br>If only the **intention** is specified in **options**, all data in the **intention** is returned.<br>If both **intention** and **key** are specified, the intersection of the two is returned, which is the result obtained when only **key** is specified. If there is no intersection between the specified **intention** and **key**, an error object is returned.|
1114
1115**Error codes**
1116
1117For details about the error codes, see [Universal Error Codes](../errorcode-universal.md).
1118
1119| **ID**| **Error Message**                               |
1120| ------------ | ------------------------------------------- |
1121| 401          | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameters types.  |
1122
1123**Example**
1124
1125```ts
1126import { unifiedDataChannel } from '@kit.ArkData';
1127import { uniformTypeDescriptor } from '@kit.ArkData';
1128import { BusinessError } from '@kit.BasicServicesKit';
1129
1130let options: unifiedDataChannel.Options = {
1131  intention: unifiedDataChannel.Intention.DATA_HUB
1132};
1133
1134try {
1135  unifiedDataChannel.queryData(options, (err, data) => {
1136    if (err === undefined) {
1137      console.info(`Succeeded in querying data. size = ${data.length}`);
1138      for (let i = 0; i < data.length; i++) {
1139        let records = data[i].getRecords();
1140        for (let j = 0; j < records.length; j++) {
1141          if (records[j].getType() === uniformTypeDescriptor.UniformDataType.PLAIN_TEXT) {
1142            let text = records[j] as unifiedDataChannel.PlainText;
1143            console.info(`${i + 1}.${text.textContent}`);
1144          }
1145        }
1146      }
1147    } else {
1148      console.error(`Failed to query data. code is ${err.code},message is ${err.message} `);
1149    }
1150  });
1151} catch (e) {
1152  let error: BusinessError = e as BusinessError;
1153  console.error(`Query data throws an exception. code is ${error.code},message is ${error.message} `);
1154}
1155```
1156
1157## unifiedDataChannel.queryData
1158
1159queryData(options: Options): Promise&lt;Array&lt;UnifiedData&gt;&gt;
1160
1161Queries data in the UDMF public data channel. This API uses a promise to return the result.
1162
1163**Atomic service API**: This API can be used in atomic services since API version 11.
1164
1165**System capability**: SystemCapability.DistributedDataManager.UDMF.Core
1166
1167**Parameters**
1168
1169| Name    | Type                 | Mandatory| Description                                           |
1170|---------|---------------------|----|-----------------------------------------------|
1171| options | [Options](#options) | Yes | Configuration parameters. Both the **key** and **intention** are optional, and the return value varies depending on the parameters passed in.|
1172
1173**Return value**
1174
1175| Type                                                     | Description                                                                                                                                 |
1176|---------------------------------------------------------|-------------------------------------------------------------------------------------------------------------------------------------|
1177| Promise&lt;Array&lt;[UnifiedData](#unifieddata)&gt;&gt; | Promise used to return the result.<br>If only the **key** is specified in **options**, the data corresponding to the key is returned.<br>If only the **intention** is specified in **options**, all data in the **intention** is returned.<br>If both **intention** and **key** are specified, the intersection of the two is returned, which is the result obtained when only **key** is specified. If there is no intersection between the specified **intention** and **key**, an error object is returned.|
1178
1179**Error codes**
1180
1181For details about the error codes, see [Universal Error Codes](../errorcode-universal.md).
1182
1183| **ID**| **Error Message**                               |
1184| ------------ | ------------------------------------------- |
1185| 401          | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameters types.  |
1186
1187**Example**
1188
1189```ts
1190import { unifiedDataChannel } from '@kit.ArkData';
1191import { uniformTypeDescriptor } from '@kit.ArkData';
1192import { BusinessError } from '@kit.BasicServicesKit';
1193
1194let options: unifiedDataChannel.Options = {
1195  key: 'udmf://DataHub/com.ohos.test/0123456789'
1196};
1197
1198try {
1199  unifiedDataChannel.queryData(options).then((data) => {
1200    console.info(`Succeeded in querying data. size = ${data.length}`);
1201    for (let i = 0; i < data.length; i++) {
1202      let records = data[i].getRecords();
1203      for (let j = 0; j < records.length; j++) {
1204        if (records[j].getType() === uniformTypeDescriptor.UniformDataType.PLAIN_TEXT) {
1205          let text = records[j] as unifiedDataChannel.PlainText;
1206          console.info(`${i + 1}.${text.textContent}`);
1207        }
1208      }
1209    }
1210  }).catch((err: BusinessError) => {
1211    console.error(`Failed to query data. code is ${err.code},message is ${err.message} `);
1212  });
1213} catch (e) {
1214  let error: BusinessError = e as BusinessError;
1215  console.error(`Query data throws an exception. code is ${error.code},message is ${error.message} `);
1216}
1217```
1218
1219## unifiedDataChannel.deleteData
1220
1221deleteData(options: Options, callback: AsyncCallback&lt;Array&lt;UnifiedData&gt;&gt;): void
1222
1223Deletes data from the UDMF public data channel. This API uses an asynchronous callback to return the result.
1224
1225**Atomic service API**: This API can be used in atomic services since API version 11.
1226
1227**System capability**: SystemCapability.DistributedDataManager.UDMF.Core
1228
1229**Parameters**
1230
1231| Name     | Type                                                           | Mandatory| Description                                                                                                                                                                                    |
1232|----------|---------------------------------------------------------------|----|----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
1233| options  | [Options](#options)                                           | Yes | Configuration parameters. Both the **key** and **intention** are optional, and the return value varies depending on the parameters passed in.                                                                                                                                         |
1234| callback | AsyncCallback&lt;Array&lt;[UnifiedData](#unifieddata)&gt;&gt; | Yes | Callback used to return the data deleted.<br>If only the **key** is specified in **options**, the data corresponding to the key deleted is returned.<br>If only the **intention** is specified in **options**, all data in the **intention** deleted is returned.<br>If both **intention** and **key** are specified, the intersection of the two deleted is returned. If there is no intersection between the two, an error object is returned.|
1235
1236**Error codes**
1237
1238For details about the error codes, see [Universal Error Codes](../errorcode-universal.md).
1239
1240| **ID**| **Error Message**                               |
1241| ------------ | ------------------------------------------- |
1242| 401          | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameters types.  |
1243
1244**Example**
1245
1246```ts
1247import { unifiedDataChannel } from '@kit.ArkData';
1248import { uniformTypeDescriptor } from '@kit.ArkData';
1249import { BusinessError } from '@kit.BasicServicesKit';
1250
1251let options: unifiedDataChannel.Options = {
1252  intention: unifiedDataChannel.Intention.DATA_HUB
1253};
1254
1255try {
1256  unifiedDataChannel.deleteData(options, (err, data) => {
1257    if (err === undefined) {
1258      console.info(`Succeeded in deleting data. size = ${data.length}`);
1259      for (let i = 0; i < data.length; i++) {
1260        let records = data[i].getRecords();
1261        for (let j = 0; j < records.length; j++) {
1262          if (records[j].getType() === uniformTypeDescriptor.UniformDataType.PLAIN_TEXT) {
1263            let text = records[j] as unifiedDataChannel.PlainText;
1264            console.info(`${i + 1}.${text.textContent}`);
1265          }
1266        }
1267      }
1268    } else {
1269      console.error(`Failed to delete data. code is ${err.code},message is ${err.message} `);
1270    }
1271  });
1272} catch (e) {
1273  let error: BusinessError = e as BusinessError;
1274  console.error(`Delete data throws an exception. code is ${error.code},message is ${error.message} `);
1275}
1276```
1277
1278## unifiedDataChannel.deleteData
1279
1280deleteData(options: Options): Promise&lt;Array&lt;UnifiedData&gt;&gt;
1281
1282Deletes data from the UDMF public data channel. This API uses a promise to return the result.
1283
1284**Atomic service API**: This API can be used in atomic services since API version 11.
1285
1286**System capability**: SystemCapability.DistributedDataManager.UDMF.Core
1287
1288**Parameters**
1289
1290| Name    | Type                 | Mandatory| Description    |
1291|---------|---------------------|----|--------|
1292| options | [Options](#options) | Yes | Configuration parameters. Both the **key** and **intention** are optional, and the return value varies depending on the parameters passed in.|
1293
1294**Return value**
1295
1296| Type                                                     | Description                                                                                                                                                         |
1297|---------------------------------------------------------|-------------------------------------------------------------------------------------------------------------------------------------------------------------|
1298| Promise&lt;Array&lt;[UnifiedData](#unifieddata)&gt;&gt; | Promise used to return the data deleted.<br>If only the **key** is specified in **options**, the data corresponding to the key deleted is returned.<br>If only the **intention** is specified in **options**, all data in the **intention** deleted is returned.<br>If both **intention** and **key** are specified, the intersection of the two deleted is returned. If there is no intersection between the two, an error object is returned.|
1299
1300**Error codes**
1301
1302For details about the error codes, see [Universal Error Codes](../errorcode-universal.md).
1303
1304| **ID**| **Error Message**                               |
1305| ------------ | ------------------------------------------- |
1306| 401          | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameters types.  |
1307
1308**Example**
1309
1310```ts
1311import { unifiedDataChannel } from '@kit.ArkData';
1312import { uniformTypeDescriptor } from '@kit.ArkData';
1313import { BusinessError } from '@kit.BasicServicesKit';
1314
1315let options: unifiedDataChannel.Options = {
1316  key: 'udmf://DataHub/com.ohos.test/0123456789'
1317};
1318
1319try {
1320  unifiedDataChannel.deleteData(options).then((data) => {
1321    console.info(`Succeeded in deleting data. size = ${data.length}`);
1322    for (let i = 0; i < data.length; i++) {
1323      let records = data[i].getRecords();
1324      for (let j = 0; j < records.length; j++) {
1325        if (records[j].getType() === uniformTypeDescriptor.UniformDataType.PLAIN_TEXT) {
1326          let text = records[j] as unifiedDataChannel.PlainText;
1327          console.info(`${i + 1}.${text.textContent}`);
1328        }
1329      }
1330    }
1331  }).catch((err: BusinessError) => {
1332    console.error(`Failed to delete data. code is ${err.code},message is ${err.message} `);
1333  });
1334} catch (e) {
1335  let error: BusinessError = e as BusinessError;
1336  console.error(`Query data throws an exception. code is ${error.code},message is ${error.message} `);
1337}
1338```
1339