harmony 鸿蒙@ohos.bundleState (Device Usage Statistics)
@ohos.bundleState (Device Usage Statistics)
This module provides APIs for collecting statistics on device usage.
NOTE
The APIs of this module are deprecated since API version 9. The substitute APIs are open only to system applications.
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
import bundleState from '@ohos.bundleState'
bundleState.isIdleState
isIdleState(bundleName: string, callback: AsyncCallback<boolean>): void
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 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.
System capability: SystemCapability.ResourceSchedule.UsageStatistics.AppGroup
Parameters
Name | Type | Mandatory | Description |
---|---|---|---|
bundleName | string | Yes | Bundle name of an application. |
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. |
Example
import { BusinessError } from '@ohos.base';
// When a third-party application uses the sample code, change bundleName to its own bundle name.
bundleState.isIdleState("com.ohos.camera", (err: BusinessError, res: boolean) => {
if (err) {
console.error('BUNDLE_ACTIVE isIdleState callback failed, because: ' + err.code);
} else {
console.log('BUNDLE_ACTIVE isIdleState callback succeeded, result: ' + JSON.stringify(res));
}
});
bundleState.isIdleState
isIdleState(bundleName: string): Promise<boolean>
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 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.
System capability: SystemCapability.ResourceSchedule.UsageStatistics.AppGroup
Parameters
Name | Type | Mandatory | Description |
---|---|---|---|
bundleName | string | Yes | Bundle name of an application. |
Return value
Type | Description |
---|---|
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. |
Example
import { BusinessError } from '@ohos.base';
// When a third-party application uses the sample code, change bundleName to its own bundle name.
bundleState.isIdleState("com.ohos.camera").then((res: boolean) => {
console.log('BUNDLE_ACTIVE isIdleState promise succeeded, result: ' + JSON.stringify(res));
}).catch((err: BusinessError) => {
console.error('BUNDLE_ACTIVE isIdleState promise failed, because: ' + err.code);
});
你可能感兴趣的鸿蒙文章
harmony 鸿蒙Background Tasks Kit
harmony 鸿蒙BackgroundProcessManager
harmony 鸿蒙TransientTask_DelaySuspendInfo
harmony 鸿蒙background_process_manager.h
harmony 鸿蒙DeviceUsageStatistics Error Codes
harmony 鸿蒙backgroundTaskManager Error Codes
harmony 鸿蒙reminderAgentManager Error Codes
harmony 鸿蒙workScheduler Error Codes
harmony 鸿蒙@ohos.WorkSchedulerExtensionAbility (Deferred Task Scheduling Callbacks)
- 所属分类: 后端技术
- 本文标签:
热门推荐
-
2、 - 优质文章
-
3、 gate.io
-
8、 golang
-
9、 openharmony
-
10、 Vue中input框自动聚焦