Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
OpenHarmony
Docs
提交
ca518ebb
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看板
未验证
提交
ca518ebb
编写于
12月 12, 2022
作者:
O
openharmony_ci
提交者:
Gitee
12月 12, 2022
浏览文件
操作
浏览文件
下载
差异文件
!12394 【壁纸】API参考优化
Merge pull request !12394 from weishaoxiong/cherry-pick-1670825966
上级
10371407
df28197a
变更
1
显示空白变更内容
内联
并排
Showing
1 changed file
with
588 addition
and
583 deletion
+588
-583
zh-cn/application-dev/reference/apis/js-apis-wallpaper.md
zh-cn/application-dev/reference/apis/js-apis-wallpaper.md
+588
-583
未找到文件。
zh-cn/application-dev/reference/apis/js-apis-wallpaper.md
浏览文件 @
ca518ebb
...
...
@@ -26,7 +26,467 @@ import wallpaper from '@ohos.wallpaper';
| WALLPAPER_LOCKSCREEN | 1 |锁屏壁纸标识。 |
## wallpaper.getColors
## RgbaColor
定义壁纸颜色信息结构。
**系统能力**
: SystemCapability.MiscServices.Wallpaper
| 名称 | 类型 | 可读 | 可写 | 说明 |
| -------- | -------- | -------- | -------- | -------- |
| red | number | 是 | 是 | 表示红色值,范围为 0 到 255。 |
| green | number | 是 | 是 | 表示绿色值,范围为 0 到 255。 |
| blue | number | 是 | 是 | 表示蓝色值,范围为 0 到 255。 |
| alpha | number | 是 | 是 | 表示 alpha 值,范围为 0 到 255。 |
## wallpaper.getColorsSync<sup>9+</sup>
getColorsSync(wallpaperType: WallpaperType): Array
<
RgbaColor
>
获取指定类型壁纸的主要颜色信息。
**系统能力**
: SystemCapability.MiscServices.Wallpaper
**参数:**
| 参数名 | 类型 | 必填 | 说明 |
| -------- | -------- | -------- | -------- |
| wallpaperType |
[
WallpaperType
](
#wallpapertype
)
| 是 | 壁纸类型。 |
**返回值**
:
| 类型 | 说明 |
| -------- | -------- |
| Array
<
[RgbaColor](#rgbacolor)
>
| 返回壁纸的主要颜色信息。 |
**示例**
:
```
js
let
colors
=
wallpaper
.
getColorsSync
(
wallpaper
.
WallpaperType
.
WALLPAPER_SYSTEM
);
```
## wallpaper.getIdSync<sup>9+</sup>
getIdSync(wallpaperType: WallpaperType): number
获取指定类型壁纸的ID。
**系统能力**
: SystemCapability.MiscServices.Wallpaper
**参数:**
| 参数名 | 类型 | 必填 | 说明 |
| -------- | -------- | -------- | -------- |
| wallpaperType |
[
WallpaperType
](
#wallpapertype
)
| 是 | 壁纸类型。 |
**返回值**
:
| 类型 | 说明 |
| -------- | -------- |
| number | 返回壁纸的ID。如果配置了这种壁纸类型的壁纸就返回一个大于等于0的数,否则返回-1。取值范围是-1~2^31-1。 |
**示例**
:
```
js
let
id
=
wallpaper
.
getIdSync
(
wallpaper
.
WallpaperType
.
WALLPAPER_SYSTEM
);
```
## wallpaper.getMinHeightSync<sup>9+</sup>
getMinHeightSync(): number
获取壁纸的最小高度值。
**系统能力**
: SystemCapability.MiscServices.Wallpaper
**返回值:**
| 类型 | 说明 |
| -------- | -------- |
| number | 返回壁纸的最小高度值,单位是像素。如果返回值等于0,说明没有设置壁纸,调用者应该使用默认显示的高度值代替。 |
**示例:**
```
js
let
minHeight
=
wallpaper
.
getMinHeightSync
();
```
## wallpaper.getMinWidthSync<sup>9+</sup>
getMinWidthSync(): number
获取壁纸的最小宽度值。
**系统能力**
: SystemCapability.MiscServices.Wallpaper
**返回值:**
| 类型 | 说明 |
| -------- | -------- |
| number | 壁纸的最小宽度值,单位是像素。如果返回值等于0,说明没有设置壁纸,调用者应该使用默认显示的宽度值代替。 |
**示例:**
```
js
let
minWidth
=
wallpaper
.
getMinWidthSync
();
```
## wallpaper.isChangeAllowed<sup>9+</sup>
isChangeAllowed(): boolean
是否允许应用改变当前用户的壁纸。
**系统能力**
: SystemCapability.MiscServices.Wallpaper
**返回值:**
| 类型 | 说明 |
| -------- | -------- |
| boolean | 返回是否允许应用改变当前用户的壁纸。如果允许返回true,否则返回false。 |
**示例:**
```
js
let
isChangeAllowed
=
wallpaper
.
isChangeAllowed
();
```
## wallpaper.isUserChangeAllowed<sup>9+</sup>
isUserChangeAllowed(): boolean
是否允许用户设置壁纸。
**系统能力**
: SystemCapability.MiscServices.Wallpaper
**返回值:**
| 类型 | 说明 |
| -------- | -------- |
| boolean | 返回是否允许用户设置壁纸。如果允许返回true,否则返回false。 |
**示例:**
```
js
let
isUserChangeAllowed
=
wallpaper
.
isUserChangeAllowed
();
```
## wallpaper.restore<sup>9+</sup>
restore(wallpaperType: WallpaperType, callback: AsyncCallback
<
void
>
): void
移除指定类型的壁纸,恢复为默认显示的壁纸。
**需要权限**
:ohos.permission.SET_WALLPAPER
**系统能力**
: SystemCapability.MiscServices.Wallpaper
**参数:**
| 参数名 | 类型 | 必填 | 说明 |
| -------- | -------- | -------- | -------- |
| wallpaperType |
[
WallpaperType
](
#wallpapertype
)
| 是 | 壁纸类型。 |
| callback | AsyncCallback
<
void
>
| 是 | 回调函数,移除壁纸成功,error为undefined 否则返回error信息。 |
**示例:**
```
js
wallpaper
.
restore
(
wallpaper
.
WallpaperType
.
WALLPAPER_SYSTEM
,
(
error
)
=>
{
if
(
error
)
{
console
.
error
(
`failed to restore because:
${
JSON
.
stringify
(
error
)}
`
);
return
;
}
console
.
log
(
`success to restore.`
);
});
```
## wallpaper.restore<sup>9+</sup>
restore(wallpaperType: WallpaperType): Promise
<
void
>
移除指定类型的壁纸,恢复为默认显示的壁纸。
**需要权限**
:ohos.permission.SET_WALLPAPER
**系统能力**
: SystemCapability.MiscServices.Wallpaper
**参数:**
| 参数名 | 类型 | 必填 | 说明 |
| -------- | -------- | -------- | -------- |
| wallpaperType |
[
WallpaperType
](
#wallpapertype
)
| 是 | 壁纸类型。 |
**返回值:**
| 类型 | 说明 |
| -------- | -------- |
| Promise
<
void
>
| Promise对象。无返回结果的Promise对象。 |
**示例:**
```
js
wallpaper
.
restore
(
wallpaper
.
WallpaperType
.
WALLPAPER_SYSTEM
).
then
(()
=>
{
console
.
log
(
`success to restore.`
);
}).
catch
((
error
)
=>
{
console
.
error
(
`failed to restore because:
${
JSON
.
stringify
(
error
)}
`
);
});
```
## wallpaper.setImage<sup>9+</sup>
setImage(source: string | image.PixelMap, wallpaperType: WallpaperType, callback: AsyncCallback
<
void
>
): void
将指定资源设置为指定类型的壁纸。
**需要权限**
:ohos.permission.SET_WALLPAPER
**系统能力**
: SystemCapability.MiscServices.Wallpaper
**参数:**
| 参数名 | 类型 | 必填 | 说明 |
| -------- | -------- | -------- | -------- |
| source | string
\|
[
image.PixelMap
](
js-apis-image.md#pixelmap7
)
| 是 | JPEG或PNG文件的Uri路径,或者PNG格式文件的位图。 |
| wallpaperType |
[
WallpaperType
](
#wallpapertype
)
| 是 | 壁纸类型。 |
| callback | AsyncCallback
<
void
>
| 是 | 回调函数,设置壁纸成功,error为undefined 否则返回error信息。 |
**示例:**
```
js
// source类型为string
let
wallpaperPath
=
"
/data/data/ohos.acts.aafwk.plrdtest.form/files/Cup_ic.jpg
"
;
wallpaper
.
setImage
(
wallpaperPath
,
wallpaper
.
WallpaperType
.
WALLPAPER_SYSTEM
,
(
error
)
=>
{
if
(
error
)
{
console
.
error
(
`failed to setImage because:
${
JSON
.
stringify
(
error
)}
`
);
return
;
}
console
.
log
(
`success to setImage.`
);
});
// source类型为image.PixelMap
import
image
from
'
@ohos.multimedia.image
'
;
let
imageSource
=
image
.
createImageSource
(
"
file://
"
+
wallpaperPath
);
let
opts
=
{
"
desiredSize
"
:
{
"
height
"
:
3648
,
"
width
"
:
2736
}
};
imageSource
.
createPixelMap
(
opts
).
then
((
pixelMap
)
=>
{
wallpaper
.
setImage
(
pixelMap
,
wallpaper
.
WallpaperType
.
WALLPAPER_SYSTEM
,
(
error
)
=>
{
if
(
error
)
{
console
.
error
(
`failed to setImage because:
${
JSON
.
stringify
(
error
)}
`
);
return
;
}
console
.
log
(
`success to setImage.`
);
});
}).
catch
((
error
)
=>
{
console
.
error
(
`failed to createPixelMap because:
${
JSON
.
stringify
(
error
)}
`
);
});
```
## wallpaper.setImage<sup>9+</sup>
setImage(source: string | image.PixelMap, wallpaperType: WallpaperType): Promise
<
void
>
将指定资源设置为指定类型的壁纸。
**需要权限**
:ohos.permission.SET_WALLPAPER
**系统能力**
: SystemCapability.MiscServices.Wallpaper
**参数:**
| 参数名 | 类型 | 必填 | 说明 |
| -------- | -------- | -------- | -------- |
| source | string
\|
[
image.PixelMap
](
js-apis-image.md#pixelmap7
)
| 是 | JPEG或PNG文件的Uri路径,或者PNG格式文件的位图。 |
| wallpaperType |
[
WallpaperType
](
#wallpapertype
)
| 是 | 壁纸类型。 |
**返回值:**
| 类型 | 说明 |
| -------- | -------- |
| Promise
<
void
>
| Promise对象。无返回结果的Promise对象。 |
**示例:**
```
js
// source类型为string
let
wallpaperPath
=
"
/data/data/ohos.acts.aafwk.plrdtest.form/files/Cup_ic.jpg
"
;
wallpaper
.
setImage
(
wallpaperPath
,
wallpaper
.
WallpaperType
.
WALLPAPER_SYSTEM
).
then
(()
=>
{
console
.
log
(
`success to setImage.`
);
}).
catch
((
error
)
=>
{
console
.
error
(
`failed to setImage because:
${
JSON
.
stringify
(
error
)}
`
);
});
// source类型为image.PixelMap
import
image
from
'
@ohos.multimedia.image
'
;
let
imageSource
=
image
.
createImageSource
(
"
file://
"
+
wallpaperPath
);
let
opts
=
{
"
desiredSize
"
:
{
"
height
"
:
3648
,
"
width
"
:
2736
}
};
imageSource
.
createPixelMap
(
opts
).
then
((
pixelMap
)
=>
{
wallpaper
.
setImage
(
pixelMap
,
wallpaper
.
WallpaperType
.
WALLPAPER_SYSTEM
).
then
(()
=>
{
console
.
log
(
`success to setImage.`
);
}).
catch
((
error
)
=>
{
console
.
error
(
`failed to setImage because:
${
JSON
.
stringify
(
error
)}
`
);
});
}).
catch
((
error
)
=>
{
console
.
error
(
`failed to createPixelMap because:
${
JSON
.
stringify
(
error
)}
`
);
});
```
## wallpaper.getFileSync<sup>9+</sup>
getFileSync(wallpaperType: WallpaperType): number;
获取指定类型的壁纸文件。
**需要权限**
:ohos.permission.GET_WALLPAPER
**系统能力**
: SystemCapability.MiscServices.Wallpaper
**参数:**
| 参数名 | 类型 | 必填 | 说明 |
| -------- | -------- | -------- | -------- |
| wallpaperType |
[
WallpaperType
](
#wallpapertype
)
| 是 | 壁纸类型。 |
**返回值:**
| 类型 | 说明 |
| -------- | -------- |
| number | 调用成功则返回壁纸文件描述符ID,调用失败则返回error信息。 |
**示例:**
```
js
let
file
=
wallpaper
.
getFileSync
(
wallpaper
.
WallpaperType
.
WALLPAPER_SYSTEM
);
```
## wallpaper.getImage<sup>9+</sup>
getImage(wallpaperType: WallpaperType, callback: AsyncCallback
<
image.PixelMap
>
): void;
获取壁纸图片的像素图。
**需要权限**
:ohos.permission.GET_WALLPAPER
**系统能力**
: SystemCapability.MiscServices.Wallpaper
**系统接口**
:此接口为系统接口。
**参数:**
| 参数名 | 类型 | 必填 | 说明 |
| -------- | -------- | -------- | -------- |
| wallpaperType |
[
WallpaperType
](
#wallpapertype
)
| 是 | 壁纸类型。 |
| callback | AsyncCallback
<
[image.PixelMap](js-apis-image.md#pixelmap7)
>
| 是 | 回调函数,调用成功则返回壁纸图片的像素图大小,调用失败则返回error信息。 |
**示例:**
```
js
wallpaper
.
getImage
(
wallpaper
.
WallpaperType
.
WALLPAPER_SYSTEM
,
function
(
error
,
data
)
{
if
(
error
)
{
console
.
error
(
`failed to getImage because:
${
JSON
.
stringify
(
error
)}
`
);
return
;
}
console
.
log
(
`success to getImage:
${
JSON
.
stringify
(
data
)}
`
);
});
```
## wallpaper.getImage<sup>9+</sup>
getImage(wallpaperType: WallpaperType): Promise
<
image.PixelMap
>
获取壁纸图片的像素图。
**需要权限**
:ohos.permission.GET_WALLPAPER
**系统能力**
: SystemCapability.MiscServices.Wallpaper
**系统接口**
:此接口为系统接口。
**参数:**
| 参数名 | 类型 | 必填 | 说明 |
| -------- | -------- | -------- | -------- |
| wallpaperType |
[
WallpaperType
](
#wallpapertype
)
| 是 | 壁纸类型。 |
**返回值:**
| 类型 | 说明 |
| -------- | -------- |
| Promise
<
[image.PixelMap](js-apis-image.md#pixelmap7)
>
| 调用成功则返回壁纸图片的像素图大小,调用失败则返回error信息。 |
**示例:**
```
js
wallpaper
.
getImage
(
wallpaper
.
WallpaperType
.
WALLPAPER_SYSTEM
).
then
((
data
)
=>
{
console
.
log
(
`success to getImage:
${
JSON
.
stringify
(
data
)}
`
);
}).
catch
((
error
)
=>
{
console
.
error
(
`failed to getImage because:
${
JSON
.
stringify
(
error
)}
`
);
});
```
## wallpaper.on('colorChange')<sup>9+</sup>
on(type: 'colorChange', callback: (colors: Array
<
RgbaColor
>
, wallpaperType: WallpaperType) =
>
void): void
订阅壁纸颜色变化结果上报事件。
**系统能力**
: SystemCapability.MiscServices.Wallpaper
**参数:**
| 参数名 | 类型 | 必填 | 说明 |
| -------- | -------- | -------- | -------- |
| type | string | 是 | 取值为'colorChange',表示壁纸颜色变化结果上报事件。 |
| callback | function | 是 | 壁纸颜色变化触发该回调方法,返回壁纸类型和壁纸的主要颜色信息。
<br/>
- colors
<br/>
壁纸的主要颜色信息,其类型见
[
RgbaColor
](
#rgbacolor
)
。
<br/>
- wallpaperType
<br/>
壁纸类型。 |
**示例:**
```
js
let
listener
=
(
colors
,
wallpaperType
)
=>
{
console
.
log
(
`wallpaper color changed.`
);
};
wallpaper
.
on
(
'
colorChange
'
,
listener
);
```
## wallpaper.off('colorChange')<sup>9+</sup>
off(type: 'colorChange', callback?: (colors: Array
<
RgbaColor
>
, wallpaperType: WallpaperType) =
>
void): void
取消订阅壁纸颜色变化结果上报事件。
**系统能力**
: SystemCapability.MiscServices.Wallpaper
**参数:**
| 参数名 | 类型 | 必填 | 说明 |
| -------- | -------- | -------- | -------- |
| type | string | 是 | 取值为'colorChange',表示取消订阅壁纸颜色变化结果上报事件。 |
| callback | function | 否 | 表示要取消的壁纸颜色变化的回调,不填写该参数则取消订阅该type对应的所有回调。
<br/>
- colors
<br/>
壁纸的主要颜色信息,其类型见
[
RgbaColor
](
#rgbacolor
)
。
<br/>
- wallpaperType
<br/>
壁纸类型。 |
**示例:**
```
js
let
listener
=
(
colors
,
wallpaperType
)
=>
{
console
.
log
(
`wallpaper color changed.`
);
};
wallpaper
.
on
(
'
colorChange
'
,
listener
);
// 取消订阅listener
wallpaper
.
off
(
'
colorChange
'
,
listener
);
// 取消所有'colorChange'类型的订阅
wallpaper
.
off
(
'
colorChange
'
);
```
## wallpaper.getColors<sup>(deprecated)</sup>
getColors(wallpaperType: WallpaperType, callback: AsyncCallback
<
Array
<
RgbaColor
>>
): void
...
...
@@ -50,14 +510,14 @@ getColors(wallpaperType: WallpaperType, callback: AsyncCallback<Array<Rgba
```
js
wallpaper
.
getColors
(
wallpaper
.
WallpaperType
.
WALLPAPER_SYSTEM
,
(
error
,
data
)
=>
{
if
(
error
)
{
console
.
error
(
`failed to getColors because:
`
+
JSON
.
stringify
(
error
)
);
console
.
error
(
`failed to getColors because:
${
JSON
.
stringify
(
error
)}
`
);
return
;
}
console
.
log
(
`success to getColors
.
`
);
console
.
log
(
`success to getColors
:
${
JSON
.
stringify
(
data
)}
`
);
});
```
## wallpaper.getColors
## wallpaper.getColors
<sup>(deprecated)</sup>
getColors(wallpaperType: WallpaperType): Promise
<
Array
<
RgbaColor
>>
...
...
@@ -85,39 +545,13 @@ getColors(wallpaperType: WallpaperType): Promise<Array<RgbaColor>>
```
js
wallpaper
.
getColors
(
wallpaper
.
WallpaperType
.
WALLPAPER_SYSTEM
).
then
((
data
)
=>
{
console
.
log
(
`success to getColors
.
`
);
console
.
log
(
`success to getColors
:
${
JSON
.
stringify
(
data
)}
`
);
}).
catch
((
error
)
=>
{
console
.
error
(
`failed to getColors because:
`
+
JSON
.
stringify
(
error
)
);
console
.
error
(
`failed to getColors because:
${
JSON
.
stringify
(
error
)}
`
);
});
```
## wallpaper.getColorsSync<sup>9+</sup>
getColorsSync(wallpaperType: WallpaperType): Array
<
RgbaColor
>
获取指定类型壁纸的主要颜色信息。
**系统能力**
: SystemCapability.MiscServices.Wallpaper
**参数:**
| 参数名 | 类型 | 必填 | 说明 |
| -------- | -------- | -------- | -------- |
| wallpaperType |
[
WallpaperType
](
#wallpapertype
)
| 是 | 壁纸类型。 |
**返回值**
:
| 类型 | 说明 |
| -------- | -------- |
| Array
<
[RgbaColor](#rgbacolor)
>
| 返回壁纸的主要颜色信息。 |
**示例**
:
```
js
let
colors
=
wallpaper
.
getColorsSync
(
wallpaper
.
WallpaperType
.
WALLPAPER_SYSTEM
);
```
## wallpaper.getId
## wallpaper.getId<sup>(deprecated)</sup>
getId(wallpaperType: WallpaperType, callback: AsyncCallback
<
number
>
): void
...
...
@@ -141,14 +575,14 @@ getId(wallpaperType: WallpaperType, callback: AsyncCallback<number>): void
```
js
wallpaper
.
getId
(
wallpaper
.
WallpaperType
.
WALLPAPER_SYSTEM
,
(
error
,
data
)
=>
{
if
(
error
)
{
console
.
error
(
`failed to getId because:
`
+
JSON
.
stringify
(
error
)
);
console
.
error
(
`failed to getId because:
${
JSON
.
stringify
(
error
)}
`
);
return
;
}
console
.
log
(
`success to getId:
`
+
JSON
.
stringify
(
data
)
);
console
.
log
(
`success to getId:
${
JSON
.
stringify
(
data
)}
`
);
});
```
## wallpaper.getId
## wallpaper.getId
<sup>(deprecated)</sup>
getId(wallpaperType: WallpaperType): Promise
<
number
>
...
...
@@ -176,39 +610,13 @@ getId(wallpaperType: WallpaperType): Promise<number>
```
js
wallpaper
.
getId
(
wallpaper
.
WallpaperType
.
WALLPAPER_SYSTEM
).
then
((
data
)
=>
{
console
.
log
(
`success to getId:
`
+
JSON
.
stringify
(
data
)
);
console
.
log
(
`success to getId:
${
JSON
.
stringify
(
data
)}
`
);
}).
catch
((
error
)
=>
{
console
.
error
(
`failed to getId because:
`
+
JSON
.
stringify
(
error
)
);
console
.
error
(
`failed to getId because:
${
JSON
.
stringify
(
error
)}
`
);
});
```
## wallpaper.getIdSync<sup>9+</sup>
getIdSync(wallpaperType: WallpaperType): number
获取指定类型壁纸的ID。
**系统能力**
: SystemCapability.MiscServices.Wallpaper
**参数:**
| 参数名 | 类型 | 必填 | 说明 |
| -------- | -------- | -------- | -------- |
| wallpaperType |
[
WallpaperType
](
#wallpapertype
)
| 是 | 壁纸类型。 |
**返回值**
:
| 类型 | 说明 |
| -------- | -------- |
| number | 返回壁纸的ID。如果配置了这种壁纸类型的壁纸就返回一个大于等于0的数,否则返回-1。取值范围是-1~2^31-1。 |
**示例**
:
```
js
let
id
=
wallpaper
.
getIdSync
(
wallpaper
.
WallpaperType
.
WALLPAPER_SYSTEM
);
```
## wallpaper.getMinHeight
## wallpaper.getMinHeight<sup>(deprecated)</sup>
getMinHeight(callback: AsyncCallback
<
number
>
): void
...
...
@@ -231,14 +639,14 @@ getMinHeight(callback: AsyncCallback<number>): void
```
js
wallpaper
.
getMinHeight
((
error
,
data
)
=>
{
if
(
error
)
{
console
.
error
(
`failed to getMinHeight because:
`
+
JSON
.
stringify
(
error
)
);
console
.
error
(
`failed to getMinHeight because:
${
JSON
.
stringify
(
error
)}
`
);
return
;
}
console
.
log
(
`success to getMinHeight:
`
+
JSON
.
stringify
(
data
)
);
console
.
log
(
`success to getMinHeight:
${
JSON
.
stringify
(
data
)}
`
);
});
```
## wallpaper.getMinHeight
## wallpaper.getMinHeight
<sup>(deprecated)</sup>
getMinHeight(): Promise
<
number
>
...
...
@@ -260,33 +668,13 @@ getMinHeight(): Promise<number>
```
js
wallpaper
.
getMinHeight
().
then
((
data
)
=>
{
console
.
log
(
`success to getMinHeight:
`
+
JSON
.
stringify
(
data
)
);
console
.
log
(
`success to getMinHeight:
${
JSON
.
stringify
(
data
)}
`
);
}).
catch
((
error
)
=>
{
console
.
error
(
`failed to getMinHeight because:
`
+
JSON
.
stringify
(
error
)
);
console
.
error
(
`failed to getMinHeight because:
${
JSON
.
stringify
(
error
)}
`
);
});
```
## wallpaper.getMinHeightSync<sup>9+</sup>
getMinHeightSync(): number
获取壁纸的最小高度值。
**系统能力**
: SystemCapability.MiscServices.Wallpaper
**返回值:**
| 类型 | 说明 |
| -------- | -------- |
| number | 返回壁纸的最小高度值,单位是像素。如果返回值等于0,说明没有设置壁纸,调用者应该使用默认显示的高度值代替。 |
**示例:**
```
js
let
minHeight
=
wallpaper
.
getMinHeightSync
();
```
## wallpaper.getMinWidth
## wallpaper.getMinWidth<sup>(deprecated)</sup>
getMinWidth(callback: AsyncCallback
<
number
>
): void
...
...
@@ -309,14 +697,14 @@ getMinWidth(callback: AsyncCallback<number>): void
```
js
wallpaper
.
getMinWidth
((
error
,
data
)
=>
{
if
(
error
)
{
console
.
error
(
`failed to getMinWidth because:
`
+
JSON
.
stringify
(
error
)
);
console
.
error
(
`failed to getMinWidth because:
${
JSON
.
stringify
(
error
)}
`
);
return
;
}
console
.
log
(
`success to getMinWidth:
`
+
JSON
.
stringify
(
data
)
);
console
.
log
(
`success to getMinWidth:
${
JSON
.
stringify
(
data
)}
`
);
});
```
## wallpaper.getMinWidth
## wallpaper.getMinWidth
<sup>(deprecated)</sup>
getMinWidth(): Promise
<
number
>
...
...
@@ -338,33 +726,13 @@ getMinWidth(): Promise<number>
```
js
wallpaper
.
getMinWidth
().
then
((
data
)
=>
{
console
.
log
(
`success to getMinWidth:
`
+
JSON
.
stringify
(
data
)
);
console
.
log
(
`success to getMinWidth:
${
JSON
.
stringify
(
data
)}
`
);
}).
catch
((
error
)
=>
{
console
.
error
(
`failed to getMinWidth because:
`
+
JSON
.
stringify
(
error
)
);
console
.
error
(
`failed to getMinWidth because:
${
JSON
.
stringify
(
error
)}
`
);
});
```
## wallpaper.getMinWidthSync<sup>9+</sup>
getMinWidthSync(): number
获取壁纸的最小宽度值。
**系统能力**
: SystemCapability.MiscServices.Wallpaper
**返回值:**
| 类型 | 说明 |
| -------- | -------- |
| number | 壁纸的最小宽度值,单位是像素。如果返回值等于0,说明没有设置壁纸,调用者应该使用默认显示的宽度值代替。 |
**示例:**
```
js
let
minWidth
=
wallpaper
.
getMinWidthSync
();
```
## wallpaper.isChangePermitted
## wallpaper.isChangePermitted<sup>(deprecated)</sup>
isChangePermitted(callback: AsyncCallback
<
boolean
>
): void
...
...
@@ -387,14 +755,14 @@ isChangePermitted(callback: AsyncCallback<boolean>): void
```
js
wallpaper
.
isChangePermitted
((
error
,
data
)
=>
{
if
(
error
)
{
console
.
error
(
`failed to isChangePermitted because:
`
+
JSON
.
stringify
(
error
)
);
console
.
error
(
`failed to isChangePermitted because:
${
JSON
.
stringify
(
error
)}
`
);
return
;
}
console
.
log
(
`success to isChangePermitted:
`
+
JSON
.
stringify
(
data
)
);
console
.
log
(
`success to isChangePermitted:
${
JSON
.
stringify
(
data
)}
`
);
});
```
## wallpaper.isChangePermitted
## wallpaper.isChangePermitted
<sup>(deprecated)</sup>
isChangePermitted(): Promise
<
boolean
>
...
...
@@ -416,33 +784,13 @@ isChangePermitted(): Promise<boolean>
```
js
wallpaper
.
isChangePermitted
().
then
((
data
)
=>
{
console
.
log
(
`success to isChangePermitted:
`
+
JSON
.
stringify
(
data
)
);
console
.
log
(
`success to isChangePermitted:
${
JSON
.
stringify
(
data
)}
`
);
}).
catch
((
error
)
=>
{
console
.
error
(
`failed to isChangePermitted because:
`
+
JSON
.
stringify
(
error
)
);
console
.
error
(
`failed to isChangePermitted because:
${
JSON
.
stringify
(
error
)}
`
);
});
```
## wallpaper.isChangeAllowed<sup>9+</sup>
isChangeAllowed(): boolean
是否允许应用改变当前用户的壁纸。
**系统能力**
: SystemCapability.MiscServices.Wallpaper
**返回值:**
| 类型 | 说明 |
| -------- | -------- |
| boolean | 返回是否允许应用改变当前用户的壁纸。如果允许返回true,否则返回false。 |
**示例:**
```
js
let
isChangeAllowed
=
wallpaper
.
isChangeAllowed
();
```
## wallpaper.isOperationAllowed
## wallpaper.isOperationAllowed<sup>(deprecated)</sup>
isOperationAllowed(callback: AsyncCallback
<
boolean
>
): void
...
...
@@ -465,200 +813,50 @@ isOperationAllowed(callback: AsyncCallback<boolean>): void
```
js
wallpaper
.
isOperationAllowed
((
error
,
data
)
=>
{
if
(
error
)
{
console
.
error
(
`failed to isOperationAllowed because: `
+
JSON
.
stringify
(
error
));
return
;
}
console
.
log
(
`success to isOperationAllowed: `
+
JSON
.
stringify
(
data
));
});
```
## wallpaper.isOperationAllowed
isOperationAllowed(): Promise
<
boolean
>
是否允许用户设置壁纸。
> **说明:**
>
> 从 API version 7开始支持,从API version 9开始废弃。建议使用[wallpaper.isUserChangeAllowed<sup>9+</sup>](#wallpaperisuserchangeallowed9)代替。
**系统能力**
: SystemCapability.MiscServices.Wallpaper
**返回值:**
| 类型 | 说明 |
| -------- | -------- |
| Promise
<
boolean
>
| 异步回调函数,返回是否允许用户设置壁纸。如果允许返回true,否则返回false。 |
**示例:**
```
js
wallpaper
.
isOperationAllowed
().
then
((
data
)
=>
{
console
.
log
(
`success to isOperationAllowed: `
+
JSON
.
stringify
(
data
));
}).
catch
((
error
)
=>
{
console
.
error
(
`failed to isOperationAllowed because: `
+
JSON
.
stringify
(
error
));
});
```
## wallpaper.isUserChangeAllowed<sup>9+</sup>
isUserChangeAllowed(): boolean
是否允许用户设置壁纸。
**系统能力**
: SystemCapability.MiscServices.Wallpaper
**返回值:**
| 类型 | 说明 |
| -------- | -------- |
| boolean | 返回是否允许用户设置壁纸。如果允许返回true,否则返回false。 |
**示例:**
```
js
let
isUserChangeAllowed
=
wallpaper
.
isUserChangeAllowed
();
```
## wallpaper.reset
reset(wallpaperType: WallpaperType, callback: AsyncCallback
<
void
>
): void
移除指定类型的壁纸,恢复为默认显示的壁纸。
> **说明:**
>
> 从 API version 7开始支持,从API version 9开始废弃。建议使用[wallpaper.restore<sup>9+</sup>](#wallpaperrestore9)代替。
**需要权限**
:ohos.permission.SET_WALLPAPER
**系统能力**
: SystemCapability.MiscServices.Wallpaper
**参数:**
| 参数名 | 类型 | 必填 | 说明 |
| -------- | -------- | -------- | -------- |
| wallpaperType |
[
WallpaperType
](
#wallpapertype
)
| 是 | 壁纸类型。 |
| callback | AsyncCallback
<
void
>
| 是 | 回调函数,调用成功则返回是否移除成功的结果,调用失败则返回error信息。 |
**示例:**
```
js
wallpaper
.
reset
(
wallpaper
.
WallpaperType
.
WALLPAPER_SYSTEM
,
(
error
,
data
)
=>
{
if
(
error
)
{
console
.
error
(
`failed to reset because: `
+
JSON
.
stringify
(
error
));
return
;
}
console
.
log
(
`success to reset.`
);
});
```
## wallpaper.reset
reset(wallpaperType: WallpaperType): Promise
<
void
>
移除指定类型的壁纸,恢复为默认显示的壁纸。
> **说明:**
>
> 从 API version 7开始支持,从API version 9开始废弃。建议使用[wallpaper.restore<sup>9+</sup>](#wallpaperrestore9)代替。
**需要权限**
:ohos.permission.SET_WALLPAPER
**系统能力**
: SystemCapability.MiscServices.Wallpaper
**参数:**
| 参数名 | 类型 | 必填 | 说明 |
| -------- | -------- | -------- | -------- |
| wallpaperType |
[
WallpaperType
](
#wallpapertype
)
| 是 | 壁纸类型。 |
**返回值:**
| 类型 | 说明 |
| -------- | -------- |
| Promise
<
void
>
| 调用成功则返回是否移除成功的结果,调用失败则返回error信息。 |
**示例:**
```
js
wallpaper
.
reset
(
wallpaper
.
WallpaperType
.
WALLPAPER_SYSTEM
).
then
((
data
)
=>
{
console
.
log
(
`success to reset.`
);
}).
catch
((
error
)
=>
{
console
.
error
(
`failed to reset because: `
+
JSON
.
stringify
(
error
));
});
```
## wallpaper.restore<sup>9+</sup>
restore(wallpaperType: WallpaperType, callback: AsyncCallback
<
void
>
): void
移除指定类型的壁纸,恢复为默认显示的壁纸。
**需要权限**
:ohos.permission.SET_WALLPAPER
**系统能力**
: SystemCapability.MiscServices.Wallpaper
**参数:**
| 参数名 | 类型 | 必填 | 说明 |
| -------- | -------- | -------- | -------- |
| wallpaperType |
[
WallpaperType
](
#wallpapertype
)
| 是 | 壁纸类型。 |
| callback | AsyncCallback
<
void
>
| 是 | 回调函数,调用成功则返回是否移除成功的结果,调用失败则返回error信息。 |
**示例:**
```
js
wallpaper
.
restore
(
wallpaper
.
WallpaperType
.
WALLPAPER_SYSTEM
,
(
error
,
data
)
=>
{
if
(
error
)
{
console
.
error
(
`failed to restore because: `
+
JSON
.
stringify
(
error
));
console
.
error
(
`failed to isOperationAllowed because:
${
JSON
.
stringify
(
error
)}
`
);
return
;
}
console
.
log
(
`success to
restore.
`
);
console
.
log
(
`success to
isOperationAllowed:
${
JSON
.
stringify
(
data
)}
`
);
});
```
## wallpaper.
restore<sup>9+
</sup>
## wallpaper.
isOperationAllowed<sup>(deprecated)
</sup>
restore(wallpaperType: WallpaperType): Promise
<
void
>
isOperationAllowed(): Promise
<
boolean
>
移除指定类型的壁纸,恢复为默认显示的
壁纸。
是否允许用户设置
壁纸。
**需要权限**
:ohos.permission.SET_WALLPAPER
> **说明:**
>
> 从 API version 7开始支持,从API version 9开始废弃。建议使用[wallpaper.isUserChangeAllowed<sup>9+</sup>](#wallpaperisuserchangeallowed9)代替。
**系统能力**
: SystemCapability.MiscServices.Wallpaper
**参数:**
| 参数名 | 类型 | 必填 | 说明 |
| -------- | -------- | -------- | -------- |
| wallpaperType |
[
WallpaperType
](
#wallpapertype
)
| 是 | 壁纸类型。 |
**返回值:**
| 类型 | 说明 |
| -------- | -------- |
| Promise
<
void
>
| 调用成功则返回是否移除成功的结果,调用失败则返回error信息
。 |
| Promise
<
boolean
>
| 异步回调函数,返回是否允许用户设置壁纸。如果允许返回true,否则返回false
。 |
**示例:**
```
js
wallpaper
.
restore
(
wallpaper
.
WallpaperType
.
WALLPAPER_SYSTEM
).
then
((
data
)
=>
{
console
.
log
(
`success to
restore.
`
);
wallpaper
.
isOperationAllowed
(
).
then
((
data
)
=>
{
console
.
log
(
`success to
isOperationAllowed:
${
JSON
.
stringify
(
data
)}
`
);
}).
catch
((
error
)
=>
{
console
.
error
(
`failed to
restore because: `
+
JSON
.
stringify
(
error
)
);
console
.
error
(
`failed to
isOperationAllowed because:
${
JSON
.
stringify
(
error
)}
`
);
});
```
## wallpaper.
setWallpaper
## wallpaper.
reset<sup>(deprecated)</sup>
setWallpaper(source: string | image.PixelMap,
wallpaperType: WallpaperType, callback: AsyncCallback
<
void
>
): void
reset(
wallpaperType: WallpaperType, callback: AsyncCallback
<
void
>
): void
将指定资源设置为指定类型
的壁纸。
移除指定类型的壁纸,恢复为默认显示
的壁纸。
> **说明:**
>
> 从 API version 7开始支持,从API version 9开始废弃。建议使用[wallpaper.
setImage<sup>9+</sup>](#wallpapersetimag
e9)代替。
> 从 API version 7开始支持,从API version 9开始废弃。建议使用[wallpaper.
restore<sup>9+</sup>](#wallpaperrestor
e9)代替。
**需要权限**
:ohos.permission.SET_WALLPAPER
...
...
@@ -668,54 +866,30 @@ setWallpaper(source: string | image.PixelMap, wallpaperType: WallpaperType, call
| 参数名 | 类型 | 必填 | 说明 |
| -------- | -------- | -------- | -------- |
| source | string
\|
[
image.PixelMap
](
js-apis-image.md#pixelmap7
)
| 是 | JPEG或PNG文件的Uri路径,或者PNG格式文件的位图。 |
| wallpaperType |
[
WallpaperType
](
#wallpapertype
)
| 是 | 壁纸类型。 |
| callback | AsyncCallback
<
void
>
| 是 | 回调函数,
调用成功则返回是返回设置的结果,调用失败
则返回error信息。 |
| callback | AsyncCallback
<
void
>
| 是 | 回调函数,
移除壁纸成功,error为undefined 否
则返回error信息。 |
**示例:**
```
js
// source类型为string
let
wallpaperPath
=
"
/data/data/ohos.acts.aafwk.plrdtest.form/files/Cup_ic.jpg
"
;
wallpaper
.
setWallpaper
(
wallpaperPath
,
wallpaper
.
WallpaperType
.
WALLPAPER_SYSTEM
,
(
error
,
data
)
=>
{
if
(
error
)
{
console
.
error
(
`failed to setWallpaper because: `
+
JSON
.
stringify
(
error
));
return
;
}
console
.
log
(
`success to setWallpaper.`
);
});
// source类型为image.PixelMap
import
image
from
'
@ohos.multimedia.image
'
;
let
imageSource
=
image
.
createImageSource
(
"
file://
"
+
wallpaperPath
);
let
opts
=
{
"
desiredSize
"
:
{
"
height
"
:
3648
,
"
width
"
:
2736
}
};
imageSource
.
createPixelMap
(
opts
).
then
((
pixelMap
)
=>
{
wallpaper
.
setWallpaper
(
pixelMap
,
wallpaper
.
WallpaperType
.
WALLPAPER_SYSTEM
,
(
error
,
data
)
=>
{
wallpaper
.
reset
(
wallpaper
.
WallpaperType
.
WALLPAPER_SYSTEM
,
(
error
)
=>
{
if
(
error
)
{
console
.
error
(
`failed to setWallpaper because: `
+
JSON
.
stringify
(
error
)
);
console
.
error
(
`failed to reset because:
${
JSON
.
stringify
(
error
)}
`
);
return
;
}
console
.
log
(
`success to setWallpaper.`
);
});
}).
catch
((
error
)
=>
{
console
.
error
(
`failed to createPixelMap because: `
+
JSON
.
stringify
(
error
));
console
.
log
(
`success to reset.`
);
});
```
## wallpaper.
setWallpaper
## wallpaper.
reset<sup>(deprecated)</sup>
setWallpaper(source: string | image.PixelMap,
wallpaperType: WallpaperType): Promise
<
void
>
reset(
wallpaperType: WallpaperType): Promise
<
void
>
将指定资源设置为指定类型
的壁纸。
移除指定类型的壁纸,恢复为默认显示
的壁纸。
> **说明:**
>
> 从 API version 7开始支持,从API version 9开始废弃。建议使用[wallpaper.
setImage<sup>9+</sup>](#wallpapersetimag
e9)代替。
> 从 API version 7开始支持,从API version 9开始废弃。建议使用[wallpaper.
restore<sup>9+</sup>](#wallpaperrestor
e9)代替。
**需要权限**
:ohos.permission.SET_WALLPAPER
...
...
@@ -725,53 +899,34 @@ setWallpaper(source: string | image.PixelMap, wallpaperType: WallpaperType): Pro
| 参数名 | 类型 | 必填 | 说明 |
| -------- | -------- | -------- | -------- |
| source | string
\|
[
image.PixelMap
](
js-apis-image.md#pixelmap7
)
| 是 | JPEG或PNG文件的Uri路径,或者PNG格式文件的位图。 |
| wallpaperType |
[
WallpaperType
](
#wallpapertype
)
| 是 | 壁纸类型。 |
**返回值:**
| 类型 | 说明 |
| -------- | -------- |
| Promise
<
void
>
|
调用成功则返回是返回设置的结果,调用失败则返回error信息
。 |
| Promise
<
void
>
|
Promise对象。无返回结果的Promise对象
。 |
**示例:**
```
js
// source类型为string
let
wallpaperPath
=
"
/data/data/ohos.acts.aafwk.plrdtest.form/files/Cup_ic.jpg
"
;
wallpaper
.
setWallpaper
(
wallpaperPath
,
wallpaper
.
WallpaperType
.
WALLPAPER_SYSTEM
).
then
((
data
)
=>
{
console
.
log
(
`success to setWallpaper.`
);
}).
catch
((
error
)
=>
{
console
.
error
(
`failed to setWallpaper because: `
+
JSON
.
stringify
(
error
));
});
// source类型为image.PixelMap
import
image
from
'
@ohos.multimedia.image
'
;
let
imageSource
=
image
.
createImageSource
(
"
file://
"
+
wallpaperPath
);
let
opts
=
{
"
desiredSize
"
:
{
"
height
"
:
3648
,
"
width
"
:
2736
}
};
imageSource
.
createPixelMap
(
opts
).
then
((
pixelMap
)
=>
{
wallpaper
.
setWallpaper
(
pixelMap
,
wallpaper
.
WallpaperType
.
WALLPAPER_SYSTEM
).
then
((
data
)
=>
{
console
.
log
(
`success to setWallpaper.`
);
}).
catch
((
error
)
=>
{
console
.
error
(
`failed to setWallpaper because: `
+
JSON
.
stringify
(
error
));
});
}).
catch
((
error
)
=>
{
console
.
error
(
`failed to createPixelMap because: `
+
JSON
.
stringify
(
error
));
wallpaper
.
reset
(
wallpaper
.
WallpaperType
.
WALLPAPER_SYSTEM
).
then
(()
=>
{
console
.
log
(
`success to reset.`
);
}).
catch
((
error
)
=>
{
console
.
error
(
`failed to reset because:
${
JSON
.
stringify
(
error
)}
`
);
});
```
## wallpaper.setWallpaper<sup>(deprecated)</sup>
## wallpaper.setImage<sup>9+</sup>
setImage(source: string | image.PixelMap, wallpaperType: WallpaperType, callback: AsyncCallback
<
void
>
): void
setWallpaper(source: string | image.PixelMap, wallpaperType: WallpaperType, callback: AsyncCallback
<
void
>
): void
将指定资源设置为指定类型的壁纸。
> **说明:**
>
> 从 API version 7开始支持,从API version 9开始废弃。建议使用[wallpaper.setImage<sup>9+</sup>](#wallpapersetimage9)代替。
**需要权限**
:ohos.permission.SET_WALLPAPER
**系统能力**
: SystemCapability.MiscServices.Wallpaper
...
...
@@ -782,19 +937,19 @@ setImage(source: string | image.PixelMap, wallpaperType: WallpaperType, callback
| -------- | -------- | -------- | -------- |
| source | string
\|
[
image.PixelMap
](
js-apis-image.md#pixelmap7
)
| 是 | JPEG或PNG文件的Uri路径,或者PNG格式文件的位图。 |
| wallpaperType |
[
WallpaperType
](
#wallpapertype
)
| 是 | 壁纸类型。 |
| callback | AsyncCallback
<
void
>
| 是 | 回调函数,
调用成功则返回是返回设置的结果,调用失败
则返回error信息。 |
| callback | AsyncCallback
<
void
>
| 是 | 回调函数,
设置壁纸成功,error为undefined 否
则返回error信息。 |
**示例:**
```
js
// source类型为string
let
wallpaperPath
=
"
/data/data/ohos.acts.aafwk.plrdtest.form/files/Cup_ic.jpg
"
;
wallpaper
.
set
Image
(
wallpaperPath
,
wallpaper
.
WallpaperType
.
WALLPAPER_SYSTEM
,
(
error
,
data
)
=>
{
wallpaper
.
set
Wallpaper
(
wallpaperPath
,
wallpaper
.
WallpaperType
.
WALLPAPER_SYSTEM
,
(
error
)
=>
{
if
(
error
)
{
console
.
error
(
`failed to set
Image because: `
+
JSON
.
stringify
(
error
));
console
.
error
(
`failed to set
Wallpaper because:
${
JSON
.
stringify
(
error
)}
`
);
return
;
}
console
.
log
(
`success to set
Image
.`
);
console
.
log
(
`success to set
Wallpaper
.`
);
});
// source类型为image.PixelMap
...
...
@@ -807,24 +962,28 @@ let opts = {
}
};
imageSource
.
createPixelMap
(
opts
).
then
((
pixelMap
)
=>
{
wallpaper
.
set
Image
(
pixelMap
,
wallpaper
.
WallpaperType
.
WALLPAPER_SYSTEM
,
(
error
,
data
)
=>
{
wallpaper
.
set
Wallpaper
(
pixelMap
,
wallpaper
.
WallpaperType
.
WALLPAPER_SYSTEM
,
(
error
)
=>
{
if
(
error
)
{
console
.
error
(
`failed to set
Image because: `
+
JSON
.
stringify
(
error
)
);
console
.
error
(
`failed to set
Wallpaper because:
${
JSON
.
stringify
(
error
)}
`
);
return
;
}
console
.
log
(
`success to set
Image
.`
);
console
.
log
(
`success to set
Wallpaper
.`
);
});
}).
catch
((
error
)
=>
{
console
.
error
(
`failed to createPixelMap because:
`
+
JSON
.
stringify
(
error
)
);
console
.
error
(
`failed to createPixelMap because:
${
JSON
.
stringify
(
error
)}
`
);
});
```
## wallpaper.set
Image<sup>9+
</sup>
## wallpaper.set
Wallpaper<sup>(deprecated)
</sup>
set
Image
(source: string | image.PixelMap, wallpaperType: WallpaperType): Promise
<
void
>
set
Wallpaper
(source: string | image.PixelMap, wallpaperType: WallpaperType): Promise
<
void
>
将指定资源设置为指定类型的壁纸。
> **说明:**
>
> 从 API version 7开始支持,从API version 9开始废弃。建议使用[wallpaper.setImage<sup>9+</sup>](#wallpapersetimage9)代替。
**需要权限**
:ohos.permission.SET_WALLPAPER
**系统能力**
: SystemCapability.MiscServices.Wallpaper
...
...
@@ -840,17 +999,17 @@ setImage(source: string | image.PixelMap, wallpaperType: WallpaperType): Promise
| 类型 | 说明 |
| -------- | -------- |
| Promise
<
void
>
|
调用成功则返回是返回设置的结果,调用失败则返回error信息
。 |
| Promise
<
void
>
|
Promise对象。无返回结果的Promise对象
。 |
**示例:**
```
js
// source类型为string
let
wallpaperPath
=
"
/data/data/ohos.acts.aafwk.plrdtest.form/files/Cup_ic.jpg
"
;
wallpaper
.
set
Image
(
wallpaperPath
,
wallpaper
.
WallpaperType
.
WALLPAPER_SYSTEM
).
then
((
data
)
=>
{
console
.
log
(
`success to set
Image
.`
);
}).
catch
((
error
)
=>
{
console
.
error
(
`failed to set
Image because: `
+
JSON
.
stringify
(
error
)
);
wallpaper
.
set
Wallpaper
(
wallpaperPath
,
wallpaper
.
WallpaperType
.
WALLPAPER_SYSTEM
).
then
((
)
=>
{
console
.
log
(
`success to set
Wallpaper
.`
);
}).
catch
((
error
)
=>
{
console
.
error
(
`failed to set
Wallpaper because:
${
JSON
.
stringify
(
error
)}
`
);
});
// source类型为image.PixelMap
...
...
@@ -863,17 +1022,18 @@ let opts = {
}
};
imageSource
.
createPixelMap
(
opts
).
then
((
pixelMap
)
=>
{
wallpaper
.
set
Image
(
pixelMap
,
wallpaper
.
WallpaperType
.
WALLPAPER_SYSTEM
).
then
((
data
)
=>
{
console
.
log
(
`success to set
Image
.`
);
wallpaper
.
set
Wallpaper
(
pixelMap
,
wallpaper
.
WallpaperType
.
WALLPAPER_SYSTEM
).
then
((
)
=>
{
console
.
log
(
`success to set
Wallpaper
.`
);
}).
catch
((
error
)
=>
{
console
.
error
(
`failed to set
Image because: `
+
JSON
.
stringify
(
error
)
);
console
.
error
(
`failed to set
Wallpaper because:
${
JSON
.
stringify
(
error
)}
`
);
});
}).
catch
((
error
)
=>
{
console
.
error
(
`failed to createPixelMap because:
`
+
JSON
.
stringify
(
error
)
);
}).
catch
((
error
)
=>
{
console
.
error
(
`failed to createPixelMap because:
${
JSON
.
stringify
(
error
)}
`
);
});
```
## wallpaper.getFile<sup>8+</sup>
## wallpaper.getFile<sup>(deprecated)</sup>
getFile(wallpaperType: WallpaperType, callback: AsyncCallback
<
number
>
): void
...
...
@@ -899,14 +1059,14 @@ getFile(wallpaperType: WallpaperType, callback: AsyncCallback<number>): vo
```
js
wallpaper
.
getFile
(
wallpaper
.
WallpaperType
.
WALLPAPER_SYSTEM
,
(
error
,
data
)
=>
{
if
(
error
)
{
console
.
error
(
`failed to getFile because:
`
+
JSON
.
stringify
(
error
)
);
console
.
error
(
`failed to getFile because:
${
JSON
.
stringify
(
error
)}
`
);
return
;
}
console
.
log
(
`success to getFile:
`
+
JSON
.
stringify
(
data
)
);
console
.
log
(
`success to getFile:
${
JSON
.
stringify
(
data
)}
`
);
});
```
## wallpaper.getFile<sup>
8+
</sup>
## wallpaper.getFile<sup>
(deprecated)
</sup>
getFile(wallpaperType: WallpaperType): Promise
<
number
>
...
...
@@ -936,41 +1096,13 @@ getFile(wallpaperType: WallpaperType): Promise<number>
```
js
wallpaper
.
getFile
(
wallpaper
.
WallpaperType
.
WALLPAPER_SYSTEM
).
then
((
data
)
=>
{
console
.
log
(
`success to getFile:
`
+
JSON
.
stringify
(
data
)
);
console
.
log
(
`success to getFile:
${
JSON
.
stringify
(
data
)}
`
);
}).
catch
((
error
)
=>
{
console
.
error
(
`failed to getFile because:
`
+
JSON
.
stringify
(
error
)
);
console
.
error
(
`failed to getFile because:
${
JSON
.
stringify
(
error
)}
`
);
});
```
## wallpaper.getFileSync<sup>9+</sup>
getFileSync(wallpaperType: WallpaperType): number;
获取指定类型的壁纸文件。
**需要权限**
:ohos.permission.GET_WALLPAPER
**系统能力**
: SystemCapability.MiscServices.Wallpaper
**参数:**
| 参数名 | 类型 | 必填 | 说明 |
| -------- | -------- | -------- | -------- |
| wallpaperType |
[
WallpaperType
](
#wallpapertype
)
| 是 | 壁纸类型。 |
**返回值:**
| 类型 | 说明 |
| -------- | -------- |
| number | 调用成功则返回壁纸文件描述符ID,调用失败则返回error信息。 |
**示例:**
```
js
let
file
=
wallpaper
.
getFileSync
(
wallpaper
.
WallpaperType
.
WALLPAPER_SYSTEM
);
```
## wallpaper.getPixelMap
## wallpaper.getPixelMap<sup>(deprecated)</sup>
getPixelMap(wallpaperType: WallpaperType, callback: AsyncCallback
<
image.PixelMap
>
): void;
...
...
@@ -996,13 +1128,16 @@ getPixelMap(wallpaperType: WallpaperType, callback: AsyncCallback<image.Pixel
**示例:**
```
js
wallpaper
.
getPixelMap
(
wallpaper
.
WallpaperType
.
WALLPAPER_SYSTEM
,
function
(
err
,
data
)
{
console
.
info
(
'
wallpaperXTS ===> testGetPixelMapCallbackSystem err :
'
+
JSON
.
stringify
(
err
));
console
.
info
(
'
wallpaperXTS ===> testGetPixelMapCallbackSystem data :
'
+
JSON
.
stringify
(
data
));
wallpaper
.
getPixelMap
(
wallpaper
.
WallpaperType
.
WALLPAPER_SYSTEM
,
function
(
error
,
data
)
{
if
(
error
)
{
console
.
error
(
`failed to getPixelMap because:
${
JSON
.
stringify
(
error
)}
`
);
return
;
}
console
.
log
(
`success to getPixelMap :
${
JSON
.
stringify
(
data
)}
`
);
});
```
## wallpaper.getPixelMap
## wallpaper.getPixelMap
<sup>(deprecated)</sup>
getPixelMap(wallpaperType: WallpaperType): Promise
<
image.PixelMap
>
...
...
@@ -1034,138 +1169,8 @@ getPixelMap(wallpaperType: WallpaperType): Promise<image.PixelMap>
```
js
wallpaper
.
getPixelMap
(
wallpaper
.
WallpaperType
.
WALLPAPER_SYSTEM
).
then
((
data
)
=>
{
console
.
info
(
'
wallpaperXTS ===> testGetPixelMapPromiseSystem data :
'
+
data
);
console
.
info
(
'
wallpaperXTS ===> testGetPixelMapPromiseSystem data :
'
+
JSON
.
stringify
(
data
));
}).
catch
((
err
)
=>
{
console
.
info
(
'
wallpaperXTS ===> testGetPixelMapPromiseSystem err :
'
+
err
);
console
.
info
(
'
wallpaperXTS ===> testGetPixelMapPromiseSystem err :
'
+
JSON
.
stringify
(
err
));
});
```
## wallpaper.getImage<sup>9+</sup>
getImage(wallpaperType: WallpaperType, callback: AsyncCallback
<
image.PixelMap
>
): void;
获取壁纸图片的像素图。
**需要权限**
:ohos.permission.GET_WALLPAPER
**系统能力**
: SystemCapability.MiscServices.Wallpaper
**系统接口**
:此接口为系统接口。
**参数:**
| 参数名 | 类型 | 必填 | 说明 |
| -------- | -------- | -------- | -------- |
| wallpaperType |
[
WallpaperType
](
#wallpapertype
)
| 是 | 壁纸类型。 |
| callback | AsyncCallback
<
[image.PixelMap](js-apis-image.md#pixelmap7)
>
| 是 | 回调函数,调用成功则返回壁纸图片的像素图大小,调用失败则返回error信息。 |
**示例:**
```
js
wallpaper
.
getImage
(
wallpaper
.
WallpaperType
.
WALLPAPER_SYSTEM
,
function
(
err
,
data
)
{
console
.
info
(
'
wallpaperXTS ===> testgetImageCallbackSystem err :
'
+
JSON
.
stringify
(
err
));
console
.
info
(
'
wallpaperXTS ===> testgetImageCallbackSystem data :
'
+
JSON
.
stringify
(
data
));
});
```
## wallpaper.getImage<sup>9+</sup>
getImage(wallpaperType: WallpaperType): Promise
<
image.PixelMap
>
获取壁纸图片的像素图。
**需要权限**
:ohos.permission.GET_WALLPAPER
**系统能力**
: SystemCapability.MiscServices.Wallpaper
**系统接口**
:此接口为系统接口。
**参数:**
| 参数名 | 类型 | 必填 | 说明 |
| -------- | -------- | -------- | -------- |
| wallpaperType |
[
WallpaperType
](
#wallpapertype
)
| 是 | 壁纸类型。 |
**返回值:**
| 类型 | 说明 |
| -------- | -------- |
| Promise
<
[image.PixelMap](js-apis-image.md#pixelmap7)
>
| 调用成功则返回壁纸图片的像素图大小,调用失败则返回error信息。 |
**示例:**
```
js
wallpaper
.
getImage
(
wallpaper
.
WallpaperType
.
WALLPAPER_SYSTEM
).
then
((
data
)
=>
{
console
.
info
(
'
wallpaperXTS ===> testgetImagePromiseSystem data :
'
+
data
);
console
.
info
(
'
wallpaperXTS ===> testgetImagePromiseSystem data :
'
+
JSON
.
stringify
(
data
));
}).
catch
((
err
)
=>
{
console
.
info
(
'
wallpaperXTS ===> testgetImagePromiseSystem err :
'
+
err
);
console
.
info
(
'
wallpaperXTS ===> testgetImagePromiseSystem err :
'
+
JSON
.
stringify
(
err
));
console
.
log
(
`success to getPixelMap :
${
JSON
.
stringify
(
data
)}
`
);
}).
catch
((
error
)
=>
{
console
.
error
(
`failed to getPixelMap because:
${
JSON
.
stringify
(
error
)}
`
);
});
```
## wallpaper.on('colorChange')<sup>9+</sup>
on(type: 'colorChange', callback: (colors: Array
<
RgbaColor
>
, wallpaperType: WallpaperType) =
>
void): void
订阅壁纸颜色变化结果上报事件。
**系统能力**
: SystemCapability.MiscServices.Wallpaper
**参数:**
| 参数名 | 类型 | 必填 | 说明 |
| -------- | -------- | -------- | -------- |
| type | string | 是 | 取值为'colorChange',表示壁纸颜色变化结果上报事件。 |
| callback | function | 是 | 壁纸颜色变化触发该回调方法,返回壁纸类型和壁纸的主要颜色信息。
<br/>
- colors
<br/>
壁纸的主要颜色信息,其类型见
[
RgbaColor
](
#rgbacolor
)
。
<br/>
- wallpaperType
<br/>
壁纸类型。 |
**示例:**
```
js
let
listener
=
(
colors
,
wallpaperType
)
=>
{
console
.
log
(
`wallpaper color changed.`
);
};
wallpaper
.
on
(
'
colorChange
'
,
listener
);
```
## wallpaper.off('colorChange')<sup>9+</sup>
off(type: 'colorChange', callback?: (colors: Array
<
RgbaColor
>
, wallpaperType: WallpaperType) =
>
void): void
取消订阅壁纸颜色变化结果上报事件。
**系统能力**
: SystemCapability.MiscServices.Wallpaper
**参数:**
| 参数名 | 类型 | 必填 | 说明 |
| -------- | -------- | -------- | -------- |
| type | string | 是 | 取值为'colorChange',表示取消订阅壁纸颜色变化结果上报事件。 |
| callback | function | 否 | 表示取消壁纸颜色变化结果上报,不填写该参数则取消订阅该type对应的所有回调。
<br/>
- colors
<br/>
壁纸的主要颜色信息,其类型见
[
RgbaColor
](
#rgbacolor
)
。
<br/>
- wallpaperType
<br/>
壁纸类型。 |
**示例:**
```
js
let
listener
=
(
colors
,
wallpaperType
)
=>
{
console
.
log
(
`wallpaper color changed.`
);
};
wallpaper
.
on
(
'
colorChange
'
,
listener
);
// 取消订阅listener
wallpaper
.
off
(
'
colorChange
'
,
listener
);
// 取消所有'colorChange'类型的订阅
wallpaper
.
off
(
'
colorChange
'
);
```
## RgbaColor
**系统能力**
: SystemCapability.MiscServices.Wallpaper
| 名称 | 类型 | 可读 | 可写 | 说明 |
| -------- | -------- | -------- | -------- | -------- |
| red | number | 是 | 是 | 表示红色值,范围为 0 到 255。 |
| green | number | 是 | 是 | 表示绿色值,范围为 0 到 255。 |
| blue | number | 是 | 是 | 表示蓝色值,范围为 0 到 255。 |
| alpha | number | 是 | 是 | 表示 alpha 值,范围为 0 到 255。 |
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录