js-apis-wallpaper.md 40.7 KB
Newer Older
Z
zengyawen 已提交
1 2
# Wallpaper

E
ester.zhou 已提交
3
The **wallpaper** module is part of the theme framework and provides the system-level wallpaper management service in OpenHarmony. You can use the APIs of this module to show, set, and switch between wallpapers.
Z
zengyawen 已提交
4

E
ester.zhou 已提交
5 6 7
> **NOTE**
>
> The initial APIs of this module are supported since API version 7. Newly added APIs will be marked with a superscript to indicate their earliest API version.
Z
zengyawen 已提交
8 9 10 11 12 13 14 15 16 17 18 19


## Modules to Import


```
import wallpaper from '@ohos.wallpaper';
```


## WallpaperType

E
ester.zhou 已提交
20
Enumerates the wallpaper types.
Z
zengyawen 已提交
21 22 23

**System capability**: SystemCapability.MiscServices.Wallpaper

E
ester.zhou 已提交
24 25 26 27
| Name| Value|Description|
| -------- | -------- |-------- |
| WALLPAPER_SYSTEM | 0 |Home screen wallpaper.|
| WALLPAPER_LOCKSCREEN | 1 |Lock screen wallpaper.|
Z
zengyawen 已提交
28 29 30 31 32 33


## wallpaper.getColors

getColors(wallpaperType: WallpaperType, callback: AsyncCallback<Array<RgbaColor>>): void

E
ester.zhou 已提交
34
Obtains the main color information of the wallpaper of the specified type. This API uses an asynchronous callback to return the result.
Z
zengyawen 已提交
35

E
ester.zhou 已提交
36 37 38 39
> **NOTE**
> 
> This API is supported since API version 7 and deprecated since API version 9. You are advised to use [wallpaper.getColorsSync<sup>9+</sup>](#wallpapergetcolorssync9) instead.

Z
zengyawen 已提交
40 41
**System capability**: SystemCapability.MiscServices.Wallpaper

E
ester.zhou 已提交
42
**Parameters**
E
ester.zhou 已提交
43 44

| Name| Type| Mandatory| Description|
E
ester.zhou 已提交
45
| -------- | -------- | -------- | -------- |
E
ester.zhou 已提交
46 47
| wallpaperType | [WallpaperType](#wallpapertype) | Yes| Wallpaper type.|
| callback | AsyncCallback&lt;Array&lt;[RgbaColor](#rgbacolor)&gt;&gt; | Yes| Callback used to return the main color information of the wallpaper.|
E
ester.zhou 已提交
48 49

**Example**
Z
zengyawen 已提交
50

E
ester.zhou 已提交
51
  ```js
Z
zengyawen 已提交
52 53 54 55 56 57 58 59 60 61 62 63 64 65
  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.`);
  });
  ```


## wallpaper.getColors

getColors(wallpaperType: WallpaperType): Promise&lt;Array&lt;RgbaColor&gt;&gt;

E
ester.zhou 已提交
66
Obtains the main color information of the wallpaper of the specified type. This API uses a promise to return the result.
Z
zengyawen 已提交
67

E
ester.zhou 已提交
68 69 70 71
> **NOTE**
> 
> This API is supported since API version 7 and deprecated since API version 9. You are advised to use [wallpaper.getColorsSync<sup>9+</sup>](#wallpapergetcolorssync9) instead.

Z
zengyawen 已提交
72 73
**System capability**: SystemCapability.MiscServices.Wallpaper

E
ester.zhou 已提交
74
**Parameters**
Z
zengyawen 已提交
75

E
ester.zhou 已提交
76
| Name| Type| Mandatory| Description|
E
ester.zhou 已提交
77
| -------- | -------- | -------- | -------- |
E
ester.zhou 已提交
78
| wallpaperType | [WallpaperType](#wallpapertype) | Yes| Wallpaper type.|
Z
zengyawen 已提交
79

E
ester.zhou 已提交
80 81
**Return value**

E
ester.zhou 已提交
82
| Type| Description|
E
ester.zhou 已提交
83
| -------- | -------- |
E
ester.zhou 已提交
84
| Promise&lt;Array&lt;[RgbaColor](#rgbacolor)&gt;&gt; | Promise used to return the main color information of the wallpaper.|
E
ester.zhou 已提交
85 86 87

**Example**

E
ester.zhou 已提交
88 89 90 91 92 93 94
  ```js
  wallpaper.getColors(wallpaper.WallpaperType.WALLPAPER_SYSTEM).then((data) => {
      console.log(`success to getColors.`);
  }).catch((error) => {
      console.error(`failed to getColors because: ` + JSON.stringify(error));
  });
  ```
Z
zengyawen 已提交
95 96


E
ester.zhou 已提交
97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123
## wallpaper.getColorsSync<sup>9+</sup>

getColorsSync(wallpaperType: WallpaperType): Array&lt;RgbaColor&gt;

Obtains the main color information of the wallpaper of the specified type. This API uses an asynchronous callback to return the result.

**System capability**: SystemCapability.MiscServices.Wallpaper

**Parameters**

| Name| Type| Mandatory| Description|
| -------- | -------- | -------- | -------- |
| wallpaperType | [WallpaperType](#wallpapertype) | Yes| Wallpaper type.|

**Return value**

| Type| Description|
| -------- | -------- |
| Array&lt;[RgbaColor](#rgbacolor)&gt; | Promise used to return the main color information of the wallpaper.|

**Example**

  ```js
  var colors = wallpaper.getColorsSync(wallpaper.WallpaperType.WALLPAPER_SYSTEM);
  ```


Z
zengyawen 已提交
124 125 126 127
## wallpaper.getId

getId(wallpaperType: WallpaperType, callback: AsyncCallback&lt;number&gt;): void

E
ester.zhou 已提交
128
Obtains the ID of the wallpaper of the specified type. This API uses an asynchronous callback to return the result.
Z
zengyawen 已提交
129

E
ester.zhou 已提交
130 131 132 133
> **NOTE**
> 
> This API is supported since API version 7 and deprecated since API version 9. You are advised to use [wallpaper.getIdSync<sup>9+</sup>](#wallpapergetidsync9) instead.

Z
zengyawen 已提交
134 135
**System capability**: SystemCapability.MiscServices.Wallpaper

E
ester.zhou 已提交
136
**Parameters**
Z
zengyawen 已提交
137

E
ester.zhou 已提交
138
| Name| Type| Mandatory| Description|
E
ester.zhou 已提交
139
| -------- | -------- | -------- | -------- |
E
ester.zhou 已提交
140 141
| wallpaperType | [WallpaperType](#wallpapertype) | Yes| Wallpaper type.|
| callback | AsyncCallback&lt;number&gt; | Yes| Callback used to return the wallpaper ID. If the wallpaper of the specified type is configured, a number greater than or equal to **0** is returned. Otherwise, **-1** is returned. The value ranges from -1 to 2^31-1.|
E
ester.zhou 已提交
142 143 144

**Example**

E
ester.zhou 已提交
145 146 147 148 149 150 151 152 153
  ```js
  wallpaper.getId(wallpaper.WallpaperType.WALLPAPER_SYSTEM, (error, data) => {
      if (error) {
          console.error(`failed to getId because: ` + JSON.stringify(error));
          return;
      }
      console.log(`success to getId: ` + JSON.stringify(data));
  });
  ```
Z
zengyawen 已提交
154 155 156 157 158 159


## wallpaper.getId

getId(wallpaperType: WallpaperType): Promise&lt;number&gt;

E
ester.zhou 已提交
160
Obtains the ID of the wallpaper of the specified type. This API uses a promise to return the result.
Z
zengyawen 已提交
161

E
ester.zhou 已提交
162 163 164
> **NOTE**
> 
> This API is supported since API version 7 and deprecated since API version 9. You are advised to use [wallpaper.getIdSync<sup>9+</sup>](#wallpapergetidsync9) instead.
Z
zengyawen 已提交
165

E
ester.zhou 已提交
166
**System capability**: SystemCapability.MiscServices.Wallpaper
E
ester.zhou 已提交
167

E
ester.zhou 已提交
168
**Parameters**
Z
zengyawen 已提交
169

E
ester.zhou 已提交
170
| Name| Type| Mandatory| Description|
E
ester.zhou 已提交
171
| -------- | -------- | -------- | -------- |
E
ester.zhou 已提交
172
| wallpaperType | [WallpaperType](#wallpapertype) | Yes| Wallpaper type.|
Z
zengyawen 已提交
173

E
ester.zhou 已提交
174
**Return value**
Z
zengyawen 已提交
175

E
ester.zhou 已提交
176
| Type| Description|
E
ester.zhou 已提交
177
| -------- | -------- |
E
ester.zhou 已提交
178
| Promise&lt;number&gt; | Promise used to return the wallpaper ID. If this type of wallpaper is configured, a number greater than or equal to **0** is returned. Otherwise, **-1** is returned. The value ranges from -1 to 2^31-1.|
E
ester.zhou 已提交
179 180 181

**Example**

E
ester.zhou 已提交
182 183 184 185 186 187 188
  ```js
  wallpaper.getId(wallpaper.WallpaperType.WALLPAPER_SYSTEM).then((data) => {
      console.log(`success to getId: ` + JSON.stringify(data));
  }).catch((error) => {
      console.error(`failed to getId because: ` + JSON.stringify(error));
  });
  ```
Z
zengyawen 已提交
189 190


E
ester.zhou 已提交
191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217
## wallpaper.getIdSync<sup>9+</sup>

getIdSync(wallpaperType: WallpaperType): number

Obtains the ID of the wallpaper of the specified type. This API uses an asynchronous callback to return the result.

**System capability**: SystemCapability.MiscServices.Wallpaper

**Parameters**

| Name| Type| Mandatory| Description|
| -------- | -------- | -------- | -------- |
| wallpaperType | [WallpaperType](#wallpapertype) | Yes| Wallpaper type.|

**Return value**

| Type| Description|
| -------- | -------- |
| number | ID of the wallpaper. If this type of wallpaper is configured, a number greater than or equal to **0** is returned. Otherwise, **-1** is returned. The value ranges from -1 to 2^31-1.|

**Example**

  ```js
  var id = wallpaper.getIdSync(wallpaper.WallpaperType.WALLPAPER_SYSTEM);
  ```


Z
zengyawen 已提交
218 219 220 221
## wallpaper.getMinHeight

getMinHeight(callback: AsyncCallback&lt;number&gt;): void

E
ester.zhou 已提交
222
Obtains the minimum height of this wallpaper. This API uses an asynchronous callback to return the result.
Z
zengyawen 已提交
223

E
ester.zhou 已提交
224 225 226 227
> **NOTE**
> 
> This API is supported since API version 7 and deprecated since API version 9. You are advised to use [wallpaper.getMinHeightSync<sup>9+</sup>](#wallpapergetminheightsync9) instead.

Z
zengyawen 已提交
228 229
**System capability**: SystemCapability.MiscServices.Wallpaper

E
ester.zhou 已提交
230
**Parameters**
Z
zengyawen 已提交
231

E
ester.zhou 已提交
232
| Name| Type| Mandatory| Description|
E
ester.zhou 已提交
233
| -------- | -------- | -------- | -------- |
E
ester.zhou 已提交
234
| callback | AsyncCallback&lt;number&gt; | Yes| Callback used to return the minimum wallpaper height, in pixels. If the return value is **0**, no wallpaper is set. In this case, the default height should be used instead.|
E
ester.zhou 已提交
235 236 237

**Example**

E
ester.zhou 已提交
238 239 240 241 242 243 244 245 246
  ```js
  wallpaper.getMinHeight((error, data) => {
      if (error) {
          console.error(`failed to getMinHeight because: ` + JSON.stringify(error));
          return;
      }
      console.log(`success to getMinHeight: ` + JSON.stringify(data));
  });
  ```
Z
zengyawen 已提交
247 248 249 250 251 252


## wallpaper.getMinHeight

getMinHeight(): Promise&lt;number&gt;

E
ester.zhou 已提交
253
Obtains the minimum height of this wallpaper. This API uses a promise to return the result.
Z
zengyawen 已提交
254

E
ester.zhou 已提交
255 256 257
> **NOTE**
> 
> This API is supported since API version 7 and deprecated since API version 9. You are advised to use [wallpaper.getMinHeightSync<sup>9+</sup>](#wallpapergetminheightsync9) instead.
Z
zengyawen 已提交
258

E
ester.zhou 已提交
259
**System capability**: SystemCapability.MiscServices.Wallpaper
E
ester.zhou 已提交
260

E
ester.zhou 已提交
261
**Return value**
Z
zengyawen 已提交
262

E
ester.zhou 已提交
263
| Type| Description|
E
ester.zhou 已提交
264
| -------- | -------- |
E
ester.zhou 已提交
265
| Promise&lt;number&gt; | Promise used to return the minimum wallpaper height, in pixels. If the return value is **0**, no wallpaper is set. In this case, the default height should be used instead.|
Z
zengyawen 已提交
266

E
ester.zhou 已提交
267 268
**Example**

E
ester.zhou 已提交
269 270 271 272 273 274 275
  ```js
  wallpaper.getMinHeight().then((data) => {
      console.log(`success to getMinHeight: ` + JSON.stringify(data));
  }).catch((error) => {
      console.error(`failed to getMinHeight because: ` + JSON.stringify(error));
  });
  ```
Z
zengyawen 已提交
276 277


E
ester.zhou 已提交
278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298
## wallpaper.getMinHeightSync<sup>9+</sup>

getMinHeightSync(): number

Obtains the minimum height of this wallpaper. This API uses an asynchronous callback to return the result.

**System capability**: SystemCapability.MiscServices.Wallpaper

**Return value**

| Type| Description|
| -------- | -------- |
| number | Promise used to return the minimum wallpaper height, in pixels. If the return value is **0**, no wallpaper is set. In this case, the default height should be used instead.|

**Example**

  ```js
  var minHeight = wallpaper.getMinHeightSync();
  ```


Z
zengyawen 已提交
299 300 301 302
## wallpaper.getMinWidth

getMinWidth(callback: AsyncCallback&lt;number&gt;): void

E
ester.zhou 已提交
303
Obtains the minimum width of this wallpaper. This API uses an asynchronous callback to return the result.
Z
zengyawen 已提交
304

E
ester.zhou 已提交
305 306 307
> **NOTE**
> 
> This API is supported since API version 7 and deprecated since API version 9. You are advised to use [wallpaper.getMinWidthSync<sup>9+</sup>](#wallpapergetminwidthsync9) instead.
Z
zengyawen 已提交
308

E
ester.zhou 已提交
309
**System capability**: SystemCapability.MiscServices.Wallpaper
E
ester.zhou 已提交
310

E
ester.zhou 已提交
311
**Parameters**
Z
zengyawen 已提交
312

E
ester.zhou 已提交
313
| Name| Type| Mandatory| Description|
E
ester.zhou 已提交
314
| -------- | -------- | -------- | -------- |
E
ester.zhou 已提交
315
| callback | AsyncCallback&lt;number&gt; | Yes| Callback used to return the minimum wallpaper width, in pixels. If the return value is **0**, no wallpaper is set. In this case, the default width should be used instead.|
Z
zengyawen 已提交
316

E
ester.zhou 已提交
317 318
**Example**

E
ester.zhou 已提交
319 320 321 322 323 324 325 326 327
  ```js
  wallpaper.getMinWidth((error, data) => {
      if (error) {
          console.error(`failed to getMinWidth because: ` + JSON.stringify(error));
          return;
      }
      console.log(`success to getMinWidth: ` + JSON.stringify(data));
  });
  ```
Z
zengyawen 已提交
328 329 330 331 332 333


## wallpaper.getMinWidth

getMinWidth(): Promise&lt;number&gt;

E
ester.zhou 已提交
334
Obtains the minimum width of this wallpaper. This API uses a promise to return the result.
Z
zengyawen 已提交
335

E
ester.zhou 已提交
336 337 338 339
> **NOTE**
> 
> This API is supported since API version 7 and deprecated since API version 9. You are advised to use [wallpaper.getMinWidthSync<sup>9+</sup>](#wallpapergetminwidthsync9) instead.

Z
zengyawen 已提交
340 341
**System capability**: SystemCapability.MiscServices.Wallpaper

E
ester.zhou 已提交
342
**Return value**
Z
zengyawen 已提交
343

E
ester.zhou 已提交
344
| Type| Description|
E
ester.zhou 已提交
345
| -------- | -------- |
E
ester.zhou 已提交
346
| Promise&lt;number&gt; | Promise used to return the minimum wallpaper width, in pixels. If the return value is **0**, no wallpaper is set. In this case, the default width should be used instead.|
E
ester.zhou 已提交
347 348 349

**Example**

E
ester.zhou 已提交
350 351 352 353 354 355 356
  ```js
  wallpaper.getMinWidth().then((data) => {
      console.log(`success to getMinWidth: ` + JSON.stringify(data));
  }).catch((error) => {
      console.error(`failed to getMinWidth because: ` + JSON.stringify(error));
  });
  ```
Z
zengyawen 已提交
357 358


E
ester.zhou 已提交
359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379
## wallpaper.getMinWidthSync<sup>9+</sup>

getMinWidthSync(): number

Obtains the minimum width of this wallpaper. This API uses an asynchronous callback to return the result.

**System capability**: SystemCapability.MiscServices.Wallpaper

**Return value**

| Type| Description|
| -------- | -------- |
| number | Promise used to return the minimum wallpaper width, in pixels. If the return value is **0**, no wallpaper is set. In this case, the default width should be used instead.|

**Example**

  ```js
  var minWidth = wallpaper.getMinWidthSync();
  ```


Z
zengyawen 已提交
380 381 382 383
## wallpaper.isChangePermitted

isChangePermitted(callback: AsyncCallback&lt;boolean&gt;): void

E
ester.zhou 已提交
384
Checks whether to allow the application to change the wallpaper for the current user. This API uses an asynchronous callback to return the result.
Z
zengyawen 已提交
385

E
ester.zhou 已提交
386 387 388 389
> **NOTE**
> 
> This API is supported since API version 7 and deprecated since API version 9. You are advised to use [wallpaper.isChangeAllowed<sup>9+</sup>](#wallpaperischangeallowed9) instead.

Z
zengyawen 已提交
390 391
**System capability**: SystemCapability.MiscServices.Wallpaper

E
ester.zhou 已提交
392
**Parameters**
Z
zengyawen 已提交
393

E
ester.zhou 已提交
394
| Name| Type| Mandatory| Description|
E
ester.zhou 已提交
395
| -------- | -------- | -------- | -------- |
E
ester.zhou 已提交
396
| callback | AsyncCallback&lt;boolean&gt; | Yes| Callback used to return whether to allow the application to change the wallpaper for the current user. The value **true** means that the operation is allowed, and **false** means the opposite.|
E
ester.zhou 已提交
397 398 399

**Example**

E
ester.zhou 已提交
400 401 402 403 404 405 406 407 408
  ```js
  wallpaper.isChangePermitted((error, data) => {
      if (error) {
          console.error(`failed to isChangePermitted because: ` + JSON.stringify(error));
          return;
      }
      console.log(`success to isChangePermitted: ` + JSON.stringify(data));
  });
  ```
Z
zengyawen 已提交
409 410 411 412 413 414


## wallpaper.isChangePermitted

isChangePermitted(): Promise&lt;boolean&gt;

E
ester.zhou 已提交
415
Checks whether to allow the application to change the wallpaper for the current user. This API uses a promise to return the result.
Z
zengyawen 已提交
416

E
ester.zhou 已提交
417 418 419 420
> **NOTE**
> 
> This API is supported since API version 7 and deprecated since API version 9. You are advised to use [wallpaper.isChangeAllowed<sup>9+</sup>](#wallpaperischangeallowed9) instead.

Z
zengyawen 已提交
421 422
**System capability**: SystemCapability.MiscServices.Wallpaper

E
ester.zhou 已提交
423
**Return value**
Z
zengyawen 已提交
424

E
ester.zhou 已提交
425
| Type| Description|
E
ester.zhou 已提交
426
| -------- | -------- |
E
ester.zhou 已提交
427
| Promise&lt;boolean&gt; | Promise used to return whether to allow the application to change the wallpaper for the current user. The value **true** means that the operation is allowed, and **false** means the opposite.|
E
ester.zhou 已提交
428 429 430

**Example**

E
ester.zhou 已提交
431 432 433 434 435 436 437
  ```js
  wallpaper.isChangePermitted().then((data) => {
      console.log(`success to isChangePermitted: ` + JSON.stringify(data));
  }).catch((error) => {
      console.error(`failed to isChangePermitted because: ` + JSON.stringify(error));
  });
  ```
Z
zengyawen 已提交
438 439


E
ester.zhou 已提交
440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460
## wallpaper.isChangeAllowed<sup>9+</sup>

isChangeAllowed(): boolean

Checks whether to allow the application to change the wallpaper for the current user. This API uses an asynchronous callback to return the result.

**System capability**: SystemCapability.MiscServices.Wallpaper

**Return value**

| Type| Description|
| -------- | -------- |
| boolean | Whether to allow the application to change the wallpaper for the current user. The value **true** means that the operation is allowed, and **false** means the opposite.|

**Example**

  ```js
  var isChangeAllowed = wallpaper.isChangeAllowed();
  ```


Z
zengyawen 已提交
461 462 463 464
## wallpaper.isOperationAllowed

isOperationAllowed(callback: AsyncCallback&lt;boolean&gt;): void

E
ester.zhou 已提交
465
Checks whether the user is allowed to set wallpapers. This API uses an asynchronous callback to return the result.
Z
zengyawen 已提交
466

E
ester.zhou 已提交
467 468 469 470
> **NOTE**
> 
> This API is supported since API version 7 and deprecated since API version 9. You are advised to use [wallpaper.isUserChangeAllowed<sup>9+</sup>](#wallpaperisuserchangeallowed9) instead.

Z
zengyawen 已提交
471 472
**System capability**: SystemCapability.MiscServices.Wallpaper

E
ester.zhou 已提交
473
**Parameters**
Z
zengyawen 已提交
474

E
ester.zhou 已提交
475
| Name| Type| Mandatory| Description|
E
ester.zhou 已提交
476
| -------- | -------- | -------- | -------- |
E
ester.zhou 已提交
477
| callback | AsyncCallback&lt;boolean&gt; | Yes| Callback used to return whether the user is allowed to set wallpapers. The value **true** means that the operation is allowed, and **false** means the opposite.|
E
ester.zhou 已提交
478 479 480

**Example**

E
ester.zhou 已提交
481 482 483 484 485 486 487 488 489
  ```js
  wallpaper.isOperationAllowed((error, data) => {
      if (error) {
          console.error(`failed to isOperationAllowed because: ` + JSON.stringify(error));
          return;
      }
      console.log(`success to isOperationAllowed: ` + JSON.stringify(data));
  });
  ```
Z
zengyawen 已提交
490 491 492 493 494 495


## wallpaper.isOperationAllowed

isOperationAllowed(): Promise&lt;boolean&gt;

E
ester.zhou 已提交
496
Checks whether the user is allowed to set wallpapers. This API uses a promise to return the result.
Z
zengyawen 已提交
497

E
ester.zhou 已提交
498 499 500 501
> **NOTE**
> 
> This API is supported since API version 7 and deprecated since API version 9. You are advised to use [wallpaper.isUserChangeAllowed<sup>9+</sup>](#wallpaperisuserchangeallowed9) instead.

Z
zengyawen 已提交
502 503
**System capability**: SystemCapability.MiscServices.Wallpaper

E
ester.zhou 已提交
504
**Return value**
Z
zengyawen 已提交
505

E
ester.zhou 已提交
506
| Type| Description|
E
ester.zhou 已提交
507
| -------- | -------- |
E
ester.zhou 已提交
508
| Promise&lt;boolean&gt; | Promise used to return whether the user is allowed to set wallpapers. The value **true** means that the operation is allowed, and **false** means the opposite.|
E
ester.zhou 已提交
509 510 511

**Example**

E
ester.zhou 已提交
512 513 514 515 516 517 518
  ```js
  wallpaper.isOperationAllowed().then((data) => {
      console.log(`success to isOperationAllowed: ` + JSON.stringify(data));
  }).catch((error) => {
      console.error(`failed to isOperationAllowed because: ` + JSON.stringify(error));
  });
  ```
Z
zengyawen 已提交
519 520


E
ester.zhou 已提交
521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541
## wallpaper.isUserChangeAllowed<sup>9+</sup>

isUserChangeAllowed(): boolean

Checks whether the user is allowed to set wallpapers. This API uses an asynchronous callback to return the result.

**System capability**: SystemCapability.MiscServices.Wallpaper

**Return value**

| Type| Description|
| -------- | -------- |
| boolean | Whether the user is allowed to set wallpapers. The value **true** means that the operation is allowed, and **false** means the opposite.|

**Example**

  ```js
  var isUserChangeAllowed = wallpaper.isUserChangeAllowed();
  ```


Z
zengyawen 已提交
542 543 544 545
## wallpaper.reset

reset(wallpaperType: WallpaperType, callback: AsyncCallback&lt;void&gt;): void

E
ester.zhou 已提交
546
Resets the wallpaper of the specified type to the default wallpaper. This API uses an asynchronous callback to return the result.
Z
zengyawen 已提交
547

E
ester.zhou 已提交
548 549 550 551
> **NOTE**
> 
> This API is supported since API version 7 and deprecated since API version 9. You are advised to use [wallpaper.restore<sup>9+</sup>](#wallpaperrestore9) instead.

E
ester.zhou 已提交
552
**Required permissions**: ohos.permission.SET_WALLPAPER
Z
zengyawen 已提交
553 554 555

**System capability**: SystemCapability.MiscServices.Wallpaper

E
ester.zhou 已提交
556
**Parameters**
Z
zengyawen 已提交
557

E
ester.zhou 已提交
558
| Name| Type| Mandatory| Description|
E
ester.zhou 已提交
559
| -------- | -------- | -------- | -------- |
E
ester.zhou 已提交
560 561
| wallpaperType | [WallpaperType](#wallpapertype) | Yes| Wallpaper type.|
| callback | AsyncCallback&lt;void&gt; | Yes| Callback used to return the result. If the operation is successful, the result of removal is returned. Otherwise, error information is returned.|
E
ester.zhou 已提交
562 563 564

**Example**

E
ester.zhou 已提交
565 566 567 568 569 570 571 572 573
  ```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.`);
  });
  ```
Z
zengyawen 已提交
574 575 576 577 578 579


## wallpaper.reset

reset(wallpaperType: WallpaperType): Promise&lt;void&gt;

E
ester.zhou 已提交
580
Resets the wallpaper of the specified type to the default wallpaper. This API uses a promise to return the result.
Z
zengyawen 已提交
581

E
ester.zhou 已提交
582 583 584 585
> **NOTE**
>
> This API is supported since API version 7 and deprecated since API version 9. You are advised to use [wallpaper.restore<sup>9+</sup>](#wallpaperrestore9) instead.

E
ester.zhou 已提交
586
**Required permissions**: ohos.permission.SET_WALLPAPER
Z
zengyawen 已提交
587 588 589

**System capability**: SystemCapability.MiscServices.Wallpaper

E
ester.zhou 已提交
590
**Parameters**
Z
zengyawen 已提交
591

E
ester.zhou 已提交
592
| Name| Type| Mandatory| Description|
E
ester.zhou 已提交
593
| -------- | -------- | -------- | -------- |
E
ester.zhou 已提交
594
| wallpaperType | [WallpaperType](#wallpapertype) | Yes| Wallpaper type.|
Z
zengyawen 已提交
595

E
ester.zhou 已提交
596 597
**Return value**

E
ester.zhou 已提交
598
| Type| Description|
E
ester.zhou 已提交
599
| -------- | -------- |
E
ester.zhou 已提交
600
| Promise&lt;void&gt; | Promise used to return the result. If the operation is successful, the result is returned. Otherwise, error information is returned.|
E
ester.zhou 已提交
601 602 603

**Example**

E
ester.zhou 已提交
604 605 606 607 608 609 610
  ```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));
  });
  ```
Z
zengyawen 已提交
611 612


E
ester.zhou 已提交
613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675
## wallpaper.restore<sup>9+</sup>

restore(wallpaperType: WallpaperType, callback: AsyncCallback&lt;void&gt;): void

Resets the wallpaper of the specified type to the default wallpaper. This API uses an asynchronous callback to return the result.

**Required permissions**: ohos.permission.SET_WALLPAPER

**System capability**: SystemCapability.MiscServices.Wallpaper

**Parameters**

| Name| Type| Mandatory| Description|
| -------- | -------- | -------- | -------- |
| wallpaperType | [WallpaperType](#wallpapertype) | Yes| Wallpaper type.|
| callback | AsyncCallback&lt;void&gt; | Yes| Callback used to return the result. If the operation is successful, the result of removal is returned. Otherwise, error information is returned.|

**Example**

  ```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.restore<sup>9+</sup>

restore(wallpaperType: WallpaperType): Promise&lt;void&gt;

Resets the wallpaper of the specified type to the default wallpaper. This API uses an asynchronous callback to return the result.

**Required permissions**: ohos.permission.SET_WALLPAPER

**System capability**: SystemCapability.MiscServices.Wallpaper

**Parameters**

| Name| Type| Mandatory| Description|
| -------- | -------- | -------- | -------- |
| wallpaperType | [WallpaperType](#wallpapertype) | Yes| Wallpaper type.|

**Return value**

| Type| Description|
| -------- | -------- |
| Promise&lt;void&gt; | Promise used to return the result. If the operation is successful, the result is returned. Otherwise, error information is returned.|

**Example**

  ```js
  wallpaper.restore(wallpaper.WallpaperType.WALLPAPER_SYSTEM).then((data) => {
      console.log(`success to restore.`);
  }).catch((error) => {
      console.error(`failed to restore because: ` + JSON.stringify(error));
  });
  ```


Z
zengyawen 已提交
676 677 678 679
## wallpaper.setWallpaper

setWallpaper(source: string | image.PixelMap, wallpaperType: WallpaperType, callback: AsyncCallback&lt;void&gt;): void

E
ester.zhou 已提交
680
Sets a specified source as the wallpaper of a specified type. This API uses an asynchronous callback to return the result.
Z
zengyawen 已提交
681

E
ester.zhou 已提交
682 683 684 685
> **NOTE**
> 
> This API is supported since API version 7 and deprecated since API version 9. You are advised to use [wallpaper.setImage<sup>9+</sup>](#wallpapersetimage9) instead.

E
ester.zhou 已提交
686
**Required permissions**: ohos.permission.SET_WALLPAPER
Z
zengyawen 已提交
687 688 689

**System capability**: SystemCapability.MiscServices.Wallpaper

E
ester.zhou 已提交
690 691
**Parameters**

E
ester.zhou 已提交
692
| Name| Type| Mandatory| Description|
E
ester.zhou 已提交
693
| -------- | -------- | -------- | -------- |
E
ester.zhou 已提交
694
| source | string \|[image.PixelMap](js-apis-image.md#pixelmap7) | Yes| URI of a JPEG or PNG file, or bitmap of a PNG file.|
E
ester.zhou 已提交
695 696
| wallpaperType | [WallpaperType](#wallpapertype) | Yes| Wallpaper type.|
| callback | AsyncCallback&lt;void&gt; | Yes| Callback used to return the result. If the operation is successful, the setting result is returned. Otherwise, error information is returned.|
E
ester.zhou 已提交
697 698 699

**Example**

E
ester.zhou 已提交
700 701
  ```js
  //The source type is string.
E
ester.zhou 已提交
702 703 704 705 706 707 708 709 710
  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.`);
  });
  
E
ester.zhou 已提交
711
  // The source type is image.PixelMap.
E
ester.zhou 已提交
712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730
  import image from '@ohos.multimedia.image';
  let imageSource = image.createImageSource("file://" + wallpaperPath);
  let opts = {
      "desiredSize": {
          "height": 3648,
          "width": 2736
      }
  };
  imageSource.createPixelMap(opts).then((pixelMap) => {      
      wallpaper.setWallpaper(pixelMap, wallpaper.WallpaperType.WALLPAPER_SYSTEM, (error, data) => {    
          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));
  });
E
ester.zhou 已提交
731
  ```
Z
zengyawen 已提交
732 733 734 735 736 737


## wallpaper.setWallpaper

setWallpaper(source: string | image.PixelMap, wallpaperType: WallpaperType): Promise&lt;void&gt;

E
ester.zhou 已提交
738
Sets a specified source as the wallpaper of a specified type. This API uses a promise to return the result.
Z
zengyawen 已提交
739

E
ester.zhou 已提交
740 741 742 743
> **NOTE**
> 
> This API is supported since API version 7 and deprecated since API version 9. You are advised to use [wallpaper.setImage<sup>9+</sup>](#wallpapersetimage9) instead.

E
ester.zhou 已提交
744
**Required permissions**: ohos.permission.SET_WALLPAPER
Z
zengyawen 已提交
745 746 747

**System capability**: SystemCapability.MiscServices.Wallpaper

E
ester.zhou 已提交
748
**Parameters**
Z
zengyawen 已提交
749

E
ester.zhou 已提交
750
| Name| Type| Mandatory| Description|
E
ester.zhou 已提交
751
| -------- | -------- | -------- | -------- |
E
ester.zhou 已提交
752
| source | string \|[image.PixelMap](js-apis-image.md#pixelmap7) | Yes| URI of a JPEG or PNG file, or bitmap of a PNG file.|
E
ester.zhou 已提交
753
| wallpaperType | [WallpaperType](#wallpapertype) | Yes| Wallpaper type.|
Z
zengyawen 已提交
754

E
ester.zhou 已提交
755 756
**Return value**

E
ester.zhou 已提交
757
| Type| Description|
E
ester.zhou 已提交
758
| -------- | -------- |
E
ester.zhou 已提交
759
| Promise&lt;void&gt; | Promise used to return the result. If the operation is successful, the setting result is returned. Otherwise, error information is returned.|
E
ester.zhou 已提交
760 761 762

**Example**

E
ester.zhou 已提交
763
  ```js
E
ester.zhou 已提交
764
  //The source type is string.
E
ester.zhou 已提交
765 766 767 768 769 770 771
  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));
  });
  
E
ester.zhou 已提交
772
  // The source type is image.PixelMap.
E
ester.zhou 已提交
773 774 775 776 777 778 779 780 781 782 783 784 785 786 787 788 789
  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));
  });
E
ester.zhou 已提交
790
  ```
Z
zengyawen 已提交
791

E
ester.zhou 已提交
792 793 794 795 796 797 798 799 800 801 802 803 804 805 806 807 808 809 810 811 812 813 814 815 816 817 818 819 820 821 822 823 824 825 826 827 828 829 830 831 832 833 834 835 836 837 838 839 840 841 842 843 844 845 846 847 848 849 850 851 852 853 854 855 856 857 858 859 860 861 862 863 864 865 866 867 868 869 870 871 872 873 874 875 876 877 878 879 880 881 882 883 884 885 886 887 888 889 890 891 892 893 894 895 896 897 898 899 900 901

## wallpaper.setImage<sup>9+</sup>

setImage(source: string | image.PixelMap, wallpaperType: WallpaperType, callback: AsyncCallback&lt;void&gt;): void

Sets a specified source as the wallpaper of a specified type. This API uses an asynchronous callback to return the result.

**Required permissions**: ohos.permission.SET_WALLPAPER

**System capability**: SystemCapability.MiscServices.Wallpaper

**Parameters**

| Name| Type| Mandatory| Description|
| -------- | -------- | -------- | -------- |
| source | string \|[image.PixelMap](js-apis-image.md#pixelmap7) | Yes| URI of a JPEG or PNG file, or bitmap of a PNG file.|
| wallpaperType | [WallpaperType](#wallpapertype) | Yes| Wallpaper type.|
| callback | AsyncCallback&lt;void&gt; | Yes| Callback used to return the result. If the operation is successful, the setting result is returned. Otherwise, error information is returned.|

**Example**

  ```js
  //The source type is 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.`);
  });
  
  // The source type is 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, data) => {    
          if (error) {       
              console.error(`failed to setImage because: ` + JSON.stringify(error));
              return;
          }    
          console.log(`success to setImage.`);
      });
  }).catch((error) => {       
      console.error(`failed to createPixelMap because: ` + JSON.stringify(error));
  });
  ```


## wallpaper.setImage<sup>9+</sup>

setImage(source: string | image.PixelMap, wallpaperType: WallpaperType): Promise&lt;void&gt;

Sets a specified source as the wallpaper of a specified type. This API uses an asynchronous callback to return the result.

**Required permissions**: ohos.permission.SET_WALLPAPER

**System capability**: SystemCapability.MiscServices.Wallpaper

**Parameters**

| Name| Type| Mandatory| Description|
| -------- | -------- | -------- | -------- |
| source | string \|[image.PixelMap](js-apis-image.md#pixelmap7) | Yes| URI of a JPEG or PNG file, or bitmap of a PNG file.|
| wallpaperType | [WallpaperType](#wallpapertype) | Yes| Wallpaper type.|

**Return value**

| Type| Description|
| -------- | -------- |
| Promise&lt;void&gt; | Promise used to return the result. If the operation is successful, the setting result is returned. Otherwise, error information is returned.|

**Example**

  ```js
  //The source type is 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));
  });
  
  // The source type is 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((data) => {
          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));
  });
  ```


Z
zengyawen 已提交
902 903 904 905
## wallpaper.getFile<sup>8+</sup>

getFile(wallpaperType: WallpaperType, callback: AsyncCallback&lt;number&gt;): void

E
ester.zhou 已提交
906
Obtains the wallpaper of the specified type. This API uses an asynchronous callback to return the result.
Z
zengyawen 已提交
907

E
ester.zhou 已提交
908 909 910 911
> **NOTE**
> 
> This API is supported since API version 8 and deprecated since API version 9. You are advised to use [wallpaper.getFileSync<sup>9+</sup>](#wallpapergetfilesync9) instead.

912
**Required permissions**: ohos.permission.GET_WALLPAPER
Z
zengyawen 已提交
913 914 915

**System capability**: SystemCapability.MiscServices.Wallpaper

E
ester.zhou 已提交
916
**Parameters**
Z
zengyawen 已提交
917

E
ester.zhou 已提交
918
| Name| Type| Mandatory| Description|
E
ester.zhou 已提交
919
| -------- | -------- | -------- | -------- |
E
ester.zhou 已提交
920 921
| wallpaperType | [WallpaperType](#wallpapertype) | Yes| Wallpaper type.|
| callback | AsyncCallback&lt;number&gt; | Yes| Callback used to return the result. If the operation is successful, the file descriptor ID to the wallpaper is returned. Otherwise, error information is returned.|
E
ester.zhou 已提交
922 923 924

**Example**

E
ester.zhou 已提交
925 926 927 928 929 930 931 932 933
  ```js
  wallpaper.getFile(wallpaper.WallpaperType.WALLPAPER_SYSTEM, (error, data) => {
      if (error) {
          console.error(`failed to getFile because: ` + JSON.stringify(error));
          return;
      }
      console.log(`success to getFile: ` + JSON.stringify(data));
  });
  ```
Z
zengyawen 已提交
934 935 936 937 938

## wallpaper.getFile<sup>8+</sup>

getFile(wallpaperType: WallpaperType): Promise&lt;number&gt;

E
ester.zhou 已提交
939
Obtains the wallpaper of the specified type. This API uses a promise to return the result.
Z
zengyawen 已提交
940

E
ester.zhou 已提交
941 942 943 944
> **NOTE**
>
> This API is supported since API version 8 and deprecated since API version 9. You are advised to use [wallpaper.getFileSync<sup>9+</sup>](#wallpapergetfilesync9) instead.

945
**Required permissions**: ohos.permission.GET_WALLPAPER
Z
zengyawen 已提交
946 947 948

**System capability**: SystemCapability.MiscServices.Wallpaper

E
ester.zhou 已提交
949
**Parameters**
Z
zengyawen 已提交
950

E
ester.zhou 已提交
951
| Name| Type| Mandatory| Description|
E
ester.zhou 已提交
952
| -------- | -------- | -------- | -------- |
E
ester.zhou 已提交
953
| wallpaperType | [WallpaperType](#wallpapertype) | Yes| Wallpaper type.|
Z
zengyawen 已提交
954

E
ester.zhou 已提交
955 956
**Return value**

E
ester.zhou 已提交
957
| Type| Description|
E
ester.zhou 已提交
958
| -------- | -------- |
E
ester.zhou 已提交
959
| Promise&lt;number&gt; | Promise used to return the result. If the operation is successful, the file descriptor ID to the wallpaper is returned. Otherwise, error information is returned.|
E
ester.zhou 已提交
960 961 962

**Example**

E
ester.zhou 已提交
963 964 965 966 967 968 969 970 971
  ```js
  wallpaper.getFile(wallpaper.WallpaperType.WALLPAPER_SYSTEM).then((data) => {
      console.log(`success to getFile: ` + JSON.stringify(data));
  }).catch((error) => {
      console.error(`failed to getFile because: ` + JSON.stringify(error));
  });
  ```


E
ester.zhou 已提交
972 973 974 975 976 977 978 979 980 981 982 983 984 985 986 987 988 989 990 991 992 993 994 995 996 997 998 999 1000
## wallpaper.getFileSync<sup>9+</sup>

getFileSync(wallpaperType: WallpaperType): number;

Obtains the wallpaper of the specified type. This API uses an asynchronous callback to return the result.

**Required permissions**: ohos.permission.GET_WALLPAPER

**System capability**: SystemCapability.MiscServices.Wallpaper

**Parameters**

| Name| Type| Mandatory| Description|
| -------- | -------- | -------- | -------- |
| wallpaperType | [WallpaperType](#wallpapertype) | Yes| Wallpaper type.|

**Return value**

| Type| Description|
| -------- | -------- |
| number | Promise used to return the result. If the operation is successful, the file descriptor ID to the wallpaper is returned. Otherwise, error information is returned.|

**Example**

  ```js
  var file = wallpaper.getFileSync(wallpaper.WallpaperType.WALLPAPER_SYSTEM);
  ```


E
ester.zhou 已提交
1001 1002 1003 1004
## wallpaper.getPixelMap

getPixelMap(wallpaperType: WallpaperType, callback: AsyncCallback&lt;image.PixelMap&gt;): void;

E
ester.zhou 已提交
1005
Obtains the pixel map for the wallpaper of the specified type. This API uses an asynchronous callback to return the result.
E
ester.zhou 已提交
1006

E
ester.zhou 已提交
1007 1008 1009 1010
> **NOTE**
>
> This API is supported since API version 7 and deprecated since API version 9. You are advised to use [wallpaper.getImage<sup>9+</sup>](#wallpapergetimage9) instead.

1011
**Required permissions**: ohos.permission.GET_WALLPAPER
E
ester.zhou 已提交
1012 1013 1014

**System capability**: SystemCapability.MiscServices.Wallpaper

E
ester.zhou 已提交
1015 1016
**System API**: This is a system API and cannot be called by third-party applications.

E
ester.zhou 已提交
1017 1018 1019 1020 1021
**Parameters**

| Name| Type| Mandatory| Description|
| -------- | -------- | -------- | -------- |
| wallpaperType | [WallpaperType](#wallpapertype) | Yes| Wallpaper type.|
E
ester.zhou 已提交
1022
| callback | AsyncCallback&lt;image.PixelMap&gt; | Yes| Callback used to return the result. Returns the pixel map size of the wallpaper if the operation is successful; returns an error message otherwise.|
E
ester.zhou 已提交
1023 1024 1025 1026 1027 1028 1029 1030 1031 1032 1033 1034 1035 1036 1037

**Example**

  ```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

getPixelMap(wallpaperType: WallpaperType): Promise&lt;image.PixelMap&gt;

E
ester.zhou 已提交
1038
Obtains the pixel map for the wallpaper of the specified type. This API uses a promise to return the result.
E
ester.zhou 已提交
1039

E
ester.zhou 已提交
1040 1041 1042 1043
> **NOTE**
>
> This API is supported since API version 7 and deprecated since API version 9. You are advised to use [wallpaper.getImage<sup>9+</sup>](#wallpapergetimage9) instead.

1044
**Required permissions**: ohos.permission.GET_WALLPAPER
E
ester.zhou 已提交
1045 1046 1047

**System capability**: SystemCapability.MiscServices.Wallpaper

E
ester.zhou 已提交
1048 1049
**System API**: This is a system API and cannot be called by third-party applications.

E
ester.zhou 已提交
1050 1051 1052 1053 1054 1055 1056 1057 1058 1059
**Parameters**

| Name| Type| Mandatory| Description|
| -------- | -------- | -------- | -------- |
| wallpaperType | [WallpaperType](#wallpapertype) | Yes| Wallpaper type.|

**Return value**

| Type| Description|
| -------- | -------- |
E
ester.zhou 已提交
1060
| Promise&lt;image.PixelMap&gt; | Promise used to return the result. Returns the pixel map size of the wallpaper if the operation is successful; returns an error message otherwise.|
E
ester.zhou 已提交
1061 1062 1063 1064

**Example**

  ```js
E
ester.zhou 已提交
1065
  wallpaper.getPixelMap(wallpaper.WallpaperType.WALLPAPER_SYSTEM).then((data) => {
E
ester.zhou 已提交
1066 1067 1068 1069 1070 1071 1072
      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));
  });
  ```
Z
zengyawen 已提交
1073 1074


E
ester.zhou 已提交
1075 1076 1077 1078 1079 1080 1081 1082 1083 1084 1085 1086 1087 1088 1089 1090 1091 1092 1093 1094 1095 1096 1097 1098 1099 1100 1101 1102 1103 1104 1105 1106 1107 1108 1109 1110 1111 1112 1113 1114 1115 1116 1117 1118 1119 1120 1121 1122 1123 1124 1125 1126 1127 1128 1129 1130 1131 1132 1133 1134 1135 1136 1137 1138 1139 1140 1141
## wallpaper.getImage<sup>9+</sup>

getImage(wallpaperType: WallpaperType, callback: AsyncCallback&lt;image.PixelMap&gt;): void;

Obtains the pixel map for the wallpaper of the specified type. This API uses an asynchronous callback to return the result.

**Required permissions**: ohos.permission.GET_WALLPAPER

**System capability**: SystemCapability.MiscServices.Wallpaper

**System API**: This is a system API and cannot be called by third-party applications.

**Parameters**

| Name| Type| Mandatory| Description|
| -------- | -------- | -------- | -------- |
| wallpaperType | [WallpaperType](#wallpapertype) | Yes| Wallpaper type.|
| callback | AsyncCallback&lt;[image.PixelMap](js-apis-image.md#pixelmap7)&gt; | Yes| Callback used to return the result. Returns the pixel map size of the wallpaper if the operation is successful; returns an error message otherwise.|

**Example**

  ```js
  wallpaper.getImage(wallpaper.WallpaperType.WALLPAPER_SYSTEM, function (err, data) {
      console.info('wallpaperXTS ===> testgetImageCallbackSystem err : ' + JSON.stringify(err));
      console.info('wallpaperXTS ===> testgetImageCallbackSystem data : ' + JSON.stringify(data));
  });
  ```


## wallpaper.getImage<sup>9+</sup>

getImage(wallpaperType: WallpaperType): Promise&lt;image.PixelMap&gt;

Obtains the pixel map for the wallpaper of the specified type. This API uses an asynchronous callback to return the result.

**Required permissions**: ohos.permission.GET_WALLPAPER

**System capability**: SystemCapability.MiscServices.Wallpaper

**System API**: This is a system API and cannot be called by third-party applications.

**Parameters**

| Name| Type| Mandatory| Description|
| -------- | -------- | -------- | -------- |
| wallpaperType | [WallpaperType](#wallpapertype) | Yes| Wallpaper type.|

**Return value**

| Type| Description|
| -------- | -------- |
| Promise&lt;[image.PixelMap](js-apis-image.md#pixelmap7)&gt; | Promise used to return the result. Returns the pixel map size of the wallpaper if the operation is successful; returns an error message otherwise.|

**Example**

  ```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.on('colorChange')<sup>9+</sup>
Z
zengyawen 已提交
1142 1143 1144 1145 1146 1147 1148

on(type: 'colorChange', callback: (colors: Array&lt;RgbaColor&gt;, wallpaperType: WallpaperType) =&gt; void): void

Subscribes to the wallpaper color change event.

**System capability**: SystemCapability.MiscServices.Wallpaper

E
ester.zhou 已提交
1149
**Parameters**
Z
zengyawen 已提交
1150

E
ester.zhou 已提交
1151
| Name| Type| Mandatory| Description|
E
ester.zhou 已提交
1152
| -------- | -------- | -------- | -------- |
E
ester.zhou 已提交
1153 1154
| type | string | Yes| Type of the event to subscribe to. The value **'colorChange'** indicates subscribing to the wallpaper color change event.|
| callback | function | Yes| Callback triggered when the wallpaper color changes. The wallpaper type and main colors are returned.<br>- colors<br>Main color information of the wallpaper. For details, see [RgbaColor](#rgbacolor).<br>- wallpaperType<br>Wallpaper type.|
E
ester.zhou 已提交
1155 1156 1157

**Example**

E
ester.zhou 已提交
1158 1159 1160 1161 1162 1163
  ```js
  let listener = (colors, wallpaperType) => {
      console.log(`wallpaper color changed.`);
  };
  wallpaper.on('colorChange', listener);
  ```
Z
zengyawen 已提交
1164 1165


E
ester.zhou 已提交
1166
## wallpaper.off('colorChange')<sup>9+</sup>
Z
zengyawen 已提交
1167 1168 1169 1170 1171 1172 1173

off(type: 'colorChange', callback?: (colors: Array&lt;RgbaColor&gt;, wallpaperType: WallpaperType) =&gt; void): void

Unsubscribes from the wallpaper color change event.

**System capability**: SystemCapability.MiscServices.Wallpaper

E
ester.zhou 已提交
1174
**Parameters**
Z
zengyawen 已提交
1175

E
ester.zhou 已提交
1176
| Name| Type| Mandatory| Description|
E
ester.zhou 已提交
1177
| -------- | -------- | -------- | -------- |
E
ester.zhou 已提交
1178 1179
| type | string | Yes| Type of the event to unsubscribe from. The value **colorChange** indicates unsubscribing from the wallpaper color change event.|
| callback | function | No| Callback for the wallpaper color change event. If this parameter is not specified, all callbacks corresponding to the wallpaper color change event are invoked.<br>- colors<br>Main color information of the wallpaper. For details, see [RgbaColor](#rgbacolor).<br>- wallpaperType<br>Wallpaper type.|
E
ester.zhou 已提交
1180 1181 1182

**Example**

E
ester.zhou 已提交
1183 1184 1185 1186 1187
  ```js
  let listener = (colors, wallpaperType) => {
      console.log(`wallpaper color changed.`);
  };
  wallpaper.on('colorChange', listener);
E
ester.zhou 已提交
1188 1189 1190 1191
  // Unsubscribe from the listener.
  wallpaper.off('colorChange', listener);
  // Unsubscribe from all subscriptions of the colorChange type.
  wallpaper.off('colorChange');
E
ester.zhou 已提交
1192
  ```
Z
zengyawen 已提交
1193 1194 1195 1196 1197 1198


## RgbaColor

**System capability**: SystemCapability.MiscServices.Wallpaper

E
ester.zhou 已提交
1199
| Name| Type| Readable| Writable| Description|
Z
zengyawen 已提交
1200
| -------- | -------- | -------- | -------- | -------- |
E
ester.zhou 已提交
1201 1202 1203 1204
| red | number | Yes| Yes| Red color. The value ranges from 0 to 255.|
| green | number | Yes| Yes| Green color. The value ranges from 0 to 255.|
| blue | number | Yes| Yes| Blue color. The value ranges from 0 to 255.|
| alpha | number | Yes| Yes| Alpha value. The value ranges from 0 to 255.|