• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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```js
12import pasteboard from '@ohos.pasteboard';
13```
14
15## Constants
16
17**System capability**: SystemCapability.MiscServices.Pasteboard
18
19| Name| Type| Value| Description|
20| -------- | -------- | -------- | -------- |
21| MAX_RECORD_NUM<sup>7+</sup> | number | 512 | Maximum number of records in a **PasteData** object.|
22| MIMETYPE_TEXT_HTML<sup>7+</sup> | string | 'text/html' | MIME type of the HTML content.|
23| MIMETYPE_TEXT_WANT<sup>7+</sup> | string | 'text/want' | MIME type of the Want content.|
24| MIMETYPE_TEXT_PLAIN<sup>7+</sup> | string | 'text/plain' | MIME type of the plain text content.|
25| MIMETYPE_TEXT_URI<sup>7+</sup> | string | 'text/uri' | MIME type of the URI content.|
26| MIMETYPE_PIXELMAP<sup>9+</sup> | string | 'pixelMap' | MIME type of the pixel map.|
27
28## ValueType<sup>9+</sup>
29
30Enumerates the value types.
31
32**System capability**: SystemCapability.MiscServices.Pasteboard
33
34| Type| Description|
35| -------- | -------- |
36| string | The value is a string.|
37| image.PixelMap | The value is of the [image.PixelMap](js-apis-image.md#pixelmap7) type.|
38| Want | The value is of the [Want](js-apis-app-ability-want.md) type.|
39| ArrayBuffer | The value is of the **ArrayBuffer** type.|
40
41## pasteboard.createData<sup>9+</sup>
42
43createData(mimeType: string, value: ValueType): PasteData
44
45Creates a **PasteData** object of a custom type.
46
47**System capability**: SystemCapability.MiscServices.Pasteboard
48
49**Parameters**
50
51| Name| Type| Mandatory| Description|
52| -------- | -------- | -------- | -------- |
53| mimeType | string | Yes| MIME type of custom data.|
54| value | [ValueType](#valuetype9) | Yes| Content of custom data.|
55
56**Return value**
57
58| Type| Description|
59| -------- | -------- |
60| [PasteData](#pastedata) |  **PasteData** object.|
61
62**Example**
63
64  ```js
65  let dataXml = new ArrayBuffer(256);
66let pasteData = pasteboard.createData('app/xml', dataXml);
67  ```
68
69## pasteboard.createRecord<sup>9+</sup>
70
71createRecord(mimeType: string, value: ValueType):PasteDataRecord;
72
73Creates a **PasteDataRecord** object of the custom type.
74
75**System capability**: SystemCapability.MiscServices.Pasteboard
76
77**Parameters**
78
79| Name| Type| Mandatory| Description|
80| -------- | -------- | -------- | -------- |
81| mimeType | string | Yes| MIME type of custom data.|
82| value | [ValueType](#valuetype9) | Yes| Content of custom data.|
83
84**Return value**
85
86| Type| Description|
87| -------- | -------- |
88| [PasteDataRecord](#pastedatarecord7) | New **PasteDataRecord** object of the custom type.|
89
90**Example**
91
92  ```js
93let dataXml = new ArrayBuffer(256);
94let pasteDataRecord = pasteboard.createRecord('app/xml', dataXml);
95  ```
96
97## pasteboard.getSystemPasteboard
98
99getSystemPasteboard(): SystemPasteboard
100
101Obtains this **SystemPasteboard** object.
102
103**System capability**: SystemCapability.MiscServices.Pasteboard
104
105**Return value**
106
107| Type| Description|
108| -------- | -------- |
109| [SystemPasteboard](#systempasteboard) | **SystemPasteboard** object.|
110
111**Example**
112
113```js
114let systemPasteboard = pasteboard.getSystemPasteboard();
115```
116
117## ShareOption<sup>9+</sup>
118
119Enumerates the paste options of data.
120
121**System capability**: SystemCapability.MiscServices.Pasteboard
122
123| Name         | Value| Description               |
124|-------------|---|-------------------|
125| INAPP       | 0 | Only intra-application pasting is allowed.     |
126| LOCALDEVICE | 1 | Paste is allowed in any application on the local device.|
127| CROSSDEVICE | 2 | Paste is allowed in any application across devices. |
128
129## pasteboard.createHtmlData<sup>(deprecated)</sup>
130
131createHtmlData(htmlText: string): PasteData
132
133Creates a **PasteData** object of the HTML type.
134> **NOTE**
135>
136> This API is supported since API version 7 and deprecated since API version 9. You are advised to use [pasteboard.createData](#pasteboardcreatedata9).
137
138**System capability**: SystemCapability.MiscServices.Pasteboard
139
140**Parameters**
141
142| Name| Type| Mandatory| Description|
143| -------- | -------- | -------- | -------- |
144| htmlText | string | Yes| HTML content.|
145
146**Return value**
147
148| Type| Description|
149| -------- | -------- |
150| [PasteData](#pastedata) | **PasteData** object.|
151
152**Example**
153
154```js
155let 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>";
156let pasteData = pasteboard.createHtmlData(html);
157```
158
159## pasteboard.createWantData<sup>(deprecated)</sup>
160
161createWantData(want: Want): PasteData
162
163Creates a **PasteData** object of the Want type.
164> **NOTE**
165>
166> This API is supported since API version 7 and deprecated since API version 9. You are advised to use [pasteboard.createData](#pasteboardcreatedata9).
167
168**System capability**: SystemCapability.MiscServices.Pasteboard
169
170**Parameters**
171
172| Name| Type| Mandatory| Description|
173| -------- | -------- | -------- | -------- |
174| want | [Want](js-apis-app-ability-want.md) | Yes| Want content.|
175
176**Return value**
177
178| Type| Description|
179| -------- | -------- |
180| [PasteData](#pastedata) | **PasteData** object.|
181
182**Example**
183
184```js
185let object = {
186    bundleName: "com.example.aafwk.test",
187    abilityName: "com.example.aafwk.test.TwoAbility"
188};
189let pasteData = pasteboard.createWantData(object);
190```
191
192## pasteboard.createPlainTextData<sup>(deprecated)</sup>
193
194createPlainTextData(text: string): PasteData
195
196Creates a **PasteData** object of the plain text type.
197> **NOTE**
198>
199> This API is supported since API version 7 and deprecated since API version 9. You are advised to use [pasteboard.createData](#pasteboardcreatedata9).
200
201**System capability**: SystemCapability.MiscServices.Pasteboard
202
203**Parameters**
204
205| Name| Type| Mandatory| Description|
206| -------- | -------- | -------- | -------- |
207| text | string | Yes| Plain text.|
208
209**Return value**
210
211| Type| Description|
212| -------- | -------- |
213| [PasteData](#pastedata) | **PasteData** object.|
214
215**Example**
216
217```js
218let pasteData = pasteboard.createPlainTextData('content');
219```
220
221## pasteboard.createUriData<sup>(deprecated)</sup>
222
223createUriData(uri: string): PasteData
224
225Creates a **PasteData** object of the URI type.
226> **NOTE**
227>
228> This API is supported since API version 7 and deprecated since API version 9. You are advised to use [pasteboard.createData](#pasteboardcreatedata9).
229
230**System capability**: SystemCapability.MiscServices.Pasteboard
231
232**Parameters**
233
234| Name| Type| Mandatory| Description|
235| -------- | -------- | -------- | -------- |
236| uri | string | Yes| URI content.|
237
238**Return value**
239
240| Type| Description|
241| -------- | -------- |
242| [PasteData](#pastedata) | **PasteData** object.|
243
244**Example**
245
246```js
247let pasteData = pasteboard.createUriData('dataability:///com.example.myapplication1/user.txt');
248```
249## pasteboard.createHtmlTextRecord<sup>(deprecated)</sup>
250
251createHtmlTextRecord(htmlText: string): PasteDataRecord
252
253Creates a **PasteDataRecord** object of the HTML text 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.createRecord](#pasteboardcreaterecord9).
257
258**System capability**: SystemCapability.MiscServices.Pasteboard
259
260**Parameters**
261
262| Name| Type| Mandatory| Description|
263| -------- | -------- | -------- | -------- |
264| htmlText | string | Yes| HTML content.|
265
266**Return value**
267
268| Type| Description|
269| -------- | -------- |
270| [PasteDataRecord](#pastedatarecord7) | **PasteDataRecord** object of the HTML text type.|
271
272**Example**
273
274```js
275let 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>";
276let record = pasteboard.createHtmlTextRecord(html);
277```
278
279## pasteboard.createWantRecord<sup>(deprecated)</sup>
280
281createWantRecord(want: Want): PasteDataRecord
282
283Creates a **PasteDataRecord** object of the Want type.
284> **NOTE**
285>
286> This API is supported since API version 7 and deprecated since API version 9. You are advised to use [pasteboard.createRecord](#pasteboardcreaterecord9).
287
288**System capability**: SystemCapability.MiscServices.Pasteboard
289
290**Parameters**
291
292| Name| Type| Mandatory| Description|
293| -------- | -------- | -------- | -------- |
294| want | [Want](js-apis-app-ability-want.md) | Yes| Want content.|
295
296**Return value**
297
298| Type| Description|
299| -------- | -------- |
300| [PasteDataRecord](#pastedatarecord7) | New **PasteDataRecord** object of the Want type.|
301
302**Example**
303
304```js
305let object = {
306    bundleName: "com.example.aafwk.test",
307    abilityName: "com.example.aafwk.test.TwoAbility"
308};
309let record = pasteboard.createWantRecord(object);
310```
311
312## pasteboard.createPlainTextRecord<sup>(deprecated)</sup>
313
314createPlainTextRecord(text: string): PasteDataRecord
315
316Creates a **PasteDataRecord** object of the plain text type.
317> **NOTE**
318>
319> This API is supported since API version 7 and deprecated since API version 9. You are advised to use [pasteboard.createRecord](#pasteboardcreaterecord9).
320
321**System capability**: SystemCapability.MiscServices.Pasteboard
322
323**Parameters**
324
325| Name| Type| Mandatory| Description|
326| -------- | -------- | -------- | -------- |
327| text | string | Yes| Plain text.|
328
329**Return value**
330
331| Type| Description|
332| -------- | -------- |
333| [PasteDataRecord](#pastedatarecord7) | New **PasteDataRecord** object of the plain text type.|
334
335**Example**
336
337```js
338let record = pasteboard.createPlainTextRecord('hello');
339```
340
341## pasteboard.createUriRecord<sup>(deprecated)</sup>
342
343createUriRecord(uri: string): PasteDataRecord
344
345Creates a **PasteDataRecord** object of the URI 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| uri | string | Yes| URI content.|
357
358**Return value**
359
360| Type| Description|
361| -------- | -------- |
362| [PasteDataRecord](#pastedatarecord7) | New **PasteDataRecord** object of the URI type.|
363
364**Example**
365
366```js
367let record = pasteboard.createUriRecord('dataability:///com.example.myapplication1/user.txt');
368```
369
370
371## PasteDataProperty<sup>7+</sup>
372
373Defines the properties of all data records on the pasteboard, including the timestamp, data type, and additional data.
374
375**System capability**: SystemCapability.MiscServices.Pasteboard
376
377| Name| Type| Readable| Writable| Description                                                                                        |
378| -------- | -------- | -------- | -------- |--------------------------------------------------------------------------------------------|
379| additions<sup>7+</sup> | {[key:string]:object} | Yes| Yes| Additional data.                                                                              |
380| mimeTypes<sup>7+</sup> | Array&lt;string&gt; | Yes| No| Non-repeating data types of the data records on the pasteboard.                                                                    |
381| tag<sup>7+</sup> | string | Yes| Yes| Custom tag.                                                                                  |
382| timestamp<sup>7+</sup> | number | Yes| No| Timestamp when data is written to the pasteboard (unit: ms).                                                                       |
383| localOnly<sup>7+</sup> | boolean | Yes| Yes| Whether the pasteboard content is set for local access only. The default value is **true**.<br>- **true**: The pasteboard content is set for local access only.<br>- **false**: The pasteboard content can be shared between devices.|
384| 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.                                             |
385
386## PasteDataRecord<sup>7+</sup>
387
388Provides **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.
389
390### Attributes
391
392**System capability**: SystemCapability.MiscServices.Pasteboard
393
394| Name| Type| Readable| Writable| Description|
395| -------- | -------- | -------- | -------- | -------- |
396| htmlText<sup>7+</sup> | string | Yes| No| HTML content.|
397| want<sup>7+</sup> | [Want](js-apis-app-ability-want.md) | Yes| No| Want content.|
398| mimeType<sup>7+</sup> | string | Yes| No| Data type.|
399| plainText<sup>7+</sup> | string | Yes| No| Plain text.|
400| uri<sup>7+</sup> | string | Yes| No| URI content.|
401| pixelMap<sup>9+</sup> | [image.PixelMap](js-apis-image.md#pixelmap7) | Yes| No| Pixel map.|
402| data<sup>9+</sup> | {[mimeType: string]: ArrayBuffer} | Yes| No| Content of custom data.|
403
404### toPlainText<sup>9+</sup>
405
406toPlainText(): string
407
408Forcibly converts the content in a **PasteData** object to text.
409
410**System capability**: SystemCapability.MiscServices.Pasteboard
411
412**Return value**
413
414| Type| Description|
415| -------- | -------- |
416| string | Plain text.|
417
418**Example**
419
420```js
421let record = pasteboard.createRecord(pasteboard.MIMETYPE_TEXT_URI, 'dataability:///com.example.myapplication1/user.txt');
422let data = record.toPlainText();
423console.info(`Succeeded in converting to text. Data: ${data}`);
424```
425
426### convertToText<sup>(deprecated)</sup>
427
428convertToText(callback: AsyncCallback&lt;string&gt;): void
429
430Forcibly converts the content in a **PasteData** object to text. This API uses an asynchronous callback to return the result.
431> **NOTE**
432>
433> This API is supported since API version 7 and deprecated since API version 9. You are advised to use [toPlainText](#toplaintext9).
434
435**System capability**: SystemCapability.MiscServices.Pasteboard
436
437**Parameters**
438
439| Name| Type| Mandatory| Description|
440| -------- | -------- | -------- | -------- |
441| 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.|
442
443**Example**
444
445```js
446let record = pasteboard.createUriRecord('dataability:///com.example.myapplication1/user.txt');
447record.convertToText((err, data) => {
448    if (err) {
449        console.error(`Failed to convert to text. Cause: ${err.message}`);
450        return;
451    }
452    console.info(`Succeeded in converting to text. Data: ${data}`);
453});
454```
455
456### convertToText<sup>(deprecated)</sup>
457
458convertToText(): Promise&lt;string&gt;
459
460Forcibly converts the content in a **PasteData** object to text. This API uses a promise to return the result.
461> **NOTE**
462>
463> This API is supported since API version 7 and deprecated since API version 9. You are advised to use [toPlainText](#toplaintext9).
464
465**System capability**: SystemCapability.MiscServices.Pasteboard
466
467**Return value**
468
469| Type| Description|
470| -------- | -------- |
471| Promise&lt;string&gt; | Promise used to return the text obtained from the conversion.|
472
473**Example**
474
475```js
476let record = pasteboard.createUriRecord('dataability:///com.example.myapplication1/user.txt');
477record.convertToText().then((data) => {
478    console.info(`Succeeded in converting to text. Data: ${data}`);
479}).catch((err) => {
480    console.error(`Failed to convert to text. Cause: ${err.message}`);
481});
482```
483
484## PasteData
485
486Provides **PasteData** APIs.
487
488Before calling any **PasteData** API, you must obtain a **PasteData** object.
489
490**System capability**: SystemCapability.MiscServices.Pasteboard
491
492### getPrimaryText
493
494getPrimaryText(): string
495
496Obtains the plain text of the primary record.
497
498**System capability**: SystemCapability.MiscServices.Pasteboard
499
500**Return value**
501
502| Type| Description|
503| -------- | -------- |
504| string | Plain text.|
505
506**Example**
507
508```js
509let pasteData = pasteboard.createData(pasteboard.MIMETYPE_TEXT_PLAIN, 'hello');
510let plainText = pasteData.getPrimaryText();
511```
512
513### getPrimaryHtml<sup>7+</sup>
514
515getPrimaryHtml(): string
516
517Obtains the HTML content of the primary record.
518
519**System capability**: SystemCapability.MiscServices.Pasteboard
520
521**Return value**
522
523| Type| Description|
524| -------- | -------- |
525| string | HTML content.|
526
527**Example**
528
529```js
530let 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>";
531let pasteData = pasteboard.createData(pasteboard.MIMETYPE_TEXT_HTML, html);
532let htmlText = pasteData.getPrimaryHtml();
533```
534
535### getPrimaryWant<sup>7+</sup>
536
537getPrimaryWant(): Want
538
539Obtains the Want object of the primary record.
540
541**System capability**: SystemCapability.MiscServices.Pasteboard
542
543**Return value**
544
545| Type| Description|
546| -------- | -------- |
547| [Want](js-apis-app-ability-want.md) | Want object.|
548
549**Example**
550
551```js
552let object = {
553    bundleName: "com.example.aafwk.test",
554    abilityName: "com.example.aafwk.test.TwoAbility"
555};
556let pasteData = pasteboard.createData(pasteboard.MIMETYPE_TEXT_WANT, object);
557let want = pasteData.getPrimaryWant();
558```
559
560### getPrimaryUri<sup>7+</sup>
561
562getPrimaryUri(): string
563
564Obtains the URI of the primary record.
565
566**System capability**: SystemCapability.MiscServices.Pasteboard
567
568**Return value**
569
570| Type| Description|
571| -------- | -------- |
572| string | URI content.|
573
574**Example**
575
576```js
577let pasteData = pasteboard.createData(pasteboard.MIMETYPE_TEXT_URI, 'dataability:///com.example.myapplication1/user.txt');
578let uri = pasteData.getPrimaryUri();
579```
580
581### getPrimaryPixelMap<sup>9+</sup>
582
583getPrimaryPixelMap(): image.PixelMap
584
585Obtains the pixel map of the primary record.
586
587**System capability**: SystemCapability.MiscServices.Pasteboard
588
589**Return value**
590
591| Type| Description|
592| -------- | -------- |
593| [image.PixelMap](js-apis-image.md#pixelmap7) | Pixel map.|
594
595**Example**
596
597```js
598import image from '@ohos.multimedia.image';
599
600let buffer = new ArrayBuffer(128);
601let opt = {
602  size: { height: 3, width: 5 },
603  pixelFormat: 3,
604  editable: true,
605  alphaType: 1,
606  scaleMode: 1
607};
608image.createPixelMap(buffer, opt).then((pixelMap) => {
609    let pasteData = pasteboard.createData(pasteboard.MIMETYPE_PIXELMAP, pixelMap);
610    let PixelMap = pasteData.getPrimaryPixelMap();
611});
612```
613
614### addRecord<sup>7+</sup>
615
616addRecord(record: PasteDataRecord): void
617
618Adds a data record to this pasteboard, and adds its type to **mimeTypes** in [PasteDataProperty](#pastedataproperty7). The parameters cannot be empty. Otherwise, the operation fails.
619
620The pasteboard supports a maximum number of 512 data records.
621
622**System capability**: SystemCapability.MiscServices.Pasteboard
623
624**Parameters**
625
626| Name| Type| Mandatory| Description|
627| -------- | -------- | -------- | -------- |
628| record | [PasteDataRecord](#pastedatarecord7) | Yes| Record to add.|
629
630**Example**
631
632```js
633let pasteData = pasteboard.createData(pasteboard.MIMETYPE_TEXT_URI, 'dataability:///com.example.myapplication1/user.txt');
634let textRecord = pasteboard.createRecord(pasteboard.MIMETYPE_TEXT_PLAIN, 'hello');
635let 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>";
636let htmlRecord = pasteboard.createRecord(pasteboard.MIMETYPE_TEXT_HTML, html);
637pasteData.addRecord(textRecord);
638pasteData.addRecord(htmlRecord);
639```
640### addRecord<sup>9+</sup>
641
642addRecord(mimeType: string, value: ValueType): void
643
644Adds 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.
645
646The pasteboard supports a maximum number of 512 data records.
647
648**System capability**: SystemCapability.MiscServices.Pasteboard
649
650**Parameters**
651
652| Name| Type| Mandatory| Description|
653| -------- | -------- | -------- | -------- |
654| mimeType | string | Yes| MIME type of custom data.|
655| value | [ValueType](#valuetype9) | Yes| Content of custom data.|
656
657**Error codes**
658
659For details about the error codes, see [Pasteboard Error Codes](../errorcodes/errorcode-pasteboard.md).
660
661| Error Code ID| Error Message|
662| -------- | -------- |
663| 12900002 | The number of record exceeds the maximum limit. |
664
665**Example**
666
667  ```js
668  let pasteData = pasteboard.createData(pasteboard.MIMETYPE_TEXT_URI, 'dataability:///com.example.myapplication1/user.txt');
669let dataXml = new ArrayBuffer(256);
670pasteData.addRecord('app/xml', dataXml);
671  ```
672
673### getMimeTypes<sup>7+</sup>
674
675getMimeTypes(): Array&lt;string&gt;
676
677Obtains a list of **mimeTypes** objects in [PasteDataProperty](#pastedataproperty7) from this pasteboard. If the pasteboard is empty, the returned list is also empty.
678
679**System capability**: SystemCapability.MiscServices.Pasteboard
680
681**Return value**
682
683| Type| Description|
684| -------- | -------- |
685| Array&lt;string&gt; | Non-repeating data types of the data records on the pasteboard.|
686
687**Example**
688
689```js
690let pasteData = pasteboard.createData(pasteboard.MIMETYPE_TEXT_PLAIN, 'hello');
691let types = pasteData.getMimeTypes();
692```
693
694### getPrimaryMimeType<sup>7+</sup>
695
696getPrimaryMimeType(): string
697
698Obtains the data type of the primary record in this pasteboard.
699
700**System capability**: SystemCapability.MiscServices.Pasteboard
701
702**Return value**
703
704| Type| Description|
705| -------- | -------- |
706| string | Data type of the primary record.|
707
708**Example**
709
710```js
711let pasteData = pasteboard.createData(pasteboard.MIMETYPE_TEXT_PLAIN, 'hello');
712let type = pasteData.getPrimaryMimeType();
713```
714
715### getProperty<sup>7+</sup>
716
717getProperty(): PasteDataProperty
718
719Obtains the property of the pasteboard data.
720
721**System capability**: SystemCapability.MiscServices.Pasteboard
722
723**Return value**
724
725| Type| Description|
726| -------- | -------- |
727| [PasteDataProperty](#pastedataproperty7) | Property of the pasteboard data.|
728
729**Example**
730
731```js
732let pasteData = pasteboard.createData(pasteboard.MIMETYPE_TEXT_PLAIN, 'hello');
733let property = pasteData.getProperty();
734```
735
736### setProperty<sup>9+</sup>
737
738setProperty(property: PasteDataProperty): void
739
740Sets the property (attributes) for the pasteboard data. Currently, only the **shareOption** attribute is supported.
741
742**System capability**: SystemCapability.MiscServices.Pasteboard
743
744**Parameters**
745
746| Name| Type| Mandatory| Description|
747| -------- | -------- | -------- | -------- |
748| property | [PasteDataProperty](#pastedataproperty7) | Yes| Property of the pasteboard data.|
749
750**Example**
751
752```js
753let pasteData = pasteboard.createData(pasteboard.MIMETYPE_TEXT_HTML, 'application/xml');
754let prop = pasteData.getProperty();
755prop.shareOption = pasteboard.ShareOption.INAPP;
756pasteData.setProperty(prop);
757```
758
759### getRecord<sup>9+</sup>
760
761getRecord(index: number): PasteDataRecord
762
763Obtains the specified record in the pasteboard.
764
765**System capability**: SystemCapability.MiscServices.Pasteboard
766
767**Parameters**
768
769| Name| Type| Mandatory| Description|
770| -------- | -------- | -------- | -------- |
771| index | number | Yes| Index of the target record.|
772
773**Return value**
774
775| Type| Description|
776| -------- | -------- |
777| [PasteDataRecord](#pastedatarecord7) | Record with the specified index.|
778
779**Error codes**
780
781For details about the error codes, see [Pasteboard Error Codes](../errorcodes/errorcode-pasteboard.md).
782
783| Error Code ID| Error Message|
784| -------- | -------- |
785| 12900001 | The index is out of the record. |
786
787**Example**
788
789```js
790let pasteData = pasteboard.createData(pasteboard.MIMETYPE_TEXT_PLAIN, 'hello');
791let record = pasteData.getRecord(0);
792```
793
794### getRecordCount<sup>7+</sup>
795
796getRecordCount(): number
797
798Obtains the number of records in the pasteboard.
799
800**System capability**: SystemCapability.MiscServices.Pasteboard
801
802**Return value**
803
804| Type| Description|
805| -------- | -------- |
806| number | Number of records.|
807
808**Example**
809
810```js
811let pasteData = pasteboard.createData(pasteboard.MIMETYPE_TEXT_PLAIN, 'hello');
812let count = pasteData.getRecordCount();
813```
814
815### getTag<sup>7+</sup>
816
817getTag(): string
818
819Obtains the custom tag from the pasteboard. If no custom tag is set, null is returned.
820
821**System capability**: SystemCapability.MiscServices.Pasteboard
822
823**Return value**
824
825| Type| Description|
826| -------- | -------- |
827| string | Custom tag. If no custom tag is set, null is returned.|
828
829**Example**
830
831```js
832let pasteData = pasteboard.createData(pasteboard.MIMETYPE_TEXT_PLAIN, 'hello');
833let tag = pasteData.getTag();
834```
835
836### hasType<sup>9+</sup>
837
838hasType(mimeType: string): boolean
839
840Checks whether the pasteboard contains data of the specified type.
841
842**System capability**: SystemCapability.MiscServices.Pasteboard
843
844**Parameters**
845
846| Name| Type| Mandatory| Description|
847| -------- | -------- | -------- | -------- |
848| mimeType | string | Yes| Type of the data to query.|
849
850**Return value**
851
852| Type| Description|
853| -------- | -------- |
854| boolean | Returns **true** if the specified data type exists; returns **false** otherwise.|
855
856**Example**
857
858```js
859let pasteData = pasteboard.createData(pasteboard.MIMETYPE_TEXT_PLAIN, 'hello');
860let hasType = pasteData.hasType(pasteboard.MIMETYPE_TEXT_PLAIN);
861```
862
863### removeRecord<sup>9+</sup>
864
865removeRecord(index: number): void
866
867Removes the record with the specified index from the pasteboard.
868
869**System capability**: SystemCapability.MiscServices.Pasteboard
870
871**Parameters**
872
873| Name| Type| Mandatory| Description|
874| -------- | -------- | -------- | -------- |
875| index | number | Yes| Specified index.|
876
877**Error codes**
878
879For details about the error codes, see [Pasteboard Error Codes](../errorcodes/errorcode-pasteboard.md).
880
881| Error Code ID| Error Message|
882| -------- | -------- |
883| 12900001 | The index is out of the record. |
884
885**Example**
886
887```js
888let pasteData = pasteboard.createData(pasteboard.MIMETYPE_TEXT_PLAIN, 'hello');
889pasteData.removeRecord(0);
890```
891
892### replaceRecord<sup>9+</sup>
893
894replaceRecord(index: number, record: PasteDataRecord): void
895
896Replaces the record with the specified index in the pasteboard with a new record.
897
898**System capability**: SystemCapability.MiscServices.Pasteboard
899
900**Parameters**
901
902| Name| Type| Mandatory| Description|
903| -------- | -------- | -------- | -------- |
904| index | number | Yes| Specified index.|
905| record | [PasteDataRecord](#pastedatarecord7) | Yes| New record.|
906
907**Error codes**
908
909For details about the error codes, see [Pasteboard Error Codes](../errorcodes/errorcode-pasteboard.md).
910
911| Error Code ID| Error Message|
912| -------- | -------- |
913| 12900001 | The index is out of the record. |
914
915**Example**
916
917```js
918let pasteData = pasteboard.createData(pasteboard.MIMETYPE_TEXT_PLAIN, 'hello');
919let record = pasteboard.createRecord(pasteboard.MIMETYPE_TEXT_URI, 'dataability:///com.example.myapplication1/user.txt');
920pasteData.replaceRecord(0, record);
921```
922### addHtmlRecord<sup>(deprecated)</sup>
923
924addHtmlRecord(htmlText: string): void
925
926Adds 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.
927
928The pasteboard supports a maximum number of 512 data records.
929> **NOTE**
930>
931> This API is supported since API version 7 and deprecated since API version 9. You are advised to use [addRecord](#addrecord9).
932
933**System capability**: SystemCapability.MiscServices.Pasteboard
934
935**Parameters**
936
937| Name| Type| Mandatory| Description|
938| -------- | -------- | -------- | -------- |
939| htmlText | string | Yes| HTML content.|
940
941**Example**
942
943```js
944let pasteData = pasteboard.createPlainTextData('hello');
945let 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>";
946pasteData.addHtmlRecord(html);
947```
948
949### addWantRecord<sup>(deprecated)</sup>
950
951addWantRecord(want: Want): void
952
953Adds 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.
954
955The pasteboard supports a maximum number of 512 data records.
956> **NOTE**
957>
958> This API is supported since API version 7 and deprecated since API version 9. You are advised to use [addRecord](#addrecord9).
959
960**System capability**: SystemCapability.MiscServices.Pasteboard
961
962**Parameters**
963
964| Name| Type| Mandatory| Description|
965| -------- | -------- | -------- | -------- |
966| want | [Want](js-apis-app-ability-want.md) | Yes| Want object.|
967
968**Example**
969
970```js
971let pasteData = pasteboard.createPlainTextData('hello');
972let object = {
973    bundleName: "com.example.aafwk.test",
974    abilityName: "com.example.aafwk.test.TwoAbility"
975};
976pasteData.addWantRecord(object);
977```
978
979### addTextRecord<sup>(deprecated)</sup>
980
981addTextRecord(text: string): void
982
983Adds 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.
984
985The pasteboard supports a maximum number of 512 data records.
986> **NOTE**
987>
988> This API is supported since API version 7 and deprecated since API version 9. You are advised to use [addRecord](#addrecord9).
989
990**System capability**: SystemCapability.MiscServices.Pasteboard
991
992**Parameters**
993
994| Name| Type| Mandatory| Description|
995| -------- | -------- | -------- | -------- |
996| text | string | Yes| Plain text.|
997
998**Example**
999
1000```js
1001let pasteData = pasteboard.createPlainTextData('hello');
1002pasteData.addTextRecord('good');
1003```
1004
1005### addUriRecord<sup>(deprecated)</sup>
1006
1007addUriRecord(uri: string): void
1008
1009Adds 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.
1010
1011The pasteboard supports a maximum number of 512 data records.
1012> **NOTE**
1013>
1014> This API is supported since API version 7 and deprecated since API version 9. You are advised to use [addRecord](#addrecord9).
1015
1016**System capability**: SystemCapability.MiscServices.Pasteboard
1017
1018**Parameters**
1019
1020| Name| Type| Mandatory| Description|
1021| -------- | -------- | -------- | -------- |
1022| uri | string | Yes| URI content.|
1023
1024**Example**
1025
1026```js
1027let pasteData = pasteboard.createPlainTextData('hello');
1028pasteData.addUriRecord('dataability:///com.example.myapplication1/user.txt');
1029```
1030### getRecordAt<sup>(deprecated)</sup>
1031
1032getRecordAt(index: number): PasteDataRecord
1033
1034Obtains the specified record in the pasteboard.
1035> **NOTE**
1036>
1037> This API is supported since API version 7 and deprecated since API version 9. You are advised to use [getRecord](#getrecord9).
1038
1039**System capability**: SystemCapability.MiscServices.Pasteboard
1040
1041**Parameters**
1042
1043| Name| Type| Mandatory| Description|
1044| -------- | -------- | -------- | -------- |
1045| index | number | Yes| Index of the target record.|
1046
1047**Return value**
1048
1049| Type| Description|
1050| -------- | -------- |
1051| [PasteDataRecord](#pastedatarecord7) | Record with the specified index.|
1052
1053**Example**
1054
1055```js
1056let pasteData = pasteboard.createPlainTextData('hello');
1057let record = pasteData.getRecordAt(0);
1058```
1059
1060### hasMimeType<sup>(deprecated)</sup>
1061
1062hasMimeType(mimeType: string): boolean
1063
1064Checks whether the pasteboard contains data of the specified type.
1065> **NOTE**
1066>
1067> This API is supported since API version 7 and deprecated since API version 9. You are advised to use [hasType](#hastype9).
1068
1069**System capability**: SystemCapability.MiscServices.Pasteboard
1070
1071**Parameters**
1072
1073| Name| Type| Mandatory| Description|
1074| -------- | -------- | -------- | -------- |
1075| mimeType | string | Yes| Type of the data to query.|
1076
1077**Return value**
1078
1079| Type| Description|
1080| -------- | -------- |
1081| boolean | Returns **true** if the specified data type exists; returns **false** otherwise.|
1082
1083**Example**
1084
1085```js
1086let pasteData = pasteboard.createPlainTextData('hello');
1087let hasType = pasteData.hasMimeType(pasteboard.MIMETYPE_TEXT_PLAIN);
1088```
1089### removeRecordAt<sup>(deprecated)</sup>
1090
1091removeRecordAt(index: number): boolean
1092
1093Removes the record with the specified index from the pasteboard.
1094> **NOTE**
1095>
1096> This API is supported since API version 7 and deprecated since API version 9. You are advised to use [removeRecord](#removerecord9).
1097
1098**System capability**: SystemCapability.MiscServices.Pasteboard
1099
1100**Parameters**
1101
1102| Name| Type| Mandatory| Description|
1103| -------- | -------- | -------- | -------- |
1104| index | number | Yes| Specified index.|
1105
1106**Return value**
1107
1108| Type| Description|
1109| -------- | -------- |
1110| boolean | Returns **true** if the operation is successful; returns **false** otherwise.|
1111
1112**Example**
1113
1114```js
1115let pasteData = pasteboard.createPlainTextData('hello');
1116let isRemove = pasteData.removeRecordAt(0);
1117```
1118### replaceRecordAt<sup>(deprecated)</sup>
1119
1120replaceRecordAt(index: number, record: PasteDataRecord): boolean
1121
1122Replaces the record with the specified index in the pasteboard with a new record.
1123> **NOTE**
1124>
1125> This API is supported since API version 7 and deprecated since API version 9. You are advised to use [replaceRecord](#replacerecord9).
1126
1127**System capability**: SystemCapability.MiscServices.Pasteboard
1128
1129**Parameters**
1130
1131| Name| Type| Mandatory| Description|
1132| -------- | -------- | -------- | -------- |
1133| index | number | Yes| Specified index.|
1134| record | [PasteDataRecord](#pastedatarecord7) | Yes| New record.|
1135
1136**Return value**
1137
1138| Type| Description|
1139| -------- | -------- |
1140| boolean | Returns **true** if the operation is successful; returns **false** otherwise.|
1141
1142**Example**
1143
1144```js
1145let pasteData = pasteboard.createPlainTextData('hello');
1146let record = pasteboard.createUriRecord('dataability:///com.example.myapplication1/user.txt');
1147let isReplace = pasteData.replaceRecordAt(0, record);
1148```
1149
1150## SystemPasteboard
1151
1152Provides **SystemPasteboard** APIs.
1153
1154Before calling any **SystemPasteboard** API, you must obtain a **SystemPasteboard** object using [getSystemPasteboard](#pasteboardgetsystempasteboard).
1155
1156```js
1157let systemPasteboard = pasteboard.getSystemPasteboard();
1158```
1159
1160### on('update')<sup>7+</sup>
1161
1162on(type:  'update', callback: () =&gt;void ): void
1163
1164Subscribes to the content change event of the system pasteboard.
1165
1166**System capability**: SystemCapability.MiscServices.Pasteboard
1167
1168**Parameters**
1169
1170| Name| Type| Mandatory| Description|
1171| -------- | -------- | -------- | -------- |
1172| type | string | Yes| Event type. The value **'update'** indicates changes in the pasteboard content.|
1173| callback | function | Yes| Callback invoked when the pasteboard content changes.|
1174
1175**Example**
1176
1177```js
1178let systemPasteboard = pasteboard.getSystemPasteboard();
1179let listener = () => {
1180    console.info('The system pasteboard has changed.');
1181};
1182systemPasteboard.on('update', listener);
1183```
1184
1185### off('update')<sup>7+</sup>
1186
1187off(type:  'update', callback?: () =&gt;void ): void
1188
1189Unsubscribes from the system pasteboard content change event.
1190
1191**System capability**: SystemCapability.MiscServices.Pasteboard
1192
1193**Parameters**
1194
1195| Name| Type| Mandatory| Description|
1196| -------- | -------- | -------- | -------- |
1197| type | string | Yes| Event type. The value **'update'** indicates changes in the pasteboard content.|
1198| callback | function | No| Callback invoked when the pasteboard content changes.|
1199
1200**Example**
1201
1202```js
1203let systemPasteboard = pasteboard.getSystemPasteboard();
1204let listener = () => {
1205    console.info('The system pasteboard has changed.');
1206};
1207systemPasteboard.off('update', listener);
1208```
1209
1210### clearData<sup>9+</sup>
1211
1212clearData(callback: AsyncCallback&lt;void&gt;): void
1213
1214Clears the system pasteboard. This API uses an asynchronous callback to return the result.
1215
1216**System capability**: SystemCapability.MiscServices.Pasteboard
1217
1218**Parameters**
1219
1220| Name| Type| Mandatory| Description|
1221| -------- | -------- | -------- | -------- |
1222| 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.|
1223
1224**Example**
1225
1226```js
1227let systemPasteboard = pasteboard.getSystemPasteboard();
1228systemPasteboard.clearData((err, data) => {
1229    if (err) {
1230        console.error(`Failed to clear the pasteboard. Cause: ${err.message}`);
1231        return;
1232    }
1233    console.info('Succeeded in clearing the pasteboard.');
1234});
1235```
1236
1237### clearData<sup>9+</sup>
1238
1239clearData(): Promise&lt;void&gt;
1240
1241Clears the system pasteboard. This API uses a promise to return the result.
1242
1243**System capability**: SystemCapability.MiscServices.Pasteboard
1244
1245**Return value**
1246
1247| Type| Description|
1248| -------- | -------- |
1249| Promise&lt;void&gt; | Promise that returns no value.|
1250
1251**Example**
1252
1253```js
1254let systemPasteboard = pasteboard.getSystemPasteboard();
1255systemPasteboard.clearData().then((data) => {
1256    console.info('Succeeded in clearing the pasteboard.');
1257}).catch((err) => {
1258    console.error(`Failed to clear the pasteboard. Cause: ${err.message}`);
1259});
1260```
1261
1262### setData<sup>9+</sup>
1263
1264setData(data: PasteData, callback: AsyncCallback&lt;void&gt;): void
1265
1266Writes a **PasteData** object to the pasteboard. This API uses an asynchronous callback to return the result.
1267
1268**System capability**: SystemCapability.MiscServices.Pasteboard
1269
1270**Parameters**
1271
1272| Name| Type| Mandatory| Description|
1273| -------- | -------- | -------- | -------- |
1274| data | [PasteData](#pastedata) | Yes| **PasteData** object.|
1275| 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.|
1276
1277**Error codes**
1278
1279For details about the error codes, see [Pasteboard Error Codes](../errorcodes/errorcode-pasteboard.md).
1280
1281| Error Code ID| Error Message|
1282| -------- | -------- |
1283| 12900003 | Another copy or paste is in progress. |
1284| 12900004 | Replication is prohibited. |
1285
1286**Example**
1287
1288```js
1289let pasteData = pasteboard.createPlainTextData('content');
1290let systemPasteboard = pasteboard.getSystemPasteboard();
1291systemPasteboard.setData(pasteData, (err, data) => {
1292    if (err) {
1293        console.error('Failed to set PasteData. Cause: ' + err.message);
1294        return;
1295    }
1296    console.info('Succeeded in setting PasteData.');
1297});
1298```
1299
1300### setData<sup>9+</sup>
1301
1302setData(data: PasteData): Promise&lt;void&gt;
1303
1304Writes a **PasteData** object to the pasteboard. This API uses a promise to return the result.
1305
1306**System capability**: SystemCapability.MiscServices.Pasteboard
1307
1308**Parameters**
1309
1310| Name| Type| Mandatory| Description|
1311| -------- | -------- | -------- | -------- |
1312| data | [PasteData](#pastedata) | Yes| **PasteData** object.|
1313
1314**Return value**
1315
1316| Type| Description|
1317| -------- | -------- |
1318| Promise&lt;void&gt; | Promise that returns no value.|
1319
1320**Error codes**
1321
1322For details about the error codes, see [Pasteboard Error Codes](../errorcodes/errorcode-pasteboard.md).
1323
1324| Error Code ID| Error Message|
1325| -------- | -------- |
1326| 12900003 | Another copy or paste is in progress. |
1327| 12900004 | Replication is prohibited. |
1328
1329**Example**
1330
1331```js
1332let pasteData = pasteboard.createPlainTextData('content');
1333let systemPasteboard = pasteboard.getSystemPasteboard();
1334systemPasteboard.setData(pasteData).then((data) => {
1335    console.info('Succeeded in setting PasteData.');
1336}).catch((err) => {
1337    console.error('Failed to set PasteData. Cause: ' + err.message);
1338});
1339```
1340
1341### getData<sup>9+</sup>
1342
1343getData( callback: AsyncCallback&lt;PasteData&gt;): void
1344
1345Obtains a **PasteData** object from the pasteboard. This API uses an asynchronous callback to return the result.
1346
1347**System capability**: SystemCapability.MiscServices.Pasteboard
1348
1349**Parameters**
1350
1351| Name| Type| Mandatory| Description|
1352| -------- | -------- | -------- | -------- |
1353| 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.|
1354
1355**Error codes**
1356
1357For details about the error codes, see [Pasteboard Error Codes](../errorcodes/errorcode-pasteboard.md).
1358
1359| Error Code ID| Error Message|
1360| -------- | -------- |
1361| 12900003 | Another copy or paste is in progress. |
1362
1363**Example**
1364
1365```js
1366let systemPasteboard = pasteboard.getSystemPasteboard();
1367systemPasteboard.getData((err, pasteData) => {
1368    if (err) {
1369        console.error('Failed to get PasteData. Cause: ' + err.message);
1370        return;
1371    }
1372    let text = pasteData.getPrimaryText();
1373});
1374```
1375
1376### getData<sup>9+</sup>
1377
1378getData(): Promise&lt;PasteData&gt;
1379
1380Obtains a **PasteData** object from the pasteboard. This API uses a promise to return the result.
1381
1382**System capability**: SystemCapability.MiscServices.Pasteboard
1383
1384**Return value**
1385
1386| Type| Description|
1387| -------- | -------- |
1388| Promise&lt;[PasteData](#pastedata)&gt; | Promise used to return the system pasteboard data.|
1389
1390**Error codes**
1391
1392For details about the error codes, see [Pasteboard Error Codes](../errorcodes/errorcode-pasteboard.md).
1393
1394| Error Code ID| Error Message|
1395| -------- | -------- |
1396| 12900003 | Another copy or paste is in progress. |
1397
1398**Example**
1399
1400```js
1401let systemPasteboard = pasteboard.getSystemPasteboard();
1402systemPasteboard.getData().then((pasteData) => {
1403    let text = pasteData.getPrimaryText();
1404}).catch((err) => {
1405    console.error('Failed to get PasteData. Cause: ' + err.message);
1406})
1407```
1408
1409### hasData<sup>9+</sup>
1410
1411hasData(callback:  AsyncCallback&lt;boolean&gt;): void
1412
1413Checks whether the system pasteboard contains data. This API uses an asynchronous callback to return the result.
1414
1415**System capability**: SystemCapability.MiscServices.Pasteboard
1416
1417**Parameters**
1418
1419| Name| Type| Mandatory| Description|
1420| -------- | -------- | -------- | -------- |
1421| callback | AsyncCallback&lt;boolean&gt; | Yes| Callback used to return the result. Returns **true** if the system pasteboard contains data; returns **false** otherwise.|
1422
1423**Example**
1424
1425```js
1426let systemPasteboard = pasteboard.getSystemPasteboard();
1427systemPasteboard.hasData((err, data) => {
1428    if (err) {
1429        console.error(`Failed to check the PasteData. Cause: ${err.message}`);
1430        return;
1431    }
1432    console.info(`Succeeded in checking the PasteData. Data: ${data}`);
1433});
1434```
1435
1436### hasData<sup>9+</sup>
1437
1438hasData(): Promise&lt;boolean&gt;
1439
1440Checks whether the system pasteboard contains data. This API uses a promise to return the result.
1441
1442**System capability**: SystemCapability.MiscServices.Pasteboard
1443
1444**Return value**
1445
1446| Type| Description|
1447| -------- | -------- |
1448| Promise&lt;boolean&gt; | Promise used to return the result. Returns **true** if the system pasteboard contains data; returns **false** otherwise.|
1449
1450**Example**
1451
1452```js
1453let systemPasteboard = pasteboard.getSystemPasteboard();
1454systemPasteboard.hasData().then((data) => {
1455    console.info(`Succeeded in checking the PasteData. Data: ${data}`);
1456}).catch((err) => {
1457    console.error(`Failed to check the PasteData. Cause: ${err.message}`);
1458});
1459```
1460
1461### clear<sup>(deprecated)</sup>
1462
1463clear(callback: AsyncCallback&lt;void&gt;): void
1464
1465Clears the system pasteboard. This API uses an asynchronous callback to return the result.
1466> **NOTE**
1467>
1468> This API is supported since API version 7 and deprecated since API version 9. You are advised to use [pasteboard.clearData](#cleardata9).
1469
1470**System capability**: SystemCapability.MiscServices.Pasteboard
1471
1472**Parameters**
1473
1474| Name| Type| Mandatory| Description|
1475| -------- | -------- | -------- | -------- |
1476| 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.|
1477
1478**Example**
1479
1480```js
1481systemPasteboard.clear((err, data) => {
1482    if (err) {
1483        console.error(`Failed to clear the PasteData. Cause: ${err.message}`);
1484        return;
1485    }
1486    console.info('Succeeded in clearing the PasteData.');
1487});
1488```
1489
1490### clear<sup>(deprecated)</sup>
1491
1492clear(): Promise&lt;void&gt;
1493
1494Clears the system pasteboard. This API uses a promise to return the result.
1495> **NOTE**
1496>
1497> This API is supported since API version 7 and deprecated since API version 9. You are advised to use [pasteboard.clearData](#cleardata9-1).
1498
1499**System capability**: SystemCapability.MiscServices.Pasteboard
1500
1501**Return value**
1502
1503| Type| Description|
1504| -------- | -------- |
1505| Promise&lt;void&gt; | Promise that returns no value.|
1506
1507**Example**
1508
1509```js
1510systemPasteboard.clear().then((data) => {
1511    console.info('Succeeded in clearing the PasteData.');
1512}).catch((err) => {
1513    console.error(`Failed to clear the PasteData. Cause: ${err.message}`);
1514});
1515```
1516
1517### getPasteData<sup>(deprecated)</sup>
1518
1519getPasteData( callback: AsyncCallback&lt;PasteData&gt;): void
1520
1521Obtains a **PasteData** object from the pasteboard. This API uses an asynchronous callback to return the result.
1522> **NOTE**
1523>
1524> This API is supported since API version 6 and deprecated since API version 9. You are advised to use [getData](#getdata9).
1525
1526**System capability**: SystemCapability.MiscServices.Pasteboard
1527
1528**Parameters**
1529
1530| Name| Type| Mandatory| Description|
1531| -------- | -------- | -------- | -------- |
1532| 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.|
1533
1534**Example**
1535
1536```js
1537let systemPasteboard = pasteboard.getSystemPasteboard();
1538systemPasteboard.getPasteData((err, pasteData) => {
1539    if (err) {
1540        console.error('Failed to get PasteData. Cause: ' + err.message);
1541        return;
1542    }
1543    let text = pasteData.getPrimaryText();
1544});
1545```
1546
1547### getPasteData<sup>(deprecated)</sup>
1548
1549getPasteData(): Promise&lt;PasteData&gt;
1550
1551Obtains a **PasteData** object from the pasteboard. This API uses a promise to return the result.
1552> **NOTE**
1553>
1554> This API is supported since API version 6 and deprecated since API version 9. You are advised to use [getData](#getdata9-1).
1555
1556**System capability**: SystemCapability.MiscServices.Pasteboard
1557
1558**Return value**
1559
1560| Type| Description|
1561| -------- | -------- |
1562| Promise&lt;[PasteData](#pastedata)&gt; | Promise used to return the system pasteboard data.|
1563
1564**Example**
1565
1566```js
1567let systemPasteboard = pasteboard.getSystemPasteboard();
1568systemPasteboard.getPasteData().then((pasteData) => {
1569    let text = pasteData.getPrimaryText();
1570}).catch((err) => {
1571    console.error('Failed to get PasteData. Cause: ' + err.message);
1572})
1573```
1574
1575### hasPasteData<sup>(deprecated)</sup>
1576
1577hasPasteData(callback:  AsyncCallback&lt;boolean&gt;): void
1578
1579Checks whether the system pasteboard contains data. This API uses an asynchronous callback to return the result.
1580> **NOTE**
1581>
1582> This API is supported since API version 7 and deprecated since API version 9. You are advised to use [hasData](#hasdata9).
1583
1584**System capability**: SystemCapability.MiscServices.Pasteboard
1585
1586**Parameters**
1587
1588| Name| Type| Mandatory| Description|
1589| -------- | -------- | -------- | -------- |
1590| callback | AsyncCallback&lt;boolean&gt; | Yes| Callback used to return the result. Returns **true** if the system pasteboard contains data; returns **false** otherwise.|
1591
1592**Example**
1593
1594```js
1595systemPasteboard.hasPasteData((err, data) => {
1596    if (err) {
1597        console.error(`Failed to check the PasteData. Cause: ${err.message}`);
1598        return;
1599    }
1600    console.info(`Succeeded in checking the PasteData. Data: ${data}`);
1601});
1602```
1603
1604### hasPasteData<sup>(deprecated)</sup>
1605
1606hasPasteData(): Promise&lt;boolean&gt;
1607
1608Checks whether the system pasteboard contains data. This API uses a promise to return the result.
1609> **NOTE**
1610>
1611> This API is supported since API version 7 and deprecated since API version 9. You are advised to use [hasData](#hasdata9-1).
1612
1613**System capability**: SystemCapability.MiscServices.Pasteboard
1614
1615**Return value**
1616
1617| Type| Description|
1618| -------- | -------- |
1619| Promise&lt;boolean&gt; | Promise used to return the result. Returns **true** if the system pasteboard contains data; returns **false** otherwise.|
1620
1621**Example**
1622
1623```js
1624systemPasteboard.hasPasteData().then((data) => {
1625    console.info(`Succeeded in checking the PasteData. Data: ${data}`);
1626}).catch((err) => {
1627    console.error(`Failed to check the PasteData. Cause: ${err.message}`);
1628});
1629```
1630
1631### setPasteData<sup>(deprecated)</sup>
1632
1633setPasteData(data: PasteData, callback: AsyncCallback&lt;void&gt;): void
1634
1635Writes a **PasteData** object to the pasteboard. This API uses an asynchronous callback to return the result.
1636> **NOTE**
1637>
1638> This API is supported since API version 7 and deprecated since API version 9. You are advised to use [setData](#setdata9).
1639
1640**System capability**: SystemCapability.MiscServices.Pasteboard
1641
1642**Parameters**
1643
1644| Name| Type| Mandatory| Description|
1645| -------- | -------- | -------- | -------- |
1646| data | [PasteData](#pastedata) | Yes| **PasteData** object.|
1647| 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.|
1648
1649**Example**
1650
1651```js
1652let pasteData = pasteboard.createPlainTextData('content');
1653let systemPasteboard = pasteboard.getSystemPasteboard();
1654systemPasteboard.setPasteData(pasteData, (err, data) => {
1655    if (err) {
1656        console.error('Failed to set PasteData. Cause: ' + err.message);
1657        return;
1658    }
1659    console.info('Succeeded in setting PasteData.');
1660});
1661```
1662### setPasteData<sup>(deprecated)</sup>
1663
1664setPasteData(data: PasteData): Promise&lt;void&gt;
1665
1666Writes a **PasteData** object to the pasteboard. This API uses a promise to return the result.
1667> **NOTE**
1668>
1669> This API is supported since API version 7 and deprecated since API version 9. You are advised to use [setData](#setdata9-1).
1670
1671**System capability**: SystemCapability.MiscServices.Pasteboard
1672
1673**Parameters**
1674
1675| Name| Type| Mandatory| Description|
1676| -------- | -------- | -------- | -------- |
1677| data | [PasteData](#pastedata) | Yes| **PasteData** object.|
1678
1679**Return value**
1680
1681| Type| Description|
1682| -------- | -------- |
1683| Promise&lt;void&gt; | Promise that returns no value.|
1684
1685**Example**
1686
1687```js
1688let pasteData = pasteboard.createPlainTextData('content');
1689let systemPasteboard = pasteboard.getSystemPasteboard();
1690systemPasteboard.setPasteData(pasteData).then((data) => {
1691    console.info('Succeeded in setting PasteData.');
1692}).catch((err) => {
1693    console.error('Failed to set PasteData. Cause: ' + err.message);
1694});
1695```
1696