1 个回答

可以使用用系统剪切板对象

SetPasteboardData() {
  let plainTextData = new unifiedDataChannel.UnifiedData();
  let plainText = new unifiedDataChannel.PlainText();
  plainText.details = { Key: 'test1', Value: 'test2', };
  plainText.textContent = 'test3@@@';
  plainText.abstract = 'test4';
  plainTextData.addRecord(plainText);
  let systemPasteboard: pasteboard.SystemPasteboard = pasteboard.getSystemPasteboard();
  try {
    systemPasteboard.setUnifiedDataSync(plainTextData);
    console.info('tag, Succeeded in setting UnifiedData.');
  } catch (err) {
    console.error('tag, Failed to set UnifiedData. Cause:' + err.message);
  };
}

参考:

https://developer.huawei.com/consumer/cn/doc/harmonyos-references-V5/js-apis-pasteboard-V5\#pasteboardgetsystempasteboard

logo
HarmonyOS
子站问答
访问
宣传栏