同步操作将从 OpenHarmony/distributeddatamgr_pasteboard 强制同步,此操作会覆盖自 Fork 仓库以来所做的任何修改,且无法恢复!!!
确定后同步将在后台操作,完成时将刷新页面,请耐心等待。
As a functional component of the stray subsystem, the clipboard service provides the ability to manage the system clipboard and supports the system copy and paste functions. The system clipboard supports package text, hypertext, URIs and other content operations.
picture 1 Subsystem Architecture Diagram
The clipboard service provides functions that support application developers to use clipboard-related services conveniently and efficiently. Its main components include clipboard management client and clipboard service. The clipboard management client is responsible for clipboard interface management, providing clipboard northbound JS API to applications; creating clipboard data on the application framework side, requesting clipboard SA to perform clipboard creation, deletion, query, text conversion, configuration, etc. The clipboard service is responsible for clipboard event management, manages the life cycle of clipboard SA (startup, destruction, multi-user, etc.); executes application requests, notifies clipboard data management, and returns the results to the clipboard management client.
/foundation/distributeddatamgr/pasteboard
├── etc # Configuration files for the processes contained in the component
├── figures # Framework diagram
├── framework # innerKit interface
├── interfaces # The interface code provided by the component externally
│ └── kits # Interface provided to the application
├── profile # Configuration files for system services contained in the component
├── services # clipboard service implementation
│ └── core # Core code implementation
│ └── test # native test code
│ └── zidl # Cross-process communication code implementation
├── utils # Tests or services use mocked data
└──README.md # Instructions for use
list 1 PasteBoard open main method
list 2 SystemPasteboard open main method
Callback called when the content of the pasteboard is closed |
|
setPasteData(data: PasteData, callback: AsyncCallback<void>:void; |
|
list 3 PasteData open main method
list 4 PasteDataRecord open main method
list 5 PasteDataProperty Parameter Description
Timestamp indicating when the data was written to the system clipboard. |
||
Clipboard module usage example:
// import module
import pasteboard from '@ohos.pasteboard'
//text copy
console.log('Get SystemPasteboard')
var systemPasteboard = pasteboard.getSystemPasteboard()
systemPasteboard.clear()
var textData = 'Hello World!'
console.log('createPlainTextData = ' + textData)
var pasteData = pasteboard.createPlainTextData(textData)
console.log('Writes PasteData to the pasteboard')
systemPasteboard.setPasteData(pasteData)
console.log('Checks there is content in the pasteboard')
assert.equal(systemPasteboard.hasPasteData(), true)
console.log('Checks the number of records')
pasteData = systemPasteboard.getPasteData()
assert.equal(pasteData.getRecordCount(), 1)
console.log('Checks the pasteboard content')
assert.equal(pasteData.getPrimaryText(), textData)
console.log('Checks there is a MIMETYPE_TEXT_PLAIN MIME type of data')
assert.equal(pasteData.hasMimeType(MIMETYPE_TEXT_PLAIN), true)
assert.equal(pasteData.getPrimaryMimeType(), MIMETYPE_TEXT_PLAIN)
//clipboard change listener
console.log('Off the content changes')
var systemPasteboard = pasteboard.getSystemPasteboard()
systemPasteboard.off(contentChanges)
systemPasteboard.clear()
var textData = 'Hello World!'
console.log('createUriData = ' + textData)
var pasteData = pasteboard.createUriData(textData)
console.log('Writes PasteData to the pasteboard')
systemPasteboard.setPasteData(pasteData)
console.log('Checks there is content in the pasteboard')
assert.equal(systemPasteboard.hasPasteData(), true)
console.log('Checks the number of records')
pasteData = systemPasteboard.getPasteData()
assert.equal(pasteData.getRecordCount(), 1)
console.log('On the content changes')
systemPasteboard.on(contentChanges)
console.log('Removes the Record')
assert.equal(pasteData.removeRecordAt(0), true)
console.log('Writes PasteData to the pasteboard')
systemPasteboard.setPasteData(pasteData)
console.log('Checks the number of records')
pasteData = systemPasteboard.getPasteData()
assert.equal(pasteData.getRecordCount(), 0)
console.log('Checks there is no content in the pasteboard')
assert.equal(systemPasteboard.hasPasteData(), false)
var textDataNew = 'Hello World!-New'
console.log('createUriData = ' + textDataNew)
var pasteData = pasteboard.createUriData(textDataNew)
console.log('Writes PasteData to the pasteboard')
systemPasteboard.setPasteData(pasteData)
console.log('Checks there is content in the pasteboard')
assert.equal(systemPasteboard.hasPasteData(), true)
console.log('Checks the number of records')
pasteData = systemPasteboard.getPasteData()
assert.equal(pasteData.getRecordCount(), 1)
console.log('Checks the pasteboard content')
assert.equal(pasteData.getRecordAt(0).plainText, textDataNew)
Distributed Data Management subsystem
此处可能存在不合适展示的内容,页面不予展示。您可通过相关编辑功能自查并修改。
如您确认内容无涉及 不当用语 / 纯广告导流 / 暴力 / 低俗色情 / 侵权 / 盗版 / 虚假 / 无价值内容或违法国家有关法律法规的内容,可点击提交进行申诉,我们将尽快为您处理。