js-apis-wallpaper.md 43.7 KB
Newer Older
E
ester.zhou 已提交
1
# @ohos.wallpaper (Wallpaper)
Z
zengyawen 已提交
2

E
esterzhou 已提交
3
The **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.
Z
zengyawen 已提交
4

E
ester.zhou 已提交
5
> **NOTE**
E
ester.zhou 已提交
6
> 
E
ester.zhou 已提交
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.
Z
zengyawen 已提交
8 9 10 11 12


## Modules to Import


E
ester.zhou 已提交
13
```js
Z
zengyawen 已提交
14 15
import wallpaper from '@ohos.wallpaper';
```
E
ester.zhou 已提交
16 17 18 19 20 21 22 23 24 25 26 27 28 29 30
## WallpaperResourceType<sup>10+</sup>

Enumerates the types of wallpaper resources.

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

**System API**: This is a system API.

| Name| Value|Description|
| -------- | -------- |-------- |
| DEFAULT | 0 |Default type (image resource).|
| PICTURE | 1 |Image resource.|
| VIDEO | 2 |Video resource.|
| PACKAGE | 3 |Package resource.|

Z
zengyawen 已提交
31

E
ester.zhou 已提交
32
## WallpaperType<sup>7+</sup>
Z
zengyawen 已提交
33

E
ester.zhou 已提交
34
Enumerates the wallpaper types.
Z
zengyawen 已提交
35 36 37

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

E
ester.zhou 已提交
38 39 40 41
| Name| Value|Description|
| -------- | -------- |-------- |
| WALLPAPER_SYSTEM | 0 |Home screen wallpaper.|
| WALLPAPER_LOCKSCREEN | 1 |Lock screen wallpaper.|
Z
zengyawen 已提交
42 43


E
ester.zhou 已提交
44
## RgbaColor<sup>(deprecated)</sup>
Z
zengyawen 已提交
45

E
ester.zhou 已提交
46
Defines the RGBA color space for the wallpaper.
Z
zengyawen 已提交
47

E
ester.zhou 已提交
48 49 50
> **NOTE**
> 
> This API is supported since API version 7 and deprecated since API version 9.
Z
zengyawen 已提交
51

E
ester.zhou 已提交
52
**System capability**: SystemCapability.MiscServices.Wallpaper
E
ester.zhou 已提交
53

E
ester.zhou 已提交
54 55 56 57 58 59 60 61
| Name| Type| Readable| Writable| Description|
| -------- | -------- | -------- | -------- | -------- |
| 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.|


E
ester.zhou 已提交
62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 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 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139
## wallpaper.setVideo<sup>10+</sup>

setVideo(source: string, wallpaperType: WallpaperType, callback: AsyncCallback&lt;void&gt;): void

Sets a video resource as the home screen wallpaper or lock screen wallpaper. This API uses an asynchronous callback to return the result.

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

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

**System API**: This is a system API.

**Parameters**

| Name| Type| Mandatory| Description|
| -------- | -------- | -------- | -------- |
| source | string | Yes| URI of an MP4 file.|
| wallpaperType | [WallpaperType](#wallpapertype7) | Yes| Wallpaper type.|
| callback | AsyncCallback&lt;void&gt; | Yes| Callback used to return the result. If the wallpaper is set, **err** is **undefined**. Otherwise, **err** is an error object.|

**Example**

```js
let wallpaperPath = "/data/storage/el2/base/haps/entry/files/test.mp4";
try {
    wallpaper.setVideo(wallpaperPath, wallpaper.WallpaperType.WALLPAPER_SYSTEM, (error) => {
        if (error) {
            console.error(`failed to setVideo because: ${JSON.stringify(error)}`);
            return;
        }
        console.log(`success to setVideo.`);
    });
} catch (error) {
    console.error(`failed to setVideo because: ${JSON.stringify(error)}`);
}

```

## wallpaper.setVideo<sup>10+</sup>

setVideo(source: string, wallpaperType: WallpaperType): Promise&lt;void&gt;

Sets a video resource as the home screen wallpaper or lock screen wallpaper. This API uses a promise to return the result.

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

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

**System API**: This is a system API.

**Parameters**

| Name| Type| Mandatory| Description|
| -------- | -------- | -------- | -------- |
| source | string | Yes| URI of an MP4 file.|
| wallpaperType | [WallpaperType](#wallpapertype7) | Yes| Wallpaper type.|

**Return value**

| Type| Description|
| -------- | -------- |
| Promise&lt;void&gt; | Promise that returns no value.|

**Example**

```js
let wallpaperPath = "/data/storage/el2/base/haps/entry/files/test.mp4";
try {
    wallpaper.setVideo(wallpaperPath, wallpaper.WallpaperType.WALLPAPER_SYSTEM).then(() => {
        console.log(`success to setVideo.`);
    }).catch((error) => {
        console.error(`failed to setVideo because: ${JSON.stringify(error)}`);
    });
} catch (error) {
    console.error(`failed to setVideo because: ${JSON.stringify(error)}`);
}
```

E
ester.zhou 已提交
140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 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.setCustomWallpaper<sup>10+</sup>

setCustomWallpaper(source: string, wallpaperType: WallpaperType, callback: AsyncCallback&lt;void&gt;): void

Sets 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.

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

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

**System API**: This is a system API.

**Parameters**

| Name| Type| Mandatory| Description|
| -------- | -------- | -------- | -------- |
| source | string | Yes| URI of the custom wallpaper.|
| wallpaperType | [WallpaperType](#wallpapertype7) | Yes| Wallpaper type.|
| callback | AsyncCallback&lt;void&gt; | Yes| Callback used to return the result. If the wallpaper is set, **err** is **undefined**. Otherwise, **err** is an error object.|

**Example**

```js
let wallpaperPath = "/data/storage/el2/base/haps/entry/files/test.zip";
try {
    wallpaper.setCustomWallpaper(wallpaperPath, wallpaper.WallpaperType.WALLPAPER_SYSTEM, (error) => {
        if (error) {
            console.error(`failed to setCustomWallpaper because: ${JSON.stringify(error)}`);
            return;
        }
        console.log(`success to setCustomWallpaper.`);
    });
} catch (error) {
    console.error(`failed to setCustomWallpaper because: ${JSON.stringify(error)}`);
}

```

## wallpaper.setCustomWallpaper<sup>10+</sup>

setCustomWallpaper(source: string, wallpaperType: WallpaperType): Promise&lt;void&gt;

Sets 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.

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

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

**System API**: This is a system API.

**Parameters**

| Name| Type| Mandatory| Description|
| -------- | -------- | -------- | -------- |
| source | string | Yes| URI of the custom wallpaper.|
| wallpaperType | [WallpaperType](#wallpapertype7) | Yes| Wallpaper type.|

**Return value**

| Type| Description|
| -------- | -------- |
| Promise&lt;void&gt; | Promise that returns no value.|

**Example**

```js
let wallpaperPath = "/data/storage/el2/base/haps/entry/files/test.zip";
try {
    wallpaper.setCustomWallpaper(wallpaperPath, wallpaper.WallpaperType.WALLPAPER_SYSTEM).then(() => {
        console.log(`success to setCustomWallpaper.`);
    }).catch((error) => {
        console.error(`failed to setCustomWallpaper because: ${JSON.stringify(error)}`);
    });
} catch (error) {
    console.error(`failed to setCustomWallpaper because: ${JSON.stringify(error)}`);
}
```

E
ester.zhou 已提交
218 219
## wallpaper.on('wallpaperChange')<sup>10+</sup>

E
ester.zhou 已提交
220
on(type: 'wallpaperChange', callback: (wallpaperType: WallpaperType, resourceType: WallpaperResourceType, uri?: string) =&gt; void): void
E
ester.zhou 已提交
221 222 223 224 225 226 227 228 229 230 231 232

Subscribes to wallpaper change events.

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

**System API**: This is a system API.

**Parameters**

| Name| Type| Mandatory| Description|
| -------- | -------- | -------- | -------- |
| type | string | Yes| Event type. The value is fixed at **'wallpaperChange'**.|
E
ester.zhou 已提交
233
| 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.|
E
ester.zhou 已提交
234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249

**Example**

```js
try {
    let listener = (wallpaperType, resourceType) => {
        console.log(`wallpaper color changed.`);
    };
    wallpaper.on('wallpaperChange', listener);
} catch (error) {
    console.error(`failed to on because: ${JSON.stringify(error)}`);
}
```

## wallpaper.off('wallpaperChange')<sup>10+</sup>

E
ester.zhou 已提交
250
off(type: 'wallpaperChange', callback?: (wallpaperType: WallpaperType, resourceType: WallpaperResourceType, uri?: string) =&gt; void): void
E
ester.zhou 已提交
251 252 253 254 255 256 257 258 259 260 261 262

Unsubscribes from wallpaper change events.

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

**System API**: This is a system API.

**Parameters**

| Name| Type| Mandatory| Description|
| -------- | -------- | -------- | -------- |
| type | string | Yes| Event type. The value is fixed at **'wallpaperChange'**.|
E
ester.zhou 已提交
263
| 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.|
E
ester.zhou 已提交
264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291

**Example**

```js
let listener = (wallpaperType, resourceType) => {
    console.log(`wallpaper color changed.`);
};
try {
    wallpaper.on('wallpaperChange', listener);
} catch (error) {
    console.error(`failed to on because: ${JSON.stringify(error)}`);
}

try {
    // Unsubscribe from the listener.
    wallpaper.off('wallpaperChange', listener);
} catch (error) {
    console.error(`failed to off because: ${JSON.stringify(error)}`);
}

try {
    // Unsubscribe from all callbacks of the 'wallpaperChange' event type.
    wallpaper.off('wallpaperChange');
} catch (error) {
    console.error(`failed to off because: ${JSON.stringify(error)}`);
}
```

E
ester.zhou 已提交
292 293 294 295 296
## wallpaper.getColorsSync<sup>9+</sup>

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

Obtains the main color information of the wallpaper of the specified type.
E
ester.zhou 已提交
297

Z
zengyawen 已提交
298 299
**System capability**: SystemCapability.MiscServices.Wallpaper

E
ester.zhou 已提交
300 301
**System API**: This is a system API.

E
ester.zhou 已提交
302
**Parameters**
E
ester.zhou 已提交
303 304

| Name| Type| Mandatory| Description|
E
ester.zhou 已提交
305
| -------- | -------- | -------- | -------- |
E
ester.zhou 已提交
306
| wallpaperType | [WallpaperType](#wallpapertype7) | Yes| Wallpaper type.|
E
ester.zhou 已提交
307

E
ester.zhou 已提交
308
**Return value**
Z
zengyawen 已提交
309

E
ester.zhou 已提交
310 311
| Type| Description|
| -------- | -------- |
E
ester.zhou 已提交
312
| Array&lt;[RgbaColor](#rgbacolordeprecated)&gt; | Promise used to return the main color information of the wallpaper.|
Z
zengyawen 已提交
313

E
ester.zhou 已提交
314
**Example**
Z
zengyawen 已提交
315

E
ester.zhou 已提交
316
```js
E
esterzhou 已提交
317 318 319 320 321 322
try {
    let colors = wallpaper.getColorsSync(wallpaper.WallpaperType.WALLPAPER_SYSTEM);
    console.log(`success to getColorsSync: ${JSON.stringify(colors)}`);
} catch (error) {
    console.error(`failed to getColorsSync because: ${JSON.stringify(error)}`);
}
E
ester.zhou 已提交
323
```
Z
zengyawen 已提交
324

E
ester.zhou 已提交
325
## wallpaper.getMinHeightSync<sup>9+</sup>
Z
zengyawen 已提交
326

E
ester.zhou 已提交
327
getMinHeightSync(): number
E
ester.zhou 已提交
328

E
ester.zhou 已提交
329
Obtains the minimum height of this wallpaper.
E
ester.zhou 已提交
330

E
ester.zhou 已提交
331 332
**System capability**: SystemCapability.MiscServices.Wallpaper

E
ester.zhou 已提交
333 334
**System API**: This is a system API.

E
ester.zhou 已提交
335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354
**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
let minHeight = wallpaper.getMinHeightSync();
```

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

getMinWidthSync(): number

Obtains the minimum width of this wallpaper.

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

E
ester.zhou 已提交
355 356
**System API**: This is a system API.

E
ester.zhou 已提交
357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378
**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
let minWidth = wallpaper.getMinWidthSync();
```

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

E
ester.zhou 已提交
379 380
**System API**: This is a system API.

E
ester.zhou 已提交
381 382 383 384
**Parameters**

| Name| Type| Mandatory| Description|
| -------- | -------- | -------- | -------- |
E
ester.zhou 已提交
385
| wallpaperType | [WallpaperType](#wallpapertype7) | Yes| Wallpaper type.|
E
esterzhou 已提交
386
| callback | AsyncCallback&lt;void&gt; | Yes| Callback used to return the result. If the wallpaper is reset, **err** is **undefined**. Otherwise, **err** is an error object.|
E
ester.zhou 已提交
387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406

**Example**

```js
wallpaper.restore(wallpaper.WallpaperType.WALLPAPER_SYSTEM, (error) => {
    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 a promise to return the result.

**Required permissions**: ohos.permission.SET_WALLPAPER
E
ester.zhou 已提交
407 408 409

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

E
ester.zhou 已提交
410 411
**System API**: This is a system API.

E
ester.zhou 已提交
412 413 414 415
**Parameters**

| Name| Type| Mandatory| Description|
| -------- | -------- | -------- | -------- |
E
ester.zhou 已提交
416
| wallpaperType | [WallpaperType](#wallpapertype7) | Yes| Wallpaper type.|
E
ester.zhou 已提交
417 418 419 420 421

**Return value**

| Type| Description|
| -------- | -------- |
E
ester.zhou 已提交
422
| Promise&lt;void&gt; | Promise that returns no value.|
E
ester.zhou 已提交
423 424 425

**Example**

E
ester.zhou 已提交
426 427 428 429 430 431 432
```js 
wallpaper.restore(wallpaper.WallpaperType.WALLPAPER_SYSTEM).then(() => {
    console.log(`success to restore.`);
  }).catch((error) => {
    console.error(`failed to restore because: ${JSON.stringify(error)}`);
});
```
E
ester.zhou 已提交
433

E
ester.zhou 已提交
434
## wallpaper.setImage<sup>9+</sup>
Z
zengyawen 已提交
435

E
ester.zhou 已提交
436
setImage(source: string | image.PixelMap, wallpaperType: WallpaperType, callback: AsyncCallback&lt;void&gt;): void
Z
zengyawen 已提交
437

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

E
ester.zhou 已提交
440
**Required permissions**: ohos.permission.SET_WALLPAPER
E
ester.zhou 已提交
441

Z
zengyawen 已提交
442 443
**System capability**: SystemCapability.MiscServices.Wallpaper

E
ester.zhou 已提交
444 445
**System API**: This is a system API.

E
ester.zhou 已提交
446
**Parameters**
Z
zengyawen 已提交
447

E
ester.zhou 已提交
448
| Name| Type| Mandatory| Description|
E
ester.zhou 已提交
449
| -------- | -------- | -------- | -------- |
E
esterzhou 已提交
450
| source | string \| [image.PixelMap](js-apis-image.md#pixelmap7) | Yes| URI of a JPEG or PNG file, or pixel map of a PNG file.|
E
ester.zhou 已提交
451
| wallpaperType | [WallpaperType](#wallpapertype7) | Yes| Wallpaper type.|
E
esterzhou 已提交
452
| callback | AsyncCallback&lt;void&gt; | Yes| Callback used to return the result. If the wallpaper is set, **err** is **undefined**. Otherwise, **err** is an error object.|
E
ester.zhou 已提交
453 454 455

**Example**

E
ester.zhou 已提交
456
```js
E
esterzhou 已提交
457
// The source type is string.
E
ester.zhou 已提交
458
let wallpaperPath = "/data/storage/el2/base/haps/entry/files/js.jpeg";
E
ester.zhou 已提交
459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487
wallpaper.setImage(wallpaperPath, wallpaper.WallpaperType.WALLPAPER_SYSTEM, (error) => {
    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) => {
        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)}`);
});
```
Z
zengyawen 已提交
488

E
ester.zhou 已提交
489
## wallpaper.setImage<sup>9+</sup>
Z
zengyawen 已提交
490

E
ester.zhou 已提交
491
setImage(source: string | image.PixelMap, wallpaperType: WallpaperType): Promise&lt;void&gt;
Z
zengyawen 已提交
492

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

E
ester.zhou 已提交
495
**Required permissions**: ohos.permission.SET_WALLPAPER
Z
zengyawen 已提交
496

E
ester.zhou 已提交
497
**System capability**: SystemCapability.MiscServices.Wallpaper
E
ester.zhou 已提交
498

E
ester.zhou 已提交
499 500
**System API**: This is a system API.

E
ester.zhou 已提交
501
**Parameters**
Z
zengyawen 已提交
502

E
ester.zhou 已提交
503
| Name| Type| Mandatory| Description|
E
ester.zhou 已提交
504
| -------- | -------- | -------- | -------- |
E
esterzhou 已提交
505
| source | string \| [image.PixelMap](js-apis-image.md#pixelmap7) | Yes| URI of a JPEG or PNG file, or pixel map of a PNG file.|
E
ester.zhou 已提交
506
| wallpaperType | [WallpaperType](#wallpapertype7) | Yes| Wallpaper type.|
Z
zengyawen 已提交
507

E
ester.zhou 已提交
508
**Return value**
Z
zengyawen 已提交
509

E
ester.zhou 已提交
510
| Type| Description|
E
ester.zhou 已提交
511
| -------- | -------- |
E
ester.zhou 已提交
512
| Promise&lt;void&gt; | Promise that returns no value.|
E
ester.zhou 已提交
513 514 515

**Example**

E
ester.zhou 已提交
516
```js
E
esterzhou 已提交
517
// The source type is string.
E
ester.zhou 已提交
518
let wallpaperPath = "/data/storage/el2/base/haps/entry/files/js.jpeg";
E
ester.zhou 已提交
519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543
wallpaper.setImage(wallpaperPath, wallpaper.WallpaperType.WALLPAPER_SYSTEM).then(() => {
    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(() => {
        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 已提交
544

E
ester.zhou 已提交
545
## wallpaper.getImage<sup>9+</sup>
Z
zengyawen 已提交
546

E
ester.zhou 已提交
547
getImage(wallpaperType: WallpaperType, callback: AsyncCallback&lt;image.PixelMap&gt;): void;
Z
zengyawen 已提交
548

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

E
ester.zhou 已提交
551
**Required permissions**: ohos.permission.GET_WALLPAPER
E
ester.zhou 已提交
552

Z
zengyawen 已提交
553 554
**System capability**: SystemCapability.MiscServices.Wallpaper

E
ester.zhou 已提交
555 556
**System API**: This is a system API.

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

E
ester.zhou 已提交
559
| Name| Type| Mandatory| Description|
E
ester.zhou 已提交
560
| -------- | -------- | -------- | -------- |
E
ester.zhou 已提交
561
| wallpaperType | [WallpaperType](#wallpapertype7) | Yes| Wallpaper type.|
E
esterzhou 已提交
562
| callback | AsyncCallback&lt;[image.PixelMap](js-apis-image.md#pixelmap7)&gt; | 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.|
E
ester.zhou 已提交
563 564 565

**Example**

E
ester.zhou 已提交
566 567 568 569 570 571 572 573 574
```js
wallpaper.getImage(wallpaper.WallpaperType.WALLPAPER_SYSTEM, function (error, data) {
    if (error) {
        console.error(`failed to getImage because: ${JSON.stringify(error)}`);
        return;
    }
    console.log(`success to getImage: ${JSON.stringify(data)}`);
});
```
Z
zengyawen 已提交
575 576


E
ester.zhou 已提交
577
## wallpaper.getImage<sup>9+</sup>
Z
zengyawen 已提交
578

E
ester.zhou 已提交
579
getImage(wallpaperType: WallpaperType): Promise&lt;image.PixelMap&gt;
Z
zengyawen 已提交
580

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

E
ester.zhou 已提交
583
**Required permissions**: ohos.permission.GET_WALLPAPER
Z
zengyawen 已提交
584

E
ester.zhou 已提交
585
**System capability**: SystemCapability.MiscServices.Wallpaper
E
ester.zhou 已提交
586

E
ester.zhou 已提交
587 588 589 590 591 592
**System API**: This is a system API.

**Parameters**

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

E
ester.zhou 已提交
595
**Return value**
Z
zengyawen 已提交
596

E
ester.zhou 已提交
597
| Type| Description|
E
ester.zhou 已提交
598
| -------- | -------- |
E
esterzhou 已提交
599
| Promise&lt;[image.PixelMap](js-apis-image.md#pixelmap7)&gt; | Promise used to return the result. If the operation is successful, the pixel map of the wallpaper is returned. Otherwise, error information is returned.|
Z
zengyawen 已提交
600

E
ester.zhou 已提交
601 602
**Example**

E
ester.zhou 已提交
603 604 605
```js
wallpaper.getImage(wallpaper.WallpaperType.WALLPAPER_SYSTEM).then((data) => {
    console.log(`success to getImage: ${JSON.stringify(data)}`);
E
ester.zhou 已提交
606
  }).catch((error) => {
E
ester.zhou 已提交
607 608 609
    console.error(`failed to getImage because: ${JSON.stringify(error)}`);
});
```
Z
zengyawen 已提交
610

E
ester.zhou 已提交
611
## wallpaper.on('colorChange')<sup>(deprecated)</sup>
E
ester.zhou 已提交
612

E
ester.zhou 已提交
613
on(type: 'colorChange', callback: (colors: Array&lt;RgbaColor&gt;, wallpaperType: WallpaperType) =&gt; void): void
E
ester.zhou 已提交
614

E
ester.zhou 已提交
615
Subscribes to the wallpaper color change event.
E
ester.zhou 已提交
616

E
ester.zhou 已提交
617 618 619 620
> **NOTE**
> 
> This API is supported since API version 7 and deprecated since API version 9.

E
ester.zhou 已提交
621 622
**System capability**: SystemCapability.MiscServices.Wallpaper

E
ester.zhou 已提交
623
**Parameters**
E
ester.zhou 已提交
624

E
ester.zhou 已提交
625 626 627
| Name| Type| Mandatory| Description|
| -------- | -------- | -------- | -------- |
| type | string | Yes| Type of the event to subscribe to. The value **'colorChange'** indicates subscribing to the wallpaper color change event.|
E
ester.zhou 已提交
628
| 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.|
E
ester.zhou 已提交
629 630 631

**Example**

E
ester.zhou 已提交
632
```js
E
esterzhou 已提交
633 634 635 636 637 638 639 640
try {
    let listener = (colors, wallpaperType) => {
        console.log(`wallpaper color changed.`);
    };
    wallpaper.on('colorChange', listener);
} catch (error) {
    console.error(`failed to on because: ${JSON.stringify(error)}`);
}
E
ester.zhou 已提交
641
```
Z
zengyawen 已提交
642

E
ester.zhou 已提交
643
## wallpaper.off('colorChange')<sup>(deprecated)</sup>
Z
zengyawen 已提交
644

E
ester.zhou 已提交
645
off(type: 'colorChange', callback?: (colors: Array&lt;RgbaColor&gt;, wallpaperType: WallpaperType) =&gt; void): void
Z
zengyawen 已提交
646

E
ester.zhou 已提交
647
Unsubscribes from the wallpaper color change event.
Z
zengyawen 已提交
648

E
ester.zhou 已提交
649 650 651 652
> **NOTE**
> 
> This API is supported since API version 7 and deprecated since API version 9.

E
ester.zhou 已提交
653
**System capability**: SystemCapability.MiscServices.Wallpaper
E
ester.zhou 已提交
654

E
ester.zhou 已提交
655
**Parameters**
Z
zengyawen 已提交
656

E
ester.zhou 已提交
657
| Name| Type| Mandatory| Description|
E
ester.zhou 已提交
658
| -------- | -------- | -------- | -------- |
E
ester.zhou 已提交
659
| type | string | Yes| Type of the event to unsubscribe from. The value **'colorChange'** indicates unsubscribing from the wallpaper color change event.|
E
ester.zhou 已提交
660
| 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.|
Z
zengyawen 已提交
661

E
ester.zhou 已提交
662 663
**Example**

E
ester.zhou 已提交
664 665 666 667
```js
let listener = (colors, wallpaperType) => {
    console.log(`wallpaper color changed.`);
};
E
esterzhou 已提交
668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686
try {
    wallpaper.on('colorChange', listener);
} catch (error) {
    console.error(`failed to on because: ${JSON.stringify(error)}`);
}

try {
    // Unsubscribe from the listener.
    wallpaper.off('colorChange', listener);
} catch (error) {
    console.error(`failed to off because: ${JSON.stringify(error)}`);
}

try {
    // Unsubscribe from all subscriptions of the colorChange type.
    wallpaper.off('colorChange');
} catch (error) {
    console.error(`failed to off because: ${JSON.stringify(error)}`);
}
E
ester.zhou 已提交
687
```
Z
zengyawen 已提交
688

E
ester.zhou 已提交
689
## wallpaper.getColors<sup>(deprecated)</sup>
Z
zengyawen 已提交
690

E
ester.zhou 已提交
691
getColors(wallpaperType: WallpaperType, callback: AsyncCallback&lt;Array&lt;RgbaColor&gt;&gt;): void
Z
zengyawen 已提交
692

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

E
ester.zhou 已提交
695 696
> **NOTE**
> 
E
ester.zhou 已提交
697
> This API is supported since API version 7 and deprecated since API version 9.
E
ester.zhou 已提交
698

Z
zengyawen 已提交
699 700
**System capability**: SystemCapability.MiscServices.Wallpaper

E
ester.zhou 已提交
701
**Parameters**
Z
zengyawen 已提交
702

E
ester.zhou 已提交
703 704
| Name| Type| Mandatory| Description|
| -------- | -------- | -------- | -------- |
E
ester.zhou 已提交
705 706
| wallpaperType | [WallpaperType](#wallpapertype7) | Yes| Wallpaper type.|
| callback | AsyncCallback&lt;Array&lt;[RgbaColor](#rgbacolordeprecated)&gt;&gt; | Yes| Callback used to return the main color information of the wallpaper.|
E
ester.zhou 已提交
707 708 709

**Example**

E
ester.zhou 已提交
710 711 712 713 714 715 716 717 718
```js
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: ${JSON.stringify(data)}`);
});
```
Z
zengyawen 已提交
719

E
ester.zhou 已提交
720
## wallpaper.getColors<sup>(deprecated)</sup>
Z
zengyawen 已提交
721

E
ester.zhou 已提交
722
getColors(wallpaperType: WallpaperType): Promise&lt;Array&lt;RgbaColor&gt;&gt;
E
ester.zhou 已提交
723

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

E
ester.zhou 已提交
726 727
> **NOTE**
> 
E
ester.zhou 已提交
728
> This API is supported since API version 7 and deprecated since API version 9.
E
ester.zhou 已提交
729 730 731

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

E
ester.zhou 已提交
732 733 734 735
**Parameters**

| Name| Type| Mandatory| Description|
| -------- | -------- | -------- | -------- |
E
ester.zhou 已提交
736
| wallpaperType | [WallpaperType](#wallpapertype7) | Yes| Wallpaper type.|
E
ester.zhou 已提交
737

E
ester.zhou 已提交
738 739 740 741
**Return value**

| Type| Description|
| -------- | -------- |
E
ester.zhou 已提交
742
| Promise&lt;Array&lt;[RgbaColor](#rgbacolordeprecated)&gt;&gt; | Promise used to return the main color information of the wallpaper.|
E
ester.zhou 已提交
743 744 745

**Example**

E
ester.zhou 已提交
746 747 748 749 750 751 752
```js
wallpaper.getColors(wallpaper.WallpaperType.WALLPAPER_SYSTEM).then((data) => {
    console.log(`success to getColors: ${JSON.stringify(data)}`);
  }).catch((error) => {
    console.error(`failed to getColors because: ${JSON.stringify(error)}`);
});
```
E
ester.zhou 已提交
753

E
ester.zhou 已提交
754
## wallpaper.getId<sup>(deprecated)</sup>
Z
zengyawen 已提交
755

E
ester.zhou 已提交
756
getId(wallpaperType: WallpaperType, callback: AsyncCallback&lt;number&gt;): void
Z
zengyawen 已提交
757

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

E
ester.zhou 已提交
760 761
> **NOTE**
> 
E
ester.zhou 已提交
762
> This API is supported since API version 7 and deprecated since API version 9.
E
ester.zhou 已提交
763

Z
zengyawen 已提交
764 765
**System capability**: SystemCapability.MiscServices.Wallpaper

E
ester.zhou 已提交
766
**Parameters**
Z
zengyawen 已提交
767

E
ester.zhou 已提交
768
| Name| Type| Mandatory| Description|
E
ester.zhou 已提交
769
| -------- | -------- | -------- | -------- |
E
ester.zhou 已提交
770
| wallpaperType | [WallpaperType](#wallpapertype7) | Yes| Wallpaper type.|
E
esterzhou 已提交
771
| 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 已提交
772 773 774

**Example**

E
ester.zhou 已提交
775 776 777 778 779 780 781 782 783
```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 已提交
784

E
ester.zhou 已提交
785
## wallpaper.getId<sup>(deprecated)</sup>
Z
zengyawen 已提交
786

E
ester.zhou 已提交
787
getId(wallpaperType: WallpaperType): Promise&lt;number&gt;
Z
zengyawen 已提交
788

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

E
ester.zhou 已提交
791 792
> **NOTE**
> 
E
ester.zhou 已提交
793
> This API is supported since API version 7 and deprecated since API version 9.
E
ester.zhou 已提交
794

Z
zengyawen 已提交
795 796
**System capability**: SystemCapability.MiscServices.Wallpaper

E
ester.zhou 已提交
797 798 799 800
**Parameters**

| Name| Type| Mandatory| Description|
| -------- | -------- | -------- | -------- |
E
ester.zhou 已提交
801
| wallpaperType | [WallpaperType](#wallpapertype7) | Yes| Wallpaper type.|
E
ester.zhou 已提交
802

E
ester.zhou 已提交
803
**Return value**
Z
zengyawen 已提交
804

E
ester.zhou 已提交
805
| Type| Description|
E
ester.zhou 已提交
806
| -------- | -------- |
E
esterzhou 已提交
807
| 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 已提交
808 809 810

**Example**

E
ester.zhou 已提交
811 812 813
```js
wallpaper.getId(wallpaper.WallpaperType.WALLPAPER_SYSTEM).then((data) => {
    console.log(`success to getId: ${JSON.stringify(data)}`);
E
ester.zhou 已提交
814
  }).catch((error) => {
E
ester.zhou 已提交
815 816 817
    console.error(`failed to getId because: ${JSON.stringify(error)}`);
});
```
Z
zengyawen 已提交
818

E
ester.zhou 已提交
819
## wallpaper.getMinHeight<sup>(deprecated)</sup>
Z
zengyawen 已提交
820

E
ester.zhou 已提交
821
getMinHeight(callback: AsyncCallback&lt;number&gt;): void
E
ester.zhou 已提交
822

E
ester.zhou 已提交
823
Obtains the minimum height of this wallpaper. This API uses an asynchronous callback to return the result.
E
ester.zhou 已提交
824

E
ester.zhou 已提交
825 826
> **NOTE**
> 
E
ester.zhou 已提交
827
> This API is supported since API version 7 and deprecated since API version 9.
E
ester.zhou 已提交
828 829 830

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

E
ester.zhou 已提交
831
**Parameters**
E
ester.zhou 已提交
832

E
ester.zhou 已提交
833 834 835
| Name| Type| Mandatory| Description|
| -------- | -------- | -------- | -------- |
| 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 已提交
836 837 838

**Example**

E
ester.zhou 已提交
839 840 841 842 843 844 845 846 847
```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)}`);
});
```
E
ester.zhou 已提交
848

E
ester.zhou 已提交
849
## wallpaper.getMinHeight<sup>(deprecated)</sup>
Z
zengyawen 已提交
850

E
ester.zhou 已提交
851
getMinHeight(): Promise&lt;number&gt;
Z
zengyawen 已提交
852

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

E
ester.zhou 已提交
855 856
> **NOTE**
> 
E
ester.zhou 已提交
857
> This API is supported since API version 7 and deprecated since API version 9.
E
ester.zhou 已提交
858

Z
zengyawen 已提交
859 860
**System capability**: SystemCapability.MiscServices.Wallpaper

E
ester.zhou 已提交
861
**Return value**
Z
zengyawen 已提交
862

E
ester.zhou 已提交
863 864 865
| Type| Description|
| -------- | -------- |
| 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.|
E
ester.zhou 已提交
866 867 868

**Example**

E
ester.zhou 已提交
869 870 871 872 873 874 875
```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 已提交
876

E
ester.zhou 已提交
877
## wallpaper.getMinWidth<sup>(deprecated)</sup>
Z
zengyawen 已提交
878

E
ester.zhou 已提交
879
getMinWidth(callback: AsyncCallback&lt;number&gt;): void
Z
zengyawen 已提交
880

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

E
ester.zhou 已提交
883 884
> **NOTE**
> 
E
ester.zhou 已提交
885
> This API is supported since API version 7 and deprecated since API version 9.
E
ester.zhou 已提交
886

Z
zengyawen 已提交
887 888
**System capability**: SystemCapability.MiscServices.Wallpaper

E
ester.zhou 已提交
889
**Parameters**
Z
zengyawen 已提交
890

E
ester.zhou 已提交
891 892 893
| Name| Type| Mandatory| Description|
| -------- | -------- | -------- | -------- |
| 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.|
E
ester.zhou 已提交
894 895 896

**Example**

E
ester.zhou 已提交
897 898 899 900 901 902 903 904 905
```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 已提交
906

E
ester.zhou 已提交
907
## wallpaper.getMinWidth<sup>(deprecated)</sup>
Z
zengyawen 已提交
908

E
ester.zhou 已提交
909
getMinWidth(): Promise&lt;number&gt;
E
ester.zhou 已提交
910

E
ester.zhou 已提交
911
Obtains the minimum width of this wallpaper. This API uses a promise to return the result.
E
ester.zhou 已提交
912

E
ester.zhou 已提交
913 914
> **NOTE**
> 
E
ester.zhou 已提交
915
> This API is supported since API version 7 and deprecated since API version 9.
E
ester.zhou 已提交
916 917 918 919 920 921 922

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

**Return value**

| Type| Description|
| -------- | -------- |
E
ester.zhou 已提交
923
| 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 已提交
924 925 926

**Example**

E
ester.zhou 已提交
927 928 929 930 931 932 933
```js
wallpaper.getMinWidth().then((data) => {
    console.log(`success to getMinWidth: ${JSON.stringify(data)}`);
  }).catch((error) => {
    console.error(`failed to getMinWidth because: ${JSON.stringify(error)}`);
});
```
E
ester.zhou 已提交
934

E
ester.zhou 已提交
935
## wallpaper.isChangePermitted<sup>(deprecated)</sup>
Z
zengyawen 已提交
936

E
ester.zhou 已提交
937
isChangePermitted(callback: AsyncCallback&lt;boolean&gt;): void
Z
zengyawen 已提交
938

E
ester.zhou 已提交
939
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 已提交
940

E
ester.zhou 已提交
941 942
> **NOTE**
> 
E
ester.zhou 已提交
943
> This API is supported since API version 7 and deprecated since API version 9.
Z
zengyawen 已提交
944 945 946

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

E
ester.zhou 已提交
947
**Parameters**
Z
zengyawen 已提交
948

E
ester.zhou 已提交
949
| Name| Type| Mandatory| Description|
E
ester.zhou 已提交
950
| -------- | -------- | -------- | -------- |
E
ester.zhou 已提交
951
| 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 已提交
952 953 954

**Example**

E
ester.zhou 已提交
955 956 957 958 959 960 961 962 963
```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 已提交
964

E
ester.zhou 已提交
965
## wallpaper.isChangePermitted<sup>(deprecated)</sup>
Z
zengyawen 已提交
966

E
ester.zhou 已提交
967
isChangePermitted(): Promise&lt;boolean&gt;
Z
zengyawen 已提交
968

E
ester.zhou 已提交
969
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 已提交
970

E
ester.zhou 已提交
971
> **NOTE**
E
ester.zhou 已提交
972
> 
E
ester.zhou 已提交
973
> This API is supported since API version 7 and deprecated since API version 9.
Z
zengyawen 已提交
974 975 976

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

E
ester.zhou 已提交
977 978
**Return value**

E
ester.zhou 已提交
979
| Type| Description|
E
ester.zhou 已提交
980
| -------- | -------- |
E
ester.zhou 已提交
981
| 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 已提交
982 983 984

**Example**

E
ester.zhou 已提交
985 986 987 988 989 990 991
```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 已提交
992

E
ester.zhou 已提交
993
## wallpaper.isOperationAllowed<sup>(deprecated)</sup>
E
ester.zhou 已提交
994

E
ester.zhou 已提交
995
isOperationAllowed(callback: AsyncCallback&lt;boolean&gt;): void
E
ester.zhou 已提交
996

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

E
ester.zhou 已提交
999 1000
> **NOTE**
> 
E
ester.zhou 已提交
1001
> This API is supported since API version 7 and deprecated since API version 9.
E
ester.zhou 已提交
1002 1003 1004 1005 1006 1007 1008

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

**Parameters**

| Name| Type| Mandatory| Description|
| -------- | -------- | -------- | -------- |
E
ester.zhou 已提交
1009
| 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 已提交
1010 1011 1012

**Example**

E
ester.zhou 已提交
1013 1014 1015 1016 1017 1018 1019 1020 1021
```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)}`);
});
```
E
ester.zhou 已提交
1022

E
ester.zhou 已提交
1023
## wallpaper.isOperationAllowed<sup>(deprecated)</sup>
E
ester.zhou 已提交
1024

E
ester.zhou 已提交
1025
isOperationAllowed(): Promise&lt;boolean&gt;
E
ester.zhou 已提交
1026

E
ester.zhou 已提交
1027
Checks whether the user is allowed to set wallpapers. This API uses a promise to return the result.
E
ester.zhou 已提交
1028

E
ester.zhou 已提交
1029 1030
> **NOTE**
> 
E
ester.zhou 已提交
1031
> This API is supported since API version 7 and deprecated since API version 9.
E
ester.zhou 已提交
1032 1033 1034 1035 1036 1037 1038

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

**Return value**

| Type| Description|
| -------- | -------- |
E
ester.zhou 已提交
1039
| 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 已提交
1040 1041 1042

**Example**

E
ester.zhou 已提交
1043 1044 1045
```js
wallpaper.isOperationAllowed().then((data) => {
    console.log(`success to isOperationAllowed: ${JSON.stringify(data)}`);
E
ester.zhou 已提交
1046
  }).catch((error) => {
E
ester.zhou 已提交
1047 1048 1049
    console.error(`failed to isOperationAllowed because: ${JSON.stringify(error)}`);
});
```
E
ester.zhou 已提交
1050

E
ester.zhou 已提交
1051
## wallpaper.reset<sup>(deprecated)</sup>
Z
zengyawen 已提交
1052

E
ester.zhou 已提交
1053
reset(wallpaperType: WallpaperType, callback: AsyncCallback&lt;void&gt;): void
Z
zengyawen 已提交
1054

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

E
ester.zhou 已提交
1057 1058
> **NOTE**
> 
E
ester.zhou 已提交
1059
> This API is supported since API version 7 and deprecated since API version 9.
E
ester.zhou 已提交
1060

E
ester.zhou 已提交
1061
**Required permissions**: ohos.permission.SET_WALLPAPER
Z
zengyawen 已提交
1062 1063 1064

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

E
ester.zhou 已提交
1065 1066
**Parameters**

E
ester.zhou 已提交
1067
| Name| Type| Mandatory| Description|
E
ester.zhou 已提交
1068
| -------- | -------- | -------- | -------- |
E
ester.zhou 已提交
1069
| wallpaperType | [WallpaperType](#wallpapertype7) | Yes| Wallpaper type.|
E
esterzhou 已提交
1070
| callback | AsyncCallback&lt;void&gt; | Yes| Callback used to return the result. If the wallpaper is reset, **err** is **undefined**. Otherwise, **err** is an error object.|
E
ester.zhou 已提交
1071 1072 1073

**Example**

E
ester.zhou 已提交
1074 1075 1076 1077 1078 1079 1080 1081 1082
```js
wallpaper.reset(wallpaper.WallpaperType.WALLPAPER_SYSTEM, (error) => {
    if (error) {
        console.error(`failed to reset because: ${JSON.stringify(error)}`);
        return;
    }
    console.log(`success to reset.`);
});
```
Z
zengyawen 已提交
1083

E
ester.zhou 已提交
1084
## wallpaper.reset<sup>(deprecated)</sup>
Z
zengyawen 已提交
1085

E
ester.zhou 已提交
1086
reset(wallpaperType: WallpaperType): Promise&lt;void&gt;
Z
zengyawen 已提交
1087

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

E
ester.zhou 已提交
1090
> **NOTE**
E
ester.zhou 已提交
1091
>
E
ester.zhou 已提交
1092
> This API is supported since API version 7 and deprecated since API version 9.
E
ester.zhou 已提交
1093

E
ester.zhou 已提交
1094
**Required permissions**: ohos.permission.SET_WALLPAPER
Z
zengyawen 已提交
1095 1096 1097

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

E
ester.zhou 已提交
1098
**Parameters**
Z
zengyawen 已提交
1099

E
ester.zhou 已提交
1100
| Name| Type| Mandatory| Description|
E
ester.zhou 已提交
1101
| -------- | -------- | -------- | -------- |
E
ester.zhou 已提交
1102
| wallpaperType | [WallpaperType](#wallpapertype7) | Yes| Wallpaper type.|
Z
zengyawen 已提交
1103

E
ester.zhou 已提交
1104 1105
**Return value**

E
ester.zhou 已提交
1106
| Type| Description|
E
ester.zhou 已提交
1107
| -------- | -------- |
E
ester.zhou 已提交
1108
| Promise&lt;void&gt; | Promise that returns no value.|
E
ester.zhou 已提交
1109 1110 1111

**Example**

E
ester.zhou 已提交
1112 1113 1114 1115 1116 1117 1118
```js
wallpaper.reset(wallpaper.WallpaperType.WALLPAPER_SYSTEM).then(() => {
    console.log(`success to reset.`);
}).catch((error) => {
    console.error(`failed to reset because: ${JSON.stringify(error)}`);
});
```
E
ester.zhou 已提交
1119

E
ester.zhou 已提交
1120
## wallpaper.setWallpaper<sup>(deprecated)</sup>
E
ester.zhou 已提交
1121

E
ester.zhou 已提交
1122
setWallpaper(source: string | image.PixelMap, wallpaperType: WallpaperType, callback: AsyncCallback&lt;void&gt;): void
E
ester.zhou 已提交
1123 1124 1125

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

E
ester.zhou 已提交
1126 1127
> **NOTE**
> 
E
ester.zhou 已提交
1128
> This API is supported since API version 7 and deprecated since API version 9.
E
ester.zhou 已提交
1129

E
ester.zhou 已提交
1130 1131 1132 1133 1134 1135 1136 1137
**Required permissions**: ohos.permission.SET_WALLPAPER

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

**Parameters**

| Name| Type| Mandatory| Description|
| -------- | -------- | -------- | -------- |
E
esterzhou 已提交
1138
| source | string \| [image.PixelMap](js-apis-image.md#pixelmap7) | Yes| URI of a JPEG or PNG file, or pixel map of a PNG file.|
E
ester.zhou 已提交
1139
| wallpaperType | [WallpaperType](#wallpapertype7) | Yes| Wallpaper type.|
E
esterzhou 已提交
1140
| callback | AsyncCallback&lt;void&gt; | Yes| Callback used to return the result. If the wallpaper is set, **err** is **undefined**. Otherwise, **err** is an error object.|
E
ester.zhou 已提交
1141 1142 1143

**Example**

E
ester.zhou 已提交
1144
```js
E
esterzhou 已提交
1145
// The source type is string.
E
ester.zhou 已提交
1146
let wallpaperPath = "/data/storage/el2/base/haps/entry/files/js.jpeg";
E
ester.zhou 已提交
1147 1148 1149 1150 1151 1152 1153 1154 1155 1156 1157 1158 1159 1160 1161 1162 1163 1164 1165 1166 1167 1168 1169 1170 1171 1172 1173 1174 1175
wallpaper.setWallpaper(wallpaperPath, wallpaper.WallpaperType.WALLPAPER_SYSTEM, (error) => {
    if (error) {
        console.error(`failed to setWallpaper because: ${JSON.stringify(error)}`);
       return;
       }
    console.log(`success to setWallpaper.`);
});

// 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.setWallpaper(pixelMap, wallpaper.WallpaperType.WALLPAPER_SYSTEM, (error) => {
        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 已提交
1176

E
ester.zhou 已提交
1177
## wallpaper.setWallpaper<sup>(deprecated)</sup>
E
ester.zhou 已提交
1178

E
ester.zhou 已提交
1179
setWallpaper(source: string | image.PixelMap, wallpaperType: WallpaperType): Promise&lt;void&gt;
E
ester.zhou 已提交
1180

E
ester.zhou 已提交
1181
Sets a specified source as the wallpaper of a specified type. This API uses a promise to return the result.
E
ester.zhou 已提交
1182

E
ester.zhou 已提交
1183 1184
> **NOTE**
> 
E
ester.zhou 已提交
1185
> This API is supported since API version 7 and deprecated since API version 9.
E
ester.zhou 已提交
1186 1187 1188 1189 1190 1191 1192 1193 1194

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

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

**Parameters**

| Name| Type| Mandatory| Description|
| -------- | -------- | -------- | -------- |
E
esterzhou 已提交
1195
| source | string \| [image.PixelMap](js-apis-image.md#pixelmap7) | Yes| URI of a JPEG or PNG file, or pixel map of a PNG file.|
E
ester.zhou 已提交
1196
| wallpaperType | [WallpaperType](#wallpapertype7) | Yes| Wallpaper type.|
E
ester.zhou 已提交
1197 1198 1199 1200 1201

**Return value**

| Type| Description|
| -------- | -------- |
E
ester.zhou 已提交
1202
| Promise&lt;void&gt; | Promise that returns no value.|
E
ester.zhou 已提交
1203 1204 1205

**Example**

E
ester.zhou 已提交
1206
```js
E
esterzhou 已提交
1207
// The source type is string.
E
ester.zhou 已提交
1208
let wallpaperPath = "/data/storage/el2/base/haps/entry/files/js.jpeg";
E
ester.zhou 已提交
1209 1210
wallpaper.setWallpaper(wallpaperPath, wallpaper.WallpaperType.WALLPAPER_SYSTEM).then(() => {
    console.log(`success to setWallpaper.`);
E
ester.zhou 已提交
1211
  }).catch((error) => {
E
ester.zhou 已提交
1212 1213
    console.error(`failed to setWallpaper because: ${JSON.stringify(error)}`);
});
E
ester.zhou 已提交
1214
  
E
ester.zhou 已提交
1215 1216 1217 1218 1219 1220 1221 1222 1223 1224 1225 1226 1227 1228 1229 1230 1231 1232 1233
// 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.setWallpaper(pixelMap, wallpaper.WallpaperType.WALLPAPER_SYSTEM).then(() => {
        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 已提交
1234 1235


E
ester.zhou 已提交
1236
## wallpaper.getFile<sup>(deprecated)</sup>
Z
zengyawen 已提交
1237 1238 1239

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

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

E
ester.zhou 已提交
1242 1243
> **NOTE**
> 
E
ester.zhou 已提交
1244
> This API is supported since API version 8 and deprecated since API version 9.
E
ester.zhou 已提交
1245

1246
**Required permissions**: ohos.permission.GET_WALLPAPER
Z
zengyawen 已提交
1247 1248 1249

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

E
ester.zhou 已提交
1250
**Parameters**
Z
zengyawen 已提交
1251

E
ester.zhou 已提交
1252
| Name| Type| Mandatory| Description|
E
ester.zhou 已提交
1253
| -------- | -------- | -------- | -------- |
E
ester.zhou 已提交
1254
| wallpaperType | [WallpaperType](#wallpapertype7) | Yes| Wallpaper type.|
E
ester.zhou 已提交
1255
| 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 已提交
1256 1257 1258

**Example**

E
ester.zhou 已提交
1259 1260 1261 1262 1263 1264 1265 1266 1267
```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 已提交
1268

E
ester.zhou 已提交
1269
## wallpaper.getFile<sup>(deprecated)</sup>
Z
zengyawen 已提交
1270 1271 1272

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

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

E
ester.zhou 已提交
1275 1276
> **NOTE**
>
E
ester.zhou 已提交
1277
> This API is supported since API version 8 and deprecated since API version 9.
E
ester.zhou 已提交
1278

1279
**Required permissions**: ohos.permission.GET_WALLPAPER
Z
zengyawen 已提交
1280 1281 1282

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

E
ester.zhou 已提交
1283
**Parameters**
Z
zengyawen 已提交
1284

E
ester.zhou 已提交
1285
| Name| Type| Mandatory| Description|
E
ester.zhou 已提交
1286
| -------- | -------- | -------- | -------- |
E
ester.zhou 已提交
1287
| wallpaperType | [WallpaperType](#wallpapertype7) | Yes| Wallpaper type.|
Z
zengyawen 已提交
1288

E
ester.zhou 已提交
1289 1290
**Return value**

E
ester.zhou 已提交
1291
| Type| Description|
E
ester.zhou 已提交
1292
| -------- | -------- |
E
ester.zhou 已提交
1293
| 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 已提交
1294 1295 1296

**Example**

E
ester.zhou 已提交
1297 1298 1299
```js
wallpaper.getFile(wallpaper.WallpaperType.WALLPAPER_SYSTEM).then((data) => {
    console.log(`success to getFile: ${JSON.stringify(data)}`);
E
ester.zhou 已提交
1300
  }).catch((error) => {
E
ester.zhou 已提交
1301 1302 1303
    console.error(`failed to getFile because: ${JSON.stringify(error)}`);
});
```
E
ester.zhou 已提交
1304

E
ester.zhou 已提交
1305
## wallpaper.getPixelMap<sup>(deprecated)</sup>
E
ester.zhou 已提交
1306 1307 1308

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

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

E
ester.zhou 已提交
1311 1312
> **NOTE**
>
E
ester.zhou 已提交
1313
> This API is supported since API version 7 and deprecated since API version 9.
E
ester.zhou 已提交
1314

1315
**Required permissions**: ohos.permission.GET_WALLPAPER
E
ester.zhou 已提交
1316 1317 1318

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

E
ester.zhou 已提交
1319
**System API**: This is a system API.
E
ester.zhou 已提交
1320

E
ester.zhou 已提交
1321 1322 1323 1324
**Parameters**

| Name| Type| Mandatory| Description|
| -------- | -------- | -------- | -------- |
E
ester.zhou 已提交
1325
| wallpaperType | [WallpaperType](#wallpapertype7) | Yes| Wallpaper type.|
E
esterzhou 已提交
1326
| callback | AsyncCallback&lt;image.PixelMap&gt; | 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.|
E
ester.zhou 已提交
1327 1328 1329

**Example**

E
ester.zhou 已提交
1330 1331 1332 1333 1334 1335 1336
```js
wallpaper.getPixelMap(wallpaper.WallpaperType.WALLPAPER_SYSTEM, function (error, data) {
    if (error) {
        console.error(`failed to getPixelMap because: ${JSON.stringify(error)}`);
        return;
    }
    console.log(`success to getPixelMap : ${JSON.stringify(data)}`);
E
ester.zhou 已提交
1337
  });
E
ester.zhou 已提交
1338
```
E
ester.zhou 已提交
1339

E
ester.zhou 已提交
1340
## wallpaper.getPixelMap<sup>(deprecated)</sup>
E
ester.zhou 已提交
1341 1342 1343

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

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

E
ester.zhou 已提交
1346 1347
> **NOTE**
>
E
ester.zhou 已提交
1348
> This API is supported since API version 7 and deprecated since API version 9.
E
ester.zhou 已提交
1349

1350
**Required permissions**: ohos.permission.GET_WALLPAPER
E
ester.zhou 已提交
1351 1352 1353

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

E
ester.zhou 已提交
1354
**System API**: This is a system API.
E
ester.zhou 已提交
1355

E
ester.zhou 已提交
1356 1357 1358 1359
**Parameters**

| Name| Type| Mandatory| Description|
| -------- | -------- | -------- | -------- |
E
ester.zhou 已提交
1360
| wallpaperType | [WallpaperType](#wallpapertype7) | Yes| Wallpaper type.|
E
ester.zhou 已提交
1361 1362 1363 1364 1365

**Return value**

| Type| Description|
| -------- | -------- |
E
esterzhou 已提交
1366
| Promise&lt;image.PixelMap&gt; | Promise used to return the result. If the operation is successful, the pixel map of the wallpaper is returned. Otherwise, error information is returned.|
E
ester.zhou 已提交
1367 1368 1369

**Example**

E
ester.zhou 已提交
1370 1371 1372 1373 1374 1375 1376
```js
wallpaper.getPixelMap(wallpaper.WallpaperType.WALLPAPER_SYSTEM).then((data) => {
    console.log(`success to getPixelMap : ${JSON.stringify(data)}`);
  }).catch((error) => {
    console.error(`failed to getPixelMap because: ${JSON.stringify(error)}`);
});
```