1# Pasteboard 2 3 4## Overview 5 6The **Pasteboard** module supports copying and pasting multiple types of data, including plain text, HTML, URI, and pixel map. 7 8**Since**: 13 9 10 11## Summary 12 13 14### Files 15 16| Name| Description| 17| -------- | -------- | 18| [oh_pasteboard.h](oh__pasteboard_8h.md) | Provides data structure, enum types, and APIs for accessing the system pasteboard.| 19| [oh_pasteboard_err_code.h](oh__pasteboard__err__code_8h.md) | Declares the error code information of the pasteboard.| 20 21 22### Types 23 24| Name| Description| 25| -------- | -------- | 26| typedef enum [Pasteboard_NotifyType](#pasteboard_notifytype) [Pasteboard_NotifyType](#pasteboard_notifytype) | Defines an enum for the data change types of the pasteboard. | 27| typedef void(\* [Pasteboard_Notify](#pasteboard_notify)) (void \*context, [Pasteboard_NotifyType](#pasteboard_notifytype) type) | Defines a callback to be invoked when the pasteboard content changes. | 28| typedef void(\* [Pasteboard_Finalize](#pasteboard_finalize)) (void \*context) | Defines a callback to be invoked to release the context when the pasteboard observer object is destroyed. | 29| typedef struct [OH_PasteboardObserver](#oh_pasteboardobserver) [OH_PasteboardObserver](#oh_pasteboardobserver) | Defines a struct for the pasteboard observer. | 30| typedef struct [OH_Pasteboard](#oh_pasteboard) [OH_Pasteboard](#oh_pasteboard) | Defines a struct for the pasteboard object to operate the system pasteboard. | 31| typedef enum [PASTEBOARD_ErrCode](#pasteboard_errcode) [PASTEBOARD_ErrCode](#pasteboard_errcode) | Defines an enum for the error codes. | 32| typedef enum [Pasteboard_FileConflictOptions](#pasteboard_fileconflictoptions) [Pasteboard_FileConflictOptions](#pasteboard_fileconflictoptions) | Defines an enum for the file conflict options.| 33| typedef enum [Pasteboard_ProgressIndicator](#pasteboard_progressindicator) [Pasteboard_ProgressIndicator](#pasteboard_progressindicator) | Defines an enum for progress indicator options. You can use the default progress indicator as required.| 34| typedef struct [Pasteboard_ProgressInfo](#pasteboard_progressinfo) [Pasteboard_ProgressInfo](#pasteboard_progressinfo) | Defines a struct for the progress information. This information is reported only when [Pasteboard_ProgressIndicator](#pasteboard_progressindicator) is set to **PASTEBOARD_NONE**.| 35| typedef void (* [OH_Pasteboard_ProgressListener](#oh_pasteboard_progresslistener))([Pasteboard_ProgressInfo](#pasteboard_progressinfo)* progressInfo) | Defines a callback for obtaining the progress information. If the default progress indicator is not used, you can set this parameter to obtain the pasting progress.| 36| typedef struct [Pasteboard_GetDataParams](#pasteboard_getdataparams) [Pasteboard_GetDataParams](#pasteboard_getdataparams) | Defines a struct for the pasteboard parameters required for displaying progress, including progress indicator options, destination path, and file conflict options.| 37 38 39### Enums 40 41| Name| Description| 42| -------- | -------- | 43| [Pasteboard_NotifyType](#pasteboard_notifytype) { NOTIFY_LOCAL_DATA_CHANGE = 1, NOTIFY_REMOTE_DATA_CHANGE = 2 } | Enumerates the data change types of the pasteboard. | 44| [PASTEBOARD_ErrCode](#pasteboard_errcode) {<br>ERR_OK = 0, ERR_PERMISSION_ERROR = 201, ERR_INVALID_PARAMETER = 401, ERR_DEVICE_NOT_SUPPORTED = 801,<br>ERR_INNER_ERROR = 12900000, ERR_BUSY = 12900003, ERR_PASTEBOARD_COPY_FILE_ERROR = 12900007, ERR_PASTEBOARD_PROGRESS_START_ERROR = 12900008, ERR_PASTEBOARD_PROGRESS_ABNORMAL = 12900009, ERR_PASTEBOARD_GET_DATA_FAILED = 12900010, ERR_BUSY_PROCESSING = 27787277, ERR_COPY_FORBIDDEN = 27787278<br>} | Enumerates the error codes. | 45| [Pasteboard_FileConflictOptions](#pasteboard_fileconflictoptions) { PASTEBOARD_OVERWRITE = 0, PASTEBOARD_SKIP = 1} | Enumerates the file conflict options.| 46| [Pasteboard_ProgressIndicator](#pasteboard_progressindicator) { PASTEBOARD_NONE = 0, PASTEBOARD_DEFAULT = 1 } | Enumerates progress indicator types.| 47 48 49### Functions 50 51| Name| Description| 52| -------- | -------- | 53| [OH_PasteboardObserver](#oh_pasteboardobserver) \* [OH_PasteboardObserver_Create](#oh_pasteboardobserver_create) () | Creates an [OH_PasteboardObserver](#oh_pasteboardobserver) instance and a pointer to it. | 54| int [OH_PasteboardObserver_Destroy](#oh_pasteboardobserver_destroy) ([OH_PasteboardObserver](#oh_pasteboardobserver) \*observer) | Destroys an [OH_PasteboardObserver](#oh_pasteboardobserver) instance. | 55| int [OH_PasteboardObserver_SetData](#oh_pasteboardobserver_setdata) ([OH_PasteboardObserver](#oh_pasteboardobserver) \*observer, void \*context, const [Pasteboard_Notify](#pasteboard_notify) callback, const [Pasteboard_Finalize](#pasteboard_finalize) finalize) | Sets a callback for the pasteboard observer. | 56| [OH_Pasteboard](#oh_pasteboard) \* [OH_Pasteboard_Create](#oh_pasteboard_create) () | Creates an [OH_Pasteboard](#oh_pasteboard) instance and a pointer to it. | 57| void [OH_Pasteboard_Destroy](#oh_pasteboard_destroy) ([OH_Pasteboard](#oh_pasteboard) \*pasteboard) | Destroys an [OH_Pasteboard](#oh_pasteboard) instance. | 58| int [OH_Pasteboard_Subscribe](#oh_pasteboard_subscribe) ([OH_Pasteboard](#oh_pasteboard) \*pasteboard, int type, const [OH_PasteboardObserver](#oh_pasteboardobserver) \*observer) | Subscribes to the pasteboard observer. | 59| int [OH_Pasteboard_Unsubscribe](#oh_pasteboard_unsubscribe) ([OH_Pasteboard](#oh_pasteboard) \*pasteboard, int type, const [OH_PasteboardObserver](#oh_pasteboardobserver) \*observer) | Unsubscribes from the pasteboard observer. | 60| bool [OH_Pasteboard_IsRemoteData](#oh_pasteboard_isremotedata) ([OH_Pasteboard](#oh_pasteboard) \*pasteboard) | Checks whether the pasteboard data comes from remote devices. | 61| int [OH_Pasteboard_GetDataSource](#oh_pasteboard_getdatasource) ([OH_Pasteboard](#oh_pasteboard) \*pasteboard, char \*source, unsigned int len) | Obtains the pasteboard data source. | 62| bool [OH_Pasteboard_HasType](#oh_pasteboard_hastype) ([OH_Pasteboard](#oh_pasteboard) \*pasteboard, const char \*type) | Checks whether the pasteboard contains data of the specified type. | 63| bool [OH_Pasteboard_HasData](#oh_pasteboard_hasdata) ([OH_Pasteboard](#oh_pasteboard) \*pasteboard) | Checks whether the pasteboard contains data. | 64| OH_UdmfData \* [OH_Pasteboard_GetData](#oh_pasteboard_getdata) ([OH_Pasteboard](#oh_pasteboard) \*pasteboard, int \*status) | Obtains data from the pasteboard. | 65| int [OH_Pasteboard_SetData](#oh_pasteboard_setdata) ([OH_Pasteboard](#oh_pasteboard) \*pasteboard, OH_UdmfData \*data) | Writes the unified data object to the pasteboard. | 66| int [OH_Pasteboard_ClearData](#oh_pasteboard_cleardata) ([OH_Pasteboard](#oh_pasteboard) \*pasteboard) | Clears data from the pasteboard. | 67| char ** [OH_Pasteboard_GetMimeTypes](#oh_pasteboard_getmimetypes) ([OH_Pasteboard](#oh_pasteboard) \*pasteboard, unsigned int *count) | Obtains the MIME type from the pasteboard. | 68| [Pasteboard_GetDataParams](#pasteboard_getdataparams) *[OH_Pasteboard_GetDataParams_Create](#oh_pasteboard_getdataparams_create)(void) | Creates a [Pasteboard_GetDataParams](#pasteboard_getdataparams) instance and a pointer to it.| 69| void [OH_Pasteboard_GetDataParams_Destroy](#oh_pasteboard_getdataparams_destroy)([Pasteboard_GetDataParams](#pasteboard_getdataparams)* params) | Destroys a [Pasteboard_GetDataParams](#pasteboard_getdataparams) instance.| 70| void [OH_Pasteboard_GetDataParams_SetProgressIndicator](#oh_pasteboard_getdataparams_setprogressindicator)([Pasteboard_GetDataParams](#pasteboard_getdataparams)* params, [Pasteboard_ProgressIndicator](#pasteboard_progressindicator) progressIndicator) | Sets the progress indication options in [Pasteboard_GetDataParams](#pasteboard_getdataparams). You can use the default progress indicator as required.| 71| void [OH_Pasteboard_GetDataParams_SetDestUri](#oh_pasteboard_getdataparams_setdesturi)([Pasteboard_GetDataParams](#pasteboard_getdataparams)* params, const char* destUri, uint32_t destUriLen) | Sets the destination path in [Pasteboard_GetDataParams](#pasteboard_getdataparams).| 72| void [OH_Pasteboard_GetDataParams_SetFileConflictOptions](#oh_pasteboard_getdataparams_setfileconflictoptions)([Pasteboard_GetDataParams](#pasteboard_getdataparams)* params, [Pasteboard_FileConflictOptions](#pasteboard_fileconflictoptions) option) | Sets the file copy conflict options in [Pasteboard_GetDataParams](#pasteboard_getdataparams).| 73| void [OH_Pasteboard_GetDataParams_SetProgressListener](#oh_pasteboard_getdataparams_setprogresslistener)([Pasteboard_GetDataParams](#pasteboard_getdataparams)* params, const [OH_Pasteboard_ProgressListener](#oh_pasteboard_progresslistener) listener) | Sets a progress listener in [Pasteboard_GetDataParams](#pasteboard_getdataparams).| 74| int [OH_Pasteboard_ProgressInfo_GetProgress](#oh_pasteboard_progressinfo_getprogress)([Pasteboard_ProgressInfo](#pasteboard_progressinfo)* progressInfo) | Obtains the pasting progress using [Pasteboard_ProgressInfo](#pasteboard_progressinfo).| 75| void [OH_Pasteboard_ProgressCancel](#oh_pasteboard_progresscancel)([Pasteboard_GetDataParams](#pasteboard_getdataparams)* params) | Cancels an ongoing copy and paste task using [Pasteboard_GetDataParams](#pasteboard_getdataparams).| 76| OH_UdmfData* [OH_Pasteboard_GetDataWithProgress](#oh_pasteboard_getdatawithprogress)([OH_Pasteboard](#oh_pasteboard)* pasteboard, [Pasteboard_GetDataParams](#pasteboard_getdataparams)* params, int* status) | Obtains the pasteboard data and pasting progress. Folders cannot be copied.| 77| uint32_t [OH_Pasteboard_GetChangeCount](#oh_pasteboard_getchangecount) ([OH_Pasteboard](#oh_pasteboard) \*pasteboard) | Obtains the number of times that the pasteboard data changes. | 78 79 80## Type Description 81 82 83### OH_Pasteboard 84 85``` 86typedef struct OH_Pasteboard OH_Pasteboard 87``` 88**Description** 89 90Defines a struct for the pasteboard object to operate the system pasteboard. 91 92**Since**: 13 93 94 95### OH_PasteboardObserver 96 97``` 98typedef struct OH_PasteboardObserver OH_PasteboardObserver 99``` 100**Description** 101 102Defines a struct for the pasteboard observer. 103 104**Since**: 13 105 106 107### PASTEBOARD_ErrCode 108 109``` 110typedef enum PASTEBOARD_ErrCode PASTEBOARD_ErrCode 111``` 112**Description** 113 114Defines an enum for the error codes. 115 116**Since**: 13 117 118 119### Pasteboard_Finalize 120 121``` 122typedef void(* Pasteboard_Finalize) (void *context) 123``` 124**Description** 125 126Defines a callback to be invoked to release the context when the pasteboard observer object is destroyed. 127 128**Since**: 13 129 130**Parameters** 131 132| Name| Description| 133| -------- | -------- | 134| context | Pointer to the context to release. | 135 136 137### Pasteboard_Notify 138 139``` 140typedef void(* Pasteboard_Notify) (void *context, Pasteboard_NotifyType type) 141``` 142**Description** 143 144Defines a callback to be invoked when the pasteboard content changes. 145 146**Since**: 13 147 148**Parameters** 149 150| Name| Description| 151| -------- | -------- | 152| context | Context, which is passed in by the [OH_PasteboardObserver_SetData](#oh_pasteboardobserver_setdata) function. | 153| type | Data change type. For details, see [Pasteboard_NotifyType](#pasteboard_notifytype). | 154 155 156### Pasteboard_NotifyType 157 158``` 159typedef enum Pasteboard_NotifyType Pasteboard_NotifyType 160``` 161**Description** 162 163Defines an enum for the data change types of the pasteboard. 164 165**Since**: 13 166 167### Pasteboard_FileConflictOptions 168 169``` 170typedef enum Pasteboard_FileConflictOptions Pasteboard_FileConflictOptions 171``` 172 173**Description** 174 175Defines an enum for the file conflict options. The default value is **PASTEBOARD_OVERWRITE**. 176 177**Since**: 15 178 179### Pasteboard_ProgressIndicator 180 181``` 182typedef enum Pasteboard_ProgressIndicator Pasteboard_ProgressIndicator 183``` 184 185**Description** 186 187Defines an enum for progress indicator options. You can use the default progress indicator as required. 188 189**Since**: 15 190 191### Pasteboard_ProgressInfo 192 193``` 194typedef struct Pasteboard_ProgressInfo Pasteboard_ProgressInfo 195``` 196 197**Description** 198 199Defines a struct for the progress information. This information is reported only when [Pasteboard_ProgressIndicator](#pasteboard_progressindicator) is set to **NONE**. 200 201**Since**: 15 202 203### OH_Pasteboard_ProgressListener 204 205``` 206typedef void (*OH_Pasteboard_ProgressListener)(Pasteboard_ProgressInfo* progressInfo); 207``` 208 209**Description** 210 211Defines a callback to be invoked to obtain the progress information when the default progress indicator is not used. 212 213**Since**: 15 214 215**Parameters** 216 217| Name | Type | Description | 218| ------------ | --------------------------------------------------- | ------------------------------------------------------------ | 219| progressInfo | [Pasteboard_ProgressInfo](#pasteboard_progressinfo) | Defines the progress information. This information is reported only when [Pasteboard_ProgressIndicator](#pasteboard_progressindicator) is set to **NONE**.| 220 221### Pasteboard_GetDataParams 222 223``` 224typedef struct Pasteboard_GetDataParams Pasteboard_GetDataParams; 225``` 226 227**Description** 228 229Defines a struct for the pasteboard parameters required for displaying progress, including progress indicator options, destination path, and file conflict options. 230 231**Since**: 15 232 233 234## Enum Description 235 236 237### PASTEBOARD_ErrCode 238 239``` 240enum PASTEBOARD_ErrCode 241``` 242**Description** 243 244Enumerates the error codes. 245 246**Since**: 13 247 248| Value| Description| 249| -------- | -------- | 250| ERR_OK | The operation is successful. | 251| ERR_PERMISSION_ERROR | Permission verification failed. | 252| ERR_INVALID_PARAMETER | Invalid parameter. | 253| ERR_DEVICE_NOT_SUPPORTED | The device capability is not supported. | 254| ERR_INNER_ERROR | Internal error. | 255| ERR_BUSY | System busy. | 256| ERR_PASTEBOARD_COPY_FILE_ERROR | File copying failed.| 257| ERR_PASTEBOARD_PROGRESS_START_ERROR | Progress indicator creation fails when the application uses the system progress indicator.| 258| ERR_PASTEBOARD_PROGRESS_ABNORMAL | Progress reporting is abnormal when the application stops using the system progress indicator.| 259| ERR_PASTEBOARD_GET_DATA_FAILED | Obtaining pasteboard data failed.| 260 261 262### Pasteboard_NotifyType 263 264``` 265enum Pasteboard_NotifyType 266``` 267**Description** 268 269Enumerates the data change types of the pasteboard. 270 271**Since**: 13 272 273| Value| Description| 274| -------- | -------- | 275| NOTIFY_LOCAL_DATA_CHANGE | The pasteboard data of the local device is changed. | 276| NOTIFY_REMOTE_DATA_CHANGE | The pasteboard data of a non-local device on the network is changed. | 277 278### Pasteboard_FileConflictOptions 279 280``` 281enum Pasteboard_FileConflictOptions 282``` 283 284**Description** 285 286Enumerates the file conflict options. 287 288**Since**: 15 289 290| Value | Description | 291| -------------------- | ------------------------------------------------------------ | 292| PASTEBOARD_OVERWRITE | Overwrites the file with the same name in the destination path. | 293| PASTEBOARD_SKIP | Skips the file with the same name in the destination path. If **SKIP** is set, the pasteboard data of the skipped file is not pasted to the application.| 294 295### Pasteboard_ProgressIndicator 296 297``` 298enum Pasteboard_ProgressIndicator 299``` 300 301**Description** 302 303Enumerates the progress indicator options. You can use the default progress indicator as required. 304 305**Since**: 15 306 307| Value | Description | 308| ------------------ | ------------------------ | 309| PASTEBOARD_NONE | The default progress indicator is not used.| 310| PASTEBOARD_DEFAULT | The default progress indicator is used. | 311 312## Function Description 313 314 315### OH_Pasteboard_ClearData() 316 317``` 318int OH_Pasteboard_ClearData (OH_Pasteboard * pasteboard) 319``` 320**Description** 321 322Clears data from the pasteboard. 323 324**Since**: 13 325 326**Parameters** 327 328| Name| Description| 329| -------- | -------- | 330| pasteboard | Pointer to an [OH_Pasteboard](#oh_pasteboard) instance. | 331 332**Returns** 333 334Returns an error code. For details, see [PASTEBOARD_ErrCode](#pasteboard_errcode).<br> Returns **ERR_OK** if the operation is successful.<br> Returns **ERR_INVALID_PARAMETER** if an invalid parameter is passed in. 335 336**See** 337 338[OH_Pasteboard](#oh_pasteboard) 339 340[PASTEBOARD_ErrCode](#pasteboard_errcode) 341 342 343### OH_Pasteboard_Create() 344 345``` 346OH_Pasteboard* OH_Pasteboard_Create () 347``` 348**Description** 349 350Creates an [OH_Pasteboard](#oh_pasteboard) instance and a pointer to it. 351 352**Since**: 13 353 354**Returns** 355 356Returns a pointer to the [OH_Pasteboard](#oh_pasteboard) instance created if the operation is successful; returns **nullptr** otherwise. 357 358**See** 359 360[OH_Pasteboard](#oh_pasteboard) 361 362 363### OH_Pasteboard_Destroy() 364 365``` 366void OH_Pasteboard_Destroy (OH_Pasteboard * pasteboard) 367``` 368**Description** 369 370Destroys an [OH_Pasteboard](#oh_pasteboard) instance. 371 372**Since**: 13 373 374**Parameters** 375 376| Name| Description| 377| -------- | -------- | 378| pasteboard | Pointer to an [OH_Pasteboard](#oh_pasteboard) instance. | 379 380**See** 381 382[OH_Pasteboard](#oh_pasteboard) 383 384 385### OH_Pasteboard_GetData() 386 387``` 388OH_UdmfData* OH_Pasteboard_GetData (OH_Pasteboard * pasteboard, int * status ) 389``` 390**Description** 391 392Obtains data from the pasteboard. 393 394**Since**: 13 395 396**Parameters** 397 398| Name| Description| 399| -------- | -------- | 400| pasteboard | Pointer to an [OH_Pasteboard](#oh_pasteboard) instance. | 401| status | Output parameter, indicating the error code of the operation. For details, see [PASTEBOARD_ErrCode](#pasteboard_errcode). | 402 403**Returns** 404 405Returns the pointer to the [OH_UdmfData](../apis-arkdata/_u_d_m_f.md) instance obtained if the operation is successful; returns a null pointer otherwise. 406 407**See** 408 409[OH_Pasteboard](#oh_pasteboard) 410 411[OH_UdmfData](../apis-arkdata/_u_d_m_f.md) 412 413[PASTEBOARD_ErrCode](#pasteboard_errcode) 414 415 416### OH_Pasteboard_GetDataSource() 417 418``` 419int OH_Pasteboard_GetDataSource (OH_Pasteboard * pasteboard, char * source, unsigned int len ) 420``` 421**Description** 422 423Obtains the pasteboard data source. 424 425**Since**: 13 426 427**Parameters** 428 429| Name| Description| 430| -------- | -------- | 431| pasteboard | Pointer to an [OH_Pasteboard](#oh_pasteboard) instance. | 432| source | Output parameter, indicating the source string of the pasteboard data. | 433| len | Output parameter, indicating the length of the data source string. | 434 435**Returns** 436 437Returns an error code. For details, see [PASTEBOARD_ErrCode](#pasteboard_errcode).<br> Returns **ERR_OK** if the operation is successful.<br> Returns **ERR_INVALID_PARAMETER** if an invalid parameter is passed in. 438 439**See** 440 441[OH_Pasteboard](#oh_pasteboard) 442 443[PASTEBOARD_ErrCode](#pasteboard_errcode) 444 445 446### OH_Pasteboard_HasData() 447 448``` 449bool OH_Pasteboard_HasData (OH_Pasteboard * pasteboard) 450``` 451**Description** 452 453Checks whether the pasteboard contains data. 454 455**Since**: 13 456 457**Parameters** 458 459| Name| Description| 460| -------- | -------- | 461| pasteboard | Pointer to an [OH_Pasteboard](#oh_pasteboard) instance. | 462 463**Returns** 464 465Returns a Boolean value indicating whether the pasteboard contains data. The value **true** means the pasteboard contains data; the value **false** means the opposite. 466 467**See** 468 469[OH_Pasteboard](#oh_pasteboard) 470 471 472### OH_Pasteboard_HasType() 473 474``` 475bool OH_Pasteboard_HasType (OH_Pasteboard * pasteboard, const char * type ) 476``` 477**Description** 478 479Checks whether the pasteboard contains data of the specified type. 480 481**Since**: 13 482 483**Parameters** 484 485| Name| Description| 486| -------- | -------- | 487| pasteboard | Pointer to an [OH_Pasteboard](#oh_pasteboard) instance. | 488| type | Data type to be checked. | 489 490**Returns** 491 492Returns a Boolean value indicating whether the pasteboard contains data of the specified type. The value **true** means the pasteboard contains data of the specified type; the value **false** means the opposite. 493 494**See** 495 496[OH_Pasteboard](#oh_pasteboard) 497 498 499### OH_Pasteboard_IsRemoteData() 500 501``` 502bool OH_Pasteboard_IsRemoteData (OH_Pasteboard * pasteboard) 503``` 504**Description** 505 506Checks whether the pasteboard data comes from remote devices. 507 508**Since**: 13 509 510**Parameters** 511 512| Name| Description| 513| -------- | -------- | 514| pasteboard | Pointer to an [OH_Pasteboard](#oh_pasteboard) instance. | 515 516**Returns** 517 518Returns a Boolean value indicating whether the data is from a remote device. The value **true** means the data is from a remote device. The value **false** means the data is from the local device. 519 520**See** 521 522[OH_Pasteboard](#oh_pasteboard) 523 524 525### OH_Pasteboard_SetData() 526 527``` 528int OH_Pasteboard_SetData (OH_Pasteboard * pasteboard, OH_UdmfData * data ) 529``` 530**Description** 531 532Writes the unified data object to the pasteboard. 533 534**Since**: 13 535 536**Parameters** 537 538| Name| Description| 539| -------- | -------- | 540| pasteboard | Pointer to an [OH_Pasteboard](#oh_pasteboard) instance. | 541| data | Pointer to the [OH_UdmfData](../apis-arkdata/_u_d_m_f.md) instance. | 542 543**Returns** 544 545Returns an error code. For details, see [PASTEBOARD_ErrCode](#pasteboard_errcode).<br> Returns **ERR_OK** if the operation is successful.<br> Returns **ERR_INVALID_PARAMETER** if an invalid parameter is passed in. 546 547**See** 548 549[OH_Pasteboard](#oh_pasteboard) 550 551[OH_UdmfData](../apis-arkdata/_u_d_m_f.md) 552 553[PASTEBOARD_ErrCode](#pasteboard_errcode) 554 555 556### OH_Pasteboard_Subscribe() 557 558``` 559int OH_Pasteboard_Subscribe (OH_Pasteboard * pasteboard, int type, const OH_PasteboardObserver * observer ) 560``` 561**Description** 562 563Subscribes to the pasteboard observer. 564 565**Since**: 13 566 567**Parameters** 568 569| Name| Description| 570| -------- | -------- | 571| pasteboard | Pointer to an [OH_Pasteboard](#oh_pasteboard) instance. | 572| type | Subscribed data change type of the pasteboard. For details, see [Pasteboard_NotifyType](#pasteboard_notifytype). | 573| observer | Pointer to an [OH_PasteboardObserver](#oh_pasteboardobserver) instance. It specifies the callback to be invoked when the pasteboard data changes. For details, see [OH_PasteboardObserver](#oh_pasteboardobserver). | 574 575**Returns** 576 577Returns an error code. For details, see [PASTEBOARD_ErrCode](#pasteboard_errcode).<br> Returns **ERR_OK** if the operation is successful.<br> Returns **ERR_INVALID_PARAMETER** if an invalid parameter is passed in. 578 579**See** 580 581[OH_Pasteboard](#oh_pasteboard) 582 583[OH_PasteboardObserver](#oh_pasteboardobserver) 584 585[Pasteboard_NotifyType](#pasteboard_notifytype) 586 587[PASTEBOARD_ErrCode](#pasteboard_errcode) 588 589 590### OH_Pasteboard_Unsubscribe() 591 592``` 593int OH_Pasteboard_Unsubscribe (OH_Pasteboard * pasteboard, int type, const OH_PasteboardObserver * observer ) 594``` 595**Description** 596 597Unsubscribes from the pasteboard observer. 598 599**Since**: 13 600 601**Parameters** 602 603| Name| Description| 604| -------- | -------- | 605| pasteboard | Pointer to an [OH_Pasteboard](#oh_pasteboard) instance. | 606| type | Subscribed data change type of the pasteboard. For details, see [Pasteboard_NotifyType](#pasteboard_notifytype). | 607| observer | Pointer to an [OH_PasteboardObserver](#oh_pasteboardobserver) instance. It specifies the callback to be invoked when the pasteboard data changes. For details, see [OH_PasteboardObserver](#oh_pasteboardobserver). | 608 609**Returns** 610 611Returns an error code. For details, see [PASTEBOARD_ErrCode](#pasteboard_errcode).<br> Returns **ERR_OK** if the operation is successful.<br> Returns **ERR_INVALID_PARAMETER** if an invalid parameter is passed in. 612 613**See** 614 615[OH_Pasteboard](#oh_pasteboard) 616 617[OH_PasteboardObserver](#oh_pasteboardobserver) 618 619[Pasteboard_NotifyType](#pasteboard_notifytype) 620 621[PASTEBOARD_ErrCode](#pasteboard_errcode) 622 623 624### OH_PasteboardObserver_Create() 625 626``` 627OH_PasteboardObserver* OH_PasteboardObserver_Create () 628``` 629**Description** 630 631Creates an [OH_PasteboardObserver](#oh_pasteboardobserver) instance and a pointer to it. 632 633**Since**: 13 634 635**Returns** 636 637Returns a pointer to the [OH_PasteboardObserver](#oh_pasteboardobserver) instance created if the operation is successful; returns **nullptr** otherwise. If this pointer is no longer required, use [OH_PasteboardObserver_Destroy](#oh_pasteboardobserver_destroy) to destroy it. Otherwise, memory leaks may occur. 638 639**See** 640 641[OH_PasteboardObserver](#oh_pasteboardobserver) 642 643 644### OH_PasteboardObserver_Destroy() 645 646``` 647int OH_PasteboardObserver_Destroy (OH_PasteboardObserver * observer) 648``` 649**Description** 650 651Destroys an [OH_PasteboardObserver](_pasteboard.md#oh_pasteboardobserver) instance. 652 653**Since**: 13 654 655**Parameters** 656 657| Name| Description| 658| -------- | -------- | 659| observer | Pointer to an [OH_PasteboardObserver](#oh_pasteboardobserver) instance. | 660 661**Returns** 662 663Returns an error code. For details, see [PASTEBOARD_ErrCode](#pasteboard_errcode).<br> Returns **ERR_OK** if the operation is successful.<br> Returns **ERR_INVALID_PARAMETER** if an invalid parameter is passed in. 664 665**See** 666 667[OH_PasteboardObserver](#oh_pasteboardobserver) 668 669[PASTEBOARD_ErrCode](#pasteboard_errcode) 670 671 672### OH_PasteboardObserver_SetData() 673 674``` 675int OH_PasteboardObserver_SetData (OH_PasteboardObserver * observer, void * context, const Pasteboard_Notify callback, const Pasteboard_Finalize finalize ) 676``` 677**Description** 678 679Sets a callback for the pasteboard observer. 680 681**Since**: 13 682 683**Parameters** 684 685| Name| Description| 686| -------- | -------- | 687| observer | Pointer to an [OH_PasteboardObserver](#oh_pasteboardobserver) instance. | 688| context | Pointer to the context data, which is passed to [Pasteboard_Notify](#pasteboard_notify) as the first parameter. | 689| callback | Callback to be invoked when the data changes. For details, see [Pasteboard_Notify](#pasteboard_notify). | 690| finalize | Optional callback, which can be used to release context data when the pasteboard observer is destroyed. For details, see [Pasteboard_Finalize](#pasteboard_finalize). | 691 692**Returns** 693 694Returns an error code. For details, see [PASTEBOARD_ErrCode](#pasteboard_errcode).<br> Returns **ERR_OK** if the operation is successful.<br> Returns **ERR_INVALID_PARAMETER** if an invalid parameter is passed in. 695 696**See** 697 698[OH_PasteboardObserver](#oh_pasteboardobserver) 699 700[Pasteboard_Notify](#pasteboard_notify) 701 702[PASTEBOARD_ErrCode](#pasteboard_errcode) 703 704### OH_Pasteboard_GetMimeTypes() 705 706``` 707char ** OH_Pasteboard_GetMimeTypes (OH_Pasteboard * pasteboard, unsigned int * count) 708``` 709**Description** 710 711Obtains the MIME type from the pasteboard. 712 713**Since**: 14 714 715**Parameters** 716 717| Name| Description| 718| -------- | -------- | 719| pasteboard | Pointer to an [OH_Pasteboard](#oh_pasteboard) instance. | 720| count | Pointer to the number of uniform data types obtained. | 721 722**Returns** 723 724Returns the MIME type obtained if the operation is successful; returns **nullptr** otherwise. 725 726The lifecycle of the object returned by this API is managed by the input parameter object **pasteboard**. When the application calls [OH_Pasteboard_Destroy](#oh_pasteboard_destroy) to destroy **pasteboard**, the result returned by this API is released synchronously. 727 728The **pasteboard** object saves only the latest result and the historical results obtained by the API become invalid. 729 730**See** 731 732[OH_Pasteboard](#oh_pasteboard) 733 734### OH_Pasteboard_GetDataParams_Create() 735 736```c 737Pasteboard_GetDataParams *OH_Pasteboard_GetDataParams_Create(void); 738``` 739 740**Description** 741 742Creates a [Pasteboard_GetDataParams](#pasteboard_getdataparams) instance and a pointer to it. 743 744**Since**: 15 745 746**Returns** 747 748Returns a pointer to the [Pasteboard_GetDataParams](#pasteboard_getdataparams) instance created if the operation is successful; returns **nullptr** otherwise. If this pointer is no longer required, use [OH_Pasteboard_GetDataParams_Destroy](#oh_pasteboard_getdataparams_destroy) to destroy it. Otherwise, memory leaks may occur. 749 750**See** 751 752[Pasteboard_GetDataParams](#pasteboard_getdataparams) 753 754### OH_Pasteboard_GetDataParams_Destroy() 755 756```c 757void OH_Pasteboard_GetDataParams_Destroy(Pasteboard_GetDataParams* params) 758``` 759 760**Description** 761 762Destroys a [Pasteboard_GetDataParams](#pasteboard_getdataparams) instance. 763 764**Since**: 15 765 766**Parameters** 767 768| Name | Description | 769| ------ | ------------------------------------------------------------ | 770| params | Pointer to a [Pasteboard_GetDataParams](#pasteboard_getdataparams) instance.| 771 772**See** 773 774[Pasteboard_GetDataParams](#pasteboard_getdataparams) 775 776### OH_Pasteboard_GetDataParams_SetProgressIndicator() 777 778```c 779void OH_Pasteboard_GetDataParams_SetProgressIndicator(Pasteboard_GetDataParams* params, 780 Pasteboard_ProgressIndicator progressIndicator) 781``` 782 783**Description** 784 785Sets the progress indication options in [Pasteboard_GetDataParams](#pasteboard_getdataparams). You can use the default progress indicator as required. 786 787**Since**: 15 788 789**Parameters** 790 791| Name | Description | 792| ----------------- | ---------------------------------------------------- | 793| params | Pointer to the context data. | 794| progressIndicator | Progress indicator options. You can use the default progress indicator as required.| 795 796**See** 797 798[Pasteboard_GetDataParams](#pasteboard_getdataparams) 799 800[Pasteboard_ProgressIndicator](#pasteboard_progressindicator) 801 802### OH_Pasteboard_GetDataParams_SetDestUri() 803 804```c 805void OH_Pasteboard_GetDataParams_SetDestUri(Pasteboard_GetDataParams* params, const char* destUri, uint32_t destUriLen) 806``` 807 808**Description** 809 810 Sets the destination path in [Pasteboard_GetDataParams](#pasteboard_getdataparams) for copying files. If file processing is not supported, this parameter is not required. If the application involves complex file processing policies or needs to distinguish file multipathing storage, you are advised not to set this parameter but let the application copies files by itself. 811 812**Since**: 15 813 814**Parameters** 815 816| Name | Description | 817| ---------- | -------------------------- | 818| params | Pointer to the context data.| 819| destUri | Destination path for copying files.| 820| destUriLen | Length of the destination path. | 821 822**See** 823 824[Pasteboard_GetDataParams](#pasteboard_getdataparams) 825 826[Pasteboard_ProgressIndicator](#pasteboard_progressindicator) 827 828### OH_Pasteboard_GetDataParams_SetFileConflictOptions() 829 830```c 831void OH_Pasteboard_GetDataParams_SetFileConflictOptions(Pasteboard_GetDataParams* params, 832 Pasteboard_FileConflictOptions option) 833``` 834 835**Description** 836 837Sets the file copy conflict options in [Pasteboard_GetDataParams](#pasteboard_getdataparams). The default value is **PASTEBOARD_OVERWRITE**. 838 839**Since**: 15 840 841**Parameters** 842 843| Name | Description | 844| ------ | ------------------------------------------------------ | 845| params | Pointer to the context data. | 846| option | File copy conflict options The default value is **PASTEBOARD_OVERWRITE**.| 847 848**See** 849 850[Pasteboard_GetDataParams](#pasteboard_getdataparams) 851 852[Pasteboard_FileConflictOptions](#pasteboard_fileconflictoptions) 853 854### OH_Pasteboard_GetDataParams_SetProgressListener() 855 856```c 857void OH_Pasteboard_GetDataParams_SetProgressListener(Pasteboard_GetDataParams* params, 858 const OH_Pasteboard_ProgressListener listener) 859``` 860 861**Description** 862 863Sets a progress listener in [Pasteboard_GetDataParams](#pasteboard_getdataparams). 864 865**Since**: 15 866 867**Parameters** 868 869| Name | Description | 870| -------- | ------------------------------------------------------------ | 871| params | Pointer to the context data. | 872| listener | A listener for progress data changes. If the default progress indicator is not used, you can set this parameter to obtain the pasting progress.| 873 874**See** 875 876[Pasteboard_GetDataParams](#pasteboard_getdataparams) 877 878[OH_Pasteboard_ProgressListener](#oh_pasteboard_progresslistener) 879 880### OH_Pasteboard_ProgressInfo_GetProgress() 881 882```c 883int OH_Pasteboard_ProgressInfo_GetProgress(Pasteboard_ProgressInfo* progressInfo) 884``` 885 886**Description** 887 888Obtains the pasting progress using [Pasteboard_ProgressInfo](#pasteboard_progressinfo). Result can be obtained only when [Pasteboard_ProgressIndicator](#pasteboard_progressindicator) is set to **PASTEBOARD_NONE**. 889 890**Since**: 15 891 892**Parameters** 893 894| Name | Description | 895| ------------ | ------------------------------------------------------------ | 896| progressInfo | Defines the progress information. This information is reported only when [Pasteboard_ProgressIndicator](#pasteboard_progressindicator) is set to **PASTEBOARD_NONE**.| 897 898**Returns** 899 900Returns progress percentage of a copy and paste task. 901 902**See** 903 904[Pasteboard_ProgressInfo](#pasteboard_progressinfo) 905 906### OH_Pasteboard_ProgressCancel() 907 908```c 909void OH_Pasteboard_ProgressCancel(Pasteboard_GetDataParams* params); 910``` 911 912**Description** 913 914Cancels an ongoing copy and paste task using [Pasteboard_GetDataParams](#pasteboard_getdataparams). This parameter is valid only when [Pasteboard_ProgressIndicator](#pasteboard_progressindicator) is set to **PASTEBOARD_NONE**. 915 916**Since**: 15 917 918**Parameters** 919 920| Name | Description | 921| ------ | -------------------------- | 922| params | Pointer to the context data.| 923 924**See** 925 926[Pasteboard_GetDataParams](#pasteboard_getdataparams) 927 928### OH_Pasteboard_GetDataWithProgress() 929 930```c 931OH_UdmfData* OH_Pasteboard_GetDataWithProgress(OH_Pasteboard* pasteboard, Pasteboard_GetDataParams* params, int* status); 932``` 933 934**Description** 935 936Obtains the pasteboard content and progress. Folders cannot be copied. 937 938**Since**: 15 939 940**Parameters** 941 942| Name | Description | 943| ---------- | ------------------------------------------------------------ | 944| pasteboard | Pointer to an [OH_Pasteboard](#oh_pasteboard) instance. | 945| params | Parameters required when an application uses the file copy capability provided by the pasteboard. For details, see [Pasteboard_GetDataParams](#pasteboard_getdataparams).| 946| status | Output parameter, indicating the error code of the operation. For details, see [PASTEBOARD_ErrCode](#pasteboard_errcode).| 947 948**Returns** 949 950Returns the pointer to the [OH_UdmfData](../apis-arkdata/_u_d_m_f.md) instance obtained if the operation is successful; returns a null pointer otherwise. 951 952**See** 953 954[Pasteboard_GetDataParams](#pasteboard_getdataparams) 955 956### OH_Pasteboard_GetChangeCount() 957 958``` 959uint32_t OH_Pasteboard_GetChangeCount(OH_Pasteboard *pasteboard); 960``` 961**Description** 962 963Obtains the number of times that the pasteboard data changes. 964 965Even though the pasteboard data expires, or the data becomes empty because of the called [OH_Pasteboard_ClearData](#oh_pasteboard_cleardata) API, the number of data changes remains. 966 967When the system is restarted, or the pasteboard service is restarted due to an exception, the number of pasteboard data changes counts from 0. In addition, copying the same data repeatedly is considered to change the data for multiple times. Therefore, each time the data is copied, the number of data changes increases. 968 969**Since**: 18 970 971**Parameters** 972 973| Name| Description| 974| -------- | -------- | 975| pasteboard | Pointer to an [OH_Pasteboard](#oh_pasteboard) instance. | 976 977**Returns** 978 979Returns the result if this API is called successfully; otherwise, returns **0**. 980 981**See** 982 983[OH_Pasteboard](#oh_pasteboard) 984 985