# miscservices_wallpaper **Repository Path**: geekgaoxiang/miscservices_wallpaper ## Basic Information - **Project Name**: miscservices_wallpaper - **Description**: Wallpaper Framework | 壁纸框架 - **Primary Language**: C++ - **License**: Apache-2.0 - **Default Branch**: master - **Homepage**: None - **GVP Project**: No ## Statistics - **Stars**: 0 - **Forks**: 146 - **Created**: 2022-07-22 - **Last Updated**: 2022-07-22 ## Categories & Tags **Categories**: Uncategorized **Tags**: None ## README # 杂散子系统/壁纸管理服务 ## 简介 ### 内容介绍 该仓主要为系统提供壁纸管理服务能力,支持系统显示、设置、切换壁纸等功能。 ### 架构图介绍 **图 1** 子系统架构图 ![](figures/subsystem_architecture_zh.png "子系统架构图") #### 仓路径 /base/miscservices/wallpaper ## 目录 ``` /base/miscservices/wallpaper ├── figures # 构架图 ├── frameworks/innerkitsimpl # 对应用提供的接口 ├── interfaces/kits # 组件对外提供的接口代码 │ ├── jskits # 服务间接口 │ └── napi # js接口解析成napi接口 ├── profile # 组件包含的系统服务的配置文件和进程的配置文件 ├── services # 壁纸管理服务实现 ├── test # 接口的单元测试 └── utils # 组件包含日志打印和有序公共事件定义的常量 ``` ## 说明 #### 接口说明 **表 1** 壁纸管理服务开放的主要方法

接口名

描述

function getColors(wallpaperType: WallpaperType): Promise<Array<RgbaColor>>

获取壁纸图片主颜色(桌面或者锁屏壁纸),Promise方式

function getId(wallpaperType: WallpaperType): Promise<number>

获取壁纸id(桌面或者锁屏壁纸),Promise方式

function getPixelMap(wallpaperType: WallpaperType): Promise<image.PixelMap>

获取壁纸图片的pixelmap(桌面或者锁屏壁纸),Promise方式

function setWallpaper(source: string | image.PixelMap, wallpaperType: WallpaperType): Promise<void>

设置壁纸(图片路径或pixelmap),Promise方式

function on(type: 'colorChange', callback: (colors: Array<RgbaColor>, wallpaperType: WallpaperType) => void): void;

监听壁纸图片主颜色变化,callback方式

function off(type: 'colorChange', callback?: (colors: Array<RgbaColor>, wallpaperType: WallpaperType) => void): void;

取消监听壁纸图片主颜色变化,callback方式

**表 2** 应用extension的主要接口

接口名

描述

onCreated(want: object): void

wallpaper extension 初始化的回调

onWallpaperChanged(wallpaperType: number): void

壁纸发生了变化的回调

setUiContent(url:string): void

应用设置壁纸的布局文件路径

onDestroy(): void

wallpaper extension 销毁回调

### 使用说明 ``` //获取壁纸callback方式 wallpaper.getPixelMap(WALLPAPER_SYSTEM, function (err, data) { console.info('wallpaperXTS ===> testGetPixelMapCallbackSystem err : ' + JSON.stringify(err)); console.info('wallpaperXTS ===> testGetPixelMapCallbackSystem data : ' + JSON.stringify(data)); }) //获取壁纸Promise方式 wallpaper.getPixelMap(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)); }); //设置壁纸callback方式 wallpaper.setWallpaper(pixelmap, WALLPAPER_SYSTEM, function (err, data) { console.info('wallpaperXTS ===> testSetWallpaperPixelMapCallbackSystem err : ' + JSON.stringify(err)); console.info('wallpaperXTS ===> testSetWallpaperPixelMapCallbackSystem data : ' + JSON.stringify(data)); }); //设置壁纸Promise方式 wallpaper.setWallpaper(pixelmap, WALLPAPER_SYSTEM).then((data) => { console.info('wallpaperXTS ===> testSetWallpaperPixelMapPromiseSystem data : ' + JSON.stringify(data)); }).catch((err) => { console.info('wallpaperXTS ===> testSetWallpaperPixelMapPromiseSystem err : ' + JSON.stringify(err)); }); ``` js 应用接口使用说明 ``` import Extension from '@ohos.wallpaperextension' import wallPaper from '@ohos.wallpaper' export default class WallpaperExtAbility extends Extension { onCreated(want) { console.info(MODULE_TAG + 'ability on created start'); super.setUiContent("pages/index"); console.info(MODULE_TAG + 'ability on created end'); } onWallpaperChanged(wallpaperType) { console.info(MODULE_TAG + "ability on wallpaper changed start, type is : " + wallpaperType); if (wallPaper) { this.sendPixelMapData(); } console.info(MODULE_TAG + "ability on wallpaper changed end"); } onDestroy() { console.info(MODULE_TAG + 'ability on destroy'); } initWallpaperImage() { console.info(MODULE_TAG + 'ability init wallpaper image start'); if (!wallPaper) { console.info(MODULE_TAG + "ability init wallpaper image failed as wallpaper is null"); return; } this.sendPixelMapData() console.info(MODULE_TAG + 'ability init wallpaper image end'); } sendPixelMapData() { // 0 is WallpaperType:WALLPAPER_SYSTEM, 1 isWallpaperType:WALLPAPER_LOCKSCREEN wallPaper.getPixelMap(0, (err, data) => { console.info(MODULE_TAG + "ability get pixel map data start"); if (err) { console.info(MODULE_TAG + "ability get pixel map failed, error : " + JSON.stringify(err)); } else { console.info(MODULE_TAG + "ability get pixel map, data : " + JSON.stringify(data)); AppStorage.SetOrCreate('slPixelData', data); } console.info(MODULE_TAG + "ability get pixel map data end"); }); } }; ``` ## 相关仓 [miscservices_wallpaper](https://gitee.com/openharmony/miscservices_wallpaper/blob/master/README_ZH.md)