Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
OpenHarmony
Docs
提交
2f1b4792
D
Docs
项目概览
OpenHarmony
/
Docs
1 年多 前同步成功
通知
159
Star
292
Fork
28
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
D
Docs
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
提交
Issue看板
提交
2f1b4792
编写于
9月 05, 2023
作者:
L
linxinyu
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
剪贴板文档示例整改
Signed-off-by:
N
linxinyu
<
linxinyu1@huawei.com
>
上级
7a31f8af
变更
1
隐藏空白更改
内联
并排
Showing
1 changed file
with
252 addition
and
210 deletion
+252
-210
zh-cn/application-dev/reference/apis/js-apis-pasteboard.md
zh-cn/application-dev/reference/apis/js-apis-pasteboard.md
+252
-210
未找到文件。
zh-cn/application-dev/reference/apis/js-apis-pasteboard.md
浏览文件 @
2f1b4792
...
...
@@ -8,7 +8,7 @@
## 导入模块
```
j
s
```
t
s
import
pasteboard
from
'
@ohos.pasteboard
'
;
```
...
...
@@ -61,16 +61,16 @@ createData(mimeType: string, value: ValueType): PasteData
**示例1:**
```
j
s
```
t
s
let
dataXml
=
new
ArrayBuffer
(
256
);
let
pasteData
=
pasteboard
.
createData
(
'
app/xml
'
,
dataXml
);
let
pasteData
:
pasteboard
.
PasteData
=
pasteboard
.
createData
(
'
app/xml
'
,
dataXml
);
```
**示例2:**
```
j
s
```
t
s
let
dataText
=
'
hello
'
;
let
pasteData
=
pasteboard
.
createData
(
pasteboard
.
MIMETYPE_TEXT_PLAIN
,
dataText
);
let
pasteData
:
pasteboard
.
PasteData
=
pasteboard
.
createData
(
pasteboard
.
MIMETYPE_TEXT_PLAIN
,
dataText
);
```
...
...
@@ -97,16 +97,16 @@ createRecord(mimeType: string, value: ValueType):PasteDataRecord;
**示例1:**
```
j
s
```
t
s
let
dataXml
=
new
ArrayBuffer
(
256
);
let
pasteDataRecord
=
pasteboard
.
createRecord
(
'
app/xml
'
,
dataXml
);
let
pasteDataRecord
:
pasteboard
.
PasteDataRecord
=
pasteboard
.
createRecord
(
'
app/xml
'
,
dataXml
);
```
**示例2:**
```
j
s
```
t
s
let
dataUri
=
'
dataability:///com.example.myapplication1/user.txt
'
;
let
record
=
pasteboard
.
createRecord
(
pasteboard
.
MIMETYPE_TEXT_URI
,
dataUri
);
let
record
:
pasteboard
.
PasteDataRecord
=
pasteboard
.
createRecord
(
pasteboard
.
MIMETYPE_TEXT_URI
,
dataUri
);
```
## pasteboard.getSystemPasteboard
...
...
@@ -125,8 +125,8 @@ getSystemPasteboard(): SystemPasteboard
**示例:**
```
j
s
let
systemPasteboard
=
pasteboard
.
getSystemPasteboard
();
```
t
s
let
systemPasteboard
:
pasteboard
.
SystemPasteboard
=
pasteboard
.
getSystemPasteboard
();
```
## ShareOption<sup>9+</sup>
...
...
@@ -166,9 +166,9 @@ createHtmlData(htmlText: string): PasteData
**示例:**
```
j
s
```
t
s
let
html
=
"
<!DOCTYPE html>
\n
"
+
"
<html>
\n
"
+
"
<head>
\n
"
+
"
<meta charset=
\"
utf-8
\"
>
\n
"
+
"
<title>HTML-PASTEBOARD_HTML</title>
\n
"
+
"
</head>
\n
"
+
"
<body>
\n
"
+
"
<h1>HEAD</h1>
\n
"
+
"
<p></p>
\n
"
+
"
</body>
\n
"
+
"
</html>
"
;
let
pasteData
=
pasteboard
.
createHtmlData
(
html
);
let
pasteData
:
pasteboard
.
PasteData
=
pasteboard
.
createHtmlData
(
html
);
```
## pasteboard.createWantData<sup>(deprecated)</sup>
...
...
@@ -196,12 +196,14 @@ createWantData(want: Want): PasteData
**示例:**
```
js
let
object
=
{
```
ts
import
Want
from
'
@ohos.app.ability.Want
'
;
let
object
:
Want
=
{
bundleName
:
"
com.example.aafwk.test
"
,
abilityName
:
"
com.example.aafwk.test.TwoAbility
"
};
let
pasteData
=
pasteboard
.
createWantData
(
object
);
let
pasteData
:
pasteboard
.
PasteData
=
pasteboard
.
createWantData
(
object
);
```
## pasteboard.createPlainTextData<sup>(deprecated)</sup>
...
...
@@ -229,8 +231,8 @@ createPlainTextData(text: string): PasteData
**示例:**
```
j
s
let
pasteData
=
pasteboard
.
createPlainTextData
(
'
content
'
);
```
t
s
let
pasteData
:
pasteboard
.
PasteData
=
pasteboard
.
createPlainTextData
(
'
content
'
);
```
## pasteboard.createUriData<sup>(deprecated)</sup>
...
...
@@ -258,8 +260,8 @@ createUriData(uri: string): PasteData
**示例:**
```
j
s
let
pasteData
=
pasteboard
.
createUriData
(
'
dataability:///com.example.myapplication1/user.txt
'
);
```
t
s
let
pasteData
:
pasteboard
.
PasteData
=
pasteboard
.
createUriData
(
'
dataability:///com.example.myapplication1/user.txt
'
);
```
## pasteboard.createHtmlTextRecord<sup>(deprecated)</sup>
...
...
@@ -286,9 +288,9 @@ createHtmlTextRecord(htmlText: string): PasteDataRecord
**示例:**
```
j
s
```
t
s
let
html
=
"
<!DOCTYPE html>
\n
"
+
"
<html>
\n
"
+
"
<head>
\n
"
+
"
<meta charset=
\"
utf-8
\"
>
\n
"
+
"
<title>HTML-PASTEBOARD_HTML</title>
\n
"
+
"
</head>
\n
"
+
"
<body>
\n
"
+
"
<h1>HEAD</h1>
\n
"
+
"
<p></p>
\n
"
+
"
</body>
\n
"
+
"
</html>
"
;
let
record
=
pasteboard
.
createHtmlTextRecord
(
html
);
let
record
:
pasteboard
.
PasteDataRecord
=
pasteboard
.
createHtmlTextRecord
(
html
);
```
## pasteboard.createWantRecord<sup>(deprecated)</sup>
...
...
@@ -316,12 +318,14 @@ createWantRecord(want: Want): PasteDataRecord
**示例:**
```
js
let
object
=
{
```
ts
import
Want
from
'
@ohos.app.ability.Want
'
;
let
object
:
Want
=
{
bundleName
:
"
com.example.aafwk.test
"
,
abilityName
:
"
com.example.aafwk.test.TwoAbility
"
};
let
record
=
pasteboard
.
createWantRecord
(
object
);
let
record
:
pasteboard
.
PasteDataRecord
=
pasteboard
.
createWantRecord
(
object
);
```
## pasteboard.createPlainTextRecord<sup>(deprecated)</sup>
...
...
@@ -349,8 +353,8 @@ createPlainTextRecord(text: string): PasteDataRecord
**示例:**
```
j
s
let
record
=
pasteboard
.
createPlainTextRecord
(
'
hello
'
);
```
t
s
let
record
:
pasteboard
.
PasteDataRecord
=
pasteboard
.
createPlainTextRecord
(
'
hello
'
);
```
## pasteboard.createUriRecord<sup>(deprecated)</sup>
...
...
@@ -378,8 +382,8 @@ createUriRecord(uri: string): PasteDataRecord
**示例:**
```
j
s
let
record
=
pasteboard
.
createUriRecord
(
'
dataability:///com.example.myapplication1/user.txt
'
);
```
t
s
let
record
:
pasteboard
.
PasteDataRecord
=
pasteboard
.
createUriRecord
(
'
dataability:///com.example.myapplication1/user.txt
'
);
```
...
...
@@ -392,7 +396,7 @@ let record = pasteboard.createUriRecord('dataability:///com.example.myapplicatio
| 名称 | 类型 | 可读 | 可写 | 说明 |
| -------- | -------- | -------- | -------- |------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
| additions
<sup>
7+
</sup>
| {[key:string]:object} | 是 | 是 | 设置其他附加属性数据。 |
| additions
<sup>
7+
</sup>
| {[key:string]:object} | 是 | 是 | 设置其他附加属性数据。
不支持动态追加属性,只能通过重新赋值的方式修改附加值,具体见相关示例setProperty。
|
| mimeTypes
<sup>
7+
</sup>
| Array
<
string
>
| 是 | 否 | 剪贴板内容条目的数据类型,非重复的类型列表。 |
| tag
<sup>
7+
</sup>
| string | 是 | 是 | 用户自定义标签。 |
| timestamp
<sup>
7+
</sup>
| number | 是 | 否 | 剪贴板数据的写入时间戳(单位:ms)。 |
...
...
@@ -433,9 +437,9 @@ toPlainText(): string
**示例:**
```
j
s
let
record
=
pasteboard
.
createRecord
(
pasteboard
.
MIMETYPE_TEXT_URI
,
'
dataability:///com.example.myapplication1/user.txt
'
);
let
data
=
record
.
toPlainText
();
```
t
s
let
record
:
pasteboard
.
PasteDataRecord
=
pasteboard
.
createRecord
(
pasteboard
.
MIMETYPE_TEXT_URI
,
'
dataability:///com.example.myapplication1/user.txt
'
);
let
data
:
string
=
record
.
toPlainText
();
console
.
info
(
`Succeeded in converting to text. Data:
${
data
}
`
);
```
...
...
@@ -458,13 +462,15 @@ convertToText(callback: AsyncCallback<string>): void
**示例:**
```
js
let
record
=
pasteboard
.
createUriRecord
(
'
dataability:///com.example.myapplication1/user.txt
'
);
record
.
convertToText
((
err
,
data
)
=>
{
```
ts
import
{
BusinessError
}
from
'
@ohos.base
'
;
let
record
:
pasteboard
.
PasteDataRecord
=
pasteboard
.
createUriRecord
(
'
dataability:///com.example.myapplication1/user.txt
'
);
record
.
convertToText
((
err
:
BusinessError
,
data
:
string
)
=>
{
if
(
err
)
{
console
.
error
(
`Failed to convert to text. Cause:
${
err
.
message
}
`
);
return
;
}
return
;
}
console
.
info
(
`Succeeded in converting to text. Data:
${
data
}
`
);
});
```
...
...
@@ -488,11 +494,13 @@ convertToText(): Promise<string>
**示例:**
```
js
let
record
=
pasteboard
.
createUriRecord
(
'
dataability:///com.example.myapplication1/user.txt
'
);
record
.
convertToText
().
then
((
data
)
=>
{
```
ts
import
{
BusinessError
}
from
'
@ohos.base
'
;
let
record
:
pasteboard
.
PasteDataRecord
=
pasteboard
.
createUriRecord
(
'
dataability:///com.example.myapplication1/user.txt
'
);
record
.
convertToText
().
then
((
data
:
string
)
=>
{
console
.
info
(
`Succeeded in converting to text. Data:
${
data
}
`
);
}).
catch
((
err
)
=>
{
}).
catch
((
err
:
BusinessError
)
=>
{
console
.
error
(
`Failed to convert to text. Cause:
${
err
.
message
}
`
);
});
```
...
...
@@ -521,9 +529,9 @@ getPrimaryText(): string
**示例:**
```
j
s
let
pasteData
=
pasteboard
.
createData
(
pasteboard
.
MIMETYPE_TEXT_PLAIN
,
'
hello
'
);
let
plainText
=
pasteData
.
getPrimaryText
();
```
t
s
let
pasteData
:
pasteboard
.
PasteData
=
pasteboard
.
createData
(
pasteboard
.
MIMETYPE_TEXT_PLAIN
,
'
hello
'
);
let
plainText
:
string
=
pasteData
.
getPrimaryText
();
```
### getPrimaryHtml<sup>7+</sup>
...
...
@@ -542,10 +550,10 @@ getPrimaryHtml(): string
**示例:**
```
j
s
```
t
s
let
html
=
"
<!DOCTYPE html>
\n
"
+
"
<html>
\n
"
+
"
<head>
\n
"
+
"
<meta charset=
\"
utf-8
\"
>
\n
"
+
"
<title>HTML-PASTEBOARD_HTML</title>
\n
"
+
"
</head>
\n
"
+
"
<body>
\n
"
+
"
<h1>HEAD</h1>
\n
"
+
"
<p></p>
\n
"
+
"
</body>
\n
"
+
"
</html>
"
;
let
pasteData
=
pasteboard
.
createData
(
pasteboard
.
MIMETYPE_TEXT_HTML
,
html
);
let
htmlText
=
pasteData
.
getPrimaryHtml
();
let
pasteData
:
pasteboard
.
PasteData
=
pasteboard
.
createData
(
pasteboard
.
MIMETYPE_TEXT_HTML
,
html
);
let
htmlText
:
string
=
pasteData
.
getPrimaryHtml
();
```
### getPrimaryWant<sup>7+</sup>
...
...
@@ -564,13 +572,15 @@ getPrimaryWant(): Want
**示例:**
```
js
let
object
=
{
```
ts
import
Want
from
'
@ohos.app.ability.Want
'
;
let
object
:
Want
=
{
bundleName
:
"
com.example.aafwk.test
"
,
abilityName
:
"
com.example.aafwk.test.TwoAbility
"
};
let
pasteData
=
pasteboard
.
createData
(
pasteboard
.
MIMETYPE_TEXT_WANT
,
object
);
let
want
=
pasteData
.
getPrimaryWant
();
let
pasteData
:
pasteboard
.
PasteData
=
pasteboard
.
createData
(
pasteboard
.
MIMETYPE_TEXT_WANT
,
object
);
let
want
:
Want
=
pasteData
.
getPrimaryWant
();
```
### getPrimaryUri<sup>7+</sup>
...
...
@@ -589,9 +599,9 @@ getPrimaryUri(): string
**示例:**
```
j
s
let
pasteData
=
pasteboard
.
createData
(
pasteboard
.
MIMETYPE_TEXT_URI
,
'
dataability:///com.example.myapplication1/user.txt
'
);
let
uri
=
pasteData
.
getPrimaryUri
();
```
t
s
let
pasteData
:
pasteboard
.
PasteData
=
pasteboard
.
createData
(
pasteboard
.
MIMETYPE_TEXT_URI
,
'
dataability:///com.example.myapplication1/user.txt
'
);
let
uri
:
string
=
pasteData
.
getPrimaryUri
();
```
### getPrimaryPixelMap<sup>9+</sup>
...
...
@@ -610,20 +620,21 @@ getPrimaryPixelMap(): image.PixelMap
**示例:**
```
j
s
```
t
s
import
image
from
'
@ohos.multimedia.image
'
;
let
buffer
=
new
ArrayBuffer
(
128
);
let
opt
=
{
size
:
{
height
:
3
,
width
:
5
},
pixelFormat
:
3
,
editable
:
true
,
alphaType
:
1
,
scaleMode
:
1
let
realSize
:
image
.
Size
=
{
height
:
3
,
width
:
5
};
let
opt
:
image
.
InitializationOptions
=
{
size
:
realSize
,
pixelFormat
:
3
,
editable
:
true
,
alphaType
:
1
,
scaleMode
:
1
};
image
.
createPixelMap
(
buffer
,
opt
).
then
((
pixelMap
)
=>
{
let
pasteData
=
pasteboard
.
createData
(
pasteboard
.
MIMETYPE_PIXELMAP
,
pixelMap
);
let
PixelMap
=
pasteData
.
getPrimaryPixelMap
();
image
.
createPixelMap
(
buffer
,
opt
).
then
((
pixelMap
:
image
.
PixelMap
)
=>
{
let
pasteData
:
pasteboard
.
PasteData
=
pasteboard
.
createData
(
pasteboard
.
MIMETYPE_PIXELMAP
,
pixelMap
);
let
PixelMap
:
image
.
PixelMap
=
pasteData
.
getPrimaryPixelMap
();
});
```
...
...
@@ -643,11 +654,11 @@ addRecord(record: PasteDataRecord): void
**示例:**
```
j
s
let
pasteData
=
pasteboard
.
createData
(
pasteboard
.
MIMETYPE_TEXT_URI
,
'
dataability:///com.example.myapplication1/user.txt
'
);
let
textRecord
=
pasteboard
.
createRecord
(
pasteboard
.
MIMETYPE_TEXT_PLAIN
,
'
hello
'
);
let
html
=
"
<!DOCTYPE html>
\n
"
+
"
<html>
\n
"
+
"
<head>
\n
"
+
"
<meta charset=
\"
utf-8
\"
>
\n
"
+
"
<title>HTML-PASTEBOARD_HTML</title>
\n
"
+
"
</head>
\n
"
+
"
<body>
\n
"
+
"
<h1>HEAD</h1>
\n
"
+
"
<p></p>
\n
"
+
"
</body>
\n
"
+
"
</html>
"
;
let
htmlRecord
=
pasteboard
.
createRecord
(
pasteboard
.
MIMETYPE_TEXT_HTML
,
html
);
```
t
s
let
pasteData
:
pasteboard
.
PasteData
=
pasteboard
.
createData
(
pasteboard
.
MIMETYPE_TEXT_URI
,
'
dataability:///com.example.myapplication1/user.txt
'
);
let
textRecord
:
pasteboard
.
PasteDataRecord
=
pasteboard
.
createRecord
(
pasteboard
.
MIMETYPE_TEXT_PLAIN
,
'
hello
'
);
let
html
:
string
=
"
<!DOCTYPE html>
\n
"
+
"
<html>
\n
"
+
"
<head>
\n
"
+
"
<meta charset=
\"
utf-8
\"
>
\n
"
+
"
<title>HTML-PASTEBOARD_HTML</title>
\n
"
+
"
</head>
\n
"
+
"
<body>
\n
"
+
"
<h1>HEAD</h1>
\n
"
+
"
<p></p>
\n
"
+
"
</body>
\n
"
+
"
</html>
"
;
let
htmlRecord
:
pasteboard
.
PasteDataRecord
=
pasteboard
.
createRecord
(
pasteboard
.
MIMETYPE_TEXT_HTML
,
html
);
pasteData
.
addRecord
(
textRecord
);
pasteData
.
addRecord
(
htmlRecord
);
```
...
...
@@ -676,8 +687,8 @@ addRecord(mimeType: string, value: ValueType): void
**示例:**
```
j
s
let
pasteData
=
pasteboard
.
createData
(
pasteboard
.
MIMETYPE_TEXT_URI
,
'
dataability:///com.example.myapplication1/user.txt
'
);
```
t
s
let
pasteData
:
pasteboard
.
PasteData
=
pasteboard
.
createData
(
pasteboard
.
MIMETYPE_TEXT_URI
,
'
dataability:///com.example.myapplication1/user.txt
'
);
let
dataXml
=
new
ArrayBuffer
(
256
);
pasteData
.
addRecord
(
'
app/xml
'
,
dataXml
);
```
...
...
@@ -698,9 +709,9 @@ getMimeTypes(): Array<string>
**示例:**
```
j
s
let
pasteData
=
pasteboard
.
createData
(
pasteboard
.
MIMETYPE_TEXT_PLAIN
,
'
hello
'
);
let
types
=
pasteData
.
getMimeTypes
();
```
t
s
let
pasteData
:
pasteboard
.
PasteData
=
pasteboard
.
createData
(
pasteboard
.
MIMETYPE_TEXT_PLAIN
,
'
hello
'
);
let
types
:
string
[]
=
pasteData
.
getMimeTypes
();
```
### getPrimaryMimeType<sup>7+</sup>
...
...
@@ -719,9 +730,9 @@ getPrimaryMimeType(): string
**示例:**
```
j
s
let
pasteData
=
pasteboard
.
createData
(
pasteboard
.
MIMETYPE_TEXT_PLAIN
,
'
hello
'
);
let
type
=
pasteData
.
getPrimaryMimeType
();
```
t
s
let
pasteData
:
pasteboard
.
PasteData
=
pasteboard
.
createData
(
pasteboard
.
MIMETYPE_TEXT_PLAIN
,
'
hello
'
);
let
type
:
string
=
pasteData
.
getPrimaryMimeType
();
```
### getProperty<sup>7+</sup>
...
...
@@ -740,9 +751,9 @@ getProperty(): PasteDataProperty
**示例:**
```
j
s
let
pasteData
=
pasteboard
.
createData
(
pasteboard
.
MIMETYPE_TEXT_PLAIN
,
'
hello
'
);
let
property
=
pasteData
.
getProperty
();
```
t
s
let
pasteData
:
pasteboard
.
PasteData
=
pasteboard
.
createData
(
pasteboard
.
MIMETYPE_TEXT_PLAIN
,
'
hello
'
);
let
property
:
pasteboard
.
PasteDataProperty
=
pasteData
.
getProperty
();
```
### setProperty<sup>9+</sup>
...
...
@@ -761,58 +772,59 @@ setProperty(property: PasteDataProperty): void
**示例:**
```
js
let
pasteData
=
pasteboard
.
createData
(
pasteboard
.
MIMETYPE_TEXT_HTML
,
'
application/xml
'
);
let
prop
=
pasteData
.
getProperty
();
```
ts
type
AdditionType
=
Record
<
string
,
Record
<
string
,
Object
>>
;
let
pasteData
:
pasteboard
.
PasteData
=
pasteboard
.
createData
(
pasteboard
.
MIMETYPE_TEXT_HTML
,
'
application/xml
'
);
let
prop
:
pasteboard
.
PasteDataProperty
=
pasteData
.
getProperty
();
prop
.
shareOption
=
pasteboard
.
ShareOption
.
INAPP
;
prop
.
additions
[
'
TestOne
'
]
=
{
'
Test
'
:
123
};
prop
.
additions
[
'
TestTwo
'
]
=
{
'
Test
'
:
'
additions
'
}
;
// 需要注意,不支持对addition进行追加属性的操作,只能通过重新赋值的方式达到追加属性的目的。
prop
.
additions
=
{
'
TestOne
'
:
{
'
Test
'
:
123
},
'
TestTwo
'
:
{
'
Test
'
:
'
additions
'
}
}
as
AdditionType
;
prop
.
tag
=
'
TestTag
'
;
pasteData
.
setProperty
(
prop
);
```
[
PasteDataProperty
](
#pastedataproperty7
)
的localOnly与shareOption属性互斥,最终结果以shareOption为准,shareOption会影响localOnly的值。
```
j
s
(
async
function
()
{
let
pasteData
=
pasteboard
.
createData
(
pasteboard
.
MIMETYPE_TEXT_PLAIN
,
'
hello
'
);
let
prop
=
pasteData
.
getProperty
();
```
t
s
(
async
()
=>
{
let
pasteData
:
pasteboard
.
PasteData
=
pasteboard
.
createData
(
pasteboard
.
MIMETYPE_TEXT_PLAIN
,
'
hello
'
);
let
prop
:
pasteboard
.
PasteDataProperty
=
pasteData
.
getProperty
();
prop
.
shareOption
=
pasteboard
.
ShareOption
.
INAPP
;
prop
.
localOnly
=
false
;
pasteData
.
setProperty
(
prop
);
let
systemPasteboard
=
pasteboard
.
getSystemPasteboard
();
pasteData
.
setProperty
(
prop
);
let
systemPasteboard
:
pasteboard
.
SystemPasteboard
=
pasteboard
.
getSystemPasteboard
();
await
systemPasteboard
.
setData
(
pasteData
).
then
(
async
()
=>
{
console
.
info
(
'
Succeeded in setting PasteData.
'
);
await
systemPasteboard
.
getData
().
then
(
pasteData
=>
{
let
prop
=
pasteData
.
getProperty
();
prop
.
localOnly
//
true
await
systemPasteboard
.
getData
().
then
(
(
pasteData
:
pasteboard
.
PasteData
)
=>
{
let
prop
:
pasteboard
.
PasteDataProperty
=
pasteData
.
getProperty
();
prop
.
localOnly
;
//
true
});
});
prop
.
shareOption
=
pasteboard
.
ShareOption
.
LOCALDEVICE
;
prop
.
localOnly
=
false
;
pasteData
.
setProperty
(
prop
);
await
systemPasteboard
.
setData
(
pasteData
).
then
(
async
()
=>
{
console
.
info
(
'
Succeeded in setting PasteData.
'
);
await
systemPasteboard
.
getData
().
then
(
pasteData
=>
{
let
prop
=
pasteData
.
getProperty
();
prop
.
localOnly
;
//true
await
systemPasteboard
.
getData
().
then
(
(
pasteData
:
pasteboard
.
PasteData
)
=>
{
let
prop
:
pasteboard
.
PasteDataProperty
=
pasteData
.
getProperty
();
prop
.
localOnly
;
//
true
});
});
prop
.
shareOption
=
pasteboard
.
ShareOption
.
CROSSDEVICE
;
prop
.
localOnly
=
true
;
pasteData
.
setProperty
(
prop
);
await
systemPasteboard
.
setData
(
pasteData
).
then
(
async
()
=>
{
console
.
info
(
'
Succeeded in setting PasteData.
'
);
await
systemPasteboard
.
getData
().
then
(
pasteData
=>
{
let
prop
=
pasteData
.
getProperty
();
prop
.
localOnly
;
//false
await
systemPasteboard
.
getData
().
then
(
(
pasteData
:
pasteboard
.
PasteData
)
=>
{
let
prop
:
pasteboard
.
PasteDataProperty
=
pasteData
.
getProperty
();
prop
.
localOnly
;
//
false
});
});
})()
```
### getRecord<sup>9+</sup>
...
...
@@ -845,9 +857,9 @@ getRecord(index: number): PasteDataRecord
**示例:**
```
j
s
let
pasteData
=
pasteboard
.
createData
(
pasteboard
.
MIMETYPE_TEXT_PLAIN
,
'
hello
'
);
let
record
=
pasteData
.
getRecord
(
0
);
```
t
s
let
pasteData
:
pasteboard
.
PasteData
=
pasteboard
.
createData
(
pasteboard
.
MIMETYPE_TEXT_PLAIN
,
'
hello
'
);
let
record
:
pasteboard
.
PasteDataRecord
=
pasteData
.
getRecord
(
0
);
```
### getRecordCount<sup>7+</sup>
...
...
@@ -866,9 +878,9 @@ getRecordCount(): number
**示例:**
```
j
s
let
pasteData
=
pasteboard
.
createData
(
pasteboard
.
MIMETYPE_TEXT_PLAIN
,
'
hello
'
);
let
count
=
pasteData
.
getRecordCount
();
```
t
s
let
pasteData
:
pasteboard
.
PasteData
=
pasteboard
.
createData
(
pasteboard
.
MIMETYPE_TEXT_PLAIN
,
'
hello
'
);
let
count
:
number
=
pasteData
.
getRecordCount
();
```
### getTag<sup>7+</sup>
...
...
@@ -887,9 +899,9 @@ getTag(): string
**示例:**
```
j
s
let
pasteData
=
pasteboard
.
createData
(
pasteboard
.
MIMETYPE_TEXT_PLAIN
,
'
hello
'
);
let
tag
=
pasteData
.
getTag
();
```
t
s
let
pasteData
:
pasteboard
.
PasteData
=
pasteboard
.
createData
(
pasteboard
.
MIMETYPE_TEXT_PLAIN
,
'
hello
'
);
let
tag
:
string
=
pasteData
.
getTag
();
```
### hasType<sup>9+</sup>
...
...
@@ -914,9 +926,9 @@ hasType(mimeType: string): boolean
**示例:**
```
j
s
let
pasteData
=
pasteboard
.
createData
(
pasteboard
.
MIMETYPE_TEXT_PLAIN
,
'
hello
'
);
let
hasType
=
pasteData
.
hasType
(
pasteboard
.
MIMETYPE_TEXT_PLAIN
);
```
t
s
let
pasteData
:
pasteboard
.
PasteData
=
pasteboard
.
createData
(
pasteboard
.
MIMETYPE_TEXT_PLAIN
,
'
hello
'
);
let
hasType
:
boolean
=
pasteData
.
hasType
(
pasteboard
.
MIMETYPE_TEXT_PLAIN
);
```
### removeRecord<sup>9+</sup>
...
...
@@ -943,8 +955,8 @@ removeRecord(index: number): void
**示例:**
```
j
s
let
pasteData
=
pasteboard
.
createData
(
pasteboard
.
MIMETYPE_TEXT_PLAIN
,
'
hello
'
);
```
t
s
let
pasteData
:
pasteboard
.
PasteData
=
pasteboard
.
createData
(
pasteboard
.
MIMETYPE_TEXT_PLAIN
,
'
hello
'
);
pasteData
.
removeRecord
(
0
);
```
...
...
@@ -973,9 +985,9 @@ replaceRecord(index: number, record: PasteDataRecord): void
**示例:**
```
j
s
let
pasteData
=
pasteboard
.
createData
(
pasteboard
.
MIMETYPE_TEXT_PLAIN
,
'
hello
'
);
let
record
=
pasteboard
.
createRecord
(
pasteboard
.
MIMETYPE_TEXT_URI
,
'
dataability:///com.example.myapplication1/user.txt
'
);
```
t
s
let
pasteData
:
pasteboard
.
PasteData
=
pasteboard
.
createData
(
pasteboard
.
MIMETYPE_TEXT_PLAIN
,
'
hello
'
);
let
record
:
pasteboard
.
PasteDataRecord
=
pasteboard
.
createRecord
(
pasteboard
.
MIMETYPE_TEXT_URI
,
'
dataability:///com.example.myapplication1/user.txt
'
);
pasteData
.
replaceRecord
(
0
,
record
);
```
### addHtmlRecord<sup>(deprecated)</sup>
...
...
@@ -998,9 +1010,9 @@ addHtmlRecord(htmlText: string): void
**示例:**
```
j
s
let
pasteData
=
pasteboard
.
createPlainTextData
(
'
hello
'
);
let
html
=
"
<!DOCTYPE html>
\n
"
+
"
<html>
\n
"
+
"
<head>
\n
"
+
"
<meta charset=
\"
utf-8
\"
>
\n
"
+
"
<title>HTML-PASTEBOARD_HTML</title>
\n
"
+
"
</head>
\n
"
+
"
<body>
\n
"
+
"
<h1>HEAD</h1>
\n
"
+
"
<p></p>
\n
"
+
"
</body>
\n
"
+
"
</html>
"
;
```
t
s
let
pasteData
:
pasteboard
.
PasteData
=
pasteboard
.
createPlainTextData
(
'
hello
'
);
let
html
:
string
=
"
<!DOCTYPE html>
\n
"
+
"
<html>
\n
"
+
"
<head>
\n
"
+
"
<meta charset=
\"
utf-8
\"
>
\n
"
+
"
<title>HTML-PASTEBOARD_HTML</title>
\n
"
+
"
</head>
\n
"
+
"
<body>
\n
"
+
"
<h1>HEAD</h1>
\n
"
+
"
<p></p>
\n
"
+
"
</body>
\n
"
+
"
</html>
"
;
pasteData
.
addHtmlRecord
(
html
);
```
...
...
@@ -1024,9 +1036,11 @@ addWantRecord(want: Want): void
**示例:**
```
js
let
pasteData
=
pasteboard
.
createPlainTextData
(
'
hello
'
);
let
object
=
{
```
ts
import
Want
from
'
@ohos.app.ability.Want
'
;
let
pasteData
:
pasteboard
.
PasteData
=
pasteboard
.
createPlainTextData
(
'
hello
'
);
let
object
:
Want
=
{
bundleName
:
"
com.example.aafwk.test
"
,
abilityName
:
"
com.example.aafwk.test.TwoAbility
"
};
...
...
@@ -1053,8 +1067,8 @@ addTextRecord(text: string): void
**示例:**
```
j
s
let
pasteData
=
pasteboard
.
createPlainTextData
(
'
hello
'
);
```
t
s
let
pasteData
:
pasteboard
.
PasteData
=
pasteboard
.
createPlainTextData
(
'
hello
'
);
pasteData
.
addTextRecord
(
'
good
'
);
```
...
...
@@ -1078,8 +1092,8 @@ addUriRecord(uri: string): void
**示例:**
```
j
s
let
pasteData
=
pasteboard
.
createPlainTextData
(
'
hello
'
);
```
t
s
let
pasteData
:
pasteboard
.
PasteData
=
pasteboard
.
createPlainTextData
(
'
hello
'
);
pasteData
.
addUriRecord
(
'
dataability:///com.example.myapplication1/user.txt
'
);
```
### getRecordAt<sup>(deprecated)</sup>
...
...
@@ -1107,9 +1121,9 @@ getRecordAt(index: number): PasteDataRecord
**示例:**
```
j
s
let
pasteData
=
pasteboard
.
createPlainTextData
(
'
hello
'
);
let
record
=
pasteData
.
getRecordAt
(
0
);
```
t
s
let
pasteData
:
pasteboard
.
PasteData
=
pasteboard
.
createPlainTextData
(
'
hello
'
);
let
record
:
pasteboard
.
PasteDataRecord
=
pasteData
.
getRecordAt
(
0
);
```
### hasMimeType<sup>(deprecated)</sup>
...
...
@@ -1137,9 +1151,9 @@ hasMimeType(mimeType: string): boolean
**示例:**
```
j
s
let
pasteData
=
pasteboard
.
createPlainTextData
(
'
hello
'
);
let
hasType
=
pasteData
.
hasMimeType
(
pasteboard
.
MIMETYPE_TEXT_PLAIN
);
```
t
s
let
pasteData
:
pasteboard
.
PasteData
=
pasteboard
.
createPlainTextData
(
'
hello
'
);
let
hasType
:
boolean
=
pasteData
.
hasMimeType
(
pasteboard
.
MIMETYPE_TEXT_PLAIN
);
```
### removeRecordAt<sup>(deprecated)</sup>
...
...
@@ -1166,9 +1180,9 @@ removeRecordAt(index: number): boolean
**示例:**
```
j
s
let
pasteData
=
pasteboard
.
createPlainTextData
(
'
hello
'
);
let
isRemove
=
pasteData
.
removeRecordAt
(
0
);
```
t
s
let
pasteData
:
pasteboard
.
PasteData
=
pasteboard
.
createPlainTextData
(
'
hello
'
);
let
isRemove
:
boolean
=
pasteData
.
removeRecordAt
(
0
);
```
### replaceRecordAt<sup>(deprecated)</sup>
...
...
@@ -1196,10 +1210,10 @@ replaceRecordAt(index: number, record: PasteDataRecord): boolean
**示例:**
```
j
s
let
pasteData
=
pasteboard
.
createPlainTextData
(
'
hello
'
);
let
record
=
pasteboard
.
createUriRecord
(
'
dataability:///com.example.myapplication1/user.txt
'
);
let
isReplace
=
pasteData
.
replaceRecordAt
(
0
,
record
);
```
t
s
let
pasteData
:
pasteboard
.
PasteData
=
pasteboard
.
createPlainTextData
(
'
hello
'
);
let
record
:
pasteboard
.
PasteDataRecord
=
pasteboard
.
createUriRecord
(
'
dataability:///com.example.myapplication1/user.txt
'
);
let
isReplace
:
boolean
=
pasteData
.
replaceRecordAt
(
0
,
record
);
```
## SystemPasteboard
...
...
@@ -1208,8 +1222,8 @@ let isReplace = pasteData.replaceRecordAt(0, record);
在调用SystemPasteboard的接口前,需要先通过
[
getSystemPasteboard
](
#pasteboardgetsystempasteboard
)
获取系统剪贴板。
```
j
s
let
systemPasteboard
=
pasteboard
.
getSystemPasteboard
();
```
t
s
let
systemPasteboard
:
pasteboard
.
SystemPasteboard
=
pasteboard
.
getSystemPasteboard
();
```
### on('update')<sup>7+</sup>
...
...
@@ -1229,8 +1243,8 @@ on(type: 'update', callback: () =>void ): void
**示例:**
```
j
s
let
systemPasteboard
=
pasteboard
.
getSystemPasteboard
();
```
t
s
let
systemPasteboard
:
pasteboard
.
SystemPasteboard
=
pasteboard
.
getSystemPasteboard
();
let
listener
=
()
=>
{
console
.
info
(
'
The system pasteboard has changed.
'
);
};
...
...
@@ -1254,8 +1268,8 @@ off(type: 'update', callback?: () =>void ): void
**示例:**
```
j
s
let
systemPasteboard
=
pasteboard
.
getSystemPasteboard
();
```
t
s
let
systemPasteboard
:
pasteboard
.
SystemPasteboard
=
pasteboard
.
getSystemPasteboard
();
let
listener
=
()
=>
{
console
.
info
(
'
The system pasteboard has changed.
'
);
};
...
...
@@ -1278,8 +1292,8 @@ clearData(callback: AsyncCallback<void>): void
**示例:**
```
j
s
let
systemPasteboard
=
pasteboard
.
getSystemPasteboard
();
```
t
s
let
systemPasteboard
:
pasteboard
.
SystemPasteboard
=
pasteboard
.
getSystemPasteboard
();
systemPasteboard
.
clearData
((
err
,
data
)
=>
{
if
(
err
)
{
console
.
error
(
`Failed to clear the pasteboard. Cause:
${
err
.
message
}
`
);
...
...
@@ -1305,11 +1319,13 @@ clearData(): Promise<void>
**示例:**
```
js
let
systemPasteboard
=
pasteboard
.
getSystemPasteboard
();
systemPasteboard
.
clearData
().
then
((
data
)
=>
{
```
ts
import
{
BusinessError
}
from
'
@ohos.base
'
;
let
systemPasteboard
:
pasteboard
.
SystemPasteboard
=
pasteboard
.
getSystemPasteboard
();
systemPasteboard
.
clearData
().
then
((
data
:
void
)
=>
{
console
.
info
(
'
Succeeded in clearing the pasteboard.
'
);
}).
catch
((
err
)
=>
{
}).
catch
((
err
:
BusinessError
)
=>
{
console
.
error
(
`Failed to clear the pasteboard. Cause:
${
err
.
message
}
`
);
});
```
...
...
@@ -1340,9 +1356,9 @@ setData(data: PasteData, callback: AsyncCallback<void>): void
**示例:**
```
j
s
let
pasteData
=
pasteboard
.
createData
(
pasteboard
.
MIMETYPE_TEXT_PLAIN
,
'
content
'
);
let
systemPasteboard
=
pasteboard
.
getSystemPasteboard
();
```
t
s
let
pasteData
:
pasteboard
.
PasteData
=
pasteboard
.
createData
(
pasteboard
.
MIMETYPE_TEXT_PLAIN
,
'
content
'
);
let
systemPasteboard
:
pasteboard
.
SystemPasteboard
=
pasteboard
.
getSystemPasteboard
();
systemPasteboard
.
setData
(
pasteData
,
(
err
,
data
)
=>
{
if
(
err
)
{
console
.
error
(
'
Failed to set PasteData. Cause:
'
+
err
.
message
);
...
...
@@ -1383,12 +1399,14 @@ setData(data: PasteData): Promise<void>
**示例:**
```
js
let
pasteData
=
pasteboard
.
createData
(
pasteboard
.
MIMETYPE_TEXT_PLAIN
,
'
content
'
);
let
systemPasteboard
=
pasteboard
.
getSystemPasteboard
();
systemPasteboard
.
setData
(
pasteData
).
then
((
data
)
=>
{
```
ts
import
{
BusinessError
}
from
'
@ohos.base
'
;
let
pasteData
:
pasteboard
.
PasteData
=
pasteboard
.
createData
(
pasteboard
.
MIMETYPE_TEXT_PLAIN
,
'
content
'
);
let
systemPasteboard
:
pasteboard
.
SystemPasteboard
=
pasteboard
.
getSystemPasteboard
();
systemPasteboard
.
setData
(
pasteData
).
then
((
data
:
void
)
=>
{
console
.
info
(
'
Succeeded in setting PasteData.
'
);
}).
catch
((
err
)
=>
{
}).
catch
((
err
:
BusinessError
)
=>
{
console
.
error
(
'
Failed to set PasteData. Cause:
'
+
err
.
message
);
});
```
...
...
@@ -1417,14 +1435,16 @@ getData( callback: AsyncCallback<PasteData>): void
**示例:**
```
js
let
systemPasteboard
=
pasteboard
.
getSystemPasteboard
();
systemPasteboard
.
getData
((
err
,
pasteData
)
=>
{
```
ts
import
{
BusinessError
}
from
'
@ohos.base
'
;
let
systemPasteboard
:
pasteboard
.
SystemPasteboard
=
pasteboard
.
getSystemPasteboard
();
systemPasteboard
.
getData
((
err
:
BusinessError
,
pasteData
:
pasteboard
.
PasteData
)
=>
{
if
(
err
)
{
console
.
error
(
'
Failed to get PasteData. Cause:
'
+
err
.
message
);
return
;
}
let
text
=
pasteData
.
getPrimaryText
();
let
text
:
string
=
pasteData
.
getPrimaryText
();
});
```
...
...
@@ -1452,13 +1472,15 @@ getData(): Promise<PasteData>
**示例:**
```
js
let
systemPasteboard
=
pasteboard
.
getSystemPasteboard
();
systemPasteboard
.
getData
().
then
((
pasteData
)
=>
{
let
text
=
pasteData
.
getPrimaryText
();
}).
catch
((
err
)
=>
{
```
ts
import
{
BusinessError
}
from
'
@ohos.base
'
;
let
systemPasteboard
:
pasteboard
.
SystemPasteboard
=
pasteboard
.
getSystemPasteboard
();
systemPasteboard
.
getData
().
then
((
pasteData
:
pasteboard
.
PasteData
)
=>
{
let
text
:
string
=
pasteData
.
getPrimaryText
();
}).
catch
((
err
:
BusinessError
)
=>
{
console
.
error
(
'
Failed to get PasteData. Cause:
'
+
err
.
message
);
})
})
;
```
### hasData<sup>9+</sup>
...
...
@@ -1477,9 +1499,11 @@ hasData(callback: AsyncCallback<boolean>): void
**示例:**
```
js
let
systemPasteboard
=
pasteboard
.
getSystemPasteboard
();
systemPasteboard
.
hasData
((
err
,
data
)
=>
{
```
ts
import
{
BusinessError
}
from
'
@ohos.base
'
;
let
systemPasteboard
:
pasteboard
.
SystemPasteboard
=
pasteboard
.
getSystemPasteboard
();
systemPasteboard
.
hasData
((
err
:
BusinessError
,
data
:
boolean
)
=>
{
if
(
err
)
{
console
.
error
(
`Failed to check the PasteData. Cause:
${
err
.
message
}
`
);
return
;
...
...
@@ -1504,11 +1528,13 @@ hasData(): Promise<boolean>
**示例:**
```
js
let
systemPasteboard
=
pasteboard
.
getSystemPasteboard
();
systemPasteboard
.
hasData
().
then
((
data
)
=>
{
```
ts
import
{
BusinessError
}
from
'
@ohos.base
'
;
let
systemPasteboard
:
pasteboard
.
SystemPasteboard
=
pasteboard
.
getSystemPasteboard
();
systemPasteboard
.
hasData
().
then
((
data
:
boolean
)
=>
{
console
.
info
(
`Succeeded in checking the PasteData. Data:
${
data
}
`
);
}).
catch
((
err
)
=>
{
}).
catch
((
err
:
BusinessError
)
=>
{
console
.
error
(
`Failed to check the PasteData. Cause:
${
err
.
message
}
`
);
});
```
...
...
@@ -1532,7 +1558,8 @@ clear(callback: AsyncCallback<void>): void
**示例:**
```
js
```
ts
let
systemPasteboard
:
pasteboard
.
SystemPasteboard
=
pasteboard
.
getSystemPasteboard
();
systemPasteboard
.
clear
((
err
,
data
)
=>
{
if
(
err
)
{
console
.
error
(
`Failed to clear the PasteData. Cause:
${
err
.
message
}
`
);
...
...
@@ -1561,10 +1588,13 @@ clear(): Promise<void>
**示例:**
```
js
```
ts
import
{
BusinessError
}
from
'
@ohos.base
'
;
let
systemPasteboard
:
pasteboard
.
SystemPasteboard
=
pasteboard
.
getSystemPasteboard
();
systemPasteboard
.
clear
().
then
((
data
)
=>
{
console
.
info
(
'
Succeeded in clearing the PasteData.
'
);
}).
catch
((
err
)
=>
{
}).
catch
((
err
:
BusinessError
)
=>
{
console
.
error
(
`Failed to clear the PasteData. Cause:
${
err
.
message
}
`
);
});
```
...
...
@@ -1588,14 +1618,16 @@ getPasteData( callback: AsyncCallback<PasteData>): void
**示例:**
```
js
let
systemPasteboard
=
pasteboard
.
getSystemPasteboard
();
systemPasteboard
.
getPasteData
((
err
,
pasteData
)
=>
{
```
ts
import
{
BusinessError
}
from
'
@ohos.base
'
;
let
systemPasteboard
:
pasteboard
.
SystemPasteboard
=
pasteboard
.
getSystemPasteboard
();
systemPasteboard
.
getPasteData
((
err
:
BusinessError
,
pasteData
:
pasteboard
.
PasteData
)
=>
{
if
(
err
)
{
console
.
error
(
'
Failed to get PasteData. Cause:
'
+
err
.
message
);
return
;
}
let
text
=
pasteData
.
getPrimaryText
();
let
text
:
string
=
pasteData
.
getPrimaryText
();
});
```
...
...
@@ -1618,13 +1650,15 @@ getPasteData(): Promise<PasteData>
**示例:**
```
js
let
systemPasteboard
=
pasteboard
.
getSystemPasteboard
();
systemPasteboard
.
getPasteData
().
then
((
pasteData
)
=>
{
let
text
=
pasteData
.
getPrimaryText
();
}).
catch
((
err
)
=>
{
```
ts
import
{
BusinessError
}
from
'
@ohos.base
'
;
let
systemPasteboard
:
pasteboard
.
SystemPasteboard
=
pasteboard
.
getSystemPasteboard
();
systemPasteboard
.
getPasteData
().
then
((
pasteData
:
pasteboard
.
PasteData
)
=>
{
let
text
:
string
=
pasteData
.
getPrimaryText
();
}).
catch
((
err
:
BusinessError
)
=>
{
console
.
error
(
'
Failed to get PasteData. Cause:
'
+
err
.
message
);
})
})
;
```
### hasPasteData<sup>(deprecated)</sup>
...
...
@@ -1646,8 +1680,11 @@ hasPasteData(callback: AsyncCallback<boolean>): void
**示例:**
```
js
systemPasteboard
.
hasPasteData
((
err
,
data
)
=>
{
```
ts
import
{
BusinessError
}
from
'
@ohos.base
'
;
let
systemPasteboard
:
pasteboard
.
SystemPasteboard
=
pasteboard
.
getSystemPasteboard
();
systemPasteboard
.
hasPasteData
((
err
:
BusinessError
,
data
:
boolean
)
=>
{
if
(
err
)
{
console
.
error
(
`Failed to check the PasteData. Cause:
${
err
.
message
}
`
);
return
;
...
...
@@ -1675,10 +1712,13 @@ hasPasteData(): Promise<boolean>
**示例:**
```
js
systemPasteboard
.
hasPasteData
().
then
((
data
)
=>
{
```
ts
import
{
BusinessError
}
from
'
@ohos.base
'
;
let
systemPasteboard
:
pasteboard
.
SystemPasteboard
=
pasteboard
.
getSystemPasteboard
();
systemPasteboard
.
hasPasteData
().
then
((
data
:
boolean
)
=>
{
console
.
info
(
`Succeeded in checking the PasteData. Data:
${
data
}
`
);
}).
catch
((
err
)
=>
{
}).
catch
((
err
:
BusinessError
)
=>
{
console
.
error
(
`Failed to check the PasteData. Cause:
${
err
.
message
}
`
);
});
```
...
...
@@ -1703,9 +1743,9 @@ setPasteData(data: PasteData, callback: AsyncCallback<void>): void
**示例:**
```
j
s
let
pasteData
=
pasteboard
.
createPlainTextData
(
'
content
'
);
let
systemPasteboard
=
pasteboard
.
getSystemPasteboard
();
```
t
s
let
pasteData
:
pasteboard
.
PasteData
=
pasteboard
.
createPlainTextData
(
'
content
'
);
let
systemPasteboard
:
pasteboard
.
SystemPasteboard
=
pasteboard
.
getSystemPasteboard
();
systemPasteboard
.
setPasteData
(
pasteData
,
(
err
,
data
)
=>
{
if
(
err
)
{
console
.
error
(
'
Failed to set PasteData. Cause:
'
+
err
.
message
);
...
...
@@ -1739,12 +1779,14 @@ setPasteData(data: PasteData): Promise<void>
**示例:**
```
js
let
pasteData
=
pasteboard
.
createPlainTextData
(
'
content
'
);
let
systemPasteboard
=
pasteboard
.
getSystemPasteboard
();
systemPasteboard
.
setPasteData
(
pasteData
).
then
((
data
)
=>
{
```
ts
import
{
BusinessError
}
from
'
@ohos.base
'
;
let
pasteData
:
pasteboard
.
PasteData
=
pasteboard
.
createPlainTextData
(
'
content
'
);
let
systemPasteboard
:
pasteboard
.
SystemPasteboard
=
pasteboard
.
getSystemPasteboard
();
systemPasteboard
.
setPasteData
(
pasteData
).
then
((
data
:
void
)
=>
{
console
.
info
(
'
Succeeded in setting PasteData.
'
);
}).
catch
((
err
)
=>
{
}).
catch
((
err
:
BusinessError
)
=>
{
console
.
error
(
'
Failed to set PasteData. Cause:
'
+
err
.
message
);
});
```
\ No newline at end of file
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录