1# @ohos.wallpaper (Wallpaper) 2 3The **wallpaper** module is a system service module in OpenHarmony that provides the wallpaper management service. You can use the APIs of this module to show, set, and switch between wallpapers. 4 5> **NOTE** 6> 7> 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. 8 9 10## Modules to Import 11 12 13```js 14import wallpaper from '@ohos.wallpaper'; 15``` 16 17## WallpaperType<sup>7+</sup> 18 19Enumerates the wallpaper types. 20 21**System capability**: SystemCapability.MiscServices.Wallpaper 22 23| Name| Value|Description| 24| -------- | -------- |-------- | 25| WALLPAPER_SYSTEM | 0 |Home screen wallpaper.| 26| WALLPAPER_LOCKSCREEN | 1 |Lock screen wallpaper.| 27 28 29## RgbaColor<sup>(deprecated)</sup> 30 31Defines the RGBA color space for the wallpaper. 32 33> **NOTE** 34> 35> This API is supported since API version 7 and deprecated since API version 9. 36 37**System capability**: SystemCapability.MiscServices.Wallpaper 38 39| Name| Type| Readable| Writable| Description| 40| -------- | -------- | -------- | -------- | -------- | 41| red | number | Yes| Yes| Red color. The value ranges from 0 to 255.| 42| green | number | Yes| Yes| Green color. The value ranges from 0 to 255.| 43| blue | number | Yes| Yes| Blue color. The value ranges from 0 to 255.| 44| alpha | number | Yes| Yes| Alpha value. The value ranges from 0 to 255.| 45 46 47## wallpaper.getColorsSync<sup>9+</sup> 48 49getColorsSync(wallpaperType: WallpaperType): Array<RgbaColor> 50 51Obtains the main color information of the wallpaper of the specified type. 52 53**System capability**: SystemCapability.MiscServices.Wallpaper 54 55**System API**: This is a system API. 56 57**Parameters** 58 59| Name| Type| Mandatory| Description| 60| -------- | -------- | -------- | -------- | 61| wallpaperType | [WallpaperType](#wallpapertype7) | Yes| Wallpaper type.| 62 63**Return value** 64 65| Type| Description| 66| -------- | -------- | 67| Array<[RgbaColor](#rgbacolordeprecated)> | Promise used to return the main color information of the wallpaper.| 68 69**Example** 70 71```js 72try { 73 let colors = wallpaper.getColorsSync(wallpaper.WallpaperType.WALLPAPER_SYSTEM); 74 console.log(`success to getColorsSync: ${JSON.stringify(colors)}`); 75} catch (error) { 76 console.error(`failed to getColorsSync because: ${JSON.stringify(error)}`); 77} 78``` 79 80## wallpaper.getMinHeightSync<sup>9+</sup> 81 82getMinHeightSync(): number 83 84Obtains the minimum height of this wallpaper. 85 86**System capability**: SystemCapability.MiscServices.Wallpaper 87 88**System API**: This is a system API. 89 90**Return value** 91 92| Type| Description| 93| -------- | -------- | 94| 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.| 95 96**Example** 97 98```js 99let minHeight = wallpaper.getMinHeightSync(); 100``` 101 102## wallpaper.getMinWidthSync<sup>9+</sup> 103 104getMinWidthSync(): number 105 106Obtains the minimum width of this wallpaper. 107 108**System capability**: SystemCapability.MiscServices.Wallpaper 109 110**System API**: This is a system API. 111 112**Return value** 113 114| Type| Description| 115| -------- | -------- | 116| 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.| 117 118**Example** 119 120```js 121let minWidth = wallpaper.getMinWidthSync(); 122``` 123 124## wallpaper.restore<sup>9+</sup> 125 126restore(wallpaperType: WallpaperType, callback: AsyncCallback<void>): void 127 128Resets the wallpaper of the specified type to the default wallpaper. This API uses an asynchronous callback to return the result. 129 130**Required permissions**: ohos.permission.SET_WALLPAPER 131 132**System capability**: SystemCapability.MiscServices.Wallpaper 133 134**System API**: This is a system API. 135 136**Parameters** 137 138| Name| Type| Mandatory| Description| 139| -------- | -------- | -------- | -------- | 140| wallpaperType | [WallpaperType](#wallpapertype7) | Yes| Wallpaper type.| 141| callback | AsyncCallback<void> | Yes| Callback used to return the result. If the wallpaper is reset, **err** is **undefined**. Otherwise, **err** is an error object.| 142 143**Example** 144 145```js 146wallpaper.restore(wallpaper.WallpaperType.WALLPAPER_SYSTEM, (error) => { 147 if (error) { 148 console.error(`failed to restore because: ${JSON.stringify(error)}`); 149 return; 150 } 151 console.log(`success to restore.`); 152}); 153``` 154 155## wallpaper.restore<sup>9+</sup> 156 157restore(wallpaperType: WallpaperType): Promise<void> 158 159Resets the wallpaper of the specified type to the default wallpaper. This API uses a promise to return the result. 160 161**Required permissions**: ohos.permission.SET_WALLPAPER 162 163**System capability**: SystemCapability.MiscServices.Wallpaper 164 165**System API**: This is a system API. 166 167**Parameters** 168 169| Name| Type| Mandatory| Description| 170| -------- | -------- | -------- | -------- | 171| wallpaperType | [WallpaperType](#wallpapertype7) | Yes| Wallpaper type.| 172 173**Return value** 174 175| Type| Description| 176| -------- | -------- | 177| Promise<void> | Promise that returns no value.| 178 179**Example** 180 181```js 182wallpaper.restore(wallpaper.WallpaperType.WALLPAPER_SYSTEM).then(() => { 183 console.log(`success to restore.`); 184 }).catch((error) => { 185 console.error(`failed to restore because: ${JSON.stringify(error)}`); 186}); 187``` 188 189## wallpaper.setImage<sup>9+</sup> 190 191setImage(source: string | image.PixelMap, wallpaperType: WallpaperType, callback: AsyncCallback<void>): void 192 193Sets a specified source as the wallpaper of a specified type. This API uses an asynchronous callback to return the result. 194 195**Required permissions**: ohos.permission.SET_WALLPAPER 196 197**System capability**: SystemCapability.MiscServices.Wallpaper 198 199**System API**: This is a system API. 200 201**Parameters** 202 203| Name| Type| Mandatory| Description| 204| -------- | -------- | -------- | -------- | 205| source | string \| [image.PixelMap](js-apis-image.md#pixelmap7) | Yes| URI of a JPEG or PNG file, or pixel map of a PNG file.| 206| wallpaperType | [WallpaperType](#wallpapertype7) | Yes| Wallpaper type.| 207| callback | AsyncCallback<void> | Yes| Callback used to return the result. If the wallpaper is set, **err** is **undefined**. Otherwise, **err** is an error object.| 208 209**Example** 210 211```js 212// The source type is string. 213let wallpaperPath = "/data/data/ohos.acts.aafwk.plrdtest.form/files/Cup_ic.jpg"; 214wallpaper.setImage(wallpaperPath, wallpaper.WallpaperType.WALLPAPER_SYSTEM, (error) => { 215 if (error) { 216 console.error(`failed to setImage because: ${JSON.stringify(error)}`); 217 return; 218 } 219 console.log(`success to setImage.`); 220}); 221 222// The source type is image.PixelMap. 223import image from '@ohos.multimedia.image'; 224let imageSource = image.createImageSource("file://" + wallpaperPath); 225let opts = { 226 "desiredSize": { 227 "height": 3648, 228 "width": 2736 229 } 230}; 231imageSource.createPixelMap(opts).then((pixelMap) => { 232 wallpaper.setImage(pixelMap, wallpaper.WallpaperType.WALLPAPER_SYSTEM, (error) => { 233 if (error) { 234 console.error(`failed to setImage because: ${JSON.stringify(error)}`); 235 return; 236 } 237 console.log(`success to setImage.`); 238 }); 239}).catch((error) => { 240 console.error(`failed to createPixelMap because: ${JSON.stringify(error)}`); 241}); 242``` 243 244## wallpaper.setImage<sup>9+</sup> 245 246setImage(source: string | image.PixelMap, wallpaperType: WallpaperType): Promise<void> 247 248Sets a specified source as the wallpaper of a specified type. This API uses a promise to return the result. 249 250**Required permissions**: ohos.permission.SET_WALLPAPER 251 252**System capability**: SystemCapability.MiscServices.Wallpaper 253 254**System API**: This is a system API. 255 256**Parameters** 257 258| Name| Type| Mandatory| Description| 259| -------- | -------- | -------- | -------- | 260| source | string \| [image.PixelMap](js-apis-image.md#pixelmap7) | Yes| URI of a JPEG or PNG file, or pixel map of a PNG file.| 261| wallpaperType | [WallpaperType](#wallpapertype7) | Yes| Wallpaper type.| 262 263**Return value** 264 265| Type| Description| 266| -------- | -------- | 267| Promise<void> | Promise that returns no value.| 268 269**Example** 270 271```js 272// The source type is string. 273let wallpaperPath = "/data/data/ohos.acts.aafwk.plrdtest.form/files/Cup_ic.jpg"; 274wallpaper.setImage(wallpaperPath, wallpaper.WallpaperType.WALLPAPER_SYSTEM).then(() => { 275 console.log(`success to setImage.`); 276}).catch((error) => { 277 console.error(`failed to setImage because: ${JSON.stringify(error)}`); 278}); 279 280// The source type is image.PixelMap. 281import image from '@ohos.multimedia.image'; 282let imageSource = image.createImageSource("file://" + wallpaperPath); 283let opts = { 284 "desiredSize": { 285 "height": 3648, 286 "width": 2736 287 } 288}; 289imageSource.createPixelMap(opts).then((pixelMap) => { 290 wallpaper.setImage(pixelMap, wallpaper.WallpaperType.WALLPAPER_SYSTEM).then(() => { 291 console.log(`success to setImage.`); 292 }).catch((error) => { 293 console.error(`failed to setImage because: ${JSON.stringify(error)}`); 294 }); 295}).catch((error) => { 296 console.error(`failed to createPixelMap because: ${JSON.stringify(error)}`); 297}); 298``` 299 300## wallpaper.getImage<sup>9+</sup> 301 302getImage(wallpaperType: WallpaperType, callback: AsyncCallback<image.PixelMap>): void; 303 304Obtains the pixel map for the wallpaper of the specified type. This API uses an asynchronous callback to return the result. 305 306**Required permissions**: ohos.permission.GET_WALLPAPER 307 308**System capability**: SystemCapability.MiscServices.Wallpaper 309 310**System API**: This is a system API. 311 312**Parameters** 313 314| Name| Type| Mandatory| Description| 315| -------- | -------- | -------- | -------- | 316| wallpaperType | [WallpaperType](#wallpapertype7) | Yes| Wallpaper type.| 317| callback | AsyncCallback<[image.PixelMap](js-apis-image.md#pixelmap7)> | Yes| Callback used to return the result. If the operation is successful, the pixel map of the wallpaper is returned. Otherwise, error information is returned.| 318 319**Example** 320 321```js 322wallpaper.getImage(wallpaper.WallpaperType.WALLPAPER_SYSTEM, function (error, data) { 323 if (error) { 324 console.error(`failed to getImage because: ${JSON.stringify(error)}`); 325 return; 326 } 327 console.log(`success to getImage: ${JSON.stringify(data)}`); 328}); 329``` 330 331 332## wallpaper.getImage<sup>9+</sup> 333 334getImage(wallpaperType: WallpaperType): Promise<image.PixelMap> 335 336Obtains the pixel map for the wallpaper of the specified type. This API uses a promise to return the result. 337 338**Required permissions**: ohos.permission.GET_WALLPAPER 339 340**System capability**: SystemCapability.MiscServices.Wallpaper 341 342**System API**: This is a system API. 343 344**Parameters** 345 346| Name| Type| Mandatory| Description| 347| -------- | -------- | -------- | -------- | 348| wallpaperType | [WallpaperType](#wallpapertype7) | Yes| Wallpaper type.| 349 350**Return value** 351 352| Type| Description| 353| -------- | -------- | 354| Promise<[image.PixelMap](js-apis-image.md#pixelmap7)> | Promise used to return the result. If the operation is successful, the pixel map of the wallpaper is returned. Otherwise, error information is returned.| 355 356**Example** 357 358```js 359wallpaper.getImage(wallpaper.WallpaperType.WALLPAPER_SYSTEM).then((data) => { 360 console.log(`success to getImage: ${JSON.stringify(data)}`); 361 }).catch((error) => { 362 console.error(`failed to getImage because: ${JSON.stringify(error)}`); 363}); 364``` 365 366## wallpaper.on('colorChange')<sup>(deprecated)</sup> 367 368on(type: 'colorChange', callback: (colors: Array<RgbaColor>, wallpaperType: WallpaperType) => void): void 369 370Subscribes to the wallpaper color change event. 371 372> **NOTE** 373> 374> This API is supported since API version 7 and deprecated since API version 9. 375 376**System capability**: SystemCapability.MiscServices.Wallpaper 377 378**Parameters** 379 380| Name| Type| Mandatory| Description| 381| -------- | -------- | -------- | -------- | 382| type | string | Yes| Type of the event to subscribe to. The value **'colorChange'** indicates subscribing to the wallpaper color change event.| 383| 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](#rgbacolordeprecated).<br>- wallpaperType<br> Wallpaper type.| 384 385**Example** 386 387```js 388try { 389 let listener = (colors, wallpaperType) => { 390 console.log(`wallpaper color changed.`); 391 }; 392 wallpaper.on('colorChange', listener); 393} catch (error) { 394 console.error(`failed to on because: ${JSON.stringify(error)}`); 395} 396``` 397 398## wallpaper.off('colorChange')<sup>(deprecated)</sup> 399 400off(type: 'colorChange', callback?: (colors: Array<RgbaColor>, wallpaperType: WallpaperType) => void): void 401 402Unsubscribes from the wallpaper color change event. 403 404> **NOTE** 405> 406> This API is supported since API version 7 and deprecated since API version 9. 407 408**System capability**: SystemCapability.MiscServices.Wallpaper 409 410**Parameters** 411 412| Name| Type| Mandatory| Description| 413| -------- | -------- | -------- | -------- | 414| type | string | Yes| Type of the event to unsubscribe from. The value **'colorChange'** indicates unsubscribing from the wallpaper color change event.| 415| callback | function | No| Callback for the wallpaper color change event. If this parameter is not set, this API unsubscribes from all callbacks corresponding to **type**.<br>- colors<br> Main color information of the wallpaper. For details, see [RgbaColor](#rgbacolordeprecated).<br>- wallpaperType<br> Wallpaper type.| 416 417**Example** 418 419```js 420let listener = (colors, wallpaperType) => { 421 console.log(`wallpaper color changed.`); 422}; 423try { 424 wallpaper.on('colorChange', listener); 425} catch (error) { 426 console.error(`failed to on because: ${JSON.stringify(error)}`); 427} 428 429try { 430 // Unsubscribe from the listener. 431 wallpaper.off('colorChange', listener); 432} catch (error) { 433 console.error(`failed to off because: ${JSON.stringify(error)}`); 434} 435 436try { 437 // Unsubscribe from all subscriptions of the colorChange type. 438 wallpaper.off('colorChange'); 439} catch (error) { 440 console.error(`failed to off because: ${JSON.stringify(error)}`); 441} 442``` 443 444## wallpaper.getColors<sup>(deprecated)</sup> 445 446getColors(wallpaperType: WallpaperType, callback: AsyncCallback<Array<RgbaColor>>): void 447 448Obtains the main color information of the wallpaper of the specified type. This API uses an asynchronous callback to return the result. 449 450> **NOTE** 451> 452> This API is supported since API version 7 and deprecated since API version 9. 453 454**System capability**: SystemCapability.MiscServices.Wallpaper 455 456**Parameters** 457 458| Name| Type| Mandatory| Description| 459| -------- | -------- | -------- | -------- | 460| wallpaperType | [WallpaperType](#wallpapertype7) | Yes| Wallpaper type.| 461| callback | AsyncCallback<Array<[RgbaColor](#rgbacolordeprecated)>> | Yes| Callback used to return the main color information of the wallpaper.| 462 463**Example** 464 465```js 466wallpaper.getColors(wallpaper.WallpaperType.WALLPAPER_SYSTEM, (error, data) => { 467 if (error) { 468 console.error(`failed to getColors because: ${JSON.stringify(error)}`); 469 return; 470 } 471 console.log(`success to getColors: ${JSON.stringify(data)}`); 472}); 473``` 474 475## wallpaper.getColors<sup>(deprecated)</sup> 476 477getColors(wallpaperType: WallpaperType): Promise<Array<RgbaColor>> 478 479Obtains the main color information of the wallpaper of the specified type. This API uses a promise to return the result. 480 481> **NOTE** 482> 483> This API is supported since API version 7 and deprecated since API version 9. 484 485**System capability**: SystemCapability.MiscServices.Wallpaper 486 487**Parameters** 488 489| Name| Type| Mandatory| Description| 490| -------- | -------- | -------- | -------- | 491| wallpaperType | [WallpaperType](#wallpapertype7) | Yes| Wallpaper type.| 492 493**Return value** 494 495| Type| Description| 496| -------- | -------- | 497| Promise<Array<[RgbaColor](#rgbacolordeprecated)>> | Promise used to return the main color information of the wallpaper.| 498 499**Example** 500 501```js 502wallpaper.getColors(wallpaper.WallpaperType.WALLPAPER_SYSTEM).then((data) => { 503 console.log(`success to getColors: ${JSON.stringify(data)}`); 504 }).catch((error) => { 505 console.error(`failed to getColors because: ${JSON.stringify(error)}`); 506}); 507``` 508 509## wallpaper.getId<sup>(deprecated)</sup> 510 511getId(wallpaperType: WallpaperType, callback: AsyncCallback<number>): void 512 513Obtains the ID of the wallpaper of the specified type. This API uses an asynchronous callback to return the result. 514 515> **NOTE** 516> 517> This API is supported since API version 7 and deprecated since API version 9. 518 519**System capability**: SystemCapability.MiscServices.Wallpaper 520 521**Parameters** 522 523| Name| Type| Mandatory| Description| 524| -------- | -------- | -------- | -------- | 525| wallpaperType | [WallpaperType](#wallpapertype7) | Yes| Wallpaper type.| 526| callback | AsyncCallback<number> | 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).| 527 528**Example** 529 530```js 531wallpaper.getId(wallpaper.WallpaperType.WALLPAPER_SYSTEM, (error, data) => { 532 if (error) { 533 console.error(`failed to getId because: ${JSON.stringify(error)}`); 534 return; 535 } 536 console.log(`success to getId: ${JSON.stringify(data)}`); 537}); 538``` 539 540## wallpaper.getId<sup>(deprecated)</sup> 541 542getId(wallpaperType: WallpaperType): Promise<number> 543 544Obtains the ID of the wallpaper of the specified type. This API uses a promise to return the result. 545 546> **NOTE** 547> 548> This API is supported since API version 7 and deprecated since API version 9. 549 550**System capability**: SystemCapability.MiscServices.Wallpaper 551 552**Parameters** 553 554| Name| Type| Mandatory| Description| 555| -------- | -------- | -------- | -------- | 556| wallpaperType | [WallpaperType](#wallpapertype7) | Yes| Wallpaper type.| 557 558**Return value** 559 560| Type| Description| 561| -------- | -------- | 562| Promise<number> | 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).| 563 564**Example** 565 566```js 567wallpaper.getId(wallpaper.WallpaperType.WALLPAPER_SYSTEM).then((data) => { 568 console.log(`success to getId: ${JSON.stringify(data)}`); 569 }).catch((error) => { 570 console.error(`failed to getId because: ${JSON.stringify(error)}`); 571}); 572``` 573 574## wallpaper.getMinHeight<sup>(deprecated)</sup> 575 576getMinHeight(callback: AsyncCallback<number>): void 577 578Obtains the minimum height of this wallpaper. This API uses an asynchronous callback to return the result. 579 580> **NOTE** 581> 582> This API is supported since API version 7 and deprecated since API version 9. 583 584**System capability**: SystemCapability.MiscServices.Wallpaper 585 586**Parameters** 587 588| Name| Type| Mandatory| Description| 589| -------- | -------- | -------- | -------- | 590| callback | AsyncCallback<number> | 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.| 591 592**Example** 593 594```js 595wallpaper.getMinHeight((error, data) => { 596 if (error) { 597 console.error(`failed to getMinHeight because: ${JSON.stringify(error)}`); 598 return; 599 } 600 console.log(`success to getMinHeight: ${JSON.stringify(data)}`); 601}); 602``` 603 604## wallpaper.getMinHeight<sup>(deprecated)</sup> 605 606getMinHeight(): Promise<number> 607 608Obtains the minimum height of this wallpaper. This API uses a promise to return the result. 609 610> **NOTE** 611> 612> This API is supported since API version 7 and deprecated since API version 9. 613 614**System capability**: SystemCapability.MiscServices.Wallpaper 615 616**Return value** 617 618| Type| Description| 619| -------- | -------- | 620| Promise<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.| 621 622**Example** 623 624```js 625wallpaper.getMinHeight().then((data) => { 626 console.log(`success to getMinHeight: ${JSON.stringify(data)}`); 627}).catch((error) => { 628 console.error(`failed to getMinHeight because: ${JSON.stringify(error)}`); 629}); 630``` 631 632## wallpaper.getMinWidth<sup>(deprecated)</sup> 633 634getMinWidth(callback: AsyncCallback<number>): void 635 636Obtains the minimum width of this wallpaper. This API uses an asynchronous callback to return the result. 637 638> **NOTE** 639> 640> This API is supported since API version 7 and deprecated since API version 9. 641 642**System capability**: SystemCapability.MiscServices.Wallpaper 643 644**Parameters** 645 646| Name| Type| Mandatory| Description| 647| -------- | -------- | -------- | -------- | 648| callback | AsyncCallback<number> | 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.| 649 650**Example** 651 652```js 653wallpaper.getMinWidth((error, data) => { 654 if (error) { 655 console.error(`failed to getMinWidth because: ${JSON.stringify(error)}`); 656 return; 657 } 658 console.log(`success to getMinWidth: ${JSON.stringify(data)}`); 659}); 660``` 661 662## wallpaper.getMinWidth<sup>(deprecated)</sup> 663 664getMinWidth(): Promise<number> 665 666Obtains the minimum width of this wallpaper. This API uses a promise to return the result. 667 668> **NOTE** 669> 670> This API is supported since API version 7 and deprecated since API version 9. 671 672**System capability**: SystemCapability.MiscServices.Wallpaper 673 674**Return value** 675 676| Type| Description| 677| -------- | -------- | 678| Promise<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.| 679 680**Example** 681 682```js 683wallpaper.getMinWidth().then((data) => { 684 console.log(`success to getMinWidth: ${JSON.stringify(data)}`); 685 }).catch((error) => { 686 console.error(`failed to getMinWidth because: ${JSON.stringify(error)}`); 687}); 688``` 689 690## wallpaper.isChangePermitted<sup>(deprecated)</sup> 691 692isChangePermitted(callback: AsyncCallback<boolean>): void 693 694Checks whether to allow the application to change the wallpaper for the current user. This API uses an asynchronous callback to return the result. 695 696> **NOTE** 697> 698> This API is supported since API version 7 and deprecated since API version 9. 699 700**System capability**: SystemCapability.MiscServices.Wallpaper 701 702**Parameters** 703 704| Name| Type| Mandatory| Description| 705| -------- | -------- | -------- | -------- | 706| callback | AsyncCallback<boolean> | 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.| 707 708**Example** 709 710```js 711wallpaper.isChangePermitted((error, data) => { 712 if (error) { 713 console.error(`failed to isChangePermitted because: ${JSON.stringify(error)}`); 714 return; 715 } 716 console.log(`success to isChangePermitted: ${JSON.stringify(data)}`); 717}); 718``` 719 720## wallpaper.isChangePermitted<sup>(deprecated)</sup> 721 722isChangePermitted(): Promise<boolean> 723 724Checks whether to allow the application to change the wallpaper for the current user. This API uses a promise to return the result. 725 726> **NOTE** 727> 728> This API is supported since API version 7 and deprecated since API version 9. 729 730**System capability**: SystemCapability.MiscServices.Wallpaper 731 732**Return value** 733 734| Type| Description| 735| -------- | -------- | 736| Promise<boolean> | 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.| 737 738**Example** 739 740```js 741wallpaper.isChangePermitted().then((data) => { 742 console.log(`success to isChangePermitted: ${JSON.stringify(data)}`); 743}).catch((error) => { 744 console.error(`failed to isChangePermitted because: ${JSON.stringify(error)}`); 745}); 746``` 747 748## wallpaper.isOperationAllowed<sup>(deprecated)</sup> 749 750isOperationAllowed(callback: AsyncCallback<boolean>): void 751 752Checks whether the user is allowed to set wallpapers. This API uses an asynchronous callback to return the result. 753 754> **NOTE** 755> 756> This API is supported since API version 7 and deprecated since API version 9. 757 758**System capability**: SystemCapability.MiscServices.Wallpaper 759 760**Parameters** 761 762| Name| Type| Mandatory| Description| 763| -------- | -------- | -------- | -------- | 764| callback | AsyncCallback<boolean> | 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.| 765 766**Example** 767 768```js 769wallpaper.isOperationAllowed((error, data) => { 770 if (error) { 771 console.error(`failed to isOperationAllowed because: ${JSON.stringify(error)}`); 772 return; 773 } 774 console.log(`success to isOperationAllowed: ${JSON.stringify(data)}`); 775}); 776``` 777 778## wallpaper.isOperationAllowed<sup>(deprecated)</sup> 779 780isOperationAllowed(): Promise<boolean> 781 782Checks whether the user is allowed to set wallpapers. This API uses a promise to return the result. 783 784> **NOTE** 785> 786> This API is supported since API version 7 and deprecated since API version 9. 787 788**System capability**: SystemCapability.MiscServices.Wallpaper 789 790**Return value** 791 792| Type| Description| 793| -------- | -------- | 794| Promise<boolean> | 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.| 795 796**Example** 797 798```js 799wallpaper.isOperationAllowed().then((data) => { 800 console.log(`success to isOperationAllowed: ${JSON.stringify(data)}`); 801 }).catch((error) => { 802 console.error(`failed to isOperationAllowed because: ${JSON.stringify(error)}`); 803}); 804``` 805 806## wallpaper.reset<sup>(deprecated)</sup> 807 808reset(wallpaperType: WallpaperType, callback: AsyncCallback<void>): void 809 810Resets the wallpaper of the specified type to the default wallpaper. This API uses an asynchronous callback to return the result. 811 812> **NOTE** 813> 814> This API is supported since API version 7 and deprecated since API version 9. 815 816**Required permissions**: ohos.permission.SET_WALLPAPER 817 818**System capability**: SystemCapability.MiscServices.Wallpaper 819 820**Parameters** 821 822| Name| Type| Mandatory| Description| 823| -------- | -------- | -------- | -------- | 824| wallpaperType | [WallpaperType](#wallpapertype7) | Yes| Wallpaper type.| 825| callback | AsyncCallback<void> | Yes| Callback used to return the result. If the wallpaper is reset, **err** is **undefined**. Otherwise, **err** is an error object.| 826 827**Example** 828 829```js 830wallpaper.reset(wallpaper.WallpaperType.WALLPAPER_SYSTEM, (error) => { 831 if (error) { 832 console.error(`failed to reset because: ${JSON.stringify(error)}`); 833 return; 834 } 835 console.log(`success to reset.`); 836}); 837``` 838 839## wallpaper.reset<sup>(deprecated)</sup> 840 841reset(wallpaperType: WallpaperType): Promise<void> 842 843Resets the wallpaper of the specified type to the default wallpaper. This API uses a promise to return the result. 844 845> **NOTE** 846> 847> This API is supported since API version 7 and deprecated since API version 9. 848 849**Required permissions**: ohos.permission.SET_WALLPAPER 850 851**System capability**: SystemCapability.MiscServices.Wallpaper 852 853**Parameters** 854 855| Name| Type| Mandatory| Description| 856| -------- | -------- | -------- | -------- | 857| wallpaperType | [WallpaperType](#wallpapertype7) | Yes| Wallpaper type.| 858 859**Return value** 860 861| Type| Description| 862| -------- | -------- | 863| Promise<void> | Promise that returns no value.| 864 865**Example** 866 867```js 868wallpaper.reset(wallpaper.WallpaperType.WALLPAPER_SYSTEM).then(() => { 869 console.log(`success to reset.`); 870}).catch((error) => { 871 console.error(`failed to reset because: ${JSON.stringify(error)}`); 872}); 873``` 874 875## wallpaper.setWallpaper<sup>(deprecated)</sup> 876 877setWallpaper(source: string | image.PixelMap, wallpaperType: WallpaperType, callback: AsyncCallback<void>): void 878 879Sets a specified source as the wallpaper of a specified type. This API uses an asynchronous callback to return the result. 880 881> **NOTE** 882> 883> This API is supported since API version 7 and deprecated since API version 9. 884 885**Required permissions**: ohos.permission.SET_WALLPAPER 886 887**System capability**: SystemCapability.MiscServices.Wallpaper 888 889**Parameters** 890 891| Name| Type| Mandatory| Description| 892| -------- | -------- | -------- | -------- | 893| source | string \| [image.PixelMap](js-apis-image.md#pixelmap7) | Yes| URI of a JPEG or PNG file, or pixel map of a PNG file.| 894| wallpaperType | [WallpaperType](#wallpapertype7) | Yes| Wallpaper type.| 895| callback | AsyncCallback<void> | Yes| Callback used to return the result. If the wallpaper is set, **err** is **undefined**. Otherwise, **err** is an error object.| 896 897**Example** 898 899```js 900// The source type is string. 901let wallpaperPath = "/data/data/ohos.acts.aafwk.plrdtest.form/files/Cup_ic.jpg"; 902wallpaper.setWallpaper(wallpaperPath, wallpaper.WallpaperType.WALLPAPER_SYSTEM, (error) => { 903 if (error) { 904 console.error(`failed to setWallpaper because: ${JSON.stringify(error)}`); 905 return; 906 } 907 console.log(`success to setWallpaper.`); 908}); 909 910// The source type is image.PixelMap. 911import image from '@ohos.multimedia.image'; 912let imageSource = image.createImageSource("file://" + wallpaperPath); 913let opts = { 914 "desiredSize": { 915 "height": 3648, 916 "width": 2736 917 } 918}; 919imageSource.createPixelMap(opts).then((pixelMap) => { 920 wallpaper.setWallpaper(pixelMap, wallpaper.WallpaperType.WALLPAPER_SYSTEM, (error) => { 921 if (error) { 922 console.error(`failed to setWallpaper because: ${JSON.stringify(error)}`); 923 return; 924 } 925 console.log(`success to setWallpaper.`); 926 }); 927}).catch((error) => { 928 console.error(`failed to createPixelMap because: ${JSON.stringify(error)}`); 929}); 930``` 931 932## wallpaper.setWallpaper<sup>(deprecated)</sup> 933 934setWallpaper(source: string | image.PixelMap, wallpaperType: WallpaperType): Promise<void> 935 936Sets a specified source as the wallpaper of a specified type. This API uses a promise to return the result. 937 938> **NOTE** 939> 940> This API is supported since API version 7 and deprecated since API version 9. 941 942**Required permissions**: ohos.permission.SET_WALLPAPER 943 944**System capability**: SystemCapability.MiscServices.Wallpaper 945 946**Parameters** 947 948| Name| Type| Mandatory| Description| 949| -------- | -------- | -------- | -------- | 950| source | string \| [image.PixelMap](js-apis-image.md#pixelmap7) | Yes| URI of a JPEG or PNG file, or pixel map of a PNG file.| 951| wallpaperType | [WallpaperType](#wallpapertype7) | Yes| Wallpaper type.| 952 953**Return value** 954 955| Type| Description| 956| -------- | -------- | 957| Promise<void> | Promise that returns no value.| 958 959**Example** 960 961```js 962// The source type is string. 963let wallpaperPath = "/data/data/ohos.acts.aafwk.plrdtest.form/files/Cup_ic.jpg"; 964wallpaper.setWallpaper(wallpaperPath, wallpaper.WallpaperType.WALLPAPER_SYSTEM).then(() => { 965 console.log(`success to setWallpaper.`); 966 }).catch((error) => { 967 console.error(`failed to setWallpaper because: ${JSON.stringify(error)}`); 968}); 969 970// The source type is image.PixelMap. 971import image from '@ohos.multimedia.image'; 972let imageSource = image.createImageSource("file://" + wallpaperPath); 973let opts = { 974 "desiredSize": { 975 "height": 3648, 976 "width": 2736 977 } 978}; 979imageSource.createPixelMap(opts).then((pixelMap) => { 980 wallpaper.setWallpaper(pixelMap, wallpaper.WallpaperType.WALLPAPER_SYSTEM).then(() => { 981 console.log(`success to setWallpaper.`); 982 }).catch((error) => { 983 console.error(`failed to setWallpaper because: ${JSON.stringify(error)}`); 984 }); 985 }).catch((error) => { 986 console.error(`failed to createPixelMap because: ${JSON.stringify(error)}`); 987}); 988``` 989 990 991## wallpaper.getFile<sup>(deprecated)</sup> 992 993getFile(wallpaperType: WallpaperType, callback: AsyncCallback<number>): void 994 995Obtains the wallpaper of the specified type. This API uses an asynchronous callback to return the result. 996 997> **NOTE** 998> 999> This API is supported since API version 8 and deprecated since API version 9. 1000 1001**Required permissions**: ohos.permission.GET_WALLPAPER 1002 1003**System capability**: SystemCapability.MiscServices.Wallpaper 1004 1005**Parameters** 1006 1007| Name| Type| Mandatory| Description| 1008| -------- | -------- | -------- | -------- | 1009| wallpaperType | [WallpaperType](#wallpapertype7) | Yes| Wallpaper type.| 1010| callback | AsyncCallback<number> | 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.| 1011 1012**Example** 1013 1014```js 1015wallpaper.getFile(wallpaper.WallpaperType.WALLPAPER_SYSTEM, (error, data) => { 1016 if (error) { 1017 console.error(`failed to getFile because: ${JSON.stringify(error)}`); 1018 return; 1019 } 1020 console.log(`success to getFile: ${JSON.stringify(data)}`); 1021}); 1022``` 1023 1024## wallpaper.getFile<sup>(deprecated)</sup> 1025 1026getFile(wallpaperType: WallpaperType): Promise<number> 1027 1028Obtains the wallpaper of the specified type. This API uses a promise to return the result. 1029 1030> **NOTE** 1031> 1032> This API is supported since API version 8 and deprecated since API version 9. 1033 1034**Required permissions**: ohos.permission.GET_WALLPAPER 1035 1036**System capability**: SystemCapability.MiscServices.Wallpaper 1037 1038**Parameters** 1039 1040| Name| Type| Mandatory| Description| 1041| -------- | -------- | -------- | -------- | 1042| wallpaperType | [WallpaperType](#wallpapertype7) | Yes| Wallpaper type.| 1043 1044**Return value** 1045 1046| Type| Description| 1047| -------- | -------- | 1048| Promise<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.| 1049 1050**Example** 1051 1052```js 1053wallpaper.getFile(wallpaper.WallpaperType.WALLPAPER_SYSTEM).then((data) => { 1054 console.log(`success to getFile: ${JSON.stringify(data)}`); 1055 }).catch((error) => { 1056 console.error(`failed to getFile because: ${JSON.stringify(error)}`); 1057}); 1058``` 1059 1060## wallpaper.getPixelMap<sup>(deprecated)</sup> 1061 1062getPixelMap(wallpaperType: WallpaperType, callback: AsyncCallback<image.PixelMap>): void; 1063 1064Obtains the pixel map for the wallpaper of the specified type. This API uses an asynchronous callback to return the result. 1065 1066> **NOTE** 1067> 1068> This API is supported since API version 7 and deprecated since API version 9. 1069 1070**Required permissions**: ohos.permission.GET_WALLPAPER 1071 1072**System capability**: SystemCapability.MiscServices.Wallpaper 1073 1074**System API**: This is a system API. 1075 1076**Parameters** 1077 1078| Name| Type| Mandatory| Description| 1079| -------- | -------- | -------- | -------- | 1080| wallpaperType | [WallpaperType](#wallpapertype7) | Yes| Wallpaper type.| 1081| callback | AsyncCallback<image.PixelMap> | Yes| Callback used to return the result. If the operation is successful, the pixel map of the wallpaper is returned. Otherwise, error information is returned.| 1082 1083**Example** 1084 1085```js 1086wallpaper.getPixelMap(wallpaper.WallpaperType.WALLPAPER_SYSTEM, function (error, data) { 1087 if (error) { 1088 console.error(`failed to getPixelMap because: ${JSON.stringify(error)}`); 1089 return; 1090 } 1091 console.log(`success to getPixelMap : ${JSON.stringify(data)}`); 1092 }); 1093``` 1094 1095## wallpaper.getPixelMap<sup>(deprecated)</sup> 1096 1097getPixelMap(wallpaperType: WallpaperType): Promise<image.PixelMap> 1098 1099Obtains the pixel map for the wallpaper of the specified type. This API uses a promise to return the result. 1100 1101> **NOTE** 1102> 1103> This API is supported since API version 7 and deprecated since API version 9. 1104 1105**Required permissions**: ohos.permission.GET_WALLPAPER 1106 1107**System capability**: SystemCapability.MiscServices.Wallpaper 1108 1109**System API**: This is a system API. 1110 1111**Parameters** 1112 1113| Name| Type| Mandatory| Description| 1114| -------- | -------- | -------- | -------- | 1115| wallpaperType | [WallpaperType](#wallpapertype7) | Yes| Wallpaper type.| 1116 1117**Return value** 1118 1119| Type| Description| 1120| -------- | -------- | 1121| Promise<image.PixelMap> | Promise used to return the result. If the operation is successful, the pixel map of the wallpaper is returned. Otherwise, error information is returned.| 1122 1123**Example** 1124 1125```js 1126wallpaper.getPixelMap(wallpaper.WallpaperType.WALLPAPER_SYSTEM).then((data) => { 1127 console.log(`success to getPixelMap : ${JSON.stringify(data)}`); 1128 }).catch((error) => { 1129 console.error(`failed to getPixelMap because: ${JSON.stringify(error)}`); 1130}); 1131``` 1132