• Home
Name Date Size #Lines LOC

..--

etc/init/12-May-2024-6861

figures/12-May-2024-

frameworks/12-May-2024-3,9322,731

interfaces/kits/napi/12-May-2024-3,7862,878

profile/12-May-2024-4428

services/12-May-2024-2,8902,312

test/12-May-2024-1,7651,159

utils/12-May-2024-1,197831

BUILD.gnD12-May-2024899 2623

LICENSED12-May-20249.9 KiB177150

OAT.xmlD12-May-20244.5 KiB7219

README.mdD12-May-20247.6 KiB134118

README_ZH.mdD12-May-202437.3 KiB657612

bundle.jsonD12-May-20242.5 KiB7978

hisysevent.yamlD12-May-20242.6 KiB5613

wallpaper.gniD12-May-20241.1 KiB2820

README.md

1# wallpaper service
2
3#### Introduction
41、Provide wallpaper service capability for the system, and support wallpaper display, setting, switching wallpaper and other functions;
5
62、Provide the framework and interface for developers to develop wallpaper, and develop wallpaper applications;
7
8**subsystem architecture diagram**
9![](figures/subsystem_architecture.png "subsystem architecture diagram")
10
11#### Warehouse path
12/base/theme/wallpaper_mgr
13
14#### Introduction to framework code
15/base/theme/wallpaper_mgr
16├── figures                  # architecture diagram
17├── frameworks/innerkitsimpl # interface provided for app
18├── interfaces               # interface code provided by module
19│   ├── innerkits            # inter service interface
20│   └── kits                 # napi interface
21├── sa_profile               # module contains the config files of system services and processes
22├── services                 # implementation of wallpaper manager service
23├── test                     # unit test of interface
24└── utils                    # module contains log printing and constants for ordered commonEvent
25
26#### Interface Introduction
27**Table 1**  Main method of wallpaper service
28
29<a name="table033515471012"></a>
30<table><thead align="left"><tr id="row143351854201012"><th class="cellrowborder" valign="top" width="50%" id="mcps1.2.3.1.1"><p id="p103351154121010"><a name="p103351154121010"></a><a name="p103351154121010"></a>Interface Name</p>
31</th>
32<th class="cellrowborder" valign="top" width="50%" id="mcps1.2.3.1.2"><p id="p1033585416105"><a name="p1033585416105"></a><a name="p1033585416105"></a>Description</p>
33</th>
34</tr>
35</thead>
36<tbody><tr id="row204321219393"><td class="cellrowborder" valign="top" width="50%" headers="mcps1.2.3.1.1 "><p id="p1893413268144"><a name="p1893413268144"></a><a name="p1893413268144"></a>function getColors(wallpaperType: WallpaperType): Promise&lt;Array&lt;RgbaColor&gt;&gt;</p>
37</td>
38<td class="cellrowborder" valign="top" width="50%" headers="mcps1.2.3.1.2 "><p id="p18761104812149"><a name="p18761104812149"></a><a name="p18761104812149"></a>Obtains the wallpaper colors for the wallpaper of the specified type(system screen or lockscreen),Promise </p>
39</td>
40</tr>
41<tr id="row13335054111018"><td class="cellrowborder" valign="top" width="50%" headers="mcps1.2.3.1.1 "><p id="p12832214151418"><a name="p12832214151418"></a><a name="p12832214151418"></a>function getId(wallpaperType: WallpaperType): Promise&lt;number&gt;</p>
42</td>
43<td class="cellrowborder" valign="top" width="50%" headers="mcps1.2.3.1.2 "><p id="p3335145451011"><a name="p3335145451011"></a><a name="p3335145451011"></a>Obtains the ID of the wallpaper of the specified type(system screen or lockscreen),Promise </p>
44</td>
45</tr>
46<tr id="row204321219393"><td class="cellrowborder" valign="top" width="50%" headers="mcps1.2.3.1.1 "><p id="p1893413268144"><a name="p1893413268144"></a><a name="p1893413268144"></a>function getPixelMap(wallpaperType: WallpaperType): Promise&lt;image.PixelMap&gt;</p>
47</td>
48<td class="cellrowborder" valign="top" width="50%" headers="mcps1.2.3.1.2 "><p id="p18761104812149"><a name="p18761104812149"></a><a name="p18761104812149"></a>Obtains the default pixel map of a wallpaper of the specified type(system screen or lockscreen),Promise</p>
49</td>
50</tr>
51<tr id="row204321219393"><td class="cellrowborder" valign="top" width="50%" headers="mcps1.2.3.1.1 "><p id="p1893413268144"><a name="p1893413268144"></a><a name="p1893413268144"></a>function setWallpaper(source: string | image.PixelMap, wallpaperType: WallpaperType): Promise&lt;void&gt;</p>
52</td>
53<td class="cellrowborder" valign="top" width="50%" headers="mcps1.2.3.1.2 "><p id="p18761104812149"><a name="p18761104812149"></a><a name="p18761104812149"></a>Sets a wallpaper of the specified type based on the uri path from a JPEG or PNG file or the pixel map of a PNG file(wallpaper path or pixelmap),Promise</p>
54</td>
55</tr>
56<tr id="row204321219393"><td class="cellrowborder" valign="top" width="50%" headers="mcps1.2.3.1.1 "><p id="p1893413268144"><a name="p1893413268144"></a><a name="p1893413268144"></a>function on(type: 'colorChange', callback: (colors: Array&lt;RgbaColor&gt;, wallpaperType: WallpaperType) => void): void;
57</p>
58</td>
59<td class="cellrowborder" valign="top" width="50%" headers="mcps1.2.3.1.2 "><p id="p18761104812149"><a name="p18761104812149"></a><a name="p18761104812149"></a>Registers a listener for wallpaper color changes to receive notifications about the changes,callback</p>
60</td>
61</tr>
62<tr id="row204321219393"><td class="cellrowborder" valign="top" width="50%" headers="mcps1.2.3.1.1 "><p id="p1893413268144"><a name="p1893413268144"></a><a name="p1893413268144"></a>function off(type: 'colorChange', callback?: (colors: Array&lt;RgbaColor&gt;, wallpaperType: WallpaperType) => void): void;
63</p>
64</td>
65<td class="cellrowborder" valign="top" width="50%" headers="mcps1.2.3.1.2 "><p id="p18761104812149"><a name="p18761104812149"></a><a name="p18761104812149"></a>Unregisters a listener for wallpaper color changes,callback</p>
66</td>
67</tr>
68</tbody>
69</table>
70
71JS APIs instructions
72```
73//get pixelmap callback with callback
74wallpaper.getPixelMap(WALLPAPER_SYSTEM, function (err, data) {
75            console.info('wallpaperXTS ===> testGetPixelMapCallbackSystem err : ' + JSON.stringify(err));
76            console.info('wallpaperXTS ===> testGetPixelMapCallbackSystem data : ' + JSON.stringify(data));
77            if(err){
78                expect(null).assertFail();
79            }
80            if((data != undefined) && (data != null) && (data != '')){
81                expect(true).assertTrue();
82            }
83        })
84
85//get pixelmap callback with Promise
86wallpaper.getPixelMap(WALLPAPER_SYSTEM).then((data) => {
87            console.info('wallpaperXTS ===> testGetPixelMapPromiseSystem data : ' + data);
88            console.info('wallpaperXTS ===> testGetPixelMapPromiseSystem data : ' + JSON.stringify(data));
89            if((data != undefined) && (data != null) && (data != '')){
90                expect(true).assertTrue();
91            }
92        }).catch((err) => {
93            console.info('wallpaperXTS ===> testGetPixelMapPromiseSystem err : ' + err);
94            console.info('wallpaperXTS ===> testGetPixelMapPromiseSystem err : ' + JSON.stringify(err));
95            if(err){
96                expect(null).assertFail();
97            }
98        });
99
100//set pixelmap callback with callback
101wallpaper.setWallpaper(pixelmap, WALLPAPER_SYSTEM, function (err, data) {
102                console.info('wallpaperXTS ===> testSetWallpaperPixelMapCallbackSystem err : ' + JSON.stringify(err));
103                console.info('wallpaperXTS ===> testSetWallpaperPixelMapCallbackSystem data : ' + JSON.stringify(data));
104                if(err){
105                    expect(null).assertFail();
106                }
107                if((data != undefined) && (data != null) && (data != '')){
108                    expect(true).assertTrue();
109                }
110            });
111
112//set pixelmap callback with Promise
113wallpaper.setWallpaper(pixelmap, WALLPAPER_SYSTEM).then((data) => {
114                console.info('wallpaperXTS ===> testSetWallpaperPixelMapPromiseSystem data : ' + JSON.stringify(data));
115                if((data != undefined) && (data != null) && (data != '')){
116                    expect(true).assertTrue();
117                }
118            }).catch((err) => {
119                console.info('wallpaperXTS ===> testSetWallpaperPixelMapPromiseSystem err : ' + JSON.stringify(err));
120                if(err){
121                    expect(null).assertFail();
122                }
123            });
124```
125
126#### Participation contribution
127
1281. Fork warehouse
1292. Submission code
1303. Create a new pull request
1314. Commit is complete
132
133
134

README_ZH.md

1# 杂散子系统/壁纸管理服务
2
3## 简介
4
5### 内容介绍
6该仓主要为系统提供壁纸管理服务能力,支持系统显示、设置、切换壁纸等功能。
7
8### 架构图介绍
9**图 1** 子系统架构图
10![](figures/subsystem_architecture_zh.png "子系统架构图")
11
12#### 仓路径
13
14/base/theme/wallpaper_mgr
15
16## 目录
17
18```
19/base/theme/wallpaper_mgr
20├── figures                  # 构架图
21├── frameworks/innerkitsimpl # 对应用提供的接口
22├── interfaces/kits          # 组件对外提供的接口代码
23│   ├── jskits               # 服务间接口
24│   └── napi                 # js接口解析成napi接口
25├── profile                  # 组件包含的系统服务的配置文件和进程的配置文件
26├── services                 # 壁纸管理服务实现
27├── test                     # 接口的单元测试
28└── utils                    # 组件包含日志打印和有序公共事件定义的常量
29```
30## 说明
31
32### 接口说明
33
34**表 1**  壁纸管理服务开放的主要方法
35
36<a name="table033515471012"></a>
37<table><thead align="left"><tr id="row143351854201012"><th class="cellrowborder" valign="top" width="50%" id="mcps1.2.3.1.1"><p id="p103351154121010"><a name="p103351154121010"></a><a name="p103351154121010"></a>接口名</p>
38</th>
39<th class="cellrowborder" valign="top" width="50%" id="mcps1.2.3.1.2"><p id="p1033585416105"><a name="p1033585416105"></a><a name="p1033585416105"></a>描述</p>
40</th>
41</tr>
42</thead>
43<tbody><tr id="row204321219393"><td class="cellrowborder" valign="top" width="50%" headers="mcps1.2.3.1.1 "><p id="p1893413268144"><a name="p1893413268144"></a><a name="p1893413268144"></a>function getColors(wallpaperType: WallpaperType, callback: AsyncCallback&lt;Array&lt;RgbaColor&gt;&gt;): void</p>
44</td>
45<td class="cellrowborder" valign="top" width="50%" headers="mcps1.2.3.1.2 "><p id="p18761104812149"><a name="p18761104812149"></a><a name="p18761104812149"></a>获取壁纸图片主颜色(桌面或者锁屏壁纸),callback方式</p>
46</td>
47</tr>
48<tr id="row13335054111018"><td class="cellrowborder" valign="top" width="50%" headers="mcps1.2.3.1.1 "><p id="p12832214151418"><a name="p12832214151418"></a><a name="p12832214151418"></a>function getColors(wallpaperType: WallpaperType): Promise&lt;Array&lt;RgbaColor&gt;&gt;</p>
49</td>
50<td class="cellrowborder" valign="top" width="50%" headers="mcps1.2.3.1.2 "><p id="p3335145451011"><a name="p3335145451011"></a><a name="p3335145451011"></a>获取壁纸图片主颜色(桌面或者锁屏壁纸),Promise方式</p>
51</td>
52</tr>
53<tr id="row13335054111018"><td class="cellrowborder" valign="top" width="50%" headers="mcps1.2.3.1.1 "><p id="p12832214151418"><a name="p12832214151418"></a><a name="p12832214151418"></a>function getColorsSync(wallpaperType: WallpaperType): Array&lt;RgbaColor&gt;</p>
54</td>
55<td class="cellrowborder" valign="top" width="50%" headers="mcps1.2.3.1.2 "><p id="p3335145451011"><a name="p3335145451011"></a><a name="p3335145451011"></a>获取壁纸图片主颜色(桌面或者锁屏壁纸),同步方式</p>
56</td>
57</tr>
58<tr id="row13335054111018"><td class="cellrowborder" valign="top" width="50%" headers="mcps1.2.3.1.1 "><p id="p12832214151418"><a name="p12832214151418"></a><a name="p12832214151418"></a>function getId(wallpaperType: WallpaperType, callback: AsyncCallback&lt;number&gt;): void</p>
59</td>
60<td class="cellrowborder" valign="top" width="50%" headers="mcps1.2.3.1.2 "><p id="p3335145451011"><a name="p3335145451011"></a><a name="p3335145451011"></a>获取壁纸id(桌面或者锁屏壁纸),callback方式</p>
61</td>
62</tr>
63<tr id="row13335054111018"><td class="cellrowborder" valign="top" width="50%" headers="mcps1.2.3.1.1 "><p id="p12832214151418"><a name="p12832214151418"></a><a name="p12832214151418"></a>function getId(wallpaperType: WallpaperType): Promise&lt;number&gt;</p>
64</td>
65<td class="cellrowborder" valign="top" width="50%" headers="mcps1.2.3.1.2 "><p id="p3335145451011"><a name="p3335145451011"></a><a name="p3335145451011"></a>获取壁纸id(桌面或者锁屏壁纸),Promise方式</p>
66</td>
67</tr>
68<tr id="row13335054111018"><td class="cellrowborder" valign="top" width="50%" headers="mcps1.2.3.1.1 "><p id="p12832214151418"><a name="p12832214151418"></a><a name="p12832214151418"></a>function getIdSync(wallpaperType: WallpaperType): number</p>
69</td>
70<td class="cellrowborder" valign="top" width="50%" headers="mcps1.2.3.1.2 "><p id="p3335145451011"><a name="p3335145451011"></a><a name="p3335145451011"></a>获取壁纸id(桌面或者锁屏壁纸),同步方式</p>
71</td>
72</tr>
73<tr id="row13335054111018"><td class="cellrowborder" valign="top" width="50%" headers="mcps1.2.3.1.1 "><p id="p12832214151418"><a name="p12832214151418"></a><a name="p12832214151418"></a>function getFile(wallpaperType: WallpaperType, callback: AsyncCallback&lt;number&gt;): void</p>
74</td>
75<td class="cellrowborder" valign="top" width="50%" headers="mcps1.2.3.1.2 "><p id="p3335145451011"><a name="p3335145451011"></a><a name="p3335145451011"></a>获取指定类型的壁纸文件,callback方式</p>
76</td>
77</tr>
78<tr id="row13335054111018"><td class="cellrowborder" valign="top" width="50%" headers="mcps1.2.3.1.1 "><p id="p12832214151418"><a name="p12832214151418"></a><a name="p12832214151418"></a>function getFile(wallpaperType: WallpaperType): Promise&lt;number&gt;</p>
79</td>
80<td class="cellrowborder" valign="top" width="50%" headers="mcps1.2.3.1.2 "><p id="p3335145451011"><a name="p3335145451011"></a><a name="p3335145451011"></a>获取指定类型的壁纸文件,Promise方式</p>
81</td>
82</tr>
83<tr id="row13335054111018"><td class="cellrowborder" valign="top" width="50%" headers="mcps1.2.3.1.1 "><p id="p12832214151418"><a name="p12832214151418"></a><a name="p12832214151418"></a>function getFileSync(wallpaperType: WallpaperType): number</p>
84</td>
85<td class="cellrowborder" valign="top" width="50%" headers="mcps1.2.3.1.2 "><p id="p3335145451011"><a name="p3335145451011"></a><a name="p3335145451011"></a>获取指定类型的壁纸文件,同步方式</p>
86</td>
87</tr>
88<tr id="row13335054111018"><td class="cellrowborder" valign="top" width="50%" headers="mcps1.2.3.1.1 "><p id="p12832214151418"><a name="p12832214151418"></a><a name="p12832214151418"></a>function getMinHeight(callback: AsyncCallback&lt;number&gt;): void</p>
89</td>
90<td class="cellrowborder" valign="top" width="50%" headers="mcps1.2.3.1.2 "><p id="p3335145451011"><a name="p3335145451011"></a><a name="p3335145451011"></a>获取壁纸的最小高度值,callback方式</p>
91</td>
92</tr>
93<tr id="row13335054111018"><td class="cellrowborder" valign="top" width="50%" headers="mcps1.2.3.1.1 "><p id="p12832214151418"><a name="p12832214151418"></a><a name="p12832214151418"></a>function getMinHeight(): Promise&lt;number&gt;</p>
94</td>
95<td class="cellrowborder" valign="top" width="50%" headers="mcps1.2.3.1.2 "><p id="p3335145451011"><a name="p3335145451011"></a><a name="p3335145451011"></a>获取壁纸的最小高度值,Promise方式</p>
96</td>
97</tr>
98<tr id="row13335054111018"><td class="cellrowborder" valign="top" width="50%" headers="mcps1.2.3.1.1 "><p id="p12832214151418"><a name="p12832214151418"></a><a name="p12832214151418"></a>function getMinHeightSync(): number</p>
99</td>
100<td class="cellrowborder" valign="top" width="50%" headers="mcps1.2.3.1.2 "><p id="p3335145451011"><a name="p3335145451011"></a><a name="p3335145451011"></a>获取壁纸的最小高度值,同步方式</p>
101</td>
102</tr>
103<tr id="row13335054111018"><td class="cellrowborder" valign="top" width="50%" headers="mcps1.2.3.1.1 "><p id="p12832214151418"><a name="p12832214151418"></a><a name="p12832214151418"></a>function getMinWidth(callback: AsyncCallback&lt;number&gt;): void</p>
104</td>
105<td class="cellrowborder" valign="top" width="50%" headers="mcps1.2.3.1.2 "><p id="p3335145451011"><a name="p3335145451011"></a><a name="p3335145451011"></a>获取壁纸的最小宽度值,callback方式</p>
106</td>
107</tr>
108<tr id="row13335054111018"><td class="cellrowborder" valign="top" width="50%" headers="mcps1.2.3.1.1 "><p id="p12832214151418"><a name="p12832214151418"></a><a name="p12832214151418"></a>function getMinWidth(): Promise&lt;number&gt;</p>
109</td>
110<td class="cellrowborder" valign="top" width="50%" headers="mcps1.2.3.1.2 "><p id="p3335145451011"><a name="p3335145451011"></a><a name="p3335145451011"></a>获取壁纸的最小宽度值,Promise方式</p>
111</td>
112</tr>
113<tr id="row13335054111018"><td class="cellrowborder" valign="top" width="50%" headers="mcps1.2.3.1.1 "><p id="p12832214151418"><a name="p12832214151418"></a><a name="p12832214151418"></a>function getMinWidthSync(): number</p>
114</td>
115<td class="cellrowborder" valign="top" width="50%" headers="mcps1.2.3.1.2 "><p id="p3335145451011"><a name="p3335145451011"></a><a name="p3335145451011"></a>获取壁纸的最小宽度值,同步方式</p>
116</td>
117</tr>
118<tr id="row13335054111018"><td class="cellrowborder" valign="top" width="50%" headers="mcps1.2.3.1.1 "><p id="p12832214151418"><a name="p12832214151418"></a><a name="p12832214151418"></a>function isChangePermitted(callback: AsyncCallback&lt;boolean&gt;): void</p>
119</td>
120<td class="cellrowborder" valign="top" width="50%" headers="mcps1.2.3.1.2 "><p id="p3335145451011"><a name="p3335145451011"></a><a name="p3335145451011"></a>是否允许应用改变当前用户的壁纸,callback方式</p>
121</td>
122</tr>
123<tr id="row13335054111018"><td class="cellrowborder" valign="top" width="50%" headers="mcps1.2.3.1.1 "><p id="p12832214151418"><a name="p12832214151418"></a><a name="p12832214151418"></a>function isChangePermitted(): Promise&lt;boolean&gt;</p>
124</td>
125<td class="cellrowborder" valign="top" width="50%" headers="mcps1.2.3.1.2 "><p id="p3335145451011"><a name="p3335145451011"></a><a name="p3335145451011"></a>是否允许应用改变当前用户的壁纸,Promise方式</p>
126</td>
127</tr>
128<tr id="row13335054111018"><td class="cellrowborder" valign="top" width="50%" headers="mcps1.2.3.1.1 "><p id="p12832214151418"><a name="p12832214151418"></a><a name="p12832214151418"></a>function isChangeAllowed(): boolean</p>
129</td>
130<td class="cellrowborder" valign="top" width="50%" headers="mcps1.2.3.1.2 "><p id="p3335145451011"><a name="p3335145451011"></a><a name="p3335145451011"></a>是否允许应用改变当前用户的壁纸,同步方式</p>
131</td>
132</tr>
133<tr id="row13335054111018"><td class="cellrowborder" valign="top" width="50%" headers="mcps1.2.3.1.1 "><p id="p12832214151418"><a name="p12832214151418"></a><a name="p12832214151418"></a>function isOperationAllowed(callback: AsyncCallback&lt;boolean&gt;): void</p>
134</td>
135<td class="cellrowborder" valign="top" width="50%" headers="mcps1.2.3.1.2 "><p id="p3335145451011"><a name="p3335145451011"></a><a name="p3335145451011"></a>是否允许用户设置壁纸,callback方式</p>
136</td>
137</tr>
138<tr id="row13335054111018"><td class="cellrowborder" valign="top" width="50%" headers="mcps1.2.3.1.1 "><p id="p12832214151418"><a name="p12832214151418"></a><a name="p12832214151418"></a>function isOperationAllowed(): Promise&lt;boolean&gt;</p>
139</td>
140<td class="cellrowborder" valign="top" width="50%" headers="mcps1.2.3.1.2 "><p id="p3335145451011"><a name="p3335145451011"></a><a name="p3335145451011"></a>是否允许用户设置壁纸,Promise方式</p>
141</td>
142</tr>
143<tr id="row13335054111018"><td class="cellrowborder" valign="top" width="50%" headers="mcps1.2.3.1.1 "><p id="p12832214151418"><a name="p12832214151418"></a><a name="p12832214151418"></a>function isUserChangeAllowed(): boolean</p>
144</td>
145<td class="cellrowborder" valign="top" width="50%" headers="mcps1.2.3.1.2 "><p id="p3335145451011"><a name="p3335145451011"></a><a name="p3335145451011"></a>是否允许用户设置壁纸,同步方式</p>
146</td>
147</tr>
148<tr id="row13335054111018"><td class="cellrowborder" valign="top" width="50%" headers="mcps1.2.3.1.1 "><p id="p12832214151418"><a name="p12832214151418"></a><a name="p12832214151418"></a>function reset(wallpaperType: WallpaperType, callback: AsyncCallback&lt;void&gt;): void</p>
149</td>
150<td class="cellrowborder" valign="top" width="50%" headers="mcps1.2.3.1.2 "><p id="p3335145451011"><a name="p3335145451011"></a><a name="p3335145451011"></a>移除指定类型的壁纸,恢复为默认显示的壁纸,callback方式</p>
151</td>
152</tr>
153<tr id="row13335054111018"><td class="cellrowborder" valign="top" width="50%" headers="mcps1.2.3.1.1 "><p id="p12832214151418"><a name="p12832214151418"></a><a name="p12832214151418"></a>function reset(wallpaperType: WallpaperType): Promise&lt;void&gt;</p>
154</td>
155<td class="cellrowborder" valign="top" width="50%" headers="mcps1.2.3.1.2 "><p id="p3335145451011"><a name="p3335145451011"></a><a name="p3335145451011"></a>移除指定类型的壁纸,恢复为默认显示的壁纸,Promise方式</p>
156</td>
157</tr>
158<tr id="row13335054111018"><td class="cellrowborder" valign="top" width="50%" headers="mcps1.2.3.1.1 "><p id="p12832214151418"><a name="p12832214151418"></a><a name="p12832214151418"></a>function restore(wallpaperType: WallpaperType, callback: AsyncCallback&lt;void&gt;): void</p>
159</td>
160<td class="cellrowborder" valign="top" width="50%" headers="mcps1.2.3.1.2 "><p id="p3335145451011"><a name="p3335145451011"></a><a name="p3335145451011"></a>移除指定类型的壁纸,恢复为默认显示的壁纸,callback方式</p>
161</td>
162</tr>
163<tr id="row13335054111018"><td class="cellrowborder" valign="top" width="50%" headers="mcps1.2.3.1.1 "><p id="p12832214151418"><a name="p12832214151418"></a><a name="p12832214151418"></a>function restore(wallpaperType: WallpaperType): Promise&lt;void&gt;</p>
164</td>
165<td class="cellrowborder" valign="top" width="50%" headers="mcps1.2.3.1.2 "><p id="p3335145451011"><a name="p3335145451011"></a><a name="p3335145451011"></a>移除指定类型的壁纸,恢复为默认显示的壁纸,Promise方式</p>
166</td>
167</tr>
168<tr id="row13335054111018"><td class="cellrowborder" valign="top" width="50%" headers="mcps1.2.3.1.1 "><p id="p12832214151418"><a name="p12832214151418"></a><a name="p12832214151418"></a>function setWallpaper(source: string | image.PixelMap, wallpaperType: WallpaperType, callback: AsyncCallback&lt;void&gt;): void</p>
169</td>
170<td class="cellrowborder" valign="top" width="50%" headers="mcps1.2.3.1.2 "><p id="p3335145451011"><a name="p3335145451011"></a><a name="p3335145451011"></a>将指定资源设置为指定类型的壁纸,callback方式</p>
171</td>
172</tr>
173<tr id="row13335054111018"><td class="cellrowborder" valign="top" width="50%" headers="mcps1.2.3.1.1 "><p id="p12832214151418"><a name="p12832214151418"></a><a name="p12832214151418"></a>function setWallpaper(source: string | image.PixelMap, wallpaperType: WallpaperType): Promise&lt;void&gt;</p>
174</td>
175<td class="cellrowborder" valign="top" width="50%" headers="mcps1.2.3.1.2 "><p id="p3335145451011"><a name="p3335145451011"></a><a name="p3335145451011"></a>将指定资源设置为指定类型的壁纸,Promise方式</p>
176</td>
177</tr>
178<tr id="row13335054111018"><td class="cellrowborder" valign="top" width="50%" headers="mcps1.2.3.1.1 "><p id="p12832214151418"><a name="p12832214151418"></a><a name="p12832214151418"></a>function setImage(source: string | image.PixelMap, wallpaperType: WallpaperType, callback: AsyncCallback&lt;void&gt;): void</p>
179</td>
180<td class="cellrowborder" valign="top" width="50%" headers="mcps1.2.3.1.2 "><p id="p3335145451011"><a name="p3335145451011"></a><a name="p3335145451011"></a>将指定资源设置为指定类型的壁纸,callback方式</p>
181</td>
182</tr>
183<tr id="row13335054111018"><td class="cellrowborder" valign="top" width="50%" headers="mcps1.2.3.1.1 "><p id="p12832214151418"><a name="p12832214151418"></a><a name="p12832214151418"></a>function setImage(source: string | image.PixelMap, wallpaperType: WallpaperType): Promise&lt;void&gt;</p>
184</td>
185<td class="cellrowborder" valign="top" width="50%" headers="mcps1.2.3.1.2 "><p id="p3335145451011"><a name="p3335145451011"></a><a name="p3335145451011"></a>将指定资源设置为指定类型的壁纸,Promise方式</p>
186</td>
187</tr>
188<tr id="row13335054111018"><td class="cellrowborder" valign="top" width="50%" headers="mcps1.2.3.1.1 "><p id="p12832214151418"><a name="p12832214151418"></a><a name="p12832214151418"></a>function getPixelMap(wallpaperType: WallpaperType, callback: AsyncCallback&lt;image.PixelMap&gt;): void</p>
189</td>
190<td class="cellrowborder" valign="top" width="50%" headers="mcps1.2.3.1.2 "><p id="p3335145451011"><a name="p3335145451011"></a><a name="p3335145451011"></a>获取指定类型的壁纸文件,callback方式</p>
191</td>
192</tr>
193<tr id="row13335054111018"><td class="cellrowborder" valign="top" width="50%" headers="mcps1.2.3.1.1 "><p id="p12832214151418"><a name="p12832214151418"></a><a name="p12832214151418"></a>function getPixelMap(wallpaperType: WallpaperType): Promise&lt;image.PixelMap&gt;</p>
194</td>
195<td class="cellrowborder" valign="top" width="50%" headers="mcps1.2.3.1.2 "><p id="p3335145451011"><a name="p3335145451011"></a><a name="p3335145451011"></a>获取指定类型的壁纸文件,Promise方式</p>
196</td>
197</tr>
198<tr id="row13335054111018"><td class="cellrowborder" valign="top" width="50%" headers="mcps1.2.3.1.1 "><p id="p12832214151418"><a name="p12832214151418"></a><a name="p12832214151418"></a>function getImage(wallpaperType: WallpaperType, callback: AsyncCallback&lt;image.PixelMap&gt;): void</p>
199</td>
200<td class="cellrowborder" valign="top" width="50%" headers="mcps1.2.3.1.2 "><p id="p3335145451011"><a name="p3335145451011"></a><a name="p3335145451011"></a>获取指定类型的壁纸文件,callback方式</p>
201</td>
202</tr>
203<tr id="row13335054111018"><td class="cellrowborder" valign="top" width="50%" headers="mcps1.2.3.1.1 "><p id="p12832214151418"><a name="p12832214151418"></a><a name="p12832214151418"></a>function getImage(wallpaperType: WallpaperType): Promise&lt;image.PixelMap&gt;</p>
204</td>
205<td class="cellrowborder" valign="top" width="50%" headers="mcps1.2.3.1.2 "><p id="p3335145451011"><a name="p3335145451011"></a><a name="p3335145451011"></a>获取指定类型的壁纸文件,Promise方式</p>
206</td>
207</tr>
208<tr id="row204321219393"><td class="cellrowborder" valign="top" width="50%" headers="mcps1.2.3.1.1 "><p id="p1893413268144"><a name="p1893413268144"></a><a name="p1893413268144"></a>function on(type: 'colorChange', callback: (colors: Array&lt;RgbaColor&gt;, wallpaperType: WallpaperType) => void): void;
209</p>
210</td>
211<td class="cellrowborder" valign="top" width="50%" headers="mcps1.2.3.1.2 "><p id="p18761104812149"><a name="p18761104812149"></a><a name="p18761104812149"></a>监听壁纸图片主颜色变化,callback方式</p>
212</td>
213</tr>
214<tr id="row204321219393"><td class="cellrowborder" valign="top" width="50%" headers="mcps1.2.3.1.1 "><p id="p1893413268144"><a name="p1893413268144"></a><a name="p1893413268144"></a>function off(type: 'colorChange', callback?: (colors: Array&lt;RgbaColor&gt;, wallpaperType: WallpaperType) => void): void;
215</p>
216</td>
217<td class="cellrowborder" valign="top" width="50%" headers="mcps1.2.3.1.2 "><p id="p18761104812149"><a name="p18761104812149"></a><a name="p18761104812149"></a>取消监听壁纸图片主颜色变化,callback方式</p>
218</td>
219</tr>
220</tbody>
221</table>
222
223**表 2**  应用extension的主要接口
224
225<a name="table033515471012"></a>
226<table><thead align="left"><tr id="row143351854201012"><th class="cellrowborder" valign="top" width="50%" id="mcps1.2.3.1.1"><p id="p103351154121010"><a name="p103351154121010"></a><a name="p103351154121010"></a>接口名</p>
227</th>
228<th class="cellrowborder" valign="top" width="50%" id="mcps1.2.3.1.2"><p id="p1033585416105"><a name="p1033585416105"></a><a name="p1033585416105"></a>描述</p>
229</th>
230</tr>
231</thead>
232<tbody><tr id="row204321219393"><td class="cellrowborder" valign="top" width="50%" headers="mcps1.2.3.1.1 "><p id="p1893413268144"><a name="p1893413268144"></a><a name="p1893413268144"></a>onCreated(want: object): void</p>
233</td>
234<td class="cellrowborder" valign="top" width="50%" headers="mcps1.2.3.1.2 "><p id="p18761104812149"><a name="p18761104812149"></a><a name="p18761104812149"></a>wallpaper extension 初始化的回调</p>
235</td>
236</tr>
237<tr id="row13335054111018"><td class="cellrowborder" valign="top" width="50%" headers="mcps1.2.3.1.1 "><p id="p12832214151418"><a name="p12832214151418"></a><a name="p12832214151418"></a>onWallpaperChanged(wallpaperType: number): void</p>
238</td>
239<td class="cellrowborder" valign="top" width="50%" headers="mcps1.2.3.1.2 "><p id="p3335145451011"><a name="p3335145451011"></a><a name="p3335145451011"></a>壁纸发生了变化的回调</p>
240</td>
241</tr>
242<tr id="row204321219393"><td class="cellrowborder" valign="top" width="50%" headers="mcps1.2.3.1.1 "><p id="p1893413268144"><a name="p1893413268144"></a><a name="p1893413268144"></a>setUiContent(url:string): void</p>
243</td>
244<td class="cellrowborder" valign="top" width="50%" headers="mcps1.2.3.1.2 "><p id="p18761104812149"><a name="p18761104812149"></a><a name="p18761104812149"></a>应用设置壁纸的布局文件路径</p>
245</td>
246</tr>
247<tr id="row204321219393"><td class="cellrowborder" valign="top" width="50%" headers="mcps1.2.3.1.1 "><p id="p1893413268144"><a name="p1893413268144"></a><a name="p1893413268144"></a>onDestroy(): void
248</p>
249</td>
250<td class="cellrowborder" valign="top" width="50%" headers="mcps1.2.3.1.2 "><p id="p18761104812149"><a name="p18761104812149"></a><a name="p18761104812149"></a>wallpaper extension 销毁回调</p>
251</td>
252</tr>
253</tbody>
254</table>
255
256**表 3**  RgbaColor说明
257
258<a name="table033515471012"></a>
259<table><thead align="left"><tr id="row143351854201012"><th class="cellrowborder" valign="top" width="50%" id="mcps1.2.3.1.1"><p id="p103351154121010"><a name="p103351154121010"></a><a name="p103351154121010"></a>名称</p>
260</th>
261<th class="cellrowborder" valign="top" width="50%" id="mcps1.2.3.1.2"><p id="p1033585416105"><a name="p1033585416105"></a><a name="p1033585416105"></a>说明</p>
262</th>
263</tr>
264</thead>
265<tbody><tr id="row204321219393"><td class="cellrowborder" valign="top" width="50%" headers="mcps1.2.3.1.1 "><p id="p1893413268144"><a name="p1893413268144"></a><a name="p1893413268144"></a>red</p>
266</td>
267<td class="cellrowborder" valign="top" width="50%" headers="mcps1.2.3.1.2 "><p id="p18761104812149"><a name="p18761104812149"></a><a name="p18761104812149"></a>表示红色值,范围为&nbsp;0&nbsp;到&nbsp;255</p>
268</td>
269</tr>
270<tr id="row13335054111018"><td class="cellrowborder" valign="top" width="50%" headers="mcps1.2.3.1.1 "><p id="p12832214151418"><a name="p12832214151418"></a><a name="p12832214151418"></a>green</p>
271</td>
272<td class="cellrowborder" valign="top" width="50%" headers="mcps1.2.3.1.2 "><p id="p3335145451011"><a name="p3335145451011"></a><a name="p3335145451011"></a>表示绿色值,范围为&nbsp;0&nbsp;到&nbsp;255</p>
273</td>
274</tr>
275<tr id="row204321219393"><td class="cellrowborder" valign="top" width="50%" headers="mcps1.2.3.1.1 "><p id="p1893413268144"><a name="p1893413268144"></a><a name="p1893413268144"></a>blue</p>
276</td>
277<td class="cellrowborder" valign="top" width="50%" headers="mcps1.2.3.1.2 "><p id="p18761104812149"><a name="p18761104812149"></a><a name="p18761104812149"></a>表示蓝色值,范围为&nbsp;0&nbsp;到&nbsp;255</p>
278</td>
279</tr>
280<tr id="row204321219393"><td class="cellrowborder" valign="top" width="50%" headers="mcps1.2.3.1.1 "><p id="p1893413268144"><a name="p1893413268144"></a><a name="p1893413268144"></a>alpha
281</p>
282</td>
283<td class="cellrowborder" valign="top" width="50%" headers="mcps1.2.3.1.2 "><p id="p18761104812149"><a name="p18761104812149"></a><a name="p18761104812149"></a>表示&nbsp;alpha&nbsp;值,范围为&nbsp;0&nbsp;到&nbsp;255</p>
284</td>
285</tr>
286</tbody>
287</table>
288
289### 使用说明
290
291```js
292导入模块
293import screenLock from '@ohos.screenlock';
294
295//获取指定类型壁纸的主要颜色信息callback方式
296wallpaper.getColors(wallpaper.WallpaperType.WALLPAPER_SYSTEM, (error, data) => {
297    if (error) {
298        console.error(`failed to getColors because: ` + JSON.stringify(error));
299        return;
300    }
301    console.log(`success to getColors.`);
302});
303//获取指定类型壁纸的主要颜色信息Promise方式
304wallpaper.getColors(wallpaper.WallpaperType.WALLPAPER_SYSTEM).then((data) => {
305    console.log(`success to getColors.`);
306}).catch((error) => {
307    console.error(`failed to getColors because: ` + JSON.stringify(error));
308});
309//获取指定类型壁纸的主要颜色信息同步方式
310wallpaper.getColorsSync(wallpaper.WallpaperType.WALLPAPER_SYSTEM);
311
312//获取指定类型壁纸的IDcallback方式
313wallpaper.getId(wallpaper.WallpaperType.WALLPAPER_SYSTEM, (error, data) => {
314    if (error) {
315        console.error(`failed to getId because: ` + JSON.stringify(error));
316        return;
317    }
318    console.log(`success to getId: ` + JSON.stringify(data));
319});
320//获取指定类型壁纸的IDPromise方式
321wallpaper.getId(wallpaper.WallpaperType.WALLPAPER_SYSTEM).then((data) => {
322    console.log(`success to getId: ` + JSON.stringify(data));
323}).catch((error) => {
324    console.error(`failed to getId because: ` + JSON.stringify(error));
325});
326//获取指定类型壁纸的ID同步方式
327wallpaper.getIdSync(wallpaper.WallpaperType.WALLPAPER_SYSTEM);
328
329//获取壁纸的最小高度值callback方式
330wallpaper.getMinHeight((error, data) => {
331    if (error) {
332        console.error(`failed to getMinHeight because: ` + JSON.stringify(error));
333        return;
334    }
335    console.log(`success to getMinHeight: ` + JSON.stringify(data));
336});
337//获取壁纸的最小高度值Promise方式
338wallpaper.getMinHeight().then((data) => {
339    console.log(`success to getMinHeight: ` + JSON.stringify(data));
340}).catch((error) => {
341    console.error(`failed to getMinHeight because: ` + JSON.stringify(error));
342});
343//获取壁纸的最小高度值同步方式
344wallpaper.getMinHeightSync();
345
346//获取壁纸的最小宽度值callback方式
347wallpaper.getMinWidth((error, data) => {
348    if (error) {
349        console.error(`failed to getMinWidth because: ` + JSON.stringify(error));
350        return;
351    }
352    console.log(`success to getMinWidth: ` + JSON.stringify(data));
353});
354//获取壁纸的最小宽度值Promise方式
355wallpaper.getMinWidth().then((data) => {
356    console.log(`success to getMinWidth: ` + JSON.stringify(data));
357}).catch((error) => {
358    console.error(`failed to getMinWidth because: ` + JSON.stringify(error));
359});
360//获取壁纸的最小宽度值同步方式
361wallpaper.getMinWidthSync();
362
363//是否允许应用改变当前用户的壁纸callback方式
364wallpaper.isChangePermitted((error, data) => {
365    if (error) {
366        console.error(`failed to isChangePermitted because: ` + JSON.stringify(error));
367        return;
368    }
369    console.log(`success to isChangePermitted: ` + JSON.stringify(data));
370});
371//是否允许应用改变当前用户的壁纸Promise方式
372wallpaper.isChangePermitted().then((data) => {
373    console.log(`success to isChangePermitted: ` + JSON.stringify(data));
374}).catch((error) => {
375    console.error(`failed to isChangePermitted because: ` + JSON.stringify(error));
376});
377//是否允许应用改变当前用户的壁纸同步方式
378wallpaper.isChangeAllowed();
379
380//是否允许用户设置壁纸callback方式
381wallpaper.isOperationAllowed((error, data) => {
382    if (error) {
383        console.error(`failed to isOperationAllowed because: ` + JSON.stringify(error));
384        return;
385    }
386    console.log(`success to isOperationAllowed: ` + JSON.stringify(data));
387});
388//是否允许用户设置壁纸Promise方式
389wallpaper.isOperationAllowed().then((data) => {
390    console.log(`success to isOperationAllowed: ` + JSON.stringify(data));
391}).catch((error) => {
392    console.error(`failed to isOperationAllowed because: ` + JSON.stringify(error));
393});
394//是否允许用户设置壁纸同步方式
395wallpaper.isUserChangeAllowed();
396
397//获取指定类型的壁纸文件callback方式
398wallpaper.getFile(wallpaper.WallpaperType.WALLPAPER_SYSTEM, (error, data) => {
399    if (error) {
400        console.error(`failed to getFile because: ` + JSON.stringify(error));
401        return;
402    }
403    console.log(`success to getFile: ` + JSON.stringify(data));
404});
405//获取指定类型的壁纸文件Promise方式
406wallpaper.getFile(wallpaper.WallpaperType.WALLPAPER_SYSTEM).then((data) => {
407    console.log(`success to getFile: ` + JSON.stringify(data));
408}).catch((error) => {
409    console.error(`failed to getFile because: ` + JSON.stringify(error));
410});
411//获取指定类型的壁纸文件同步方式
412wallpaper.getFileSync(wallpaper.WallpaperType.WALLPAPER_SYSTEM);
413
414//移除指定类型的壁纸,恢复为默认显示的壁纸callback方式
415wallpaper.reset(wallpaper.WallpaperType.WALLPAPER_SYSTEM, (error, data) => {
416    if (error) {
417        console.error(`failed to reset because: ` + JSON.stringify(error));
418        return;
419    }
420    console.log(`success to reset.`);
421});
422//移除指定类型的壁纸,恢复为默认显示的壁纸Promise方式
423wallpaper.reset(wallpaper.WallpaperType.WALLPAPER_SYSTEM).then((data) => {
424    console.log(`success to reset.`);
425}).catch((error) => {
426    console.error(`failed to reset because: ` + JSON.stringify(error));
427});
428//移除指定类型的壁纸,恢复为默认显示的壁纸callback方式
429wallpaper.restore(wallpaper.WallpaperType.WALLPAPER_SYSTEM, (error, data) => {
430    if (error) {
431        console.error(`failed to restore because: ` + JSON.stringify(error));
432        return;
433    }
434    console.log(`success to restore.`);
435});
436//移除指定类型的壁纸,恢复为默认显示的壁纸Promise方式
437wallpaper.restore(wallpaper.WallpaperType.WALLPAPER_SYSTEM).then((data) => {
438    console.log(`success to restore.`);
439}).catch((error) => {
440    console.error(`failed to restore because: ` + JSON.stringify(error));
441});
442
443//将指定资源设置为指定类型的壁纸callback方式
444// source类型为string
445let wallpaperPath = "/data/data/ohos.acts.aafwk.plrdtest.form/files/Cup_ic.jpg";
446wallpaper.setWallpaper(wallpaperPath, wallpaper.WallpaperType.WALLPAPER_SYSTEM, (error, data) => {
447    if (error) {
448        console.error(`failed to setWallpaper because: ` + JSON.stringify(error));
449        return;
450    }
451    console.log(`success to setWallpaper.`);
452});
453
454// source类型为image.PixelMap
455import image from '@ohos.multimedia.image';
456let imageSource = image.createImageSource("file://" + wallpaperPath);
457let opts = {
458    "desiredSize": {
459        "height": 3648,
460        "width": 2736
461    }
462};
463imageSource.createPixelMap(opts).then((pixelMap) => {
464    wallpaper.setWallpaper(pixelMap, wallpaper.WallpaperType.WALLPAPER_SYSTEM, (error, data) => {
465        if (error) {
466            console.error(`failed to setWallpaper because: ` + JSON.stringify(error));
467            return;
468        }
469        console.log(`success to setWallpaper.`);
470    });
471}).catch((error) => {
472    console.error(`failed to createPixelMap because: ` + JSON.stringify(error));
473});
474//将指定资源设置为指定类型的壁纸romise方式
475// source类型为string
476let wallpaperPath = "/data/data/ohos.acts.aafwk.plrdtest.form/files/Cup_ic.jpg";
477wallpaper.setWallpaper(wallpaperPath, wallpaper.WallpaperType.WALLPAPER_SYSTEM).then((data) => {
478    console.log(`success to setWallpaper.`);
479}).catch((error) => {
480    console.error(`failed to setWallpaper because: ` + JSON.stringify(error));
481});
482
483// source类型为image.PixelMap
484import image from '@ohos.multimedia.image';
485let imageSource = image.createImageSource("file://" + wallpaperPath);
486let opts = {
487    "desiredSize": {
488        "height": 3648,
489        "width": 2736
490    }
491};
492imageSource.createPixelMap(opts).then((pixelMap) => {
493    wallpaper.setWallpaper(pixelMap, wallpaper.WallpaperType.WALLPAPER_SYSTEM).then((data) => {
494        console.log(`success to setWallpaper.`);
495    }).catch((error) => {
496        console.error(`failed to setWallpaper because: ` + JSON.stringify(error));
497    });
498}).catch((error) => {
499    console.error(`failed to createPixelMap because: ` + JSON.stringify(error));
500});
501//将指定资源设置为指定类型的壁纸callback方式
502// source类型为string
503let wallpaperPath = "/data/data/ohos.acts.aafwk.plrdtest.form/files/Cup_ic.jpg";
504wallpaper.setImage(wallpaperPath, wallpaper.WallpaperType.WALLPAPER_SYSTEM, (error, data) => {
505    if (error) {
506        console.error(`failed to setImage because: ` + JSON.stringify(error));
507        return;
508    }
509    console.log(`success to setImage.`);
510});
511
512// source类型为image.PixelMap
513import image from '@ohos.multimedia.image';
514let imageSource = image.createImageSource("file://" + wallpaperPath);
515let opts = {
516    "desiredSize": {
517        "height": 3648,
518        "width": 2736
519    }
520};
521imageSource.createPixelMap(opts).then((pixelMap) => {
522    wallpaper.setImage(pixelMap, wallpaper.WallpaperType.WALLPAPER_SYSTEM, (error, data) => {
523        if (error) {
524            console.error(`failed to setImage because: ` + JSON.stringify(error));
525            return;
526        }
527        console.log(`success to setImage.`);
528    });
529}).catch((error) => {
530    console.error(`failed to createPixelMap because: ` + JSON.stringify(error));
531});
532//将指定资源设置为指定类型的壁纸Promise方式
533// source类型为string
534let wallpaperPath = "/data/data/ohos.acts.aafwk.plrdtest.form/files/Cup_ic.jpg";
535wallpaper.setImage(wallpaperPath, wallpaper.WallpaperType.WALLPAPER_SYSTEM).then((data) => {
536    console.log(`success to setImage.`);
537}).catch((error) => {
538    console.error(`failed to setImage because: ` + JSON.stringify(error));
539});
540
541// source类型为image.PixelMap
542import image from '@ohos.multimedia.image';
543let imageSource = image.createImageSource("file://" + wallpaperPath);
544let opts = {
545    "desiredSize": {
546        "height": 3648,
547        "width": 2736
548    }
549};
550imageSource.createPixelMap(opts).then((pixelMap) => {
551    wallpaper.setImage(pixelMap, wallpaper.WallpaperType.WALLPAPER_SYSTEM).then((data) => {
552        console.log(`success to setImage.`);
553    }).catch((error) => {
554        console.error(`failed to setImage because: ` + JSON.stringify(error));
555    });
556}).catch((error) => {
557    console.error(`failed to createPixelMap because: ` + JSON.stringify(error));
558});
559
560//获取壁纸图片的像素图callback方式
561wallpaper.getPixelMap(wallpaper.WallpaperType.WALLPAPER_SYSTEM, function (err, data) {
562    console.info('wallpaperXTS ===> testGetPixelMapCallbackSystem err : ' + JSON.stringify(err));
563    console.info('wallpaperXTS ===> testGetPixelMapCallbackSystem data : ' + JSON.stringify(data));
564});
565//获取壁纸图片的像素图Promise方式
566wallpaper.getPixelMap(wallpaper.WallpaperType.WALLPAPER_SYSTEM).then((data) => {
567    console.info('wallpaperXTS ===> testGetPixelMapPromiseSystem data : ' + data);
568    console.info('wallpaperXTS ===> testGetPixelMapPromiseSystem data : ' + JSON.stringify(data));
569}).catch((err) => {
570    console.info('wallpaperXTS ===> testGetPixelMapPromiseSystem err : ' + err);
571    console.info('wallpaperXTS ===> testGetPixelMapPromiseSystem err : ' + JSON.stringify(err));
572});
573//获取壁纸图片的像素图callback方式
574wallpaper.getImage(wallpaper.WallpaperType.WALLPAPER_SYSTEM, function (err, data) {
575    console.info('wallpaperXTS ===> testgetImageCallbackSystem err : ' + JSON.stringify(err));
576    console.info('wallpaperXTS ===> testgetImageCallbackSystem data : ' + JSON.stringify(data));
577});
578//获取壁纸图片的像素图Promise方式
579wallpaper.getImage(wallpaper.WallpaperType.WALLPAPER_SYSTEM).then((data) => {
580    console.info('wallpaperXTS ===> testgetImagePromiseSystem data : ' + data);
581    console.info('wallpaperXTS ===> testgetImagePromiseSystem data : ' + JSON.stringify(data));
582}).catch((err) => {
583    console.info('wallpaperXTS ===> testgetImagePromiseSystem err : ' + err);
584    console.info('wallpaperXTS ===> testgetImagePromiseSystem err : ' + JSON.stringify(err));
585});
586
587//订阅壁纸颜色变化结果上报事件callback方式
588let listener = (colors, wallpaperType) => {
589    console.log(`wallpaper color changed.`);
590};
591wallpaper.on('colorChange', listener);
592// 取消订阅listener
593wallpaper.off('colorChange', listener);
594// 取消所有'colorChange'类型的订阅
595wallpaper.off('colorChange');
596
597```
598
599js 应用接口使用说明
600
601```js
602import Extension from '@ohos.wallpaperextension'
603import wallPaper from '@ohos.wallpaper'
604
605export default class WallpaperExtAbility extends Extension {
606    onCreated(want) {
607        console.info(MODULE_TAG + 'ability on created start');
608        super.setUiContent("pages/index");
609        console.info(MODULE_TAG + 'ability on created end');
610    }
611
612    onWallpaperChanged(wallpaperType) {
613        console.info(MODULE_TAG + "ability on wallpaper changed start, type is : " + wallpaperType);
614        if (wallPaper) {
615            this.sendPixelMapData();
616        }
617       console.info(MODULE_TAG + "ability on wallpaper changed end");
618    }
619
620    onDestroy() {
621        console.info(MODULE_TAG + 'ability on destroy');
622    }
623
624    initWallpaperImage() {
625        console.info(MODULE_TAG + 'ability init wallpaper image start');
626        if (!wallPaper) {
627            console.info(MODULE_TAG + "ability init wallpaper image failed as wallpaper is null");
628            return;
629        }
630        this.sendPixelMapData()
631        console.info(MODULE_TAG + 'ability init wallpaper image end');
632    }
633
634    sendPixelMapData() {
635        // 0 is WallpaperType:WALLPAPER_SYSTEM, 1 isWallpaperType:WALLPAPER_LOCKSCREEN
636        wallPaper.getPixelMap(0, (err, data) => {
637            console.info(MODULE_TAG + "ability get pixel map data start");
638            if (err) {
639                console.info(MODULE_TAG + "ability get pixel map failed, error : " + JSON.stringify(err));
640            } else {
641                console.info(MODULE_TAG + "ability get pixel map, data : " + JSON.stringify(data));
642                AppStorage.SetOrCreate('slPixelData', data);
643            }
644            console.info(MODULE_TAG + "ability get pixel map data end");
645        });
646    }
647};
648
649```
650
651## 相关仓
652
653**主题框架子系统**
654
655[theme_wallpaper_mgr](https://gitee.com/openharmony/theme_wallpaper_mgr)
656
657