openharmony 鸿蒙 js-apis-resourceschedule-deviceUsageStatistics-sys

2025-06-12 浏览 (1)

@ohos.resourceschedule.usageStatistics (Device Usage Statistics) (System API)

The usageStatistics module provides APIs for collecting statistics on device usage. For example, you can use the APIs to query whether an application is commonly used and an application's priority group, usage duration, system events (hibernation, wakeup, unlocking, and screen locking), application events (foreground, background, and start and end of continuous tasks), and the number of notifications.

NOTE

The initial APIs of this module are supported since API version 9. Newly added APIs will be marked with a superscript to indicate their earliest API version.

The APIs provided by this module are system APIs.

Modules to Import

import { usageStatistics } from '@kit.BackgroundTasksKit'

usageStatistics.isIdleState

isIdleState(bundleName: string, callback: AsyncCallback<boolean>): void

Checks whether an application is commonly used (with the value of GroupType being less than or equal to 30). This API uses an asynchronous callback to return the result.

Required permissions: ohos.permission.BUNDLE_ACTIVE_INFO

System capability: SystemCapability.ResourceSchedule.UsageStatistics.AppGroup

Parameters

NameTypeMandatoryDescription
bundleNamestringYesBundle name of the application.
callbackAsyncCallback<boolean>YesCallback used to return the result.
If the application is commonly used, true is returned. If the application is not commonly used or bundleName is invalid, false is returned.

Error codes

For details about the error codes, see Universal Error Codes and DeviceUsageStatistics Error Codes.

IDError Message
201Permission denied.
202Not System App.
401Parameter error.
801Capability not supported.
10000001Memory operation failed.
10000002Parcel operation failed.
10000003System service operation failed.
10000004IPC failed.
10000006Failed to get the application information.

Example

import { BusinessError } from '@kit.BasicServicesKit';

usageStatistics.isIdleState("com.ohos.camera", (err: BusinessError, res: boolean) => {
  if (err) {
    console.log('BUNDLE_ACTIVE isIdleState callback failed. code is: ' + err.code + ',message is: ' + err.message);
  } else {
    console.log('BUNDLE_ACTIVE isIdleState callback succeeded, result: ' + JSON.stringify(res));
  }
});

usageStatistics.isIdleState

isIdleState(bundleName: string): Promise<boolean>

Checks whether an application is commonly used (with the value of GroupType being less than or equal to 30). This API uses a promise to return the result.

Required permissions: ohos.permission.BUNDLE_ACTIVE_INFO

System capability: SystemCapability.ResourceSchedule.UsageStatistics.AppGroup

Parameters

NameTypeMandatoryDescription
bundleNamestringYesBundle name of the application.

Return value

TypeDescription
Promise<boolean>Promise used to return the result.
If the application is commonly used, true is returned. If the application is not commonly used or bundleName is invalid, false is returned.

Error codes

For details about the error codes, see Universal Error Codes and DeviceUsageStatistics Error Codes.

IDError Message
201Permission denied.
202Not System App.
401Parameter error.
801Capability not supported.
10000001Memory operation failed.
10000002Parcel operation failed.
10000003System service operation failed.
10000004IPC failed.
10000006Failed to get the application information.

Example

import { BusinessError } from '@kit.BasicServicesKit';

usageStatistics.isIdleState("com.ohos.camera").then((res: boolean) => {
  console.log('BUNDLE_ACTIVE isIdleState promise succeeded, result: ' + JSON.stringify(res));
}).catch((err: BusinessError) => {
  console.log('BUNDLE_ACTIVE isIdleState promise failed. code is: ' + err.code + ',message is: ' + err.message);
});

usageStatistics.isIdleStateSync10+

isIdleStateSync(bundleName: string): boolean

Checks whether an application is commonly used (with the value of GroupType being less than or equal to 30). This API returns the result synchronously.

Required permissions: ohos.permission.BUNDLE_ACTIVE_INFO

System capability: SystemCapability.ResourceSchedule.UsageStatistics.AppGroup

Parameters

NameTypeMandatoryDescription
bundleNamestringYesBundle name of the application.

Return value

TypeDescription
booleanIf the application is commonly used, true is returned. If the application is not commonly used or bundleName is invalid, false is returned.

Error codes

For details about the error codes, see Universal Error Codes and DeviceUsageStatistics Error Codes.

IDError Message
201Permission denied.
202Not System App.
401Parameter error.
801Capability not supported.
10000001Memory operation failed.
10000002Parcel operation failed.
10000003System service operation failed.
10000004IPC failed.
10000006Failed to get the application information.

Example

let isIdleState: boolean = usageStatistics.isIdleStateSync("com.ohos.camera");

usageStatistics.queryAppGroup

queryAppGroup(): Promise<number>

Queries the priority group of this application. This API uses a promise to return the result.

Required permissions: ohos.permission.BUNDLE_ACTIVE_INFO

System capability: SystemCapability.ResourceSchedule.UsageStatistics.AppGroup

Return value

TypeDescription
Promise<number>Promise used to return the priority group. A smaller value indicates a higher priority.

Error codes

For details about the error codes, see Universal Error Codes and DeviceUsageStatistics Error Codes.

IDError Message
201Permission denied.
202Not System App.
401Parameter error.
801Capability not supported.
10000001Memory operation failed.
10000002Parcel operation failed.
10000003System service operation failed.
10000004IPC failed.
10000005Application is not installed.
10000006Failed to get the application information.
10100002Failed to get the application group information.

Example

import { BusinessError } from '@kit.BasicServicesKit';

usageStatistics.queryAppGroup().then((res: number) => {
  console.log('BUNDLE_ACTIVE queryAppGroup promise succeeded. result: ' + JSON.stringify(res));
}).catch((err: BusinessError) => {
  console.log('BUNDLE_ACTIVE queryAppGroup promise failed. code is: ' + err.code + ',message is: ' + err.message);
});

usageStatistics.queryAppGroup

queryAppGroup(callback: AsyncCallback<number>): void

Queries the priority group of this application. This API uses an asynchronous callback to return the result.

Required permissions: ohos.permission.BUNDLE_ACTIVE_INFO

System capability: SystemCapability.ResourceSchedule.UsageStatistics.AppGroup

Parameters

NameTypeMandatoryDescription
callbackAsyncCallback<number>YesCallback used to return the priority group. A smaller value indicates a higher priority.

Error codes

For details about the error codes, see Universal Error Codes and DeviceUsageStatistics Error Codes.

IDError Message
201Permission denied.
202Not System App.
401Parameter error.
801Capability not supported.
10000001Memory operation failed.
10000002Parcel operation failed.
10000003System service operation failed.
10000004IPC failed.
10000005Application is not installed.
10000006Failed to get the application information.
10100002Failed to get the application group information.

Example

import { BusinessError } from '@kit.BasicServicesKit';

usageStatistics.queryAppGroup((err: BusinessError, res: number) => {
  if(err) {
    console.log('BUNDLE_ACTIVE queryAppGroup callback failed. code is: ' + err.code + ',message is: ' + err.message);
  } else {
    console.log('BUNDLE_ACTIVE queryAppGroup callback succeeded. result: ' + JSON.stringify(res));
  }
});

usageStatistics.queryAppGroupSync10+

queryAppGroupSync(): number

Queries the priority group of this application. This API returns the result synchronously.

Required permissions: ohos.permission.BUNDLE_ACTIVE_INFO

System capability: SystemCapability.ResourceSchedule.UsageStatistics.AppGroup

Return value

TypeDescription
numberPriority group. A smaller value indicates a higher priority.

Error codes

For details about the error codes, see Universal Error Codes and DeviceUsageStatistics Error Codes.

IDError Message
201Permission denied.
202Not System App.
401Parameter error.
801Capability not supported.
10000001Memory operation failed.
10000002Parcel operation failed.
10000003System service operation failed.
10000004IPC failed.
10000005Application is not installed.
10000006Failed to get the application information.
10100002Failed to get the application group information.

Example

let priorityGroup: number = usageStatistics.queryAppGroupSync();

usageStatistics.queryAppGroup

queryAppGroup(bundleName : string): Promise<number>

Queries the priority group of the application specified by bundleName. This API uses a promise to return the result.

Required permissions: ohos.permission.BUNDLE_ACTIVE_INFO

System capability: SystemCapability.ResourceSchedule.UsageStatistics.AppGroup

Parameters

NameTypeMandatoryDescription
bundleNamestringYesBundle name of the application.

Return value

TypeDescription
Promise<number>Promise used to return the priority group. A smaller value indicates a higher priority.

Error codes

For details about the error codes, see Universal Error Codes and DeviceUsageStatistics Error Codes.

IDError Message
201Permission denied.
202Not System App.
401Parameter error.
801Capability not supported.
10000001Memory operation failed.
10000002Parcel operation failed.
10000003System service operation failed.
10000004IPC failed.
10000005Application is not installed.
10000006Failed to get the application information.
10100002Failed to get the application group information.

Example

// Promise mode when bundleName is specified
import { BusinessError } from '@kit.BasicServicesKit';

let bundleName: string = "com.ohos.camera";
usageStatistics.queryAppGroup(bundleName).then((res: number) => {
  console.log('BUNDLE_ACTIVE queryAppGroup promise succeeded. result: ' + JSON.stringify(res));
}).catch((err: BusinessError) => {
  console.log('BUNDLE_ACTIVE queryAppGroup promise failed. code is: ' + err.code + ',message is: ' + err.message);
});

usageStatistics.queryAppGroup

queryAppGroup(bundleName : string, callback: AsyncCallback<number>): void

Queries the priority group of the application specified by bundleName. This API uses an asynchronous callback to return the result.

Required permissions: ohos.permission.BUNDLE_ACTIVE_INFO

System capability: SystemCapability.ResourceSchedule.UsageStatistics.AppGroup

Parameters

NameTypeMandatoryDescription
bundleNamestringYesBundle name of the application.
callbackAsyncCallback<number>YesCallback used to return the priority group. A smaller value indicates a higher priority.

Error codes

For details about the error codes, see Universal Error Codes and DeviceUsageStatistics Error Codes.

IDError Message
201Permission denied.
202Not System App.
401Parameter error.
801Capability not supported.
10000001Memory operation failed.
10000002Parcel operation failed.
10000003System service operation failed.
10000004IPC failed.
10000005Application is not installed.
10000006Failed to get the application information.
10100002Failed to get the application group information.

Example

import { BusinessError } from '@kit.BasicServicesKit';

let bundleName: string = "com.ohos.camera";
usageStatistics.queryAppGroup(bundleName, (err: BusinessError, res: number) => {
  if(err) {
    console.log('BUNDLE_ACTIVE queryAppGroup callback failed. code is: ' + err.code + ',message is: ' + err.message);
  } else {
    console.log('BUNDLE_ACTIVE queryAppGroup callback succeeded. result: ' + JSON.stringify(res));
  }
});

usageStatistics.queryAppGroupSync10+

queryAppGroupSync(bundleName: string): number

Queries the priority group of the application specified by bundleName. This API returns the result synchronously.

Required permissions: ohos.permission.BUNDLE_ACTIVE_INFO

System capability: SystemCapability.ResourceSchedule.UsageStatistics.AppGroup

Parameters

NameTypeMandatoryDescription
bundleNamestringYesBundle name of the application.

Return value

TypeDescription
numberPriority group. A smaller value indicates a higher priority.

Error codes

For details about the error codes, see Universal Error Codes and DeviceUsageStatistics Error Codes.

IDError Message
201Permission denied.
202Not System App.
401Parameter error.
801Capability not supported.
10000001Memory operation failed.
10000002Parcel operation failed.
10000003System service operation failed.
10000004IPC failed.
10000005Application is not installed.
10000006Failed to get the application information.
10100002Failed to get the application group information.

Example

let priorityGroup: number = usageStatistics.queryAppGroupSync("com.ohos.camera");

usageStatistics.setAppGroup

setAppGroup(bundleName: string, newGroup: GroupType): Promise<void>

Sets a new group for the application specified by bundleName. This API uses a promise to return the result. It can be called only by the current application.

Required permissions: ohos.permission.BUNDLE_ACTIVE_INFO

System capability: SystemCapability.ResourceSchedule.UsageStatistics.AppGroup

Parameters

NameTypeMandatoryDescription
bundleNamestringYesBundle name of the application.
newGroupGroupTypeYesType of the new group.

Return value

TypeDescription
Promise<void>Promise that returns no value.

Error codes

For details about the error codes, see Universal Error Codes and DeviceUsageStatistics Error Codes.

IDError Message
201Permission denied.
202Not System App.
401Parameter error.
801Capability not supported.
10000001Memory operation failed.
10000002Parcel operation failed.
10000003System service operation failed.
10000004IPC failed.
10000006Failed to get the application information.
10100001Repeated operation on the application group.

Example

import { BusinessError } from '@kit.BasicServicesKit';

let bundleName: string = "com.example.deviceUsageStatistics";
let newGroup = usageStatistics.GroupType.DAILY_GROUP;

usageStatistics.setAppGroup(bundleName, newGroup).then( () => {
  console.log('BUNDLE_ACTIVE setAppGroup promise succeeded.');
}).catch((err: BusinessError) => {
  console.log('BUNDLE_ACTIVE setAppGroup promise failed. code is: ' + err.code + ',message is: ' + err.message);
});

usageStatistics.setAppGroup

setAppGroup(bundleName: string, newGroup: GroupType, callback: AsyncCallback<void>): void

Sets a new group for the application specified by bundleName. This API uses an asynchronous callback to return the result. It can be called only by the current application.

Required permissions: ohos.permission.BUNDLE_ACTIVE_INFO

System capability: SystemCapability.ResourceSchedule.UsageStatistics.AppGroup

Parameters

NameTypeMandatoryDescription
bundleNamestringYesBundle name of the application.
newGroupGroupTypeYesType of the new group.
callbackAsyncCallback<void>YesCallback used to return the result.

Error codes

For details about the error codes, see Universal Error Codes and DeviceUsageStatistics Error Codes.

IDError Message
201Permission denied.
202Not System App.
401Parameter error.
801Capability not supported.
10000001Memory operation failed.
10000002Parcel operation failed.
10000003System service operation failed.
10000004IPC failed.
10000006Failed to get the application information.
10100001Repeated operation on the application group.

Example

import { BusinessError } from '@kit.BasicServicesKit';

let bundleName: string = "com.example.deviceUsageStatistics";
let newGroup = usageStatistics.GroupType.DAILY_GROUP;

usageStatistics.setAppGroup(bundleName, newGroup, (err: BusinessError) => {
  if(err) {
    console.log('BUNDLE_ACTIVE setAppGroup callback failed. code is: ' + err.code + ',message is: ' + err.message);
  } else {
    console.log('BUNDLE_ACTIVE setAppGroup callback succeeded.');
  }
});

usageStatistics.queryBundleStatsInfos

queryBundleStatsInfos(begin: number, end: number, callback: AsyncCallback<BundleStatsMap>): void

Queries the application usage duration statistics based on the specified start time and end time, with the minimum granularity of a day. This API uses an asynchronous callback to return the result.

Required permissions: ohos.permission.BUNDLE_ACTIVE_INFO

System capability: SystemCapability.ResourceSchedule.UsageStatistics.App

Parameters

NameTypeMandatoryDescription
beginnumberYesStart time, in milliseconds.
endnumberYesEnd time, in milliseconds.
callbackAsyncCallback<BundleStatsMap>YesCallback used to return the application usage duration statistics.

Error codes

For details about the error codes, see Universal Error Codes and DeviceUsageStatistics Error Codes.

IDError Message
201Permission denied.
202Not System App.
401Parameter error.
801Capability not supported.
10000001Memory operation failed.
10000002Parcel operation failed.
10000003System service operation failed.
10000004IPC failed.
10000006Failed to get the application information.
10000007Failed to get the system time.

Example

import { BusinessError } from '@kit.BasicServicesKit';

usageStatistics.queryBundleStatsInfos(0, 20000000000000, (err: BusinessError, res:usageStatistics.BundleStatsMap) => {
  if (err) {
    console.log('BUNDLE_ACTIVE queryBundleStatsInfos callback failed. code is: ' + err.code + ',message is: ' + err.message);
  } else {
    console.log('BUNDLE_ACTIVE queryBundleStatsInfos callback success.');
    console.log('BUNDLE_ACTIVE queryBundleStatsInfos callback result ' + JSON.stringify(res));
  }
});

usageStatistics.queryBundleStatsInfos

queryBundleStatsInfos(begin: number, end: number): Promise<BundleStatsMap>

Queries the application usage duration statistics based on the specified start time and end time, with the minimum granularity of a day. This API uses a promise to return the result.

Required permissions: ohos.permission.BUNDLE_ACTIVE_INFO

System capability: SystemCapability.ResourceSchedule.UsageStatistics.App

Parameters

NameTypeMandatoryDescription
beginnumberYesStart time, in milliseconds.
endnumberYesEnd time, in milliseconds.

Return value

TypeDescription
Promise<BundleStatsMap>Promise used to return the application usage duration statistics.

Error codes

For details about the error codes, see Universal Error Codes and DeviceUsageStatistics Error Codes.

IDError Message
201Permission denied.
202Not System App.
401Parameter error.
801Capability not supported.
10000001Memory operation failed.
10000002Parcel operation failed.
10000003System service operation failed.
10000004IPC failed.
10000006Failed to get the application information.
10000007Failed to get the system time.

Example

import { BusinessError } from '@kit.BasicServicesKit';

usageStatistics.queryBundleStatsInfos(0, 20000000000000).then((res:usageStatistics.BundleStatsMap) => {
  console.log('BUNDLE_ACTIVE queryBundleStatsInfos promise success.');
  console.log('BUNDLE_ACTIVE queryBundleStatsInfos promise result ' + JSON.stringify(res));
}).catch((err: BusinessError) => {
  console.log('BUNDLE_ACTIVE queryBundleStatsInfos promise failed. code is: ' + err.code + ',message is: ' + err.message);
});

usageStatistics.queryAppStatsInfos15+

queryAppStatsInfos(begin: number, end: number): Promise<AppStatsMap>

Queries the application usage duration statistics based on the specified start time and end time, with the minimum granularity of a day. This API uses a promise to return the result.

Required permissions: ohos.permission.BUNDLE_ACTIVE_INFO

System capability: SystemCapability.ResourceSchedule.UsageStatistics.App

Parameters

NameTypeMandatoryDescription
beginnumberYesStart time, in milliseconds.
endnumberYesEnd time, in milliseconds.

Return value

TypeDescription
Promise<AppStatsMap>Promise used to return the application usage details in a specified period.

Error codes

For details about the error codes, see Universal Error Codes and DeviceUsageStatistics Error Codes.

IDError Message
201Permission denied.
202Not System App.
401Parameter error.
801Capability not supported.
10000001Memory operation failed.
10000002Parcel operation failed.
10000003System service operation failed.
10000004IPC failed.
10000006Failed to get the application information.
10000007Failed to get the system time.

Example

import { BusinessError } from '@kit.BasicServicesKit';

usageStatistics.queryAppStatsInfos(0, 20000000000000).then((res:usageStatistics.AppStatsMap) => {
  console.log('queryAppStatsInfos promise success.');
  console.log('queryAppStatsInfos promise result ' + JSON.stringify(res));
}).catch((err: BusinessError) => {
  console.log('queryAppStatsInfos promise failed. code is: ' + err.code + ',message is: ' + err.message);
});

usageStatistics.queryLastUseTime15+

queryLastUseTime(appInfo: Record<string, Array<number>>): Promise<AppStatsMap>

Queries application usage details based on the specified bundle name and application index. The minimum granularity is day. This API uses a promise to return the result.

Required permissions: ohos.permission.BUNDLE_ACTIVE_INFO

System capability: SystemCapability.ResourceSchedule.UsageStatistics.App

Parameters

NameTypeMandatoryDescription
appInfoRecord<string, Array<number>>YesThe parameter is in the map structure. The key is the bundle name, and the value is the index of the queried application. Multiple indexes can be transferred through the array.

Return value

TypeDescription
Promise<AppStatsMap>Promise used to return the detailed information about the application with the specified bundle name and index.

Error codes

For details about the error codes, see Universal Error Codes and DeviceUsageStatistics Error Codes.

IDError Message
201Permission denied.
202Not System App.
401Parameter error.
801Capability not supported.
10000001Memory operation failed.
10000002Parcel operation failed.
10000003System service operation failed.
10000004IPC failed.
10000006Failed to get the application information.
10000007Failed to get the system time.

Example

import { BusinessError } from '@kit.BasicServicesKit';

usageStatistics.queryLastUseTime({"com.huawei.hmos.ailife": [0]}).then((res:usageStatistics.AppStatsMap) => {
  console.log('queryLastUseTime promise success.');
  console.log('queryLastUseTime promise result ' + JSON.stringify(res));
}).catch((err: BusinessError) => {
  console.log('queryLastUseTime promise failed. code is: ' + err.code + ',message is: ' + err.message);
});

usageStatistics.queryBundleStatsInfoByInterval

queryBundleStatsInfoByInterval(byInterval: IntervalType, begin: number, end: number, callback: AsyncCallback<Array<BundleStatsInfo>>): void

Queries the application usage duration statistics in the specified time frame at the specified interval (daily, weekly, monthly, or annually). This API uses an asynchronous callback to return the result.

Required permissions: ohos.permission.BUNDLE_ACTIVE_INFO

System capability: SystemCapability.ResourceSchedule.UsageStatistics.App

Parameters

NameTypeMandatoryDescription
byIntervalIntervalTypeYesType of information to be queried.
beginnumberYesStart time, in milliseconds.
endnumberYesEnd time, in milliseconds.
callbackAsyncCallback<Array<BundleStatsInfo>>YesCallback used to return the application usage duration statistics.

Error codes

For details about the error codes, see Universal Error Codes and DeviceUsageStatistics Error Codes.

IDError Message
201Permission denied.
202Not System App.
401Parameter error.
801Capability not supported.
10000001Memory operation failed.
10000002Parcel operation failed.
10000003System service operation failed.
10000004IPC failed.
10000006Failed to get the application information.
10000007Failed to get the system time.

Example

import { BusinessError } from '@kit.BasicServicesKit';

usageStatistics.queryBundleStatsInfoByInterval(0, 0, 20000000000000, (err: BusinessError, res: Array<usageStatistics.BundleStatsInfo>) => {
  if (err) {
    console.log('BUNDLE_ACTIVE queryBundleStatsInfoByInterval callback failed. code is: ' + err.code + ',message is: ' + err.message);
  } else {
    console.log('BUNDLE_ACTIVE queryBundleStatsInfoByInterval callback success.');
    for (let i = 0; i < res.length; i++) {
      console.log('BUNDLE_ACTIVE queryBundleStatsInfoByInterval callback number : ' + (i + 1));
      console.log('BUNDLE_ACTIVE queryBundleStatsInfoByInterval callback result ' + JSON.stringify(res[i]));
    }
  }
});

usageStatistics.queryBundleStatsInfoByInterval

queryBundleStatsInfoByInterval(byInterval: IntervalType, begin: number, end: number): Promise<Array<BundleStatsInfo>>

Queries the application usage duration statistics in the specified time frame at the specified interval (daily, weekly, monthly, or annually). This API uses a promise to return the result.

Required permissions: ohos.permission.BUNDLE_ACTIVE_INFO

System capability: SystemCapability.ResourceSchedule.UsageStatistics.App

Parameters

NameTypeMandatoryDescription
byIntervalIntervalTypeYesType of information to be queried.
beginnumberYesStart time, in milliseconds.
endnumberYesEnd time, in milliseconds.

Return value

TypeDescription
Promise<Array<BundleStatsInfo>>Promise used to return the application usage duration statistics.

Error codes

For details about the error codes, see Universal Error Codes and DeviceUsageStatistics Error Codes.

IDError Message
201Permission denied.
202Not System App.
401Parameter error.
801Capability not supported.
10000001Memory operation failed.
10000002Parcel operation failed.
10000003System service operation failed.
10000004IPC failed.
10000006Failed to get the application information.
10000007Failed to get the system time.

Example

import { BusinessError } from '@kit.BasicServicesKit';

usageStatistics.queryBundleStatsInfoByInterval(0, 0, 20000000000000).then((res: Array<usageStatistics.BundleStatsInfo>) => {
  console.log('BUNDLE_ACTIVE queryBundleStatsInfoByInterval promise success.');
  for (let i = 0; i < res.length; i++) {
    console.log('BUNDLE_ACTIVE queryBundleStatsInfoByInterval promise number : ' + (i + 1));
    console.log('BUNDLE_ACTIVE queryBundleStatsInfoByInterval promise result ' + JSON.stringify(res[i]));
  }
}).catch((err: BusinessError) => {
  console.log('BUNDLE_ACTIVE queryBundleStatsInfoByInterval promise failed. code is: ' + err.code + ',message is: ' + err.message);
});

usageStatistics.queryBundleEvents

queryBundleEvents(begin: number, end: number, callback: AsyncCallback<Array<BundleEvents>>): void

Queries events of all applications based on the specified start time and end time. This API uses an asynchronous callback to return the result.

Required permissions: ohos.permission.BUNDLE_ACTIVE_INFO

System capability: SystemCapability.ResourceSchedule.UsageStatistics.App

Parameters

NameTypeMandatoryDescription
beginnumberYesStart time, in milliseconds.
endnumberYesEnd time, in milliseconds.
callbackAsyncCallback<Array<BundleEvents>>YesCallback used to return the events.

Error codes

For details about the error codes, see Universal Error Codes and DeviceUsageStatistics Error Codes.

IDError Message
201Permission denied.
202Not System App.
401Parameter error.
801Capability not supported.
10000001Memory operation failed.
10000002Parcel operation failed.
10000003System service operation failed.
10000004IPC failed.
10000006Failed to get the application information.
10000007Failed to get the system time.

Example

import { BusinessError } from '@kit.BasicServicesKit';

usageStatistics.queryBundleEvents(0, 20000000000000, (err: BusinessError, res: Array<usageStatistics.BundleEvents>) => {
  if (err) {
    console.log('BUNDLE_ACTIVE queryBundleEvents callback failed. code is: ' + err.code + ',message is: ' + err.message);
  } else {
    console.log('BUNDLE_ACTIVE queryBundleEvents callback success.');
    for (let i = 0; i < res.length; i++) {
      console.log('BUNDLE_ACTIVE queryBundleEvents callback number : ' + (i + 1));
      console.log('BUNDLE_ACTIVE queryBundleEvents callback result ' + JSON.stringify(res[i]));
    }
  }
});

usageStatistics.queryBundleEvents

queryBundleEvents(begin: number, end: number): Promise<Array<BundleEvents>>

Queries events of all applications based on the specified start time and end time. This API uses a promise to return the result.

Required permissions: ohos.permission.BUNDLE_ACTIVE_INFO

System capability: SystemCapability.ResourceSchedule.UsageStatistics.App

Parameters

NameTypeMandatoryDescription
beginnumberYesStart time, in milliseconds.
endnumberYesEnd time, in milliseconds.

Return value

TypeDescription
Promise<Array<BundleEvents>>Promise used to return the events obtained.

Error codes

For details about the error codes, see Universal Error Codes and DeviceUsageStatistics Error Codes.

IDError Message
201Permission denied.
202Not System App.
401Parameter error.
801Capability not supported.
10000001Memory operation failed.
10000002Parcel operation failed.
10000003System service operation failed.
10000004IPC failed.
10000006Failed to get the application information.
10000007Failed to get the system time.

Example

import { BusinessError } from '@kit.BasicServicesKit';

usageStatistics.queryBundleEvents(0, 20000000000000).then((res: Array<usageStatistics.BundleEvents>) => {
  console.log('BUNDLE_ACTIVE queryBundleEvents promise success.');
  for (let i = 0; i < res.length; i++) {
    console.log('BUNDLE_ACTIVE queryBundleEvents promise number : ' + (i + 1));
    console.log('BUNDLE_ACTIVE queryBundleEvents promise result ' + JSON.stringify(res[i]));
  }
}).catch((err: BusinessError) => {
  console.log('BUNDLE_ACTIVE queryBundleEvents promise failed. code is: ' + err.code + ',message is: ' + err.message);
});

usageStatistics.queryCurrentBundleEvents

queryCurrentBundleEvents(begin: number, end: number, callback: AsyncCallback<Array<BundleEvents>>): void

Queries events of this application based on the specified start time and end time. This API uses an asynchronous callback to return the result.

System capability: SystemCapability.ResourceSchedule.UsageStatistics.App

Parameters

NameTypeMandatoryDescription
beginnumberYesStart time, in milliseconds.
endnumberYesEnd time, in milliseconds.
callbackAsyncCallback<Array<BundleEvents>>YesCallback used to return the events.

Error codes

For details about the error codes, see Universal Error Codes and DeviceUsageStatistics Error Codes.

IDError Message
202Not System App.
401Parameter error.
801Capability not supported.
10000001Memory operation failed.
10000002Parcel operation failed.
10000003System service operation failed.
10000004IPC failed.
10000006Failed to get the application information.
10000007Failed to get the system time.

Example

import { BusinessError } from '@kit.BasicServicesKit';

usageStatistics.queryCurrentBundleEvents(0, 20000000000000, (err: BusinessError, res: Array<usageStatistics.BundleEvents>) => {
  if (err) {
    console.log('BUNDLE_ACTIVE queryCurrentBundleEvents callback failed. code is: ' + err.code + ',message is: ' + err.message);
  } else {
    console.log('BUNDLE_ACTIVE queryCurrentBundleEvents callback success.');
    for (let i = 0; i < res.length; i++) {
      console.log('BUNDLE_ACTIVE queryCurrentBundleEvents callback number : ' + (i + 1));
      console.log('BUNDLE_ACTIVE queryCurrentBundleEvents callback result ' + JSON.stringify(res[i]));
    }
  }
});

usageStatistics.queryCurrentBundleEvents

queryCurrentBundleEvents(begin: number, end: number): Promise<Array<BundleEvents>>

Queries events of this application based on the specified start time and end time. This API uses a promise to return the result.

System capability: SystemCapability.ResourceSchedule.UsageStatistics.App

Parameters

NameTypeMandatoryDescription
beginnumberYesStart time, in milliseconds.
endnumberYesEnd time, in milliseconds.

Return value

TypeDescription
Promise<Array<BundleEvents>>Promise used to return the events obtained.

Error codes

For details about the error codes, see Universal Error Codes and DeviceUsageStatistics Error Codes.

IDError Message
202Not System App.
401Parameter error.
801Capability not supported.
10000001Memory operation failed.
10000002Parcel operation failed.
10000003System service operation failed.
10000004IPC failed.
10000006Failed to get the application information.
10000007Failed to get the system time.

Example

import { BusinessError } from '@kit.BasicServicesKit';

usageStatistics.queryCurrentBundleEvents(0, 20000000000000).then((res: Array<usageStatistics.BundleEvents>) => {
  console.log('BUNDLE_ACTIVE queryCurrentBundleEvents promise success.');
  for (let i = 0; i < res.length; i++) {
    console.log('BUNDLE_ACTIVE queryCurrentBundleEvents promise number : ' + (i + 1));
    console.log('BUNDLE_ACTIVE queryCurrentBundleEvents promise result ' + JSON.stringify(res[i]));
  }
}).catch((err: BusinessError) => {
  console.log('BUNDLE_ACTIVE queryCurrentBundleEvents promise failed. code is: ' + err.code + ',message is: ' + err.message);
});

usageStatistics.queryDeviceEventStats

queryDeviceEventStats(begin: number, end: number): Promise<Array<DeviceEventStats>>

Queries statistics about system events (hibernation, wakeup, unlocking, and locking) that occur between the specified start time and end time. This API uses a promise to return the result.

Required permissions: ohos.permission.BUNDLE_ACTIVE_INFO

System capability: SystemCapability.ResourceSchedule.UsageStatistics.App

Parameters

NameTypeMandatoryDescription
beginnumberYesStart time, in milliseconds.
endnumberYesEnd time, in milliseconds.

Return value

TypeDescription
Promise<Array<DeviceEventStats>>Promise used to return the statistics about system events.

Error codes

For details about the error codes, see Universal Error Codes and DeviceUsageStatistics Error Codes.

IDError Message
201Permission denied.
202Not System App.
401Parameter error.
801Capability not supported.
10000001Memory operation failed.
10000002Parcel operation failed.
10000003System service operation failed.
10000004IPC failed.
10000006Failed to get the application information.
10000007Failed to get the system time.

Example

import { BusinessError } from '@kit.BasicServicesKit';

usageStatistics.queryDeviceEventStats(0, 20000000000000).then((res: Array<usageStatistics.DeviceEventStats>) => {
  console.log('BUNDLE_ACTIVE queryDeviceEventStates promise success.');
  console.log('BUNDLE_ACTIVE queryDeviceEventStates promise result ' + JSON.stringify(res));
}).catch((err: BusinessError) => {
  console.log('BUNDLE_ACTIVE queryDeviceEventStats promise failed. code is: ' + err.code + ',message is: ' + err.message);
});

usageStatistics.queryDeviceEventStats

queryDeviceEventStats(begin: number, end: number, callback: AsyncCallback<Array<DeviceEventStats>>): void

Queries statistics about system events (hibernation, wakeup, unlocking, and locking) that occur between the specified start time and end time. This API uses an asynchronous callback to return the result.

Required permissions: ohos.permission.BUNDLE_ACTIVE_INFO

System capability: SystemCapability.ResourceSchedule.UsageStatistics.App

Parameters

NameTypeMandatoryDescription
beginnumberYesStart time, in milliseconds.
endnumberYesEnd time, in milliseconds.
callbackAsyncCallback<Array<DeviceEventStats>>YesCallback used to return the statistics about system events.

Error codes

For details about the error codes, see Universal Error Codes and DeviceUsageStatistics Error Codes.

IDError Message
201Permission denied.
202Not System App.
401Parameter error.
801Capability not supported.
10000001Memory operation failed.
10000002Parcel operation failed.
10000003System service operation failed.
10000004IPC failed.
10000006Failed to get the application information.
10000007Failed to get the system time.

Example

import { BusinessError } from '@kit.BasicServicesKit';

usageStatistics.queryDeviceEventStats(0, 20000000000000, (err: BusinessError, res: Array<usageStatistics.DeviceEventStats>) => {
  if(err) {
    console.log('BUNDLE_ACTIVE queryDeviceEventStats callback failed. code is: ' + err.code + ',message is: ' + err.message);
  } else {
    console.log('BUNDLE_ACTIVE queryDeviceEventStats callback success.');
    console.log('BUNDLE_ACTIVE queryDeviceEventStats callback result ' + JSON.stringify(res));
  }
});

usageStatistics.queryNotificationEventStats

queryNotificationEventStats(begin: number, end: number): Promise<Array<DeviceEventStats>>

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.

Required permissions: ohos.permission.BUNDLE_ACTIVE_INFO

System capability: SystemCapability.ResourceSchedule.UsageStatistics.App

Parameters

NameTypeMandatoryDescription
beginnumberYesStart time, in milliseconds.
endnumberYesEnd time, in milliseconds.

Return value

TypeDescription
Promise<Array<DeviceEventStats>>Promise used to return the number of notifications.

Error codes

For details about the error codes, see Universal Error Codes and DeviceUsageStatistics Error Codes.

IDError Message
201Permission denied.
202Not System App.
401Parameter error.
801Capability not supported.
10000001Memory operation failed.
10000002Parcel operation failed.
10000003System service operation failed.
10000004IPC failed.
10000006Failed to get the application information.
10000007Failed to get the system time.

Example

import { BusinessError } from '@kit.BasicServicesKit';

usageStatistics.queryNotificationEventStats(0, 20000000000000).then((res: Array<usageStatistics.DeviceEventStats>) => {
  console.log('BUNDLE_ACTIVE queryNotificationEventStats promise success.');
  console.log('BUNDLE_ACTIVE queryNotificationEventStats promise result ' + JSON.stringify(res));
}).catch((err: BusinessError) => {
  console.log('BUNDLE_ACTIVE queryNotificationEventStats promise failed. code is: ' + err.code + ',message is: ' + err.message);
});

usageStatistics.queryNotificationEventStats

queryNotificationEventStats(begin: number, end: number, callback: AsyncCallback<Array<DeviceEventStats>>): void

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.

Required permissions: ohos.permission.BUNDLE_ACTIVE_INFO

System capability: SystemCapability.ResourceSchedule.UsageStatistics.App

Parameters

NameTypeMandatoryDescription
beginnumberYesStart time, in milliseconds.
endnumberYesEnd time, in milliseconds.
callbackAsyncCallback<Array<DeviceEventStats>>YesCallback used to return the number of notifications.

Error codes

For details about the error codes, see Universal Error Codes and DeviceUsageStatistics Error Codes.

IDError Message
201Permission denied.
202Not System App.
401Parameter error.
801Capability not supported.
10000001Memory operation failed.
10000002Parcel operation failed.
10000003System service operation failed.
10000004IPC failed.
10000006Failed to get the application information.
10000007Failed to get the system time.

Example

import { BusinessError } from '@kit.BasicServicesKit';

usageStatistics.queryNotificationEventStats(0, 20000000000000, (err: BusinessError, res: Array<usageStatistics.DeviceEventStats>) => {
  if(err) {
    console.log('BUNDLE_ACTIVE queryNotificationEventStats callback failed. code is: ' + err.code + ',message is: ' + err.message);
  } else {
    console.log('BUNDLE_ACTIVE queryNotificationEventStats callback success.');
    console.log('BUNDLE_ACTIVE queryNotificationEventStats callback result ' + JSON.stringify(res));
  }
});

usageStatistics.queryModuleUsageRecords

queryModuleUsageRecords(): Promise<Array<HapModuleInfo>>

Queries the usage records of unused HAP files for each application in the FA model. If the HAP file contains FA widgets, the usage records also contain the widget information. This API uses a promise to return the result.

Queries FA usage records. This API uses a promise to return a maximum of 1000 FA usage records sorted by time (most recent first).

Required permissions: ohos.permission.BUNDLE_ACTIVE_INFO

System capability: SystemCapability.ResourceSchedule.UsageStatistics.App

Return value

TypeDescription
Promise<Array<HapModuleInfo>>Promise used to return the result. A maximum of 1000 usage records can be returned.

Error codes

For details about the error codes, see Universal Error Codes and DeviceUsageStatistics Error Codes.

IDError Message
201Permission denied.
202Not System App.
401Parameter error.
801Capability not supported.
10000001Memory operation failed.
10000002Parcel operation failed.
10000003System service operation failed.
10000004IPC failed.
10000006Failed to get the application information.
10000007Failed to get the system time.

Example

// Invocation when maxNum is not passed
import { BusinessError } from '@kit.BasicServicesKit';

usageStatistics.queryModuleUsageRecords().then((res: Array<usageStatistics.HapModuleInfo>) => {
  console.log('BUNDLE_ACTIVE queryModuleUsageRecords promise succeeded');
  for (let i = 0; i < res.length; i++) {
    console.log('BUNDLE_ACTIVE queryModuleUsageRecords promise number : ' + (i + 1));
    console.log('BUNDLE_ACTIVE queryModuleUsageRecords promise result ' + JSON.stringify(res[i]));
  }
}).catch((err: BusinessError) => {
  console.log('BUNDLE_ACTIVE queryModuleUsageRecords promise failed. code is: ' + err.code + ',message is: ' + err.message);
});

usageStatistics.queryModuleUsageRecords

queryModuleUsageRecords(callback: AsyncCallback<Array<HapModuleInfo>>): void

Queries the usage records of unused HAP files for each application in the FA model. If the HAP file contains FA widgets, the usage records also contain the widget information. This API uses an asynchronous callback to return the result.

Required permissions: ohos.permission.BUNDLE_ACTIVE_INFO

System capability: SystemCapability.ResourceSchedule.UsageStatistics.App

Parameters

NameTypeMandatoryDescription
callbackAsyncCallback<Array<HapModuleInfo>>YesCallback used to return the result. A maximum of 1000 usage records can be returned.

Error codes

For details about the error codes, see DeviceUsageStatistics Error Codes.

IDError Message
10000001Memory operation failed.
10000002Parcel operation failed.
10000003System service operation failed.
10000004IPC failed.
10000006Failed to get the application information.
10000007Failed to get the system time.

Example

import { BusinessError } from '@kit.BasicServicesKit';

usageStatistics.queryModuleUsageRecords((err: BusinessError, res: Array<usageStatistics.HapModuleInfo>) => {
  if(err) {
    console.log('BUNDLE_ACTIVE queryModuleUsageRecords callback failed. code is: ' + err.code + ',message is: ' + err.message);
  } else {
    console.log('BUNDLE_ACTIVE queryModuleUsageRecords callback succeeded.');
    for (let i = 0; i < res.length; i++) {
      console.log('BUNDLE_ACTIVE queryModuleUsageRecords callback number : ' + (i + 1));
      console.log('BUNDLE_ACTIVE queryModuleUsageRecords callback result ' + JSON.stringify(res[i]));
    }
  }
});

usageStatistics.queryModuleUsageRecords

queryModuleUsageRecords(maxNum: number): Promise<Array<HapModuleInfo>>

Queries a given number of usage records of unused HAP files for each application in the FA model. If the HAP file contains FA widgets, the usage records also contain the widget information. This API uses a promise to return the result.

Required permissions: ohos.permission.BUNDLE_ACTIVE_INFO

System capability: SystemCapability.ResourceSchedule.UsageStatistics.App

Parameters

NameTypeMandatoryDescription
maxNumnumberYesNumber of usage records, in the range [1, 1000].

Return value

TypeDescription
Promise<Array<HapModuleInfo>>Promise used to return the result. The usage records returned does not exceed the value of maxNum.

Error codes

For details about the error codes, see Universal Error Codes and DeviceUsageStatistics Error Codes.

IDError Message
201Permission denied.
202Not System App.
401Parameter error. Possible cause: 1. Mandatory parameters are left unspecified; 2. Incorrect parameters types; 3. Parameter verification failed.
801Capability not supported.
10000001Memory operation failed.
10000002Parcel operation failed.
10000003System service operation failed.
10000004IPC failed.
10000006Failed to get the application information.
10000007Failed to get the system time.

Example

import { BusinessError } from '@kit.BasicServicesKit';

usageStatistics.queryModuleUsageRecords(1000).then((res: Array<usageStatistics.HapModuleInfo>) => {
  console.log('BUNDLE_ACTIVE queryModuleUsageRecords promise succeeded');
  for (let i = 0; i < res.length; i++) {
    console.log('BUNDLE_ACTIVE queryModuleUsageRecords promise number : ' + (i + 1));
    console.log('BUNDLE_ACTIVE queryModuleUsageRecords promise result ' + JSON.stringify(res[i]));
  }
}).catch((err: BusinessError) => {
  console.log('BUNDLE_ACTIVE queryModuleUsageRecords promise failed. code is: ' + err.code + ',message is: ' + err.message);
});

usageStatistics.queryModuleUsageRecords

queryModuleUsageRecords(maxNum: number, callback: AsyncCallback<Array<HapModuleInfo>>): void

Queries a given number of usage records of unused HAP files for each application in the FA model. If the HAP file contains FA widgets, the usage records also contain the widget information. This API uses an asynchronous callback to return the result.

Required permissions: ohos.permission.BUNDLE_ACTIVE_INFO

System capability: SystemCapability.ResourceSchedule.UsageStatistics.App

Parameters

NameTypeMandatoryDescription
maxNumnumberYesNumber of usage records, in the range [1, 1000].
callbackAsyncCallback<Array<HapModuleInfo>>YesCallback used to return the result. The usage records returned does not exceed the value of maxNum.

Error codes

For details about the error codes, see Universal Error Codes and DeviceUsageStatistics Error Codes.

IDError Message
201Permission denied.
202Not System App.
401Parameter error. Possible cause: 1. Mandatory parameters are left unspecified; 2. Incorrect parameters types; 3. Parameter verification failed.
801Capability not supported.
10000001Memory operation failed.
10000002Parcel operation failed.
10000003System service operation failed.
10000004IPC failed.
10000006Failed to get the application information.
10000007Failed to get the system time.

Example

import { BusinessError } from '@kit.BasicServicesKit';

usageStatistics.queryModuleUsageRecords(1000, (err: BusinessError, res: Array<usageStatistics.HapModuleInfo>) => {
  if(err) {
    console.log('BUNDLE_ACTIVE queryModuleUsageRecords callback failed. code is: ' + err.code + ',message is: ' + err.message);
  } else {
    console.log('BUNDLE_ACTIVE queryModuleUsageRecords callback succeeded.');
    for (let i = 0; i < res.length; i++) {
      console.log('BUNDLE_ACTIVE queryModuleUsageRecords callback number : ' + (i + 1));
      console.log('BUNDLE_ACTIVE queryModuleUsageRecords callback result ' + JSON.stringify(res[i]));
    }
  }
});

usageStatistics.registerAppGroupCallBack

registerAppGroupCallBack(groupCallback: Callback<AppGroupCallbackInfo>): Promise<void>

Registers a callback for application group changes. When an application group of the user changes, an AppGroupCallbackInfo instance is returned to all applications that have registered the callback. This API uses a promise to return the result.

Required permissions: ohos.permission.BUNDLE_ACTIVE_INFO

System capability: SystemCapability.ResourceSchedule.UsageStatistics.AppGroup

Parameters

NameTypeMandatoryDescription
groupCallbackCallback<AppGroupCallbackInfo>YesApplication group change information.

Return value

TypeDescription
Promise<void>Promise that returns no value.

Error codes

For details about the error codes, see Universal Error Codes and DeviceUsageStatistics Error Codes.

IDError Message
201Permission denied.
202Not System App.
401Parameter error.
801Capability not supported.
10000001Memory operation failed.
10000002Parcel operation failed.
10000003System service operation failed.
10000004IPC failed.
10100001Repeated operation on the application group.

Example

import { BusinessError } from '@kit.BasicServicesKit';

function onBundleGroupChanged(res: usageStatistics.AppGroupCallbackInfo) {
  console.log('BUNDLE_ACTIVE registerAppGroupCallBack RegisterGroupCallBack callback success.');
  console.log('BUNDLE_ACTIVE registerAppGroupCallBack result appOldGroup is : ' + res.appOldGroup);
  console.log('BUNDLE_ACTIVE registerAppGroupCallBack result appNewGroup is : ' + res.appNewGroup);
  console.log('BUNDLE_ACTIVE registerAppGroupCallBack result changeReason is : ' + res.changeReason);
  console.log('BUNDLE_ACTIVE registerAppGroupCallBack result userId is : ' + res.userId);
  console.log('BUNDLE_ACTIVE registerAppGroupCallBack result bundleName is : ' + res.bundleName);
};
usageStatistics.registerAppGroupCallBack(onBundleGroupChanged).then( () => {
  console.log('BUNDLE_ACTIVE registerAppGroupCallBack promise succeeded.');
}).catch((err: BusinessError) => {
  console.log('BUNDLE_ACTIVE registerAppGroupCallBack promise failed. code is: ' + err.code + ',message is: ' + err.message);
});

usageStatistics.registerAppGroupCallBack

registerAppGroupCallBack(groupCallback: Callback<AppGroupCallbackInfo>, callback: AsyncCallback<void>): void

Registers a callback for application group changes. When an application group of the user changes, an AppGroupCallbackInfo instance is returned to all applications that have registered the callback. This API uses an asynchronous callback to return the result.

Required permissions: ohos.permission.BUNDLE_ACTIVE_INFO

System capability: SystemCapability.ResourceSchedule.UsageStatistics.AppGroup

Parameters

NameTypeMandatoryDescription
groupCallbackCallback<AppGroupCallbackInfo>YesApplication group change information.
callbackAsyncCallback<void>YesCallback used to return the result.

Error codes

For details about the error codes, see Universal Error Codes and DeviceUsageStatistics Error Codes.

IDError Message
201Permission denied.
202Not System App.
401Parameter error.
801Capability not supported.
10000001Memory operation failed.
10000002Parcel operation failed.
10000003System service operation failed.
10000004IPC failed.
10100001Repeated operation on the application group.

Example

import { BusinessError } from '@kit.BasicServicesKit';

function onBundleGroupChanged(res: usageStatistics.AppGroupCallbackInfo) {
  console.log('BUNDLE_ACTIVE onBundleGroupChanged RegisterGroupCallBack callback success.');
  console.log('BUNDLE_ACTIVE registerAppGroupCallBack result appOldGroup is : ' + res.appOldGroup);
  console.log('BUNDLE_ACTIVE registerAppGroupCallBack result appNewGroup is : ' + res.appNewGroup);
  console.log('BUNDLE_ACTIVE registerAppGroupCallBack result changeReason is : ' + res.changeReason);
  console.log('BUNDLE_ACTIVE registerAppGroupCallBack result userId is : ' + res.userId);
  console.log('BUNDLE_ACTIVE registerAppGroupCallBack result bundleName is : ' + res.bundleName);
};
usageStatistics.registerAppGroupCallBack(onBundleGroupChanged, (err: BusinessError) => {
  if(err) {
    console.log('BUNDLE_ACTIVE registerAppGroupCallBack callback failed. code is: ' + err.code + ',message is: ' + err.message);
  } else {
    console.log('BUNDLE_ACTIVE registerAppGroupCallBack callback success.');
  }
});

usageStatistics.unregisterAppGroupCallBack

unregisterAppGroupCallBack(): Promise<void>

Unregisters the callback for application group changes. This API uses a promise to return the result.

Required permissions: ohos.permission.BUNDLE_ACTIVE_INFO

System capability: SystemCapability.ResourceSchedule.UsageStatistics.AppGroup

Return value

TypeDescription
Promise<void>Promise that returns no value.

Error codes

For details about the error codes, see Universal Error Codes and DeviceUsageStatistics Error Codes.

IDError Message
201Permission denied.
202Not System App.
401Parameter error.
801Capability not supported.
10000001Memory operation failed.
10000002Parcel operation failed.
10000003System service operation failed.
10000004IPC failed.
10100001Repeated operation on the application group.

Example

import { BusinessError } from '@kit.BasicServicesKit';

usageStatistics.unregisterAppGroupCallBack().then( () => {
  console.log('BUNDLE_ACTIVE unregisterAppGroupCallBack promise succeeded.');
}).catch((err: BusinessError) => {
  console.log('BUNDLE_ACTIVE unregisterAppGroupCallBack promise failed. code is: ' + err.code + ',message is: ' + err.message);
});

usageStatistics.unregisterAppGroupCallBack

unregisterAppGroupCallBack(callback: AsyncCallback<void>): void;

Unregisters the callback for application group changes. This API uses an asynchronous callback to return the result.

Required permissions: ohos.permission.BUNDLE_ACTIVE_INFO

System capability: SystemCapability.ResourceSchedule.UsageStatistics.AppGroup

Parameters

NameTypeMandatoryDescription
callbackAsyncCallback<void>YesCallback used to return the result.

Error codes

For details about the error codes, see Universal Error Codes and DeviceUsageStatistics Error Codes.

IDError Message
201Permission denied.
202Not System App.
401Parameter error.
801Capability not supported.
10000001Memory operation failed.
10000002Parcel operation failed.
10000003System service operation failed.
10000004IPC failed.
10100001Repeated operation on the application group.

Example

import { BusinessError } from '@kit.BasicServicesKit';

usageStatistics.unregisterAppGroupCallBack((err: BusinessError) => {
  if(err) {
    console.log('BUNDLE_ACTIVE unregisterAppGroupCallBack callback failed. code is: ' + err.code + ',message is: ' + err.message);
  } else {
    console.log('BUNDLE_ACTIVE unregisterAppGroupCallBack callback success.');
  }
});

HapModuleInfo

Defines the information about the usage record in the FA model.

System capability: SystemCapability.ResourceSchedule.UsageStatistics.App

NameTypeMandatoryDescription
deviceIdstringNoDevice ID.
bundleNamestringYesBundle name.
moduleNamestringYesName of the module to which the FA belongs.
abilityNamestringNoMainAbility name of the FA.
appLabelIdnumberNoApplication label ID of the FA.
labelIdnumberNoLabel ID of the module to which the FA belongs.
descriptionIdnumberNoDescription ID of the application to which the FA belongs.
abilityLableIdnumberNoMainAbility label ID of the FA.
abilityDescriptionIdnumberNoMainAbility description ID of the FA.
abilityIconIdnumberNoMainAbility icon ID of the FA.
launchedCountnumberYesNumber of FA startup times.
lastModuleUsedTimenumberYesLast time when the FA was used.
formRecordsArray<HapFormInfo>YesArray of widget usage records in the FA.

HapFormInfo

Defines the information about the usage record of FA widgets.

System capability: SystemCapability.ResourceSchedule.UsageStatistics.App

NameTypeMandatoryDescription
formNamestringYesWidget name.
formDimensionnumberYesWidget dimensions.
formIdnumberYesWidget ID.
formLastUsedTimenumberYesLast time when the widget was clicked.
countnumberYesNumber of clicks on the widget.

AppGroupCallbackInfo

Provides the application group changes returned through a callback.

System capability: SystemCapability.ResourceSchedule.UsageStatistics.AppGroup

NameTypeMandatoryDescription
appOldGroupnumberYesApplication group before the change.
appNewGroupnumberYesApplication group after the change.
userIdnumberYesUser ID.
changeReasonnumberYesReason for the group change.
- 256 (default): A record is initially created.
- 512: An exception occurs when the priority group is calculated.
- 768: The usage duration changes.
- 1024: Another application forcibly sets a priority group for the current application.
bundleNamestringYesBundle name.

BundleStatsInfo

Provides the usage duration information of an application.

System capability: SystemCapability.ResourceSchedule.UsageStatistics.App

NameTypeMandatoryDescription
bundleNamestringNoBundle name of the application.
abilityPrevAccessTimenumberNoLast time when the application was used.
abilityInFgTotalTimenumberNoTotal time that the application runs in the foreground.
idnumberYesUser ID.
abilityPrevSeenTimenumberNoLast time when the application was visible in the foreground.
abilitySeenTotalTimenumberNoTotal time that the application is visible in the foreground.
fgAbilityAccessTotalTimenumberNoTotal time that the application accesses the foreground.
fgAbilityPrevAccessTimenumberNoLast time when the application accessed the foreground.
infosBeginTimenumberNoTime logged in the first application usage record in the BundleActiveInfo object.
infosEndTimenumberNoTime logged in the last application usage record in the BundleActiveInfo object.
appIndex15+numberNoApplication index.

BundleEvents

Provides information about an application event.

System capability: SystemCapability.ResourceSchedule.UsageStatistics.App

NameTypeMandatoryDescription
bundleNamestringNoBundle name of the application.
eventIdnumberNoApplication event type.
eventOccurredTimenumberNoTimestamp when the application event occurs.
appGroupnumberNoGroup of the application by usage priority.
indexOfLinkstringNoShortcut ID.
nameOfClassstringNoClass name.

BundleStatsMap

Provides the usage duration information of an application.

System capability: SystemCapability.ResourceSchedule.UsageStatistics.App

NameDescription
Record<string, BundleStatsInfo>Usage duration information by application.

AppStatsMap15+

Provides the detailed usage information of an application (including application clones).

System capability: SystemCapability.ResourceSchedule.UsageStatistics.App

NameDescription
Record<string, Array<BundleStatsInfo>>Usage information by application (including application clones).

DeviceEventStats

Provides statistics about notifications and system events.

System capability: SystemCapability.ResourceSchedule.UsageStatistics.App

NameTypeMandatoryDescription
namestringYesBundle name of the notification sending application or system event name.
eventIdnumberYesType of the notification or system event.
countnumberYesNumber of application notifications or system event triggering times.

IntervalType

Enumerates the interval types for querying the application usage duration.

System capability: SystemCapability.ResourceSchedule.UsageStatistics.App

NameValueDescription
BY_OPTIMIZED0The system queries the application usage duration statistics in the specified time frame at the interval the system deems appropriate.
BY_DAILY1The system queries the application usage duration statistics in the specified time frame on a daily basis.
BY_WEEKLY2The system queries the application usage duration statistics in the specified time frame on a weekly basis.
BY_MONTHLY3The system queries the application usage duration statistics in the specified time frame on a monthly basis.
BY_ANNUALLY4The system queries the application usage duration statistics in the specified time frame on an annual basis.

GroupType

Enumerates the application group types.

System capability: SystemCapability.ResourceSchedule.UsageStatistics.AppGroup

NameValueDescription
ALIVE_GROUP10Group of active applications.
DAILY_GROUP20Group of frequently used applications that are not in the active state.
FIXED_GROUP30Group of applications that are used periodically but not every day.
RARE_GROUP40Group of rarely used applications.
LIMITED_GROUP50Group of restricted applications.
NEVER_GROUP60Group of applications that have been installed but never run.

你可能感兴趣的鸿蒙文章

harmony 鸿蒙Background Tasks Kit

harmony 鸿蒙BackgroundProcessManager

harmony 鸿蒙TransientTask

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)

  • 所属分类: 后端技术
  • 本文标签: 软件 鸿蒙
  • 版权声明: 本文链接 https://seaxiang.com/blog/gTDMka