目录

Clipboard

has.setClipboardData

has.setClipboardData(Object object)

Sets content on the system clipboard.

On successful API call, a dialog box is displayed with the text "Content copied" and remains visible for 1.5 seconds.

Since: 1.0.8

Parameters

The input parameter is an object containing the following fields.

Parameter Type Mandatory Description
data string Yes Content on the clipboard.
success function No Callback triggered when the API call is successful.
fail function No Callback triggered when the API call fails.
complete function No Callback triggered when the API call is complete, regardless of success or failure.

Error code information

Error Code Error Message
12001101 setClipboardData error.

Example:

has.setClipboardData({
  data: 'data',
  success: () => {
    console.info('setClipboardData success');
  },
  fail: (err) => {
    console.error('setClipboardData fail', err);
  },
  complete: (res) => {
    console.info('setClipboardData complete', res);
  }
});

has.getClipboardData

has.getClipboardData(Object object)

Obtains content from the system clipboard.

Required permissions:

You need to apply for the ohos.permission.READ_PASTEBOARD permission. The permission application procedure is as follows:

  1. Check whether the app meets the requirements for requesting the permission according to the READ_PASTEBOARD description.

  2. Apply for a profile file in AppGallery Connect, which will be used for subsequent app signature configuration.

  3. Declare the permission in the module.json5 configuration file.

Since: 1.0.21

Parameters

The input parameter is an object containing the following fields.

Parameter Type Mandatory Description
success function No Callback triggered when the API call is successful.
fail function No Callback triggered when the API call fails.
complete function No Callback triggered when the API call is complete, regardless of success or failure.

Return value of success

An object containing the following fields.

Parameter Type Description
data string Content on the clipboard.

Error code information

Error Code Error Message
103

1. authorize error.

2. has no permission.

12004301 getClipboardData error.

Example:

has.getClipboardData({
  success: (res) => {
    console.info('getClipboardData success:', res.data);
  },
  fail: (err) => {
    console.error('getClipboardData fail:', err);
  },
  complete: (res) => {
    console.info('getClipboardData complete:', res);
  }
});