With device usage statistics APIs, you can have a better understanding of the application, notification, and system usage. For example, in application usage statistics, you can query the application usage, event log, and bundle group.
The application records (usage history statistics and event records) cached by components are updated to the database for persistent storage within 30 minutes after an event is reported.
## Available APIs
...
...
@@ -19,9 +20,20 @@ import stats from '@ohos.bundleState';
| function queryBundleStateInfos(begin: number, end: number, callback: AsyncCallback<BundleActiveInfoResponse>): void | Queries the application usage duration statistics based on the specified start time and end time.|
| function queryCurrentBundleActiveStates(begin: number, end: number, callback: AsyncCallback<Array<BundleActiveState>>): void | Queries events of this application based on the specified start time and end time.|
| function queryBundleStateInfoByInterval(byInterval: IntervalType, begin: number, end: number, callback: AsyncCallback<Array<BundleStateInfo>>): void | Queries the application usage duration statistics in the specified time frame at the specified interval (daily, weekly, monthly, or annually).|
| function queryAppUsagePriorityGroup(callback: AsyncCallback<number>): void | Queries the priority group of the current invoker application.|
| function queryAppUsagePriorityGroup(callback: AsyncCallback<number>): void | Queries the priority group of this application. This API uses an asynchronous callback to return the result.|
| function queryAppUsagePriorityGroup(): Promise<number>; | Queries the priority group of this application. This API uses a promise to return the result.|
| function isIdleState(bundleName: string, callback: AsyncCallback<boolean>): void | Checks whether the application specified by **bundleName** is in the idle state. |
| function getRecentlyUsedModules(maxNum: number, callback: AsyncCallback<BundleActiveModuleInfo>): void | Obtains the number of FA usage records specified by **maxNum**.|
| function queryAppNotificationNumber(begin: number, end: number, callback: AsyncCallback<Array<BundleActiveEventState>>): void | Queries the number of notifications from all applications based on the specified start time and end time.|
| function queryBundleActiveEventStates(begin: number, end: number, callback: AsyncCallback<Array<BundleActiveEventState>>): void | Queries statistics about system events (hibernation, wakeup, unlocking, and screen locking) that occur between the specified start time and end time.|
| function queryAppUsagePriorityGroup(bundleName? : string, callback: AsyncCallback<number>): void | Queries the priority group of the application specified by **bundleName**. If **bundleName** is not specified, the priority group of the current application is queried. This API uses an asynchronous callback to return the result.|
| function queryAppUsagePriorityGroup(bundleName? : string): Promise<number>; | Queries the priority group of the application specified by **bundleName**. If **bundleName** is not specified, the priority group of the current application is queried. This API uses a promise to return the result.|
| function setBundleGroup(bundleName : string, newGroup: GroupType, callback: AsyncCallback>boolean>): void | Sets the group for the application specified by **bundleName**. This API uses an asynchronous callback to return the result.|
| function setBundleGroup(bundleName : string, newGroup : GroupType): Promise>boolean>; | Sets the group for the application specified by **bundleName**. This API uses a promise to return the result.|
| function registerGroupCallBack(callback: Callback>BundleActiveGroupCallbackInfo>, callback: AsyncCallback>boolean>): void | Registers a callback for application group changes. When an application group of the user changes, the change is returned to all applications that have registered the callback. This API uses an asynchronous callback to return the result.|
| function registerGroupCallBack(callback: Callback>BundleActiveGroupCallbackInfo>): Promise>boolean>; | Registers a callback for application group changes. When an application group of the user changes, the change is returned to all applications that have registered the callback. This API uses a promise to return the result.|
| function unRegisterGroupCallBack(callback: AsyncCallback>boolean>): void | Deregisters the callback for application group changes. This API uses an asynchronous callback to return the result.|
| function unRegisterGroupCallBack(): Promise>boolean>; | Deregisters the callback for application group changes. This API uses a promise to return the result.|
## How to Develop
...
...
@@ -44,7 +56,7 @@ import stats from '@ohos.bundleState';
```js
import stats from '@ohos.bundleState'
// Use a promise to return the result.
// Promise mode
stats.queryBundleActiveStates(0, 20000000000000).then( res => {
@@ -184,20 +196,20 @@ import stats from '@ohos.bundleState';
}
});
```
7. Check whether the application specified by **bundleName** is in the idle state. This requires no permission to be configured in the **config.json** file.
7. Check whether the application specified by **bundleName** is in the idle state. This requires no permission to be configured in the **config.json** file. A third-party application can only check the idle status of itself.
```js
import stats from '@ohos.bundleState'
// Use a promise to return the result.
// Promise mode
stats.isIdleState("com.ohos.camera").then( res => {
@@ -260,3 +272,168 @@ import stats from '@ohos.bundleState';
}
});
```
9. Query the number of notifications from all applications based on the specified start time and end time. This requires the **ohos.permission.BUNDLE_ACTIVE_INFO** permission to be configured in the **config.json** file.
```js
import stats from '@ohos.bundleState'
// Promise mode
stats.queryAppNotificationNumber(0, 20000000000000).then( res => {
console.log('BUNDLE_ACTIVE queryAppNotificationNumber callback result ' + JSON.stringify(res));
}
});
```
10. Query statistics about system events (hibernation, wakeup, unlocking, and screen locking) that occur between the specified start time and end time. This requires the **ohos.permission.BUNDLE_ACTIVE_INFO** permission to be configured in the **config.json** file.
```js
import stats from '@ohos.bundleState'
// Promise mode
stats.queryBundleActiveEventStates(0, 20000000000000).then( res => {
console.log('BUNDLE_ACTIVE queryBundleActiveEventStates callback result ' + JSON.stringify(res));
}
});
```
11. Query the priority group of the current application. This requires no permission to be configured in the **config.json** file. Query the priority group of a specified application. This requires the **ohos.permission.BUNDLE_ACTIVE_INFO** permission to be configured in the **config.json** file.
12. Register a callback for application group changes. When an application group of the user changes, the change is returned to all applications that have registered the callback.
@@ -12,22 +12,29 @@ Currently you can have access to statistics on the application usage, and notifi
3. Upon start of a new day
-**The application usage statistics can include the following**:
1. Events of all applications based on the specified start time and end time
1. Events of all applications based on the specified start time and end time
2. Application usage duration statistics based on the specified start time and end time
3. Events of the current application based on the specified start time and end time
4. Application usage duration statistics in the specified time frame at the specified interval (daily, weekly, monthly, or annually)
5. Priority group of the current invoker application
6. Whether a specific application is in the idle state
7. Number of FA usage records specified by **maxNum**, sorted by time (most recent first). If **maxNum** is not specified, the default value **1000** will be used.
8. Number of notifications from applications based on the specified start time and end time
9. Statistics about system events (hibernation, wakeup, unlocking, and screen locking) that occur between the specified start time and end time
9. Priority group of the invoker application or a specified application
2. Application usage duration statistics based on the specified start time and end time
-**The setters can be used to:**
3. Events of the current application based on the specified start time and end time
Set the group for the application specified by **bundleName**.
4. Application usage duration statistics in the specified time frame at the specified interval (daily, weekly, monthly, or annually)
-**The registration APIs can be used to:**
5. Priority group of the current invoker application
Register a callback for application group changes. When an application group of the user changes, the change is returned to all applications that have registered the callback.
6. Whether a specific application is in the idle state
-**The deregistration APIs can be used to:**
7. The number of FA usage records specified by **maxNum**, sorted by time (most recent first)
If **maxNum** is not specified, the default value **1000** will be used.
Deregister the callback for application group changes.
### Required Permissions
-The **queryBundleActiveStates**, **queryBundleStateInfos**, and **queryBundleStateInfoByInterval** APIs used for device usage statistics are system APIs. Before calling these APIs, you need to apply for the **ohos.permission.BUNDLE_ACTIVE_INFO** permission.
- This permission is not required for calling **queryCurrentBundleActiveStates**, **queryAppUsagePriorityGroup**, and **isIdleState**, which are third-party APIs.
-Before calling the following system APIs, you need to apply for the **ohos.permission.BUNDLE_ACTIVE_INFO** permission: **queryBundleActiveStates**, **queryBundleStateInfos**, **queryBundleStateInfoByInterval**, **queryBundleActiveEventStates**, **queryAppNotificationNumber**, **queryAppUsagePriorityGroup(bundleName?)**, **setBundleGroup**, **registerGroupCallBack**, and **unRegisterGroupCallBack**.
- This permission is not required for calling third-party APIs: **queryCurrentBundleActiveStates**, **queryAppUsagePriorityGroup()**, and **isIdleState**.
@@ -123,7 +123,7 @@ Add **Column**, **Text**, and **Button** components to the first page. A column
## Implementing Page Redirection
You can implement page redirection through the page router, which finds the target page based on the page URI. Import the **router** module and then perform the steps below:
You can implement page redirection through the page router, which finds the target page based on the page URL. Import the **router** module and then perform the steps below:
1. Implement redirection from the first page to the second page.
-**src > main > resources**: a collection of resource files used by your application/service, such as graphics, multimedia, character strings, and layout files.
-**src > main > config.json**: module configuration file. This file describes the global configuration information of the application/service, the device-specific configuration information, and the configuration information of the HAP file.
-**build-profile.json5**: current module information and build configuration options, including **buildOption target**.
-**build-profile.json5**: current module information and build configuration options, including **buildOption** and **targets**.
-**hvigorfile.js**: module-level compilation and build task script. You can customize related tasks and code implementation.
-**build-profile.json5**: application-level configuration information, including the signature and product configuration.
-**hvigorfile.js**: application-level compilation and build task script.
...
...
@@ -157,7 +157,7 @@
## Implementing Page Redirection
You can implement page redirection through the page router, which finds the target page based on the page URI. Import the **router** module and then perform the steps below:
You can implement page redirection through the page router, which finds the target page based on the page URL. Import the **router** module and then perform the steps below:
1. Implement redirection from the first page to the second page.
@@ -109,7 +109,7 @@ Open the index.visual file, right-click the existing template components on the
## Implementing Page Redirection
You can implement page redirection through the [page router](../ui/ui-js-building-ui-routes.md), which finds the target page based on the page URI. Import the **router** module and then perform the steps below:
You can implement page redirection through the [page router](../ui/ui-js-building-ui-routes.md), which finds the target page based on the page URL. Import the **router** module and then perform the steps below:
1. Implement redirection from the first page to the second page.
-**src > main > resources**: a collection of resource files used by your application/service, such as graphics, multimedia, character strings, and layout files.
-**src > main > config.json**: module configuration file. This file describes the global configuration information of the application/service, the device-specific configuration information, and the configuration information of the HAP file.
-**build-profile.json5**: current module information and build configuration options, including **buildOption target**.
-**build-profile.json5**: current module information and build configuration options, including **buildOption** and **targets**.
-**hvigorfile.js**: module-level compilation and build task script. You can customize related tasks and code implementation.
-**build-profile.json5**: application-level configuration information, including the signature and product configuration.
-**hvigorfile.js**: application-level compilation and build task script.
...
...
@@ -168,7 +168,7 @@
## Implementing Page Redirection
You can implement page redirection through the [page router](../ui/ui-js-building-ui-routes.md), which finds the target page based on the page URI. Import the **router** module and then perform the steps below:
You can implement page redirection through the [page router](../ui/ui-js-building-ui-routes.md), which finds the target page based on the page URL. Import the **router** module and then perform the steps below:
1. Implement redirection from the first page to the second page.
>  **NOTE**<br/>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.
>
> **NOTE**<br>
> 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
...
...
@@ -14,16 +14,16 @@ import bundleState from '@ohos.bundleState'
Checks whether the application specified by **bundleName** is in the idle state. This API uses an asynchronous callback to return the result.
Checks whether the application specified by **bundleName** is in the idle state. This API uses an asynchronous callback to return the result. A third-party application can only check the idle status of itself.
| bundleName | string | Yes| Bundle name of an application.|
| callback | AsyncCallback<boolean> | Yes| Callback used to return the result. Returns whether the application specified by **bundleName** is in the idle state if the value of **bundleName** is valid; returns **null** otherwise.|
| bundleName | string | Yes | Bundle name of an application. |
| callback | AsyncCallback<boolean> | Yes | Callback used to return the result. If the value of **bundleName** is valid, **null** will be returned.|
**Example**
...
...
@@ -41,21 +41,21 @@ Checks whether the application specified by **bundleName** is in the idle state.
Checks whether the application specified by **bundleName** is in the idle state. This API uses a promise to return the result.
Checks whether the application specified by **bundleName** is in the idle state. This API uses a promise to return the result. A third-party application can only check the idle status of itself.
| bundleName | string | Yes| Bundle name of an application.|
| Name | Type | Mandatory | Description |
| ---------- | ------ | ---- | -------------- |
| bundleName | string | Yes| Bundle name of an application.|
**Return value**
| Type| Description|
| -------- | -------- |
| Promise<boolean> | Promise used to return the result. Returns whether the application specified by **bundleName** is in the idle state if the value of **bundleName** is valid; returns **null** otherwise.|
**System API**: This is a system API and cannot be called by third-party applications.
**Parameters**
| Name| Type| Mandatory| Description|
| -------- | -------- | -------- | -------- |
| maxNum | number | No| Maximum number of returned records. The maximum and default value is **1000**. If this parameter is not specified, **1000** is used.|
| maxNum | number | No| Maximum number of returned records. The maximum and default value is **1000**. If this parameter is not specified, **1000** is used.|
**System API**: This is a system API and cannot be called by third-party applications.
**Parameters**
| Name| Type| Mandatory| Description|
| -------- | -------- | -------- | -------- |
| maxNum | number | No| Maximum number of returned records. The maximum and default value is **1000**. If this parameter is not specified, **1000** is used.|
| callback | AsyncCallback<Array<[BundleActiveModuleInfo](#bundleactivemoduleinfo9)>> | Yes| Callback used to return the result.|
| maxNum | number | No | Maximum number of returned records. The maximum and default value is **1000**. If this parameter is not specified, **1000** is used. |
| callback | AsyncCallback<Array<[BundleActiveModuleInfo](#bundleactivemoduleinfo9)>> | Yes| Callback used to return the result.|
Queries the priority group of the application specified by **bundleName**. If **bundleName** is not specified, the priority group of the current application is queried. This API uses a promise to return the result.
| bundleName | string | No | Bundle name of the target application. If this parameter is not specified, the priority group of the current application is queried.|
**Return value**
| Type | Description |
| --------------- | --------------------------- |
| Promise\<number> | Promise used to return the result.|
Queries the priority group of the application specified by **bundleName**. If **bundleName** is not specified, the priority group of the current application is queried. This API uses an asynchronous callback to return the result.
| bundleName | string | No | Bundle name of the target application. If this parameter is not specified, the priority group of the current application is queried.|
| callback | AsyncCallback\<number> | Yes | Callback used to return the result. |
Registers a callback for application group changes. When an application group of the user changes, **BundleActiveGroupCallbackInfo** is returned to all applications that have registered the callback. This API uses a promise to return the result.
Registers a callback for application group changes. When an application group of the user changes, **BundleActiveGroupCallbackInfo** is returned to all applications that have registered the callback. This API uses an asynchronous callback to return the result.
Queries statistics about system events (hibernation, wakeup, unlocking, and screen locking) that occur between the specified start time and end time. This API uses a promise to return the result.
Queries statistics about system events (hibernation, wakeup, unlocking, and screen locking) that occur between the specified start time and end time. This API uses an asynchronous callback to return the result.
Queries the number of notifications from all applications based on the specified start time and end time. This API uses a promise to return the result.
Queries the number of notifications from all applications based on the specified start time and end time. This API uses an asynchronous callback to return the result.
| abilityPrevAccessTime | number | Yes| Last time when the application was used.|
| abilityInFgTotalTime | number | Yes| Total time that the application runs in the foreground.|
| id | number | No| User ID.<br>This API is defined but not implemented in OpenHarmony 3.1 Release. It will be available for use in OpenHarmony 3.1 MR.|
| abilityPrevSeenTime | number | No| Last time when the application was visible in the foreground.<br>This API is defined but not implemented in OpenHarmony 3.1 Release. It will be available for use in OpenHarmony 3.1 MR.|
| abilitySeenTotalTime | number | No| Total time when the application is visible in the foreground.<br>This API is defined but not implemented in OpenHarmony 3.1 Release. It will be available for use in OpenHarmony 3.1 MR.|
| fgAbilityAccessTotalTime | number | No| Total time that the application accesses the foreground.<br>This API is defined but not implemented in OpenHarmony 3.1 Release. It will be available for use in OpenHarmony 3.1 MR.|
| fgAbilityPrevAccessTime | number | No| Last time when the application accessed the foreground.<br>This API is defined but not implemented in OpenHarmony 3.1 Release. It will be available for use in OpenHarmony 3.1 MR.|
| infosBeginTime | number | No| Time logged in the first application usage record in the **BundleActiveInfo** object.<br>This API is defined but not implemented in OpenHarmony 3.1 Release. It will be available for use in OpenHarmony 3.1 MR.|
| infosEndTime | number | No| Time logged in the last application usage record in the **BundleActiveInfo** object.<br>This API is defined but not implemented in OpenHarmony 3.1 Release. It will be available for use in OpenHarmony 3.1 MR.|
| bundleName | string | Yes | Bundle name of the application. |
| abilityPrevAccessTime | number | Yes | Last time when the application was used. |
| abilityInFgTotalTime | number | Yes | Total time that the application runs in the foreground. |
| id | number | No | User ID.<br>This API is defined but not implemented in OpenHarmony 3.1 Release. It will be available for use in OpenHarmony 3.1 MR.|
| abilityPrevSeenTime | number | No | Last time when the application was visible in the foreground.<br>This API is defined but not implemented in OpenHarmony 3.1 Release. It will be available for use in OpenHarmony 3.1 MR.|
| abilitySeenTotalTime | number | No | Total time that the application is visible in the foreground.<br>This API is defined but not implemented in OpenHarmony 3.1 Release. It will be available for use in OpenHarmony 3.1 MR.|
| fgAbilityAccessTotalTime | number | No| Total time that the application accesses the foreground.<br>This API is defined but not implemented in OpenHarmony 3.1 Release. It will be available for use in OpenHarmony 3.1 MR.|
| fgAbilityPrevAccessTime | number | No | Last time when the application accessed the foreground.<br>This API is defined but not implemented in OpenHarmony 3.1 Release. It will be available for use in OpenHarmony 3.1 MR.|
| infosBeginTime | number | No | Time logged in the first application usage record in the **BundleActiveInfo** object.<br>This API is defined but not implemented in OpenHarmony 3.1 Release. It will be available for use in OpenHarmony 3.1 MR.|
| infosEndTime | number | No | Time logged in the last application usage record in the **BundleActiveInfo** object.<br>This API is defined but not implemented in OpenHarmony 3.1 Release. It will be available for use in OpenHarmony 3.1 MR.|
### merge
...
...
@@ -562,9 +1035,9 @@ This API is defined but not implemented in OpenHarmony 3.1 Release. It will be a
**Parameters**
| Name| Type| Mandatory| Description|
| -------- | -------- | -------- | -------- |
| toMerge | [BundleStateInfo](#bundlestateinfo) | Yes| Application usage information to merge.|
| stateType | number | Yes| Application event type.|
| stateOccurredTime | number | Yes| Timestamp when the application event occurs.|
| appUsagePriorityGroup | number | No| Usage priority group of the application.<br>This API is defined but not implemented in OpenHarmony 3.1 Release. It will be available for use in OpenHarmony 3.1 MR.|
| indexOfLink | string | No| Shortcut ID.<br>This API is defined but not implemented in OpenHarmony 3.1 Release. It will be available for use in OpenHarmony 3.1 MR.|
| nameOfClass | string | No| Class name.<br>This API is defined but not implemented in OpenHarmony 3.1 Release. It will be available for use in OpenHarmony 3.1 MR.|
| stateOccurredTime | number | Yes | Timestamp when the application event occurs. |
| appUsagePriorityGroup | number | No| Usage priority group of the application.<br>This API is defined but not implemented in OpenHarmony 3.1 Release. It will be available for use in OpenHarmony 3.1 MR.|
| indexOfLink | string | No | Shortcut ID.<br>This API is defined but not implemented in OpenHarmony 3.1 Release. It will be available for use in OpenHarmony 3.1 MR.|
| nameOfClass | string | No | Class name.<br>This API is defined but not implemented in OpenHarmony 3.1 Release. It will be available for use in OpenHarmony 3.1 MR.|
## BundleActiveInfoResponse
...
...
@@ -587,9 +1060,23 @@ Provides the usage duration information of applications.
| BY_OPTIMIZED | 0 | The system obtains the application usage duration statistics in the specified time frame at the interval the system deems appropriate.|
| BY_DAILY | 1 | The system obtains the application usage duration statistics in the specified time frame on a daily basis.|
| BY_WEEKLY | 2 | The system obtains the application usage duration statistics in the specified time frame on a weekly basis.|
| BY_MONTHLY | 3 | The system obtains the application usage duration statistics in the specified time frame on a monthly basis.|
| BY_ANNUALLY | 4 | The system obtains the application usage duration statistics in the specified time frame on an annual basis.|
| BY_OPTIMIZED | 0 | The system obtains the application usage duration statistics in the specified time frame at the interval the system deems appropriate.|
| BY_DAILY | 1 | The system obtains the application usage duration statistics in the specified time frame on a daily basis. |
| BY_WEEKLY | 2 | The system obtains the application usage duration statistics in the specified time frame on a weekly basis. |
| BY_MONTHLY | 3 | The system obtains the application usage duration statistics in the specified time frame on a monthly basis. |
| BY_ANNUALLY | 4 | The system obtains the application usage duration statistics in the specified time frame on an annual basis. |
>  **NOTE**<br>The initial APIs of this module are supported since API version 6. Newly added APIs will be marked with a superscript to indicate their earliest API version.
> **NOTE**<br>The initial APIs of this module are supported since API version 6. Newly added APIs will be marked with a superscript to indicate their earliest API version.
>
...
...
@@ -48,9 +48,9 @@ Creates a **PasteData** object for plain text.
>  **NOTE**<br>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.
>
> **NOTE**<br>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.
@@ -258,26 +259,26 @@ Checks whether to allow the application to change the wallpaper for the current
| Name | Type | Mandatory | Description |
| -------- | -------- | -------- | -------- |
| callback | AsyncCallback<boolean> | Yes | Callback used to return the queried result. Returns **true** if it is allowed; returns **false** otherwise. |
| callback | AsyncCallback<boolean> | Yes | Returns **true** if the application is allowed to change the wallpaper for the current user; returns **false** otherwise. |
**Example**
```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));
});
```
```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));
});
```
## wallpaper.isChangePermitted
isChangePermitted(): Promise<boolean>
Checks whether to allow the application to change the wallpaper for the current user.
Checks whether to allow the application to change the wallpaper for the current user. This API uses a promise to return the result.
@@ -285,24 +286,24 @@ Checks whether to allow the application to change the wallpaper for the current
| Type | Description |
| -------- | -------- |
| Promise<boolean> | Promise used to return whether to allow the application to change the wallpaper for the current user. Returns **true** if it is allowed; returns **false** otherwise. |
| Promise<boolean> | Returns **true** if the application is allowed to change the wallpaper for the current user; returns **false** otherwise. |
**Example**
```js
wallpaper.isChangePermitted().then((data)=>{
console.log(`success to isChangePermitted: `+JSON.stringify(data));
}).catch((error)=>{
console.error(`failed to isChangePermitted because: `+JSON.stringify(error));
});
```
```js
wallpaper.isChangePermitted().then((data)=>{
console.log(`success to isChangePermitted: `+JSON.stringify(data));
}).catch((error)=>{
console.error(`failed to isChangePermitted because: `+JSON.stringify(error));
@@ -310,26 +311,26 @@ Checks whether the user is allowed to set wallpapers.
| Name | Type | Mandatory | Description |
| -------- | -------- | -------- | -------- |
| callback | AsyncCallback<boolean> | Yes | Callback used to return whether the user is allowed to set wallpapers. Returns **true** if it is allowed; returns **false** otherwise. |
| callback | AsyncCallback<boolean> | Yes | Returns **true** if the user is allowed to set wallpapers; returns **false** otherwise. |
**Example**
```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));
});
```
```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));
});
```
## wallpaper.isOperationAllowed
isOperationAllowed(): Promise<boolean>
Checks whether the user is allowed to set wallpapers.
Checks whether the user is allowed to set wallpapers. This API uses a promise to return the result.
@@ -337,26 +338,26 @@ Checks whether the user is allowed to set wallpapers.
| Type | Description |
| -------- | -------- |
| Promise<boolean> | Promise used to return whether the user is allowed to set wallpapers. Returns **true** if it is allowed; returns **false** otherwise. |
| Promise<boolean> | Returns **true** if the user is allowed to set wallpapers; returns **false** otherwise. |
**Example**
```js
wallpaper.isOperationAllowed().then((data)=>{
console.log(`success to isOperationAllowed: `+JSON.stringify(data));
}).catch((error)=>{
console.error(`failed to isOperationAllowed because: `+JSON.stringify(error));
});
```
```js
wallpaper.isOperationAllowed().then((data)=>{
console.log(`success to isOperationAllowed: `+JSON.stringify(data));
}).catch((error)=>{
console.error(`failed to isOperationAllowed because: `+JSON.stringify(error));
| callback | AsyncCallback<void> | Yes | Callback used to return the result. If the operation is successful, the result of removal is returned. Otherwise, error information is returned. |
| callback | AsyncCallback<void> | Yes | Callback used to return the result. If the operation is successful, the result is returned. Otherwise, error information is returned. |
@@ -400,26 +401,26 @@ Removes a wallpaper of the specified type and restores the default one.
| Type | Description |
| -------- | -------- |
| Promise<void> | Promise used to return the result. If the operation is successful, the result of removal is returned. Otherwise, error information is returned. |
| Promise<void> | Promise used to return the result. If the operation is successful, the result is returned. Otherwise, error information is returned. |
| callback | AsyncCallback<void> | Yes | Callback used to return the result. If the operation is successful, the setting result is returned. Otherwise, error information is returned. |
...
...
@@ -435,45 +436,45 @@ Sets a specified source as the wallpaper of a specified type.
| callback | AsyncCallback<void> | Yes| Callback used to return the result. If the operation is successful, the result is returned. Otherwise, error information is returned.|
**Example**
```js
wallpaper.getPixelMap(wallpaper.WallpaperType.WALLPAPER_SYSTEM, function (err, data) {
| Promise<void> | Promise used to return the result. If the operation is successful, the result is returned. Otherwise, error information is returned.|
@@ -596,16 +659,16 @@ Subscribes to the wallpaper color change event.
| 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. |
| 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. |
**Example**
```js
letlistener=(colors,wallpaperType)=>{
console.log(`wallpaper color changed.`);
};
wallpaper.on('colorChange',listener);
```
```js
let listener = (colors, wallpaperType) => {
console.log(`wallpaper color changed.`);
};
wallpaper.on('colorChange', listener);
```
## wallpaper.off('colorChange')
...
...
@@ -621,15 +684,15 @@ Unsubscribes from the wallpaper color change event.
| Name | Type | Mandatory | Description |
| -------- | -------- | -------- | -------- |
| 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 specified, all callbacks corresponding to the wallpaper color change event are invoked.<br/>- colors<br/> Main color information of the wallpaper. For details, see [RgbaColor](#rgbacolor).<br/>- wallpaperType<br/> Wallpaper type. |
| callback | function | No | Callback for the wallpaper color change event. If this parameter is not specified, all callbacks corresponding to the wallpaper color change event are invoked.<br>- colors<br> Main color information of the wallpaper. For details, see [RgbaColor](#rgbacolor).<br>- wallpaperType<br> Wallpaper type. |
**Example**
```js
letlistener=(colors,wallpaperType)=>{
console.log(`wallpaper color changed.`);
};
wallpaper.on('colorChange',listener);
```js
let listener = (colors, wallpaperType) => {
console.log(`wallpaper color changed.`);
};
wallpaper.on('colorChange', listener);
// Unsubscribe from the listener.
wallpaper.off('colorChange', listener);
//Unsubscribe from all subscriptions of the colorChange type.