1# @ohos.bundleState (Device Usage Statistics) 2 3This module provides APIs for collecting statistics on device usage. 4 5> **NOTE** 6> 7> The APIs of this module are deprecated since API version 9. The substitute APIs are open only to system applications. 8> 9> 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. 10 11 12## Modules to Import 13 14```js 15import bundleState from '@ohos.bundleState' 16``` 17 18## bundleState.isIdleState<sup>(deprecated)</sup> 19 20isIdleState(bundleName: string, callback: AsyncCallback<boolean>): void 21> This API is supported since API version 7 and deprecated since API version 9. Its substitute is available only to system applications. 22 23Checks whether the application specified by **bundleName** is in the idle state. A third-party application can only check the idle state of itself. A system application can check the idle state of other applications only when it is granted with the ohos.permission.BUNDLE_ACTIVE_INFO permission. This API uses an asynchronous callback to return the result. 24 25**System capability**: SystemCapability.ResourceSchedule.UsageStatistics.AppGroup 26 27**Parameters** 28 29| Name | Type | Mandatory | Description | 30| ---------- | ---------------------------- | ---- | ---------------------------------------- | 31| bundleName | string | Yes | Bundle name of an application. | 32| callback | AsyncCallback<boolean> | Yes | Callback used to return the result. If the specified **bundleName** is valid, the idle state of the application is returned; otherwise, **null** is returned.| 33 34**Example** 35 36```ts 37import { BusinessError } from '@ohos.base'; 38// When a third-party application uses the sample code, change bundleName to its own bundle name. 39bundleState.isIdleState("com.ohos.camera", (err: BusinessError, res: boolean) => { 40 if (err) { 41 console.error('BUNDLE_ACTIVE isIdleState callback failed, because: ' + err.code); 42 } else { 43 console.log('BUNDLE_ACTIVE isIdleState callback succeeded, result: ' + JSON.stringify(res)); 44 } 45}); 46``` 47 48## bundleState.isIdleState<sup>(deprecated)</sup> 49 50isIdleState(bundleName: string): Promise<boolean> 51> This API is supported since API version 7 and deprecated since API version 9. Its substitute is available only to system applications. 52 53Checks whether the application specified by **bundleName** is in the idle state. A third-party application can only check the idle state of itself. A system application can check the idle state of other applications only when it is granted with the ohos.permission.BUNDLE_ACTIVE_INFO permission. This API uses a promise to return the result. 54 55**System capability**: SystemCapability.ResourceSchedule.UsageStatistics.AppGroup 56 57**Parameters** 58 59| Name | Type | Mandatory | Description | 60| ---------- | ------ | ---- | -------------- | 61| bundleName | string | Yes | Bundle name of an application.| 62 63**Return value** 64 65| Type | Description | 66| ---------------------- | ---------------------------------------- | 67| Promise<boolean> | Promise used to return the result. If the specified **bundleName** is valid, the idle state of the application is returned; otherwise, **null** is returned.| 68 69**Example** 70 71```ts 72import { BusinessError } from '@ohos.base'; 73// When a third-party application uses the sample code, change bundleName to its own bundle name. 74bundleState.isIdleState("com.ohos.camera").then((res: boolean) => { 75 console.log('BUNDLE_ACTIVE isIdleState promise succeeded, result: ' + JSON.stringify(res)); 76}).catch((err: BusinessError) => { 77 console.error('BUNDLE_ACTIVE isIdleState promise failed, because: ' + err.code); 78}); 79``` 80