Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
OpenHarmony
Docs
提交
893b1edf
D
Docs
项目概览
OpenHarmony
/
Docs
大约 2 年 前同步成功
通知
161
Star
293
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看板
提交
893b1edf
编写于
5月 06, 2023
作者:
W
weishaoxiong
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Signed-off-by: weishaoxiong <weishaoxiong1@huawei.com>
feat: API10 接口资料适配刷新
上级
61545968
变更
1
隐藏空白更改
内联
并排
Showing
1 changed file
with
169 addition
and
2 deletion
+169
-2
zh-cn/application-dev/reference/apis/js-apis-wallpaper.md
zh-cn/application-dev/reference/apis/js-apis-wallpaper.md
+169
-2
未找到文件。
zh-cn/application-dev/reference/apis/js-apis-wallpaper.md
浏览文件 @
893b1edf
...
...
@@ -13,6 +13,21 @@
```
js
import
wallpaper
from
'
@ohos.wallpaper
'
;
```
## WallpaperResourceType<sup>10+</sup>
定义壁纸的资源枚举类型。
**系统能力**
: SystemCapability.MiscServices.Wallpaper
**系统接口**
:此接口为系统接口。
| 名称 | 值 |说明 |
| -------- | -------- |-------- |
| DEFAULT | 0 |默认资源。 |
| PICTURE | 1 |图片资源。 |
| VIDEO | 2 |视频资源。 |
| PACKAGE | 3 |package资源。 |
## WallpaperType<sup>7+</sup>
...
...
@@ -44,6 +59,158 @@ import wallpaper from '@ohos.wallpaper';
| alpha | number | 是 | 是 | 表示 alpha 值,范围为 0 到 255。 |
## wallpaper.setVideo<sup>10+</sup>
setVideo(source: string, wallpaperType: WallpaperType, callback: AsyncCallback
<
void
>
): void
将指定资源设置为指定类型的动态壁纸
**需要权限**
:ohos.permission.SET_WALLPAPER
**系统能力**
: SystemCapability.MiscServices.Wallpaper
**系统接口**
:此接口为系统接口。
**参数:**
| 参数名 | 类型 | 必填 | 说明 |
| -------- | -------- | -------- | -------- |
| source | string | 是 | mp4文件的Uri路径。 |
| wallpaperType |
[
WallpaperType
](
#wallpapertype
)
| 是 | 壁纸类型。 |
| callback | AsyncCallback
<
void
>
| 是 | 回调函数,设置壁纸成功,error为undefined,否则返回error信息。 |
**示例:**
```
js
let
wallpaperPath
=
"
/data/storage/el2/base/haps/test.mp4
"
;
try
{
wallpaper
.
setVideo
(
wallpaperPath
,
wallpaper
.
WallpaperType
.
WALLPAPER_SYSTEM
,
(
error
)
=>
{
if
(
error
)
{
console
.
error
(
`failed to setVideo because:
${
JSON
.
stringify
(
error
)}
`
);
return
;
}
console
.
log
(
`success to setVideo.`
);
});
}
catch
(
error
)
{
console
.
error
(
`failed to setVideo because:
${
JSON
.
stringify
(
error
)}
`
);
}
```
## wallpaper.setVideo<sup>10+</sup>
setVideo(source: string, wallpaperType: WallpaperType): Promise
<
void
>
将指定资源设置为指定类型的动态壁纸
**需要权限**
:ohos.permission.SET_WALLPAPER
**系统能力**
: SystemCapability.MiscServices.Wallpaper
**系统接口**
:此接口为系统接口。
**参数:**
| 参数名 | 类型 | 必填 | 说明 |
| -------- | -------- | -------- | -------- |
| source | string | 是 | mp4文件的Uri路径。 |
| wallpaperType |
[
WallpaperType
](
#wallpapertype
)
| 是 | 壁纸类型。 |
**返回值:**
| 类型 | 说明 |
| -------- | -------- |
| Promise
<
void
>
| 无返回结果的Promise对象。 |
**示例:**
```
js
let
wallpaperPath
=
"
/data/storage/el2/base/haps/test.mp4
"
;
try
{
wallpaper
.
setVideo
(
wallpaperPath
,
wallpaper
.
WallpaperType
.
WALLPAPER_SYSTEM
).
then
(()
=>
{
console
.
log
(
`success to setVideo.`
);
}).
catch
((
error
)
=>
{
console
.
error
(
`failed to setVideo because:
${
JSON
.
stringify
(
error
)}
`
);
});
}
catch
(
error
)
{
console
.
error
(
`failed to setVideo because:
${
JSON
.
stringify
(
error
)}
`
);
}
```
## wallpaper.on('wallpaperChange')<sup>10+</sup>
on(type: 'wallpaperChange', callback: (wallpaperType: WallpaperType, resourceType: WallpaperResourceType) =
>
void): void
订阅壁纸颜色变化结果上报事件。
**系统能力**
: SystemCapability.MiscServices.Wallpaper
**系统接口**
:此接口为系统接口。
**参数:**
| 参数名 | 类型 | 必填 | 说明 |
| -------- | -------- | -------- | -------- |
| type | string | 是 | 事件回调类型。支持的事件为'wallpaperChange',完成壁纸切换变化后触发该事件。 |
| callback | function | 是 | 壁纸变化触发该回调方法,返回壁纸类型和壁纸壁纸类型。
<br/>
- wallpaperType
<br/>
壁纸类型。
<br/>
- resourceType
<br/>
壁纸资源类型。 |
**示例:**
```
js
try
{
let
listener
=
(
wallpaperType
,
resourceType
)
=>
{
console
.
log
(
`wallpaper color changed.`
);
};
wallpaper
.
on
(
'
wallpaperChange
'
,
listener
);
}
catch
(
error
)
{
console
.
error
(
`failed to on because:
${
JSON
.
stringify
(
error
)}
`
);
}
```
## wallpaper.off('wallpaperChange')<sup>10+</sup>
off(type: 'wallpaperChange', callback?: (wallpaperType: WallpaperType, resourceType: WallpaperResourceType) =
>
void): void
取消订阅壁纸变化结果上报事件。
**系统能力**
: SystemCapability.MiscServices.Wallpaper
**系统接口**
:此接口为系统接口。
**参数:**
| 参数名 | 类型 | 必填 | 说明 |
| -------- | -------- | -------- | -------- |
| type | string | 是 | 事件回调类型。支持的事件为'wallpaperChange',完成壁纸切换变化后触发该事件。 |
| callback | function | 否 | 表示要取消的壁纸变化的回调,不填写该参数则取消订阅该type对应的所有回调。
<br/>
- wallpaperType
<br/>
壁纸类型。
<br/>
- resourceType
<br/>
壁纸资源类型。 |
**示例:**
```
js
let
listener
=
(
wallpaperType
,
resourceType
)
=>
{
console
.
log
(
`wallpaper color changed.`
);
};
try
{
wallpaper
.
on
(
'
wallpaperChange
'
,
listener
);
}
catch
(
error
)
{
console
.
error
(
`failed to on because:
${
JSON
.
stringify
(
error
)}
`
);
}
try
{
// 取消订阅listener
wallpaper
.
off
(
'
wallpaperChange
'
,
listener
);
}
catch
(
error
)
{
console
.
error
(
`failed to off because:
${
JSON
.
stringify
(
error
)}
`
);
}
try
{
// 取消所有'wallpaperChange'类型的订阅
wallpaper
.
off
(
'
wallpaperChange
'
);
}
catch
(
error
)
{
console
.
error
(
`failed to off because:
${
JSON
.
stringify
(
error
)}
`
);
}
```
## wallpaper.getColorsSync<sup>9+</sup>
getColorsSync(wallpaperType: WallpaperType): Array
<
RgbaColor
>
...
...
@@ -210,7 +377,7 @@ setImage(source: string | image.PixelMap, wallpaperType: WallpaperType, callback
```
js
// source类型为string
let
wallpaperPath
=
"
/data/
data/ohos.acts.aafwk.plrdtest.form/files/Cup_ic.jp
g
"
;
let
wallpaperPath
=
"
/data/
storage/el2/base/haps/js.jpe
g
"
;
wallpaper
.
setImage
(
wallpaperPath
,
wallpaper
.
WallpaperType
.
WALLPAPER_SYSTEM
,
(
error
)
=>
{
if
(
error
)
{
console
.
error
(
`failed to setImage because:
${
JSON
.
stringify
(
error
)}
`
);
...
...
@@ -270,7 +437,7 @@ setImage(source: string | image.PixelMap, wallpaperType: WallpaperType): Promise
```
js
// source类型为string
let
wallpaperPath
=
"
/data/
data/ohos.acts.aafwk.plrdtest.form/files/Cup_ic.jp
g
"
;
let
wallpaperPath
=
"
/data/
storage/el2/base/haps/js.jpe
g
"
;
wallpaper
.
setImage
(
wallpaperPath
,
wallpaper
.
WallpaperType
.
WALLPAPER_SYSTEM
).
then
(()
=>
{
console
.
log
(
`success to setImage.`
);
}).
catch
((
error
)
=>
{
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录