• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1# @ohos.pasteboard (Pasteboard) (System API)
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> - This topic describes only the system APIs provided by the module. For details about its public APIs, see [@ohos.pasteboard (Pasteboard)](js-apis-pasteboard.md).
9
10## Modules to Import
11
12```ts
13import pasteboard from '@ohos.pasteboard';
14```
15
16### setAppShareOptions<sup>12+</sup>
17
18setShareOptions(shareOptions: ShareOption): void
19
20Sets the global pasteable range of the application.
21
22**System API**: This is a system API.
23
24**System capability**: SystemCapability.MiscServices.Pasteboard
25
26**Parameters**
27
28| Name| Type| Mandatory| Description|
29| -------- | -------- | -------- | -------- |
30| shareOptions | [ShareOption](js-apis-pasteboard.md#shareoption9) | Yes| Pasteable range.|
31
32**Error codes**
33
34For details about the error codes, see [Pasteboard Error Codes](errorcode-pasteboard.md).
35
36| ID| Error Message|
37| -------- | -------- |
38| 202 | Permission verification failed. A non-system application calls a system API. |
39| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types; 3. Parameter verification failed. |
40| 12900006 | Settings already exist. |
41
42**Example**
43
44```ts
45let systemPasteboard: pasteboard.SystemPasteboard = pasteboard.getSystemPasteboard();
46try {
47  systemPasteboard.setAppShareOptions(pasteboard.ShareOption.INAPP);
48  console.info('Set app share options success.');
49} catch (err) {
50  let error: BusinessError = err as BusinessError;
51  console.error(`Set app share options failed, errorCode: ${error.code}, errorMessage: ${error.message}.`);
52}
53```
54
55### removeAppShareOptions<sup>12+</sup>
56
57removeShareOptions(): void
58
59Deletes the global pasteable range of the application.
60
61**System API**: This is a system API.
62
63**System capability**: SystemCapability.MiscServices.Pasteboard
64
65**Error codes**
66
67For details about the error codes, see [Pasteboard Error Codes](errorcode-pasteboard.md).
68
69| ID| Error Message|
70| -------- | -------- |
71| 202 | Permission verification failed. A non-system application calls a system API. |
72
73**Example**
74
75```ts
76let systemPasteboard: pasteboard.SystemPasteboard = pasteboard.getSystemPasteboard();
77try {
78  systemPasteboard.removeAppShareOptions();
79  console.info('Remove app share options success.');
80} catch (err) {
81  let error: BusinessError = err as BusinessError;
82  console.error(`Remove app share options failed, errorCode: ${error.code}, errorMessage: ${error.message}.`);
83}
84```
85