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