提交 cab9764e 编写于 作者: E ester.zhou

Update docs (10239)

Signed-off-by: Nester.zhou <ester.zhou@huawei.com>
上级 33d56ea2
...@@ -6,41 +6,41 @@ The **screenlock** module is a system module in OpenHarmony. It provides APIs fo ...@@ -6,41 +6,41 @@ The **screenlock** module is a system module in OpenHarmony. It provides APIs fo
> >
> 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. > 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.
## Modules to Import ## Modules to Import
```js ```js
import screenlock from '@ohos.screenLock'; import screenlock from '@ohos.screenLock';
``` ```
## screenlock.isScreenLocked ## screenlock.isScreenLocked
isScreenLocked(callback: AsyncCallback&lt;boolean&gt;): void isScreenLocked(callback: AsyncCallback&lt;boolean&gt;): void
Checks whether the screen is locked. This API uses an asynchronous callback to return the result. Checks whether the screen is locked. This API uses an asynchronous callback to return the result.
> **NOTE**
>
>This API is supported since API version 7 and deprecated since API version 9. You are advised to use [screenlock.isLocked<sup>9+</sup>](#screenlockislocked9) instead.
**System capability**: SystemCapability.MiscServices.ScreenLock **System capability**: SystemCapability.MiscServices.ScreenLock
**Parameters** **Parameters**
| Name| Type| Mandatory| Description| | Name | Type | Mandatory| Description |
| -------- | -------- | -------- | -------- | | -------- | ---------------------------- | ---- | ----------------------------------------------------------- |
| callback | AsyncCallback&lt;boolean&gt; | Yes| Callback used to return the result. Returns **true** if the screen is locked; returns **false** otherwise.| | callback | AsyncCallback&lt;boolean&gt; | Yes | Callback used to return the result. The value **true** means that the screen is locked, and **false** means the opposite.|
**Example** **Example**
```js ```js
screenlock.isScreenLocked((err, data)=>{ screenlock.isScreenLocked((err, data)=>{
if (err) { if (err) {
console.error('isScreenLocked callback error -> ${JSON.stringify(err)}'); console.error('isScreenLocked callback error -> ${JSON.stringify(err)}');
return; return;
} }
console.info('isScreenLocked callback success data -> ${JSON.stringify(data)}'); console.info('isScreenLocked callback success data -> ${JSON.stringify(data)}');
}); });
``` ```
## screenlock.isScreenLocked ## screenlock.isScreenLocked
...@@ -48,109 +48,155 @@ isScreenLocked(): Promise&lt;boolean&gt; ...@@ -48,109 +48,155 @@ isScreenLocked(): Promise&lt;boolean&gt;
Checks whether the screen is locked. This API uses a promise to return the result. Checks whether the screen is locked. This API uses a promise to return the result.
> **NOTE**
>
> This API is supported since API version 7 and deprecated since API version 9. You are advised to use [screenlock.isLocked<sup>9+</sup>](#screenlockislocked9) instead.
**System capability**: SystemCapability.MiscServices.ScreenLock **System capability**: SystemCapability.MiscServices.ScreenLock
**Return value** **Return value**
| Type| Description| | Type | Description |
| -------- | -------- | | ---------------------- | ------------------------------------------- |
| Promise&lt;boolean&gt; | Promise used to return the result.| | Promise&lt;boolean&gt; | Promise used to return the result. The value **true** means that the screen is locked, and **false** means the opposite.|
**Example** **Example**
```js ```js
screenlock.isScreenLocked().then((data) => { screenlock.isScreenLocked().then((data) => {
console.log('isScreenLocked success: data -> ${JSON.stringify(data)}'); console.log('isScreenLocked success: data -> ${JSON.stringify(data)}');
}).catch((err) => { }).catch((err) => {
console.error('isScreenLocked fail, promise: err -> ${JSON.stringify(err)}'); console.error('isScreenLocked fail, promise: err -> ${JSON.stringify(err)}');
}); });
``` ```
## screenlock.isLocked<sup>9+</sup>
isLocked(): boolean
Checks whether the screen is locked. This API returns the result synchronously.
**System capability**: SystemCapability.MiscServices.ScreenLock
**Return value**
| Type | Description |
| ------- | ------------------------------------------------- |
| boolean | Returns **true** if the screen is locked; returns **false** otherwise.|
**Example**
```js
let isLocked = screenlock.isLocked();
```
## screenlock.isSecureMode ## screenlock.isSecureMode
isSecureMode(callback: AsyncCallback&lt;boolean&gt;): void isSecureMode(callback: AsyncCallback&lt;boolean&gt;): void
Checks whether the device is in secure mode. This API uses an asynchronous callback to return the result.
Checks whether a device is in secure mode. This API uses an asynchronous callback to return the result. > **NOTE**
>
> This API is supported since API version 7 and deprecated since API version 9. You are advised to use [screenlock.isSecure<sup>9+</sup>](#screenlockissecure9) instead.
**System capability**: SystemCapability.MiscServices.ScreenLock **System capability**: SystemCapability.MiscServices.ScreenLock
**Parameters** **Parameters**
| Name| Type| Mandatory| Description| | Name | Type | Mandatory| Description |
| -------- | -------- | -------- | -------- | | -------- | --------------------- | ---- | ------------------------ |
| callback | AsyncCallback&lt;boolean&gt; | Yes| Callback used to return the result. Returns **true** if the device is in secure mode; returns **false** otherwise.| | callback | AsyncCallback&lt;boolean&gt; | Yes | Callback used to return the result. The value **true** means that the device is in secure mode, and **false** means the opposite.|
**Example** **Example**
```js ```js
screenlock.isSecureMode((err, data)=>{ screenlock.isSecureMode((err, data)=>{
if (err) { if (err) {
console.error('isSecureMode callback error -> ${JSON.stringify(err)}'); console.error('isSecureMode callback error -> ${JSON.stringify(err)}');
return; return;
} }
console.info('isSecureMode callback success data -> ${JSON.stringify(err)}'); console.info('isSecureMode callback success data -> ${JSON.stringify(err)}');
}); });
``` ```
## screenlock.isSecureMode ## screenlock.isSecureMode
isSecureMode(): Promise&lt;boolean&gt; isSecureMode(): Promise&lt;boolean&gt;
Checks whether a device is in secure mode. This API uses a promise to return the result. Checks whether the device is in secure mode. This API uses a promise to return the result.
> **NOTE**
>
> This API is supported since API version 7 and deprecated since API version 9. You are advised to use [screenlock.isSecure<sup>9+</sup>](#screenlockissecure9) instead.
**System capability**: SystemCapability.MiscServices.ScreenLock **System capability**: SystemCapability.MiscServices.ScreenLock
**Return value** **Return value**
| Type| Description| | Type | Description |
| -------- | -------- | | ---------------------- | ------------------------------------------------------------ |
| Promise&lt;boolean&gt; | Promise used to return the result.| | Promise&lt;boolean&gt; | Promise used to return the result. The value **true** means that the device is in secure mode, and **false** means the opposite.|
**Example** **Example**
```js ```js
screenlock.isSecureMode().then((data) => { screenlock.isSecureMode().then((data) => {
console.log('isSecureMode success: data->${JSON.stringify(data)}'); console.log('isSecureMode success: data->${JSON.stringify(data)}');
}).catch((err) => { }).catch((err) => {
console.error('isSecureMode fail, promise: err->${JSON.stringify(err)}'); console.error('isSecureMode fail, promise: err->${JSON.stringify(err)}');
}); });
``` ```
## screenlock.isSecure<sup>9+</sup>
isSecure(): boolean
Checks whether the device is in secure mode.
**System capability**: SystemCapability.MiscServices.ScreenLock
**Return value**
| Type | Description |
| ------- | ------------------------------------------------------------ |
| boolean | The value **true** means that the device is in secure mode, and **false** means the opposite.|
**Example**
```js
let isSecure = screenlock.isSecure();
```
## screenlock.unlockScreen ## screenlock.unlockScreen
unlockScreen(callback: AsyncCallback&lt;void&gt;): void unlockScreen(callback: AsyncCallback&lt;void&gt;): void
Unlocks the screen. This API uses an asynchronous callback to return the result. Unlocks the screen. This API uses an asynchronous callback to return the result.
> **NOTE**
>
> This API is supported since API version 7 and deprecated since API version 9. You are advised to use [screenlock.unlock<sup>9+</sup>](#screenlockunlock9) instead.
**System capability**: SystemCapability.MiscServices.ScreenLock **System capability**: SystemCapability.MiscServices.ScreenLock
**Parameters** **Parameters**
| Name| Type| Mandatory| Description| | Name | Type | Mandatory| Description |
| -------- | -------- | -------- | -------- | | -------- | ------------- | ---- | --------------- |
| callback | AsyncCallback&lt;void&gt; | Yes| Callback used to return the result. If the operation fails, an error message is returned.| | callback | AsyncCallback&lt;void&gt; | Yes| Callback used to return the result. If the operation fails, an error message is returned.|
**Example** **Example**
```js ```js
screenlock.unlockScreen((err) => { screenlock.unlockScreen((err) => {
if (err) { if (err) {
console.error('unlockScreen callback error -> ${JSON.stringify(err)}'); console.error('unlockScreen callback error -> ${JSON.stringify(err)}');
return; return;
} }
console.info('unlockScreen callback success'); console.info('unlockScreen callback success');
}); });
``` ```
## screenlock.unlockScreen ## screenlock.unlockScreen
...@@ -158,80 +204,131 @@ unlockScreen(): Promise&lt;void&gt; ...@@ -158,80 +204,131 @@ unlockScreen(): Promise&lt;void&gt;
Unlocks the screen. This API uses a promise to return the result. Unlocks the screen. This API uses a promise to return the result.
> **NOTE**
>
> This API is supported since API version 7 and deprecated since API version 9. You are advised to use [screenlock.unlock<sup>9+</sup>](#screenlockunlock9) instead.
**System capability**: SystemCapability.MiscServices.ScreenLock **System capability**: SystemCapability.MiscServices.ScreenLock
**Return value** **Return value**
| Type| Description| | Type | Description |
| -------- | -------- | | ------------------- | ------------------------- |
| Promise&lt;void&gt; | Promise used to return the result.| | Promise&lt;void&gt; | Promise that returns no value.|
**Example** **Example**
```js ```js
screenlock.unlockScreen().then(() => { screenlock.unlockScreen().then(() => {
console.log('unlockScreen success'); console.log('unlockScreen success');
}).catch((err) => { }).catch((err) => {
console.error('unlockScreen fail, promise: err->${JSON.stringify(err)}'); console.error('unlockScreen fail, promise: err->${JSON.stringify(err)}');
}); });
``` ```
## screenlock.unlock<sup>9+</sup>
## screenlock.lockScreen<sup>9+</sup> unlock(callback: AsyncCallback&lt;boolean&gt;): void
lockScreen(callback: AsyncCallback&lt;boolean&gt;): void Unlocks the screen. This API uses an asynchronous callback to return the result.
**System capability**: SystemCapability.MiscServices.ScreenLock
Locks the screen. This API uses an asynchronous callback to return the result. **Parameters**
| Name | Type | Mandatory| Description |
| -------- | --------------------- | ---- | ------------------------- |
| callback | AsyncCallback&lt;boolean&gt; | Yes | Callback used to return the result. The value **true** means that the screen is unlocked successfully, and **false** means the opposite.|
**Example**
```js
screenlock.unlock((err,data) => {
if (err) {
console.error('unlock error -> ${JSON.stringify(err)}');
return;
}
console.info('unlock success data -> ${JSON.stringify(data)}');
});
```
## screenlock.unlock<sup>9+</sup>
unlock(): Promise&lt;boolean&gt;
Unlocks the screen. This API uses a promise to return the result.
**System capability**: SystemCapability.MiscServices.ScreenLock
**Return value**
| Type | Description |
| ------------------- | ------------------------------------------------------------ |
| Promise&lt;boolean&gt; | Promise used to return the result. The value **true** means that the screen is unlocked successfully, and **false** means the opposite.|
**Example**
```js
screenlock.unlock().then((data) => {
console.log('unlock success');
}).catch((err) => {
console.error('unlock fail, : err->${JSON.stringify(err)}');
});
```
## screenlock.lock<sup>9+</sup>
lock(callback: AsyncCallback&lt;boolean&gt;): void
Locks the screen. This API uses an asynchronous callback to return the result.
**System capability**: SystemCapability.MiscServices.ScreenLock **System capability**: SystemCapability.MiscServices.ScreenLock
**System API**: This is a system API and cannot be called by third-party applications. **System API**: This is a system API.
**Parameters** **Parameters**
| Name| Type| Mandatory| Description| | Name | Type | Mandatory| Description |
| -------- | -------- | -------- | -------- | | -------- | ---------------------- | ---- | ---------------- |
| callback | AsyncCallback&lt;void&gt; | Yes| Callback used to return the result. If the operation fails, an error message is returned.| | callback | AsyncCallback&lt;boolean&gt; | Yes | Callback used to return the result. The value **true** means that the screen is locked successfully, and **false** means the opposite.|
**Example** **Example**
```js ```js
screenlock.lockScreen((err) => { screenlock.lock((err,data) => {
if (err) { if (err) {
console.error('lockScreen callback error -> ${JSON.stringify(err)}'); console.error('lock callback error -> ${JSON.stringify(err)}');
return; return;
} }
console.info('lockScreen callback success'); console.info('lock callback success');
}); });
``` ```
## screenlock.lockScreen<sup>9+</sup> ## screenlock.lock<sup>9+</sup>
lockScreen(): Promise&lt;boolean&gt; lock(): Promise&lt;boolean&gt;
Locks the screen. This API uses a promise to return the result. Locks the screen. This API uses a promise to return the result.
**System capability**: SystemCapability.MiscServices.ScreenLock **System capability**: SystemCapability.MiscServices.ScreenLock
**System API**: This is a system API and cannot be called by third-party applications. **System API**: This is a system API.
**Return value** **Return value**
| Type| Description| | Type | Description |
| -------- | -------- | | ---------------------- | ------------------------------------------------------------ |
| Promise&lt;void&gt; | Promise used to return the result.| | Promise&lt;boolean&gt; | Promise used to return the result. The value **true** means that the screen is locked successfully, and **false** means the opposite.|
**Example** **Example**
```js ```js
screenlock.lockScreen().then(() => { screenlock.lock().then((data) => {
console.log('lockScreen success'); console.log('lock success');
}).catch((err) => { }).catch((err) => {
console.error('lockScreen fail, promise: err->${JSON.stringify(err)}'); console.error('lock fail, promise: err->${JSON.stringify(err)}');
}); });
``` ```
## EventType ## EventType
...@@ -239,22 +336,22 @@ Defines the system event type. ...@@ -239,22 +336,22 @@ Defines the system event type.
**System capability**: SystemCapability.MiscServices.ScreenLock **System capability**: SystemCapability.MiscServices.ScreenLock
| Name| Description| | Event Type | Description |
| -------- | -------- | | ------------------ | ------------------------ |
| beginWakeUp | Wakeup starts when the event starts.| | beginWakeUp | Wakeup starts when the event starts.|
| endWakeUp | Wakeup ends when the event ends.| | endWakeUp | Wakeup ends when the event ends.|
| beginScreenOn | Screen turn-on starts when the event starts.| | beginScreenOn | Screen turn-on starts when the event starts.|
| endScreenOn | Screen turn-on ends when the event ends.| | endScreenOn | Screen turn-on ends when the event ends.|
| beginScreenOff | Screen turn-off starts when the event starts.| | beginScreenOff | Screen turn-off starts when the event starts.|
| endScreenOff | Screen turn-off ends when the event ends.| | endScreenOff | Screen turn-off ends when the event ends.|
| unlockScreen | The screen is unlocked.| | unlockScreen | The screen is unlocked. |
| lockScreen | The screen is locked.| | lockScreen | The screen is locked. |
| beginExitAnimation | Animation starts to exit.| | beginExitAnimation | Animation starts to exit. |
| beginSleep | The screen enters sleep mode.| | beginSleep | The screen enters sleep mode. |
| endSleep | The screen exits sleep mode.| | endSleep | The screen exits sleep mode. |
| changeUser | The user is switched.| | changeUser | The user is switched. |
| screenlockEnabled | Screen lock is enabled.| | screenlockEnabled | Screen lock is enabled. |
| serviceRestart | The screen lock service is restarted.| | serviceRestart | The screen lock service is restarted. |
## SystemEvent ## SystemEvent
...@@ -263,10 +360,10 @@ Defines the structure of the system event callback. ...@@ -263,10 +360,10 @@ Defines the structure of the system event callback.
**System capability**: SystemCapability.MiscServices.ScreenLock **System capability**: SystemCapability.MiscServices.ScreenLock
| Name| Description| | Name | Type | Mandatory| Description |
| -------- | -------- | | --------- | ------ | ---- | ------------- |
| eventType | System event type.| | eventType | [EventType](#eventtype) | Yes | System event type.|
| params | System event parameters.| | params | string | Yes | System event parameters.|
## screenlock.onSystemEvent<sup>9+</sup> ## screenlock.onSystemEvent<sup>9+</sup>
...@@ -276,87 +373,84 @@ Registers a callback for system events related to screen locking. ...@@ -276,87 +373,84 @@ Registers a callback for system events related to screen locking.
**System capability**: SystemCapability.MiscServices.ScreenLock **System capability**: SystemCapability.MiscServices.ScreenLock
**System API**: This is a system API and cannot be called by third-party applications. **System API**: This is a system API.
**Parameters** **Parameters**
| Name| Type| Mandatory| Description| | Name | Type | Mandatory| Description |
| -------- | -------- | -------- | -------- | | -------- | -------------------------------------- | ---- | ---------------------------- |
| callback | Callback\<SystemEvent\> | Yes| Callback for system events related to screen locking| | callback | Callback\<[SystemEvent](#systemevent)> | Yes | Callback for system events related to screen locking.|
**Return value** **Return value**
| Type | Description | | Type | Description |
| ------- | -------------------------------------------- | | ------- | ------------------------------------------------- |
| boolean | The value **true** means that the callback is registered successfully, and **false** means the opposite.| | boolean | Returns **true** if the callback is registered successfully; returns **false** otherwise.|
**Example** **Example**
```js ```js
let isSuccess = screenlock.onSystemEvent((err, event)=>{ let isSuccess = screenlock.onSystemEvent((event)=>{
console.log(`onSystemEvent:callback:${event.eventType}`) console.log(`onSystemEvent:callback:${event.eventType}`)
if (err) { });
console.log(`onSystemEvent callback error -> ${JSON.stringify(err)}`); if (!isSuccess) {
} console.log(`onSystemEvent result is false`)
}); }
if (!isSuccess) { ```
console.log(`onSystemEvent result is false`)
}
```
## screenlock.sendScreenLockEvent<sup>9+</sup> ## screenlock.sendScreenLockEvent<sup>9+</sup>
sendScreenLockEvent(event: String, parameter: number, callback: AsyncCallback\<boolean\>): void sendScreenLockEvent(event: String, parameter: number, callback: AsyncCallback\<boolean>): void
Sends an event to the screen lock service. This API uses an asynchronous callback to return the result. Sends an event to the screen lock service. This API uses an asynchronous callback to return the result.
**System capability**: SystemCapability.MiscServices.ScreenLock **System capability**: SystemCapability.MiscServices.ScreenLock
**System API**: This is a system API and cannot be called by third-party applications. **System API**: This is a system API.
**Parameters** **Parameters**
| Name| Type| Mandatory| Description| | Name | Type | Mandatory| Description |
| -------- | -------- | -------- | -------- | | --------- | ------------------------ | ---- | -------------------- |
| event | String | Yes| Event type.<br>- **"unlockScreenResult"**: Screen unlock result.<br>- **"screenDrawDone"**: Screen drawing is complete.| | event | String | Yes | Event type.<br>- **"unlockScreenResult"**: Screen unlock result.<br>- **"screenDrawDone"**: Screen drawing is complete.|
| parameter | number | Yes| Screen unlock status.<br>- **0**: The unlock is successful.<br>- **1**: The unlock failed.<br>- **2**: The unlock was canceled.| | parameter | number | Yes | Screen unlock status.<br>- **0**: The unlock is successful.<br>- **1**: The unlock failed.<br>- **2**: The unlock was canceled.|
| callback | AsyncCallback\<boolean\> | Yes| Callback used to return the result.| | callback | AsyncCallback\<boolean> | Yes | Callback used to return the result. The value **true** means that the operation is successful, and **false** means the opposite. |
**Example** **Example**
```js ```js
screenlock.sendScreenLockEvent('unlockScreenResult', 0, (err, result) => { screenlock.sendScreenLockEvent('unlockScreenResult', 0, (err, result) => {
console.log('sending result:' + result); console.log('sending result:' + result);
}); });
``` ```
## screenlock.sendScreenLockEvent<sup>9+</sup> ## screenlock.sendScreenLockEvent<sup>9+</sup>
sendScreenLockEvent(event: String, parameter: number): Promise\<boolean\> sendScreenLockEvent(event: String, parameter: number): Promise\<boolean>
Sends an event to the screen lock service. This API uses a promise to return the result. Sends an event to the screen lock service. This API uses a promise to return the result.
**System capability**: SystemCapability.MiscServices.ScreenLock **System capability**: SystemCapability.MiscServices.ScreenLock
**System API**: This is a system API and cannot be called by third-party applications. **System API**: This is a system API.
**Parameters** **Parameters**
| Name| Type| Mandatory| Description| | Name | Type | Mandatory| Description |
| -------- | -------- | -------- | -------- | | --------- | ------ | ---- | --------------------------------------- |
| event | String | Yes| Event type.<br>- **"unlockScreenResult"**: Screen unlock result.<br>- **"screenDrawDone"**: Screen drawing is complete.| | event | String | Yes | Event type.<br>- **"unlockScreenResult"**: Screen unlock result.<br>- **"screenDrawDone"**: Screen drawing is complete.|
| parameter | number | Yes| Screen unlock status.<br>- **0**: The unlock is successful.<br>- **1**: The unlock fails.<br>- **2**: The unlock is canceled.| | parameter | number | Yes | Screen unlock status.<br>- **0**: The unlock is successful.<br>- **1**: The unlock failed.<br>- **2**: The unlock was canceled.|
**Return value** **Return value**
| Type| Description| | Type | Description |
| -------- | -------- | | ------------------ | ------------------------------------------------------------ |
| Promise\<boolean\> | Promise used to return the result.| | Promise\<boolean> | Promise used to return the result. The value **true** means that the operation is successful, and **false** means the opposite.|
**Example** **Example**
```js ```js
screenlock.sendScreenLockEvent('unlockScreenResult', 0).then((result) => { screenlock.sendScreenLockEvent('unlockScreenResult', 0).then((result) => {
console.log('sending result:' + result); console.log('sending result:' + result);
}); });
``` ```
...@@ -17,14 +17,14 @@ import wallpaper from '@ohos.wallpaper'; ...@@ -17,14 +17,14 @@ import wallpaper from '@ohos.wallpaper';
## WallpaperType ## WallpaperType
Defines the wallpaper type. Enumerates the wallpaper types.
**System capability**: SystemCapability.MiscServices.Wallpaper **System capability**: SystemCapability.MiscServices.Wallpaper
| Name| Description| | Name| Value|Description|
| -------- | -------- | | -------- | -------- |-------- |
| WALLPAPER_LOCKSCREEN | Lock screen wallpaper.| | WALLPAPER_SYSTEM | 0 |Home screen wallpaper.|
| WALLPAPER_SYSTEM | Home screen wallpaper.| | WALLPAPER_LOCKSCREEN | 1 |Lock screen wallpaper.|
## wallpaper.getColors ## wallpaper.getColors
...@@ -33,6 +33,10 @@ getColors(wallpaperType: WallpaperType, callback: AsyncCallback&lt;Array&lt;Rgba ...@@ -33,6 +33,10 @@ getColors(wallpaperType: WallpaperType, callback: AsyncCallback&lt;Array&lt;Rgba
Obtains the main color information of the wallpaper of the specified type. This API uses an asynchronous callback to return the result. Obtains the main color information of the wallpaper of the specified type. This API uses an asynchronous callback to return the result.
> **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.
**System capability**: SystemCapability.MiscServices.Wallpaper **System capability**: SystemCapability.MiscServices.Wallpaper
**Parameters** **Parameters**
...@@ -61,6 +65,10 @@ getColors(wallpaperType: WallpaperType): Promise&lt;Array&lt;RgbaColor&gt;&gt; ...@@ -61,6 +65,10 @@ getColors(wallpaperType: WallpaperType): Promise&lt;Array&lt;RgbaColor&gt;&gt;
Obtains the main color information of the wallpaper of the specified type. This API uses a promise to return the result. Obtains the main color information of the wallpaper of the specified type. This API uses a promise to return the result.
> **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.
**System capability**: SystemCapability.MiscServices.Wallpaper **System capability**: SystemCapability.MiscServices.Wallpaper
**Parameters** **Parameters**
...@@ -86,12 +94,43 @@ Obtains the main color information of the wallpaper of the specified type. This ...@@ -86,12 +94,43 @@ Obtains the main color information of the wallpaper of the specified type. This
``` ```
## wallpaper.getColorsSync<sup>9+</sup>
getColorsSync(wallpaperType: WallpaperType): Array&lt;RgbaColor&gt;
Obtains the main color information of the wallpaper of the specified type. This API uses an asynchronous callback to return the result.
**System capability**: SystemCapability.MiscServices.Wallpaper
**Parameters**
| Name| Type| Mandatory| Description|
| -------- | -------- | -------- | -------- |
| wallpaperType | [WallpaperType](#wallpapertype) | Yes| Wallpaper type.|
**Return value**
| Type| Description|
| -------- | -------- |
| Array&lt;[RgbaColor](#rgbacolor)&gt; | Promise used to return the main color information of the wallpaper.|
**Example**
```js
var colors = wallpaper.getColorsSync(wallpaper.WallpaperType.WALLPAPER_SYSTEM);
```
## wallpaper.getId ## wallpaper.getId
getId(wallpaperType: WallpaperType, callback: AsyncCallback&lt;number&gt;): void getId(wallpaperType: WallpaperType, callback: AsyncCallback&lt;number&gt;): void
Obtains the ID of the wallpaper of the specified type. This API uses an asynchronous callback to return the result. Obtains the ID of the wallpaper of the specified type. This API uses an asynchronous callback to return the result.
> **NOTE**
>
> 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.
**System capability**: SystemCapability.MiscServices.Wallpaper **System capability**: SystemCapability.MiscServices.Wallpaper
**Parameters** **Parameters**
...@@ -120,8 +159,11 @@ getId(wallpaperType: WallpaperType): Promise&lt;number&gt; ...@@ -120,8 +159,11 @@ getId(wallpaperType: WallpaperType): Promise&lt;number&gt;
Obtains the ID of the wallpaper of the specified type. This API uses a promise to return the result. Obtains the ID of the wallpaper of the specified type. This API uses a promise to return the result.
**System capability**: SystemCapability.MiscServices.Wallpaper > **NOTE**
>
> 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.
**System capability**: SystemCapability.MiscServices.Wallpaper
**Parameters** **Parameters**
...@@ -146,12 +188,43 @@ Obtains the ID of the wallpaper of the specified type. This API uses a promise t ...@@ -146,12 +188,43 @@ Obtains the ID of the wallpaper of the specified type. This API uses a promise t
``` ```
## wallpaper.getIdSync<sup>9+</sup>
getIdSync(wallpaperType: WallpaperType): number
Obtains the ID of the wallpaper of the specified type. This API uses an asynchronous callback to return the result.
**System capability**: SystemCapability.MiscServices.Wallpaper
**Parameters**
| Name| Type| Mandatory| Description|
| -------- | -------- | -------- | -------- |
| wallpaperType | [WallpaperType](#wallpapertype) | Yes| Wallpaper type.|
**Return value**
| Type| Description|
| -------- | -------- |
| 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.|
**Example**
```js
var id = wallpaper.getIdSync(wallpaper.WallpaperType.WALLPAPER_SYSTEM);
```
## wallpaper.getMinHeight ## wallpaper.getMinHeight
getMinHeight(callback: AsyncCallback&lt;number&gt;): void getMinHeight(callback: AsyncCallback&lt;number&gt;): void
Obtains the minimum height of this wallpaper. This API uses an asynchronous callback to return the result. Obtains the minimum height of this wallpaper. This API uses an asynchronous callback to return the result.
> **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.
**System capability**: SystemCapability.MiscServices.Wallpaper **System capability**: SystemCapability.MiscServices.Wallpaper
**Parameters** **Parameters**
...@@ -179,8 +252,11 @@ getMinHeight(): Promise&lt;number&gt; ...@@ -179,8 +252,11 @@ getMinHeight(): Promise&lt;number&gt;
Obtains the minimum height of this wallpaper. This API uses a promise to return the result. Obtains the minimum height of this wallpaper. This API uses a promise to return the result.
**System capability**: SystemCapability.MiscServices.Wallpaper > **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.
**System capability**: SystemCapability.MiscServices.Wallpaper
**Return value** **Return value**
...@@ -199,14 +275,38 @@ Obtains the minimum height of this wallpaper. This API uses a promise to return ...@@ -199,14 +275,38 @@ Obtains the minimum height of this wallpaper. This API uses a promise to return
``` ```
## wallpaper.getMinHeightSync<sup>9+</sup>
getMinHeightSync(): number
Obtains the minimum height of this wallpaper. This API uses an asynchronous callback to return the result.
**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
var minHeight = wallpaper.getMinHeightSync();
```
## wallpaper.getMinWidth ## wallpaper.getMinWidth
getMinWidth(callback: AsyncCallback&lt;number&gt;): void getMinWidth(callback: AsyncCallback&lt;number&gt;): void
Obtains the minimum width of this wallpaper. This API uses an asynchronous callback to return the result. Obtains the minimum width of this wallpaper. This API uses an asynchronous callback to return the result.
**System capability**: SystemCapability.MiscServices.Wallpaper > **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.
**System capability**: SystemCapability.MiscServices.Wallpaper
**Parameters** **Parameters**
...@@ -233,13 +333,17 @@ getMinWidth(): Promise&lt;number&gt; ...@@ -233,13 +333,17 @@ getMinWidth(): Promise&lt;number&gt;
Obtains the minimum width of this wallpaper. This API uses a promise to return the result. Obtains the minimum width of this wallpaper. This API uses a promise to return the result.
> **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.
**System capability**: SystemCapability.MiscServices.Wallpaper **System capability**: SystemCapability.MiscServices.Wallpaper
**Return value** **Return value**
| Type| Description| | Type| Description|
| -------- | -------- | | -------- | -------- |
| Promise&lt;number&gt; | Promised 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.| | 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.|
**Example** **Example**
...@@ -252,19 +356,44 @@ Obtains the minimum width of this wallpaper. This API uses a promise to return t ...@@ -252,19 +356,44 @@ Obtains the minimum width of this wallpaper. This API uses a promise to return t
``` ```
## wallpaper.getMinWidthSync<sup>9+</sup>
getMinWidthSync(): number
Obtains the minimum width of this wallpaper. This API uses an asynchronous callback to return the result.
**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
var minWidth = wallpaper.getMinWidthSync();
```
## wallpaper.isChangePermitted ## wallpaper.isChangePermitted
isChangePermitted(callback: AsyncCallback&lt;boolean&gt;): void isChangePermitted(callback: AsyncCallback&lt;boolean&gt;): void
Checks whether to allow the application to change the wallpaper for the current user. This API uses an asynchronous callback to return the result. Checks whether to allow the application to change the wallpaper for the current user. This API uses an asynchronous callback to return the result.
> **NOTE**
>
> 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.
**System capability**: SystemCapability.MiscServices.Wallpaper **System capability**: SystemCapability.MiscServices.Wallpaper
**Parameters** **Parameters**
| Name| Type| Mandatory| Description| | Name| Type| Mandatory| Description|
| -------- | -------- | -------- | -------- | | -------- | -------- | -------- | -------- |
| callback | AsyncCallback&lt;boolean&gt; | Yes| Callback used to return the result. Returns **true** if the application is allowed to change the wallpaper for the current user; returns **false** otherwise.| | 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.|
**Example** **Example**
...@@ -285,13 +414,17 @@ isChangePermitted(): Promise&lt;boolean&gt; ...@@ -285,13 +414,17 @@ isChangePermitted(): Promise&lt;boolean&gt;
Checks whether to allow the application to change the wallpaper for the current user. This API uses a promise to return the result. Checks whether to allow the application to change the wallpaper for the current user. This API uses a promise to return the result.
> **NOTE**
>
> 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.
**System capability**: SystemCapability.MiscServices.Wallpaper **System capability**: SystemCapability.MiscServices.Wallpaper
**Return value** **Return value**
| Type| Description| | Type| Description|
| -------- | -------- | | -------- | -------- |
| Promise&lt;boolean&gt; | Promise used to return the result. Returns **true** if the application is allowed to change the wallpaper for the current user; returns **false** otherwise.| | 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.|
**Example** **Example**
...@@ -304,19 +437,44 @@ Checks whether to allow the application to change the wallpaper for the current ...@@ -304,19 +437,44 @@ Checks whether to allow the application to change the wallpaper for the current
``` ```
## wallpaper.isChangeAllowed<sup>9+</sup>
isChangeAllowed(): boolean
Checks whether to allow the application to change the wallpaper for the current user. This API uses an asynchronous callback to return the result.
**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
var isChangeAllowed = wallpaper.isChangeAllowed();
```
## wallpaper.isOperationAllowed ## wallpaper.isOperationAllowed
isOperationAllowed(callback: AsyncCallback&lt;boolean&gt;): void isOperationAllowed(callback: AsyncCallback&lt;boolean&gt;): void
Checks whether the user is allowed to set wallpapers. This API uses an asynchronous callback to return the result. Checks whether the user is allowed to set wallpapers. This API uses an asynchronous callback to return the result.
> **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.
**System capability**: SystemCapability.MiscServices.Wallpaper **System capability**: SystemCapability.MiscServices.Wallpaper
**Parameters** **Parameters**
| Name| Type| Mandatory| Description| | Name| Type| Mandatory| Description|
| -------- | -------- | -------- | -------- | | -------- | -------- | -------- | -------- |
| callback | AsyncCallback&lt;boolean&gt; | Yes| Callback used to return the result. Returns **true** if the user is allowed to set wallpapers; returns **false** otherwise.| | 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.|
**Example** **Example**
...@@ -337,13 +495,17 @@ isOperationAllowed(): Promise&lt;boolean&gt; ...@@ -337,13 +495,17 @@ isOperationAllowed(): Promise&lt;boolean&gt;
Checks whether the user is allowed to set wallpapers. This API uses a promise to return the result. Checks whether the user is allowed to set wallpapers. This API uses a promise to return the result.
> **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.
**System capability**: SystemCapability.MiscServices.Wallpaper **System capability**: SystemCapability.MiscServices.Wallpaper
**Return value** **Return value**
| Type| Description| | Type| Description|
| -------- | -------- | | -------- | -------- |
| Promise&lt;boolean&gt; | Promise used to return the result. Returns **true** if the user is allowed to set wallpapers; returns **false** otherwise.| | 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.|
**Example** **Example**
...@@ -356,12 +518,37 @@ Checks whether the user is allowed to set wallpapers. This API uses a promise to ...@@ -356,12 +518,37 @@ Checks whether the user is allowed to set wallpapers. This API uses a promise to
``` ```
## wallpaper.isUserChangeAllowed<sup>9+</sup>
isUserChangeAllowed(): boolean
Checks whether the user is allowed to set wallpapers. This API uses an asynchronous callback to return the result.
**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
var isUserChangeAllowed = wallpaper.isUserChangeAllowed();
```
## wallpaper.reset ## wallpaper.reset
reset(wallpaperType: WallpaperType, callback: AsyncCallback&lt;void&gt;): void reset(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. Resets the wallpaper of the specified type to the default wallpaper. This API uses an asynchronous callback to return the result.
> **NOTE**
>
> 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.
**Required permissions**: ohos.permission.SET_WALLPAPER **Required permissions**: ohos.permission.SET_WALLPAPER
**System capability**: SystemCapability.MiscServices.Wallpaper **System capability**: SystemCapability.MiscServices.Wallpaper
...@@ -392,6 +579,10 @@ reset(wallpaperType: WallpaperType): Promise&lt;void&gt; ...@@ -392,6 +579,10 @@ reset(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. Resets the wallpaper of the specified type to the default wallpaper. This API uses a promise to return the result.
> **NOTE**
>
> 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.
**Required permissions**: ohos.permission.SET_WALLPAPER **Required permissions**: ohos.permission.SET_WALLPAPER
**System capability**: SystemCapability.MiscServices.Wallpaper **System capability**: SystemCapability.MiscServices.Wallpaper
...@@ -419,12 +610,79 @@ Resets the wallpaper of the specified type to the default wallpaper. This API us ...@@ -419,12 +610,79 @@ Resets the wallpaper of the specified type to the default wallpaper. This API us
``` ```
## 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.|
| callback | AsyncCallback&lt;void&gt; | Yes| Callback used to return the result. If the operation is successful, the result of removal is returned. Otherwise, error information is returned.|
**Example**
```js
wallpaper.restore(wallpaper.WallpaperType.WALLPAPER_SYSTEM, (error, data) => {
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 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.|
**Return value**
| Type| Description|
| -------- | -------- |
| Promise&lt;void&gt; | Promise used to return the result. If the operation is successful, the result is returned. Otherwise, error information is returned.|
**Example**
```js
wallpaper.restore(wallpaper.WallpaperType.WALLPAPER_SYSTEM).then((data) => {
console.log(`success to restore.`);
}).catch((error) => {
console.error(`failed to restore because: ` + JSON.stringify(error));
});
```
## wallpaper.setWallpaper ## wallpaper.setWallpaper
setWallpaper(source: string | image.PixelMap, wallpaperType: WallpaperType, callback: AsyncCallback&lt;void&gt;): void setWallpaper(source: string | image.PixelMap, wallpaperType: WallpaperType, callback: AsyncCallback&lt;void&gt;): void
Sets a specified source as the wallpaper of a specified type. This API uses an asynchronous callback to return the result. Sets a specified source as the wallpaper of a specified type. This API uses an asynchronous callback to return the result.
> **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.
**Required permissions**: ohos.permission.SET_WALLPAPER **Required permissions**: ohos.permission.SET_WALLPAPER
**System capability**: SystemCapability.MiscServices.Wallpaper **System capability**: SystemCapability.MiscServices.Wallpaper
...@@ -433,7 +691,7 @@ Sets a specified source as the wallpaper of a specified type. This API uses an a ...@@ -433,7 +691,7 @@ Sets a specified source as the wallpaper of a specified type. This API uses an a
| Name| Type| Mandatory| Description| | Name| Type| Mandatory| Description|
| -------- | -------- | -------- | -------- | | -------- | -------- | -------- | -------- |
| source | string \|[PixelMap](js-apis-image.md#pixelmap7) | | URI of a JPEG or PNG file, or bitmap of a PNG file.| | source | string \|[image.PixelMap](js-apis-image.md#pixelmap7) | Yes| URI of a JPEG or PNG file, or bitmap of a PNG file.|
| wallpaperType | [WallpaperType](#wallpapertype) | Yes| Wallpaper type.| | wallpaperType | [WallpaperType](#wallpapertype) | Yes| Wallpaper type.|
| callback | AsyncCallback&lt;void&gt; | Yes| Callback used to return the result. If the operation is successful, the setting result is returned. Otherwise, error information is returned.| | callback | AsyncCallback&lt;void&gt; | Yes| Callback used to return the result. If the operation is successful, the setting result is returned. Otherwise, error information is returned.|
...@@ -479,6 +737,10 @@ setWallpaper(source: string | image.PixelMap, wallpaperType: WallpaperType): Pro ...@@ -479,6 +737,10 @@ setWallpaper(source: string | image.PixelMap, wallpaperType: WallpaperType): Pro
Sets a specified source as the wallpaper of a specified type. This API uses a promise to return the result. Sets a specified source as the wallpaper of a specified type. This API uses a promise to return the result.
> **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.
**Required permissions**: ohos.permission.SET_WALLPAPER **Required permissions**: ohos.permission.SET_WALLPAPER
**System capability**: SystemCapability.MiscServices.Wallpaper **System capability**: SystemCapability.MiscServices.Wallpaper
...@@ -487,7 +749,7 @@ Sets a specified source as the wallpaper of a specified type. This API uses a pr ...@@ -487,7 +749,7 @@ Sets a specified source as the wallpaper of a specified type. This API uses a pr
| Name| Type| Mandatory| Description| | Name| Type| Mandatory| Description|
| -------- | -------- | -------- | -------- | | -------- | -------- | -------- | -------- |
| source | string \|[PixelMap](js-apis-image.md#pixelmap7) | Yes| URI of a JPEG or PNG file, or bitmap of a PNG file.| | source | string \|[image.PixelMap](js-apis-image.md#pixelmap7) | Yes| URI of a JPEG or PNG file, or bitmap of a PNG file.|
| wallpaperType | [WallpaperType](#wallpapertype) | Yes| Wallpaper type.| | wallpaperType | [WallpaperType](#wallpapertype) | Yes| Wallpaper type.|
**Return value** **Return value**
...@@ -499,7 +761,7 @@ Sets a specified source as the wallpaper of a specified type. This API uses a pr ...@@ -499,7 +761,7 @@ Sets a specified source as the wallpaper of a specified type. This API uses a pr
**Example** **Example**
```js ```js
// The source type is string. //The source type is string.
let wallpaperPath = "/data/data/ohos.acts.aafwk.plrdtest.form/files/Cup_ic.jpg"; let wallpaperPath = "/data/data/ohos.acts.aafwk.plrdtest.form/files/Cup_ic.jpg";
wallpaper.setWallpaper(wallpaperPath, wallpaper.WallpaperType.WALLPAPER_SYSTEM).then((data) => { wallpaper.setWallpaper(wallpaperPath, wallpaper.WallpaperType.WALLPAPER_SYSTEM).then((data) => {
console.log(`success to setWallpaper.`); console.log(`success to setWallpaper.`);
...@@ -527,12 +789,126 @@ Sets a specified source as the wallpaper of a specified type. This API uses a pr ...@@ -527,12 +789,126 @@ Sets a specified source as the wallpaper of a specified type. This API uses a pr
}); });
``` ```
## wallpaper.setImage<sup>9+</sup>
setImage(source: string | image.PixelMap, wallpaperType: WallpaperType, callback: AsyncCallback&lt;void&gt;): void
Sets a specified source as the wallpaper of a specified type. 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|
| -------- | -------- | -------- | -------- |
| source | string \|[image.PixelMap](js-apis-image.md#pixelmap7) | Yes| URI of a JPEG or PNG file, or bitmap of a PNG file.|
| wallpaperType | [WallpaperType](#wallpapertype) | Yes| Wallpaper type.|
| callback | AsyncCallback&lt;void&gt; | Yes| Callback used to return the result. If the operation is successful, the setting result is returned. Otherwise, error information is returned.|
**Example**
```js
//The source type is string.
let wallpaperPath = "/data/data/ohos.acts.aafwk.plrdtest.form/files/Cup_ic.jpg";
wallpaper.setImage(wallpaperPath, wallpaper.WallpaperType.WALLPAPER_SYSTEM, (error, data) => {
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, data) => {
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));
});
```
## wallpaper.setImage<sup>9+</sup>
setImage(source: string | image.PixelMap, wallpaperType: WallpaperType): Promise&lt;void&gt;
Sets a specified source as the wallpaper of a specified type. 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|
| -------- | -------- | -------- | -------- |
| source | string \|[image.PixelMap](js-apis-image.md#pixelmap7) | Yes| URI of a JPEG or PNG file, or bitmap of a PNG file.|
| wallpaperType | [WallpaperType](#wallpapertype) | Yes| Wallpaper type.|
**Return value**
| Type| Description|
| -------- | -------- |
| Promise&lt;void&gt; | Promise used to return the result. If the operation is successful, the setting result is returned. Otherwise, error information is returned.|
**Example**
```js
//The source type is string.
let wallpaperPath = "/data/data/ohos.acts.aafwk.plrdtest.form/files/Cup_ic.jpg";
wallpaper.setImage(wallpaperPath, wallpaper.WallpaperType.WALLPAPER_SYSTEM).then((data) => {
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((data) => {
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));
});
```
## wallpaper.getFile<sup>8+</sup> ## wallpaper.getFile<sup>8+</sup>
getFile(wallpaperType: WallpaperType, callback: AsyncCallback&lt;number&gt;): void getFile(wallpaperType: WallpaperType, callback: AsyncCallback&lt;number&gt;): void
Obtains the wallpaper of the specified type. This API uses an asynchronous callback to return the result. Obtains the wallpaper of the specified type. This API uses an asynchronous callback to return the result.
> **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.
**Required permissions**: ohos.permission.GET_WALLPAPER **Required permissions**: ohos.permission.GET_WALLPAPER
**System capability**: SystemCapability.MiscServices.Wallpaper **System capability**: SystemCapability.MiscServices.Wallpaper
...@@ -562,6 +938,10 @@ getFile(wallpaperType: WallpaperType): Promise&lt;number&gt; ...@@ -562,6 +938,10 @@ getFile(wallpaperType: WallpaperType): Promise&lt;number&gt;
Obtains the wallpaper of the specified type. This API uses a promise to return the result. Obtains the wallpaper of the specified type. This API uses a promise to return the result.
> **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.
**Required permissions**: ohos.permission.GET_WALLPAPER **Required permissions**: ohos.permission.GET_WALLPAPER
**System capability**: SystemCapability.MiscServices.Wallpaper **System capability**: SystemCapability.MiscServices.Wallpaper
...@@ -589,12 +969,45 @@ Obtains the wallpaper of the specified type. This API uses a promise to return t ...@@ -589,12 +969,45 @@ Obtains the wallpaper of the specified type. This API uses a promise to return t
``` ```
## wallpaper.getFileSync<sup>9+</sup>
getFileSync(wallpaperType: WallpaperType): number;
Obtains the wallpaper of the specified type. This API uses an asynchronous callback to return the result.
**Required permissions**: ohos.permission.GET_WALLPAPER
**System capability**: SystemCapability.MiscServices.Wallpaper
**Parameters**
| Name| Type| Mandatory| Description|
| -------- | -------- | -------- | -------- |
| wallpaperType | [WallpaperType](#wallpapertype) | Yes| Wallpaper type.|
**Return value**
| Type| Description|
| -------- | -------- |
| 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.|
**Example**
```js
var file = wallpaper.getFileSync(wallpaper.WallpaperType.WALLPAPER_SYSTEM);
```
## wallpaper.getPixelMap ## wallpaper.getPixelMap
getPixelMap(wallpaperType: WallpaperType, callback: AsyncCallback&lt;image.PixelMap&gt;): void; getPixelMap(wallpaperType: WallpaperType, callback: AsyncCallback&lt;image.PixelMap&gt;): void;
Obtains the pixel map for the wallpaper of the specified type. This API uses an asynchronous callback to return the result. Obtains the pixel map for the wallpaper of the specified type. This API uses an asynchronous callback to return the result.
> **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.
**Required permissions**: ohos.permission.GET_WALLPAPER **Required permissions**: ohos.permission.GET_WALLPAPER
**System capability**: SystemCapability.MiscServices.Wallpaper **System capability**: SystemCapability.MiscServices.Wallpaper
...@@ -606,7 +1019,7 @@ Obtains the pixel map for the wallpaper of the specified type. This API uses an ...@@ -606,7 +1019,7 @@ Obtains the pixel map for the wallpaper of the specified type. This API uses an
| Name| Type| Mandatory| Description| | Name| Type| Mandatory| Description|
| -------- | -------- | -------- | -------- | | -------- | -------- | -------- | -------- |
| wallpaperType | [WallpaperType](#wallpapertype) | Yes| Wallpaper type.| | wallpaperType | [WallpaperType](#wallpapertype) | Yes| Wallpaper type.|
| callback | AsyncCallback&lt;void&gt; | Yes| Callback used to return the result. Returns the pixel map size of the wallpaper if the operation is successful; returns an error message otherwise.| | callback | AsyncCallback&lt;image.PixelMap&gt; | Yes| Callback used to return the result. Returns the pixel map size of the wallpaper if the operation is successful; returns an error message otherwise.|
**Example** **Example**
...@@ -624,6 +1037,10 @@ getPixelMap(wallpaperType: WallpaperType): Promise&lt;image.PixelMap&gt; ...@@ -624,6 +1037,10 @@ getPixelMap(wallpaperType: WallpaperType): Promise&lt;image.PixelMap&gt;
Obtains the pixel map for the wallpaper of the specified type. This API uses a promise to return the result. Obtains the pixel map for the wallpaper of the specified type. This API uses a promise to return the result.
> **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.
**Required permissions**: ohos.permission.GET_WALLPAPER **Required permissions**: ohos.permission.GET_WALLPAPER
**System capability**: SystemCapability.MiscServices.Wallpaper **System capability**: SystemCapability.MiscServices.Wallpaper
...@@ -640,7 +1057,7 @@ Obtains the pixel map for the wallpaper of the specified type. This API uses a p ...@@ -640,7 +1057,7 @@ Obtains the pixel map for the wallpaper of the specified type. This API uses a p
| Type| Description| | Type| Description|
| -------- | -------- | | -------- | -------- |
| Promise&lt;void&gt; | Promise used to return the result. Returns the pixel map size of the wallpaper if the operation is successful; returns an error message otherwise.| | Promise&lt;image.PixelMap&gt; | Promise used to return the result. Returns the pixel map size of the wallpaper if the operation is successful; returns an error message otherwise.|
**Example** **Example**
...@@ -655,7 +1072,73 @@ Obtains the pixel map for the wallpaper of the specified type. This API uses a p ...@@ -655,7 +1072,73 @@ Obtains the pixel map for the wallpaper of the specified type. This API uses a p
``` ```
## wallpaper.on('colorChange') ## wallpaper.getImage<sup>9+</sup>
getImage(wallpaperType: WallpaperType, callback: AsyncCallback&lt;image.PixelMap&gt;): void;
Obtains the pixel map for the wallpaper of the specified type. This API uses an asynchronous callback to return the result.
**Required permissions**: ohos.permission.GET_WALLPAPER
**System capability**: SystemCapability.MiscServices.Wallpaper
**System API**: This is a system API and cannot be called by third-party applications.
**Parameters**
| Name| Type| Mandatory| Description|
| -------- | -------- | -------- | -------- |
| wallpaperType | [WallpaperType](#wallpapertype) | Yes| Wallpaper type.|
| callback | AsyncCallback&lt;[image.PixelMap](js-apis-image.md#pixelmap7)&gt; | Yes| Callback used to return the result. Returns the pixel map size of the wallpaper if the operation is successful; returns an error message otherwise.|
**Example**
```js
wallpaper.getImage(wallpaper.WallpaperType.WALLPAPER_SYSTEM, function (err, data) {
console.info('wallpaperXTS ===> testgetImageCallbackSystem err : ' + JSON.stringify(err));
console.info('wallpaperXTS ===> testgetImageCallbackSystem data : ' + JSON.stringify(data));
});
```
## wallpaper.getImage<sup>9+</sup>
getImage(wallpaperType: WallpaperType): Promise&lt;image.PixelMap&gt;
Obtains the pixel map for the wallpaper of the specified type. This API uses an asynchronous callback to return the result.
**Required permissions**: ohos.permission.GET_WALLPAPER
**System capability**: SystemCapability.MiscServices.Wallpaper
**System API**: This is a system API and cannot be called by third-party applications.
**Parameters**
| Name| Type| Mandatory| Description|
| -------- | -------- | -------- | -------- |
| wallpaperType | [WallpaperType](#wallpapertype) | Yes| Wallpaper type.|
**Return value**
| Type| Description|
| -------- | -------- |
| Promise&lt;[image.PixelMap](js-apis-image.md#pixelmap7)&gt; | Promise used to return the result. Returns the pixel map size of the wallpaper if the operation is successful; returns an error message otherwise.|
**Example**
```js
wallpaper.getImage(wallpaper.WallpaperType.WALLPAPER_SYSTEM).then((data) => {
console.info('wallpaperXTS ===> testgetImagePromiseSystem data : ' + data);
console.info('wallpaperXTS ===> testgetImagePromiseSystem data : ' + JSON.stringify(data));
}).catch((err) => {
console.info('wallpaperXTS ===> testgetImagePromiseSystem err : ' + err);
console.info('wallpaperXTS ===> testgetImagePromiseSystem err : ' + JSON.stringify(err));
});
```
## wallpaper.on('colorChange')<sup>9+</sup>
on(type: 'colorChange', callback: (colors: Array&lt;RgbaColor&gt;, wallpaperType: WallpaperType) =&gt; void): void on(type: 'colorChange', callback: (colors: Array&lt;RgbaColor&gt;, wallpaperType: WallpaperType) =&gt; void): void
...@@ -680,7 +1163,7 @@ Subscribes to the wallpaper color change event. ...@@ -680,7 +1163,7 @@ Subscribes to the wallpaper color change event.
``` ```
## wallpaper.off('colorChange') ## wallpaper.off('colorChange')<sup>9+</sup>
off(type: 'colorChange', callback?: (colors: Array&lt;RgbaColor&gt;, wallpaperType: WallpaperType) =&gt; void): void off(type: 'colorChange', callback?: (colors: Array&lt;RgbaColor&gt;, wallpaperType: WallpaperType) =&gt; void): void
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册