js-apis-wallpaper.md 39.8 KB
Newer Older
E
ester.zhou 已提交
1
# @ohos.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 16 17 18
import wallpaper from '@ohos.wallpaper';
```

## WallpaperType

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

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

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


E
ester.zhou 已提交
29
## RgbaColor
Z
zengyawen 已提交
30

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

E
ester.zhou 已提交
33
**System capability**: SystemCapability.MiscServices.Wallpaper
Z
zengyawen 已提交
34

E
ester.zhou 已提交
35 36 37 38 39 40 41 42 43 44 45 46 47
| 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.|


## 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 已提交
48

Z
zengyawen 已提交
49 50
**System capability**: SystemCapability.MiscServices.Wallpaper

E
ester.zhou 已提交
51
**Parameters**
E
ester.zhou 已提交
52 53

| Name| Type| Mandatory| Description|
E
ester.zhou 已提交
54
| -------- | -------- | -------- | -------- |
E
ester.zhou 已提交
55
| wallpaperType | [WallpaperType](#wallpapertype) | Yes| Wallpaper type.|
E
ester.zhou 已提交
56

E
ester.zhou 已提交
57
**Return value**
Z
zengyawen 已提交
58

E
ester.zhou 已提交
59 60 61
| Type| Description|
| -------- | -------- |
| Array&lt;[RgbaColor](#rgbacolor)&gt; | Promise used to return the main color information of the wallpaper.|
Z
zengyawen 已提交
62

E
ester.zhou 已提交
63
**Example**
Z
zengyawen 已提交
64

E
ester.zhou 已提交
65
```js
E
esterzhou 已提交
66 67 68 69 70 71
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 已提交
72
```
Z
zengyawen 已提交
73

E
ester.zhou 已提交
74
## wallpaper.getIdSync<sup>9+</sup>
Z
zengyawen 已提交
75

E
ester.zhou 已提交
76
getIdSync(wallpaperType: WallpaperType): number
Z
zengyawen 已提交
77

E
ester.zhou 已提交
78
Obtains the ID of the wallpaper of the specified type.
E
ester.zhou 已提交
79

Z
zengyawen 已提交
80 81
**System capability**: SystemCapability.MiscServices.Wallpaper

E
ester.zhou 已提交
82
**Parameters**
Z
zengyawen 已提交
83

E
ester.zhou 已提交
84
| Name| Type| Mandatory| Description|
E
ester.zhou 已提交
85
| -------- | -------- | -------- | -------- |
E
ester.zhou 已提交
86
| wallpaperType | [WallpaperType](#wallpapertype) | Yes| Wallpaper type.|
Z
zengyawen 已提交
87

E
ester.zhou 已提交
88 89
**Return value**

E
ester.zhou 已提交
90
| Type| Description|
E
ester.zhou 已提交
91
| -------- | -------- |
E
esterzhou 已提交
92
| number | ID of the wallpaper. If this type of wallpaper is configured, a number greater than or equal to **0** is returned. Otherwise, **-1** is returned. The value ranges from -1 to (2^31-1).|
E
ester.zhou 已提交
93 94 95

**Example**

E
ester.zhou 已提交
96
```js
E
esterzhou 已提交
97 98 99 100 101 102
try {
    let id = wallpaper.getIdSync(wallpaper.WallpaperType.WALLPAPER_SYSTEM);
    console.log(`success to getIdSync: ${JSON.stringify(id)}`);
} catch (error) {
    console.error(`failed to getIdSync because: ${JSON.stringify(error)}`);
}
E
ester.zhou 已提交
103
```
Z
zengyawen 已提交
104

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

E
ester.zhou 已提交
107
getMinHeightSync(): number
E
ester.zhou 已提交
108

E
ester.zhou 已提交
109
Obtains the minimum height of this wallpaper.
E
ester.zhou 已提交
110

E
ester.zhou 已提交
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
**System capability**: SystemCapability.MiscServices.Wallpaper

**Return value**

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

**Example**

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

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

getMinWidthSync(): number

Obtains the minimum width of this wallpaper.

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

**Return value**

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

**Example**

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

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

isChangeAllowed(): boolean

Checks whether to allow the application to change the wallpaper for the current user.

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

**Return value**

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

**Example**

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

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

isUserChangeAllowed(): boolean

Checks whether the user is allowed to set wallpapers.

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

**Return value**

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

**Example**

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

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

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

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

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

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

**Parameters**

| Name| Type| Mandatory| Description|
| -------- | -------- | -------- | -------- |
| wallpaperType | [WallpaperType](#wallpapertype) | Yes| Wallpaper type.|
E
esterzhou 已提交
200
| 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 已提交
201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220

**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 已提交
221 222 223 224 225 226 227 228 229 230 231 232 233

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

**Parameters**

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

**Return value**

| Type| Description|
| -------- | -------- |
E
ester.zhou 已提交
234
| Promise&lt;void&gt; | Promise that returns no value.|
E
ester.zhou 已提交
235 236 237

**Example**

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

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

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

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

E
ester.zhou 已提交
252
**Required permissions**: ohos.permission.SET_WALLPAPER
E
ester.zhou 已提交
253

Z
zengyawen 已提交
254 255
**System capability**: SystemCapability.MiscServices.Wallpaper

E
ester.zhou 已提交
256
**Parameters**
Z
zengyawen 已提交
257

E
ester.zhou 已提交
258
| Name| Type| Mandatory| Description|
E
ester.zhou 已提交
259
| -------- | -------- | -------- | -------- |
E
esterzhou 已提交
260
| source | string \| [image.PixelMap](js-apis-image.md#pixelmap7) | Yes| URI of a JPEG or PNG file, or pixel map of a PNG file.|
E
ester.zhou 已提交
261
| wallpaperType | [WallpaperType](#wallpapertype) | Yes| Wallpaper type.|
E
esterzhou 已提交
262
| 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 已提交
263 264 265

**Example**

E
ester.zhou 已提交
266
```js
E
esterzhou 已提交
267
// The source type is string.
E
ester.zhou 已提交
268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297
let wallpaperPath = "/data/data/ohos.acts.aafwk.plrdtest.form/files/Cup_ic.jpg";
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 已提交
298

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

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

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

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

E
ester.zhou 已提交
307
**System capability**: SystemCapability.MiscServices.Wallpaper
E
ester.zhou 已提交
308

E
ester.zhou 已提交
309
**Parameters**
Z
zengyawen 已提交
310

E
ester.zhou 已提交
311
| Name| Type| Mandatory| Description|
E
ester.zhou 已提交
312
| -------- | -------- | -------- | -------- |
E
esterzhou 已提交
313
| 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 已提交
314
| wallpaperType | [WallpaperType](#wallpapertype) | Yes| Wallpaper type.|
Z
zengyawen 已提交
315

E
ester.zhou 已提交
316
**Return value**
Z
zengyawen 已提交
317

E
ester.zhou 已提交
318
| Type| Description|
E
ester.zhou 已提交
319
| -------- | -------- |
E
ester.zhou 已提交
320
| Promise&lt;void&gt; | Promise that returns no value.|
E
ester.zhou 已提交
321 322 323

**Example**

E
ester.zhou 已提交
324
```js
E
esterzhou 已提交
325
// The source type is string.
E
ester.zhou 已提交
326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351
let wallpaperPath = "/data/data/ohos.acts.aafwk.plrdtest.form/files/Cup_ic.jpg";
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 已提交
352

E
ester.zhou 已提交
353
## wallpaper.getFileSync<sup>9+</sup>
Z
zengyawen 已提交
354

E
ester.zhou 已提交
355
getFileSync(wallpaperType: WallpaperType): number;
E
ester.zhou 已提交
356

E
ester.zhou 已提交
357
Obtains the wallpaper of the specified type.
E
ester.zhou 已提交
358

E
ester.zhou 已提交
359
**Required permissions**: ohos.permission.GET_WALLPAPER
E
ester.zhou 已提交
360 361 362 363 364 365 366 367 368 369 370 371 372

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

**Parameters**

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

**Return value**

| Type| Description|
| -------- | -------- |
E
ester.zhou 已提交
373
| number | Promise used to return the result. If the operation is successful, the file descriptor ID to the wallpaper is returned. Otherwise, error information is returned.|
E
ester.zhou 已提交
374 375 376

**Example**

E
ester.zhou 已提交
377
```js
E
esterzhou 已提交
378 379 380 381 382 383
try {
    let file = wallpaper.getFileSync(wallpaper.WallpaperType.WALLPAPER_SYSTEM);
    console.log(`success to getFileSync: ${JSON.stringify(file)}`);
} catch (error) {
    console.error(`failed to getFileSync because: ${JSON.stringify(error)}`);
}
E
ester.zhou 已提交
384
```
E
ester.zhou 已提交
385

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

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

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

E
ester.zhou 已提交
392
**Required permissions**: ohos.permission.GET_WALLPAPER
E
ester.zhou 已提交
393

Z
zengyawen 已提交
394 395
**System capability**: SystemCapability.MiscServices.Wallpaper

E
ester.zhou 已提交
396 397
**System API**: This is a system API.

E
ester.zhou 已提交
398
**Parameters**
Z
zengyawen 已提交
399

E
ester.zhou 已提交
400
| Name| Type| Mandatory| Description|
E
ester.zhou 已提交
401
| -------- | -------- | -------- | -------- |
E
ester.zhou 已提交
402
| wallpaperType | [WallpaperType](#wallpapertype) | Yes| Wallpaper type.|
E
esterzhou 已提交
403
| 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 已提交
404 405 406

**Example**

E
ester.zhou 已提交
407 408 409 410 411 412 413 414 415
```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 已提交
416 417


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

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

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

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

E
ester.zhou 已提交
426
**System capability**: SystemCapability.MiscServices.Wallpaper
E
ester.zhou 已提交
427

E
ester.zhou 已提交
428 429 430 431 432 433 434 435
**System API**: This is a system API.

**Parameters**

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

E
ester.zhou 已提交
436
**Return value**
Z
zengyawen 已提交
437

E
ester.zhou 已提交
438
| Type| Description|
E
ester.zhou 已提交
439
| -------- | -------- |
E
esterzhou 已提交
440
| 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 已提交
441

E
ester.zhou 已提交
442 443
**Example**

E
ester.zhou 已提交
444 445 446
```js
wallpaper.getImage(wallpaper.WallpaperType.WALLPAPER_SYSTEM).then((data) => {
    console.log(`success to getImage: ${JSON.stringify(data)}`);
E
ester.zhou 已提交
447
  }).catch((error) => {
E
ester.zhou 已提交
448 449 450
    console.error(`failed to getImage because: ${JSON.stringify(error)}`);
});
```
Z
zengyawen 已提交
451

E
ester.zhou 已提交
452
## wallpaper.on('colorChange')<sup>9+</sup>
E
ester.zhou 已提交
453

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

E
ester.zhou 已提交
456
Subscribes to the wallpaper color change event.
E
ester.zhou 已提交
457 458 459

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

E
ester.zhou 已提交
460
**Parameters**
E
ester.zhou 已提交
461

E
ester.zhou 已提交
462 463 464 465
| 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.|
| callback | function | Yes| Callback triggered when the wallpaper color changes. The wallpaper type and main colors are returned.<br>- colors<br>  Main color information of the wallpaper. For details, see [RgbaColor](#rgbacolor).<br>- wallpaperType<br>  Wallpaper type.|
E
ester.zhou 已提交
466 467 468

**Example**

E
ester.zhou 已提交
469
```js
E
esterzhou 已提交
470 471 472 473 474 475 476 477
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 已提交
478
```
Z
zengyawen 已提交
479

E
ester.zhou 已提交
480
## wallpaper.off('colorChange')<sup>9+</sup>
Z
zengyawen 已提交
481

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

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

E
ester.zhou 已提交
486
**System capability**: SystemCapability.MiscServices.Wallpaper
E
ester.zhou 已提交
487

E
ester.zhou 已提交
488
**Parameters**
Z
zengyawen 已提交
489

E
ester.zhou 已提交
490
| Name| Type| Mandatory| Description|
E
ester.zhou 已提交
491
| -------- | -------- | -------- | -------- |
E
ester.zhou 已提交
492 493
| type | string | Yes| Type of the event to unsubscribe from. The value **'colorChange'** indicates unsubscribing from the wallpaper color change event.|
| callback | function | No|   Callback for the wallpaper color change event. If this parameter is not set, this API unsubscribes from all callbacks corresponding to **type**.<br>- colors<br>  Main color information of the wallpaper. For details, see [RgbaColor](#rgbacolor).<br>- wallpaperType<br>  Wallpaper type.|
Z
zengyawen 已提交
494

E
ester.zhou 已提交
495 496
**Example**

E
ester.zhou 已提交
497 498 499 500
```js
let listener = (colors, wallpaperType) => {
    console.log(`wallpaper color changed.`);
};
E
esterzhou 已提交
501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519
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 已提交
520
```
Z
zengyawen 已提交
521

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

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

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

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

Z
zengyawen 已提交
532 533
**System capability**: SystemCapability.MiscServices.Wallpaper

E
ester.zhou 已提交
534
**Parameters**
Z
zengyawen 已提交
535

E
ester.zhou 已提交
536 537 538 539
| Name| Type| Mandatory| Description|
| -------- | -------- | -------- | -------- |
| wallpaperType | [WallpaperType](#wallpapertype) | Yes| Wallpaper type.|
| callback | AsyncCallback&lt;Array&lt;[RgbaColor](#rgbacolor)&gt;&gt; | Yes| Callback used to return the main color information of the wallpaper.|
E
ester.zhou 已提交
540 541 542

**Example**

E
ester.zhou 已提交
543 544 545 546 547 548 549 550 551
```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 已提交
552

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

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

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

E
ester.zhou 已提交
559 560 561
> **NOTE**
> 
> This API is supported since API version 7 and deprecated since API version 9. You are advised to use [wallpaper.getColorsSync<sup>9+</sup>](#wallpapergetcolorssync9) instead.
E
ester.zhou 已提交
562 563 564

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

E
ester.zhou 已提交
565 566 567 568 569 570
**Parameters**

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

E
ester.zhou 已提交
571 572 573 574
**Return value**

| Type| Description|
| -------- | -------- |
E
ester.zhou 已提交
575
| Promise&lt;Array&lt;[RgbaColor](#rgbacolor)&gt;&gt; | Promise used to return the main color information of the wallpaper.|
E
ester.zhou 已提交
576 577 578

**Example**

E
ester.zhou 已提交
579 580 581 582 583 584 585
```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 已提交
586

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

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

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

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

Z
zengyawen 已提交
597 598
**System capability**: SystemCapability.MiscServices.Wallpaper

E
ester.zhou 已提交
599
**Parameters**
Z
zengyawen 已提交
600

E
ester.zhou 已提交
601
| Name| Type| Mandatory| Description|
E
ester.zhou 已提交
602
| -------- | -------- | -------- | -------- |
E
ester.zhou 已提交
603
| wallpaperType | [WallpaperType](#wallpapertype) | Yes| Wallpaper type.|
E
esterzhou 已提交
604
| 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 已提交
605 606 607

**Example**

E
ester.zhou 已提交
608 609 610 611 612 613 614 615 616
```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 已提交
617

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

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

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

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

Z
zengyawen 已提交
628 629
**System capability**: SystemCapability.MiscServices.Wallpaper

E
ester.zhou 已提交
630 631 632 633 634 635
**Parameters**

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

E
ester.zhou 已提交
636
**Return value**
Z
zengyawen 已提交
637

E
ester.zhou 已提交
638
| Type| Description|
E
ester.zhou 已提交
639
| -------- | -------- |
E
esterzhou 已提交
640
| 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 已提交
641 642 643

**Example**

E
ester.zhou 已提交
644 645 646
```js
wallpaper.getId(wallpaper.WallpaperType.WALLPAPER_SYSTEM).then((data) => {
    console.log(`success to getId: ${JSON.stringify(data)}`);
E
ester.zhou 已提交
647
  }).catch((error) => {
E
ester.zhou 已提交
648 649 650
    console.error(`failed to getId because: ${JSON.stringify(error)}`);
});
```
Z
zengyawen 已提交
651

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

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

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

E
ester.zhou 已提交
658 659 660
> **NOTE**
> 
> This API is supported since API version 7 and deprecated since API version 9. You are advised to use [wallpaper.getMinHeightSync<sup>9+</sup>](#wallpapergetminheightsync9) instead.
E
ester.zhou 已提交
661 662 663

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

E
ester.zhou 已提交
664
**Parameters**
E
ester.zhou 已提交
665

E
ester.zhou 已提交
666 667 668
| 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 已提交
669 670 671

**Example**

E
ester.zhou 已提交
672 673 674 675 676 677 678 679 680
```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 已提交
681

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

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

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

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

Z
zengyawen 已提交
692 693
**System capability**: SystemCapability.MiscServices.Wallpaper

E
ester.zhou 已提交
694
**Return value**
Z
zengyawen 已提交
695

E
ester.zhou 已提交
696 697 698
| 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 已提交
699 700 701

**Example**

E
ester.zhou 已提交
702 703 704 705 706 707 708
```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 已提交
709

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

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

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

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

Z
zengyawen 已提交
720 721
**System capability**: SystemCapability.MiscServices.Wallpaper

E
ester.zhou 已提交
722
**Parameters**
Z
zengyawen 已提交
723

E
ester.zhou 已提交
724 725 726
| 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 已提交
727 728 729

**Example**

E
ester.zhou 已提交
730 731 732 733 734 735 736 737 738
```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 已提交
739

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

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

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

E
ester.zhou 已提交
746 747 748
> **NOTE**
> 
> This API is supported since API version 7 and deprecated since API version 9. You are advised to use [wallpaper.getMinWidthSync<sup>9+</sup>](#wallpapergetminwidthsync9) instead.
E
ester.zhou 已提交
749 750 751 752 753 754 755

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

**Return value**

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

**Example**

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

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

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

E
ester.zhou 已提交
772
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 已提交
773

E
ester.zhou 已提交
774 775
> **NOTE**
> 
E
ester.zhou 已提交
776
> This API is supported since API version 7 and deprecated since API version 9. You are advised to use [wallpaper.isChangeAllowed<sup>9+</sup>](#wallpaperischangeallowed9) instead.
Z
zengyawen 已提交
777 778 779

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

E
ester.zhou 已提交
780
**Parameters**
Z
zengyawen 已提交
781

E
ester.zhou 已提交
782
| Name| Type| Mandatory| Description|
E
ester.zhou 已提交
783
| -------- | -------- | -------- | -------- |
E
ester.zhou 已提交
784
| 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 已提交
785 786 787

**Example**

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

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

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

E
ester.zhou 已提交
802
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 已提交
803

E
ester.zhou 已提交
804
> **NOTE**
E
ester.zhou 已提交
805 806
> 
> This API is supported since API version 7 and deprecated since API version 9. You are advised to use [wallpaper.isChangeAllowed<sup>9+</sup>](#wallpaperischangeallowed9) instead.
Z
zengyawen 已提交
807 808 809

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

E
ester.zhou 已提交
810 811
**Return value**

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

**Example**

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

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

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

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

E
ester.zhou 已提交
832 833 834
> **NOTE**
> 
> This API is supported since API version 7 and deprecated since API version 9. You are advised to use [wallpaper.isUserChangeAllowed<sup>9+</sup>](#wallpaperisuserchangeallowed9) instead.
E
ester.zhou 已提交
835 836 837 838 839 840 841

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

**Parameters**

| Name| Type| Mandatory| Description|
| -------- | -------- | -------- | -------- |
E
ester.zhou 已提交
842
| 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 已提交
843 844 845

**Example**

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

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

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

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

E
ester.zhou 已提交
862 863 864
> **NOTE**
> 
> This API is supported since API version 7 and deprecated since API version 9. You are advised to use [wallpaper.isUserChangeAllowed<sup>9+</sup>](#wallpaperisuserchangeallowed9) instead.
E
ester.zhou 已提交
865 866 867 868 869 870 871

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

**Return value**

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

**Example**

E
ester.zhou 已提交
876 877 878
```js
wallpaper.isOperationAllowed().then((data) => {
    console.log(`success to isOperationAllowed: ${JSON.stringify(data)}`);
E
ester.zhou 已提交
879
  }).catch((error) => {
E
ester.zhou 已提交
880 881 882
    console.error(`failed to isOperationAllowed because: ${JSON.stringify(error)}`);
});
```
E
ester.zhou 已提交
883

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

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

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

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

E
ester.zhou 已提交
894
**Required permissions**: ohos.permission.SET_WALLPAPER
Z
zengyawen 已提交
895 896 897

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

E
ester.zhou 已提交
898 899
**Parameters**

E
ester.zhou 已提交
900
| Name| Type| Mandatory| Description|
E
ester.zhou 已提交
901
| -------- | -------- | -------- | -------- |
E
ester.zhou 已提交
902
| wallpaperType | [WallpaperType](#wallpapertype) | Yes| Wallpaper type.|
E
esterzhou 已提交
903
| 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 已提交
904 905 906

**Example**

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

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

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

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

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

E
ester.zhou 已提交
927
**Required permissions**: ohos.permission.SET_WALLPAPER
Z
zengyawen 已提交
928 929 930

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

E
ester.zhou 已提交
931
**Parameters**
Z
zengyawen 已提交
932

E
ester.zhou 已提交
933
| Name| Type| Mandatory| Description|
E
ester.zhou 已提交
934
| -------- | -------- | -------- | -------- |
E
ester.zhou 已提交
935
| wallpaperType | [WallpaperType](#wallpapertype) | Yes| Wallpaper type.|
Z
zengyawen 已提交
936

E
ester.zhou 已提交
937 938
**Return value**

E
ester.zhou 已提交
939
| Type| Description|
E
ester.zhou 已提交
940
| -------- | -------- |
E
ester.zhou 已提交
941
| Promise&lt;void&gt; | Promise that returns no value.|
E
ester.zhou 已提交
942 943 944

**Example**

E
ester.zhou 已提交
945 946 947 948 949 950 951
```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 已提交
952

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

E
ester.zhou 已提交
955
setWallpaper(source: string | image.PixelMap, wallpaperType: WallpaperType, callback: AsyncCallback&lt;void&gt;): void
E
ester.zhou 已提交
956 957 958

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

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

E
ester.zhou 已提交
963 964 965 966 967 968 969 970
**Required permissions**: ohos.permission.SET_WALLPAPER

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

**Parameters**

| Name| Type| Mandatory| Description|
| -------- | -------- | -------- | -------- |
E
esterzhou 已提交
971
| 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 已提交
972
| wallpaperType | [WallpaperType](#wallpapertype) | Yes| Wallpaper type.|
E
esterzhou 已提交
973
| 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 已提交
974 975 976

**Example**

E
ester.zhou 已提交
977
```js
E
esterzhou 已提交
978
// The source type is string.
E
ester.zhou 已提交
979 980 981 982 983 984 985 986 987 988 989 990 991 992 993 994 995 996 997 998 999 1000 1001 1002 1003 1004 1005 1006 1007 1008
let wallpaperPath = "/data/data/ohos.acts.aafwk.plrdtest.form/files/Cup_ic.jpg";
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 已提交
1009

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

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

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

E
ester.zhou 已提交
1016 1017 1018
> **NOTE**
> 
> This API is supported since API version 7 and deprecated since API version 9. You are advised to use [wallpaper.setImage<sup>9+</sup>](#wallpapersetimage9) instead.
E
ester.zhou 已提交
1019 1020 1021 1022 1023 1024 1025 1026 1027

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

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

**Parameters**

| Name| Type| Mandatory| Description|
| -------- | -------- | -------- | -------- |
E
esterzhou 已提交
1028
| 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 已提交
1029 1030 1031 1032 1033 1034
| wallpaperType | [WallpaperType](#wallpapertype) | Yes| Wallpaper type.|

**Return value**

| Type| Description|
| -------- | -------- |
E
ester.zhou 已提交
1035
| Promise&lt;void&gt; | Promise that returns no value.|
E
ester.zhou 已提交
1036 1037 1038

**Example**

E
ester.zhou 已提交
1039
```js
E
esterzhou 已提交
1040
// The source type is string.
E
ester.zhou 已提交
1041 1042 1043
let wallpaperPath = "/data/data/ohos.acts.aafwk.plrdtest.form/files/Cup_ic.jpg";
wallpaper.setWallpaper(wallpaperPath, wallpaper.WallpaperType.WALLPAPER_SYSTEM).then(() => {
    console.log(`success to setWallpaper.`);
E
ester.zhou 已提交
1044
  }).catch((error) => {
E
ester.zhou 已提交
1045 1046
    console.error(`failed to setWallpaper because: ${JSON.stringify(error)}`);
});
E
ester.zhou 已提交
1047
  
E
ester.zhou 已提交
1048 1049 1050 1051 1052 1053 1054 1055 1056 1057 1058 1059 1060 1061 1062 1063 1064 1065 1066
// 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 已提交
1067 1068


E
ester.zhou 已提交
1069
## wallpaper.getFile<sup>(deprecated)</sup>
Z
zengyawen 已提交
1070 1071 1072

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

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

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

1079
**Required permissions**: ohos.permission.GET_WALLPAPER
Z
zengyawen 已提交
1080 1081 1082

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

E
ester.zhou 已提交
1083
**Parameters**
Z
zengyawen 已提交
1084

E
ester.zhou 已提交
1085
| Name| Type| Mandatory| Description|
E
ester.zhou 已提交
1086
| -------- | -------- | -------- | -------- |
E
ester.zhou 已提交
1087 1088
| wallpaperType | [WallpaperType](#wallpapertype) | Yes| Wallpaper type.|
| callback | AsyncCallback&lt;number&gt; | Yes| Callback used to return the result. If the operation is successful, the file descriptor ID to the wallpaper is returned. Otherwise, error information is returned.|
E
ester.zhou 已提交
1089 1090 1091

**Example**

E
ester.zhou 已提交
1092 1093 1094 1095 1096 1097 1098 1099 1100
```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 已提交
1101

E
ester.zhou 已提交
1102
## wallpaper.getFile<sup>(deprecated)</sup>
Z
zengyawen 已提交
1103 1104 1105

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

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

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

1112
**Required permissions**: ohos.permission.GET_WALLPAPER
Z
zengyawen 已提交
1113 1114 1115

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

E
ester.zhou 已提交
1116
**Parameters**
Z
zengyawen 已提交
1117

E
ester.zhou 已提交
1118
| Name| Type| Mandatory| Description|
E
ester.zhou 已提交
1119
| -------- | -------- | -------- | -------- |
E
ester.zhou 已提交
1120
| wallpaperType | [WallpaperType](#wallpapertype) | Yes| Wallpaper type.|
Z
zengyawen 已提交
1121

E
ester.zhou 已提交
1122 1123
**Return value**

E
ester.zhou 已提交
1124
| Type| Description|
E
ester.zhou 已提交
1125
| -------- | -------- |
E
ester.zhou 已提交
1126
| 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 已提交
1127 1128 1129

**Example**

E
ester.zhou 已提交
1130 1131 1132
```js
wallpaper.getFile(wallpaper.WallpaperType.WALLPAPER_SYSTEM).then((data) => {
    console.log(`success to getFile: ${JSON.stringify(data)}`);
E
ester.zhou 已提交
1133
  }).catch((error) => {
E
ester.zhou 已提交
1134 1135 1136
    console.error(`failed to getFile because: ${JSON.stringify(error)}`);
});
```
E
ester.zhou 已提交
1137

E
ester.zhou 已提交
1138
## wallpaper.getPixelMap<sup>(deprecated)</sup>
E
ester.zhou 已提交
1139 1140 1141

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

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

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

1148
**Required permissions**: ohos.permission.GET_WALLPAPER
E
ester.zhou 已提交
1149 1150 1151

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

E
ester.zhou 已提交
1152
**System API**: This is a system API.
E
ester.zhou 已提交
1153

E
ester.zhou 已提交
1154 1155 1156 1157 1158
**Parameters**

| Name| Type| Mandatory| Description|
| -------- | -------- | -------- | -------- |
| wallpaperType | [WallpaperType](#wallpapertype) | Yes| Wallpaper type.|
E
esterzhou 已提交
1159
| 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 已提交
1160 1161 1162

**Example**

E
ester.zhou 已提交
1163 1164 1165 1166 1167 1168 1169
```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 已提交
1170
  });
E
ester.zhou 已提交
1171
```
E
ester.zhou 已提交
1172

E
ester.zhou 已提交
1173
## wallpaper.getPixelMap<sup>(deprecated)</sup>
E
ester.zhou 已提交
1174 1175 1176

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

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

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

1183
**Required permissions**: ohos.permission.GET_WALLPAPER
E
ester.zhou 已提交
1184 1185 1186

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

E
ester.zhou 已提交
1187
**System API**: This is a system API.
E
ester.zhou 已提交
1188

E
ester.zhou 已提交
1189 1190 1191 1192 1193 1194 1195 1196 1197 1198
**Parameters**

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

**Return value**

| Type| Description|
| -------- | -------- |
E
esterzhou 已提交
1199
| 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 已提交
1200 1201 1202

**Example**

E
ester.zhou 已提交
1203 1204 1205 1206 1207 1208 1209
```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)}`);
});
```