Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
OpenHarmony
Docs
提交
fb337dea
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看板
体验新版 GitCode,发现更多精彩内容 >>
提交
fb337dea
编写于
12月 26, 2022
作者:
Z
zzs110
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
api优化
Signed-off-by:
N
zzs110
<
zhouzishuai@huawei.com
>
上级
afe9cedf
变更
1
隐藏空白更改
内联
并排
Showing
1 changed file
with
44 addition
and
44 deletion
+44
-44
zh-cn/application-dev/reference/apis/js-apis-pasteboard.md
zh-cn/application-dev/reference/apis/js-apis-pasteboard.md
+44
-44
未找到文件。
zh-cn/application-dev/reference/apis/js-apis-pasteboard.md
浏览文件 @
fb337dea
...
...
@@ -3,7 +3,7 @@
本模块主要提供管理系统剪贴板的能力,为系统复制、粘贴功能提供支持。系统剪贴板支持对文本、HTML、URI、Want、PixelMap等内容的操作。
> **说明:**
>
>
> 本模块首批接口从API version 6开始支持。后续版本的新增接口,采用上角标单独标记接口的起始版本。
## 导入模块
...
...
@@ -29,7 +29,7 @@ import pasteboard from '@ohos.pasteboard';
用于表示允许的数据字段类型。
**系统能力:**
以下各项对应的系统能力均为
SystemCapability.MiscServices.Pasteboard
**系统能力:**
SystemCapability.MiscServices.Pasteboard
| 类型 | 说明 |
| -------- | -------- |
...
...
@@ -120,11 +120,11 @@ let systemPasteboard = pasteboard.getSystemPasteboard();
**系统能力:**
SystemCapability.MiscServices.Pasteboard
| 名称
| 说明
|
| ----
- | -----------------------
|
| InApp
|表示仅允许同应用内粘贴。
|
| LocalDevice
|
表示允许在此设备中任何应用内粘贴。 |
| CrossDevice
|表示允许跨设备在任何应用内粘贴。
|
| 名称
| 值 | 说明
|
| ----
|---|-------------------
|
| InApp
| 0 | 表示仅允许同应用内粘贴。
|
| LocalDevice
| 1 |
表示允许在此设备中任何应用内粘贴。 |
| CrossDevice
| 2 | 表示允许跨设备在任何应用内粘贴。
|
## pasteboard.createHtmlData<sup>(deprecated)</sup>
...
...
@@ -418,7 +418,7 @@ convertToTextV9(callback: AsyncCallback<string>): void
**示例:**
```
js
let
record
=
pasteboard
.
create
UriRecord
(
'
dataability:///com.example.myapplication1/user.txt
'
);
let
record
=
pasteboard
.
create
Record
(
pasteboard
.
MIMETYPE_TEXT_URI
,
'
dataability:///com.example.myapplication1/user.txt
'
);
record
.
convertToTextV9
((
err
,
data
)
=>
{
if
(
err
)
{
console
.
error
(
`Failed to convert to text. Cause:
${
err
.
message
}
`
);
...
...
@@ -445,7 +445,7 @@ convertToTextV9(): Promise<string>
**示例:**
```
js
let
record
=
pasteboard
.
create
UriRecord
(
'
dataability:///com.example.myapplication1/user.txt
'
);
let
record
=
pasteboard
.
create
Record
(
pasteboard
.
MIMETYPE_TEXT_URI
,
'
dataability:///com.example.myapplication1/user.txt
'
);
record
.
convertToTextV9
().
then
((
data
)
=>
{
console
.
info
(
`Succeeded in converting to text. Data:
${
data
}
`
);
}).
catch
((
err
)
=>
{
...
...
@@ -536,7 +536,7 @@ getPrimaryText(): string
**示例:**
```
js
let
pasteData
=
pasteboard
.
create
PlainTextData
(
'
hello
'
);
let
pasteData
=
pasteboard
.
create
Data
(
pasteboard
.
MIMETYPE_TEXT_PLAIN
,
'
hello
'
);
let
plainText
=
pasteData
.
getPrimaryText
();
```
...
...
@@ -558,7 +558,7 @@ getPrimaryHtml(): string
```
js
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
.
create
HtmlData
(
html
);
let
pasteData
=
pasteboard
.
create
Data
(
pasteboard
.
MIMETYPE_TEXT_HTML
,
html
);
let
htmlText
=
pasteData
.
getPrimaryHtml
();
```
...
...
@@ -583,7 +583,7 @@ let object = {
bundleName
:
"
com.example.aafwk.test
"
,
abilityName
:
"
com.example.aafwk.test.TwoAbility
"
};
let
pasteData
=
pasteboard
.
create
WantData
(
object
);
let
pasteData
=
pasteboard
.
create
Data
(
pasteboard
.
MIMETYPE_TEXT_WANT
,
object
);
let
want
=
pasteData
.
getPrimaryWant
();
```
...
...
@@ -604,7 +604,7 @@ getPrimaryUri(): string
**示例:**
```
js
let
pasteData
=
pasteboard
.
create
UriData
(
'
dataability:///com.example.myapplication1/user.txt
'
);
let
pasteData
=
pasteboard
.
create
Data
(
pasteboard
.
MIMETYPE_TEXT_URI
,
'
dataability:///com.example.myapplication1/user.txt
'
);
let
uri
=
pasteData
.
getPrimaryUri
();
```
...
...
@@ -636,7 +636,7 @@ let opt = {
scaleMode
:
1
};
image
.
createPixelMap
(
buffer
,
opt
).
then
((
pixelMap
)
=>
{
let
pasteData
=
pasteboard
.
createData
(
'
app/xml
'
,
pixelMap
);
let
pasteData
=
pasteboard
.
createData
(
MIMETYPE_PIXELMAP
,
pixelMap
);
let
PixelMap
=
pasteData
.
getPrimaryPixelMap
();
});
```
...
...
@@ -660,10 +660,10 @@ addRecord(record: PasteDataRecord): void
**示例:**
```
js
let
pasteData
=
pasteboard
.
create
UriData
(
'
dataability:///com.example.myapplication1/user.txt
'
);
let
textRecord
=
pasteboard
.
create
PlainTextRecord
(
'
hello
'
);
let
pasteData
=
pasteboard
.
create
Data
(
pasteboard
.
MIMETYPE_TEXT_URI
,
'
dataability:///com.example.myapplication1/user.txt
'
);
let
textRecord
=
pasteboard
.
create
Record
(
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
.
create
HtmlTextRecord
(
html
);
let
htmlRecord
=
pasteboard
.
create
Record
(
pasteboard
.
MIMETYPE_TEXT_HTML
,
html
);
pasteData
.
addRecord
(
textRecord
);
pasteData
.
addRecord
(
htmlRecord
);
```
...
...
@@ -695,7 +695,7 @@ addRecord(mimeType: string, value: ValueType): void
**示例:**
```
js
let
pasteData
=
pasteboard
.
create
UriData
(
'
dataability:///com.example.myapplication1/user.txt
'
);
let
pasteData
=
pasteboard
.
create
Data
(
pasteboard
.
MIMETYPE_TEXT_URI
,
'
dataability:///com.example.myapplication1/user.txt
'
);
let
dataXml
=
new
ArrayBuffer
(
256
);
pasteData
.
addRecord
(
'
app/xml
'
,
dataXml
);
```
...
...
@@ -717,7 +717,7 @@ getMimeTypes(): Array<string>
**示例:**
```
js
let
pasteData
=
pasteboard
.
create
PlainTextData
(
'
hello
'
);
let
pasteData
=
pasteboard
.
create
Data
(
pasteboard
.
MIMETYPE_TEXT_PLAIN
,
'
hello
'
);
let
types
=
pasteData
.
getMimeTypes
();
```
...
...
@@ -738,7 +738,7 @@ getPrimaryMimeType(): string
**示例:**
```
js
let
pasteData
=
pasteboard
.
create
PlainTextData
(
'
hello
'
);
let
pasteData
=
pasteboard
.
create
Data
(
pasteboard
.
MIMETYPE_TEXT_PLAIN
,
'
hello
'
);
let
type
=
pasteData
.
getPrimaryMimeType
();
```
...
...
@@ -759,7 +759,7 @@ getProperty(): PasteDataProperty
**示例:**
```
js
let
pasteData
=
pasteboard
.
create
PlainTextData
(
'
hello
'
);
let
pasteData
=
pasteboard
.
create
Data
(
pasteboard
.
MIMETYPE_TEXT_PLAIN
,
'
hello
'
);
let
property
=
pasteData
.
getProperty
();
```
...
...
@@ -780,7 +780,7 @@ setProperty(property: PasteDataProperty): void
**示例:**
```
js
let
pasteData
=
pasteboard
.
create
HtmlData
(
'
application/xml
'
);
let
pasteData
=
pasteboard
.
create
Data
(
pasteboard
.
MIMETYPE_TEXT_HTML
,
'
application/xml
'
);
let
prop
=
pasteData
.
getProperty
();
prop
.
shareOption
=
pasteboard
.
ShareOption
.
InApp
;
pasteData
.
setProperty
(
prop
);
...
...
@@ -817,7 +817,7 @@ getRecord(index: number): PasteDataRecord
**示例:**
```
js
let
pasteData
=
pasteboard
.
create
PlainTextData
(
'
hello
'
);
let
pasteData
=
pasteboard
.
create
Data
(
pasteboard
.
MIMETYPE_TEXT_PLAIN
,
'
hello
'
);
let
record
=
pasteData
.
getRecord
(
0
);
```
...
...
@@ -838,7 +838,7 @@ getRecordCount(): number
**示例:**
```
js
let
pasteData
=
pasteboard
.
create
PlainTextData
(
'
hello
'
);
let
pasteData
=
pasteboard
.
create
Data
(
pasteboard
.
MIMETYPE_TEXT_PLAIN
,
'
hello
'
);
let
count
=
pasteData
.
getRecordCount
();
```
...
...
@@ -859,7 +859,7 @@ getTag(): string
**示例:**
```
js
let
pasteData
=
pasteboard
.
create
PlainTextData
(
'
hello
'
);
let
pasteData
=
pasteboard
.
create
Data
(
pasteboard
.
MIMETYPE_TEXT_PLAIN
,
'
hello
'
);
let
tag
=
pasteData
.
getTag
();
```
...
...
@@ -886,7 +886,7 @@ hasType(mimeType: string): boolean
**示例:**
```
js
let
pasteData
=
pasteboard
.
create
PlainTextData
(
'
hello
'
);
let
pasteData
=
pasteboard
.
create
Data
(
pasteboard
.
MIMETYPE_TEXT_PLAIN
,
'
hello
'
);
let
hasType
=
pasteData
.
hasType
(
pasteboard
.
MIMETYPE_TEXT_PLAIN
);
```
...
...
@@ -915,7 +915,7 @@ removeRecord(index: number): void
**示例:**
```
js
let
pasteData
=
pasteboard
.
create
PlainTextData
(
'
hello
'
);
let
pasteData
=
pasteboard
.
create
Data
(
pasteboard
.
MIMETYPE_TEXT_PLAIN
,
'
hello
'
);
pasteData
.
removeRecord
(
0
);
```
...
...
@@ -945,8 +945,8 @@ replaceRecord(index: number, record: PasteDataRecord): void
**示例:**
```
js
let
pasteData
=
pasteboard
.
create
PlainTextData
(
'
hello
'
);
let
record
=
pasteboard
.
create
UriRecord
(
'
dataability:///com.example.myapplication1/user.txt
'
);
let
pasteData
=
pasteboard
.
create
Data
(
pasteboard
.
MIMETYPE_TEXT_PLAIN
,
'
hello
'
);
let
record
=
pasteboard
.
create
Record
(
pasteboard
.
MIMETYPE_TEXT_URI
,
'
dataability:///com.example.myapplication1/user.txt
'
);
pasteData
.
replaceRecord
(
0
,
record
);
```
### addHtmlRecord<sup>(deprecated)</sup>
...
...
@@ -999,8 +999,8 @@ addWantRecord(want: Want): void
```
js
let
pasteData
=
pasteboard
.
createPlainTextData
(
'
hello
'
);
let
object
=
{
bundleName
:
"
com.example.aafwk.test
"
,
let
object
=
{
bundleName
:
"
com.example.aafwk.test
"
,
abilityName
:
"
com.example.aafwk.test.TwoAbility
"
};
pasteData
.
addWantRecord
(
object
);
...
...
@@ -1255,7 +1255,7 @@ clearData(callback: AsyncCallback<void>): void
```
js
let
systemPasteboard
=
pasteboard
.
getSystemPasteboard
();
systemPasteboard
.
clearData
((
err
,
data
)
=>
{
systemPasteboard
.
clearData
((
err
,
data
)
=>
{
if
(
err
)
{
console
.
error
(
`Failed to clear the pasteboard. Cause:
${
err
.
message
}
`
);
return
;
...
...
@@ -1282,7 +1282,7 @@ clearData(): Promise<void>
```
js
let
systemPasteboard
=
pasteboard
.
getSystemPasteboard
();
systemPasteboard
.
clearData
().
then
((
data
)
=>
{
systemPasteboard
.
clearData
().
then
((
data
)
=>
{
console
.
info
(
'
Succeeded in clearing the pasteboard.
'
);
}).
catch
((
err
)
=>
{
console
.
error
(
`Failed to clear the pasteboard. Cause:
${
err
.
message
}
`
);
...
...
@@ -1318,7 +1318,7 @@ setData(data: PasteData, callback: AsyncCallback<void>): void
```
js
let
pasteData
=
pasteboard
.
createPlainTextData
(
'
content
'
);
let
systemPasteboard
=
pasteboard
.
getSystemPasteboard
();
systemPasteboard
.
setData
(
pasteData
,
(
err
,
data
)
=>
{
systemPasteboard
.
setData
(
pasteData
,
(
err
,
data
)
=>
{
if
(
err
)
{
console
.
error
(
'
Failed to set PasteData. Cause:
'
+
err
.
message
);
return
;
...
...
@@ -1394,7 +1394,7 @@ getData( callback: AsyncCallback<PasteData>): void
```
js
let
systemPasteboard
=
pasteboard
.
getSystemPasteboard
();
systemPasteboard
.
getData
((
err
,
pasteData
)
=>
{
systemPasteboard
.
getData
((
err
,
pasteData
)
=>
{
if
(
err
)
{
console
.
error
(
'
Failed to get PasteData. Cause:
'
+
err
.
message
);
return
;
...
...
@@ -1429,7 +1429,7 @@ getData(): Promise<PasteData>
```
js
let
systemPasteboard
=
pasteboard
.
getSystemPasteboard
();
systemPasteboard
.
getData
().
then
((
pasteData
)
=>
{
systemPasteboard
.
getData
().
then
((
pasteData
)
=>
{
let
text
=
pasteData
.
getPrimaryText
();
}).
catch
((
err
)
=>
{
console
.
error
(
'
Failed to get PasteData. Cause:
'
+
err
.
message
);
...
...
@@ -1481,7 +1481,7 @@ hasData(): Promise<boolean>
```
js
let
systemPasteboard
=
pasteboard
.
getSystemPasteboard
();
systemPasteboard
.
hasData
().
then
((
data
)
=>
{
systemPasteboard
.
hasData
().
then
((
data
)
=>
{
console
.
info
(
`Succeeded in checking the PasteData. Data:
${
data
}
`
);
}).
catch
((
err
)
=>
{
console
.
error
(
`Failed to check the PasteData. Cause:
${
err
.
message
}
`
);
...
...
@@ -1508,8 +1508,8 @@ clear(callback: AsyncCallback<void>): void
**示例:**
```
js
systemPasteboard
.
clear
((
err
,
data
)
=>
{
if
(
err
)
{
systemPasteboard
.
clear
((
err
,
data
)
=>
{
if
(
err
)
{
console
.
error
(
`Failed to clear the PasteData. Cause:
${
err
.
message
}
`
);
return
;
}
...
...
@@ -1537,9 +1537,9 @@ clear(): Promise<void>
**示例:**
```
js
systemPasteboard
.
clear
().
then
((
data
)
=>
{
systemPasteboard
.
clear
().
then
((
data
)
=>
{
console
.
info
(
'
Succeeded in clearing the PasteData.
'
);
}).
catch
((
err
)
=>
{
}).
catch
((
err
)
=>
{
console
.
error
(
`Failed to clear the PasteData. Cause:
${
err
.
message
}
`
);
});
```
...
...
@@ -1595,7 +1595,7 @@ getPasteData(): Promise<PasteData>
```
js
let
systemPasteboard
=
pasteboard
.
getSystemPasteboard
();
systemPasteboard
.
getPasteData
().
then
((
pasteData
)
=>
{
systemPasteboard
.
getPasteData
().
then
((
pasteData
)
=>
{
let
text
=
pasteData
.
getPrimaryText
();
}).
catch
((
err
)
=>
{
console
.
error
(
'
Failed to get PasteData. Cause:
'
+
err
.
message
);
...
...
@@ -1651,7 +1651,7 @@ hasPasteData(): Promise<boolean>
**示例:**
```
js
systemPasteboard
.
hasPasteData
().
then
((
data
)
=>
{
systemPasteboard
.
hasPasteData
().
then
((
data
)
=>
{
console
.
info
(
`Succeeded in checking the PasteData. Data:
${
data
}
`
);
}).
catch
((
err
)
=>
{
console
.
error
(
`Failed to check the PasteData. Cause:
${
err
.
message
}
`
);
...
...
@@ -1681,7 +1681,7 @@ setPasteData(data: PasteData, callback: AsyncCallback<void>): void
```
js
let
pasteData
=
pasteboard
.
createPlainTextData
(
'
content
'
);
let
systemPasteboard
=
pasteboard
.
getSystemPasteboard
();
systemPasteboard
.
setPasteData
(
pasteData
,
(
err
,
data
)
=>
{
systemPasteboard
.
setPasteData
(
pasteData
,
(
err
,
data
)
=>
{
if
(
err
)
{
console
.
error
(
'
Failed to set PasteData. Cause:
'
+
err
.
message
);
return
;
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录