js-apis-wallpaper.md 40.9 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 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
## 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)}`);
}
```

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

on(type: 'wallpaperChange', callback: (wallpaperType: WallpaperType, resourceType: WallpaperResourceType) =&gt; void): void

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'**.|
| callback | function | Yes| Callback used to return the wallpaper type and wallpaper resource type.<br>- wallpaperType<br>  Wallpaper type.<br>- resourceType<br>  Wallpaper resource type.|

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

off(type: 'wallpaperChange', callback?: (wallpaperType: WallpaperType, resourceType: WallpaperResourceType) =&gt; void): void

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'**.|
| 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<br>  Wallpaper type.<br>- resourceType<br>  Wallpaper resource type.|

**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 已提交
214 215 216 217 218
## 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 已提交
219

Z
zengyawen 已提交
220 221
**System capability**: SystemCapability.MiscServices.Wallpaper

E
ester.zhou 已提交
222 223
**System API**: This is a system API.

E
ester.zhou 已提交
224
**Parameters**
E
ester.zhou 已提交
225 226

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

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

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

E
ester.zhou 已提交
236
**Example**
Z
zengyawen 已提交
237

E
ester.zhou 已提交
238
```js
E
esterzhou 已提交
239 240 241 242 243 244
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 已提交
245
```
Z
zengyawen 已提交
246

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

E
ester.zhou 已提交
249
getMinHeightSync(): number
E
ester.zhou 已提交
250

E
ester.zhou 已提交
251
Obtains the minimum height of this wallpaper.
E
ester.zhou 已提交
252

E
ester.zhou 已提交
253 254
**System capability**: SystemCapability.MiscServices.Wallpaper

E
ester.zhou 已提交
255 256
**System API**: This is a system API.

E
ester.zhou 已提交
257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276
**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 已提交
277 278
**System API**: This is a system API.

E
ester.zhou 已提交
279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300
**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 已提交
301 302
**System API**: This is a system API.

E
ester.zhou 已提交
303 304 305 306
**Parameters**

| Name| Type| Mandatory| Description|
| -------- | -------- | -------- | -------- |
E
ester.zhou 已提交
307
| wallpaperType | [WallpaperType](#wallpapertype7) | Yes| Wallpaper type.|
E
esterzhou 已提交
308
| 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 已提交
309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328

**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 已提交
329 330 331

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

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

E
ester.zhou 已提交
334 335 336 337
**Parameters**

| Name| Type| Mandatory| Description|
| -------- | -------- | -------- | -------- |
E
ester.zhou 已提交
338
| wallpaperType | [WallpaperType](#wallpapertype7) | Yes| Wallpaper type.|
E
ester.zhou 已提交
339 340 341 342 343

**Return value**

| Type| Description|
| -------- | -------- |
E
ester.zhou 已提交
344
| Promise&lt;void&gt; | Promise that returns no value.|
E
ester.zhou 已提交
345 346 347

**Example**

E
ester.zhou 已提交
348 349 350 351 352 353 354
```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 已提交
355

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

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

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

E
ester.zhou 已提交
362
**Required permissions**: ohos.permission.SET_WALLPAPER
E
ester.zhou 已提交
363

Z
zengyawen 已提交
364 365
**System capability**: SystemCapability.MiscServices.Wallpaper

E
ester.zhou 已提交
366 367
**System API**: This is a system API.

E
ester.zhou 已提交
368
**Parameters**
Z
zengyawen 已提交
369

E
ester.zhou 已提交
370
| Name| Type| Mandatory| Description|
E
ester.zhou 已提交
371
| -------- | -------- | -------- | -------- |
E
esterzhou 已提交
372
| 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 已提交
373
| wallpaperType | [WallpaperType](#wallpapertype7) | Yes| Wallpaper type.|
E
esterzhou 已提交
374
| 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 已提交
375 376 377

**Example**

E
ester.zhou 已提交
378
```js
E
esterzhou 已提交
379
// The source type is string.
E
ester.zhou 已提交
380
let wallpaperPath = "/data/storage/el2/base/haps/entry/files/js.jpeg";
E
ester.zhou 已提交
381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409
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 已提交
410

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

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

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

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

E
ester.zhou 已提交
419
**System capability**: SystemCapability.MiscServices.Wallpaper
E
ester.zhou 已提交
420

E
ester.zhou 已提交
421 422
**System API**: This is a system API.

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

E
ester.zhou 已提交
425
| Name| Type| Mandatory| Description|
E
ester.zhou 已提交
426
| -------- | -------- | -------- | -------- |
E
esterzhou 已提交
427
| 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 已提交
428
| wallpaperType | [WallpaperType](#wallpapertype7) | Yes| Wallpaper type.|
Z
zengyawen 已提交
429

E
ester.zhou 已提交
430
**Return value**
Z
zengyawen 已提交
431

E
ester.zhou 已提交
432
| Type| Description|
E
ester.zhou 已提交
433
| -------- | -------- |
E
ester.zhou 已提交
434
| Promise&lt;void&gt; | Promise that returns no value.|
E
ester.zhou 已提交
435 436 437

**Example**

E
ester.zhou 已提交
438
```js
E
esterzhou 已提交
439
// The source type is string.
E
ester.zhou 已提交
440
let wallpaperPath = "/data/storage/el2/base/haps/entry/files/js.jpeg";
E
ester.zhou 已提交
441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465
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 已提交
466

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

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

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

E
ester.zhou 已提交
473
**Required permissions**: ohos.permission.GET_WALLPAPER
E
ester.zhou 已提交
474

Z
zengyawen 已提交
475 476
**System capability**: SystemCapability.MiscServices.Wallpaper

E
ester.zhou 已提交
477 478
**System API**: This is a system API.

E
ester.zhou 已提交
479
**Parameters**
Z
zengyawen 已提交
480

E
ester.zhou 已提交
481
| Name| Type| Mandatory| Description|
E
ester.zhou 已提交
482
| -------- | -------- | -------- | -------- |
E
ester.zhou 已提交
483
| wallpaperType | [WallpaperType](#wallpapertype7) | Yes| Wallpaper type.|
E
esterzhou 已提交
484
| 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 已提交
485 486 487

**Example**

E
ester.zhou 已提交
488 489 490 491 492 493 494 495 496
```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 已提交
497 498


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

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

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

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

E
ester.zhou 已提交
507
**System capability**: SystemCapability.MiscServices.Wallpaper
E
ester.zhou 已提交
508

E
ester.zhou 已提交
509 510 511 512 513 514
**System API**: This is a system API.

**Parameters**

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

E
ester.zhou 已提交
517
**Return value**
Z
zengyawen 已提交
518

E
ester.zhou 已提交
519
| Type| Description|
E
ester.zhou 已提交
520
| -------- | -------- |
E
esterzhou 已提交
521
| 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 已提交
522

E
ester.zhou 已提交
523 524
**Example**

E
ester.zhou 已提交
525 526 527
```js
wallpaper.getImage(wallpaper.WallpaperType.WALLPAPER_SYSTEM).then((data) => {
    console.log(`success to getImage: ${JSON.stringify(data)}`);
E
ester.zhou 已提交
528
  }).catch((error) => {
E
ester.zhou 已提交
529 530 531
    console.error(`failed to getImage because: ${JSON.stringify(error)}`);
});
```
Z
zengyawen 已提交
532

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

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

E
ester.zhou 已提交
537
Subscribes to the wallpaper color change event.
E
ester.zhou 已提交
538

E
ester.zhou 已提交
539 540 541 542
> **NOTE**
> 
> This API is supported since API version 7 and deprecated since API version 9.

E
ester.zhou 已提交
543 544
**System capability**: SystemCapability.MiscServices.Wallpaper

E
ester.zhou 已提交
545
**Parameters**
E
ester.zhou 已提交
546

E
ester.zhou 已提交
547 548 549
| 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 已提交
550
| 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 已提交
551 552 553

**Example**

E
ester.zhou 已提交
554
```js
E
esterzhou 已提交
555 556 557 558 559 560 561 562
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 已提交
563
```
Z
zengyawen 已提交
564

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

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

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

E
ester.zhou 已提交
571 572 573 574
> **NOTE**
> 
> This API is supported since API version 7 and deprecated since API version 9.

E
ester.zhou 已提交
575
**System capability**: SystemCapability.MiscServices.Wallpaper
E
ester.zhou 已提交
576

E
ester.zhou 已提交
577
**Parameters**
Z
zengyawen 已提交
578

E
ester.zhou 已提交
579
| Name| Type| Mandatory| Description|
E
ester.zhou 已提交
580
| -------- | -------- | -------- | -------- |
E
ester.zhou 已提交
581
| type | string | Yes| Type of the event to unsubscribe from. The value **'colorChange'** indicates unsubscribing from the wallpaper color change event.|
E
ester.zhou 已提交
582
| 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 已提交
583

E
ester.zhou 已提交
584 585
**Example**

E
ester.zhou 已提交
586 587 588 589
```js
let listener = (colors, wallpaperType) => {
    console.log(`wallpaper color changed.`);
};
E
esterzhou 已提交
590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608
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 已提交
609
```
Z
zengyawen 已提交
610

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

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

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

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

Z
zengyawen 已提交
621 622
**System capability**: SystemCapability.MiscServices.Wallpaper

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

E
ester.zhou 已提交
625 626
| Name| Type| Mandatory| Description|
| -------- | -------- | -------- | -------- |
E
ester.zhou 已提交
627 628
| 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 已提交
629 630 631

**Example**

E
ester.zhou 已提交
632 633 634 635 636 637 638 639 640
```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 已提交
641

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

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

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

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

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

E
ester.zhou 已提交
654 655 656 657
**Parameters**

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

E
ester.zhou 已提交
660 661 662 663
**Return value**

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

**Example**

E
ester.zhou 已提交
668 669 670 671 672 673 674
```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 已提交
675

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

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

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

E
ester.zhou 已提交
682 683
> **NOTE**
> 
E
ester.zhou 已提交
684
> This API is supported since API version 7 and deprecated since API version 9.
E
ester.zhou 已提交
685

Z
zengyawen 已提交
686 687
**System capability**: SystemCapability.MiscServices.Wallpaper

E
ester.zhou 已提交
688
**Parameters**
Z
zengyawen 已提交
689

E
ester.zhou 已提交
690
| Name| Type| Mandatory| Description|
E
ester.zhou 已提交
691
| -------- | -------- | -------- | -------- |
E
ester.zhou 已提交
692
| wallpaperType | [WallpaperType](#wallpapertype7) | Yes| Wallpaper type.|
E
esterzhou 已提交
693
| 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 已提交
694 695 696

**Example**

E
ester.zhou 已提交
697 698 699 700 701 702 703 704 705
```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 已提交
706

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

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

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

E
ester.zhou 已提交
713 714
> **NOTE**
> 
E
ester.zhou 已提交
715
> This API is supported since API version 7 and deprecated since API version 9.
E
ester.zhou 已提交
716

Z
zengyawen 已提交
717 718
**System capability**: SystemCapability.MiscServices.Wallpaper

E
ester.zhou 已提交
719 720 721 722
**Parameters**

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

E
ester.zhou 已提交
725
**Return value**
Z
zengyawen 已提交
726

E
ester.zhou 已提交
727
| Type| Description|
E
ester.zhou 已提交
728
| -------- | -------- |
E
esterzhou 已提交
729
| 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 已提交
730 731 732

**Example**

E
ester.zhou 已提交
733 734 735
```js
wallpaper.getId(wallpaper.WallpaperType.WALLPAPER_SYSTEM).then((data) => {
    console.log(`success to getId: ${JSON.stringify(data)}`);
E
ester.zhou 已提交
736
  }).catch((error) => {
E
ester.zhou 已提交
737 738 739
    console.error(`failed to getId because: ${JSON.stringify(error)}`);
});
```
Z
zengyawen 已提交
740

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

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

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

E
ester.zhou 已提交
747 748
> **NOTE**
> 
E
ester.zhou 已提交
749
> This API is supported since API version 7 and deprecated since API version 9.
E
ester.zhou 已提交
750 751 752

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

E
ester.zhou 已提交
753
**Parameters**
E
ester.zhou 已提交
754

E
ester.zhou 已提交
755 756 757
| 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 已提交
758 759 760

**Example**

E
ester.zhou 已提交
761 762 763 764 765 766 767 768 769
```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 已提交
770

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

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

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

E
ester.zhou 已提交
777 778
> **NOTE**
> 
E
ester.zhou 已提交
779
> This API is supported since API version 7 and deprecated since API version 9.
E
ester.zhou 已提交
780

Z
zengyawen 已提交
781 782
**System capability**: SystemCapability.MiscServices.Wallpaper

E
ester.zhou 已提交
783
**Return value**
Z
zengyawen 已提交
784

E
ester.zhou 已提交
785 786 787
| 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 已提交
788 789 790

**Example**

E
ester.zhou 已提交
791 792 793 794 795 796 797
```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 已提交
798

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

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

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

E
ester.zhou 已提交
805 806
> **NOTE**
> 
E
ester.zhou 已提交
807
> This API is supported since API version 7 and deprecated since API version 9.
E
ester.zhou 已提交
808

Z
zengyawen 已提交
809 810
**System capability**: SystemCapability.MiscServices.Wallpaper

E
ester.zhou 已提交
811
**Parameters**
Z
zengyawen 已提交
812

E
ester.zhou 已提交
813 814 815
| 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 已提交
816 817 818

**Example**

E
ester.zhou 已提交
819 820 821 822 823 824 825 826 827
```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 已提交
828

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

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

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

E
ester.zhou 已提交
835 836
> **NOTE**
> 
E
ester.zhou 已提交
837
> This API is supported since API version 7 and deprecated since API version 9.
E
ester.zhou 已提交
838 839 840 841 842 843 844

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

**Return value**

| Type| Description|
| -------- | -------- |
E
ester.zhou 已提交
845
| 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 已提交
846 847 848

**Example**

E
ester.zhou 已提交
849 850 851 852 853 854 855
```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 已提交
856

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

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

E
ester.zhou 已提交
861
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 已提交
862

E
ester.zhou 已提交
863 864
> **NOTE**
> 
E
ester.zhou 已提交
865
> This API is supported since API version 7 and deprecated since API version 9.
Z
zengyawen 已提交
866 867 868

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

E
ester.zhou 已提交
869
**Parameters**
Z
zengyawen 已提交
870

E
ester.zhou 已提交
871
| Name| Type| Mandatory| Description|
E
ester.zhou 已提交
872
| -------- | -------- | -------- | -------- |
E
ester.zhou 已提交
873
| 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 已提交
874 875 876

**Example**

E
ester.zhou 已提交
877 878 879 880 881 882 883 884 885
```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 已提交
886

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

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

E
ester.zhou 已提交
891
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 已提交
892

E
ester.zhou 已提交
893
> **NOTE**
E
ester.zhou 已提交
894
> 
E
ester.zhou 已提交
895
> This API is supported since API version 7 and deprecated since API version 9.
Z
zengyawen 已提交
896 897 898

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

E
ester.zhou 已提交
899 900
**Return value**

E
ester.zhou 已提交
901
| Type| Description|
E
ester.zhou 已提交
902
| -------- | -------- |
E
ester.zhou 已提交
903
| 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 已提交
904 905 906

**Example**

E
ester.zhou 已提交
907 908 909 910 911 912 913
```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 已提交
914

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

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

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

E
ester.zhou 已提交
921 922
> **NOTE**
> 
E
ester.zhou 已提交
923
> This API is supported since API version 7 and deprecated since API version 9.
E
ester.zhou 已提交
924 925 926 927 928 929 930

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

**Parameters**

| Name| Type| Mandatory| Description|
| -------- | -------- | -------- | -------- |
E
ester.zhou 已提交
931
| 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 已提交
932 933 934

**Example**

E
ester.zhou 已提交
935 936 937 938 939 940 941 942 943
```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 已提交
944

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

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

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

E
ester.zhou 已提交
951 952
> **NOTE**
> 
E
ester.zhou 已提交
953
> This API is supported since API version 7 and deprecated since API version 9.
E
ester.zhou 已提交
954 955 956 957 958 959 960

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

**Return value**

| Type| Description|
| -------- | -------- |
E
ester.zhou 已提交
961
| 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 已提交
962 963 964

**Example**

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

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

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

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

E
ester.zhou 已提交
979 980
> **NOTE**
> 
E
ester.zhou 已提交
981
> This API is supported since API version 7 and deprecated since API version 9.
E
ester.zhou 已提交
982

E
ester.zhou 已提交
983
**Required permissions**: ohos.permission.SET_WALLPAPER
Z
zengyawen 已提交
984 985 986

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

E
ester.zhou 已提交
987 988
**Parameters**

E
ester.zhou 已提交
989
| Name| Type| Mandatory| Description|
E
ester.zhou 已提交
990
| -------- | -------- | -------- | -------- |
E
ester.zhou 已提交
991
| wallpaperType | [WallpaperType](#wallpapertype7) | Yes| Wallpaper type.|
E
esterzhou 已提交
992
| 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 已提交
993 994 995

**Example**

E
ester.zhou 已提交
996 997 998 999 1000 1001 1002 1003 1004
```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 已提交
1005

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

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

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

E
ester.zhou 已提交
1012
> **NOTE**
E
ester.zhou 已提交
1013
>
E
ester.zhou 已提交
1014
> This API is supported since API version 7 and deprecated since API version 9.
E
ester.zhou 已提交
1015

E
ester.zhou 已提交
1016
**Required permissions**: ohos.permission.SET_WALLPAPER
Z
zengyawen 已提交
1017 1018 1019

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

E
ester.zhou 已提交
1020
**Parameters**
Z
zengyawen 已提交
1021

E
ester.zhou 已提交
1022
| Name| Type| Mandatory| Description|
E
ester.zhou 已提交
1023
| -------- | -------- | -------- | -------- |
E
ester.zhou 已提交
1024
| wallpaperType | [WallpaperType](#wallpapertype7) | Yes| Wallpaper type.|
Z
zengyawen 已提交
1025

E
ester.zhou 已提交
1026 1027
**Return value**

E
ester.zhou 已提交
1028
| Type| Description|
E
ester.zhou 已提交
1029
| -------- | -------- |
E
ester.zhou 已提交
1030
| Promise&lt;void&gt; | Promise that returns no value.|
E
ester.zhou 已提交
1031 1032 1033

**Example**

E
ester.zhou 已提交
1034 1035 1036 1037 1038 1039 1040
```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 已提交
1041

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

E
ester.zhou 已提交
1044
setWallpaper(source: string | image.PixelMap, wallpaperType: WallpaperType, callback: AsyncCallback&lt;void&gt;): void
E
ester.zhou 已提交
1045 1046 1047

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

E
ester.zhou 已提交
1048 1049
> **NOTE**
> 
E
ester.zhou 已提交
1050
> This API is supported since API version 7 and deprecated since API version 9.
E
ester.zhou 已提交
1051

E
ester.zhou 已提交
1052 1053 1054 1055 1056 1057 1058 1059
**Required permissions**: ohos.permission.SET_WALLPAPER

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

**Parameters**

| Name| Type| Mandatory| Description|
| -------- | -------- | -------- | -------- |
E
esterzhou 已提交
1060
| 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 已提交
1061
| wallpaperType | [WallpaperType](#wallpapertype7) | Yes| Wallpaper type.|
E
esterzhou 已提交
1062
| 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 已提交
1063 1064 1065

**Example**

E
ester.zhou 已提交
1066
```js
E
esterzhou 已提交
1067
// The source type is string.
E
ester.zhou 已提交
1068
let wallpaperPath = "/data/storage/el2/base/haps/entry/files/js.jpeg";
E
ester.zhou 已提交
1069 1070 1071 1072 1073 1074 1075 1076 1077 1078 1079 1080 1081 1082 1083 1084 1085 1086 1087 1088 1089 1090 1091 1092 1093 1094 1095 1096 1097
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 已提交
1098

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

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

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

E
ester.zhou 已提交
1105 1106
> **NOTE**
> 
E
ester.zhou 已提交
1107
> This API is supported since API version 7 and deprecated since API version 9.
E
ester.zhou 已提交
1108 1109 1110 1111 1112 1113 1114 1115 1116

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

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

**Parameters**

| Name| Type| Mandatory| Description|
| -------- | -------- | -------- | -------- |
E
esterzhou 已提交
1117
| 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 已提交
1118
| wallpaperType | [WallpaperType](#wallpapertype7) | Yes| Wallpaper type.|
E
ester.zhou 已提交
1119 1120 1121 1122 1123

**Return value**

| Type| Description|
| -------- | -------- |
E
ester.zhou 已提交
1124
| Promise&lt;void&gt; | Promise that returns no value.|
E
ester.zhou 已提交
1125 1126 1127

**Example**

E
ester.zhou 已提交
1128
```js
E
esterzhou 已提交
1129
// The source type is string.
E
ester.zhou 已提交
1130
let wallpaperPath = "/data/storage/el2/base/haps/entry/files/js.jpeg";
E
ester.zhou 已提交
1131 1132
wallpaper.setWallpaper(wallpaperPath, wallpaper.WallpaperType.WALLPAPER_SYSTEM).then(() => {
    console.log(`success to setWallpaper.`);
E
ester.zhou 已提交
1133
  }).catch((error) => {
E
ester.zhou 已提交
1134 1135
    console.error(`failed to setWallpaper because: ${JSON.stringify(error)}`);
});
E
ester.zhou 已提交
1136
  
E
ester.zhou 已提交
1137 1138 1139 1140 1141 1142 1143 1144 1145 1146 1147 1148 1149 1150 1151 1152 1153 1154 1155
// 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 已提交
1156 1157


E
ester.zhou 已提交
1158
## wallpaper.getFile<sup>(deprecated)</sup>
Z
zengyawen 已提交
1159 1160 1161

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

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

E
ester.zhou 已提交
1164 1165
> **NOTE**
> 
E
ester.zhou 已提交
1166
> This API is supported since API version 8 and deprecated since API version 9.
E
ester.zhou 已提交
1167

1168
**Required permissions**: ohos.permission.GET_WALLPAPER
Z
zengyawen 已提交
1169 1170 1171

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

E
ester.zhou 已提交
1172
**Parameters**
Z
zengyawen 已提交
1173

E
ester.zhou 已提交
1174
| Name| Type| Mandatory| Description|
E
ester.zhou 已提交
1175
| -------- | -------- | -------- | -------- |
E
ester.zhou 已提交
1176
| wallpaperType | [WallpaperType](#wallpapertype7) | Yes| Wallpaper type.|
E
ester.zhou 已提交
1177
| 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 已提交
1178 1179 1180

**Example**

E
ester.zhou 已提交
1181 1182 1183 1184 1185 1186 1187 1188 1189
```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 已提交
1190

E
ester.zhou 已提交
1191
## wallpaper.getFile<sup>(deprecated)</sup>
Z
zengyawen 已提交
1192 1193 1194

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

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

E
ester.zhou 已提交
1197 1198
> **NOTE**
>
E
ester.zhou 已提交
1199
> This API is supported since API version 8 and deprecated since API version 9.
E
ester.zhou 已提交
1200

1201
**Required permissions**: ohos.permission.GET_WALLPAPER
Z
zengyawen 已提交
1202 1203 1204

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

E
ester.zhou 已提交
1205
**Parameters**
Z
zengyawen 已提交
1206

E
ester.zhou 已提交
1207
| Name| Type| Mandatory| Description|
E
ester.zhou 已提交
1208
| -------- | -------- | -------- | -------- |
E
ester.zhou 已提交
1209
| wallpaperType | [WallpaperType](#wallpapertype7) | Yes| Wallpaper type.|
Z
zengyawen 已提交
1210

E
ester.zhou 已提交
1211 1212
**Return value**

E
ester.zhou 已提交
1213
| Type| Description|
E
ester.zhou 已提交
1214
| -------- | -------- |
E
ester.zhou 已提交
1215
| 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 已提交
1216 1217 1218

**Example**

E
ester.zhou 已提交
1219 1220 1221
```js
wallpaper.getFile(wallpaper.WallpaperType.WALLPAPER_SYSTEM).then((data) => {
    console.log(`success to getFile: ${JSON.stringify(data)}`);
E
ester.zhou 已提交
1222
  }).catch((error) => {
E
ester.zhou 已提交
1223 1224 1225
    console.error(`failed to getFile because: ${JSON.stringify(error)}`);
});
```
E
ester.zhou 已提交
1226

E
ester.zhou 已提交
1227
## wallpaper.getPixelMap<sup>(deprecated)</sup>
E
ester.zhou 已提交
1228 1229 1230

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

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

E
ester.zhou 已提交
1233 1234
> **NOTE**
>
E
ester.zhou 已提交
1235
> This API is supported since API version 7 and deprecated since API version 9.
E
ester.zhou 已提交
1236

1237
**Required permissions**: ohos.permission.GET_WALLPAPER
E
ester.zhou 已提交
1238 1239 1240

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

E
ester.zhou 已提交
1241
**System API**: This is a system API.
E
ester.zhou 已提交
1242

E
ester.zhou 已提交
1243 1244 1245 1246
**Parameters**

| Name| Type| Mandatory| Description|
| -------- | -------- | -------- | -------- |
E
ester.zhou 已提交
1247
| wallpaperType | [WallpaperType](#wallpapertype7) | Yes| Wallpaper type.|
E
esterzhou 已提交
1248
| 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 已提交
1249 1250 1251

**Example**

E
ester.zhou 已提交
1252 1253 1254 1255 1256 1257 1258
```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 已提交
1259
  });
E
ester.zhou 已提交
1260
```
E
ester.zhou 已提交
1261

E
ester.zhou 已提交
1262
## wallpaper.getPixelMap<sup>(deprecated)</sup>
E
ester.zhou 已提交
1263 1264 1265

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

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

E
ester.zhou 已提交
1268 1269
> **NOTE**
>
E
ester.zhou 已提交
1270
> This API is supported since API version 7 and deprecated since API version 9.
E
ester.zhou 已提交
1271

1272
**Required permissions**: ohos.permission.GET_WALLPAPER
E
ester.zhou 已提交
1273 1274 1275

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

E
ester.zhou 已提交
1276
**System API**: This is a system API.
E
ester.zhou 已提交
1277

E
ester.zhou 已提交
1278 1279 1280 1281
**Parameters**

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

**Return value**

| Type| Description|
| -------- | -------- |
E
esterzhou 已提交
1288
| 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 已提交
1289 1290 1291

**Example**

E
ester.zhou 已提交
1292 1293 1294 1295 1296 1297 1298
```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)}`);
});
```