1# @ohos.pasteboard (Pasteboard)
2
3The **Pasteboard** module provides the copy and paste support for the system pasteboard. You can use the APIs of this module to operate pasteboard content of the plain text, HTML, URI, Want, pixel map, and other types.
4
5> **NOTE**
6>
7> The initial APIs of this module are supported since API version 6. Newly added APIs will be marked with a superscript to indicate their earliest API version.
8
9## Modules to Import
10
11```ts
12import { pasteboard } from '@kit.BasicServicesKit';
13```
14
15## Constants
16
17**Atomic service API**: This API can be used in atomic services since API version 11.
18
19**System capability**: SystemCapability.MiscServices.Pasteboard
20
21| Name| Type| Value           | Description                                                                                                                                       |
22| -------- | -------- |--------------|-------------------------------------------------------------------------------------------------------------------------------------------|
23| MAX_RECORD_NUM<sup>7+</sup> | number | -            | Maximum number of records in a **PasteData** object. In versions earlier than API version 10, the value is 512, indicating that no more records can be added once the number of records reaches 512.<br>Since API version 10, no limit is placed on the number of records in a **PasteData** object.|
24| MIMETYPE_TEXT_HTML<sup>7+</sup> | string | 'text/html'  | MIME type of the HTML content.                                                                                                                         |
25| MIMETYPE_TEXT_WANT<sup>7+</sup> | string | 'text/want'  | MIME type of the Want content.                                                                                                                         |
26| MIMETYPE_TEXT_PLAIN<sup>7+</sup> | string | 'text/plain' | MIME type of the plain text content.                                                                                                                          |
27| MIMETYPE_TEXT_URI<sup>7+</sup> | string | 'text/uri'   | MIME type of the URI content.                                                                                                                          |
28| MIMETYPE_PIXELMAP<sup>9+</sup> | string | 'pixelMap'   | MIME type of the pixel map.                                                                                                                     |
29
30## ValueType<sup>9+</sup>
31
32type ValueType = string | image.PixelMap | Want | ArrayBuffer
33
34Enumerates the value types.
35
36**Atomic service API**: This API can be used in atomic services since API version 11.
37
38**System capability**: SystemCapability.MiscServices.Pasteboard
39
40| Type| Description|
41| -------- | -------- |
42| string | The value is a string.|
43| image.PixelMap | The value is of the [image.PixelMap](../apis-image-kit/js-apis-image.md#pixelmap7) type.|
44| Want | The value is of the [Want](../apis-ability-kit/js-apis-app-ability-want.md) type.|
45| ArrayBuffer | The value is of the **ArrayBuffer** type.|
46
47## pasteboard.createData<sup>9+</sup>
48
49createData(mimeType: string, value: ValueType): PasteData
50
51Creates a **PasteData** object of a custom type.
52
53**Atomic service API**: This API can be used in atomic services since API version 11.
54
55**System capability**: SystemCapability.MiscServices.Pasteboard
56
57**Parameters**
58
59| Name| Type| Mandatory| Description                                                                                                    |
60| -------- | -------- | -------- |--------------------------------------------------------------------------------------------------------|
61| mimeType | string | Yes| MIME type of custom data. The value can a predefined MIME type listed in [Constants](#constants), including HTML, WANT, plain text, URI, and pixel map, or a custom MIME type. The value of **mimeType** cannot exceed 1024 bytes.|
62| value | [ValueType](#valuetype9) | Yes| Content of custom data.                                                                                              |
63
64**Return value**
65
66| Type| Description|
67| -------- | -------- |
68| [PasteData](#pastedata) |  **PasteData** object.|
69
70**Error codes**
71
72For details about the error codes, see [Universal Error Codes](../errorcode-universal.md).
73
74| Error Code ID| Error Message|
75| -------- | -------- |
76| 401      | Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameters types; 3. Parameter verification failed. |
77
78**Example 1**
79
80  ```ts
81  let dataXml = new ArrayBuffer(256);
82  let pasteData: pasteboard.PasteData = pasteboard.createData('app/xml', dataXml);
83  ```
84
85**Example 2**
86
87  ```ts
88 let dataText = 'hello';
89 let pasteData: pasteboard.PasteData = pasteboard.createData(pasteboard.MIMETYPE_TEXT_PLAIN, dataText);
90  ```
91
92## pasteboard.createData<sup>14+</sup>
93
94createData(data: Record&lt;string, ValueType&gt;): PasteData
95
96Creates a **PasteData** object that contains multiple types of data.
97
98**System capability**: SystemCapability.MiscServices.Pasteboard
99
100**Parameters**
101
102| Name| Type                                            | Mandatory| Description                                                                                                                                                                                                                                                                                         |
103| -------- |------------------------------------------------| -------- |---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
104| data | Record&lt;string, [ValueType](#valuetype9)&gt; | Yes| The key of **Record** can be the MIME type corresponding to the pasteboard data, including HTML, WANT, plain text, URI, and PixelMap defined in [Constants](#constants). Alternatively, the key could be a custom MIME type, whose parameter, the length of **mimeType**, cannot exceed 1024 bytes.<br>The value of **Record** is the custom data corresponding to the MIME type specified in the key.<br>The first MIME type specified by the key-value in **Record** is used as the default MIME type of the first **PasteDataRecord** in the **PasteData** object. Data of non-default types can be read only by using the [getData](#getdata14) API.|
105
106**Return value**
107
108| Type| Description|
109| -------- | -------- |
110| [PasteData](#pastedata) |  **PasteData** object.|
111
112**Error codes**
113
114For details about the error codes, see [Universal Error Codes](../errorcode-universal.md).
115
116| Error Code ID| Error Message|
117| -------- | -------- |
118| 401      | Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameters types; 3. Parameter verification failed. |
119
120**Example 1**
121
122```ts
123let pasteData: pasteboard.PasteData = pasteboard.createData({
124    'text/plain': 'hello',
125    'app/xml': new ArrayBuffer(256),
126});
127```
128
129**Example 2**
130
131```ts
132let record: Record<string, pasteboard.ValueType> = {};
133record[pasteboard.MIMETYPE_TEXT_PLAIN] = 'hello';
134record[pasteboard.MIMETYPE_TEXT_URI] = 'dataability:///com.example.myapplication1/user.txt';
135let pasteData: pasteboard.PasteData = pasteboard.createData(record);
136```
137
138## pasteboard.createRecord<sup>9+</sup>
139
140createRecord(mimeType: string, value: ValueType):PasteDataRecord;
141
142Creates a **PasteDataRecord** object of the custom type.
143
144**Atomic service API**: This API can be used in atomic services since API version 11.
145
146**System capability**: SystemCapability.MiscServices.Pasteboard
147
148**Parameters**
149
150| Name| Type| Mandatory| Description               |
151| -------- | -------- | -------- |-------------------|
152| mimeType | string | Yes| MIME type of custom data. The value can a predefined MIME type listed in [Constants](#constants), including HTML, WANT, plain text, URI, and pixel map, or a custom MIME type. The value of **mimeType** cannot exceed 1024 bytes. |
153| value | [ValueType](#valuetype9) | Yes| Content of custom data.         |
154
155**Return value**
156
157| Type| Description|
158| -------- | -------- |
159| [PasteDataRecord](#pastedatarecord7) | New **PasteDataRecord** object of the custom type.|
160
161**Error codes**
162
163For details about the error codes, see [Universal Error Codes](../errorcode-universal.md).
164
165| Error Code ID| Error Message|
166| -------- | -------- |
167| 401      | Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameters types;  3. Parameter verification failed. |
168
169**Example 1**
170
171  ```ts
172let dataXml = new ArrayBuffer(256);
173let pasteDataRecord: pasteboard.PasteDataRecord = pasteboard.createRecord('app/xml', dataXml);
174  ```
175
176**Example 2**
177
178  ```ts
179let dataUri = 'dataability:///com.example.myapplication1/user.txt';
180let record: pasteboard.PasteDataRecord = pasteboard.createRecord(pasteboard.MIMETYPE_TEXT_URI, dataUri);
181  ```
182
183## pasteboard.getSystemPasteboard
184
185getSystemPasteboard(): SystemPasteboard
186
187Obtains this **SystemPasteboard** object.
188
189**Atomic service API**: This API can be used in atomic services since API version 11.
190
191**System capability**: SystemCapability.MiscServices.Pasteboard
192
193**Return value**
194
195| Type| Description|
196| -------- | -------- |
197| [SystemPasteboard](#systempasteboard) | **SystemPasteboard** object.|
198
199**Example**
200
201```ts
202let systemPasteboard: pasteboard.SystemPasteboard = pasteboard.getSystemPasteboard();
203```
204
205## ShareOption<sup>9+</sup>
206
207Enumerates the pasteable ranges of pasteboard data.
208
209**Atomic service API**: This API can be used in atomic services since API version 11.
210
211**System capability**: SystemCapability.MiscServices.Pasteboard
212
213| Name                              | Value | Description                                                                                 |
214| ---------------------------------- | --- | ------------------------------------------------------------------------------------- |
215| INAPP                              | 0   | Only intra-application pasting is allowed.                                                             |
216| LOCALDEVICE                        | 1   | Paste is allowed in any application on the local device.                                                   |
217| CROSSDEVICE<sup>(deprecated)</sup> | 2   | Paste is allowed in any application across devices.<br>This API has been deprecated since API Version 12. No alternative API or method is available. You can choose **Settings** > **Multi-Device Collaboration** > **Cross-Device Clipboard Switch** to set whether to allow cross-device pasting.|
218
219## pasteboard.createHtmlData<sup>(deprecated)</sup>
220
221createHtmlData(htmlText: string): PasteData
222
223Creates a **PasteData** object of the HTML type.
224> **NOTE**
225>
226> This API is supported since API version 7 and deprecated since API version 9. You are advised to use [pasteboard.createData](#pasteboardcreatedata9).
227
228**System capability**: SystemCapability.MiscServices.Pasteboard
229
230**Parameters**
231
232| Name| Type| Mandatory| Description|
233| -------- | -------- | -------- | -------- |
234| htmlText | string | Yes| HTML content.|
235
236**Return value**
237
238| Type| Description|
239| -------- | -------- |
240| [PasteData](#pastedata) | **PasteData** object.|
241
242**Example**
243
244```ts
245let html = "<!DOCTYPE html>\n" + "<html>\n" + "<head>\n" + "<meta charset=\"utf-8\">\n" + "<title>HTML-PASTEBOARD_HTML</title>\n" + "</head>\n" + "<body>\n" + "    <h1>HEAD</h1>\n" + "    <p></p>\n" + "</body>\n" + "</html>";
246let pasteData: pasteboard.PasteData = pasteboard.createHtmlData(html);
247```
248
249## pasteboard.createWantData<sup>(deprecated)</sup>
250
251createWantData(want: Want): PasteData
252
253Creates a **PasteData** object of the Want type.
254> **NOTE**
255>
256> This API is supported since API version 7 and deprecated since API version 9. You are advised to use [pasteboard.createData](#pasteboardcreatedata9).
257
258**System capability**: SystemCapability.MiscServices.Pasteboard
259
260**Parameters**
261
262| Name| Type| Mandatory| Description|
263| -------- | -------- | -------- | -------- |
264| want | [Want](../apis-ability-kit/js-apis-app-ability-want.md) | Yes| Want content.|
265
266**Return value**
267
268| Type| Description|
269| -------- | -------- |
270| [PasteData](#pastedata) | **PasteData** object.|
271
272**Example**
273
274```ts
275import { Want } from '@kit.AbilityKit';
276
277let object: Want = {
278    bundleName: "com.example.aafwk.test",
279    abilityName: "com.example.aafwk.test.TwoAbility"
280};
281let pasteData: pasteboard.PasteData = pasteboard.createWantData(object);
282```
283
284## pasteboard.createPlainTextData<sup>(deprecated)</sup>
285
286createPlainTextData(text: string): PasteData
287
288Creates a **PasteData** object of the plain text type.
289> **NOTE**
290>
291> This API is supported since API version 6 and deprecated since API version 9. You are advised to use [pasteboard.createData](#pasteboardcreatedata9).
292
293**System capability**: SystemCapability.MiscServices.Pasteboard
294
295**Parameters**
296
297| Name| Type| Mandatory| Description|
298| -------- | -------- | -------- | -------- |
299| text | string | Yes| Plain text.|
300
301**Return value**
302
303| Type| Description|
304| -------- | -------- |
305| [PasteData](#pastedata) | **PasteData** object.|
306
307**Example**
308
309```ts
310let pasteData: pasteboard.PasteData = pasteboard.createPlainTextData('content');
311```
312
313## pasteboard.createUriData<sup>(deprecated)</sup>
314
315createUriData(uri: string): PasteData
316
317Creates a **PasteData** object of the URI type.
318> **NOTE**
319>
320> This API is supported since API version 7 and deprecated since API version 9. You are advised to use [pasteboard.createData](#pasteboardcreatedata9).
321
322**System capability**: SystemCapability.MiscServices.Pasteboard
323
324**Parameters**
325
326| Name| Type| Mandatory| Description|
327| -------- | -------- | -------- | -------- |
328| uri | string | Yes| URI content.|
329
330**Return value**
331
332| Type| Description|
333| -------- | -------- |
334| [PasteData](#pastedata) | **PasteData** object.|
335
336**Example**
337
338```ts
339let pasteData: pasteboard.PasteData = pasteboard.createUriData('dataability:///com.example.myapplication1/user.txt');
340```
341## pasteboard.createHtmlTextRecord<sup>(deprecated)</sup>
342
343createHtmlTextRecord(htmlText: string): PasteDataRecord
344
345Creates a **PasteDataRecord** object of the HTML text type.
346> **NOTE**
347>
348> This API is supported since API version 7 and deprecated since API version 9. You are advised to use [pasteboard.createRecord](#pasteboardcreaterecord9).
349
350**System capability**: SystemCapability.MiscServices.Pasteboard
351
352**Parameters**
353
354| Name| Type| Mandatory| Description|
355| -------- | -------- | -------- | -------- |
356| htmlText | string | Yes| HTML content.|
357
358**Return value**
359
360| Type| Description|
361| -------- | -------- |
362| [PasteDataRecord](#pastedatarecord7) | **PasteDataRecord** object of the HTML text type.|
363
364**Example**
365
366```ts
367let html = "<!DOCTYPE html>\n" + "<html>\n" + "<head>\n" + "<meta charset=\"utf-8\">\n" + "<title>HTML-PASTEBOARD_HTML</title>\n" + "</head>\n" + "<body>\n" + "    <h1>HEAD</h1>\n" + "    <p></p>\n" + "</body>\n" + "</html>";
368let record: pasteboard.PasteDataRecord = pasteboard.createHtmlTextRecord(html);
369```
370
371## pasteboard.createWantRecord<sup>(deprecated)</sup>
372
373createWantRecord(want: Want): PasteDataRecord
374
375Creates a **PasteDataRecord** object of the Want type.
376> **NOTE**
377>
378> This API is supported since API version 7 and deprecated since API version 9. You are advised to use [pasteboard.createRecord](#pasteboardcreaterecord9).
379
380**System capability**: SystemCapability.MiscServices.Pasteboard
381
382**Parameters**
383
384| Name| Type| Mandatory| Description|
385| -------- | -------- | -------- | -------- |
386| want | [Want](../apis-ability-kit/js-apis-app-ability-want.md) | Yes| Want content.|
387
388**Return value**
389
390| Type| Description|
391| -------- | -------- |
392| [PasteDataRecord](#pastedatarecord7) | New **PasteDataRecord** object of the Want type.|
393
394**Example**
395
396```ts
397import { Want } from '@kit.AbilityKit';
398
399let object: Want = {
400    bundleName: "com.example.aafwk.test",
401    abilityName: "com.example.aafwk.test.TwoAbility"
402};
403let record: pasteboard.PasteDataRecord = pasteboard.createWantRecord(object);
404```
405
406## pasteboard.createPlainTextRecord<sup>(deprecated)</sup>
407
408createPlainTextRecord(text: string): PasteDataRecord
409
410Creates a **PasteDataRecord** object of the plain text type.
411> **NOTE**
412>
413> This API is supported since API version 7 and deprecated since API version 9. You are advised to use [pasteboard.createRecord](#pasteboardcreaterecord9).
414
415**System capability**: SystemCapability.MiscServices.Pasteboard
416
417**Parameters**
418
419| Name| Type| Mandatory| Description|
420| -------- | -------- | -------- | -------- |
421| text | string | Yes| Plain text.|
422
423**Return value**
424
425| Type| Description|
426| -------- | -------- |
427| [PasteDataRecord](#pastedatarecord7) | New **PasteDataRecord** object of the plain text type.|
428
429**Example**
430
431```ts
432let record: pasteboard.PasteDataRecord = pasteboard.createPlainTextRecord('hello');
433```
434
435## pasteboard.createUriRecord<sup>(deprecated)</sup>
436
437createUriRecord(uri: string): PasteDataRecord
438
439Creates a **PasteDataRecord** object of the URI type.
440> **NOTE**
441>
442> This API is supported since API version 7 and deprecated since API version 9. You are advised to use [pasteboard.createRecord](#pasteboardcreaterecord9).
443
444**System capability**: SystemCapability.MiscServices.Pasteboard
445
446**Parameters**
447
448| Name| Type| Mandatory| Description|
449| -------- | -------- | -------- | -------- |
450| uri | string | Yes| URI content.|
451
452**Return value**
453
454| Type| Description|
455| -------- | -------- |
456| [PasteDataRecord](#pastedatarecord7) | New **PasteDataRecord** object of the URI type.|
457
458**Example**
459
460```ts
461let record: pasteboard.PasteDataRecord = pasteboard.createUriRecord('dataability:///com.example.myapplication1/user.txt');
462```
463
464
465## PasteDataProperty<sup>7+</sup>
466
467Defines the properties of all data records on the pasteboard, including the timestamp, data type, and additional data.
468The defined properties can be applied to the pasteboard only with the [setProperty](#setproperty9) API.
469
470**Atomic service API**: This API can be used in atomic services since API version 11.
471
472**System capability**: SystemCapability.MiscServices.Pasteboard
473
474| Name| Type| Readable| Writable| Description                                                                                                                                                                                                                                      |
475| -------- | -------- | -------- | -------- |------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
476| additions<sup>7+</sup> | {[key:string]:object} | Yes| Yes| Additional data. It does not allow for dynamic adding of attributes. Attributes can be added only by re-assigning values. For details, see the example of **setProperty**.                                                                                                                                                                                                                             |
477| mimeTypes<sup>7+</sup> | Array&lt;string&gt; | Yes| No| Non-repeating data types of the data records on the pasteboard.                                                                                                                                                                                                                  |
478| tag<sup>7+</sup> | string | Yes| Yes| Custom tag.                                                                                                                                                                                                                                |
479| timestamp<sup>7+</sup> | number | Yes| No| Timestamp when data is written to the pasteboard (unit: ms).                                                                                                                                                                                                                     |
480| localOnly<sup>7+</sup> | boolean | Yes| Yes| Whether the pasteboard content is for local access only. The default value is **false**. The value will be overwritten by the value of the **shareOption** attribute. You are advised to use the **shareOption** attribute instead. **ShareOption.INAPP** and **ShareOption.LOCALDEVICE** set **localOnly** to **true**, and **ShareOption.CROSSDEVICE** sets **localOnly** to false.<br>- **true**: The pasteboard content is set for local access only.<br>- **false**: The pasteboard content can be shared between devices.|
481| shareOption<sup>9+</sup> | [ShareOption](#shareoption9) | Yes| Yes| Where the pasteboard content can be pasted. If this attribute is set incorrectly or not set, the default value **CROSSDEVICE** is used.|
482
483## PasteDataRecord<sup>7+</sup>
484
485Provides **PasteDataRecord** APIs. A **PasteDataRecord** is an abstract definition of the content on the pasteboard. The pasteboard content consists of one or more plain text, HTML, URI, or Want records.
486
487### Attributes
488
489**Atomic service API**: This API can be used in atomic services since API version 11.
490
491**System capability**: SystemCapability.MiscServices.Pasteboard
492
493| Name| Type| Readable| Writable| Description|
494| -------- | -------- | -------- | -------- | -------- |
495| htmlText<sup>7+</sup> | string | Yes| No| HTML content.|
496| want<sup>7+</sup> | [Want](../apis-ability-kit/js-apis-app-ability-want.md) | Yes| No| Want content.|
497| mimeType<sup>7+</sup> | string | Yes| No| Data type.|
498| plainText<sup>7+</sup> | string | Yes| No| Plain text.|
499| uri<sup>7+</sup> | string | Yes| No| URI content.|
500| pixelMap<sup>9+</sup> | [image.PixelMap](../apis-image-kit/js-apis-image.md#pixelmap7) | Yes| No| Pixel map.|
501| data<sup>9+</sup> | {[mimeType:&nbsp;string]:&nbsp;ArrayBuffer} | Yes| No| Content of custom data.|
502
503### toPlainText<sup>9+</sup>
504
505toPlainText(): string
506
507Forcibly converts the content in a **PasteData** object to text.
508
509**Atomic service API**: This API can be used in atomic services since API version 11.
510
511**System capability**: SystemCapability.MiscServices.Pasteboard
512
513**Return value**
514
515| Type| Description|
516| -------- | -------- |
517| string | Plain text.|
518
519**Example**
520
521```ts
522let record: pasteboard.PasteDataRecord = pasteboard.createRecord(pasteboard.MIMETYPE_TEXT_URI, 'dataability:///com.example.myapplication1/user.txt');
523let data: string = record.toPlainText();
524console.info(`Succeeded in converting to text. Data: ${data}`);
525```
526
527### addEntry<sup>14+</sup>
528
529addEntry(type: string, value: ValueType): void
530
531Adds custom data of an extra type to **PasteDataRecord**. The MIME type added using this method is not the default type of **Record**. You can only use the [getData](#getdata14) API to read the corresponding data.
532
533**System capability**: SystemCapability.MiscServices.Pasteboard
534
535**Parameters**
536
537| Name  | Type| Mandatory| Description               |
538|-------| -------- | -------- |-------------------|
539| type  | string | Yes| MIME type of custom data. The value can a predefined MIME type listed in [Constants](#constants), including HTML, WANT, plain text, URI, and pixel map, or a custom MIME type. The value of **mimeType** cannot exceed 1024 bytes. |
540| value | [ValueType](#valuetype9) | Yes| Content of custom data.         |
541
542**Error codes**
543
544For details about the error codes, see [Universal Error Codes](../errorcode-universal.md) and [Pasteboard Error Codes](errorcode-pasteboard.md).
545
546| Error Code ID| Error Message|
547| -------- | -------- |
548| 401      | Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameters types; 3. Parameter verification failed. |
549
550**Example**
551
552```ts
553let html = "<!DOCTYPE html>\n" + "<html>\n" + "<head>\n" + "<meta charset=\"utf-8\">\n" + "<title>HTML-PASTEBOARD_HTML</title>\n" + "</head>\n" + "<body>\n" + "    <h1>HEAD</h1>\n" + "    <p></p>\n" + "</body>\n" + "</html>";
554let record: pasteboard.PasteDataRecord = pasteboard.createRecord(pasteboard.MIMETYPE_TEXT_URI, 'dataability:///com.example.myapplication1/user.txt');
555record.addEntry(pasteboard.MIMETYPE_TEXT_PLAIN, 'hello');
556record.addEntry(pasteboard.MIMETYPE_TEXT_HTML, html);
557```
558
559### getValidTypes<sup>14+</sup>
560
561getValidTypes(types: Array&lt;string&gt;): Array&lt;string&gt;
562
563Obtains the intersection of the input MIME type and the MIME type of the pasteboard data.
564
565**System capability**: SystemCapability.MiscServices.Pasteboard
566
567**Parameters**
568
569| Name  | Type| Mandatory| Description            |
570|-------| -------- | -------- |----------------|
571| types | Array&lt;string&gt; | Yes| List of the MIME types.|
572
573**Return value**
574
575| Type| Description                                  |
576| -------- |--------------------------------------|
577| Array&lt;string&gt; | Intersection of the input MIME type and the MIME type of the pasteboard data obtained.|
578
579**Error codes**
580
581For details about the error codes, see [Universal Error Codes](../errorcode-universal.md) and [Pasteboard Error Codes](errorcode-pasteboard.md).
582
583| Error Code ID| Error Message|
584| -------- | -------- |
585| 401      | Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameters types; 3. Parameter verification failed. |
586
587**Example**
588
589```ts
590let html = "<!DOCTYPE html>\n" + "<html>\n" + "<head>\n" + "<meta charset=\"utf-8\">\n" + "<title>HTML-PASTEBOARD_HTML</title>\n" + "</head>\n" + "<body>\n" + "    <h1>HEAD</h1>\n" + "    <p></p>\n" + "</body>\n" + "</html>";
591let record: pasteboard.PasteDataRecord = pasteboard.createRecord(pasteboard.MIMETYPE_TEXT_URI, 'dataability:///com.example.myapplication1/user.txt');
592record.addEntry(pasteboard.MIMETYPE_TEXT_PLAIN, 'hello');
593record.addEntry(pasteboard.MIMETYPE_TEXT_HTML, html);
594let types: string[] = record.getValidTypes([
595    pasteboard.MIMETYPE_TEXT_PLAIN,
596    pasteboard.MIMETYPE_TEXT_HTML,
597    pasteboard.MIMETYPE_TEXT_URI,
598    pasteboard.MIMETYPE_TEXT_WANT,
599    pasteboard.MIMETYPE_PIXELMAP
600]);
601```
602
603### getData<sup>14+</sup>
604
605getData(type: string): Promise&lt;ValueType&gt;
606
607Obtains custom data of the specified MIME type from **PasteDataRecord**.
608
609**System capability**: SystemCapability.MiscServices.Pasteboard
610
611**Parameters**
612
613| Name | Type    |Mandatory| Description      |
614|------|--------|-------- |----------|
615| type | string |Yes| MIME type.|
616
617**Return value**
618
619| Type                                     | Description                                                                                                                  |
620|-----------------------------------------|----------------------------------------------------------------------------------------------------------------------|
621| Promise&lt;[ValueType](#valuetype9)&gt; | Promise used to return the result.<br>If **PasteDataRecord** contains data of multiple MIME types, the non-**PasteDataRecord** data of the default MIME type can be obtained only through this API.|
622
623**Error codes**
624
625For details about the error codes, see [Universal Error Codes](../errorcode-universal.md) and [Pasteboard Error Codes](errorcode-pasteboard.md).
626
627| Error Code ID| Error Message|
628| -------- | -------- |
629| 401      | Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameters types; 3. Parameter verification failed. |
630
631**Example**
632
633```ts
634let html = "<!DOCTYPE html>\n" + "<html>\n" + "<head>\n" + "<meta charset=\"utf-8\">\n" + "<title>HTML-PASTEBOARD_HTML</title>\n" + "</head>\n" + "<body>\n" + "    <h1>HEAD</h1>\n" + "    <p></p>\n" + "</body>\n" + "</html>";
635let record: pasteboard.PasteDataRecord = pasteboard.createRecord(pasteboard.MIMETYPE_TEXT_URI, 'dataability:///com.example.myapplication1/user.txt');
636record.addEntry(pasteboard.MIMETYPE_TEXT_PLAIN, 'hello');
637record.addEntry(pasteboard.MIMETYPE_TEXT_HTML, html);
638record.getData(pasteboard.MIMETYPE_TEXT_PLAIN).then((value: pasteboard.ValueType) => {
639    let textPlainContent = value as string;
640    console.info('Success to get text/plain value. value is: ' + textPlainContent);
641}).catch((err: BusinessError) => {
642    console.error('Failed to get text/plain value. Cause: ' + err.message);
643});
644record.getData(pasteboard.MIMETYPE_TEXT_URI).then((value: pasteboard.ValueType) => {
645    let uri = value as string;
646    console.info('Success to get text/uri value. value is: ' + uri);
647}).catch((err: BusinessError) => {
648    console.error('Failed to get text/uri value. Cause: ' + err.message);
649});
650```
651
652### convertToText<sup>(deprecated)</sup>
653
654convertToText(callback: AsyncCallback&lt;string&gt;): void
655
656Forcibly converts the content in a **PasteData** object to text. This API uses an asynchronous callback to return the result.
657> **NOTE**
658>
659> This API is supported since API version 7 and deprecated since API version 9. You are advised to use [toPlainText](#toplaintext9).
660
661**System capability**: SystemCapability.MiscServices.Pasteboard
662
663**Parameters**
664
665| Name| Type| Mandatory| Description|
666| -------- | -------- | -------- | -------- |
667| callback | AsyncCallback&lt;string&gt; | Yes| Callback used to return the result. If the operation is successful, **err** is **undefined** and **data** is the text obtained from the conversion. Otherwise, **err** is error information.|
668
669**Error codes**
670
671For details about the error codes, see [Universal Error Codes](../errorcode-universal.md).
672
673| Error Code ID| Error Message|
674| -------- | -------- |
675| 401      | Possible causes: Incorrect parameters types. |
676
677**Example**
678
679```ts
680import { BusinessError } from '@kit.BasicServicesKit';
681
682let record: pasteboard.PasteDataRecord = pasteboard.createUriRecord('dataability:///com.example.myapplication1/user.txt');
683record.convertToText((err: BusinessError, data: string) => {
684    if (err) {
685        console.error(`Failed to convert to text. Cause: ${err.message}`);
686        return;
687    }
688    console.info(`Succeeded in converting to text. Data: ${data}`);
689});
690```
691
692### convertToText<sup>(deprecated)</sup>
693
694convertToText(): Promise&lt;string&gt;
695
696Forcibly converts the content in a **PasteData** object to text. This API uses a promise to return the result.
697> **NOTE**
698>
699> This API is supported since API version 7 and deprecated since API version 9. You are advised to use [toPlainText](#toplaintext9).
700
701**System capability**: SystemCapability.MiscServices.Pasteboard
702
703**Return value**
704
705| Type| Description|
706| -------- | -------- |
707| Promise&lt;string&gt; | Promise used to return the text obtained from the conversion.|
708
709**Example**
710
711```ts
712import { BusinessError } from '@kit.BasicServicesKit';
713
714let record: pasteboard.PasteDataRecord = pasteboard.createUriRecord('dataability:///com.example.myapplication1/user.txt');
715record.convertToText().then((data: string) => {
716    console.info(`Succeeded in converting to text. Data: ${data}`);
717}).catch((err: BusinessError) => {
718    console.error(`Failed to convert to text. Cause: ${err.message}`);
719});
720```
721
722## PasteData
723
724Implements a **PasteData** object. Paste data contains one or more data records ([PasteDataRecord](#pastedatarecord7)) and property description objects ([PasteDataProperty](#pastedataproperty7)).
725
726Before calling any API in **PasteData**, you must use **[createData()](#pasteboardcreatedata9)** or **[getData()](#getdata9)** to create a **PasteData** object.
727
728**System capability**: SystemCapability.MiscServices.Pasteboard
729
730### getPrimaryText
731
732getPrimaryText(): string
733
734Obtains the plain text of the primary record.
735
736**Atomic service API**: This API can be used in atomic services since API version 11.
737
738**System capability**: SystemCapability.MiscServices.Pasteboard
739
740**Return value**
741
742| Type| Description|
743| -------- | -------- |
744| string | Plain text.|
745
746**Example**
747
748```ts
749let pasteData: pasteboard.PasteData = pasteboard.createData(pasteboard.MIMETYPE_TEXT_PLAIN, 'hello');
750let plainText: string = pasteData.getPrimaryText();
751```
752
753### getPrimaryHtml<sup>7+</sup>
754
755getPrimaryHtml(): string
756
757Obtains the HTML content of the primary record.
758
759**Atomic service API**: This API can be used in atomic services since API version 11.
760
761**System capability**: SystemCapability.MiscServices.Pasteboard
762
763**Return value**
764
765| Type| Description|
766| -------- | -------- |
767| string | HTML content.|
768
769**Example**
770
771```ts
772let html = "<!DOCTYPE html>\n" + "<html>\n" + "<head>\n" + "<meta charset=\"utf-8\">\n" + "<title>HTML-PASTEBOARD_HTML</title>\n" + "</head>\n" + "<body>\n" + "    <h1>HEAD</h1>\n" + "    <p></p>\n" + "</body>\n" + "</html>";
773let pasteData: pasteboard.PasteData = pasteboard.createData(pasteboard.MIMETYPE_TEXT_HTML, html);
774let htmlText: string = pasteData.getPrimaryHtml();
775```
776
777### getPrimaryWant<sup>7+</sup>
778
779getPrimaryWant(): Want
780
781Obtains the Want object of the primary record.
782
783**Atomic service API**: This API can be used in atomic services since API version 11.
784
785**System capability**: SystemCapability.MiscServices.Pasteboard
786
787**Return value**
788
789| Type| Description|
790| -------- | -------- |
791| [Want](../apis-ability-kit/js-apis-app-ability-want.md) | Want object.|
792
793**Example**
794
795```ts
796import { Want } from '@kit.AbilityKit';
797
798let object: Want = {
799    bundleName: "com.example.aafwk.test",
800    abilityName: "com.example.aafwk.test.TwoAbility"
801};
802let pasteData: pasteboard.PasteData = pasteboard.createData(pasteboard.MIMETYPE_TEXT_WANT, object);
803let want: Want = pasteData.getPrimaryWant();
804```
805
806### getPrimaryUri<sup>7+</sup>
807
808getPrimaryUri(): string
809
810Obtains the URI of the primary record.
811
812**Atomic service API**: This API can be used in atomic services since API version 11.
813
814**System capability**: SystemCapability.MiscServices.Pasteboard
815
816**Return value**
817
818| Type| Description|
819| -------- | -------- |
820| string | URI content.|
821
822**Example**
823
824```ts
825let pasteData: pasteboard.PasteData = pasteboard.createData(pasteboard.MIMETYPE_TEXT_URI, 'dataability:///com.example.myapplication1/user.txt');
826let uri: string = pasteData.getPrimaryUri();
827```
828
829### getPrimaryPixelMap<sup>9+</sup>
830
831getPrimaryPixelMap(): image.PixelMap
832
833Obtains the pixel map of the primary record.
834
835**Atomic service API**: This API can be used in atomic services since API version 11.
836
837**System capability**: SystemCapability.MiscServices.Pasteboard
838
839**Return value**
840
841| Type| Description|
842| -------- | -------- |
843| [image.PixelMap](../apis-image-kit/js-apis-image.md#pixelmap7) | Pixel map.|
844
845**Example**
846
847```ts
848import { image } from '@kit.ImageKit';
849
850let buffer = new ArrayBuffer(128);
851let realSize: image.Size = { height: 3, width: 5 };
852let opt: image.InitializationOptions = {
853    size: realSize,
854    pixelFormat: 3,
855    editable: true,
856    alphaType: 1,
857    scaleMode: 1
858};
859image.createPixelMap(buffer, opt).then((pixelMap: image.PixelMap) => {
860    let pasteData: pasteboard.PasteData = pasteboard.createData(pasteboard.MIMETYPE_PIXELMAP, pixelMap);
861    let PixelMap: image.PixelMap = pasteData.getPrimaryPixelMap();
862});
863```
864
865### addRecord<sup>7+</sup>
866
867addRecord(record: PasteDataRecord): void
868
869Adds a data record to this pasteboard, and adds its type to **mimeTypes** in [PasteDataProperty](#pastedataproperty7). The parameters cannot be empty. Otherwise, the operation fails.
870
871**Atomic service API**: This API can be used in atomic services since API version 11.
872
873**System capability**: SystemCapability.MiscServices.Pasteboard
874
875**Parameters**
876
877| Name| Type| Mandatory| Description|
878| -------- | -------- | -------- | -------- |
879| record | [PasteDataRecord](#pastedatarecord7) | Yes| Record to add.|
880
881**Example**
882
883```ts
884let pasteData: pasteboard.PasteData = pasteboard.createData(pasteboard.MIMETYPE_TEXT_URI, 'dataability:///com.example.myapplication1/user.txt');
885let textRecord: pasteboard.PasteDataRecord = pasteboard.createRecord(pasteboard.MIMETYPE_TEXT_PLAIN, 'hello');
886let html: string = "<!DOCTYPE html>\n" + "<html>\n" + "<head>\n" + "<meta charset=\"utf-8\">\n" + "<title>HTML-PASTEBOARD_HTML</title>\n" + "</head>\n" + "<body>\n" + "    <h1>HEAD</h1>\n" + "    <p></p>\n" + "</body>\n" + "</html>";
887let htmlRecord: pasteboard.PasteDataRecord = pasteboard.createRecord(pasteboard.MIMETYPE_TEXT_HTML, html);
888pasteData.addRecord(textRecord);
889pasteData.addRecord(htmlRecord);
890```
891### addRecord<sup>9+</sup>
892
893addRecord(mimeType: string, value: ValueType): void
894
895Adds a custom-type record to this pasteboard, and adds the custom type to **mimeTypes** in [PasteDataProperty](#pastedataproperty7). The parameters cannot be empty. Otherwise, the operation fails.
896
897**Atomic service API**: This API can be used in atomic services since API version 11.
898
899**System capability**: SystemCapability.MiscServices.Pasteboard
900
901**Parameters**
902
903| Name| Type| Mandatory| Description|
904| -------- | -------- | -------- | -------- |
905| mimeType | string | Yes| MIME type of custom data. The length cannot exceed 1024 bytes.|
906| value | [ValueType](#valuetype9) | Yes| Content of custom data.|
907
908**Error codes**
909
910For details about the error codes, see [Universal Error Codes](../errorcode-universal.md) and [Pasteboard Error Codes](errorcode-pasteboard.md).
911
912| Error Code ID| Error Message|
913| -------- | -------- |
914| 401      | Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameters types; 3. Parameter verification failed. |
915
916**Example**
917
918  ```ts
919  let pasteData: pasteboard.PasteData = pasteboard.createData(pasteboard.MIMETYPE_TEXT_URI, 'dataability:///com.example.myapplication1/user.txt');
920  let dataXml = new ArrayBuffer(256);
921  pasteData.addRecord('app/xml', dataXml);
922  ```
923
924### getMimeTypes<sup>7+</sup>
925
926getMimeTypes(): Array&lt;string&gt;
927
928Obtains a list of **mimeTypes** objects in [PasteDataProperty](#pastedataproperty7) from this pasteboard. If the pasteboard is empty, the returned list is also empty.
929
930**Atomic service API**: This API can be used in atomic services since API version 11.
931
932**System capability**: SystemCapability.MiscServices.Pasteboard
933
934**Return value**
935
936| Type| Description|
937| -------- | -------- |
938| Array&lt;string&gt; | Non-repeating data types of the data records on the pasteboard.|
939
940**Example**
941
942```ts
943let pasteData: pasteboard.PasteData = pasteboard.createData(pasteboard.MIMETYPE_TEXT_PLAIN, 'hello');
944let types: string[] = pasteData.getMimeTypes();
945```
946
947### getPrimaryMimeType<sup>7+</sup>
948
949getPrimaryMimeType(): string
950
951Obtains the data type of the primary record in this pasteboard.
952
953**Atomic service API**: This API can be used in atomic services since API version 11.
954
955**System capability**: SystemCapability.MiscServices.Pasteboard
956
957**Return value**
958
959| Type| Description|
960| -------- | -------- |
961| string | Data type of the primary record.|
962
963**Example**
964
965```ts
966let pasteData: pasteboard.PasteData = pasteboard.createData(pasteboard.MIMETYPE_TEXT_PLAIN, 'hello');
967let type: string = pasteData.getPrimaryMimeType();
968```
969
970### getProperty<sup>7+</sup>
971
972getProperty(): PasteDataProperty
973
974Obtains the property of the pasteboard data.
975
976**Atomic service API**: This API can be used in atomic services since API version 11.
977
978**System capability**: SystemCapability.MiscServices.Pasteboard
979
980**Return value**
981
982| Type| Description|
983| -------- | -------- |
984| [PasteDataProperty](#pastedataproperty7) | Property of the pasteboard data.|
985
986**Example**
987
988```ts
989let pasteData: pasteboard.PasteData = pasteboard.createData(pasteboard.MIMETYPE_TEXT_PLAIN, 'hello');
990let property: pasteboard.PasteDataProperty = pasteData.getProperty();
991```
992
993### setProperty<sup>9+</sup>
994
995setProperty(property: PasteDataProperty): void
996
997Sets a [PasteDataProperty](#pastedataproperty7) object.
998
999**Atomic service API**: This API can be used in atomic services since API version 11.
1000
1001**System capability**: SystemCapability.MiscServices.Pasteboard
1002
1003**Parameters**
1004
1005| Name| Type| Mandatory| Description|
1006| -------- | -------- | -------- | -------- |
1007| property | [PasteDataProperty](#pastedataproperty7) | Yes| Property of the pasteboard data.|
1008
1009**Error codes**
1010
1011For details about the error codes, see [Universal Error Codes](../errorcode-universal.md).
1012
1013| Error Code ID| Error Message|
1014| -------- | -------- |
1015| 401      | Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameters types. |
1016
1017**Example**
1018
1019```ts
1020type AdditionType = Record<string, Record<string, Object>>;
1021
1022let pasteData: pasteboard.PasteData = pasteboard.createData(pasteboard.MIMETYPE_TEXT_HTML, 'application/xml');
1023let prop: pasteboard.PasteDataProperty = pasteData.getProperty();
1024prop.shareOption = pasteboard.ShareOption.INAPP;
1025// Note that attributes cannot be added to additions. Attributes can be added only by re-assigning values.
1026prop.additions = { 'TestOne': { 'Test': 123 }, 'TestTwo': { 'Test': 'additions' } } as AdditionType;
1027prop.tag = 'TestTag';
1028pasteData.setProperty(prop);
1029```
1030The **localOnly** and **shareOption** attributes of [PasteDataProperty](#pastedataproperty7) are mutually exclusive. The **shareOption** attribute is prioritized, and its value affects the value of **localOnly**.
1031```ts
1032(async () => {
1033    let pasteData: pasteboard.PasteData = pasteboard.createData(pasteboard.MIMETYPE_TEXT_PLAIN, 'hello');
1034    let prop: pasteboard.PasteDataProperty = pasteData.getProperty();
1035    prop.shareOption = pasteboard.ShareOption.INAPP;
1036    prop.localOnly = false;
1037    pasteData.setProperty(prop);
1038    let systemPasteboard: pasteboard.SystemPasteboard = pasteboard.getSystemPasteboard();
1039
1040    await systemPasteboard.setData(pasteData).then(async () => {
1041        console.info('Succeeded in setting PasteData.');
1042        await systemPasteboard.getData().then((pasteData: pasteboard.PasteData) => {
1043            let prop: pasteboard.PasteDataProperty = pasteData.getProperty();
1044            prop.localOnly; // true
1045        });
1046    });
1047
1048    prop.shareOption = pasteboard.ShareOption.LOCALDEVICE;
1049    prop.localOnly = false;
1050    pasteData.setProperty(prop);
1051
1052    await systemPasteboard.setData(pasteData).then(async () => {
1053        console.info('Succeeded in setting PasteData.');
1054        await systemPasteboard.getData().then((pasteData: pasteboard.PasteData) => {
1055            let prop: pasteboard.PasteDataProperty = pasteData.getProperty();
1056            prop.localOnly; // true
1057        });
1058    });
1059
1060    prop.shareOption = pasteboard.ShareOption.CROSSDEVICE;
1061    prop.localOnly = true;
1062    pasteData.setProperty(prop);
1063
1064    await systemPasteboard.setData(pasteData).then(async () => {
1065        console.info('Succeeded in setting PasteData.');
1066        await systemPasteboard.getData().then((pasteData: pasteboard.PasteData) => {
1067            let prop: pasteboard.PasteDataProperty = pasteData.getProperty();
1068            prop.localOnly; // false
1069        });
1070    });
1071})()
1072```
1073
1074### getRecord<sup>9+</sup>
1075
1076getRecord(index: number): PasteDataRecord
1077
1078Obtains the record with a specific index from the pasteboard.
1079
1080**Atomic service API**: This API can be used in atomic services since API version 11.
1081
1082**System capability**: SystemCapability.MiscServices.Pasteboard
1083
1084**Parameters**
1085
1086| Name| Type| Mandatory| Description|
1087| -------- | -------- | -------- | -------- |
1088| index | number | Yes| Index of the target record.|
1089
1090**Return value**
1091
1092| Type| Description|
1093| -------- | -------- |
1094| [PasteDataRecord](#pastedatarecord7) | Record with the specified index.|
1095
1096**Error codes**
1097
1098For details about the error codes, see [Universal Error Codes](../errorcode-universal.md) and [Pasteboard Error Codes](errorcode-pasteboard.md).
1099
1100| Error Code ID| Error Message|
1101| -------- | -------- |
1102| 12900001 | The index is out of the record. |
1103| 401      | Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameters types. |
1104
1105**Example**
1106
1107```ts
1108let pasteData: pasteboard.PasteData = pasteboard.createData(pasteboard.MIMETYPE_TEXT_PLAIN, 'hello');
1109let record: pasteboard.PasteDataRecord = pasteData.getRecord(0);
1110```
1111
1112### getRecordCount<sup>7+</sup>
1113
1114getRecordCount(): number
1115
1116Obtains the number of records in the pasteboard.
1117
1118**Atomic service API**: This API can be used in atomic services since API version 11.
1119
1120**System capability**: SystemCapability.MiscServices.Pasteboard
1121
1122**Return value**
1123
1124| Type| Description|
1125| -------- | -------- |
1126| number | Number of records.|
1127
1128**Example**
1129
1130```ts
1131let pasteData: pasteboard.PasteData = pasteboard.createData(pasteboard.MIMETYPE_TEXT_PLAIN, 'hello');
1132let count: number = pasteData.getRecordCount();
1133```
1134
1135### getTag<sup>7+</sup>
1136
1137getTag(): string
1138
1139Obtains the custom tag from the pasteboard. If no custom tag is set, null is returned.
1140
1141**Atomic service API**: This API can be used in atomic services since API version 11.
1142
1143**System capability**: SystemCapability.MiscServices.Pasteboard
1144
1145**Return value**
1146
1147| Type| Description|
1148| -------- | -------- |
1149| string | Custom tag. If no custom tag is set, null is returned.|
1150
1151**Example**
1152
1153```ts
1154let pasteData: pasteboard.PasteData = pasteboard.createData(pasteboard.MIMETYPE_TEXT_PLAIN, 'hello');
1155let tag: string = pasteData.getTag();
1156```
1157
1158### hasType<sup>9+</sup>
1159
1160hasType(mimeType: string): boolean
1161
1162Checks whether the pasteboard contains data of the specified type.
1163
1164**Atomic service API**: This API can be used in atomic services since API version 11.
1165
1166**System capability**: SystemCapability.MiscServices.Pasteboard
1167
1168**Parameters**
1169
1170| Name| Type| Mandatory| Description|
1171| -------- | -------- | -------- | -------- |
1172| mimeType | string | Yes| Type of the data to query.|
1173
1174**Return value**
1175
1176| Type| Description|
1177| -------- | -------- |
1178| boolean | Returns **true** if the specified data type exists; returns **false** otherwise.|
1179
1180**Error codes**
1181
1182For details about the error codes, see [Universal Error Codes](../errorcode-universal.md).
1183
1184| Error Code ID| Error Message|
1185| -------- | -------- |
1186| 401      | Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameters types. |
1187
1188**Example**
1189
1190```ts
1191let pasteData: pasteboard.PasteData = pasteboard.createData(pasteboard.MIMETYPE_TEXT_PLAIN, 'hello');
1192let hasType: boolean = pasteData.hasType(pasteboard.MIMETYPE_TEXT_PLAIN);
1193```
1194
1195### removeRecord<sup>9+</sup>
1196
1197removeRecord(index: number): void
1198
1199Removes the record with a specific index from the pasteboard.
1200
1201**Atomic service API**: This API can be used in atomic services since API version 11.
1202
1203**System capability**: SystemCapability.MiscServices.Pasteboard
1204
1205**Parameters**
1206
1207| Name| Type| Mandatory| Description|
1208| -------- | -------- | -------- | -------- |
1209| index | number | Yes| Specified index.|
1210
1211**Error codes**
1212
1213For details about the error codes, see [Universal Error Codes](../errorcode-universal.md) and [Pasteboard Error Codes](errorcode-pasteboard.md).
1214
1215| Error Code ID| Error Message|
1216| -------- | -------- |
1217| 12900001 | The index is out of the record. |
1218| 401      | Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameters types. |
1219
1220**Example**
1221
1222```ts
1223let pasteData: pasteboard.PasteData = pasteboard.createData(pasteboard.MIMETYPE_TEXT_PLAIN, 'hello');
1224pasteData.removeRecord(0);
1225```
1226
1227### replaceRecord<sup>9+</sup>
1228
1229replaceRecord(index: number, record: PasteDataRecord): void
1230
1231Replaces the record with a specific index from the pasteboard.
1232
1233**Atomic service API**: This API can be used in atomic services since API version 11.
1234
1235**System capability**: SystemCapability.MiscServices.Pasteboard
1236
1237**Parameters**
1238
1239| Name| Type| Mandatory| Description|
1240| -------- | -------- | -------- | -------- |
1241| index | number | Yes| Specified index.|
1242| record | [PasteDataRecord](#pastedatarecord7) | Yes| New record.|
1243
1244**Error codes**
1245
1246For details about the error codes, see [Universal Error Codes](../errorcode-universal.md) and [Pasteboard Error Codes](errorcode-pasteboard.md).
1247
1248| Error Code ID| Error Message|
1249| -------- | -------- |
1250| 12900001 | The index is out of the record. |
1251| 401      | Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameters types. |
1252
1253**Example**
1254
1255```ts
1256let pasteData: pasteboard.PasteData = pasteboard.createData(pasteboard.MIMETYPE_TEXT_PLAIN, 'hello');
1257let record: pasteboard.PasteDataRecord = pasteboard.createRecord(pasteboard.MIMETYPE_TEXT_URI, 'dataability:///com.example.myapplication1/user.txt');
1258pasteData.replaceRecord(0, record);
1259```
1260
1261### pasteStart<sup>12+</sup>
1262
1263pasteStart(): void
1264
1265Notifies the clipboard service to retain the cross-device channel before reading data from the clipboard.
1266
1267**System capability**: SystemCapability.MiscServices.Pasteboard
1268
1269**Example**
1270
1271```ts
1272import { BusinessError } from '@kit.BasicServicesKit';
1273
1274let systemPasteboard: pasteboard.SystemPasteboard = pasteboard.getSystemPasteboard();
1275systemPasteboard.getData((err: BusinessError, pasteData: pasteboard.PasteData) => {
1276    if (err) {
1277        console.error('Failed to get PasteData. Cause: ' + err.message);
1278        return;
1279    }
1280    pasteData.pasteStart();
1281    console.log(`using data: ${pasteData.getPrimaryText()}`);
1282    pasteData.pasteComplete();
1283});
1284```
1285
1286### pasteComplete<sup>12+</sup>
1287
1288pasteComplete(): void
1289
1290Notifies the clipboard service that the paste is complete.
1291
1292**System capability**: SystemCapability.MiscServices.Pasteboard
1293
1294**Example**
1295
1296```ts
1297import { BusinessError } from '@kit.BasicServicesKit';
1298
1299let systemPasteboard: pasteboard.SystemPasteboard = pasteboard.getSystemPasteboard();
1300systemPasteboard.getData((err: BusinessError, pasteData: pasteboard.PasteData) => {
1301    if (err) {
1302        console.error('Failed to get PasteData. Cause: ' + err.message);
1303        return;
1304    }
1305    pasteData.pasteStart();
1306    console.log(`using data: ${pasteData.getPrimaryText()}`);
1307    pasteData.pasteComplete();
1308});
1309```
1310
1311### addHtmlRecord<sup>(deprecated)</sup>
1312
1313addHtmlRecord(htmlText: string): void
1314
1315Adds an HTML record to this pasteboard, and adds **MIMETYPE_TEXT_HTML** to **mimeTypes** in [PasteDataProperty](#pastedataproperty7). The parameters cannot be empty. Otherwise, the operation fails.
1316
1317> **NOTE**
1318>
1319> This API is supported since API version 7 and deprecated since API version 9. You are advised to use [addRecord](#addrecord9).
1320
1321**System capability**: SystemCapability.MiscServices.Pasteboard
1322
1323**Parameters**
1324
1325| Name| Type| Mandatory| Description|
1326| -------- | -------- | -------- | -------- |
1327| htmlText | string | Yes| HTML content.|
1328
1329**Example**
1330
1331```ts
1332let pasteData: pasteboard.PasteData = pasteboard.createPlainTextData('hello');
1333let html: string = "<!DOCTYPE html>\n" + "<html>\n" + "<head>\n" + "<meta charset=\"utf-8\">\n" + "<title>HTML-PASTEBOARD_HTML</title>\n" + "</head>\n" + "<body>\n" + "    <h1>HEAD</h1>\n" + "    <p></p>\n" + "</body>\n" + "</html>";
1334pasteData.addHtmlRecord(html);
1335```
1336
1337### addWantRecord<sup>(deprecated)</sup>
1338
1339addWantRecord(want: Want): void
1340
1341Adds a Want record to this pasteboard, and adds **MIMETYPE_TEXT_WANT** to **mimeTypes** in [PasteDataProperty](#pastedataproperty7). The parameters cannot be empty. Otherwise, the operation fails.
1342
1343> **NOTE**
1344>
1345> This API is supported since API version 7 and deprecated since API version 9. You are advised to use [addRecord](#addrecord9).
1346
1347**System capability**: SystemCapability.MiscServices.Pasteboard
1348
1349**Parameters**
1350
1351| Name| Type| Mandatory| Description|
1352| -------- | -------- | -------- | -------- |
1353| want | [Want](../apis-ability-kit/js-apis-app-ability-want.md) | Yes| Want object.|
1354
1355**Example**
1356
1357```ts
1358import { Want } from '@kit.AbilityKit';
1359
1360let pasteData: pasteboard.PasteData = pasteboard.createPlainTextData('hello');
1361let object: Want = {
1362    bundleName: "com.example.aafwk.test",
1363    abilityName: "com.example.aafwk.test.TwoAbility"
1364};
1365pasteData.addWantRecord(object);
1366```
1367
1368### addTextRecord<sup>(deprecated)</sup>
1369
1370addTextRecord(text: string): void
1371
1372Adds a plain text record to this pasteboard, and adds **MIME_TEXT_PLAIN** to **mimeTypes** in [PasteDataProperty](#pastedataproperty7). The parameters cannot be empty. Otherwise, the operation fails.
1373
1374> **NOTE**
1375>
1376> This API is supported since API version 7 and deprecated since API version 9. You are advised to use [addRecord](#addrecord9).
1377
1378**System capability**: SystemCapability.MiscServices.Pasteboard
1379
1380**Parameters**
1381
1382| Name| Type| Mandatory| Description|
1383| -------- | -------- | -------- | -------- |
1384| text | string | Yes| Plain text.|
1385
1386**Example**
1387
1388```ts
1389let pasteData: pasteboard.PasteData = pasteboard.createPlainTextData('hello');
1390pasteData.addTextRecord('good');
1391```
1392
1393### addUriRecord<sup>(deprecated)</sup>
1394
1395addUriRecord(uri: string): void
1396
1397Adds a URI record to this pasteboard, and adds **MIMETYPE_TEXT_URI** to **mimeTypes** in [PasteDataProperty](#pastedataproperty7). The parameters cannot be empty. Otherwise, the operation fails.
1398
1399> **NOTE**
1400>
1401> This API is supported since API version 7 and deprecated since API version 9. You are advised to use [addRecord](#addrecord9).
1402
1403**System capability**: SystemCapability.MiscServices.Pasteboard
1404
1405**Parameters**
1406
1407| Name| Type| Mandatory| Description|
1408| -------- | -------- | -------- | -------- |
1409| uri | string | Yes| URI content.|
1410
1411**Example**
1412
1413```ts
1414let pasteData: pasteboard.PasteData = pasteboard.createPlainTextData('hello');
1415pasteData.addUriRecord('dataability:///com.example.myapplication1/user.txt');
1416```
1417### getRecordAt<sup>(deprecated)</sup>
1418
1419getRecordAt(index: number): PasteDataRecord
1420
1421Obtains the record with a specific index from the pasteboard.
1422> **NOTE**
1423>
1424> This API is supported since API version 7 and deprecated since API version 9. You are advised to use [getRecord](#getrecord9).
1425
1426**System capability**: SystemCapability.MiscServices.Pasteboard
1427
1428**Parameters**
1429
1430| Name| Type| Mandatory| Description|
1431| -------- | -------- | -------- | -------- |
1432| index | number | Yes| Index of the target record.|
1433
1434**Return value**
1435
1436| Type| Description|
1437| -------- | -------- |
1438| [PasteDataRecord](#pastedatarecord7) | Record with the specified index.|
1439
1440**Error codes**
1441
1442For details about the error codes, see [Universal Error Codes](../errorcode-universal.md).
1443
1444| Error Code ID| Error Message|
1445| -------- | -------- |
1446| 401      | Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameters types. |
1447
1448**Example**
1449
1450```ts
1451let pasteData: pasteboard.PasteData = pasteboard.createPlainTextData('hello');
1452let record: pasteboard.PasteDataRecord = pasteData.getRecordAt(0);
1453```
1454
1455### hasMimeType<sup>(deprecated)</sup>
1456
1457hasMimeType(mimeType: string): boolean
1458
1459Checks whether the pasteboard contains data of the specified type.
1460> **NOTE**
1461>
1462> This API is supported since API version 7 and deprecated since API version 9. You are advised to use [hasType](#hastype9).
1463
1464**System capability**: SystemCapability.MiscServices.Pasteboard
1465
1466**Parameters**
1467
1468| Name| Type| Mandatory| Description|
1469| -------- | -------- | -------- | -------- |
1470| mimeType | string | Yes| Type of the data to query.|
1471
1472**Return value**
1473
1474| Type| Description|
1475| -------- | -------- |
1476| boolean | Returns **true** if the specified data type exists; returns **false** otherwise.|
1477
1478**Error codes**
1479
1480For details about the error codes, see [Universal Error Codes](../errorcode-universal.md).
1481
1482| Error Code ID| Error Message|
1483| -------- | -------- |
1484| 401      | Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameters types. |
1485
1486**Example**
1487
1488```ts
1489let pasteData: pasteboard.PasteData = pasteboard.createPlainTextData('hello');
1490let hasType: boolean = pasteData.hasMimeType(pasteboard.MIMETYPE_TEXT_PLAIN);
1491```
1492### removeRecordAt<sup>(deprecated)</sup>
1493
1494removeRecordAt(index: number): boolean
1495
1496Removes the record with a specific index from the pasteboard.
1497> **NOTE**
1498>
1499> This API is supported since API version 7 and deprecated since API version 9. You are advised to use [removeRecord](#removerecord9).
1500
1501**System capability**: SystemCapability.MiscServices.Pasteboard
1502
1503**Parameters**
1504
1505| Name| Type| Mandatory| Description|
1506| -------- | -------- | -------- | -------- |
1507| index | number | Yes| Specified index.|
1508
1509**Return value**
1510
1511| Type| Description|
1512| -------- | -------- |
1513| boolean | Returns **true** if the operation is successful; returns **false** otherwise.|
1514
1515**Error codes**
1516
1517For details about the error codes, see [Universal Error Codes](../errorcode-universal.md).
1518
1519| Error Code ID| Error Message|
1520| -------- | -------- |
1521| 401      | Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameters types. |
1522
1523**Example**
1524
1525```ts
1526let pasteData: pasteboard.PasteData = pasteboard.createPlainTextData('hello');
1527let isRemove: boolean = pasteData.removeRecordAt(0);
1528```
1529### replaceRecordAt<sup>(deprecated)</sup>
1530
1531replaceRecordAt(index: number, record: PasteDataRecord): boolean
1532
1533Replaces the record with a specific index from the pasteboard.
1534> **NOTE**
1535>
1536> This API is supported since API version 7 and deprecated since API version 9. You are advised to use [replaceRecord](#replacerecord9).
1537
1538**System capability**: SystemCapability.MiscServices.Pasteboard
1539
1540**Parameters**
1541
1542| Name| Type| Mandatory| Description|
1543| -------- | -------- | -------- | -------- |
1544| index | number | Yes| Specified index.|
1545| record | [PasteDataRecord](#pastedatarecord7) | Yes| New record.|
1546
1547**Return value**
1548
1549| Type| Description|
1550| -------- | -------- |
1551| boolean | Returns **true** if the operation is successful; returns **false** otherwise.|
1552
1553**Example**
1554
1555```ts
1556let pasteData: pasteboard.PasteData = pasteboard.createPlainTextData('hello');
1557let record: pasteboard.PasteDataRecord = pasteboard.createUriRecord('dataability:///com.example.myapplication1/user.txt');
1558let isReplace: boolean = pasteData.replaceRecordAt(0, record);
1559```
1560
1561## SystemPasteboard
1562
1563Provides **SystemPasteboard** APIs.
1564
1565Before calling any **SystemPasteboard** API, you must obtain a **SystemPasteboard** object using [getSystemPasteboard](#pasteboardgetsystempasteboard).
1566
1567```ts
1568let systemPasteboard: pasteboard.SystemPasteboard = pasteboard.getSystemPasteboard();
1569```
1570
1571### on('update')<sup>7+</sup>
1572
1573on(type:  'update', callback: () =&gt;void ): void
1574
1575Subscribes to the content change event of the system pasteboard.
1576
1577**System capability**: SystemCapability.MiscServices.Pasteboard
1578
1579**Parameters**
1580
1581| Name| Type| Mandatory| Description|
1582| -------- | -------- | -------- | -------- |
1583| type | string | Yes| Event type. The value **'update'** indicates changes in the pasteboard content.|
1584| callback | function | Yes| Callback invoked when the pasteboard content changes.|
1585
1586**Error codes**
1587
1588For details about the error codes, see [Universal Error Codes](../errorcode-universal.md).
1589
1590| Error Code ID| Error Message|
1591| -------- | -------- |
1592| 401      | Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameters types. |
1593
1594**Example**
1595
1596```ts
1597let systemPasteboard: pasteboard.SystemPasteboard = pasteboard.getSystemPasteboard();
1598let listener = () => {
1599    console.info('The system pasteboard has changed.');
1600};
1601systemPasteboard.on('update', listener);
1602```
1603
1604### off('update')<sup>7+</sup>
1605
1606off(type:  'update', callback?: () =&gt;void ): void
1607
1608Unsubscribes from the system pasteboard content change event.
1609
1610**System capability**: SystemCapability.MiscServices.Pasteboard
1611
1612**Parameters**
1613
1614| Name| Type| Mandatory| Description                                                     |
1615| -------- | -------- | -------- |---------------------------------------------------------|
1616| type | string | Yes| Event type. The value **'update'** indicates changes in the pasteboard content.                             |
1617| callback | function | No| Callback invoked when the pasteboard content changes. If this parameter is not specified, listening will be disabled for all callbacks registered by the current application.|
1618
1619**Error codes**
1620
1621For details about the error codes, see [Universal Error Codes](../errorcode-universal.md).
1622
1623| Error Code ID| Error Message|
1624| -------- | -------- |
1625| 401      | Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameters types. |
1626
1627**Example**
1628
1629```ts
1630let systemPasteboard: pasteboard.SystemPasteboard = pasteboard.getSystemPasteboard();
1631let listener = () => {
1632    console.info('The system pasteboard has changed.');
1633};
1634systemPasteboard.off('update', listener);
1635```
1636
1637### clearData<sup>9+</sup>
1638
1639clearData(callback: AsyncCallback&lt;void&gt;): void
1640
1641Clears the system pasteboard. This API uses an asynchronous callback to return the result.
1642
1643**Atomic service API**: This API can be used in atomic services since API version 11.
1644
1645**System capability**: SystemCapability.MiscServices.Pasteboard
1646
1647**Parameters**
1648
1649| Name| Type| Mandatory| Description|
1650| -------- | -------- | -------- | -------- |
1651| callback | AsyncCallback&lt;void&gt; | Yes| Callback used to return the result. If the operation is successful, **err** is **undefined**; otherwise, **err** is an error object.|
1652
1653**Error codes**
1654
1655For details about the error codes, see [Universal Error Codes](../errorcode-universal.md).
1656
1657| Error Code ID| Error Message|
1658| -------- | -------- |
1659| 401      | Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameters types. |
1660
1661**Example**
1662
1663```ts
1664let systemPasteboard: pasteboard.SystemPasteboard = pasteboard.getSystemPasteboard();
1665systemPasteboard.clearData((err, data) => {
1666    if (err) {
1667        console.error(`Failed to clear the pasteboard. Cause: ${err.message}`);
1668        return;
1669    }
1670    console.info('Succeeded in clearing the pasteboard.');
1671});
1672```
1673
1674### clearData<sup>9+</sup>
1675
1676clearData(): Promise&lt;void&gt;
1677
1678Clears the system pasteboard. This API uses a promise to return the result.
1679
1680**Atomic service API**: This API can be used in atomic services since API version 11.
1681
1682**System capability**: SystemCapability.MiscServices.Pasteboard
1683
1684**Return value**
1685
1686| Type| Description|
1687| -------- | -------- |
1688| Promise&lt;void&gt; | Promise that returns no value.|
1689
1690**Example**
1691
1692```ts
1693import { BusinessError } from '@kit.BasicServicesKit';
1694
1695let systemPasteboard: pasteboard.SystemPasteboard = pasteboard.getSystemPasteboard();
1696systemPasteboard.clearData().then((data: void) => {
1697    console.info('Succeeded in clearing the pasteboard.');
1698}).catch((err: BusinessError) => {
1699    console.error(`Failed to clear the pasteboard. Cause: ${err.message}`);
1700});
1701```
1702
1703### setData<sup>9+</sup>
1704
1705setData(data: PasteData, callback: AsyncCallback&lt;void&gt;): void
1706
1707Writes a **PasteData** object to the pasteboard. This API uses an asynchronous callback to return the result.
1708
1709**Atomic service API**: This API can be used in atomic services since API version 11.
1710
1711**System capability**: SystemCapability.MiscServices.Pasteboard
1712
1713**Parameters**
1714
1715| Name| Type| Mandatory| Description|
1716| -------- | -------- | -------- | -------- |
1717| data | [PasteData](#pastedata) | Yes| **PasteData** object.|
1718| callback | AsyncCallback&lt;void> | Yes| Callback used to return the result. If the operation is successful, **err** is **undefined**; otherwise, **err** is an error object.|
1719
1720**Error codes**
1721
1722For details about the error codes, see [Universal Error Codes](../errorcode-universal.md) and [Pasteboard Error Codes](errorcode-pasteboard.md).
1723
1724| Error Code ID| Error Message|
1725| -------- | -------- |
1726| 12900003 | Another copy or paste operation is in progress. |
1727| 12900004 | Replication is prohibited. |
1728| 401      | Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameters types. |
1729
1730**Example**
1731
1732```ts
1733let pasteData: pasteboard.PasteData = pasteboard.createData(pasteboard.MIMETYPE_TEXT_PLAIN, 'content');
1734let systemPasteboard: pasteboard.SystemPasteboard = pasteboard.getSystemPasteboard();
1735systemPasteboard.setData(pasteData, (err, data) => {
1736    if (err) {
1737        console.error('Failed to set PasteData. Cause: ' + err.message);
1738        return;
1739    }
1740    console.info('Succeeded in setting PasteData.');
1741});
1742```
1743
1744### setData<sup>9+</sup>
1745
1746setData(data: PasteData): Promise&lt;void&gt;
1747
1748Writes a **PasteData** object to the pasteboard. This API uses a promise to return the result.
1749
1750**Atomic service API**: This API can be used in atomic services since API version 11.
1751
1752**System capability**: SystemCapability.MiscServices.Pasteboard
1753
1754**Parameters**
1755
1756| Name| Type| Mandatory| Description|
1757| -------- | -------- | -------- | -------- |
1758| data | [PasteData](#pastedata) | Yes| **PasteData** object.|
1759
1760**Return value**
1761
1762| Type| Description|
1763| -------- | -------- |
1764| Promise&lt;void&gt; | Promise that returns no value.|
1765
1766**Error codes**
1767
1768For details about the error codes, see [Universal Error Codes](../errorcode-universal.md) and [Pasteboard Error Codes](errorcode-pasteboard.md).
1769
1770| Error Code ID| Error Message|
1771| -------- | -------- |
1772| 12900003 | Another copy or paste operation is in progress. |
1773| 12900004 | Replication is prohibited. |
1774| 401      | Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameters types. |
1775
1776**Example**
1777
1778```ts
1779import { BusinessError } from '@kit.BasicServicesKit';
1780
1781let pasteData: pasteboard.PasteData = pasteboard.createData(pasteboard.MIMETYPE_TEXT_PLAIN, 'content');
1782let systemPasteboard: pasteboard.SystemPasteboard = pasteboard.getSystemPasteboard();
1783systemPasteboard.setData(pasteData).then((data: void) => {
1784    console.info('Succeeded in setting PasteData.');
1785}).catch((err: BusinessError) => {
1786    console.error('Failed to set PasteData. Cause: ' + err.message);
1787});
1788```
1789
1790### getData<sup>9+</sup>
1791
1792getData( callback: AsyncCallback&lt;PasteData&gt;): void
1793
1794Obtains a **PasteData** object from the pasteboard. This API uses an asynchronous callback to return the result.
1795
1796**Required permissions**: ohos.permission.READ_PASTEBOARD
1797
1798**Atomic service API**: This API can be used in atomic services since API version 11.
1799
1800**System capability**: SystemCapability.MiscServices.Pasteboard
1801
1802**Parameters**
1803
1804| Name| Type| Mandatory| Description|
1805| -------- | -------- | -------- | -------- |
1806| callback | AsyncCallback&lt;[PasteData](#pastedata)&gt; | Yes| Callback used to return the result. If the operation is successful, **err** is **undefined** and **data** is the system pasteboard data. Otherwise, **err** is an error object.|
1807
1808**Error codes**
1809
1810For details about the error codes, see [Universal Error Codes](../errorcode-universal.md) and [Pasteboard Error Codes](errorcode-pasteboard.md).
1811
1812| Error Code ID| Error Message|
1813| -------- | -------- |
1814| 12900003 | Another copy or paste operation is in progress. |
1815| 201      | Permission verification failed. The application does not have the permission required to call the API. |
1816| 401      | Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameters types. |
1817
1818**Example**
1819
1820```ts
1821import { BusinessError } from '@kit.BasicServicesKit';
1822
1823let systemPasteboard: pasteboard.SystemPasteboard = pasteboard.getSystemPasteboard();
1824systemPasteboard.getData((err: BusinessError, pasteData: pasteboard.PasteData) => {
1825    if (err) {
1826        console.error('Failed to get PasteData. Cause: ' + err.message);
1827        return;
1828    }
1829    let text: string = pasteData.getPrimaryText();
1830});
1831```
1832
1833### getData<sup>9+</sup>
1834
1835getData(): Promise&lt;PasteData&gt;
1836
1837Obtains a **PasteData** object from the pasteboard. This API uses a promise to return the result.
1838
1839**Required permissions**: ohos.permission.READ_PASTEBOARD
1840
1841**Atomic service API**: This API can be used in atomic services since API version 11.
1842
1843**System capability**: SystemCapability.MiscServices.Pasteboard
1844
1845**Return value**
1846
1847| Type| Description|
1848| -------- | -------- |
1849| Promise&lt;[PasteData](#pastedata)&gt; | Promise used to return the system pasteboard data.|
1850
1851**Error codes**
1852
1853For details about the error codes, see [Universal Error Codes](../errorcode-universal.md) and [Pasteboard Error Codes](errorcode-pasteboard.md).
1854
1855| Error Code ID| Error Message|
1856| -------- | -------- |
1857| 12900003 | Another copy or paste operation is in progress. |
1858| 201      | Permission verification failed. The application does not have the permission required to call the API. |
1859
1860**Example**
1861
1862```ts
1863import { BusinessError } from '@kit.BasicServicesKit';
1864
1865let systemPasteboard: pasteboard.SystemPasteboard = pasteboard.getSystemPasteboard();
1866systemPasteboard.getData().then((pasteData: pasteboard.PasteData) => {
1867    let text: string = pasteData.getPrimaryText();
1868}).catch((err: BusinessError) => {
1869    console.error('Failed to get PasteData. Cause: ' + err.message);
1870});
1871```
1872
1873### hasData<sup>9+</sup>
1874
1875hasData(callback:  AsyncCallback&lt;boolean&gt;): void
1876
1877Checks whether the system pasteboard contains data. This API uses an asynchronous callback to return the result.
1878
1879**Atomic service API**: This API can be used in atomic services since API version 11.
1880
1881**System capability**: SystemCapability.MiscServices.Pasteboard
1882
1883**Parameters**
1884
1885| Name| Type| Mandatory| Description|
1886| -------- | -------- | -------- | -------- |
1887| callback | AsyncCallback&lt;boolean&gt; | Yes| Callback used to return the result. Returns **true** if the system pasteboard contains data; returns **false** otherwise.|
1888
1889**Error codes**
1890
1891For details about the error codes, see [Universal Error Codes](../errorcode-universal.md).
1892
1893| Error Code ID| Error Message|
1894| -------- | -------- |
1895| 401      | Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameters types. |
1896
1897**Example**
1898
1899```ts
1900import { BusinessError } from '@kit.BasicServicesKit';
1901
1902let systemPasteboard: pasteboard.SystemPasteboard = pasteboard.getSystemPasteboard();
1903systemPasteboard.hasData((err: BusinessError, data: boolean) => {
1904    if (err) {
1905        console.error(`Failed to check the PasteData. Cause: ${err.message}`);
1906        return;
1907    }
1908    console.info(`Succeeded in checking the PasteData. Data: ${data}`);
1909});
1910```
1911
1912### hasData<sup>9+</sup>
1913
1914hasData(): Promise&lt;boolean&gt;
1915
1916Checks whether the system pasteboard contains data. This API uses a promise to return the result.
1917
1918**Atomic service API**: This API can be used in atomic services since API version 11.
1919
1920**System capability**: SystemCapability.MiscServices.Pasteboard
1921
1922**Return value**
1923
1924| Type| Description|
1925| -------- | -------- |
1926| Promise&lt;boolean&gt; | Callback used to return the result. Returns **true** if the system pasteboard contains data; returns **false** otherwise.|
1927
1928**Example**
1929
1930```ts
1931import { BusinessError } from '@kit.BasicServicesKit';
1932
1933let systemPasteboard: pasteboard.SystemPasteboard = pasteboard.getSystemPasteboard();
1934systemPasteboard.hasData().then((data: boolean) => {
1935    console.info(`Succeeded in checking the PasteData. Data: ${data}`);
1936}).catch((err: BusinessError) => {
1937    console.error(`Failed to check the PasteData. Cause: ${err.message}`);
1938});
1939```
1940
1941### clear<sup>(deprecated)</sup>
1942
1943clear(callback: AsyncCallback&lt;void&gt;): void
1944
1945Clears the system pasteboard. This API uses an asynchronous callback to return the result.
1946> **NOTE**
1947>
1948> This API is supported since API version 7 and deprecated since API version 9. You are advised to use [pasteboard.clearData](#cleardata9).
1949
1950**System capability**: SystemCapability.MiscServices.Pasteboard
1951
1952**Parameters**
1953
1954| Name| Type| Mandatory| Description|
1955| -------- | -------- | -------- | -------- |
1956| callback | AsyncCallback&lt;void&gt; | Yes| Callback used to return the result. If the operation is successful, **err** is **undefined**; otherwise, **err** is an error object.|
1957
1958**Error codes**
1959
1960For details about the error codes, see [Universal Error Codes](../errorcode-universal.md).
1961
1962| Error Code ID| Error Message|
1963| -------- | -------- |
1964| 401      | Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameters types. |
1965
1966**Example**
1967
1968```ts
1969let systemPasteboard: pasteboard.SystemPasteboard = pasteboard.getSystemPasteboard();
1970systemPasteboard.clear((err, data) => {
1971    if (err) {
1972        console.error(`Failed to clear the PasteData. Cause: ${err.message}`);
1973        return;
1974    }
1975    console.info('Succeeded in clearing the PasteData.');
1976});
1977```
1978
1979### clear<sup>(deprecated)</sup>
1980
1981clear(): Promise&lt;void&gt;
1982
1983Clears the system pasteboard. This API uses a promise to return the result.
1984> **NOTE**
1985>
1986> This API is supported since API version 7 and deprecated since API version 9. You are advised to use [pasteboard.clearData](#cleardata9-1).
1987
1988**System capability**: SystemCapability.MiscServices.Pasteboard
1989
1990**Return value**
1991
1992| Type| Description|
1993| -------- | -------- |
1994| Promise&lt;void&gt; | Promise that returns no value.|
1995
1996**Example**
1997
1998```ts
1999import { BusinessError } from '@kit.BasicServicesKit';
2000
2001let systemPasteboard: pasteboard.SystemPasteboard = pasteboard.getSystemPasteboard();
2002systemPasteboard.clear().then((data) => {
2003    console.info('Succeeded in clearing the PasteData.');
2004}).catch((err: BusinessError) => {
2005    console.error(`Failed to clear the PasteData. Cause: ${err.message}`);
2006});
2007```
2008
2009### getPasteData<sup>(deprecated)</sup>
2010
2011getPasteData( callback: AsyncCallback&lt;PasteData&gt;): void
2012
2013Obtains a **PasteData** object from the pasteboard. This API uses an asynchronous callback to return the result.
2014> **NOTE**
2015>
2016> This API is supported since API version 6 and deprecated since API version 9. You are advised to use [getData](#getdata9).
2017
2018**System capability**: SystemCapability.MiscServices.Pasteboard
2019
2020**Parameters**
2021
2022| Name| Type| Mandatory| Description|
2023| -------- | -------- | -------- | -------- |
2024| callback | AsyncCallback&lt;[PasteData](#pastedata)&gt; | Yes| Callback used to return the result. If the operation is successful, **err** is **undefined** and **data** is the system pasteboard data. Otherwise, **err** is an error object.|
2025
2026**Error codes**
2027
2028For details about the error codes, see [Universal Error Codes](../errorcode-universal.md).
2029
2030| Error Code ID| Error Message|
2031| -------- | -------- |
2032| 401      | Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameters types. |
2033
2034**Example**
2035
2036```ts
2037import { BusinessError } from '@kit.BasicServicesKit';
2038
2039let systemPasteboard: pasteboard.SystemPasteboard = pasteboard.getSystemPasteboard();
2040systemPasteboard.getPasteData((err: BusinessError, pasteData: pasteboard.PasteData) => {
2041    if (err) {
2042        console.error('Failed to get PasteData. Cause: ' + err.message);
2043        return;
2044    }
2045    let text: string = pasteData.getPrimaryText();
2046});
2047```
2048
2049### getPasteData<sup>(deprecated)</sup>
2050
2051getPasteData(): Promise&lt;PasteData&gt;
2052
2053Obtains a **PasteData** object from the pasteboard. This API uses a promise to return the result.
2054> **NOTE**
2055>
2056> This API is supported since API version 6 and deprecated since API version 9. You are advised to use [getData](#getdata9-1).
2057
2058**System capability**: SystemCapability.MiscServices.Pasteboard
2059
2060**Return value**
2061
2062| Type| Description|
2063| -------- | -------- |
2064| Promise&lt;[PasteData](#pastedata)&gt; | Promise used to return the system pasteboard data.|
2065
2066**Example**
2067
2068```ts
2069import { BusinessError } from '@kit.BasicServicesKit';
2070
2071let systemPasteboard: pasteboard.SystemPasteboard = pasteboard.getSystemPasteboard();
2072systemPasteboard.getPasteData().then((pasteData: pasteboard.PasteData) => {
2073    let text: string = pasteData.getPrimaryText();
2074}).catch((err: BusinessError) => {
2075    console.error('Failed to get PasteData. Cause: ' + err.message);
2076});
2077```
2078
2079### hasPasteData<sup>(deprecated)</sup>
2080
2081hasPasteData(callback:  AsyncCallback&lt;boolean&gt;): void
2082
2083Checks whether the system pasteboard contains data. This API uses an asynchronous callback to return the result.
2084> **NOTE**
2085>
2086> This API is supported since API version 7 and deprecated since API version 9. You are advised to use [hasData](#hasdata9).
2087
2088**System capability**: SystemCapability.MiscServices.Pasteboard
2089
2090**Parameters**
2091
2092| Name| Type| Mandatory| Description|
2093| -------- | -------- | -------- | -------- |
2094| callback | AsyncCallback&lt;boolean&gt; | Yes| Callback used to return the result. Returns **true** if the system pasteboard contains data; returns **false** otherwise.|
2095
2096**Error codes**
2097
2098For details about the error codes, see [Universal Error Codes](../errorcode-universal.md).
2099
2100| Error Code ID| Error Message|
2101| -------- | -------- |
2102| 401      | Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameters types. |
2103
2104**Example**
2105
2106```ts
2107import { BusinessError } from '@kit.BasicServicesKit';
2108
2109let systemPasteboard: pasteboard.SystemPasteboard = pasteboard.getSystemPasteboard();
2110systemPasteboard.hasPasteData((err: BusinessError, data: boolean) => {
2111    if (err) {
2112        console.error(`Failed to check the PasteData. Cause: ${err.message}`);
2113        return;
2114    }
2115    console.info(`Succeeded in checking the PasteData. Data: ${data}`);
2116});
2117```
2118
2119### hasPasteData<sup>(deprecated)</sup>
2120
2121hasPasteData(): Promise&lt;boolean&gt;
2122
2123Checks whether the system pasteboard contains data. This API uses a promise to return the result.
2124> **NOTE**
2125>
2126> This API is supported since API version 7 and deprecated since API version 9. You are advised to use [hasData](#hasdata9-1).
2127
2128**System capability**: SystemCapability.MiscServices.Pasteboard
2129
2130**Return value**
2131
2132| Type| Description|
2133| -------- | -------- |
2134| Promise&lt;boolean&gt; | Callback used to return the result. Returns **true** if the system pasteboard contains data; returns **false** otherwise.|
2135
2136**Example**
2137
2138```ts
2139import { BusinessError } from '@kit.BasicServicesKit';
2140
2141let systemPasteboard: pasteboard.SystemPasteboard = pasteboard.getSystemPasteboard();
2142systemPasteboard.hasPasteData().then((data: boolean) => {
2143    console.info(`Succeeded in checking the PasteData. Data: ${data}`);
2144}).catch((err: BusinessError) => {
2145    console.error(`Failed to check the PasteData. Cause: ${err.message}`);
2146});
2147```
2148
2149### setPasteData<sup>(deprecated)</sup>
2150
2151setPasteData(data: PasteData, callback: AsyncCallback&lt;void&gt;): void
2152
2153Writes a **PasteData** object to the pasteboard. This API uses an asynchronous callback to return the result.
2154> **NOTE**
2155>
2156> This API is supported since API version 6 and deprecated since API version 9. You are advised to use [setData](#setdata9).
2157
2158**System capability**: SystemCapability.MiscServices.Pasteboard
2159
2160**Parameters**
2161
2162| Name| Type| Mandatory| Description|
2163| -------- | -------- | -------- | -------- |
2164| data | [PasteData](#pastedata) | Yes| **PasteData** object.|
2165| callback | AsyncCallback&lt;void> | Yes| Callback used to return the result. If the operation is successful, **err** is **undefined**; otherwise, **err** is an error object.|
2166
2167**Error codes**
2168
2169For details about the error codes, see [Universal Error Codes](../errorcode-universal.md).
2170
2171| Error Code ID| Error Message|
2172| -------- | -------- |
2173| 401      | Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameters types. |
2174
2175**Example**
2176
2177```ts
2178let pasteData: pasteboard.PasteData = pasteboard.createPlainTextData('content');
2179let systemPasteboard: pasteboard.SystemPasteboard = pasteboard.getSystemPasteboard();
2180systemPasteboard.setPasteData(pasteData, (err, data) => {
2181    if (err) {
2182        console.error('Failed to set PasteData. Cause: ' + err.message);
2183        return;
2184    }
2185    console.info('Succeeded in setting PasteData.');
2186});
2187```
2188### setPasteData<sup>(deprecated)</sup>
2189
2190setPasteData(data: PasteData): Promise&lt;void&gt;
2191
2192Writes a **PasteData** object to the pasteboard. This API uses a promise to return the result.
2193> **NOTE**
2194>
2195> This API is supported since API version 6 and deprecated since API version 9. You are advised to use [setData](#setdata9-1).
2196
2197**System capability**: SystemCapability.MiscServices.Pasteboard
2198
2199**Parameters**
2200
2201| Name| Type| Mandatory| Description|
2202| -------- | -------- | -------- | -------- |
2203| data | [PasteData](#pastedata) | Yes| **PasteData** object.|
2204
2205**Return value**
2206
2207| Type| Description|
2208| -------- | -------- |
2209| Promise&lt;void&gt; | Promise that returns no value.|
2210
2211**Example**
2212
2213```ts
2214import { BusinessError } from '@kit.BasicServicesKit';
2215
2216let pasteData: pasteboard.PasteData = pasteboard.createPlainTextData('content');
2217let systemPasteboard: pasteboard.SystemPasteboard = pasteboard.getSystemPasteboard();
2218systemPasteboard.setPasteData(pasteData).then((data: void) => {
2219    console.info('Succeeded in setting PasteData.');
2220}).catch((err: BusinessError) => {
2221    console.error('Failed to set PasteData. Cause: ' + err.message);
2222});
2223```
2224### isRemoteData<sup>11+</sup>
2225
2226isRemoteData(): boolean
2227
2228Checks whether the data in the pasteboard is from another device.
2229
2230**Atomic service API**: This API can be used in atomic services since API version 11.
2231
2232**System capability**: SystemCapability.MiscServices.Pasteboard
2233
2234**Return value**
2235
2236| Type   | Description                                 |
2237| ------- | ------------------------------------- |
2238| boolean | Returns **true** if the data in the pasteboard is from another device; returns **false** otherwise.|
2239
2240**Error codes**
2241
2242For details about the error codes, see [Pasteboard Error Codes](errorcode-pasteboard.md).
2243
2244| Error Code ID| Error Message|
2245| -------- | -------- |
2246| 12900005 | Request timed out. |
2247
2248**Example**
2249
2250```ts
2251let systemPasteboard: pasteboard.SystemPasteboard = pasteboard.getSystemPasteboard();
2252try {
2253    let result: boolean = systemPasteboard.isRemoteData();
2254    console.info(`Succeeded in checking the RemoteData. Result: ${result}`);
2255} catch (err) {
2256    console.error('Failed to check the RemoteData. Cause:' + err.message);
2257};
2258```
2259
2260### getDataSource<sup>11+</sup>
2261
2262getDataSource(): string
2263
2264Obtains the data source.
2265
2266**Atomic service API**: This API can be used in atomic services since API version 11.
2267
2268**System capability**: SystemCapability.MiscServices.Pasteboard
2269
2270**Return value**
2271
2272| Type  | Description  |
2273| ------ | ------ |
2274| string | Data source.|
2275
2276**Error codes**
2277
2278For details about the error codes, see [Pasteboard Error Codes](errorcode-pasteboard.md).
2279
2280| Error Code ID| Error Message|
2281| -------- | -------- |
2282| 12900005 | Request timed out. |
2283
2284**Example**
2285
2286```ts
2287let systemPasteboard: pasteboard.SystemPasteboard = pasteboard.getSystemPasteboard();
2288try {
2289    let result: string = systemPasteboard.getDataSource();
2290    console.info(`Succeeded in getting DataSource. Result: ${result}`);
2291} catch (err) {
2292    console.error('Failed to get DataSource. Cause:' + err.message);
2293};
2294```
2295
2296### hasDataType<sup>11+</sup>
2297
2298hasDataType(mimeType: string): boolean
2299
2300Checks whether the pasteboard contains data of the specified type.
2301
2302**Atomic service API**: This API can be used in atomic services since API version 11.
2303
2304**System capability**: SystemCapability.MiscServices.Pasteboard
2305
2306**Parameters**
2307
2308| Name  | Type  | Mandatory| Description              |
2309| -------- | ------ | ---- | ------------------ |
2310| mimeType | string | Yes  | Data type.|
2311
2312**Return value**
2313
2314| Type   | Description                                       |
2315| ------- | ------------------------------------------- |
2316| boolean | Returns **true** if the pasteboard contains data of the specified type; returns **false** otherwise.|
2317
2318**Error codes**
2319
2320For details about the error codes, see [Universal Error Codes](../errorcode-universal.md) and [Pasteboard Error Codes](errorcode-pasteboard.md).
2321
2322| Error Code ID| Error Message|
2323| -------- | -------- |
2324| 401 | Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameters types. |
2325| 12900005 | Request timed out. |
2326
2327**Example**
2328
2329```ts
2330let systemPasteboard: pasteboard.SystemPasteboard = pasteboard.getSystemPasteboard();
2331try {
2332    let result: boolean = systemPasteboard.hasDataType(pasteboard.MIMETYPE_TEXT_PLAIN);
2333    console.info(`Succeeded in checking the DataType. Result: ${result}`);
2334} catch (err) {
2335    console.error('Failed to check the DataType. Cause:' + err.message);
2336};
2337```
2338
2339### clearDataSync<sup>11+</sup>
2340
2341clearDataSync(): void
2342
2343Clears the system pasteboard. This API returns the result synchronously.
2344
2345**Atomic service API**: This API can be used in atomic services since API version 11.
2346
2347**System capability**: SystemCapability.MiscServices.Pasteboard
2348
2349**Error codes**
2350
2351For details about the error codes, see [Pasteboard Error Codes](errorcode-pasteboard.md).
2352
2353| Error Code ID| Error Message|
2354| -------- | -------- |
2355| 12900005 | Request timed out. |
2356
2357**Example**
2358
2359```ts
2360let systemPasteboard: pasteboard.SystemPasteboard = pasteboard.getSystemPasteboard();
2361try {
2362    systemPasteboard.clearDataSync();
2363    console.info('Succeeded in clearing the pasteboard.');
2364} catch (err) {
2365    console.error('Failed to clear the pasteboard. Cause:' + err.message);
2366};
2367```
2368
2369### getDataSync<sup>11+</sup>
2370
2371getDataSync(): PasteData
2372
2373Reads data in the system pasteboard. This API returns the result synchronously.
2374
2375**Required permissions**: ohos.permission.READ_PASTEBOARD
2376
2377**Atomic service API**: This API can be used in atomic services since API version 11.
2378
2379**System capability**: SystemCapability.MiscServices.Pasteboard
2380
2381**Return value**
2382
2383| Type                   | Description                |
2384| ----------------------- | -------------------- |
2385| [PasteData](#pastedata) | Data in the system pasteboard.|
2386
2387**Error codes**
2388
2389For details about the error codes, see [Universal Error Codes](../errorcode-universal.md) and [Pasteboard Error Codes](errorcode-pasteboard.md).
2390
2391| Error Code ID| Error Message|
2392| -------- | -------- |
2393| 12900005 | Request timed out. |
2394| 201      | Permission verification failed. The application does not have the permission required to call the API. |
2395
2396**Example**
2397
2398```ts
2399let systemPasteboard: pasteboard.SystemPasteboard = pasteboard.getSystemPasteboard();
2400try {
2401    let result: pasteboard.PasteData = systemPasteboard.getDataSync();
2402    console.info('Succeeded in getting PasteData.');
2403} catch (err) {
2404    console.error('Failed to get PasteData. Cause:' + err.message);
2405};
2406```
2407
2408### setDataSync<sup>11+</sup>
2409
2410setDataSync(data: PasteData): void
2411
2412Writes data to the system pasteboard. This API returns the result synchronously.
2413
2414**Atomic service API**: This API can be used in atomic services since API version 11.
2415
2416**System capability**: SystemCapability.MiscServices.Pasteboard
2417
2418**Parameters**
2419
2420| Name| Type                   | Mandatory| Description            |
2421| ------ | ----------------------- | ---- | ---------------- |
2422| data   | [PasteData](#pastedata) | Yes  | Data to be written to the pasteboard.|
2423
2424**Error codes**
2425
2426For details about the error codes, see [Universal Error Codes](../errorcode-universal.md) and [Pasteboard Error Codes](errorcode-pasteboard.md).
2427
2428| Error Code ID| Error Message|
2429| -------- | -------- |
2430| 401      | Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameters types. |
2431| 12900005 | Request timed out. |
2432
2433**Example**
2434
2435```ts
2436let pasteData: pasteboard.PasteData = pasteboard.createData(pasteboard.MIMETYPE_TEXT_PLAIN, 'hello');
2437let systemPasteboard: pasteboard.SystemPasteboard = pasteboard.getSystemPasteboard();
2438try {
2439    systemPasteboard.setDataSync(pasteData);
2440    console.info('Succeeded in setting PasteData.');
2441} catch (err) {
2442    console.error('Failed to set PasteData. Cause:' + err.message);
2443};
2444```
2445
2446### hasDataSync<sup>11+</sup>
2447
2448hasDataSync(): boolean
2449
2450Checks whether the system pasteboard contains data. This API returns the result synchronously.
2451
2452**Atomic service API**: This API can be used in atomic services since API version 11.
2453
2454**System capability**: SystemCapability.MiscServices.Pasteboard
2455
2456**Return value**
2457
2458| Type   | Description                                                                   |
2459| ------- | ----------------------------------------------------------------------- |
2460| boolean | Callback used to return the result. Returns **true** if the system pasteboard contains data; returns **false** otherwise.|
2461
2462**Error codes**
2463
2464For details about the error codes, see [Pasteboard Error Codes](errorcode-pasteboard.md).
2465
2466| Error Code ID| Error Message|
2467| -------- | -------- |
2468| 12900005 | Request timed out. |
2469
2470**Example**
2471
2472```ts
2473let systemPasteboard: pasteboard.SystemPasteboard = pasteboard.getSystemPasteboard();
2474try {
2475    let result: boolean = systemPasteboard.hasDataSync();
2476    console.info(`Succeeded in checking the PasteData. Result: ${result}`);
2477} catch (err) {
2478    console.error('Failed to check the PasteData. Cause:' + err.message);
2479};
2480```
2481
2482### getUnifiedData<sup>12+</sup>
2483
2484getUnifiedData(): Promise&lt;unifiedDataChannel.UnifiedData&gt;
2485
2486Obtains a **PasteData** object from the pasteboard. This API uses a promise to return the result.
2487
2488**Required permissions**: ohos.permission.READ_PASTEBOARD
2489
2490**Atomic service API**: This API can be used in atomic services since API version 12.
2491
2492**System capability**: SystemCapability.MiscServices.Pasteboard
2493
2494**Return value**
2495
2496| Type| Description|
2497| -------- | -------- |
2498| Promise&lt;[unifiedDataChannel.UnifiedData](../apis-arkdata/js-apis-data-unifiedDataChannel.md#unifieddata)&gt; | Promise used to return the system pasteboard data.|
2499
2500**Error codes**
2501
2502For details about the error codes, see [Pasteboard Error Codes](errorcode-pasteboard.md).
2503
2504| Error Code ID| Error Message|
2505| -------- | -------- |
2506| 201      | Permission verification failed. The application does not have the permission required to call the API. |
2507| 12900003 | Another copy or paste operation is in progress. |
2508
2509**Example**
2510
2511```ts
2512import { BusinessError } from '@kit.BasicServicesKit';
2513import { unifiedDataChannel } from '@kit.ArkData';
2514import { uniformTypeDescriptor } from '@kit.ArkData';
2515
2516let systemPasteboard: pasteboard.SystemPasteboard = pasteboard.getSystemPasteboard();
2517systemPasteboard.getUnifiedData().then((data) => {
2518    let records: Array<unifiedDataChannel.UnifiedRecord> = data.getRecords();
2519    for (let j = 0; j < records.length; j++) {
2520        if (records[j].getType() === uniformTypeDescriptor.UniformDataType.PLAIN_TEXT) {
2521            let text = records[j] as unifiedDataChannel.PlainText;
2522            console.info(`${j + 1}.${text.textContent}`);
2523        }
2524    }
2525}).catch((err: BusinessError) => {
2526    console.error('Failed to get UnifiedData. Cause: ' + err.message);
2527});
2528```
2529
2530### getUnifiedDataSync<sup>12+</sup>
2531
2532getUnifiedDataSync(): unifiedDataChannel.UnifiedData
2533
2534Reads data in the system pasteboard. This API returns the result synchronously.
2535
2536**Required permissions**: ohos.permission.READ_PASTEBOARD
2537
2538**Atomic service API**: This API can be used in atomic services since API version 12.
2539
2540**System capability**: SystemCapability.MiscServices.Pasteboard
2541
2542**Return value**
2543
2544| Type                | Description                |
2545| -------------------- | -------------------- |
2546| [unifiedDataChannel.UnifiedData](../apis-arkdata/js-apis-data-unifiedDataChannel.md#unifieddata) | Data in the system pasteboard.|
2547
2548**Error codes**
2549
2550For details about the error codes, see [Pasteboard Error Codes](errorcode-pasteboard.md).
2551
2552| Error Code ID| Error Message|
2553| -------- | -------- |
2554| 201      | Permission verification failed. The application does not have the permission required to call the API. |
2555| 12900005 | Request timed out. |
2556
2557**Example**
2558
2559```ts
2560import { unifiedDataChannel } from '@kit.ArkData';
2561
2562let systemPasteboard: pasteboard.SystemPasteboard = pasteboard.getSystemPasteboard();
2563try {
2564    let result: unifiedDataChannel.UnifiedData = systemPasteboard.getUnifiedDataSync();
2565    console.info('Succeeded in getting UnifiedData.');
2566} catch (err) {
2567    console.error('Failed to get UnifiedData. Cause:' + err.message);
2568};
2569```
2570
2571### setUnifiedData<sup>12+</sup>
2572
2573setUnifiedData(data: unifiedDataChannel.UnifiedData): Promise&lt;void&gt;
2574
2575Writes a **PasteData** object to the pasteboard. This API uses a promise to return the result.
2576
2577**System capability**: SystemCapability.MiscServices.Pasteboard
2578
2579**Atomic service API**: This API can be used in atomic services since API version 12.
2580
2581**Parameters**
2582
2583| Name| Type| Mandatory| Description|
2584| -------- | -------- | -------- | -------- |
2585| data | [unifiedDataChannel.UnifiedData](../apis-arkdata/js-apis-data-unifiedDataChannel.md#unifieddata) | Yes| 	Data to be written to the pasteboard.|
2586
2587**Return value**
2588
2589| Type| Description|
2590| -------- | -------- |
2591| Promise&lt;void&gt; | Promise that returns no value.|
2592
2593**Error codes**
2594
2595For details about the error codes, see [Pasteboard Error Codes](errorcode-pasteboard.md).
2596
2597| Error Code ID| Error Message|
2598| -------- | -------- |
2599| 401      | Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameters types. |
2600| 12900003 | Another copy or paste operation is in progress. |
2601| 12900004 | Replication is prohibited. |
2602
2603**Example**
2604
2605```ts
2606import { BusinessError } from '@kit.BasicServicesKit';
2607import { unifiedDataChannel } from '@kit.ArkData';
2608
2609let plainTextData = new unifiedDataChannel.UnifiedData();
2610let plainText = new unifiedDataChannel.PlainText();
2611plainText.details = {
2612    Key: 'delayPlaintext',
2613    Value: 'delayPlaintext',
2614};
2615plainText.textContent = 'delayTextContent';
2616plainText.abstract = 'delayTextContent';
2617plainTextData.addRecord(plainText);
2618
2619let systemPasteboard: pasteboard.SystemPasteboard = pasteboard.getSystemPasteboard();
2620systemPasteboard.setUnifiedData(plainTextData).then((data: void) => {
2621    console.info('Succeeded in setting UnifiedData.');
2622}).catch((err: BusinessError) => {
2623    console.error('Failed to set UnifiedData. Cause: ' + err.message);
2624});
2625```
2626
2627### setUnifiedDataSync<sup>12+</sup>
2628
2629setUnifiedDataSync(data: unifiedDataChannel.UnifiedData): void
2630
2631Writes data to the system pasteboard. This API returns the result synchronously.
2632
2633**System capability**: SystemCapability.MiscServices.Pasteboard
2634
2635**Atomic service API**: This API can be used in atomic services since API version 12.
2636
2637**Parameters**
2638
2639| Name| Type       | Mandatory| Description            |
2640| ------ | ----------- | ---- | ---------------- |
2641| data   | [unifiedDataChannel.UnifiedData](../apis-arkdata/js-apis-data-unifiedDataChannel.md#unifieddata) | Yes  | Data to be written to the pasteboard.|
2642
2643**Error codes**
2644
2645For details about the error codes, see [Pasteboard Error Codes](errorcode-pasteboard.md).
2646
2647| Error Code ID| Error Message|
2648| -------- | -------- |
2649| 401      | Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameters types. |
2650| 12900005 | Request timed out. |
2651
2652**Example**
2653
2654```ts
2655import { unifiedDataChannel } from '@kit.ArkData';
2656
2657let plainTextData = new unifiedDataChannel.UnifiedData();
2658let plainText = new unifiedDataChannel.PlainText();
2659plainText.details = {
2660    Key: 'delayPlaintext',
2661    Value: 'delayPlaintext',
2662};
2663plainText.textContent = 'delayTextContent';
2664plainText.abstract = 'delayTextContent';
2665plainTextData.addRecord(plainText);
2666
2667let systemPasteboard: pasteboard.SystemPasteboard = pasteboard.getSystemPasteboard();
2668try {
2669    systemPasteboard.setUnifiedDataSync(plainTextData);
2670    console.info('Succeeded in setting UnifiedData.');
2671} catch (err) {
2672    console.error('Failed to set UnifiedData. Cause:' + err.message);
2673};
2674```
2675
2676### setAppShareOptions<sup>14+</sup>
2677
2678setAppShareOptions(shareOptions: ShareOption): void
2679
2680Sets pasteable range of pasteboard data for applications.
2681
2682**Required permissions**: ohos.permission.MANAGE_PASTEBOARD_APP_SHARE_OPTION
2683
2684**System capability**: SystemCapability.MiscServices.Pasteboard
2685
2686**Parameters**
2687
2688| Name| Type| Mandatory| Description|
2689| -------- | -------- | -------- | -------- |
2690| shareOptions | [ShareOption](js-apis-pasteboard.md#shareoption9) | Yes| Pasteable range. Only **pasteboard.ShareOption.INAPP** is allowed.|
2691
2692**Error codes**
2693
2694For details about the error codes, see [Pasteboard Error Codes](errorcode-pasteboard.md).
2695
2696| Error Code ID| Error Message|
2697| -------- | -------- |
2698| 201 | Permission verification failed. The application does not have the permission required to call the API. |
2699| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types; 3. Parameter verification failed. |
2700| 12900006 | Settings already exist. |
2701
2702**Example**
2703
2704```ts
2705let systemPasteboard: pasteboard.SystemPasteboard = pasteboard.getSystemPasteboard();
2706try {
2707  systemPasteboard.setAppShareOptions(pasteboard.ShareOption.INAPP);
2708  console.info('Set app share options success.');
2709} catch (err) {
2710  let error: BusinessError = err as BusinessError;
2711  console.error(`Set app share options failed, errorCode: ${error.code}, errorMessage: ${error.message}.`);
2712}
2713```
2714
2715### removeAppShareOptions<sup>14+</sup>
2716
2717removeAppShareOptions(): void
2718
2719Deletes the global pasteable range of the application.
2720
2721**Required permissions**: ohos.permission.MANAGE_PASTEBOARD_APP_SHARE_OPTION
2722
2723**System capability**: SystemCapability.MiscServices.Pasteboard
2724
2725**Error codes**
2726
2727For details about the error codes, see [Pasteboard Error Codes](errorcode-pasteboard.md).
2728
2729| Error Code ID| Error Message|
2730| -------- | -------- |
2731| 201 | Permission verification failed. The application does not have the permission required to call the API. |
2732
2733**Example**
2734
2735```ts
2736let systemPasteboard: pasteboard.SystemPasteboard = pasteboard.getSystemPasteboard();
2737try {
2738  systemPasteboard.removeAppShareOptions();
2739  console.info('Remove app share options success.');
2740} catch (err) {
2741  let error: BusinessError = err as BusinessError;
2742  console.error(`Remove app share options failed, errorCode: ${error.code}, errorMessage: ${error.message}.`);
2743}
2744```
2745
2746### Pattern<sup>13+</sup>
2747Describes the modes supported by the pasteboard.
2748
2749**System capability**: SystemCapability.MiscServices.Pasteboard
2750
2751| Name                              | Value | Description                                                                                 |
2752| ---------------------------------- | --- | ------------------------------------------------------------------------------------- |
2753| URL                              | 0   | URL.                                                             |
2754| NUMBER                        | 1   | Number.                                                   |
2755| EMAIL_ADDRESS | 2   | Email address.|
2756
2757### detectPatterns<sup>13+</sup>
2758
2759detectPatterns(patterns: Array&lt;Pattern&gt;): Promise&lt;Array&lt;Pattern&gt;&gt;
2760
2761Detects patterns on the **local** pasteboard. This API uses a promise to return the result.
2762
2763**System capability**: SystemCapability.MiscServices.Pasteboard
2764
2765**Parameters**
2766
2767| Name| Type| Mandatory| Description|
2768| -------- | -------- | -------- | -------- |
2769| patterns | [Array&lt;Pattern&gt;](#pattern13) | Yes| 	Pattern to be detected in the pasteboard.|
2770
2771**Return value**
2772
2773| Type| Description|
2774| -------- | -------- |
2775| Promise&lt;Array&lt;Pattern&gt;&gt; | Promise used to return the detected pattern.|
2776
2777**Error codes**
2778
2779For details about the error codes, see [Universal Error Codes](../errorcode-universal.md).
2780
2781| Error Code ID| Error Message|
2782| -------- | -------- |
2783| 401      | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types. 3. Parameter verification failed. |
2784
2785**Example**
2786
2787```ts
2788import { pasteboard } from '@kit.BasicServicesKit'
2789
2790let systemPasteboard: pasteboard.SystemPasteboard = pasteboard.getSystemPasteboard();
2791let patterns: Array<pasteboard.Pattern> = [pasteboard.Pattern.URL, pasteboard.Pattern.EMAIL_ADDRESS];
2792
2793systemPasteboard.detectPatterns(patterns).then((data: Array<pasteboard.Pattern>) => {
2794    if (patterns.sort().join('')==data.sort().join('')) {
2795      console.info('All needed patterns detected, next get data');
2796      try {
2797        let result: pasteboard.PasteData = systemPasteboard.getDataSync();
2798        console.info('Succeeded in getting PasteData.');
2799      } catch (err) {
2800        console.error('Failed to get PasteData. Cause:' + err.message);
2801      };
2802    } else {
2803      console.info("Not all needed patterns detected, no need to get data.");
2804    }
2805});
2806```
2807
2808### getMimeTypes<sup>14+</sup>
2809
2810getMimeTypes(): Promise&lt;Array&lt;string&gt;&gt;
2811
2812Obtains the MIME type from the pasteboard. This API uses a promise to return the result.
2813
2814**Atomic service API**: This API can be used in atomic services since API version 14.
2815
2816**System capability**: SystemCapability.MiscServices.Pasteboard
2817
2818**Return value**
2819
2820| Type| Description|
2821| -------- | -------- |
2822| Promise&lt;Array&lt;string&gt;&gt; | Promise used to return the result.|
2823
2824**Example**
2825
2826```ts
2827import { pasteboard, BusinessError } from '@kit.BasicServicesKit'
2828
2829let systemPasteboard: pasteboard.SystemPasteboard = pasteboard.getSystemPasteboard();
2830systemPasteboard.getMimeTypes().then((data: Array<String>) => {
2831    console.info('Succeeded in getting mimeTypes. mimeTypes: ' + data.sort().join(','));
2832}).catch((err: BusinessError) => {
2833    console.error('Failed to get mimeTypes. Cause:' + err.message);
2834});
2835```