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
子站问答
访问
宣传栏