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```ts 14import wallpaper from '@ohos.wallpaper'; 15``` 16## WallpaperResourceType<sup>10+</sup> 17 18Enumerates the types of wallpaper resources. 19 20**System capability**: SystemCapability.MiscServices.Wallpaper 21 22**System API**: This is a system API. 23 24| Name| Value|Description| 25| -------- | -------- |-------- | 26| DEFAULT | 0 |Default type (image resource).| 27| PICTURE | 1 |Image resource.| 28| VIDEO | 2 |Video resource.| 29| PACKAGE | 3 |Package resource.| 30 31 32## WallpaperType<sup>7+</sup> 33 34Enumerates the wallpaper types. 35 36**System capability**: SystemCapability.MiscServices.Wallpaper 37 38| Name| Value|Description| 39| -------- | -------- |-------- | 40| WALLPAPER_SYSTEM | 0 |Home screen wallpaper.| 41| WALLPAPER_LOCKSCREEN | 1 |Lock screen wallpaper.| 42 43 44## RgbaColor<sup>(deprecated)</sup> 45 46Defines the RGBA color space for the wallpaper. 47 48> **NOTE** 49> 50> This API is supported since API version 7 and deprecated since API version 9. 51 52**System capability**: SystemCapability.MiscServices.Wallpaper 53 54| Name| Type| Readable| Writable| Description| 55| -------- | -------- | -------- | -------- | -------- | 56| red | number | Yes| Yes| Red color. The value ranges from 0 to 255.| 57| green | number | Yes| Yes| Green color. The value ranges from 0 to 255.| 58| blue | number | Yes| Yes| Blue color. The value ranges from 0 to 255.| 59| alpha | number | Yes| Yes| Alpha value. The value ranges from 0 to 255.| 60 61 62## wallpaper.setVideo<sup>10+</sup> 63 64setVideo(source: string, wallpaperType: WallpaperType, callback: AsyncCallback<void>): void 65 66Sets a video resource as the home screen wallpaper or lock screen wallpaper. This API uses an asynchronous callback to return the result. 67 68**Required permissions**: ohos.permission.SET_WALLPAPER 69 70**System capability**: SystemCapability.MiscServices.Wallpaper 71 72**System API**: This is a system API. 73 74**Parameters** 75 76| Name| Type| Mandatory| Description| 77| -------- | -------- | -------- | -------- | 78| source | string | Yes| URI of an MP4 file.| 79| wallpaperType | [WallpaperType](#wallpapertype) | Yes| Wallpaper type.| 80| callback | AsyncCallback<void> | Yes| Callback used to return the result. If the wallpaper is set, **err** is **undefined**. Otherwise, **err** is an error object.| 81 82**Example** 83 84```ts 85import { BusinessError } from '@ohos.base'; 86 87let wallpaperPath = "/data/storage/el2/base/haps/entry/files/test.mp4"; 88try { 89 wallpaper.setVideo(wallpaperPath, wallpaper.WallpaperType.WALLPAPER_SYSTEM, (error: BusinessError) => { 90 if (error) { 91 console.error(`failed to setVideo because: ${JSON.stringify(error)}`); 92 return; 93 } 94 console.log(`success to setVideo.`); 95 }); 96} catch (error) { 97 console.error(`failed to setVideo because: ${JSON.stringify(error)}`); 98} 99``` 100 101## wallpaper.setVideo<sup>10+</sup> 102 103setVideo(source: string, wallpaperType: WallpaperType): Promise<void> 104 105Sets a video resource as the home screen wallpaper or lock screen wallpaper. This API uses a promise to return the result. 106 107**Required permissions**: ohos.permission.SET_WALLPAPER 108 109**System capability**: SystemCapability.MiscServices.Wallpaper 110 111**System API**: This is a system API. 112 113**Parameters** 114 115| Name| Type| Mandatory| Description| 116| -------- | -------- | -------- | -------- | 117| source | string | Yes| URI of an MP4 file.| 118| wallpaperType | [WallpaperType](#wallpapertype) | Yes| Wallpaper type.| 119 120**Return value** 121 122| Type| Description| 123| -------- | -------- | 124| Promise<void> | Promise that returns no value.| 125 126**Example** 127 128```ts 129import { BusinessError } from '@ohos.base'; 130 131let wallpaperPath = "/data/storage/el2/base/haps/entry/files/test.mp4"; 132try { 133 wallpaper.setVideo(wallpaperPath, wallpaper.WallpaperType.WALLPAPER_SYSTEM).then(() => { 134 console.log(`success to setVideo.`); 135 }).catch((error: BusinessError) => { 136 console.error(`failed to setVideo because: ${JSON.stringify(error)}`); 137 }); 138} catch (error) { 139 console.error(`failed to setVideo because: ${JSON.stringify(error)}`); 140} 141``` 142 143## wallpaper.setCustomWallpaper<sup>10+</sup> 144 145setCustomWallpaper(source: string, wallpaperType: WallpaperType, callback: AsyncCallback<void>): void 146 147Sets the content from a specified URI as the wallpaper. This API works only when com.ohos.sceneboard is set. This API uses an asynchronous callback to return the result. 148 149**Required permissions**: ohos.permission.SET_WALLPAPER 150 151**System capability**: SystemCapability.MiscServices.Wallpaper 152 153**System API**: This is a system API. 154 155**Parameters** 156 157| Name| Type| Mandatory| Description| 158| -------- | -------- | -------- | -------- | 159| source | string | Yes| URI of the custom wallpaper.| 160| wallpaperType | [WallpaperType](#wallpapertype) | Yes| Wallpaper type.| 161| callback | AsyncCallback<void> | Yes| Callback used to return the result. If the wallpaper is set, **err** is **undefined**. Otherwise, **err** is an error object.| 162 163**Example** 164 165```ts 166import { BusinessError } from '@ohos.base'; 167 168let wallpaperPath = "/data/storage/el2/base/haps/entry/files/test.zip"; 169try { 170 wallpaper.setCustomWallpaper(wallpaperPath, wallpaper.WallpaperType.WALLPAPER_SYSTEM, (error: BusinessError) => { 171 if (error) { 172 console.error(`failed to setCustomWallpaper because: ${JSON.stringify(error)}`); 173 return; 174 } 175 console.log(`success to setCustomWallpaper.`); 176 }); 177} catch (error) { 178 console.error(`failed to setCustomWallpaper because: ${JSON.stringify(error)}`); 179} 180 181``` 182 183## wallpaper.setCustomWallpaper<sup>10+</sup> 184 185setCustomWallpaper(source: string, wallpaperType: WallpaperType): Promise<void> 186 187Sets the content from a specified URI as the wallpaper. This API works only when com.ohos.sceneboard is set. This API uses a promise to return the result. 188 189**Required permissions**: ohos.permission.SET_WALLPAPER 190 191**System capability**: SystemCapability.MiscServices.Wallpaper 192 193**System API**: This is a system API. 194 195**Parameters** 196 197| Name| Type| Mandatory| Description| 198| -------- | -------- | -------- | -------- | 199| source | string | Yes| URI of the custom wallpaper.| 200| wallpaperType | [WallpaperType](#wallpapertype) | Yes| Wallpaper type.| 201 202**Return value** 203 204| Type| Description| 205| -------- | -------- | 206| Promise<void> | Promise that returns no value.| 207 208**Example** 209 210```ts 211import { BusinessError } from '@ohos.base'; 212 213let wallpaperPath = "/data/storage/el2/base/haps/entry/files/test.zip"; 214try { 215 wallpaper.setCustomWallpaper(wallpaperPath, wallpaper.WallpaperType.WALLPAPER_SYSTEM).then(() => { 216 console.log(`success to setCustomWallpaper.`); 217 }).catch((error: BusinessError) => { 218 console.error(`failed to setCustomWallpaper because: ${JSON.stringify(error)}`); 219 }); 220} catch (error) { 221 console.error(`failed to setCustomWallpaper because: ${JSON.stringify(error)}`); 222} 223``` 224 225## wallpaper.on('wallpaperChange')<sup>10+</sup> 226 227on(type: 'wallpaperChange', callback: (wallpaperType: WallpaperType, resourceType: WallpaperResourceType, uri?: string) => void): void 228 229Subscribes to wallpaper change events. 230 231**System capability**: SystemCapability.MiscServices.Wallpaper 232 233**System API**: This is a system API. 234 235**Parameters** 236 237| Name| Type| Mandatory| Description| 238| -------- | -------- | -------- | -------- | 239| type | string | Yes| Event type. The value is fixed at **'wallpaperChange'**.| 240| callback | function | Yes| Callback used to return the wallpaper type and wallpaper resource type.<br>- **wallpaperType**: wallpaper type.<br>- **resourceType**: wallpaper resource type.<br>- **uri**: URI of the wallpaper resource.| 241 242**Example** 243 244```ts 245try { 246 let listener = (wallpaperType: wallpaper.WallpaperType, resourceType: wallpaper.WallpaperResourceType): void => { 247 console.log(`wallpaper color changed.`); 248 }; 249 wallpaper.on('wallpaperChange', listener); 250} catch (error) { 251 console.error(`failed to on because: ${JSON.stringify(error)}`); 252} 253``` 254 255## wallpaper.off('wallpaperChange')<sup>10+</sup> 256 257off(type: 'wallpaperChange', callback?: (wallpaperType: WallpaperType, resourceType: WallpaperResourceType, uri?: string) => void): void 258 259Unsubscribes from wallpaper change events. 260 261**System capability**: SystemCapability.MiscServices.Wallpaper 262 263**System API**: This is a system API. 264 265**Parameters** 266 267| Name| Type| Mandatory| Description| 268| -------- | -------- | -------- | -------- | 269| type | string | Yes| Event type. The value is fixed at **'wallpaperChange'**.| 270| callback | function | No| Callback used for unsubscription. If this parameter is not set, this API unsubscribes from all callbacks of the specified event type.<br>- **wallpaperType**: wallpaper type.<br>- **resourceType**: wallpaper resource type.<br>- **uri**: URI of the wallpaper resource.| 271 272**Example** 273 274```ts 275let listener = (wallpaperType: wallpaper.WallpaperType, resourceType: wallpaper.WallpaperResourceType): void => { 276 console.log(`wallpaper color changed.`); 277}; 278try { 279 wallpaper.on('wallpaperChange', listener); 280} catch (error) { 281 console.error(`failed to on because: ${JSON.stringify(error)}`); 282} 283 284try { 285 // Unsubscribe from the listener. 286 wallpaper.off('wallpaperChange', listener); 287} catch (error) { 288 console.error(`failed to off because: ${JSON.stringify(error)}`); 289} 290 291try { 292 // Unsubscribe from all callbacks of the 'wallpaperChange' event type. 293 wallpaper.off('wallpaperChange'); 294} catch (error) { 295 console.error(`failed to off because: ${JSON.stringify(error)}`); 296} 297``` 298 299## wallpaper.getColorsSync<sup>9+</sup> 300 301getColorsSync(wallpaperType: WallpaperType): Array<RgbaColor> 302 303Obtains the main color information of the wallpaper of the specified type. 304 305**System capability**: SystemCapability.MiscServices.Wallpaper 306 307**System API**: This is a system API. 308 309**Parameters** 310 311| Name| Type| Mandatory| Description| 312| -------- | -------- | -------- | -------- | 313| wallpaperType | [WallpaperType](#wallpapertype) | Yes| Wallpaper type.| 314 315**Return value** 316 317| Type| Description| 318| -------- | -------- | 319| Array<[RgbaColor](#rgbacolor)> | Promise used to return the main color information of the wallpaper.| 320 321**Example** 322 323```ts 324try { 325 let colors = wallpaper.getColorsSync(wallpaper.WallpaperType.WALLPAPER_SYSTEM); 326 console.log(`success to getColorsSync: ${JSON.stringify(colors)}`); 327} catch (error) { 328 console.error(`failed to getColorsSync because: ${JSON.stringify(error)}`); 329} 330``` 331 332## wallpaper.getMinHeightSync<sup>9+</sup> 333 334getMinHeightSync(): number 335 336Obtains the minimum height of this wallpaper. 337 338**System capability**: SystemCapability.MiscServices.Wallpaper 339 340**System API**: This is a system API. 341 342**Return value** 343 344| Type| Description| 345| -------- | -------- | 346| 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.| 347 348**Example** 349 350```ts 351let minHeight = wallpaper.getMinHeightSync(); 352``` 353 354## wallpaper.getMinWidthSync<sup>9+</sup> 355 356getMinWidthSync(): number 357 358Obtains the minimum width of this wallpaper. 359 360**System capability**: SystemCapability.MiscServices.Wallpaper 361 362**System API**: This is a system API. 363 364**Return value** 365 366| Type| Description| 367| -------- | -------- | 368| 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.| 369 370**Example** 371 372```ts 373let minWidth = wallpaper.getMinWidthSync(); 374``` 375 376## wallpaper.restore<sup>9+</sup> 377 378restore(wallpaperType: WallpaperType, callback: AsyncCallback<void>): void 379 380Resets the wallpaper of the specified type to the default wallpaper. This API uses an asynchronous callback to return the result. 381 382**Required permissions**: ohos.permission.SET_WALLPAPER 383 384**System capability**: SystemCapability.MiscServices.Wallpaper 385 386**System API**: This is a system API. 387 388**Parameters** 389 390| Name| Type| Mandatory| Description| 391| -------- | -------- | -------- | -------- | 392| wallpaperType | [WallpaperType](#wallpapertype) | Yes| Wallpaper type.| 393| callback | AsyncCallback<void> | Yes| Callback used to return the result. If the wallpaper is reset, **err** is **undefined**. Otherwise, **err** is an error object.| 394 395**Example** 396 397```ts 398import { BusinessError } from '@ohos.base'; 399 400wallpaper.restore(wallpaper.WallpaperType.WALLPAPER_SYSTEM, (error: BusinessError) => { 401 if (error) { 402 console.error(`failed to restore because: ${JSON.stringify(error)}`); 403 return; 404 } 405 console.log(`success to restore.`); 406}); 407``` 408 409## wallpaper.restore<sup>9+</sup> 410 411restore(wallpaperType: WallpaperType): Promise<void> 412 413Resets the wallpaper of the specified type to the default wallpaper. This API uses a promise to return the result. 414 415**Required permissions**: ohos.permission.SET_WALLPAPER 416 417**System capability**: SystemCapability.MiscServices.Wallpaper 418 419**System API**: This is a system API. 420 421**Parameters** 422 423| Name| Type| Mandatory| Description| 424| -------- | -------- | -------- | -------- | 425| wallpaperType | [WallpaperType](#wallpapertype) | Yes| Wallpaper type.| 426 427**Return value** 428 429| Type| Description| 430| -------- | -------- | 431| Promise<void> | Promise that returns no value.| 432 433**Example** 434 435```ts 436import { BusinessError } from '@ohos.base'; 437 438wallpaper.restore(wallpaper.WallpaperType.WALLPAPER_SYSTEM).then(() => { 439 console.log(`success to restore.`); 440 }).catch((error: BusinessError) => { 441 console.error(`failed to restore because: ${JSON.stringify(error)}`); 442}); 443``` 444 445## wallpaper.setImage<sup>9+</sup> 446 447setImage(source: string | image.PixelMap, wallpaperType: WallpaperType, callback: AsyncCallback<void>): void 448 449Sets a specified source as the wallpaper of a specified type. This API uses an asynchronous callback to return the result. 450 451**Required permissions**: ohos.permission.SET_WALLPAPER 452 453**System capability**: SystemCapability.MiscServices.Wallpaper 454 455**System API**: This is a system API. 456 457**Parameters** 458 459| Name| Type| Mandatory| Description| 460| -------- | -------- | -------- | -------- | 461| source | string \| [image.PixelMap](js-apis-image.md#pixelmap7) | Yes| URI of a JPEG or PNG file, or pixel map of a PNG file.| 462| wallpaperType | [WallpaperType](#wallpapertype) | Yes| Wallpaper type.| 463| callback | AsyncCallback<void> | Yes| Callback used to return the result. If the wallpaper is set, **err** is **undefined**. Otherwise, **err** is an error object.| 464 465**Example** 466 467```ts 468import { BusinessError } from '@ohos.base'; 469import image from '@ohos.multimedia.image'; 470 471// The source type is string. 472let wallpaperPath = "/data/storage/el2/base/haps/entry/files/js.jpeg"; 473wallpaper.setImage(wallpaperPath, wallpaper.WallpaperType.WALLPAPER_SYSTEM, (error: BusinessError) => { 474 if (error) { 475 console.error(`failed to setImage because: ${JSON.stringify(error)}`); 476 return; 477 } 478 console.log(`success to setImage.`); 479}); 480 481// The source type is image.PixelMap. 482let imageSource = image.createImageSource("file://" + wallpaperPath); 483let opts: image.DecodingOptions = { 484 desiredSize: { 485 height: 3648, 486 width: 2736 487 } 488}; 489imageSource.createPixelMap(opts).then((pixelMap: image.PixelMap) => { 490 wallpaper.setImage(pixelMap, wallpaper.WallpaperType.WALLPAPER_SYSTEM, (error: BusinessError) => { 491 if (error) { 492 console.error(`failed to setImage because: ${JSON.stringify(error)}`); 493 return; 494 } 495 console.log(`success to setImage.`); 496 }); 497}).catch((error: BusinessError) => { 498 console.error(`failed to createPixelMap because: ${JSON.stringify(error)}`); 499}); 500``` 501 502## wallpaper.setImage<sup>9+</sup> 503 504setImage(source: string | image.PixelMap, wallpaperType: WallpaperType): Promise<void> 505 506Sets a specified source as the wallpaper of a specified type. This API uses a promise to return the result. 507 508**Required permissions**: ohos.permission.SET_WALLPAPER 509 510**System capability**: SystemCapability.MiscServices.Wallpaper 511 512**System API**: This is a system API. 513 514**Parameters** 515 516| Name| Type| Mandatory| Description| 517| -------- | -------- | -------- | -------- | 518| source | string \| [image.PixelMap](js-apis-image.md#pixelmap7) | Yes| URI of a JPEG or PNG file, or pixel map of a PNG file.| 519| wallpaperType | [WallpaperType](#wallpapertype) | Yes| Wallpaper type.| 520 521**Return value** 522 523| Type| Description| 524| -------- | -------- | 525| Promise<void> | Promise that returns no value.| 526 527**Example** 528 529```ts 530import { BusinessError } from '@ohos.base'; 531import image from '@ohos.multimedia.image'; 532 533// The source type is string. 534let wallpaperPath = "/data/storage/el2/base/haps/entry/files/js.jpeg"; 535wallpaper.setImage(wallpaperPath, wallpaper.WallpaperType.WALLPAPER_SYSTEM).then(() => { 536 console.log(`success to setImage.`); 537}).catch((error: BusinessError) => { 538 console.error(`failed to setImage because: ${JSON.stringify(error)}`); 539}); 540 541// The source type is image.PixelMap. 542let imageSource = image.createImageSource("file://" + wallpaperPath); 543let opts: image.DecodingOptions = { 544 desiredSize: { 545 height: 3648, 546 width: 2736 547 } 548}; 549imageSource.createPixelMap(opts).then((pixelMap: image.PixelMap) => { 550 wallpaper.setImage(pixelMap, wallpaper.WallpaperType.WALLPAPER_SYSTEM).then(() => { 551 console.log(`success to setImage.`); 552 }).catch((error: BusinessError) => { 553 console.error(`failed to setImage because: ${JSON.stringify(error)}`); 554 }); 555}).catch((error: BusinessError) => { 556 console.error(`failed to createPixelMap because: ${JSON.stringify(error)}`); 557}); 558``` 559 560## wallpaper.getImage<sup>9+</sup> 561 562getImage(wallpaperType: WallpaperType, callback: AsyncCallback<image.PixelMap>): void; 563 564Obtains the pixel map for the wallpaper of the specified type. This API uses an asynchronous callback to return the result. 565 566**Required permissions**: ohos.permission.GET_WALLPAPER 567 568**System capability**: SystemCapability.MiscServices.Wallpaper 569 570**System API**: This is a system API. 571 572**Parameters** 573 574| Name| Type| Mandatory| Description| 575| -------- | -------- | -------- | -------- | 576| wallpaperType | [WallpaperType](#wallpapertype) | Yes| Wallpaper type.| 577| 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.| 578 579**Example** 580 581```ts 582import { BusinessError } from '@ohos.base'; 583 584wallpaper.getImage(wallpaper.WallpaperType.WALLPAPER_SYSTEM, (error: BusinessError, data: image.PixelMap) => { 585 if (error) { 586 console.error(`failed to getImage because: ${JSON.stringify(error)}`); 587 return; 588 } 589 console.log(`success to getImage: ${JSON.stringify(data)}`); 590}); 591``` 592 593 594## wallpaper.getImage<sup>9+</sup> 595 596getImage(wallpaperType: WallpaperType): Promise<image.PixelMap> 597 598Obtains the pixel map for the wallpaper of the specified type. This API uses a promise to return the result. 599 600**Required permissions**: ohos.permission.GET_WALLPAPER 601 602**System capability**: SystemCapability.MiscServices.Wallpaper 603 604**System API**: This is a system API. 605 606**Parameters** 607 608| Name| Type| Mandatory| Description| 609| -------- | -------- | -------- | -------- | 610| wallpaperType | [WallpaperType](#wallpapertype) | Yes| Wallpaper type.| 611 612**Return value** 613 614| Type| Description| 615| -------- | -------- | 616| 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.| 617 618**Example** 619 620```ts 621import { BusinessError } from '@ohos.base'; 622 623wallpaper.getImage(wallpaper.WallpaperType.WALLPAPER_SYSTEM).then((data: image.PixelMap) => { 624 console.log(`success to getImage: ${JSON.stringify(data)}`); 625 }).catch((error: BusinessError) => { 626 console.error(`failed to getImage because: ${JSON.stringify(error)}`); 627}); 628``` 629 630## wallpaper.on('colorChange')<sup>(deprecated)</sup> 631 632on(type: 'colorChange', callback: (colors: Array<RgbaColor>, wallpaperType: WallpaperType) => void): void 633 634Subscribes to the wallpaper color change event. 635 636> **NOTE** 637> 638> This API is supported since API version 7 and deprecated since API version 9. 639 640**System capability**: SystemCapability.MiscServices.Wallpaper 641 642**Parameters** 643 644| Name| Type| Mandatory| Description| 645| -------- | -------- | -------- | -------- | 646| type | string | Yes| Type of the event to subscribe to. The value **'colorChange'** indicates subscribing to the wallpaper color change event.| 647| 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.| 648 649**Example** 650 651```ts 652try { 653 let listener = (colors: Array<wallpaper.RgbaColor>, wallpaperType: wallpaper.WallpaperType): void => { 654 console.log(`wallpaper color changed.`); 655 }; 656 wallpaper.on('colorChange', listener); 657} catch (error) { 658 console.error(`failed to on because: ${JSON.stringify(error)}`); 659} 660``` 661 662## wallpaper.off('colorChange')<sup>(deprecated)</sup> 663 664off(type: 'colorChange', callback?: (colors: Array<RgbaColor>, wallpaperType: WallpaperType) => void): void 665 666Unsubscribes from the wallpaper color change event. 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**Parameters** 675 676| Name| Type| Mandatory| Description| 677| -------- | -------- | -------- | -------- | 678| type | string | Yes| Type of the event to unsubscribe from. The value **'colorChange'** indicates unsubscribing from the wallpaper color change event.| 679| callback | function | No| Callback used for unsubscription. If this parameter is not set, this API unsubscribes from all callbacks of the specified event type.<br>- colors<br> Main color information of the wallpaper. For details, see [RgbaColor](#rgbacolor).<br>- wallpaperType<br> Wallpaper type.| 680 681**Example** 682 683```ts 684let listener = (colors: Array<wallpaper.RgbaColor>, wallpaperType: wallpaper.WallpaperType): void => { 685 console.log(`wallpaper color changed.`); 686}; 687try { 688 wallpaper.on('colorChange', listener); 689} catch (error) { 690 console.error(`failed to on because: ${JSON.stringify(error)}`); 691} 692 693try { 694 // Unsubscribe from the listener. 695 wallpaper.off('colorChange', listener); 696} catch (error) { 697 console.error(`failed to off because: ${JSON.stringify(error)}`); 698} 699 700try { 701 // Unsubscribe from all subscriptions of the colorChange type. 702 wallpaper.off('colorChange'); 703} catch (error) { 704 console.error(`failed to off because: ${JSON.stringify(error)}`); 705} 706``` 707 708## wallpaper.getColors<sup>(deprecated)</sup> 709 710getColors(wallpaperType: WallpaperType, callback: AsyncCallback<Array<RgbaColor>>): void 711 712Obtains the main color information of the wallpaper of the specified type. This API uses an asynchronous callback to return the result. 713 714> **NOTE** 715> 716> This API is supported since API version 7 and deprecated since API version 9. 717 718**System capability**: SystemCapability.MiscServices.Wallpaper 719 720**Parameters** 721 722| Name| Type| Mandatory| Description| 723| -------- | -------- | -------- | -------- | 724| wallpaperType | [WallpaperType](#wallpapertype) | Yes| Wallpaper type.| 725| callback | AsyncCallback<Array<[RgbaColor](#rgbacolor)>> | Yes| Callback used to return the main color information of the wallpaper.| 726 727**Example** 728 729```ts 730import { BusinessError } from '@ohos.base'; 731 732wallpaper.getColors(wallpaper.WallpaperType.WALLPAPER_SYSTEM, (error: BusinessError, data: Array<wallpaper.RgbaColor>) => { 733 if (error) { 734 console.error(`failed to getColors because: ${JSON.stringify(error)}`); 735 return; 736 } 737 console.log(`success to getColors: ${JSON.stringify(data)}`); 738}); 739``` 740 741## wallpaper.getColors<sup>(deprecated)</sup> 742 743getColors(wallpaperType: WallpaperType): Promise<Array<RgbaColor>> 744 745Obtains the main color information of the wallpaper of the specified type. This API uses a promise to return the result. 746 747> **NOTE** 748> 749> This API is supported since API version 7 and deprecated since API version 9. 750 751**System capability**: SystemCapability.MiscServices.Wallpaper 752 753**Parameters** 754 755| Name| Type| Mandatory| Description| 756| -------- | -------- | -------- | -------- | 757| wallpaperType | [WallpaperType](#wallpapertype) | Yes| Wallpaper type.| 758 759**Return value** 760 761| Type| Description| 762| -------- | -------- | 763| Promise<Array<[RgbaColor](#rgbacolor)>> | Promise used to return the main color information of the wallpaper.| 764 765**Example** 766 767```ts 768import { BusinessError } from '@ohos.base'; 769 770wallpaper.getColors(wallpaper.WallpaperType.WALLPAPER_SYSTEM).then((data: Array<wallpaper.RgbaColor>) => { 771 console.log(`success to getColors: ${JSON.stringify(data)}`); 772 }).catch((error: BusinessError) => { 773 console.error(`failed to getColors because: ${JSON.stringify(error)}`); 774}); 775``` 776 777## wallpaper.getId<sup>(deprecated)</sup> 778 779getId(wallpaperType: WallpaperType, callback: AsyncCallback<number>): void 780 781Obtains the ID of the wallpaper of the specified type. This API uses an asynchronous callback to return the result. 782 783> **NOTE** 784> 785> This API is supported since API version 7 and deprecated since API version 9. 786 787**System capability**: SystemCapability.MiscServices.Wallpaper 788 789**Parameters** 790 791| Name| Type| Mandatory| Description| 792| -------- | -------- | -------- | -------- | 793| wallpaperType | [WallpaperType](#wallpapertype) | Yes| Wallpaper type.| 794| 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).| 795 796**Example** 797 798```ts 799import { BusinessError } from '@ohos.base'; 800 801wallpaper.getId(wallpaper.WallpaperType.WALLPAPER_SYSTEM, (error: BusinessError, data: Number) => { 802 if (error) { 803 console.error(`failed to getId because: ${JSON.stringify(error)}`); 804 return; 805 } 806 console.log(`success to getId: ${JSON.stringify(data)}`); 807}); 808``` 809 810## wallpaper.getId<sup>(deprecated)</sup> 811 812getId(wallpaperType: WallpaperType): Promise<number> 813 814Obtains the ID of the wallpaper of the specified type. This API uses a promise to return the result. 815 816> **NOTE** 817> 818> This API is supported since API version 7 and deprecated since API version 9. 819 820**System capability**: SystemCapability.MiscServices.Wallpaper 821 822**Parameters** 823 824| Name| Type| Mandatory| Description| 825| -------- | -------- | -------- | -------- | 826| wallpaperType | [WallpaperType](#wallpapertype) | Yes| Wallpaper type.| 827 828**Return value** 829 830| Type| Description| 831| -------- | -------- | 832| 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).| 833 834**Example** 835 836```ts 837import { BusinessError } from '@ohos.base'; 838 839wallpaper.getId(wallpaper.WallpaperType.WALLPAPER_SYSTEM).then((data: Number) => { 840 console.log(`success to getId: ${JSON.stringify(data)}`); 841 }).catch((error: BusinessError) => { 842 console.error(`failed to getId because: ${JSON.stringify(error)}`); 843}); 844``` 845 846## wallpaper.getMinHeight<sup>(deprecated)</sup> 847 848getMinHeight(callback: AsyncCallback<number>): void 849 850Obtains the minimum height of this wallpaper. This API uses an asynchronous callback to return the result. 851 852> **NOTE** 853> 854> This API is supported since API version 7 and deprecated since API version 9. 855 856**System capability**: SystemCapability.MiscServices.Wallpaper 857 858**Parameters** 859 860| Name| Type| Mandatory| Description| 861| -------- | -------- | -------- | -------- | 862| 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.| 863 864**Example** 865 866```ts 867import { BusinessError } from '@ohos.base'; 868 869wallpaper.getMinHeight((error: BusinessError, data: Number) => { 870 if (error) { 871 console.error(`failed to getMinHeight because: ${JSON.stringify(error)}`); 872 return; 873 } 874 console.log(`success to getMinHeight: ${JSON.stringify(data)}`); 875}); 876``` 877 878## wallpaper.getMinHeight<sup>(deprecated)</sup> 879 880getMinHeight(): Promise<number> 881 882Obtains the minimum height of this wallpaper. This API uses a promise to return the result. 883 884> **NOTE** 885> 886> This API is supported since API version 7 and deprecated since API version 9. 887 888**System capability**: SystemCapability.MiscServices.Wallpaper 889 890**Return value** 891 892| Type| Description| 893| -------- | -------- | 894| 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.| 895 896**Example** 897 898```ts 899import { BusinessError } from '@ohos.base'; 900 901wallpaper.getMinHeight().then((data: Number) => { 902 console.log(`success to getMinHeight: ${JSON.stringify(data)}`); 903}).catch((error: BusinessError) => { 904 console.error(`failed to getMinHeight because: ${JSON.stringify(error)}`); 905}); 906``` 907 908## wallpaper.getMinWidth<sup>(deprecated)</sup> 909 910getMinWidth(callback: AsyncCallback<number>): void 911 912Obtains the minimum width of this wallpaper. This API uses an asynchronous callback to return the result. 913 914> **NOTE** 915> 916> This API is supported since API version 7 and deprecated since API version 9. 917 918**System capability**: SystemCapability.MiscServices.Wallpaper 919 920**Parameters** 921 922| Name| Type| Mandatory| Description| 923| -------- | -------- | -------- | -------- | 924| 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.| 925 926**Example** 927 928```ts 929import { BusinessError } from '@ohos.base'; 930 931wallpaper.getMinWidth((error: BusinessError, data: Number) => { 932 if (error) { 933 console.error(`failed to getMinWidth because: ${JSON.stringify(error)}`); 934 return; 935 } 936 console.log(`success to getMinWidth: ${JSON.stringify(data)}`); 937}); 938``` 939 940## wallpaper.getMinWidth<sup>(deprecated)</sup> 941 942getMinWidth(): Promise<number> 943 944Obtains the minimum width of this wallpaper. This API uses a promise to return the result. 945 946> **NOTE** 947> 948> This API is supported since API version 7 and deprecated since API version 9. 949 950**System capability**: SystemCapability.MiscServices.Wallpaper 951 952**Return value** 953 954| Type| Description| 955| -------- | -------- | 956| 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.| 957 958**Example** 959 960```ts 961import { BusinessError } from '@ohos.base'; 962 963wallpaper.getMinWidth().then((data: Number) => { 964 console.log(`success to getMinWidth: ${JSON.stringify(data)}`); 965 }).catch((error: BusinessError) => { 966 console.error(`failed to getMinWidth because: ${JSON.stringify(error)}`); 967}); 968``` 969 970## wallpaper.isChangePermitted<sup>(deprecated)</sup> 971 972isChangePermitted(callback: AsyncCallback<boolean>): void 973 974Checks whether to allow the application to change the wallpaper for the current user. This API uses an asynchronous callback to return the result. 975 976> **NOTE** 977> 978> This API is supported since API version 7 and deprecated since API version 9. 979 980**System capability**: SystemCapability.MiscServices.Wallpaper 981 982**Parameters** 983 984| Name| Type| Mandatory| Description| 985| -------- | -------- | -------- | -------- | 986| 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.| 987 988**Example** 989 990```ts 991import { BusinessError } from '@ohos.base'; 992 993wallpaper.isChangePermitted((error: BusinessError, data: Boolean) => { 994 if (error) { 995 console.error(`failed to isChangePermitted because: ${JSON.stringify(error)}`); 996 return; 997 } 998 console.log(`success to isChangePermitted: ${JSON.stringify(data)}`); 999}); 1000``` 1001 1002## wallpaper.isChangePermitted<sup>(deprecated)</sup> 1003 1004isChangePermitted(): Promise<boolean> 1005 1006Checks whether to allow the application to change the wallpaper for the current user. This API uses a promise to return the result. 1007 1008> **NOTE** 1009> 1010> This API is supported since API version 7 and deprecated since API version 9. 1011 1012**System capability**: SystemCapability.MiscServices.Wallpaper 1013 1014**Return value** 1015 1016| Type| Description| 1017| -------- | -------- | 1018| 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.| 1019 1020**Example** 1021 1022```ts 1023import { BusinessError } from '@ohos.base'; 1024 1025wallpaper.isChangePermitted().then((data: Boolean) => { 1026 console.log(`success to isChangePermitted: ${JSON.stringify(data)}`); 1027}).catch((error: BusinessError) => { 1028 console.error(`failed to isChangePermitted because: ${JSON.stringify(error)}`); 1029}); 1030``` 1031 1032## wallpaper.isOperationAllowed<sup>(deprecated)</sup> 1033 1034isOperationAllowed(callback: AsyncCallback<boolean>): void 1035 1036Checks whether the user is allowed to set wallpapers. This API uses an asynchronous callback to return the result. 1037 1038> **NOTE** 1039> 1040> This API is supported since API version 7 and deprecated since API version 9. 1041 1042**System capability**: SystemCapability.MiscServices.Wallpaper 1043 1044**Parameters** 1045 1046| Name| Type| Mandatory| Description| 1047| -------- | -------- | -------- | -------- | 1048| 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.| 1049 1050**Example** 1051 1052```ts 1053import { BusinessError } from '@ohos.base'; 1054 1055wallpaper.isChangePermitted().then((data: Boolean) => { 1056 console.log(`success to isChangePermitted: ${JSON.stringify(data)}`); 1057}).catch((error: BusinessError) => { 1058 console.error(`failed to isChangePermitted because: ${JSON.stringify(error)}`); 1059}); 1060``` 1061 1062## wallpaper.isOperationAllowed<sup>(deprecated)</sup> 1063 1064isOperationAllowed(): Promise<boolean> 1065 1066Checks whether the user is allowed to set wallpapers. This API uses a promise to return the result. 1067 1068> **NOTE** 1069> 1070> This API is supported since API version 7 and deprecated since API version 9. 1071 1072**System capability**: SystemCapability.MiscServices.Wallpaper 1073 1074**Return value** 1075 1076| Type| Description| 1077| -------- | -------- | 1078| 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.| 1079 1080**Example** 1081 1082```ts 1083import { BusinessError } from '@ohos.base'; 1084 1085wallpaper.isOperationAllowed().then((data: Boolean) => { 1086 console.log(`success to isOperationAllowed: ${JSON.stringify(data)}`); 1087 }).catch((error: BusinessError) => { 1088 console.error(`failed to isOperationAllowed because: ${JSON.stringify(error)}`); 1089}); 1090``` 1091 1092## wallpaper.reset<sup>(deprecated)</sup> 1093 1094reset(wallpaperType: WallpaperType, callback: AsyncCallback<void>): void 1095 1096Resets the wallpaper of the specified type to the default wallpaper. This API uses an asynchronous callback to return the result. 1097 1098> **NOTE** 1099> 1100> This API is supported since API version 7 and deprecated since API version 9. 1101 1102**Required permissions**: ohos.permission.SET_WALLPAPER 1103 1104**System capability**: SystemCapability.MiscServices.Wallpaper 1105 1106**Parameters** 1107 1108| Name| Type| Mandatory| Description| 1109| -------- | -------- | -------- | -------- | 1110| wallpaperType | [WallpaperType](#wallpapertype) | Yes| Wallpaper type.| 1111| callback | AsyncCallback<void> | Yes| Callback used to return the result. If the wallpaper is reset, **err** is **undefined**. Otherwise, **err** is an error object.| 1112 1113**Example** 1114 1115```ts 1116import { BusinessError } from '@ohos.base'; 1117 1118wallpaper.reset(wallpaper.WallpaperType.WALLPAPER_SYSTEM, (error: BusinessError) => { 1119 if (error) { 1120 console.error(`failed to reset because: ${JSON.stringify(error)}`); 1121 return; 1122 } 1123 console.log(`success to reset.`); 1124}); 1125``` 1126 1127## wallpaper.reset<sup>(deprecated)</sup> 1128 1129reset(wallpaperType: WallpaperType): Promise<void> 1130 1131Resets the wallpaper of the specified type to the default wallpaper. This API uses a promise to return the result. 1132 1133> **NOTE** 1134> 1135> This API is supported since API version 7 and deprecated since API version 9. 1136 1137**Required permissions**: ohos.permission.SET_WALLPAPER 1138 1139**System capability**: SystemCapability.MiscServices.Wallpaper 1140 1141**Parameters** 1142 1143| Name| Type| Mandatory| Description| 1144| -------- | -------- | -------- | -------- | 1145| wallpaperType | [WallpaperType](#wallpapertype) | Yes| Wallpaper type.| 1146 1147**Return value** 1148 1149| Type| Description| 1150| -------- | -------- | 1151| Promise<void> | Promise that returns no value.| 1152 1153**Example** 1154 1155```ts 1156import { BusinessError } from '@ohos.base'; 1157 1158wallpaper.reset(wallpaper.WallpaperType.WALLPAPER_SYSTEM).then(() => { 1159 console.log(`success to reset.`); 1160}).catch((error: BusinessError) => { 1161 console.error(`failed to reset because: ${JSON.stringify(error)}`); 1162}); 1163``` 1164 1165## wallpaper.setWallpaper<sup>(deprecated)</sup> 1166 1167setWallpaper(source: string | image.PixelMap, wallpaperType: WallpaperType, callback: AsyncCallback<void>): void 1168 1169Sets a specified source as the wallpaper of a specified type. This API uses an asynchronous callback to return the result. 1170 1171> **NOTE** 1172> 1173> This API is supported since API version 7 and deprecated since API version 9. 1174 1175**Required permissions**: ohos.permission.SET_WALLPAPER 1176 1177**System capability**: SystemCapability.MiscServices.Wallpaper 1178 1179**Parameters** 1180 1181| Name| Type| Mandatory| Description| 1182| -------- | -------- | -------- | -------- | 1183| source | string \| [image.PixelMap](js-apis-image.md#pixelmap7) | Yes| URI of a JPEG or PNG file, or pixel map of a PNG file.| 1184| wallpaperType | [WallpaperType](#wallpapertype) | Yes| Wallpaper type.| 1185| callback | AsyncCallback<void> | Yes| Callback used to return the result. If the wallpaper is set, **err** is **undefined**. Otherwise, **err** is an error object.| 1186 1187**Example** 1188 1189```ts 1190import { BusinessError } from '@ohos.base'; 1191import image from '@ohos.multimedia.image'; 1192 1193// The source type is string. 1194let wallpaperPath = "/data/storage/el2/base/haps/entry/files/js.jpeg"; 1195wallpaper.setWallpaper(wallpaperPath, wallpaper.WallpaperType.WALLPAPER_SYSTEM, (error: BusinessError) => { 1196 if (error) { 1197 console.error(`failed to setWallpaper because: ${JSON.stringify(error)}`); 1198 return; 1199 } 1200 console.log(`success to setWallpaper.`); 1201}); 1202 1203// The source type is image.PixelMap. 1204let imageSource = image.createImageSource("file://" + wallpaperPath); 1205let opts: image.DecodingOptions = { 1206 desiredSize: { 1207 height: 3648, 1208 width: 2736 1209 } 1210}; 1211imageSource.createPixelMap(opts).then((pixelMap: image.PixelMap) => { 1212 wallpaper.setWallpaper(pixelMap, wallpaper.WallpaperType.WALLPAPER_SYSTEM, (error: BusinessError) => { 1213 if (error) { 1214 console.error(`failed to setWallpaper because: ${JSON.stringify(error)}`); 1215 return; 1216 } 1217 console.log(`success to setWallpaper.`); 1218 }); 1219}).catch((error: BusinessError) => { 1220 console.error(`failed to createPixelMap because: ${JSON.stringify(error)}`); 1221}); 1222``` 1223 1224## wallpaper.setWallpaper<sup>(deprecated)</sup> 1225 1226setWallpaper(source: string | image.PixelMap, wallpaperType: WallpaperType): Promise<void> 1227 1228Sets a specified source as the wallpaper of a specified type. This API uses a promise to return the result. 1229 1230> **NOTE** 1231> 1232> This API is supported since API version 7 and deprecated since API version 9. 1233 1234**Required permissions**: ohos.permission.SET_WALLPAPER 1235 1236**System capability**: SystemCapability.MiscServices.Wallpaper 1237 1238**Parameters** 1239 1240| Name| Type| Mandatory| Description| 1241| -------- | -------- | -------- | -------- | 1242| source | string \| [image.PixelMap](js-apis-image.md#pixelmap7) | Yes| URI of a JPEG or PNG file, or pixel map of a PNG file.| 1243| wallpaperType | [WallpaperType](#wallpapertype) | Yes| Wallpaper type.| 1244 1245**Return value** 1246 1247| Type| Description| 1248| -------- | -------- | 1249| Promise<void> | Promise that returns no value.| 1250 1251**Example** 1252 1253```ts 1254import { BusinessError } from '@ohos.base'; 1255import image from '@ohos.multimedia.image'; 1256 1257// The source type is string. 1258let wallpaperPath = "/data/storage/el2/base/haps/entry/files/js.jpeg"; 1259wallpaper.setWallpaper(wallpaperPath, wallpaper.WallpaperType.WALLPAPER_SYSTEM).then(() => { 1260 console.log(`success to setWallpaper.`); 1261 }).catch((error: BusinessError) => { 1262 console.error(`failed to setWallpaper because: ${JSON.stringify(error)}`); 1263}); 1264 1265// The source type is image.PixelMap. 1266let imageSource = image.createImageSource("file://" + wallpaperPath); 1267let opts: image.DecodingOptions = { 1268 desiredSize: { 1269 height: 3648, 1270 width: 2736 1271 } 1272}; 1273imageSource.createPixelMap(opts).then((pixelMap: image.PixelMap) => { 1274 wallpaper.setWallpaper(pixelMap, wallpaper.WallpaperType.WALLPAPER_SYSTEM).then(() => { 1275 console.log(`success to setWallpaper.`); 1276 }).catch((error: BusinessError) => { 1277 console.error(`failed to setWallpaper because: ${JSON.stringify(error)}`); 1278 }); 1279 }).catch((error: BusinessError) => { 1280 console.error(`failed to createPixelMap because: ${JSON.stringify(error)}`); 1281}); 1282``` 1283 1284 1285## wallpaper.getFile<sup>(deprecated)</sup> 1286 1287getFile(wallpaperType: WallpaperType, callback: AsyncCallback<number>): void 1288 1289Obtains the wallpaper of the specified type. This API uses an asynchronous callback to return the result. 1290 1291> **NOTE** 1292> 1293> This API is supported since API version 8 and deprecated since API version 9. 1294 1295**Required permissions**: ohos.permission.GET_WALLPAPER 1296 1297**System capability**: SystemCapability.MiscServices.Wallpaper 1298 1299**Parameters** 1300 1301| Name| Type| Mandatory| Description| 1302| -------- | -------- | -------- | -------- | 1303| wallpaperType | [WallpaperType](#wallpapertype) | Yes| Wallpaper type.| 1304| 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.| 1305 1306**Example** 1307 1308```ts 1309import { BusinessError } from '@ohos.base'; 1310 1311wallpaper.getFile(wallpaper.WallpaperType.WALLPAPER_SYSTEM, (error: BusinessError, data: number) => { 1312 if (error) { 1313 console.error(`failed to getFile because: ${JSON.stringify(error)}`); 1314 return; 1315 } 1316 console.log(`success to getFile: ${JSON.stringify(data)}`); 1317}); 1318``` 1319 1320## wallpaper.getFile<sup>(deprecated)</sup> 1321 1322getFile(wallpaperType: WallpaperType): Promise<number> 1323 1324Obtains the wallpaper of the specified type. This API uses a promise to return the result. 1325 1326> **NOTE** 1327> 1328> This API is supported since API version 8 and deprecated since API version 9. 1329 1330**Required permissions**: ohos.permission.GET_WALLPAPER 1331 1332**System capability**: SystemCapability.MiscServices.Wallpaper 1333 1334**Parameters** 1335 1336| Name| Type| Mandatory| Description| 1337| -------- | -------- | -------- | -------- | 1338| wallpaperType | [WallpaperType](#wallpapertype) | Yes| Wallpaper type.| 1339 1340**Return value** 1341 1342| Type| Description| 1343| -------- | -------- | 1344| 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.| 1345 1346**Example** 1347 1348```ts 1349import { BusinessError } from '@ohos.base'; 1350 1351wallpaper.getFile(wallpaper.WallpaperType.WALLPAPER_SYSTEM).then((data: number) => { 1352 console.log(`success to getFile: ${JSON.stringify(data)}`); 1353 }).catch((error: BusinessError) => { 1354 console.error(`failed to getFile because: ${JSON.stringify(error)}`); 1355}); 1356 1357``` 1358 1359## wallpaper.getPixelMap<sup>(deprecated)</sup> 1360 1361getPixelMap(wallpaperType: WallpaperType, callback: AsyncCallback<image.PixelMap>): void; 1362 1363Obtains the pixel map for the wallpaper of the specified type. This API uses an asynchronous callback to return the result. 1364 1365> **NOTE** 1366> 1367> This API is supported since API version 7 and deprecated since API version 9. 1368 1369**Required permissions**: ohos.permission.GET_WALLPAPER 1370 1371**System capability**: SystemCapability.MiscServices.Wallpaper 1372 1373**System API**: This is a system API. 1374 1375**Parameters** 1376 1377| Name| Type| Mandatory| Description| 1378| -------- | -------- | -------- | -------- | 1379| wallpaperType | [WallpaperType](#wallpapertype) | Yes| Wallpaper type.| 1380| 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.| 1381 1382**Example** 1383 1384```ts 1385import { BusinessError } from '@ohos.base'; 1386 1387wallpaper.getPixelMap(wallpaper.WallpaperType.WALLPAPER_SYSTEM, (error: BusinessError, data: image.PixelMap) => { 1388 if (error) { 1389 console.error(`failed to getPixelMap because: ${JSON.stringify(error)}`); 1390 return; 1391 } 1392 console.log(`success to getPixelMap : ${JSON.stringify(data)}`); 1393 }); 1394``` 1395 1396## wallpaper.getPixelMap<sup>(deprecated)</sup> 1397 1398getPixelMap(wallpaperType: WallpaperType): Promise<image.PixelMap> 1399 1400Obtains the pixel map for the wallpaper of the specified type. This API uses a promise to return the result. 1401 1402> **NOTE** 1403> 1404> This API is supported since API version 7 and deprecated since API version 9. 1405 1406**Required permissions**: ohos.permission.GET_WALLPAPER 1407 1408**System capability**: SystemCapability.MiscServices.Wallpaper 1409 1410**System API**: This is a system API. 1411 1412**Parameters** 1413 1414| Name| Type| Mandatory| Description| 1415| -------- | -------- | -------- | -------- | 1416| wallpaperType | [WallpaperType](#wallpapertype) | Yes| Wallpaper type.| 1417 1418**Return value** 1419 1420| Type| Description| 1421| -------- | -------- | 1422| 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.| 1423 1424**Example** 1425 1426```ts 1427import { BusinessError } from '@ohos.base'; 1428 1429wallpaper.getPixelMap(wallpaper.WallpaperType.WALLPAPER_SYSTEM).then((data: image.PixelMap) => { 1430 console.log(`success to getPixelMap : ${JSON.stringify(data)}`); 1431 }).catch((error: BusinessError) => { 1432 console.error(`failed to getPixelMap because: ${JSON.stringify(error)}`); 1433}); 1434``` 1435