mirror of
https://github.com/openharmony/miscservices_wallpaper.git
synced 2026-07-01 06:42:05 -04:00
c2e1e12c2d
Changes to be committed:
10 KiB
10 KiB
杂散子系统/壁纸管理服务
简介
内容介绍
该仓主要为系统提供壁纸管理服务能力,支持系统显示、设置、切换壁纸等功能。
架构图介绍
仓路径
/base/miscservices/wallpaper
目录
/base/miscservices/wallpaper
├── figures # 构架图
├── frameworks/innerkitsimpl # 对应用提供的接口
├── interfaces/kits # 组件对外提供的接口代码
│ ├── jskits # 服务间接口
│ └── napi # js接口解析成napi接口
├── profile # 组件包含的系统服务的配置文件和进程的配置文件
├── services # 壁纸管理服务实现
├── test # 接口的单元测试
└── utils # 组件包含日志打印和有序公共事件定义的常量
说明
接口说明
表 1 壁纸管理服务开放的主要方法
表 2 应用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");
});
}
};
