From 9eb15e934ea6cffa2cbb6c7de1f98a233e96ad14 Mon Sep 17 00:00:00 2001 From: weishaoxiong Date: Sat, 10 Dec 2022 14:21:53 +0800 Subject: [PATCH] =?UTF-8?q?Signed-off-by:=20weishaoxiong=20=20fix:=20=E7=A4=BA=E4=BE=8B=E4=BB=A3=E7=A0=81?= =?UTF-8?q?=E4=BF=AE=E6=94=B9=20=E5=8F=8A=20callback=E6=8F=8F=E8=BF=B0?= =?UTF-8?q?=E4=BF=AE=E6=94=B9?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: weishaoxiong fix:【wallpaper】API参考优化 --- .../reference/apis/js-apis-wallpaper.md | 1171 +++++++++-------- 1 file changed, 588 insertions(+), 583 deletions(-) diff --git a/zh-cn/application-dev/reference/apis/js-apis-wallpaper.md b/zh-cn/application-dev/reference/apis/js-apis-wallpaper.md index 63269945f7..bc09873847 100644 --- a/zh-cn/application-dev/reference/apis/js-apis-wallpaper.md +++ b/zh-cn/application-dev/reference/apis/js-apis-wallpaper.md @@ -26,15 +26,51 @@ import wallpaper from '@ohos.wallpaper'; | WALLPAPER_LOCKSCREEN | 1 |锁屏壁纸标识。 | -## wallpaper.getColors +## RgbaColor -getColors(wallpaperType: WallpaperType, callback: AsyncCallback<Array<RgbaColor>>): void +定义壁纸颜色信息结构。 + +**系统能力**: SystemCapability.MiscServices.Wallpaper + +| 名称 | 类型 | 可读 | 可写 | 说明 | +| -------- | -------- | -------- | -------- | -------- | +| red | number | 是 | 是 | 表示红色值,范围为 0 到 255。 | +| green | number | 是 | 是 | 表示绿色值,范围为 0 到 255。 | +| blue | number | 是 | 是 | 表示蓝色值,范围为 0 到 255。 | +| alpha | number | 是 | 是 | 表示 alpha 值,范围为 0 到 255。 | + + +## wallpaper.getColorsSync9+ + +getColorsSync(wallpaperType: WallpaperType): Array<RgbaColor> 获取指定类型壁纸的主要颜色信息。 -> **说明:** -> -> 从 API version 7开始支持,从API version 9开始废弃。建议使用[wallpaper.getColorsSync9+](#wallpapergetcolorssync9)代替。 +**系统能力**: SystemCapability.MiscServices.Wallpaper + +**参数:** + +| 参数名 | 类型 | 必填 | 说明 | +| -------- | -------- | -------- | -------- | +| wallpaperType | [WallpaperType](#wallpapertype) | 是 | 壁纸类型。 | + +**返回值**: + +| 类型 | 说明 | +| -------- | -------- | +| Array<[RgbaColor](#rgbacolor)> | 返回壁纸的主要颜色信息。 | + +**示例**: + +```js +let colors = wallpaper.getColorsSync(wallpaper.WallpaperType.WALLPAPER_SYSTEM); +``` + +## wallpaper.getIdSync9+ + +getIdSync(wallpaperType: WallpaperType): number + +获取指定类型壁纸的ID。 **系统能力**: SystemCapability.MiscServices.Wallpaper @@ -43,29 +79,135 @@ getColors(wallpaperType: WallpaperType, callback: AsyncCallback<Array<Rgba | 参数名 | 类型 | 必填 | 说明 | | -------- | -------- | -------- | -------- | | wallpaperType | [WallpaperType](#wallpapertype) | 是 | 壁纸类型。 | -| callback | AsyncCallback<Array<[RgbaColor](#rgbacolor)>> | 是 | 回调函数,返回壁纸的主要颜色信息。 | + +**返回值**: + +| 类型 | 说明 | +| -------- | -------- | +| number | 返回壁纸的ID。如果配置了这种壁纸类型的壁纸就返回一个大于等于0的数,否则返回-1。取值范围是-1~2^31-1。 | + +**示例**: + +```js +let id = wallpaper.getIdSync(wallpaper.WallpaperType.WALLPAPER_SYSTEM); +``` + +## wallpaper.getMinHeightSync9+ + +getMinHeightSync(): number + +获取壁纸的最小高度值。 + +**系统能力**: SystemCapability.MiscServices.Wallpaper + +**返回值:** + +| 类型 | 说明 | +| -------- | -------- | +| number | 返回壁纸的最小高度值,单位是像素。如果返回值等于0,说明没有设置壁纸,调用者应该使用默认显示的高度值代替。 | **示例:** - + ```js -wallpaper.getColors(wallpaper.WallpaperType.WALLPAPER_SYSTEM, (error, data) => { +let minHeight = wallpaper.getMinHeightSync(); +``` + +## wallpaper.getMinWidthSync9+ + +getMinWidthSync(): number + +获取壁纸的最小宽度值。 + +**系统能力**: SystemCapability.MiscServices.Wallpaper + +**返回值:** + +| 类型 | 说明 | +| -------- | -------- | +| number | 壁纸的最小宽度值,单位是像素。如果返回值等于0,说明没有设置壁纸,调用者应该使用默认显示的宽度值代替。 | + +**示例:** + +```js +let minWidth = wallpaper.getMinWidthSync(); +``` + +## wallpaper.isChangeAllowed9+ + +isChangeAllowed(): boolean + +是否允许应用改变当前用户的壁纸。 + +**系统能力**: SystemCapability.MiscServices.Wallpaper + +**返回值:** + +| 类型 | 说明 | +| -------- | -------- | +| boolean | 返回是否允许应用改变当前用户的壁纸。如果允许返回true,否则返回false。 | + +**示例:** + +```js +let isChangeAllowed = wallpaper.isChangeAllowed(); +``` + +## wallpaper.isUserChangeAllowed9+ + +isUserChangeAllowed(): boolean + +是否允许用户设置壁纸。 + +**系统能力**: SystemCapability.MiscServices.Wallpaper + +**返回值:** + +| 类型 | 说明 | +| -------- | -------- | +| boolean | 返回是否允许用户设置壁纸。如果允许返回true,否则返回false。 | + +**示例:** + +```js +let isUserChangeAllowed = wallpaper.isUserChangeAllowed(); +``` + +## wallpaper.restore9+ + +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 getColors because: ` + JSON.stringify(error)); + console.error(`failed to restore because: ${JSON.stringify(error)}`); return; } - console.log(`success to getColors.`); + console.log(`success to restore.`); }); ``` -## wallpaper.getColors +## wallpaper.restore9+ -getColors(wallpaperType: WallpaperType): Promise<Array<RgbaColor>> +restore(wallpaperType: WallpaperType): Promise<void> -获取指定类型壁纸的主要颜色信息。 +移除指定类型的壁纸,恢复为默认显示的壁纸。 -> **说明:** -> -> 从 API version 7开始支持,从API version 9开始废弃。建议使用[wallpaper.getColorsSync9+](#wallpapergetcolorssync9)代替。 +**需要权限**:ohos.permission.SET_WALLPAPER **系统能力**: SystemCapability.MiscServices.Wallpaper @@ -79,24 +221,312 @@ getColors(wallpaperType: WallpaperType): Promise<Array<RgbaColor>> | 类型 | 说明 | | -------- | -------- | -| Promise<Array<[RgbaColor](#rgbacolor)>> | 返回壁纸的主要颜色信息。 | +| 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.setImage9+ + +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.setImage9+ + +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 -wallpaper.getColors(wallpaper.WallpaperType.WALLPAPER_SYSTEM).then((data) => { - console.log(`success to getColors.`); +// 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.getFileSync9+ + +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.getImage9+ + +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.getImage9+ + +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 getColors because: ` + JSON.stringify(error)); + console.error(`failed to getImage because: ${JSON.stringify(error)}`); }); ``` -## wallpaper.getColorsSync9+ +## wallpaper.on('colorChange')9+ -getColorsSync(wallpaperType: WallpaperType): Array<RgbaColor> +on(type: 'colorChange', callback: (colors: Array<RgbaColor>, wallpaperType: WallpaperType) => void): void + +订阅壁纸颜色变化结果上报事件。 + +**系统能力**: SystemCapability.MiscServices.Wallpaper + +**参数:** + +| 参数名 | 类型 | 必填 | 说明 | +| -------- | -------- | -------- | -------- | +| type | string | 是 | 取值为'colorChange',表示壁纸颜色变化结果上报事件。 | +| callback | function | 是 | 壁纸颜色变化触发该回调方法,返回壁纸类型和壁纸的主要颜色信息。
- colors
壁纸的主要颜色信息,其类型见[RgbaColor](#rgbacolor)。
- wallpaperType
壁纸类型。 | + +**示例:** + +```js +let listener = (colors, wallpaperType) => { + console.log(`wallpaper color changed.`); +}; +wallpaper.on('colorChange', listener); +``` + +## wallpaper.off('colorChange')9+ + +off(type: 'colorChange', callback?: (colors: Array<RgbaColor>, wallpaperType: WallpaperType) => void): void + +取消订阅壁纸颜色变化结果上报事件。 + +**系统能力**: SystemCapability.MiscServices.Wallpaper + +**参数:** + +| 参数名 | 类型 | 必填 | 说明 | +| -------- | -------- | -------- | -------- | +| type | string | 是 | 取值为'colorChange',表示取消订阅壁纸颜色变化结果上报事件。 | +| callback | function | 否 | 表示要取消的壁纸颜色变化的回调,不填写该参数则取消订阅该type对应的所有回调。
- colors
壁纸的主要颜色信息,其类型见[RgbaColor](#rgbacolor)。
- wallpaperType
壁纸类型。 | + +**示例:** + +```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(deprecated) + +getColors(wallpaperType: WallpaperType, callback: AsyncCallback<Array<RgbaColor>>): void + +获取指定类型壁纸的主要颜色信息。 + +> **说明:** +> +> 从 API version 7开始支持,从API version 9开始废弃。建议使用[wallpaper.getColorsSync9+](#wallpapergetcolorssync9)代替。 + +**系统能力**: SystemCapability.MiscServices.Wallpaper + +**参数:** + +| 参数名 | 类型 | 必填 | 说明 | +| -------- | -------- | -------- | -------- | +| wallpaperType | [WallpaperType](#wallpapertype) | 是 | 壁纸类型。 | +| callback | AsyncCallback<Array<[RgbaColor](#rgbacolor)>> | 是 | 回调函数,返回壁纸的主要颜色信息。 | + +**示例:** + +```js +wallpaper.getColors(wallpaper.WallpaperType.WALLPAPER_SYSTEM, (error, data) => { + if (error) { + console.error(`failed to getColors because: ${JSON.stringify(error)}`); + return; + } + console.log(`success to getColors: ${JSON.stringify(data)}`); +}); +``` + +## wallpaper.getColors(deprecated) + +getColors(wallpaperType: WallpaperType): Promise<Array<RgbaColor>> 获取指定类型壁纸的主要颜色信息。 +> **说明:** +> +> 从 API version 7开始支持,从API version 9开始废弃。建议使用[wallpaper.getColorsSync9+](#wallpapergetcolorssync9)代替。 + **系统能力**: SystemCapability.MiscServices.Wallpaper **参数:** @@ -105,19 +535,23 @@ getColorsSync(wallpaperType: WallpaperType): Array<RgbaColor> | -------- | -------- | -------- | -------- | | wallpaperType | [WallpaperType](#wallpapertype) | 是 | 壁纸类型。 | -**返回值**: +**返回值:** -| 类型 | 说明 | +| 类型 | 说明 | | -------- | -------- | -| Array<[RgbaColor](#rgbacolor)> | 返回壁纸的主要颜色信息。 | +| Promise<Array<[RgbaColor](#rgbacolor)>> | 返回壁纸的主要颜色信息。 | -**示例**: +**示例:** ```js -let colors = wallpaper.getColorsSync(wallpaper.WallpaperType.WALLPAPER_SYSTEM); +wallpaper.getColors(wallpaper.WallpaperType.WALLPAPER_SYSTEM).then((data) => { + console.log(`success to getColors: ${JSON.stringify(data)}`); + }).catch((error) => { + console.error(`failed to getColors because: ${JSON.stringify(error)}`); +}); ``` -## wallpaper.getId +## wallpaper.getId(deprecated) getId(wallpaperType: WallpaperType, callback: AsyncCallback<number>): void @@ -137,18 +571,18 @@ getId(wallpaperType: WallpaperType, callback: AsyncCallback<number>): void | callback | AsyncCallback<number> | 是 | 回调函数,返回壁纸的ID。如果配置了指定类型的壁纸就返回一个大于等于0的数,否则返回-1。取值范围是-1~2^31-1。 | **示例:** - + ```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(deprecated) getId(wallpaperType: WallpaperType): Promise<number> @@ -173,42 +607,16 @@ getId(wallpaperType: WallpaperType): Promise<number> | Promise<number> | 壁纸的ID。如果配置了这种壁纸类型的壁纸就返回一个大于等于0的数,否则返回-1。取值范围是-1~2^31-1。 | **示例:** - + ```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.getIdSync9+ - -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(deprecated) getMinHeight(callback: AsyncCallback<number>): void @@ -227,18 +635,18 @@ getMinHeight(callback: AsyncCallback<number>): void | callback | AsyncCallback<number> | 是 | 回调函数,返回壁纸的最小高度值,单位是像素。如果返回值等于0,说明没有设置壁纸,调用者应该使用默认显示的高度值代替。 | **示例:** - + ```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(deprecated) getMinHeight(): Promise<number> @@ -257,36 +665,16 @@ getMinHeight(): Promise<number> | Promise<number> | 返回壁纸的最小高度值,单位是像素。如果返回值等于0,说明没有设置壁纸,调用者应该使用默认显示的高度值代替。 | **示例:** - + ```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.getMinHeightSync9+ - -getMinHeightSync(): number - -获取壁纸的最小高度值。 - -**系统能力**: SystemCapability.MiscServices.Wallpaper - -**返回值:** - -| 类型 | 说明 | -| -------- | -------- | -| number | 返回壁纸的最小高度值,单位是像素。如果返回值等于0,说明没有设置壁纸,调用者应该使用默认显示的高度值代替。 | - -**示例:** - -```js -let minHeight = wallpaper.getMinHeightSync(); -``` - -## wallpaper.getMinWidth +## wallpaper.getMinWidth(deprecated) getMinWidth(callback: AsyncCallback<number>): void @@ -305,18 +693,18 @@ getMinWidth(callback: AsyncCallback<number>): void | callback | AsyncCallback<number> | 是 | 回调函数,壁纸的最小宽度值,单位是像素。如果返回值等于0,说明没有设置壁纸,调用者应该使用默认显示的宽度值代替。 | **示例:** - + ```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(deprecated) getMinWidth(): Promise<number> @@ -335,36 +723,16 @@ getMinWidth(): Promise<number> | Promise<number> | 壁纸的最小宽度值,单位是像素。如果返回值等于0,说明没有设置壁纸,调用者应该使用默认显示的宽度值代替。 | **示例:** - + ```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.getMinWidthSync9+ - -getMinWidthSync(): number - -获取壁纸的最小宽度值。 - -**系统能力**: SystemCapability.MiscServices.Wallpaper - -**返回值:** - -| 类型 | 说明 | -| -------- | -------- | -| number | 壁纸的最小宽度值,单位是像素。如果返回值等于0,说明没有设置壁纸,调用者应该使用默认显示的宽度值代替。 | - -**示例:** - -```js -let minWidth = wallpaper.getMinWidthSync(); -``` - -## wallpaper.isChangePermitted +## wallpaper.isChangePermitted(deprecated) isChangePermitted(callback: AsyncCallback<boolean>): void @@ -383,18 +751,18 @@ isChangePermitted(callback: AsyncCallback<boolean>): void | callback | AsyncCallback<boolean> | 是 | 回调函数,返回是否允许应用改变当前用户的壁纸。如果允许返回true,否则返回false。 | **示例:** - + ```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(deprecated) isChangePermitted(): Promise<boolean> @@ -413,36 +781,16 @@ isChangePermitted(): Promise<boolean> | Promise<boolean> | 返回是否允许应用改变当前用户的壁纸。如果允许返回true,否则返回false。 | **示例:** - + ```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.isChangeAllowed9+ - -isChangeAllowed(): boolean - -是否允许应用改变当前用户的壁纸。 - -**系统能力**: SystemCapability.MiscServices.Wallpaper - -**返回值:** - -| 类型 | 说明 | -| -------- | -------- | -| boolean | 返回是否允许应用改变当前用户的壁纸。如果允许返回true,否则返回false。 | - -**示例:** - -```js -let isChangeAllowed = wallpaper.isChangeAllowed(); -``` - -## wallpaper.isOperationAllowed +## wallpaper.isOperationAllowed(deprecated) isOperationAllowed(callback: AsyncCallback<boolean>): void @@ -461,18 +809,18 @@ isOperationAllowed(callback: AsyncCallback<boolean>): void | callback | AsyncCallback<boolean> | 是 | 回调函数,返回是否允许用户设置壁纸。如果允许返回true,否则返回false。 | **示例:** - + ```js wallpaper.isOperationAllowed((error, data) => { if (error) { - console.error(`failed to isOperationAllowed because: ` + JSON.stringify(error)); + console.error(`failed to isOperationAllowed because: ${JSON.stringify(error)}`); return; } - console.log(`success to isOperationAllowed: ` + JSON.stringify(data)); + console.log(`success to isOperationAllowed: ${JSON.stringify(data)}`); }); ``` -## wallpaper.isOperationAllowed +## wallpaper.isOperationAllowed(deprecated) isOperationAllowed(): Promise<boolean> @@ -491,174 +839,24 @@ isOperationAllowed(): Promise<boolean> | 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.isUserChangeAllowed9+ - -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.restore9+](#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.restore9+](#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.restore9+ - -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)); - return; - } - console.log(`success to restore.`); -}); -``` - -## wallpaper.restore9+ - -restore(wallpaperType: WallpaperType): Promise<void> - -移除指定类型的壁纸,恢复为默认显示的壁纸。 - -**需要权限**:ohos.permission.SET_WALLPAPER - -**系统能力**: SystemCapability.MiscServices.Wallpaper - -**参数:** - -| 参数名 | 类型 | 必填 | 说明 | -| -------- | -------- | -------- | -------- | -| wallpaperType | [WallpaperType](#wallpapertype) | 是 | 壁纸类型。 | - -**返回值:** - -| 类型 | 说明 | -| -------- | -------- | -| Promise<void> | 调用成功则返回是否移除成功的结果,调用失败则返回error信息。 | - -**示例:** - -```js -wallpaper.restore(wallpaper.WallpaperType.WALLPAPER_SYSTEM).then((data) => { - console.log(`success to restore.`); + +```js +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(deprecated) -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.setImage9+](#wallpapersetimage9)代替。 +> 从 API version 7开始支持,从API version 9开始废弃。建议使用[wallpaper.restore9+](#wallpaperrestore9)代替。 **需要权限**: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 +```js +wallpaper.reset(wallpaper.WallpaperType.WALLPAPER_SYSTEM, (error) => { + if (error) { + console.error(`failed to reset because: ${JSON.stringify(error)}`); + return; } -}; -imageSource.createPixelMap(opts).then((pixelMap) => { - wallpaper.setWallpaper(pixelMap, wallpaper.WallpaperType.WALLPAPER_SYSTEM, (error, data) => { - if (error) { - console.error(`failed to setWallpaper 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(deprecated) -setWallpaper(source: string | image.PixelMap, wallpaperType: WallpaperType): Promise<void> +reset(wallpaperType: WallpaperType): Promise<void> -将指定资源设置为指定类型的壁纸。 +移除指定类型的壁纸,恢复为默认显示的壁纸。 > **说明:** -> -> 从 API version 7开始支持,从API version 9开始废弃。建议使用[wallpaper.setImage9+](#wallpapersetimage9)代替。 +> +> 从 API version 7开始支持,从API version 9开始废弃。建议使用[wallpaper.restore9+](#wallpaperrestore9)代替。 **需要权限**: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(deprecated) -## wallpaper.setImage9+ - -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.setImage9+](#wallpapersetimage9)代替。 + **需要权限**:ohos.permission.SET_WALLPAPER **系统能力**: SystemCapability.MiscServices.Wallpaper @@ -782,21 +937,21 @@ 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.setImage(wallpaperPath, wallpaper.WallpaperType.WALLPAPER_SYSTEM, (error, data) => { - if (error) { - console.error(`failed to setImage because: ` + JSON.stringify(error)); - return; - } - console.log(`success to setImage.`); +wallpaper.setWallpaper(wallpaperPath, wallpaper.WallpaperType.WALLPAPER_SYSTEM, (error) => { + 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); @@ -806,25 +961,29 @@ let opts = { "width": 2736 } }; -imageSource.createPixelMap(opts).then((pixelMap) => { - wallpaper.setImage(pixelMap, wallpaper.WallpaperType.WALLPAPER_SYSTEM, (error, data) => { - if (error) { - console.error(`failed to setImage because: ` + JSON.stringify(error)); +imageSource.createPixelMap(opts).then((pixelMap) => { + wallpaper.setWallpaper(pixelMap, wallpaper.WallpaperType.WALLPAPER_SYSTEM, (error) => { + if (error) { + console.error(`failed to setWallpaper because: ${JSON.stringify(error)}`); return; - } - console.log(`success to setImage.`); + } + console.log(`success to setWallpaper.`); }); -}).catch((error) => { - console.error(`failed to createPixelMap because: ` + JSON.stringify(error)); +}).catch((error) => { + console.error(`failed to createPixelMap because: ${JSON.stringify(error)}`); }); ``` -## wallpaper.setImage9+ +## wallpaper.setWallpaper(deprecated) -setImage(source: string | image.PixelMap, wallpaperType: WallpaperType): Promise<void> +setWallpaper(source: string | image.PixelMap, wallpaperType: WallpaperType): Promise<void> 将指定资源设置为指定类型的壁纸。 +> **说明:** +> +> 从 API version 7开始支持,从API version 9开始废弃。建议使用[wallpaper.setImage9+](#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.setImage(wallpaperPath, wallpaper.WallpaperType.WALLPAPER_SYSTEM).then((data) => { - console.log(`success to setImage.`); -}).catch((error) => { - console.error(`failed to setImage because: ` + JSON.stringify(error)); +wallpaper.setWallpaper(wallpaperPath, wallpaper.WallpaperType.WALLPAPER_SYSTEM).then(() => { + console.log(`success to setWallpaper.`); + }).catch((error) => { + console.error(`failed to setWallpaper because: ${JSON.stringify(error)}`); }); // source类型为image.PixelMap @@ -862,18 +1021,19 @@ let opts = { "width": 2736 } }; -imageSource.createPixelMap(opts).then((pixelMap) => { - wallpaper.setImage(pixelMap, wallpaper.WallpaperType.WALLPAPER_SYSTEM).then((data) => { - console.log(`success to setImage.`); +imageSource.createPixelMap(opts).then((pixelMap) => { + wallpaper.setWallpaper(pixelMap, wallpaper.WallpaperType.WALLPAPER_SYSTEM).then(() => { + console.log(`success to setWallpaper.`); }).catch((error) => { - console.error(`failed to setImage because: ` + JSON.stringify(error)); + console.error(`failed to setWallpaper 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.getFile8+ + +## wallpaper.getFile(deprecated) getFile(wallpaperType: WallpaperType, callback: AsyncCallback<number>): void @@ -895,18 +1055,18 @@ getFile(wallpaperType: WallpaperType, callback: AsyncCallback<number>): vo | callback | AsyncCallback<number> | 是 | 回调函数,调用成功则返回壁纸文件描述符ID,调用失败则返回error信息。 | **示例:** - + ```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.getFile8+ +## wallpaper.getFile(deprecated) getFile(wallpaperType: WallpaperType): Promise<number> @@ -933,44 +1093,16 @@ getFile(wallpaperType: WallpaperType): Promise<number> | Promise<number> | 调用成功则返回壁纸文件描述符ID,调用失败则返回error信息。 | **示例:** - + ```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.getFileSync9+ - -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(deprecated) getPixelMap(wallpaperType: WallpaperType, callback: AsyncCallback<image.PixelMap>): void; @@ -994,15 +1126,18 @@ getPixelMap(wallpaperType: WallpaperType, callback: AsyncCallback<image.Pixel | callback | AsyncCallback<image.PixelMap> | 是 | 回调函数,调用成功则返回壁纸图片的像素图大小,调用失败则返回error信息。 | **示例:** - + ```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(deprecated) getPixelMap(wallpaperType: WallpaperType): Promise<image.PixelMap> @@ -1031,141 +1166,11 @@ getPixelMap(wallpaperType: WallpaperType): Promise<image.PixelMap> | Promise<image.PixelMap> | 调用成功则返回壁纸图片的像素图大小,调用失败则返回error信息。 | **示例:** - -```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.getImage9+ - -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.getImage9+ - -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)); +wallpaper.getPixelMap(wallpaper.WallpaperType.WALLPAPER_SYSTEM).then((data) => { + console.log(`success to getPixelMap : ${JSON.stringify(data)}`); + }).catch((error) => { + console.error(`failed to getPixelMap because: ${JSON.stringify(error)}`); }); ``` - -## wallpaper.on('colorChange')9+ - -on(type: 'colorChange', callback: (colors: Array<RgbaColor>, wallpaperType: WallpaperType) => void): void - -订阅壁纸颜色变化结果上报事件。 - -**系统能力**: SystemCapability.MiscServices.Wallpaper - -**参数:** - -| 参数名 | 类型 | 必填 | 说明 | -| -------- | -------- | -------- | -------- | -| type | string | 是 | 取值为'colorChange',表示壁纸颜色变化结果上报事件。 | -| callback | function | 是 | 壁纸颜色变化触发该回调方法,返回壁纸类型和壁纸的主要颜色信息。
- colors
壁纸的主要颜色信息,其类型见[RgbaColor](#rgbacolor)。
- wallpaperType
壁纸类型。 | - -**示例:** - -```js -let listener = (colors, wallpaperType) => { - console.log(`wallpaper color changed.`); -}; -wallpaper.on('colorChange', listener); -``` - -## wallpaper.off('colorChange')9+ - -off(type: 'colorChange', callback?: (colors: Array<RgbaColor>, wallpaperType: WallpaperType) => void): void - -取消订阅壁纸颜色变化结果上报事件。 - -**系统能力**: SystemCapability.MiscServices.Wallpaper - -**参数:** - -| 参数名 | 类型 | 必填 | 说明 | -| -------- | -------- | -------- | -------- | -| type | string | 是 | 取值为'colorChange',表示取消订阅壁纸颜色变化结果上报事件。 | -| callback | function | 否 | 表示取消壁纸颜色变化结果上报,不填写该参数则取消订阅该type对应的所有回调。
- colors
壁纸的主要颜色信息,其类型见[RgbaColor](#rgbacolor)。
- wallpaperType
壁纸类型。 | - -**示例:** - -```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。 | -- GitLab