Clipboard: System Clipboard

更新时间:
2025-01-13

Clipboard: System Clipboard

The Clipboard module provides many interfaces for applications to implement copy and past functions with the system clipboard.

Developers can determine whether these interfaces work in the EdgerOS mobile App environment through the following code:

edger.env().then(data => {
  if (data.env === 'edgerapp') {
    // We work in EdgerOS mobile App environment.
  }
}).catch(error => {
  console.error(error)
})

Functions

edger.clipboard.read()

Read a value from the clipboard (the "paste" action).

  • Returns: {Promise} Fulfill upon success with an object.

Get an object of result, the object includes:

  • result {Object} Information about the execution result, it can contain the following members:
    • value {String} Data read from the clipboard.
    • type {String} Types of data in the clipboard.

Example

edger.clipboard.read().then((res) => {
  console.log('clipboard read successful.', res)
})

async / await

async function clipboardRead() {
  try {
    const res = await edger.clipboard.read();
    console.log('clipboard read successful.', res)
  } catch (error) {
    console.error(error)
  }
}

edger.clipboard.write(options)

Write a value to the clipboard (the "copy" action).

  • options {ClipboardWriteOptions} The initialization parameters of the API for writing to the clipboard, it can contain the following members:
    • string {string} Text value to be copied. Optional.
    • image {string} Image in Data URL format to be copied. Optional.
    • url {String} URL string to copied. Optional.
    • label {string} User visible label accompanying the copied data (Android Only). Optional.
  • Returns: {Promise} Promise empty object.

Example

const params = {
  string: 'copy message'
}

edger.clipboard.write(params).then(() => {
  console.log('clipboard write successful.')
})

async / await

async function clipboardWrite() {
  try {.
    const params = {
      string: 'copy message'
    }

    await edger.clipboard.write(params)
    console.log('clipboard write successful.')
  } catch (error) {
    console.error(error)
  }
}
文档内容是否对您有所帮助?
有帮助
没帮助