1e41f4b71Sopenharmony_ci# @ohos.resourceschedule.usageStatistics (设备使用信息统计)(系统接口) 2e41f4b71Sopenharmony_ci 3e41f4b71Sopenharmony_ci本模块提供设备使用信息统计能力,包括查询应用是否为常用应用、优先级分组、使用时长、系统事件(休眠、唤醒、解锁、锁屏)信息、应用事件(前台、后台、长时任务开始和结束)信息、通知次数等不同类型信息。 4e41f4b71Sopenharmony_ci 5e41f4b71Sopenharmony_ci> **说明:** 6e41f4b71Sopenharmony_ci> 7e41f4b71Sopenharmony_ci> 本模块首批接口从API version 9开始支持。后续版本的新增接口,采用上角标单独标记接口的起始版本。 8e41f4b71Sopenharmony_ci> 9e41f4b71Sopenharmony_ci> 本模块接口为系统接口。 10e41f4b71Sopenharmony_ci 11e41f4b71Sopenharmony_ci## 导入模块 12e41f4b71Sopenharmony_ci 13e41f4b71Sopenharmony_ci``` 14e41f4b71Sopenharmony_ciimport { usageStatistics } from '@kit.BackgroundTasksKit' 15e41f4b71Sopenharmony_ci``` 16e41f4b71Sopenharmony_ci 17e41f4b71Sopenharmony_ci## usageStatistics.isIdleState 18e41f4b71Sopenharmony_ci 19e41f4b71Sopenharmony_ciisIdleState(bundleName: string, callback: AsyncCallback<boolean>): void 20e41f4b71Sopenharmony_ci 21e41f4b71Sopenharmony_ci查询指定的应用是否为常用应用(GroupType值≤30),使用Callback形式返回。 22e41f4b71Sopenharmony_ci 23e41f4b71Sopenharmony_ci**需要权限**:ohos.permission.BUNDLE_ACTIVE_INFO 24e41f4b71Sopenharmony_ci 25e41f4b71Sopenharmony_ci**系统能力**:SystemCapability.ResourceSchedule.UsageStatistics.AppGroup 26e41f4b71Sopenharmony_ci 27e41f4b71Sopenharmony_ci**参数**: 28e41f4b71Sopenharmony_ci 29e41f4b71Sopenharmony_ci| 参数名 | 类型 | 必填 | 说明 | 30e41f4b71Sopenharmony_ci| ---------- | ---------------------------- | ---- | ---------------------------------------- | 31e41f4b71Sopenharmony_ci| bundleName | string | 是 | 应用的bundleName。 | 32e41f4b71Sopenharmony_ci| callback | AsyncCallback<boolean> | 是 | 回调函数。<br>若应用为常用应用,返回true;若指定应用不是常用应用或bundleName无效,则返回false。 | 33e41f4b71Sopenharmony_ci 34e41f4b71Sopenharmony_ci**错误码**: 35e41f4b71Sopenharmony_ci 36e41f4b71Sopenharmony_ci以下错误码的详细介绍请参见[设备信息使用统计错误码](errorcode-DeviceUsageStatistics.md)和[通用错误码](../errorcode-universal.md)。 37e41f4b71Sopenharmony_ci 38e41f4b71Sopenharmony_ci| 错误码ID | 错误信息 | 39e41f4b71Sopenharmony_ci| ---- | --------------------- | 40e41f4b71Sopenharmony_ci| 201 | Permission denied. | 41e41f4b71Sopenharmony_ci| 202 | Not System App. | 42e41f4b71Sopenharmony_ci| 401 | Parameter error. | 43e41f4b71Sopenharmony_ci| 801 | Capability not supported.| 44e41f4b71Sopenharmony_ci| 10000001 | Memory operation failed. | 45e41f4b71Sopenharmony_ci| 10000002 | Parcel operation failed. | 46e41f4b71Sopenharmony_ci| 10000003 | System service operation failed. | 47e41f4b71Sopenharmony_ci| 10000004 | IPC failed. | 48e41f4b71Sopenharmony_ci| 10000006 | Failed to get the application information. | 49e41f4b71Sopenharmony_ci 50e41f4b71Sopenharmony_ci**示例**: 51e41f4b71Sopenharmony_ci```ts 52e41f4b71Sopenharmony_ciimport { BusinessError } from '@kit.BasicServicesKit'; 53e41f4b71Sopenharmony_ci 54e41f4b71Sopenharmony_ciusageStatistics.isIdleState("com.ohos.camera", (err: BusinessError, res: boolean) => { 55e41f4b71Sopenharmony_ci if (err) { 56e41f4b71Sopenharmony_ci console.log('BUNDLE_ACTIVE isIdleState callback failed. code is: ' + err.code + ',message is: ' + err.message); 57e41f4b71Sopenharmony_ci } else { 58e41f4b71Sopenharmony_ci console.log('BUNDLE_ACTIVE isIdleState callback succeeded, result: ' + JSON.stringify(res)); 59e41f4b71Sopenharmony_ci } 60e41f4b71Sopenharmony_ci}); 61e41f4b71Sopenharmony_ci``` 62e41f4b71Sopenharmony_ci 63e41f4b71Sopenharmony_ci## usageStatistics.isIdleState 64e41f4b71Sopenharmony_ci 65e41f4b71Sopenharmony_ciisIdleState(bundleName: string): Promise<boolean> 66e41f4b71Sopenharmony_ci 67e41f4b71Sopenharmony_ci查询指定的应用是否为常用应用(GroupType值≤30),使用Promise异步回调。 68e41f4b71Sopenharmony_ci 69e41f4b71Sopenharmony_ci**需要权限**:ohos.permission.BUNDLE_ACTIVE_INFO 70e41f4b71Sopenharmony_ci 71e41f4b71Sopenharmony_ci**系统能力**:SystemCapability.ResourceSchedule.UsageStatistics.AppGroup 72e41f4b71Sopenharmony_ci 73e41f4b71Sopenharmony_ci**参数**: 74e41f4b71Sopenharmony_ci 75e41f4b71Sopenharmony_ci| 参数名 | 类型 | 必填 | 说明 | 76e41f4b71Sopenharmony_ci| ---------- | ------ | ---- | -------------- | 77e41f4b71Sopenharmony_ci| bundleName | string | 是 | 应用的bundleName。 | 78e41f4b71Sopenharmony_ci 79e41f4b71Sopenharmony_ci**返回值**: 80e41f4b71Sopenharmony_ci 81e41f4b71Sopenharmony_ci| 类型 | 说明 | 82e41f4b71Sopenharmony_ci| ---------------------- | ---------------------------------------- | 83e41f4b71Sopenharmony_ci| Promise<boolean> | Promise对象。<br>若应用为常用应用,返回true;若指定应用不是常用应用或bundleName无效,则返回false。 | 84e41f4b71Sopenharmony_ci 85e41f4b71Sopenharmony_ci**错误码**: 86e41f4b71Sopenharmony_ci 87e41f4b71Sopenharmony_ci以下错误码的详细介绍请参见[设备信息使用统计错误码](errorcode-DeviceUsageStatistics.md)和[通用错误码](../errorcode-universal.md)。 88e41f4b71Sopenharmony_ci 89e41f4b71Sopenharmony_ci| 错误码ID | 错误信息 | 90e41f4b71Sopenharmony_ci| ---- | --------------------- | 91e41f4b71Sopenharmony_ci| 201 | Permission denied. | 92e41f4b71Sopenharmony_ci| 202 | Not System App. | 93e41f4b71Sopenharmony_ci| 401 | Parameter error. | 94e41f4b71Sopenharmony_ci| 801 | Capability not supported.| 95e41f4b71Sopenharmony_ci| 10000001 | Memory operation failed. | 96e41f4b71Sopenharmony_ci| 10000002 | Parcel operation failed. | 97e41f4b71Sopenharmony_ci| 10000003 | System service operation failed. | 98e41f4b71Sopenharmony_ci| 10000004 | IPC failed. | 99e41f4b71Sopenharmony_ci| 10000006 | Failed to get the application information. | 100e41f4b71Sopenharmony_ci 101e41f4b71Sopenharmony_ci**示例**: 102e41f4b71Sopenharmony_ci 103e41f4b71Sopenharmony_ci```ts 104e41f4b71Sopenharmony_ciimport { BusinessError } from '@kit.BasicServicesKit'; 105e41f4b71Sopenharmony_ci 106e41f4b71Sopenharmony_ciusageStatistics.isIdleState("com.ohos.camera").then((res: boolean) => { 107e41f4b71Sopenharmony_ci console.log('BUNDLE_ACTIVE isIdleState promise succeeded, result: ' + JSON.stringify(res)); 108e41f4b71Sopenharmony_ci}).catch((err: BusinessError) => { 109e41f4b71Sopenharmony_ci console.log('BUNDLE_ACTIVE isIdleState promise failed. code is: ' + err.code + ',message is: ' + err.message); 110e41f4b71Sopenharmony_ci}); 111e41f4b71Sopenharmony_ci``` 112e41f4b71Sopenharmony_ci## usageStatistics.isIdleStateSync<sup>10+<sup> 113e41f4b71Sopenharmony_ci 114e41f4b71Sopenharmony_ciisIdleStateSync(bundleName: string): boolean 115e41f4b71Sopenharmony_ci 116e41f4b71Sopenharmony_ci查询指定的应用是否为常用应用(GroupType值≤30),使用同步方式返回。 117e41f4b71Sopenharmony_ci 118e41f4b71Sopenharmony_ci**需要权限**:ohos.permission.BUNDLE_ACTIVE_INFO 119e41f4b71Sopenharmony_ci 120e41f4b71Sopenharmony_ci**系统能力**:SystemCapability.ResourceSchedule.UsageStatistics.AppGroup 121e41f4b71Sopenharmony_ci 122e41f4b71Sopenharmony_ci**参数**: 123e41f4b71Sopenharmony_ci 124e41f4b71Sopenharmony_ci| 参数名 | 类型 | 必填 | 说明 | 125e41f4b71Sopenharmony_ci| ---------- | ---------------------------- | ---- | ---------------------------------------- | 126e41f4b71Sopenharmony_ci| bundleName | string | 是 | 应用的bundleName。 | 127e41f4b71Sopenharmony_ci 128e41f4b71Sopenharmony_ci**返回值**: 129e41f4b71Sopenharmony_ci 130e41f4b71Sopenharmony_ci| 类型 | 说明 | 131e41f4b71Sopenharmony_ci| ---------------------- | ---------------------------------------- | 132e41f4b71Sopenharmony_ci| boolean | 若应用为常用应用,返回true;若指定应用不是常用应用或bundleName无效,则返回false。 | 133e41f4b71Sopenharmony_ci 134e41f4b71Sopenharmony_ci**错误码**: 135e41f4b71Sopenharmony_ci 136e41f4b71Sopenharmony_ci以下错误码的详细介绍请参见[设备信息使用统计错误码](errorcode-DeviceUsageStatistics.md)和[通用错误码](../errorcode-universal.md)。 137e41f4b71Sopenharmony_ci 138e41f4b71Sopenharmony_ci| 错误码ID | 错误信息 | 139e41f4b71Sopenharmony_ci| ---- | --------------------- | 140e41f4b71Sopenharmony_ci| 201 | Permission denied. | 141e41f4b71Sopenharmony_ci| 202 | Not System App. | 142e41f4b71Sopenharmony_ci| 401 | Parameter error. | 143e41f4b71Sopenharmony_ci| 801 | Capability not supported.| 144e41f4b71Sopenharmony_ci| 10000001 | Memory operation failed. | 145e41f4b71Sopenharmony_ci| 10000002 | Parcel operation failed. | 146e41f4b71Sopenharmony_ci| 10000003 | System service operation failed. | 147e41f4b71Sopenharmony_ci| 10000004 | IPC failed. | 148e41f4b71Sopenharmony_ci| 10000006 | Failed to get the application information. | 149e41f4b71Sopenharmony_ci 150e41f4b71Sopenharmony_ci**示例**: 151e41f4b71Sopenharmony_ci```ts 152e41f4b71Sopenharmony_cilet isIdleState: boolean = usageStatistics.isIdleStateSync("com.ohos.camera"); 153e41f4b71Sopenharmony_ci``` 154e41f4b71Sopenharmony_ci 155e41f4b71Sopenharmony_ci## usageStatistics.queryAppGroup 156e41f4b71Sopenharmony_ci 157e41f4b71Sopenharmony_ciqueryAppGroup(): Promise<number> 158e41f4b71Sopenharmony_ci 159e41f4b71Sopenharmony_ci查询当前应用的优先级分组,使用Promise异步回调。 160e41f4b71Sopenharmony_ci 161e41f4b71Sopenharmony_ci**需要权限**:ohos.permission.BUNDLE_ACTIVE_INFO 162e41f4b71Sopenharmony_ci 163e41f4b71Sopenharmony_ci**系统能力**:SystemCapability.ResourceSchedule.UsageStatistics.AppGroup 164e41f4b71Sopenharmony_ci 165e41f4b71Sopenharmony_ci**返回值**: 166e41f4b71Sopenharmony_ci 167e41f4b71Sopenharmony_ci| 类型 | 说明 | 168e41f4b71Sopenharmony_ci| --------------- | --------------------------- | 169e41f4b71Sopenharmony_ci| Promise<number> | Promise对象。返回当前应用优先级分组结果,值越小,优先级越高。 | 170e41f4b71Sopenharmony_ci 171e41f4b71Sopenharmony_ci**错误码**: 172e41f4b71Sopenharmony_ci 173e41f4b71Sopenharmony_ci以下错误码的详细介绍请参见[设备信息使用统计错误码](errorcode-DeviceUsageStatistics.md)和[通用错误码](../errorcode-universal.md)。 174e41f4b71Sopenharmony_ci 175e41f4b71Sopenharmony_ci| 错误码ID | 错误信息 | 176e41f4b71Sopenharmony_ci| ---- | --------------------- | 177e41f4b71Sopenharmony_ci| 201 | Permission denied. | 178e41f4b71Sopenharmony_ci| 202 | Not System App. | 179e41f4b71Sopenharmony_ci| 401 | Parameter error. | 180e41f4b71Sopenharmony_ci| 801 | Capability not supported.| 181e41f4b71Sopenharmony_ci| 10000001 | Memory operation failed. | 182e41f4b71Sopenharmony_ci| 10000002 | Parcel operation failed. | 183e41f4b71Sopenharmony_ci| 10000003 | System service operation failed. | 184e41f4b71Sopenharmony_ci| 10000004 | IPC failed. | 185e41f4b71Sopenharmony_ci| 10000005 | Application is not installed. | 186e41f4b71Sopenharmony_ci| 10000006 | Failed to get the application information. | 187e41f4b71Sopenharmony_ci| 10100002 | Failed to get the application group information. | 188e41f4b71Sopenharmony_ci 189e41f4b71Sopenharmony_ci**示例**: 190e41f4b71Sopenharmony_ci 191e41f4b71Sopenharmony_ci```ts 192e41f4b71Sopenharmony_ciimport { BusinessError } from '@kit.BasicServicesKit'; 193e41f4b71Sopenharmony_ci 194e41f4b71Sopenharmony_ciusageStatistics.queryAppGroup().then((res: number) => { 195e41f4b71Sopenharmony_ci console.log('BUNDLE_ACTIVE queryAppGroup promise succeeded. result: ' + JSON.stringify(res)); 196e41f4b71Sopenharmony_ci}).catch((err: BusinessError) => { 197e41f4b71Sopenharmony_ci console.log('BUNDLE_ACTIVE queryAppGroup promise failed. code is: ' + err.code + ',message is: ' + err.message); 198e41f4b71Sopenharmony_ci}); 199e41f4b71Sopenharmony_ci``` 200e41f4b71Sopenharmony_ci 201e41f4b71Sopenharmony_ci## usageStatistics.queryAppGroup 202e41f4b71Sopenharmony_ci 203e41f4b71Sopenharmony_ciqueryAppGroup(callback: AsyncCallback<number>): void 204e41f4b71Sopenharmony_ci 205e41f4b71Sopenharmony_ci查询当前应用的优先级分组,使用Callback异步回调。 206e41f4b71Sopenharmony_ci 207e41f4b71Sopenharmony_ci**需要权限**:ohos.permission.BUNDLE_ACTIVE_INFO 208e41f4b71Sopenharmony_ci 209e41f4b71Sopenharmony_ci**系统能力**:SystemCapability.ResourceSchedule.UsageStatistics.AppGroup 210e41f4b71Sopenharmony_ci 211e41f4b71Sopenharmony_ci**参数**: 212e41f4b71Sopenharmony_ci 213e41f4b71Sopenharmony_ci| 参数名 | 类型 | 必填 | 说明 | 214e41f4b71Sopenharmony_ci| -------- | --------------------- | ---- | -------------------------- | 215e41f4b71Sopenharmony_ci| callback | AsyncCallback<number> | 是 | 回调函数,返回当前应用优先级分组结果,值越小,优先级越高。 | 216e41f4b71Sopenharmony_ci 217e41f4b71Sopenharmony_ci**错误码**: 218e41f4b71Sopenharmony_ci 219e41f4b71Sopenharmony_ci以下错误码的详细介绍请参见[设备信息使用统计错误码](errorcode-DeviceUsageStatistics.md)和[通用错误码](../errorcode-universal.md)。 220e41f4b71Sopenharmony_ci 221e41f4b71Sopenharmony_ci| 错误码ID | 错误信息 | 222e41f4b71Sopenharmony_ci| ---- | --------------------- | 223e41f4b71Sopenharmony_ci| 201 | Permission denied. | 224e41f4b71Sopenharmony_ci| 202 | Not System App. | 225e41f4b71Sopenharmony_ci| 401 | Parameter error. | 226e41f4b71Sopenharmony_ci| 801 | Capability not supported.| 227e41f4b71Sopenharmony_ci| 10000001 | Memory operation failed. | 228e41f4b71Sopenharmony_ci| 10000002 | Parcel operation failed. | 229e41f4b71Sopenharmony_ci| 10000003 | System service operation failed. | 230e41f4b71Sopenharmony_ci| 10000004 | IPC failed. | 231e41f4b71Sopenharmony_ci| 10000005 | Application is not installed. | 232e41f4b71Sopenharmony_ci| 10000006 | Failed to get the application information. | 233e41f4b71Sopenharmony_ci| 10100002 | Failed to get the application group information. | 234e41f4b71Sopenharmony_ci 235e41f4b71Sopenharmony_ci**示例**: 236e41f4b71Sopenharmony_ci 237e41f4b71Sopenharmony_ci```ts 238e41f4b71Sopenharmony_ciimport { BusinessError } from '@kit.BasicServicesKit'; 239e41f4b71Sopenharmony_ci 240e41f4b71Sopenharmony_ciusageStatistics.queryAppGroup((err: BusinessError, res: number) => { 241e41f4b71Sopenharmony_ci if(err) { 242e41f4b71Sopenharmony_ci console.log('BUNDLE_ACTIVE queryAppGroup callback failed. code is: ' + err.code + ',message is: ' + err.message); 243e41f4b71Sopenharmony_ci } else { 244e41f4b71Sopenharmony_ci console.log('BUNDLE_ACTIVE queryAppGroup callback succeeded. result: ' + JSON.stringify(res)); 245e41f4b71Sopenharmony_ci } 246e41f4b71Sopenharmony_ci}); 247e41f4b71Sopenharmony_ci``` 248e41f4b71Sopenharmony_ci 249e41f4b71Sopenharmony_ci## usageStatistics.queryAppGroupSync<sup>10+<sup> 250e41f4b71Sopenharmony_ci 251e41f4b71Sopenharmony_ciqueryAppGroupSync(): number 252e41f4b71Sopenharmony_ci 253e41f4b71Sopenharmony_ci查询当前应用的优先级分组,使用同步方式返回。 254e41f4b71Sopenharmony_ci 255e41f4b71Sopenharmony_ci**需要权限**:ohos.permission.BUNDLE_ACTIVE_INFO 256e41f4b71Sopenharmony_ci 257e41f4b71Sopenharmony_ci**系统能力**:SystemCapability.ResourceSchedule.UsageStatistics.AppGroup 258e41f4b71Sopenharmony_ci 259e41f4b71Sopenharmony_ci**返回值**: 260e41f4b71Sopenharmony_ci 261e41f4b71Sopenharmony_ci| 类型 | 说明 | 262e41f4b71Sopenharmony_ci| --------------- | --------------------------- | 263e41f4b71Sopenharmony_ci| number | 返回当前应用优先级分组结果,值越小,优先级越高。 | 264e41f4b71Sopenharmony_ci 265e41f4b71Sopenharmony_ci**错误码**: 266e41f4b71Sopenharmony_ci 267e41f4b71Sopenharmony_ci以下错误码的详细介绍请参见[设备信息使用统计错误码](errorcode-DeviceUsageStatistics.md)和[通用错误码](../errorcode-universal.md)。 268e41f4b71Sopenharmony_ci 269e41f4b71Sopenharmony_ci| 错误码ID | 错误信息 | 270e41f4b71Sopenharmony_ci| ---- | --------------------- | 271e41f4b71Sopenharmony_ci| 201 | Permission denied. | 272e41f4b71Sopenharmony_ci| 202 | Not System App. | 273e41f4b71Sopenharmony_ci| 401 | Parameter error. | 274e41f4b71Sopenharmony_ci| 801 | Capability not supported.| 275e41f4b71Sopenharmony_ci| 10000001 | Memory operation failed. | 276e41f4b71Sopenharmony_ci| 10000002 | Parcel operation failed. | 277e41f4b71Sopenharmony_ci| 10000003 | System service operation failed. | 278e41f4b71Sopenharmony_ci| 10000004 | IPC failed. | 279e41f4b71Sopenharmony_ci| 10000005 | Application is not installed. | 280e41f4b71Sopenharmony_ci| 10000006 | Failed to get the application information. | 281e41f4b71Sopenharmony_ci| 10100002 | Failed to get the application group information. | 282e41f4b71Sopenharmony_ci 283e41f4b71Sopenharmony_ci**示例**: 284e41f4b71Sopenharmony_ci 285e41f4b71Sopenharmony_ci```ts 286e41f4b71Sopenharmony_cilet priorityGroup: number = usageStatistics.queryAppGroupSync(); 287e41f4b71Sopenharmony_ci``` 288e41f4b71Sopenharmony_ci 289e41f4b71Sopenharmony_ci## usageStatistics.queryAppGroup 290e41f4b71Sopenharmony_ci 291e41f4b71Sopenharmony_ciqueryAppGroup(bundleName : string): Promise<number> 292e41f4b71Sopenharmony_ci 293e41f4b71Sopenharmony_ci查询指定bundleName应用的优先级分组,使用Promise异步回调。 294e41f4b71Sopenharmony_ci 295e41f4b71Sopenharmony_ci**需要权限**:ohos.permission.BUNDLE_ACTIVE_INFO 296e41f4b71Sopenharmony_ci 297e41f4b71Sopenharmony_ci**系统能力**:SystemCapability.ResourceSchedule.UsageStatistics.AppGroup 298e41f4b71Sopenharmony_ci 299e41f4b71Sopenharmony_ci**参数**: 300e41f4b71Sopenharmony_ci 301e41f4b71Sopenharmony_ci| 参数名 | 类型 | 必填 | 说明 | 302e41f4b71Sopenharmony_ci| ---------- | ------ | ---- | ---------------------------------------- | 303e41f4b71Sopenharmony_ci| bundleName | string | 是 | 应用的bundleName。 | 304e41f4b71Sopenharmony_ci 305e41f4b71Sopenharmony_ci**返回值**: 306e41f4b71Sopenharmony_ci 307e41f4b71Sopenharmony_ci| 类型 | 说明 | 308e41f4b71Sopenharmony_ci| --------------- | --------------------------- | 309e41f4b71Sopenharmony_ci| Promise<number> | Promise对象。返回指定应用的优先级分组结果,值越小,优先级越高。 | 310e41f4b71Sopenharmony_ci 311e41f4b71Sopenharmony_ci**错误码**: 312e41f4b71Sopenharmony_ci 313e41f4b71Sopenharmony_ci以下错误码的详细介绍请参见[设备信息使用统计错误码](errorcode-DeviceUsageStatistics.md)和[通用错误码](../errorcode-universal.md)。 314e41f4b71Sopenharmony_ci 315e41f4b71Sopenharmony_ci| 错误码ID | 错误信息 | 316e41f4b71Sopenharmony_ci| ---- | --------------------- | 317e41f4b71Sopenharmony_ci| 201 | Permission denied. | 318e41f4b71Sopenharmony_ci| 202 | Not System App. | 319e41f4b71Sopenharmony_ci| 401 | Parameter error. | 320e41f4b71Sopenharmony_ci| 801 | Capability not supported.| 321e41f4b71Sopenharmony_ci| 10000001 | Memory operation failed. | 322e41f4b71Sopenharmony_ci| 10000002 | Parcel operation failed. | 323e41f4b71Sopenharmony_ci| 10000003 | System service operation failed. | 324e41f4b71Sopenharmony_ci| 10000004 | IPC failed. | 325e41f4b71Sopenharmony_ci| 10000005 | Application is not installed. | 326e41f4b71Sopenharmony_ci| 10000006 | Failed to get the application information. | 327e41f4b71Sopenharmony_ci| 10100002 | Failed to get the application group information. | 328e41f4b71Sopenharmony_ci 329e41f4b71Sopenharmony_ci**示例**: 330e41f4b71Sopenharmony_ci 331e41f4b71Sopenharmony_ci```javascript 332e41f4b71Sopenharmony_ci//有bundleName的promise 333e41f4b71Sopenharmony_ciimport { BusinessError } from '@kit.BasicServicesKit'; 334e41f4b71Sopenharmony_ci 335e41f4b71Sopenharmony_cilet bundleName: string = "com.ohos.camera"; 336e41f4b71Sopenharmony_ciusageStatistics.queryAppGroup(bundleName).then((res: number) => { 337e41f4b71Sopenharmony_ci console.log('BUNDLE_ACTIVE queryAppGroup promise succeeded. result: ' + JSON.stringify(res)); 338e41f4b71Sopenharmony_ci}).catch((err: BusinessError) => { 339e41f4b71Sopenharmony_ci console.log('BUNDLE_ACTIVE queryAppGroup promise failed. code is: ' + err.code + ',message is: ' + err.message); 340e41f4b71Sopenharmony_ci}); 341e41f4b71Sopenharmony_ci``` 342e41f4b71Sopenharmony_ci 343e41f4b71Sopenharmony_ci## usageStatistics.queryAppGroup 344e41f4b71Sopenharmony_ci 345e41f4b71Sopenharmony_ciqueryAppGroup(bundleName : string, callback: AsyncCallback<number>): void 346e41f4b71Sopenharmony_ci 347e41f4b71Sopenharmony_ci查询指定bundleName应用的优先级分组,使用Callback异步回调。 348e41f4b71Sopenharmony_ci 349e41f4b71Sopenharmony_ci**需要权限**:ohos.permission.BUNDLE_ACTIVE_INFO 350e41f4b71Sopenharmony_ci 351e41f4b71Sopenharmony_ci**系统能力**:SystemCapability.ResourceSchedule.UsageStatistics.AppGroup 352e41f4b71Sopenharmony_ci 353e41f4b71Sopenharmony_ci**参数**: 354e41f4b71Sopenharmony_ci 355e41f4b71Sopenharmony_ci| 参数名 | 类型 | 必填 | 说明 | 356e41f4b71Sopenharmony_ci| ---------- | --------------------- | ---- | ---------------------------------------- | 357e41f4b71Sopenharmony_ci| bundleName | string | 是 | 应用的bundleName。 | 358e41f4b71Sopenharmony_ci| callback | AsyncCallback<number> | 是 | 回调函数,返回指定应用的优先级分组结果,值越小,优先级越高。| 359e41f4b71Sopenharmony_ci 360e41f4b71Sopenharmony_ci**错误码**: 361e41f4b71Sopenharmony_ci 362e41f4b71Sopenharmony_ci以下错误码的详细介绍请参见[设备信息使用统计错误码](errorcode-DeviceUsageStatistics.md)和[通用错误码](../errorcode-universal.md)。 363e41f4b71Sopenharmony_ci 364e41f4b71Sopenharmony_ci| 错误码ID | 错误信息 | 365e41f4b71Sopenharmony_ci| ---- | --------------------- | 366e41f4b71Sopenharmony_ci| 201 | Permission denied. | 367e41f4b71Sopenharmony_ci| 202 | Not System App. | 368e41f4b71Sopenharmony_ci| 401 | Parameter error. | 369e41f4b71Sopenharmony_ci| 801 | Capability not supported.| 370e41f4b71Sopenharmony_ci| 10000001 | Memory operation failed. | 371e41f4b71Sopenharmony_ci| 10000002 | Parcel operation failed. | 372e41f4b71Sopenharmony_ci| 10000003 | System service operation failed. | 373e41f4b71Sopenharmony_ci| 10000004 | IPC failed. | 374e41f4b71Sopenharmony_ci| 10000005 | Application is not installed. | 375e41f4b71Sopenharmony_ci| 10000006 | Failed to get the application information. | 376e41f4b71Sopenharmony_ci| 10100002 | Failed to get the application group information. | 377e41f4b71Sopenharmony_ci 378e41f4b71Sopenharmony_ci**示例**: 379e41f4b71Sopenharmony_ci 380e41f4b71Sopenharmony_ci```ts 381e41f4b71Sopenharmony_ciimport { BusinessError } from '@kit.BasicServicesKit'; 382e41f4b71Sopenharmony_ci 383e41f4b71Sopenharmony_cilet bundleName: string = "com.ohos.camera"; 384e41f4b71Sopenharmony_ciusageStatistics.queryAppGroup(bundleName, (err: BusinessError, res: number) => { 385e41f4b71Sopenharmony_ci if(err) { 386e41f4b71Sopenharmony_ci console.log('BUNDLE_ACTIVE queryAppGroup callback failed. code is: ' + err.code + ',message is: ' + err.message); 387e41f4b71Sopenharmony_ci } else { 388e41f4b71Sopenharmony_ci console.log('BUNDLE_ACTIVE queryAppGroup callback succeeded. result: ' + JSON.stringify(res)); 389e41f4b71Sopenharmony_ci } 390e41f4b71Sopenharmony_ci}); 391e41f4b71Sopenharmony_ci``` 392e41f4b71Sopenharmony_ci 393e41f4b71Sopenharmony_ci## usageStatistics.queryAppGroupSync<sup>10+<sup> 394e41f4b71Sopenharmony_ci 395e41f4b71Sopenharmony_ciqueryAppGroupSync(bundleName: string): number 396e41f4b71Sopenharmony_ci 397e41f4b71Sopenharmony_ci查询指定bundleName应用的优先级分组,使用同步方式返回。 398e41f4b71Sopenharmony_ci 399e41f4b71Sopenharmony_ci**需要权限**:ohos.permission.BUNDLE_ACTIVE_INFO 400e41f4b71Sopenharmony_ci 401e41f4b71Sopenharmony_ci**系统能力**:SystemCapability.ResourceSchedule.UsageStatistics.AppGroup 402e41f4b71Sopenharmony_ci 403e41f4b71Sopenharmony_ci**参数**: 404e41f4b71Sopenharmony_ci 405e41f4b71Sopenharmony_ci| 参数名 | 类型 | 必填 | 说明 | 406e41f4b71Sopenharmony_ci| ---------- | ---------------------------- | ---- | ---------------------------------------- | 407e41f4b71Sopenharmony_ci| bundleName | string | 是 | 应用的bundleName。 | 408e41f4b71Sopenharmony_ci 409e41f4b71Sopenharmony_ci**返回值**: 410e41f4b71Sopenharmony_ci 411e41f4b71Sopenharmony_ci| 类型 | 说明 | 412e41f4b71Sopenharmony_ci| --------------- | --------------------------- | 413e41f4b71Sopenharmony_ci| number | 返回应用的优先级分组结果,值越小,优先级越高。 | 414e41f4b71Sopenharmony_ci 415e41f4b71Sopenharmony_ci**错误码**: 416e41f4b71Sopenharmony_ci 417e41f4b71Sopenharmony_ci以下错误码的详细介绍请参见[设备信息使用统计错误码](errorcode-DeviceUsageStatistics.md)和[通用错误码](../errorcode-universal.md)。 418e41f4b71Sopenharmony_ci 419e41f4b71Sopenharmony_ci| 错误码ID | 错误信息 | 420e41f4b71Sopenharmony_ci| ---- | --------------------- | 421e41f4b71Sopenharmony_ci| 201 | Permission denied. | 422e41f4b71Sopenharmony_ci| 202 | Not System App. | 423e41f4b71Sopenharmony_ci| 401 | Parameter error. | 424e41f4b71Sopenharmony_ci| 801 | Capability not supported.| 425e41f4b71Sopenharmony_ci| 10000001 | Memory operation failed. | 426e41f4b71Sopenharmony_ci| 10000002 | Parcel operation failed. | 427e41f4b71Sopenharmony_ci| 10000003 | System service operation failed. | 428e41f4b71Sopenharmony_ci| 10000004 | IPC failed. | 429e41f4b71Sopenharmony_ci| 10000005 | Application is not installed. | 430e41f4b71Sopenharmony_ci| 10000006 | Failed to get the application information. | 431e41f4b71Sopenharmony_ci| 10100002 | Failed to get the application group information. | 432e41f4b71Sopenharmony_ci 433e41f4b71Sopenharmony_ci**示例**: 434e41f4b71Sopenharmony_ci 435e41f4b71Sopenharmony_ci```ts 436e41f4b71Sopenharmony_cilet priorityGroup: number = usageStatistics.queryAppGroupSync("com.ohos.camera"); 437e41f4b71Sopenharmony_ci``` 438e41f4b71Sopenharmony_ci 439e41f4b71Sopenharmony_ci## usageStatistics.setAppGroup 440e41f4b71Sopenharmony_ci 441e41f4b71Sopenharmony_cisetAppGroup(bundleName: string, newGroup: GroupType): Promise<void> 442e41f4b71Sopenharmony_ci 443e41f4b71Sopenharmony_ci将指定bundleName应用的分组设置为newGroup,仅支持当前应用为其他应用设置,使用Promise异步回调。 444e41f4b71Sopenharmony_ci 445e41f4b71Sopenharmony_ci**需要权限**:ohos.permission.BUNDLE_ACTIVE_INFO 446e41f4b71Sopenharmony_ci 447e41f4b71Sopenharmony_ci**系统能力**:SystemCapability.ResourceSchedule.UsageStatistics.AppGroup 448e41f4b71Sopenharmony_ci 449e41f4b71Sopenharmony_ci**参数**: 450e41f4b71Sopenharmony_ci 451e41f4b71Sopenharmony_ci| 参数名 | 类型 | 必填 | 说明 | 452e41f4b71Sopenharmony_ci| ---------- | --------- | ---- | ---- | 453e41f4b71Sopenharmony_ci| bundleName | string | 是 | 应用的bundleName。 | 454e41f4b71Sopenharmony_ci| newGroup | [GroupType](#grouptype) | 是 | 应用分组类型。 | 455e41f4b71Sopenharmony_ci 456e41f4b71Sopenharmony_ci**返回值**: 457e41f4b71Sopenharmony_ci 458e41f4b71Sopenharmony_ci| 类型 | 说明 | 459e41f4b71Sopenharmony_ci| ------------- | ------------------------- | 460e41f4b71Sopenharmony_ci| Promise<void> | 无返回结果的Promise对象。 | 461e41f4b71Sopenharmony_ci 462e41f4b71Sopenharmony_ci**错误码**: 463e41f4b71Sopenharmony_ci 464e41f4b71Sopenharmony_ci以下错误码的详细介绍请参见[设备信息使用统计错误码](errorcode-DeviceUsageStatistics.md)和[通用错误码](../errorcode-universal.md)。 465e41f4b71Sopenharmony_ci 466e41f4b71Sopenharmony_ci| 错误码ID | 错误信息 | 467e41f4b71Sopenharmony_ci| ---- | --------------------- | 468e41f4b71Sopenharmony_ci| 201 | Permission denied. | 469e41f4b71Sopenharmony_ci| 202 | Not System App. | 470e41f4b71Sopenharmony_ci| 401 | Parameter error. | 471e41f4b71Sopenharmony_ci| 801 | Capability not supported.| 472e41f4b71Sopenharmony_ci| 10000001 | Memory operation failed. | 473e41f4b71Sopenharmony_ci| 10000002 | Parcel operation failed. | 474e41f4b71Sopenharmony_ci| 10000003 | System service operation failed. | 475e41f4b71Sopenharmony_ci| 10000004 | IPC failed. | 476e41f4b71Sopenharmony_ci| 10000006 | Failed to get the application information. | 477e41f4b71Sopenharmony_ci| 10100001 | Repeated operation on the application group. | 478e41f4b71Sopenharmony_ci 479e41f4b71Sopenharmony_ci**示例**: 480e41f4b71Sopenharmony_ci 481e41f4b71Sopenharmony_ci```ts 482e41f4b71Sopenharmony_ciimport { BusinessError } from '@kit.BasicServicesKit'; 483e41f4b71Sopenharmony_ci 484e41f4b71Sopenharmony_cilet bundleName: string = "com.example.deviceUsageStatistics"; 485e41f4b71Sopenharmony_cilet newGroup = usageStatistics.GroupType.DAILY_GROUP; 486e41f4b71Sopenharmony_ci 487e41f4b71Sopenharmony_ciusageStatistics.setAppGroup(bundleName, newGroup).then( () => { 488e41f4b71Sopenharmony_ci console.log('BUNDLE_ACTIVE setAppGroup promise succeeded.'); 489e41f4b71Sopenharmony_ci}).catch((err: BusinessError) => { 490e41f4b71Sopenharmony_ci console.log('BUNDLE_ACTIVE setAppGroup promise failed. code is: ' + err.code + ',message is: ' + err.message); 491e41f4b71Sopenharmony_ci}); 492e41f4b71Sopenharmony_ci``` 493e41f4b71Sopenharmony_ci 494e41f4b71Sopenharmony_ci## usageStatistics.setAppGroup 495e41f4b71Sopenharmony_ci 496e41f4b71Sopenharmony_cisetAppGroup(bundleName: string, newGroup: GroupType, callback: AsyncCallback<void>): void 497e41f4b71Sopenharmony_ci 498e41f4b71Sopenharmony_ci将指定bundleName应用的分组设置为newGroup,仅支持当前应用为其他应用设置,使用CallBack异步回调。 499e41f4b71Sopenharmony_ci 500e41f4b71Sopenharmony_ci**需要权限**:ohos.permission.BUNDLE_ACTIVE_INFO 501e41f4b71Sopenharmony_ci 502e41f4b71Sopenharmony_ci**系统能力**:SystemCapability.ResourceSchedule.UsageStatistics.AppGroup 503e41f4b71Sopenharmony_ci 504e41f4b71Sopenharmony_ci**参数**: 505e41f4b71Sopenharmony_ci 506e41f4b71Sopenharmony_ci| 参数名 | 类型 | 必填 | 说明 | 507e41f4b71Sopenharmony_ci| ---------- | ------------------- | ---- | ------------------------- | 508e41f4b71Sopenharmony_ci| bundleName | string | 是 | 应用的bundleName。 | 509e41f4b71Sopenharmony_ci| newGroup | [GroupType](#grouptype) | 是 | 应用分组类型。 | 510e41f4b71Sopenharmony_ci| callback | AsyncCallback<void> | 是 | 回调函数,返回是否设置成功。 | 511e41f4b71Sopenharmony_ci 512e41f4b71Sopenharmony_ci**错误码**: 513e41f4b71Sopenharmony_ci 514e41f4b71Sopenharmony_ci以下错误码的详细介绍请参见[设备信息使用统计错误码](errorcode-DeviceUsageStatistics.md)和[通用错误码](../errorcode-universal.md)。 515e41f4b71Sopenharmony_ci 516e41f4b71Sopenharmony_ci| 错误码ID | 错误信息 | 517e41f4b71Sopenharmony_ci| ---- | --------------------- | 518e41f4b71Sopenharmony_ci| 201 | Permission denied. | 519e41f4b71Sopenharmony_ci| 202 | Not System App. | 520e41f4b71Sopenharmony_ci| 401 | Parameter error. | 521e41f4b71Sopenharmony_ci| 801 | Capability not supported.| 522e41f4b71Sopenharmony_ci| 10000001 | Memory operation failed. | 523e41f4b71Sopenharmony_ci| 10000002 | Parcel operation failed. | 524e41f4b71Sopenharmony_ci| 10000003 | System service operation failed. | 525e41f4b71Sopenharmony_ci| 10000004 | IPC failed. | 526e41f4b71Sopenharmony_ci| 10000006 | Failed to get the application information. | 527e41f4b71Sopenharmony_ci| 10100001 | Repeated operation on the application group. | 528e41f4b71Sopenharmony_ci 529e41f4b71Sopenharmony_ci**示例**: 530e41f4b71Sopenharmony_ci 531e41f4b71Sopenharmony_ci```ts 532e41f4b71Sopenharmony_ciimport { BusinessError } from '@kit.BasicServicesKit'; 533e41f4b71Sopenharmony_ci 534e41f4b71Sopenharmony_cilet bundleName: string = "com.example.deviceUsageStatistics"; 535e41f4b71Sopenharmony_cilet newGroup = usageStatistics.GroupType.DAILY_GROUP; 536e41f4b71Sopenharmony_ci 537e41f4b71Sopenharmony_ciusageStatistics.setAppGroup(bundleName, newGroup, (err: BusinessError) => { 538e41f4b71Sopenharmony_ci if(err) { 539e41f4b71Sopenharmony_ci console.log('BUNDLE_ACTIVE setAppGroup callback failed. code is: ' + err.code + ',message is: ' + err.message); 540e41f4b71Sopenharmony_ci } else { 541e41f4b71Sopenharmony_ci console.log('BUNDLE_ACTIVE setAppGroup callback succeeded.'); 542e41f4b71Sopenharmony_ci } 543e41f4b71Sopenharmony_ci}); 544e41f4b71Sopenharmony_ci``` 545e41f4b71Sopenharmony_ci 546e41f4b71Sopenharmony_ci## usageStatistics.queryBundleStatsInfos 547e41f4b71Sopenharmony_ci 548e41f4b71Sopenharmony_ciqueryBundleStatsInfos(begin: number, end: number, callback: AsyncCallback<BundleStatsMap>): void 549e41f4b71Sopenharmony_ci 550e41f4b71Sopenharmony_ci通过指定起始和结束时间,查询应用使用时长的具体信息,统计的最小颗粒度是天,使用Callback异步回调。 551e41f4b71Sopenharmony_ci 552e41f4b71Sopenharmony_ci**需要权限**:ohos.permission.BUNDLE_ACTIVE_INFO 553e41f4b71Sopenharmony_ci 554e41f4b71Sopenharmony_ci**系统能力**:SystemCapability.ResourceSchedule.UsageStatistics.App 555e41f4b71Sopenharmony_ci 556e41f4b71Sopenharmony_ci**参数**: 557e41f4b71Sopenharmony_ci 558e41f4b71Sopenharmony_ci| 参数名 | 类型 | 必填 | 说明 | 559e41f4b71Sopenharmony_ci| -------- | ---------------------------------------- | ---- | --------------------------------------- | 560e41f4b71Sopenharmony_ci| begin | number | 是 | 起始时间,以毫秒为单位。 | 561e41f4b71Sopenharmony_ci| end | number | 是 | 结束时间,以毫秒为单位。 | 562e41f4b71Sopenharmony_ci| callback | AsyncCallback<[BundleStatsMap](#bundlestatsmap)> | 是 | 回调函数,返回指定时间段内应用使用时长的具体信息。 | 563e41f4b71Sopenharmony_ci 564e41f4b71Sopenharmony_ci**错误码**: 565e41f4b71Sopenharmony_ci 566e41f4b71Sopenharmony_ci以下错误码的详细介绍请参见[设备信息使用统计错误码](errorcode-DeviceUsageStatistics.md)和[通用错误码](../errorcode-universal.md)。 567e41f4b71Sopenharmony_ci 568e41f4b71Sopenharmony_ci| 错误码ID | 错误信息 | 569e41f4b71Sopenharmony_ci| ---- | --------------------- | 570e41f4b71Sopenharmony_ci| 201 | Permission denied. | 571e41f4b71Sopenharmony_ci| 202 | Not System App. | 572e41f4b71Sopenharmony_ci| 401 | Parameter error. | 573e41f4b71Sopenharmony_ci| 801 | Capability not supported.| 574e41f4b71Sopenharmony_ci| 10000001 | Memory operation failed. | 575e41f4b71Sopenharmony_ci| 10000002 | Parcel operation failed. | 576e41f4b71Sopenharmony_ci| 10000003 | System service operation failed. | 577e41f4b71Sopenharmony_ci| 10000004 | IPC failed. | 578e41f4b71Sopenharmony_ci| 10000006 | Failed to get the application information. | 579e41f4b71Sopenharmony_ci| 10000007 | Failed to get the system time. | 580e41f4b71Sopenharmony_ci 581e41f4b71Sopenharmony_ci**示例**: 582e41f4b71Sopenharmony_ci 583e41f4b71Sopenharmony_ci```ts 584e41f4b71Sopenharmony_ciimport { BusinessError } from '@kit.BasicServicesKit'; 585e41f4b71Sopenharmony_ci 586e41f4b71Sopenharmony_ciusageStatistics.queryBundleStatsInfos(0, 20000000000000, (err: BusinessError, res:usageStatistics.BundleStatsMap) => { 587e41f4b71Sopenharmony_ci if (err) { 588e41f4b71Sopenharmony_ci console.log('BUNDLE_ACTIVE queryBundleStatsInfos callback failed. code is: ' + err.code + ',message is: ' + err.message); 589e41f4b71Sopenharmony_ci } else { 590e41f4b71Sopenharmony_ci console.log('BUNDLE_ACTIVE queryBundleStatsInfos callback success.'); 591e41f4b71Sopenharmony_ci console.log('BUNDLE_ACTIVE queryBundleStatsInfos callback result ' + JSON.stringify(res)); 592e41f4b71Sopenharmony_ci } 593e41f4b71Sopenharmony_ci}); 594e41f4b71Sopenharmony_ci``` 595e41f4b71Sopenharmony_ci 596e41f4b71Sopenharmony_ci## usageStatistics.queryBundleStatsInfos 597e41f4b71Sopenharmony_ci 598e41f4b71Sopenharmony_ciqueryBundleStatsInfos(begin: number, end: number): Promise<BundleStatsMap> 599e41f4b71Sopenharmony_ci 600e41f4b71Sopenharmony_ci通过指定起始和结束时间,查询应用使用时长的具体信息,统计的最小颗粒度是天,使用Promise异步回调。 601e41f4b71Sopenharmony_ci 602e41f4b71Sopenharmony_ci**需要权限**:ohos.permission.BUNDLE_ACTIVE_INFO 603e41f4b71Sopenharmony_ci 604e41f4b71Sopenharmony_ci**系统能力**:SystemCapability.ResourceSchedule.UsageStatistics.App 605e41f4b71Sopenharmony_ci 606e41f4b71Sopenharmony_ci**参数**: 607e41f4b71Sopenharmony_ci 608e41f4b71Sopenharmony_ci| 参数名 | 类型 | 必填 | 说明 | 609e41f4b71Sopenharmony_ci| ----- | ------ | ---- | ----- | 610e41f4b71Sopenharmony_ci| begin | number | 是 | 起始时间,以毫秒为单位。 | 611e41f4b71Sopenharmony_ci| end | number | 是 | 结束时间,以毫秒为单位。 | 612e41f4b71Sopenharmony_ci 613e41f4b71Sopenharmony_ci**返回值**: 614e41f4b71Sopenharmony_ci 615e41f4b71Sopenharmony_ci| 类型 | 说明 | 616e41f4b71Sopenharmony_ci| ---------------------------------------- | -------------------------------------- | 617e41f4b71Sopenharmony_ci| Promise<[BundleStatsMap](#bundlestatsmap)> | Promise对象。返回指定时间段内应用使用时长的具体信息。 | 618e41f4b71Sopenharmony_ci 619e41f4b71Sopenharmony_ci**错误码**: 620e41f4b71Sopenharmony_ci 621e41f4b71Sopenharmony_ci以下错误码的详细介绍请参见[设备信息使用统计错误码](errorcode-DeviceUsageStatistics.md)和[通用错误码](../errorcode-universal.md)。 622e41f4b71Sopenharmony_ci 623e41f4b71Sopenharmony_ci| 错误码ID | 错误信息 | 624e41f4b71Sopenharmony_ci| ---- | --------------------- | 625e41f4b71Sopenharmony_ci| 201 | Permission denied. | 626e41f4b71Sopenharmony_ci| 202 | Not System App. | 627e41f4b71Sopenharmony_ci| 401 | Parameter error. | 628e41f4b71Sopenharmony_ci| 801 | Capability not supported.| 629e41f4b71Sopenharmony_ci| 10000001 | Memory operation failed. | 630e41f4b71Sopenharmony_ci| 10000002 | Parcel operation failed. | 631e41f4b71Sopenharmony_ci| 10000003 | System service operation failed. | 632e41f4b71Sopenharmony_ci| 10000004 | IPC failed. | 633e41f4b71Sopenharmony_ci| 10000006 | Failed to get the application information. | 634e41f4b71Sopenharmony_ci| 10000007 | Failed to get the system time. | 635e41f4b71Sopenharmony_ci 636e41f4b71Sopenharmony_ci**示例**: 637e41f4b71Sopenharmony_ci 638e41f4b71Sopenharmony_ci```ts 639e41f4b71Sopenharmony_ciimport { BusinessError } from '@kit.BasicServicesKit'; 640e41f4b71Sopenharmony_ci 641e41f4b71Sopenharmony_ciusageStatistics.queryBundleStatsInfos(0, 20000000000000).then((res:usageStatistics.BundleStatsMap) => { 642e41f4b71Sopenharmony_ci console.log('BUNDLE_ACTIVE queryBundleStatsInfos promise success.'); 643e41f4b71Sopenharmony_ci console.log('BUNDLE_ACTIVE queryBundleStatsInfos promise result ' + JSON.stringify(res)); 644e41f4b71Sopenharmony_ci}).catch((err: BusinessError) => { 645e41f4b71Sopenharmony_ci console.log('BUNDLE_ACTIVE queryBundleStatsInfos promise failed. code is: ' + err.code + ',message is: ' + err.message); 646e41f4b71Sopenharmony_ci}); 647e41f4b71Sopenharmony_ci``` 648e41f4b71Sopenharmony_ci 649e41f4b71Sopenharmony_ci## usageStatistics.queryBundleStatsInfoByInterval 650e41f4b71Sopenharmony_ci 651e41f4b71Sopenharmony_ciqueryBundleStatsInfoByInterval(byInterval: IntervalType, begin: number, end: number, callback: AsyncCallback<Array<BundleStatsInfo>>): void 652e41f4b71Sopenharmony_ci 653e41f4b71Sopenharmony_ci通过指定时间段间隔(天、周、月、年),查询应用使用时长的统计信息,使用Callback异步回调。 654e41f4b71Sopenharmony_ci 655e41f4b71Sopenharmony_ci**需要权限**:ohos.permission.BUNDLE_ACTIVE_INFO 656e41f4b71Sopenharmony_ci 657e41f4b71Sopenharmony_ci**系统能力**:SystemCapability.ResourceSchedule.UsageStatistics.App 658e41f4b71Sopenharmony_ci 659e41f4b71Sopenharmony_ci**参数**: 660e41f4b71Sopenharmony_ci 661e41f4b71Sopenharmony_ci| 参数名 | 类型 | 必填 | 说明 | 662e41f4b71Sopenharmony_ci| ---------- | ---------------------------------------- | ---- | ---------------------------------------- | 663e41f4b71Sopenharmony_ci| byInterval | [IntervalType](#intervaltype) | 是 | 查询类型。 | 664e41f4b71Sopenharmony_ci| begin | number | 是 | 起始时间,以毫秒为单位。 | 665e41f4b71Sopenharmony_ci| end | number | 是 | 结束时间,以毫秒为单位。 | 666e41f4b71Sopenharmony_ci| callback | AsyncCallback<Array<[BundleStatsInfo](#bundlestatsinfo)>> | 是 | 回调函数,返回指定时间段间隔内,应用使用时长的统计信息。 | 667e41f4b71Sopenharmony_ci 668e41f4b71Sopenharmony_ci**错误码**: 669e41f4b71Sopenharmony_ci 670e41f4b71Sopenharmony_ci以下错误码的详细介绍请参见[设备信息使用统计错误码](errorcode-DeviceUsageStatistics.md)和[通用错误码](../errorcode-universal.md)。 671e41f4b71Sopenharmony_ci 672e41f4b71Sopenharmony_ci| 错误码ID | 错误信息 | 673e41f4b71Sopenharmony_ci| ---- | --------------------- | 674e41f4b71Sopenharmony_ci| 201 | Permission denied. | 675e41f4b71Sopenharmony_ci| 202 | Not System App. | 676e41f4b71Sopenharmony_ci| 401 | Parameter error. | 677e41f4b71Sopenharmony_ci| 801 | Capability not supported.| 678e41f4b71Sopenharmony_ci| 10000001 | Memory operation failed. | 679e41f4b71Sopenharmony_ci| 10000002 | Parcel operation failed. | 680e41f4b71Sopenharmony_ci| 10000003 | System service operation failed. | 681e41f4b71Sopenharmony_ci| 10000004 | IPC failed. | 682e41f4b71Sopenharmony_ci| 10000006 | Failed to get the application information. | 683e41f4b71Sopenharmony_ci| 10000007 | Failed to get the system time. | 684e41f4b71Sopenharmony_ci 685e41f4b71Sopenharmony_ci**示例**: 686e41f4b71Sopenharmony_ci 687e41f4b71Sopenharmony_ci```ts 688e41f4b71Sopenharmony_ciimport { BusinessError } from '@kit.BasicServicesKit'; 689e41f4b71Sopenharmony_ci 690e41f4b71Sopenharmony_ciusageStatistics.queryBundleStatsInfoByInterval(0, 0, 20000000000000, (err: BusinessError, res: Array<usageStatistics.BundleStatsInfo>) => { 691e41f4b71Sopenharmony_ci if (err) { 692e41f4b71Sopenharmony_ci console.log('BUNDLE_ACTIVE queryBundleStatsInfoByInterval callback failed. code is: ' + err.code + ',message is: ' + err.message); 693e41f4b71Sopenharmony_ci } else { 694e41f4b71Sopenharmony_ci console.log('BUNDLE_ACTIVE queryBundleStatsInfoByInterval callback success.'); 695e41f4b71Sopenharmony_ci for (let i = 0; i < res.length; i++) { 696e41f4b71Sopenharmony_ci console.log('BUNDLE_ACTIVE queryBundleStatsInfoByInterval callback number : ' + (i + 1)); 697e41f4b71Sopenharmony_ci console.log('BUNDLE_ACTIVE queryBundleStatsInfoByInterval callback result ' + JSON.stringify(res[i])); 698e41f4b71Sopenharmony_ci } 699e41f4b71Sopenharmony_ci } 700e41f4b71Sopenharmony_ci}); 701e41f4b71Sopenharmony_ci``` 702e41f4b71Sopenharmony_ci 703e41f4b71Sopenharmony_ci## usageStatistics.queryBundleStatsInfoByInterval 704e41f4b71Sopenharmony_ci 705e41f4b71Sopenharmony_ciqueryBundleStatsInfoByInterval(byInterval: IntervalType, begin: number, end: number): Promise<Array<BundleStatsInfo>> 706e41f4b71Sopenharmony_ci 707e41f4b71Sopenharmony_ci通过指定时间段间隔(天、周、月、年),查询应用使用时长的统计信息,使用Promise异步回调。 708e41f4b71Sopenharmony_ci 709e41f4b71Sopenharmony_ci**需要权限**:ohos.permission.BUNDLE_ACTIVE_INFO 710e41f4b71Sopenharmony_ci 711e41f4b71Sopenharmony_ci**系统能力**:SystemCapability.ResourceSchedule.UsageStatistics.App 712e41f4b71Sopenharmony_ci 713e41f4b71Sopenharmony_ci**参数**: 714e41f4b71Sopenharmony_ci 715e41f4b71Sopenharmony_ci| 参数名 | 类型 | 必填 | 说明 | 716e41f4b71Sopenharmony_ci| ---------- | ----------------------------- | ---- | ----- | 717e41f4b71Sopenharmony_ci| byInterval | [IntervalType](#intervaltype) | 是 | 查询类型。 | 718e41f4b71Sopenharmony_ci| begin | number | 是 | 起始时间,以毫秒为单位。 | 719e41f4b71Sopenharmony_ci| end | number | 是 | 结束时间,以毫秒为单位。 | 720e41f4b71Sopenharmony_ci 721e41f4b71Sopenharmony_ci**返回值**: 722e41f4b71Sopenharmony_ci 723e41f4b71Sopenharmony_ci| 类型 | 说明 | 724e41f4b71Sopenharmony_ci| ---------------------------------------- | ---------------------------------------- | 725e41f4b71Sopenharmony_ci| Promise<Array<[BundleStatsInfo](#bundlestatsinfo)>> | Promise对象。返回指定时间段间隔内,应用使用时长的统计信息。 | 726e41f4b71Sopenharmony_ci 727e41f4b71Sopenharmony_ci**错误码**: 728e41f4b71Sopenharmony_ci 729e41f4b71Sopenharmony_ci以下错误码的详细介绍请参见[设备信息使用统计错误码](errorcode-DeviceUsageStatistics.md)和[通用错误码](../errorcode-universal.md)。 730e41f4b71Sopenharmony_ci 731e41f4b71Sopenharmony_ci| 错误码ID | 错误信息 | 732e41f4b71Sopenharmony_ci| ---- | --------------------- | 733e41f4b71Sopenharmony_ci| 201 | Permission denied. | 734e41f4b71Sopenharmony_ci| 202 | Not System App. | 735e41f4b71Sopenharmony_ci| 401 | Parameter error. | 736e41f4b71Sopenharmony_ci| 801 | Capability not supported.| 737e41f4b71Sopenharmony_ci| 10000001 | Memory operation failed. | 738e41f4b71Sopenharmony_ci| 10000002 | Parcel operation failed. | 739e41f4b71Sopenharmony_ci| 10000003 | System service operation failed. | 740e41f4b71Sopenharmony_ci| 10000004 | IPC failed. | 741e41f4b71Sopenharmony_ci| 10000006 | Failed to get the application information. | 742e41f4b71Sopenharmony_ci| 10000007 | Failed to get the system time. | 743e41f4b71Sopenharmony_ci 744e41f4b71Sopenharmony_ci**示例**: 745e41f4b71Sopenharmony_ci 746e41f4b71Sopenharmony_ci```ts 747e41f4b71Sopenharmony_ciimport { BusinessError } from '@kit.BasicServicesKit'; 748e41f4b71Sopenharmony_ci 749e41f4b71Sopenharmony_ciusageStatistics.queryBundleStatsInfoByInterval(0, 0, 20000000000000).then((res: Array<usageStatistics.BundleStatsInfo>) => { 750e41f4b71Sopenharmony_ci console.log('BUNDLE_ACTIVE queryBundleStatsInfoByInterval promise success.'); 751e41f4b71Sopenharmony_ci for (let i = 0; i < res.length; i++) { 752e41f4b71Sopenharmony_ci console.log('BUNDLE_ACTIVE queryBundleStatsInfoByInterval promise number : ' + (i + 1)); 753e41f4b71Sopenharmony_ci console.log('BUNDLE_ACTIVE queryBundleStatsInfoByInterval promise result ' + JSON.stringify(res[i])); 754e41f4b71Sopenharmony_ci } 755e41f4b71Sopenharmony_ci}).catch((err: BusinessError) => { 756e41f4b71Sopenharmony_ci console.log('BUNDLE_ACTIVE queryBundleStatsInfoByInterval promise failed. code is: ' + err.code + ',message is: ' + err.message); 757e41f4b71Sopenharmony_ci}); 758e41f4b71Sopenharmony_ci``` 759e41f4b71Sopenharmony_ci 760e41f4b71Sopenharmony_ci## usageStatistics.queryBundleEvents 761e41f4b71Sopenharmony_ci 762e41f4b71Sopenharmony_ciqueryBundleEvents(begin: number, end: number, callback: AsyncCallback<Array<BundleEvents>>): void 763e41f4b71Sopenharmony_ci 764e41f4b71Sopenharmony_ci通过指定起始和结束时间,查询所有应用的事件集合,使用Callback异步回调。 765e41f4b71Sopenharmony_ci 766e41f4b71Sopenharmony_ci**需要权限**:ohos.permission.BUNDLE_ACTIVE_INFO 767e41f4b71Sopenharmony_ci 768e41f4b71Sopenharmony_ci**系统能力**:SystemCapability.ResourceSchedule.UsageStatistics.App 769e41f4b71Sopenharmony_ci 770e41f4b71Sopenharmony_ci**参数**: 771e41f4b71Sopenharmony_ci 772e41f4b71Sopenharmony_ci| 参数名 | 类型 | 必填 | 说明 | 773e41f4b71Sopenharmony_ci| -------- | ---------------------------------------- | ---- | --------------------------------------- | 774e41f4b71Sopenharmony_ci| begin | number | 是 | 起始时间,以毫秒为单位。 | 775e41f4b71Sopenharmony_ci| end | number | 是 | 结束时间,以毫秒为单位。 | 776e41f4b71Sopenharmony_ci| callback | AsyncCallback<Array<[BundleEvents](#bundleevents)>> | 是 | 回调函数,返回起始和结束时间段内,所有应用的事件集合。 | 777e41f4b71Sopenharmony_ci 778e41f4b71Sopenharmony_ci**错误码**: 779e41f4b71Sopenharmony_ci 780e41f4b71Sopenharmony_ci以下错误码的详细介绍请参见[设备信息使用统计错误码](errorcode-DeviceUsageStatistics.md)和[通用错误码](../errorcode-universal.md)。 781e41f4b71Sopenharmony_ci 782e41f4b71Sopenharmony_ci| 错误码ID | 错误信息 | 783e41f4b71Sopenharmony_ci| ---- | --------------------- | 784e41f4b71Sopenharmony_ci| 201 | Permission denied. | 785e41f4b71Sopenharmony_ci| 202 | Not System App. | 786e41f4b71Sopenharmony_ci| 401 | Parameter error. | 787e41f4b71Sopenharmony_ci| 801 | Capability not supported.| 788e41f4b71Sopenharmony_ci| 10000001 | Memory operation failed. | 789e41f4b71Sopenharmony_ci| 10000002 | Parcel operation failed. | 790e41f4b71Sopenharmony_ci| 10000003 | System service operation failed. | 791e41f4b71Sopenharmony_ci| 10000004 | IPC failed. | 792e41f4b71Sopenharmony_ci| 10000006 | Failed to get the application information. | 793e41f4b71Sopenharmony_ci| 10000007 | Failed to get the system time. | 794e41f4b71Sopenharmony_ci 795e41f4b71Sopenharmony_ci**示例**: 796e41f4b71Sopenharmony_ci 797e41f4b71Sopenharmony_ci```ts 798e41f4b71Sopenharmony_ciimport { BusinessError } from '@kit.BasicServicesKit'; 799e41f4b71Sopenharmony_ci 800e41f4b71Sopenharmony_ciusageStatistics.queryBundleEvents(0, 20000000000000, (err: BusinessError, res: Array<usageStatistics.BundleEvents>) => { 801e41f4b71Sopenharmony_ci if (err) { 802e41f4b71Sopenharmony_ci console.log('BUNDLE_ACTIVE queryBundleEvents callback failed. code is: ' + err.code + ',message is: ' + err.message); 803e41f4b71Sopenharmony_ci } else { 804e41f4b71Sopenharmony_ci console.log('BUNDLE_ACTIVE queryBundleEvents callback success.'); 805e41f4b71Sopenharmony_ci for (let i = 0; i < res.length; i++) { 806e41f4b71Sopenharmony_ci console.log('BUNDLE_ACTIVE queryBundleEvents callback number : ' + (i + 1)); 807e41f4b71Sopenharmony_ci console.log('BUNDLE_ACTIVE queryBundleEvents callback result ' + JSON.stringify(res[i])); 808e41f4b71Sopenharmony_ci } 809e41f4b71Sopenharmony_ci } 810e41f4b71Sopenharmony_ci}); 811e41f4b71Sopenharmony_ci``` 812e41f4b71Sopenharmony_ci 813e41f4b71Sopenharmony_ci## usageStatistics.queryBundleEvents 814e41f4b71Sopenharmony_ci 815e41f4b71Sopenharmony_ciqueryBundleEvents(begin: number, end: number): Promise<Array<BundleEvents>> 816e41f4b71Sopenharmony_ci 817e41f4b71Sopenharmony_ci通过指定起始和结束时间,查询所有应用的事件集合,使用Promise异步回调。 818e41f4b71Sopenharmony_ci 819e41f4b71Sopenharmony_ci**需要权限**:ohos.permission.BUNDLE_ACTIVE_INFO 820e41f4b71Sopenharmony_ci 821e41f4b71Sopenharmony_ci**系统能力**:SystemCapability.ResourceSchedule.UsageStatistics.App 822e41f4b71Sopenharmony_ci 823e41f4b71Sopenharmony_ci**参数**: 824e41f4b71Sopenharmony_ci 825e41f4b71Sopenharmony_ci| 参数名 | 类型 | 必填 | 说明 | 826e41f4b71Sopenharmony_ci| ----- | ------ | ---- | ----- | 827e41f4b71Sopenharmony_ci| begin | number | 是 | 起始时间,以毫秒为单位。 | 828e41f4b71Sopenharmony_ci| end | number | 是 | 结束时间,以毫秒为单位。 | 829e41f4b71Sopenharmony_ci 830e41f4b71Sopenharmony_ci**返回值**: 831e41f4b71Sopenharmony_ci 832e41f4b71Sopenharmony_ci| 类型 | 说明 | 833e41f4b71Sopenharmony_ci| ---------------------------------------- | -------------------------------------- | 834e41f4b71Sopenharmony_ci| Promise<Array<[BundleEvents](#bundleevents)>> | Promise对象。返回起始和结束时间段内,所有应用的事件集合。 | 835e41f4b71Sopenharmony_ci 836e41f4b71Sopenharmony_ci**错误码**: 837e41f4b71Sopenharmony_ci 838e41f4b71Sopenharmony_ci以下错误码的详细介绍请参见[设备信息使用统计错误码](errorcode-DeviceUsageStatistics.md)和[通用错误码](../errorcode-universal.md)。 839e41f4b71Sopenharmony_ci 840e41f4b71Sopenharmony_ci| 错误码ID | 错误信息 | 841e41f4b71Sopenharmony_ci| ---- | --------------------- | 842e41f4b71Sopenharmony_ci| 201 | Permission denied. | 843e41f4b71Sopenharmony_ci| 202 | Not System App. | 844e41f4b71Sopenharmony_ci| 401 | Parameter error. | 845e41f4b71Sopenharmony_ci| 801 | Capability not supported.| 846e41f4b71Sopenharmony_ci| 10000001 | Memory operation failed. | 847e41f4b71Sopenharmony_ci| 10000002 | Parcel operation failed. | 848e41f4b71Sopenharmony_ci| 10000003 | System service operation failed. | 849e41f4b71Sopenharmony_ci| 10000004 | IPC failed. | 850e41f4b71Sopenharmony_ci| 10000006 | Failed to get the application information. | 851e41f4b71Sopenharmony_ci| 10000007 | Failed to get the system time. | 852e41f4b71Sopenharmony_ci 853e41f4b71Sopenharmony_ci**示例**: 854e41f4b71Sopenharmony_ci 855e41f4b71Sopenharmony_ci```ts 856e41f4b71Sopenharmony_ciimport { BusinessError } from '@kit.BasicServicesKit'; 857e41f4b71Sopenharmony_ci 858e41f4b71Sopenharmony_ciusageStatistics.queryBundleEvents(0, 20000000000000).then((res: Array<usageStatistics.BundleEvents>) => { 859e41f4b71Sopenharmony_ci console.log('BUNDLE_ACTIVE queryBundleEvents promise success.'); 860e41f4b71Sopenharmony_ci for (let i = 0; i < res.length; i++) { 861e41f4b71Sopenharmony_ci console.log('BUNDLE_ACTIVE queryBundleEvents promise number : ' + (i + 1)); 862e41f4b71Sopenharmony_ci console.log('BUNDLE_ACTIVE queryBundleEvents promise result ' + JSON.stringify(res[i])); 863e41f4b71Sopenharmony_ci } 864e41f4b71Sopenharmony_ci}).catch((err: BusinessError) => { 865e41f4b71Sopenharmony_ci console.log('BUNDLE_ACTIVE queryBundleEvents promise failed. code is: ' + err.code + ',message is: ' + err.message); 866e41f4b71Sopenharmony_ci}); 867e41f4b71Sopenharmony_ci``` 868e41f4b71Sopenharmony_ci 869e41f4b71Sopenharmony_ci## usageStatistics.queryCurrentBundleEvents 870e41f4b71Sopenharmony_ci 871e41f4b71Sopenharmony_ciqueryCurrentBundleEvents(begin: number, end: number, callback: AsyncCallback<Array<BundleEvents>>): void 872e41f4b71Sopenharmony_ci 873e41f4b71Sopenharmony_ci通过指定起始和结束时间,查询当前应用的事件集合,使用Callback异步回调。 874e41f4b71Sopenharmony_ci 875e41f4b71Sopenharmony_ci**系统能力**:SystemCapability.ResourceSchedule.UsageStatistics.App 876e41f4b71Sopenharmony_ci 877e41f4b71Sopenharmony_ci**参数**: 878e41f4b71Sopenharmony_ci 879e41f4b71Sopenharmony_ci| 参数名 | 类型 | 必填 | 说明 | 880e41f4b71Sopenharmony_ci| -------- | ---------------------------------------- | ---- | --------------------------------------- | 881e41f4b71Sopenharmony_ci| begin | number | 是 | 起始时间,以毫秒为单位。 | 882e41f4b71Sopenharmony_ci| end | number | 是 | 结束时间,以毫秒为单位。 | 883e41f4b71Sopenharmony_ci| callback | AsyncCallback<Array<[BundleEvents](#bundleevents)>> | 是 | 回调函数,返回指定起始和结束时间段内,当前应用的事件集合。 | 884e41f4b71Sopenharmony_ci 885e41f4b71Sopenharmony_ci**错误码**: 886e41f4b71Sopenharmony_ci 887e41f4b71Sopenharmony_ci以下错误码的详细介绍请参见[设备信息使用统计错误码](errorcode-DeviceUsageStatistics.md)和[通用错误码](../errorcode-universal.md)。 888e41f4b71Sopenharmony_ci 889e41f4b71Sopenharmony_ci| 错误码ID | 错误信息 | 890e41f4b71Sopenharmony_ci| ---- | --------------------- | 891e41f4b71Sopenharmony_ci| 202 | Not System App. | 892e41f4b71Sopenharmony_ci| 401 | Parameter error. | 893e41f4b71Sopenharmony_ci| 801 | Capability not supported.| 894e41f4b71Sopenharmony_ci| 10000001 | Memory operation failed. | 895e41f4b71Sopenharmony_ci| 10000002 | Parcel operation failed. | 896e41f4b71Sopenharmony_ci| 10000003 | System service operation failed. | 897e41f4b71Sopenharmony_ci| 10000004 | IPC failed. | 898e41f4b71Sopenharmony_ci| 10000006 | Failed to get the application information. | 899e41f4b71Sopenharmony_ci| 10000007 | Failed to get the system time. | 900e41f4b71Sopenharmony_ci 901e41f4b71Sopenharmony_ci**示例**: 902e41f4b71Sopenharmony_ci 903e41f4b71Sopenharmony_ci```ts 904e41f4b71Sopenharmony_ciimport { BusinessError } from '@kit.BasicServicesKit'; 905e41f4b71Sopenharmony_ci 906e41f4b71Sopenharmony_ciusageStatistics.queryCurrentBundleEvents(0, 20000000000000, (err: BusinessError, res: Array<usageStatistics.BundleEvents>) => { 907e41f4b71Sopenharmony_ci if (err) { 908e41f4b71Sopenharmony_ci console.log('BUNDLE_ACTIVE queryCurrentBundleEvents callback failed. code is: ' + err.code + ',message is: ' + err.message); 909e41f4b71Sopenharmony_ci } else { 910e41f4b71Sopenharmony_ci console.log('BUNDLE_ACTIVE queryCurrentBundleEvents callback success.'); 911e41f4b71Sopenharmony_ci for (let i = 0; i < res.length; i++) { 912e41f4b71Sopenharmony_ci console.log('BUNDLE_ACTIVE queryCurrentBundleEvents callback number : ' + (i + 1)); 913e41f4b71Sopenharmony_ci console.log('BUNDLE_ACTIVE queryCurrentBundleEvents callback result ' + JSON.stringify(res[i])); 914e41f4b71Sopenharmony_ci } 915e41f4b71Sopenharmony_ci } 916e41f4b71Sopenharmony_ci}); 917e41f4b71Sopenharmony_ci``` 918e41f4b71Sopenharmony_ci 919e41f4b71Sopenharmony_ci## usageStatistics.queryCurrentBundleEvents 920e41f4b71Sopenharmony_ci 921e41f4b71Sopenharmony_ciqueryCurrentBundleEvents(begin: number, end: number): Promise<Array<BundleEvents>> 922e41f4b71Sopenharmony_ci 923e41f4b71Sopenharmony_ci通过指定起始和结束时间段内,查询当前应用的事件集合,使用Promise异步回调。 924e41f4b71Sopenharmony_ci 925e41f4b71Sopenharmony_ci**系统能力**:SystemCapability.ResourceSchedule.UsageStatistics.App 926e41f4b71Sopenharmony_ci 927e41f4b71Sopenharmony_ci**参数**: 928e41f4b71Sopenharmony_ci 929e41f4b71Sopenharmony_ci| 参数名 | 类型 | 必填 | 说明 | 930e41f4b71Sopenharmony_ci| ----- | ------ | ---- | ----- | 931e41f4b71Sopenharmony_ci| begin | number | 是 | 起始时间,以毫秒为单位。 | 932e41f4b71Sopenharmony_ci| end | number | 是 | 结束时间,以毫秒为单位。 | 933e41f4b71Sopenharmony_ci 934e41f4b71Sopenharmony_ci**返回值**: 935e41f4b71Sopenharmony_ci 936e41f4b71Sopenharmony_ci| 类型 | 说明 | 937e41f4b71Sopenharmony_ci| ---------------------------------------- | -------------------------------------- | 938e41f4b71Sopenharmony_ci| Promise<Array<[BundleEvents](#bundleevents)>> | Promise对象。返回指定起始和结束时间段内,当前应用的事件集合。 | 939e41f4b71Sopenharmony_ci 940e41f4b71Sopenharmony_ci**错误码**: 941e41f4b71Sopenharmony_ci 942e41f4b71Sopenharmony_ci以下错误码的详细介绍请参见[设备信息使用统计错误码](errorcode-DeviceUsageStatistics.md)和[通用错误码](../errorcode-universal.md)。 943e41f4b71Sopenharmony_ci 944e41f4b71Sopenharmony_ci| 错误码ID | 错误信息 | 945e41f4b71Sopenharmony_ci| ---- | --------------------- | 946e41f4b71Sopenharmony_ci| 202 | Not System App. | 947e41f4b71Sopenharmony_ci| 401 | Parameter error. | 948e41f4b71Sopenharmony_ci| 801 | Capability not supported.| 949e41f4b71Sopenharmony_ci| 10000001 | Memory operation failed. | 950e41f4b71Sopenharmony_ci| 10000002 | Parcel operation failed. | 951e41f4b71Sopenharmony_ci| 10000003 | System service operation failed. | 952e41f4b71Sopenharmony_ci| 10000004 | IPC failed. | 953e41f4b71Sopenharmony_ci| 10000006 | Failed to get the application information. | 954e41f4b71Sopenharmony_ci| 10000007 | Failed to get the system time. | 955e41f4b71Sopenharmony_ci 956e41f4b71Sopenharmony_ci**示例**: 957e41f4b71Sopenharmony_ci 958e41f4b71Sopenharmony_ci```ts 959e41f4b71Sopenharmony_ciimport { BusinessError } from '@kit.BasicServicesKit'; 960e41f4b71Sopenharmony_ci 961e41f4b71Sopenharmony_ciusageStatistics.queryCurrentBundleEvents(0, 20000000000000).then((res: Array<usageStatistics.BundleEvents>) => { 962e41f4b71Sopenharmony_ci console.log('BUNDLE_ACTIVE queryCurrentBundleEvents promise success.'); 963e41f4b71Sopenharmony_ci for (let i = 0; i < res.length; i++) { 964e41f4b71Sopenharmony_ci console.log('BUNDLE_ACTIVE queryCurrentBundleEvents promise number : ' + (i + 1)); 965e41f4b71Sopenharmony_ci console.log('BUNDLE_ACTIVE queryCurrentBundleEvents promise result ' + JSON.stringify(res[i])); 966e41f4b71Sopenharmony_ci } 967e41f4b71Sopenharmony_ci}).catch((err: BusinessError) => { 968e41f4b71Sopenharmony_ci console.log('BUNDLE_ACTIVE queryCurrentBundleEvents promise failed. code is: ' + err.code + ',message is: ' + err.message); 969e41f4b71Sopenharmony_ci}); 970e41f4b71Sopenharmony_ci``` 971e41f4b71Sopenharmony_ci 972e41f4b71Sopenharmony_ci## usageStatistics.queryDeviceEventStats 973e41f4b71Sopenharmony_ci 974e41f4b71Sopenharmony_ciqueryDeviceEventStats(begin: number, end: number): Promise<Array<DeviceEventStats>> 975e41f4b71Sopenharmony_ci 976e41f4b71Sopenharmony_ci通过指定起始和结束时间,查询系统事件(休眠、唤醒、解锁、锁屏)的统计信息,使用Promise异步回调。 977e41f4b71Sopenharmony_ci 978e41f4b71Sopenharmony_ci**需要权限**:ohos.permission.BUNDLE_ACTIVE_INFO 979e41f4b71Sopenharmony_ci 980e41f4b71Sopenharmony_ci**系统能力**:SystemCapability.ResourceSchedule.UsageStatistics.App 981e41f4b71Sopenharmony_ci 982e41f4b71Sopenharmony_ci**参数**: 983e41f4b71Sopenharmony_ci 984e41f4b71Sopenharmony_ci| 参数名 | 类型 | 必填 | 说明 | 985e41f4b71Sopenharmony_ci| ----- | ------ | ---- | ----- | 986e41f4b71Sopenharmony_ci| begin | number | 是 | 起始时间,以毫秒为单位。 | 987e41f4b71Sopenharmony_ci| end | number | 是 | 结束时间,以毫秒为单位。 | 988e41f4b71Sopenharmony_ci 989e41f4b71Sopenharmony_ci**返回值**: 990e41f4b71Sopenharmony_ci 991e41f4b71Sopenharmony_ci| 类型 | 说明 | 992e41f4b71Sopenharmony_ci| ---------------------------------------- | ---------------------------------------- | 993e41f4b71Sopenharmony_ci| Promise<Array<[DeviceEventStats](#deviceeventstats)>> | Promise对象。返回起始和结束时间段内,系统事件(休眠、唤醒、解锁、锁屏)的统计信息。 | 994e41f4b71Sopenharmony_ci 995e41f4b71Sopenharmony_ci**错误码**: 996e41f4b71Sopenharmony_ci 997e41f4b71Sopenharmony_ci以下错误码的详细介绍请参见[设备信息使用统计错误码](errorcode-DeviceUsageStatistics.md)和[通用错误码](../errorcode-universal.md)。 998e41f4b71Sopenharmony_ci 999e41f4b71Sopenharmony_ci| 错误码ID | 错误信息 | 1000e41f4b71Sopenharmony_ci| ---- | --------------------- | 1001e41f4b71Sopenharmony_ci| 201 | Permission denied. | 1002e41f4b71Sopenharmony_ci| 202 | Not System App. | 1003e41f4b71Sopenharmony_ci| 401 | Parameter error. | 1004e41f4b71Sopenharmony_ci| 801 | Capability not supported.| 1005e41f4b71Sopenharmony_ci| 10000001 | Memory operation failed. | 1006e41f4b71Sopenharmony_ci| 10000002 | Parcel operation failed. | 1007e41f4b71Sopenharmony_ci| 10000003 | System service operation failed. | 1008e41f4b71Sopenharmony_ci| 10000004 | IPC failed. | 1009e41f4b71Sopenharmony_ci| 10000006 | Failed to get the application information. | 1010e41f4b71Sopenharmony_ci| 10000007 | Failed to get the system time. | 1011e41f4b71Sopenharmony_ci 1012e41f4b71Sopenharmony_ci**示例**: 1013e41f4b71Sopenharmony_ci 1014e41f4b71Sopenharmony_ci```ts 1015e41f4b71Sopenharmony_ciimport { BusinessError } from '@kit.BasicServicesKit'; 1016e41f4b71Sopenharmony_ci 1017e41f4b71Sopenharmony_ciusageStatistics.queryDeviceEventStats(0, 20000000000000).then((res: Array<usageStatistics.DeviceEventStats>) => { 1018e41f4b71Sopenharmony_ci console.log('BUNDLE_ACTIVE queryDeviceEventStates promise success.'); 1019e41f4b71Sopenharmony_ci console.log('BUNDLE_ACTIVE queryDeviceEventStates promise result ' + JSON.stringify(res)); 1020e41f4b71Sopenharmony_ci}).catch((err: BusinessError) => { 1021e41f4b71Sopenharmony_ci console.log('BUNDLE_ACTIVE queryDeviceEventStats promise failed. code is: ' + err.code + ',message is: ' + err.message); 1022e41f4b71Sopenharmony_ci}); 1023e41f4b71Sopenharmony_ci``` 1024e41f4b71Sopenharmony_ci 1025e41f4b71Sopenharmony_ci## usageStatistics.queryDeviceEventStats 1026e41f4b71Sopenharmony_ci 1027e41f4b71Sopenharmony_ciqueryDeviceEventStats(begin: number, end: number, callback: AsyncCallback<Array<DeviceEventStats>>): void 1028e41f4b71Sopenharmony_ci 1029e41f4b71Sopenharmony_ci通过指定起始和结束时间,查询系统事件(休眠、唤醒、解锁、锁屏)的统计信息,使用Callback异步回调。 1030e41f4b71Sopenharmony_ci 1031e41f4b71Sopenharmony_ci**需要权限**:ohos.permission.BUNDLE_ACTIVE_INFO 1032e41f4b71Sopenharmony_ci 1033e41f4b71Sopenharmony_ci**系统能力**:SystemCapability.ResourceSchedule.UsageStatistics.App 1034e41f4b71Sopenharmony_ci 1035e41f4b71Sopenharmony_ci**参数**: 1036e41f4b71Sopenharmony_ci 1037e41f4b71Sopenharmony_ci| 参数名 | 类型 | 必填 | 说明 | 1038e41f4b71Sopenharmony_ci| -------- | ---------------------------------------- | ---- | ---------------------------------------- | 1039e41f4b71Sopenharmony_ci| begin | number | 是 | 起始时间,以毫秒为单位。 | 1040e41f4b71Sopenharmony_ci| end | number | 是 | 结束时间,以毫秒为单位。 | 1041e41f4b71Sopenharmony_ci| callback | AsyncCallback<Array<[DeviceEventStats](#deviceeventstats)>> | 是 | 回调函数,返回起始和结束时间段内,系统事件(休眠、唤醒、解锁、锁屏)的统计信息。 | 1042e41f4b71Sopenharmony_ci 1043e41f4b71Sopenharmony_ci**错误码**: 1044e41f4b71Sopenharmony_ci 1045e41f4b71Sopenharmony_ci以下错误码的详细介绍请参见[设备信息使用统计错误码](errorcode-DeviceUsageStatistics.md)和[通用错误码](../errorcode-universal.md)。 1046e41f4b71Sopenharmony_ci 1047e41f4b71Sopenharmony_ci| 错误码ID | 错误信息 | 1048e41f4b71Sopenharmony_ci| ---- | --------------------- | 1049e41f4b71Sopenharmony_ci| 201 | Permission denied. | 1050e41f4b71Sopenharmony_ci| 202 | Not System App. | 1051e41f4b71Sopenharmony_ci| 401 | Parameter error. | 1052e41f4b71Sopenharmony_ci| 801 | Capability not supported.| 1053e41f4b71Sopenharmony_ci| 10000001 | Memory operation failed. | 1054e41f4b71Sopenharmony_ci| 10000002 | Parcel operation failed. | 1055e41f4b71Sopenharmony_ci| 10000003 | System service operation failed. | 1056e41f4b71Sopenharmony_ci| 10000004 | IPC failed. | 1057e41f4b71Sopenharmony_ci| 10000006 | Failed to get the application information. | 1058e41f4b71Sopenharmony_ci| 10000007 | Failed to get the system time. | 1059e41f4b71Sopenharmony_ci 1060e41f4b71Sopenharmony_ci**示例**: 1061e41f4b71Sopenharmony_ci 1062e41f4b71Sopenharmony_ci```ts 1063e41f4b71Sopenharmony_ciimport { BusinessError } from '@kit.BasicServicesKit'; 1064e41f4b71Sopenharmony_ci 1065e41f4b71Sopenharmony_ciusageStatistics.queryDeviceEventStats(0, 20000000000000, (err: BusinessError, res: Array<usageStatistics.DeviceEventStats>) => { 1066e41f4b71Sopenharmony_ci if(err) { 1067e41f4b71Sopenharmony_ci console.log('BUNDLE_ACTIVE queryDeviceEventStats callback failed. code is: ' + err.code + ',message is: ' + err.message); 1068e41f4b71Sopenharmony_ci } else { 1069e41f4b71Sopenharmony_ci console.log('BUNDLE_ACTIVE queryDeviceEventStats callback success.'); 1070e41f4b71Sopenharmony_ci console.log('BUNDLE_ACTIVE queryDeviceEventStats callback result ' + JSON.stringify(res)); 1071e41f4b71Sopenharmony_ci } 1072e41f4b71Sopenharmony_ci}); 1073e41f4b71Sopenharmony_ci``` 1074e41f4b71Sopenharmony_ci 1075e41f4b71Sopenharmony_ci## usageStatistics.queryNotificationEventStats 1076e41f4b71Sopenharmony_ci 1077e41f4b71Sopenharmony_ciqueryNotificationEventStats(begin: number, end: number): Promise<Array<DeviceEventStats>> 1078e41f4b71Sopenharmony_ci 1079e41f4b71Sopenharmony_ci通过指定起始和结束时间,查询所有应用的通知次数,使用Promise异步回调。 1080e41f4b71Sopenharmony_ci 1081e41f4b71Sopenharmony_ci**需要权限**:ohos.permission.BUNDLE_ACTIVE_INFO 1082e41f4b71Sopenharmony_ci 1083e41f4b71Sopenharmony_ci**系统能力**:SystemCapability.ResourceSchedule.UsageStatistics.App 1084e41f4b71Sopenharmony_ci 1085e41f4b71Sopenharmony_ci**参数**: 1086e41f4b71Sopenharmony_ci 1087e41f4b71Sopenharmony_ci| 参数名 | 类型 | 必填 | 说明 | 1088e41f4b71Sopenharmony_ci| ----- | ------ | ---- | ----- | 1089e41f4b71Sopenharmony_ci| begin | number | 是 | 起始时间,以毫秒为单位。 | 1090e41f4b71Sopenharmony_ci| end | number | 是 | 结束时间,以毫秒为单位。 | 1091e41f4b71Sopenharmony_ci 1092e41f4b71Sopenharmony_ci**返回值**: 1093e41f4b71Sopenharmony_ci 1094e41f4b71Sopenharmony_ci| 类型 | 说明 | 1095e41f4b71Sopenharmony_ci| ---------------------------------------- | ---------------------------------------- | 1096e41f4b71Sopenharmony_ci| Promise<Array<[DeviceEventStats](#deviceeventstats)>> | Promise对象。返回指定起始和结束时间段内,所有应用的通知次数。 | 1097e41f4b71Sopenharmony_ci 1098e41f4b71Sopenharmony_ci**错误码**: 1099e41f4b71Sopenharmony_ci 1100e41f4b71Sopenharmony_ci以下错误码的详细介绍请参见[设备信息使用统计错误码](errorcode-DeviceUsageStatistics.md)和[通用错误码](../errorcode-universal.md)。 1101e41f4b71Sopenharmony_ci 1102e41f4b71Sopenharmony_ci| 错误码ID | 错误信息 | 1103e41f4b71Sopenharmony_ci| ---- | --------------------- | 1104e41f4b71Sopenharmony_ci| 201 | Permission denied. | 1105e41f4b71Sopenharmony_ci| 202 | Not System App. | 1106e41f4b71Sopenharmony_ci| 401 | Parameter error. | 1107e41f4b71Sopenharmony_ci| 801 | Capability not supported.| 1108e41f4b71Sopenharmony_ci| 10000001 | Memory operation failed. | 1109e41f4b71Sopenharmony_ci| 10000002 | Parcel operation failed. | 1110e41f4b71Sopenharmony_ci| 10000003 | System service operation failed. | 1111e41f4b71Sopenharmony_ci| 10000004 | IPC failed. | 1112e41f4b71Sopenharmony_ci| 10000006 | Failed to get the application information. | 1113e41f4b71Sopenharmony_ci| 10000007 | Failed to get the system time. | 1114e41f4b71Sopenharmony_ci 1115e41f4b71Sopenharmony_ci**示例**: 1116e41f4b71Sopenharmony_ci 1117e41f4b71Sopenharmony_ci```ts 1118e41f4b71Sopenharmony_ciimport { BusinessError } from '@kit.BasicServicesKit'; 1119e41f4b71Sopenharmony_ci 1120e41f4b71Sopenharmony_ciusageStatistics.queryNotificationEventStats(0, 20000000000000).then((res: Array<usageStatistics.DeviceEventStats>) => { 1121e41f4b71Sopenharmony_ci console.log('BUNDLE_ACTIVE queryNotificationEventStats promise success.'); 1122e41f4b71Sopenharmony_ci console.log('BUNDLE_ACTIVE queryNotificationEventStats promise result ' + JSON.stringify(res)); 1123e41f4b71Sopenharmony_ci}).catch((err: BusinessError) => { 1124e41f4b71Sopenharmony_ci console.log('BUNDLE_ACTIVE queryNotificationEventStats promise failed. code is: ' + err.code + ',message is: ' + err.message); 1125e41f4b71Sopenharmony_ci}); 1126e41f4b71Sopenharmony_ci``` 1127e41f4b71Sopenharmony_ci 1128e41f4b71Sopenharmony_ci## usageStatistics.queryNotificationEventStats 1129e41f4b71Sopenharmony_ci 1130e41f4b71Sopenharmony_ciqueryNotificationEventStats(begin: number, end: number, callback: AsyncCallback<Array<DeviceEventStats>>): void 1131e41f4b71Sopenharmony_ci 1132e41f4b71Sopenharmony_ci通过指定起始和结束时间,查询所有应用的通知次数,使用Callback异步回调。 1133e41f4b71Sopenharmony_ci 1134e41f4b71Sopenharmony_ci**需要权限**:ohos.permission.BUNDLE_ACTIVE_INFO 1135e41f4b71Sopenharmony_ci 1136e41f4b71Sopenharmony_ci**系统能力**:SystemCapability.ResourceSchedule.UsageStatistics.App 1137e41f4b71Sopenharmony_ci 1138e41f4b71Sopenharmony_ci**参数**: 1139e41f4b71Sopenharmony_ci 1140e41f4b71Sopenharmony_ci| 参数名 | 类型 | 必填 | 说明 | 1141e41f4b71Sopenharmony_ci| -------- | ---------------------------------------- | ---- | ---------------------------------------- | 1142e41f4b71Sopenharmony_ci| begin | number | 是 | 起始时间,以毫秒为单位。 | 1143e41f4b71Sopenharmony_ci| end | number | 是 | 结束时间,以毫秒为单位。 | 1144e41f4b71Sopenharmony_ci| callback | AsyncCallback<Array<[DeviceEventStats](#deviceeventstats)>> | 是 | 回调函数,返回指定起始和结束时间段内,所有应用的通知次数。 | 1145e41f4b71Sopenharmony_ci 1146e41f4b71Sopenharmony_ci**错误码**: 1147e41f4b71Sopenharmony_ci 1148e41f4b71Sopenharmony_ci以下错误码的详细介绍请参见[设备信息使用统计错误码](errorcode-DeviceUsageStatistics.md)和[通用错误码](../errorcode-universal.md)。 1149e41f4b71Sopenharmony_ci 1150e41f4b71Sopenharmony_ci| 错误码ID | 错误信息 | 1151e41f4b71Sopenharmony_ci| ---- | --------------------- | 1152e41f4b71Sopenharmony_ci| 201 | Permission denied. | 1153e41f4b71Sopenharmony_ci| 202 | Not System App. | 1154e41f4b71Sopenharmony_ci| 401 | Parameter error. | 1155e41f4b71Sopenharmony_ci| 801 | Capability not supported.| 1156e41f4b71Sopenharmony_ci| 10000001 | Memory operation failed. | 1157e41f4b71Sopenharmony_ci| 10000002 | Parcel operation failed. | 1158e41f4b71Sopenharmony_ci| 10000003 | System service operation failed. | 1159e41f4b71Sopenharmony_ci| 10000004 | IPC failed. | 1160e41f4b71Sopenharmony_ci| 10000006 | Failed to get the application information. | 1161e41f4b71Sopenharmony_ci| 10000007 | Failed to get the system time. | 1162e41f4b71Sopenharmony_ci 1163e41f4b71Sopenharmony_ci**示例**: 1164e41f4b71Sopenharmony_ci 1165e41f4b71Sopenharmony_ci```ts 1166e41f4b71Sopenharmony_ciimport { BusinessError } from '@kit.BasicServicesKit'; 1167e41f4b71Sopenharmony_ci 1168e41f4b71Sopenharmony_ciusageStatistics.queryNotificationEventStats(0, 20000000000000, (err: BusinessError, res: Array<usageStatistics.DeviceEventStats>) => { 1169e41f4b71Sopenharmony_ci if(err) { 1170e41f4b71Sopenharmony_ci console.log('BUNDLE_ACTIVE queryNotificationEventStats callback failed. code is: ' + err.code + ',message is: ' + err.message); 1171e41f4b71Sopenharmony_ci } else { 1172e41f4b71Sopenharmony_ci console.log('BUNDLE_ACTIVE queryNotificationEventStats callback success.'); 1173e41f4b71Sopenharmony_ci console.log('BUNDLE_ACTIVE queryNotificationEventStats callback result ' + JSON.stringify(res)); 1174e41f4b71Sopenharmony_ci } 1175e41f4b71Sopenharmony_ci}); 1176e41f4b71Sopenharmony_ci``` 1177e41f4b71Sopenharmony_ci 1178e41f4b71Sopenharmony_ci## usageStatistics.queryModuleUsageRecords 1179e41f4b71Sopenharmony_ci 1180e41f4b71Sopenharmony_ciqueryModuleUsageRecords(): Promise<Array<HapModuleInfo>> 1181e41f4b71Sopenharmony_ci 1182e41f4b71Sopenharmony_ci查询FA模型下各应用不用Hap包的使用记录(不超过1000条)。若Hap包中存在FA卡片,使用信息中也包含卡片信息。使用Promise异步回调。 1183e41f4b71Sopenharmony_ci 1184e41f4b71Sopenharmony_ci使用Promise形式返回不超过1000条FA使用记录,FA使用记录由近及远排序。 1185e41f4b71Sopenharmony_ci 1186e41f4b71Sopenharmony_ci**需要权限**:ohos.permission.BUNDLE_ACTIVE_INFO 1187e41f4b71Sopenharmony_ci 1188e41f4b71Sopenharmony_ci**系统能力**:SystemCapability.ResourceSchedule.UsageStatistics.App 1189e41f4b71Sopenharmony_ci 1190e41f4b71Sopenharmony_ci**返回值**: 1191e41f4b71Sopenharmony_ci 1192e41f4b71Sopenharmony_ci| 类型 | 说明 | 1193e41f4b71Sopenharmony_ci| ---------------------------------------- | ---------------------------------- | 1194e41f4b71Sopenharmony_ci| Promise<Array<[HapModuleInfo](#hapmoduleinfo)>> | Promise对象。返回FA模型下各应用不用Hap包的使用记录(不超过1000条)。 | 1195e41f4b71Sopenharmony_ci 1196e41f4b71Sopenharmony_ci**错误码**: 1197e41f4b71Sopenharmony_ci 1198e41f4b71Sopenharmony_ci以下错误码的详细介绍请参见[设备信息使用统计错误码](errorcode-DeviceUsageStatistics.md)和[通用错误码](../errorcode-universal.md)。 1199e41f4b71Sopenharmony_ci 1200e41f4b71Sopenharmony_ci| 错误码ID | 错误信息 | 1201e41f4b71Sopenharmony_ci| ---- | --------------------- | 1202e41f4b71Sopenharmony_ci| 201 | Permission denied. | 1203e41f4b71Sopenharmony_ci| 202 | Not System App. | 1204e41f4b71Sopenharmony_ci| 401 | Parameter error. | 1205e41f4b71Sopenharmony_ci| 801 | Capability not supported.| 1206e41f4b71Sopenharmony_ci| 10000001 | Memory operation failed. | 1207e41f4b71Sopenharmony_ci| 10000002 | Parcel operation failed. | 1208e41f4b71Sopenharmony_ci| 10000003 | System service operation failed. | 1209e41f4b71Sopenharmony_ci| 10000004 | IPC failed. | 1210e41f4b71Sopenharmony_ci| 10000006 | Failed to get the application information. | 1211e41f4b71Sopenharmony_ci| 10000007 | Failed to get the system time. | 1212e41f4b71Sopenharmony_ci 1213e41f4b71Sopenharmony_ci**示例**: 1214e41f4b71Sopenharmony_ci 1215e41f4b71Sopenharmony_ci```ts 1216e41f4b71Sopenharmony_ci// 无maxNum参数调用方式 1217e41f4b71Sopenharmony_ciimport { BusinessError } from '@kit.BasicServicesKit'; 1218e41f4b71Sopenharmony_ci 1219e41f4b71Sopenharmony_ciusageStatistics.queryModuleUsageRecords().then((res: Array<usageStatistics.HapModuleInfo>) => { 1220e41f4b71Sopenharmony_ci console.log('BUNDLE_ACTIVE queryModuleUsageRecords promise succeeded'); 1221e41f4b71Sopenharmony_ci for (let i = 0; i < res.length; i++) { 1222e41f4b71Sopenharmony_ci console.log('BUNDLE_ACTIVE queryModuleUsageRecords promise number : ' + (i + 1)); 1223e41f4b71Sopenharmony_ci console.log('BUNDLE_ACTIVE queryModuleUsageRecords promise result ' + JSON.stringify(res[i])); 1224e41f4b71Sopenharmony_ci } 1225e41f4b71Sopenharmony_ci}).catch((err: BusinessError) => { 1226e41f4b71Sopenharmony_ci console.log('BUNDLE_ACTIVE queryModuleUsageRecords promise failed. code is: ' + err.code + ',message is: ' + err.message); 1227e41f4b71Sopenharmony_ci}); 1228e41f4b71Sopenharmony_ci``` 1229e41f4b71Sopenharmony_ci 1230e41f4b71Sopenharmony_ci## usageStatistics.queryModuleUsageRecords 1231e41f4b71Sopenharmony_ci 1232e41f4b71Sopenharmony_ciqueryModuleUsageRecords(callback: AsyncCallback<Array<HapModuleInfo>>): void 1233e41f4b71Sopenharmony_ci 1234e41f4b71Sopenharmony_ci查询FA模型下各应用不用Hap包的使用记录(不超过1000条)。若Hap包中存在FA卡片,使用信息中也包含卡片信息。使用CallBack异步回调。 1235e41f4b71Sopenharmony_ci 1236e41f4b71Sopenharmony_ci**需要权限**:ohos.permission.BUNDLE_ACTIVE_INFO 1237e41f4b71Sopenharmony_ci 1238e41f4b71Sopenharmony_ci**系统能力**:SystemCapability.ResourceSchedule.UsageStatistics.App 1239e41f4b71Sopenharmony_ci 1240e41f4b71Sopenharmony_ci**参数**: 1241e41f4b71Sopenharmony_ci 1242e41f4b71Sopenharmony_ci| 参数名 | 类型 | 必填 | 说明 | 1243e41f4b71Sopenharmony_ci| -------- | ---------------------------------------- | ---- | ----------------------------------- | 1244e41f4b71Sopenharmony_ci| callback | AsyncCallback<Array<[HapModuleInfo](#hapmoduleinfo)>> | 是 | 回调函数,返回FA模型下各应用不用Hap包的使用记录(不超过1000条)。 | 1245e41f4b71Sopenharmony_ci 1246e41f4b71Sopenharmony_ci**错误码**: 1247e41f4b71Sopenharmony_ci 1248e41f4b71Sopenharmony_ci以下错误码的详细介绍请参见[设备信息使用统计错误码](errorcode-DeviceUsageStatistics.md)。 1249e41f4b71Sopenharmony_ci 1250e41f4b71Sopenharmony_ci| 错误码ID | 错误信息 | 1251e41f4b71Sopenharmony_ci| ---------- | ---------------------------- | 1252e41f4b71Sopenharmony_ci| 10000001 | Memory operation failed. | 1253e41f4b71Sopenharmony_ci| 10000002 | Parcel operation failed. | 1254e41f4b71Sopenharmony_ci| 10000003 | System service operation failed. | 1255e41f4b71Sopenharmony_ci| 10000004 | IPC failed. | 1256e41f4b71Sopenharmony_ci| 10000006 | Failed to get the application information. | 1257e41f4b71Sopenharmony_ci| 10000007 | Failed to get the system time. | 1258e41f4b71Sopenharmony_ci 1259e41f4b71Sopenharmony_ci**示例**: 1260e41f4b71Sopenharmony_ci 1261e41f4b71Sopenharmony_ci```ts 1262e41f4b71Sopenharmony_ciimport { BusinessError } from '@kit.BasicServicesKit'; 1263e41f4b71Sopenharmony_ci 1264e41f4b71Sopenharmony_ciusageStatistics.queryModuleUsageRecords((err: BusinessError, res: Array<usageStatistics.HapModuleInfo>) => { 1265e41f4b71Sopenharmony_ci if(err) { 1266e41f4b71Sopenharmony_ci console.log('BUNDLE_ACTIVE queryModuleUsageRecords callback failed. code is: ' + err.code + ',message is: ' + err.message); 1267e41f4b71Sopenharmony_ci } else { 1268e41f4b71Sopenharmony_ci console.log('BUNDLE_ACTIVE queryModuleUsageRecords callback succeeded.'); 1269e41f4b71Sopenharmony_ci for (let i = 0; i < res.length; i++) { 1270e41f4b71Sopenharmony_ci console.log('BUNDLE_ACTIVE queryModuleUsageRecords callback number : ' + (i + 1)); 1271e41f4b71Sopenharmony_ci console.log('BUNDLE_ACTIVE queryModuleUsageRecords callback result ' + JSON.stringify(res[i])); 1272e41f4b71Sopenharmony_ci } 1273e41f4b71Sopenharmony_ci } 1274e41f4b71Sopenharmony_ci}); 1275e41f4b71Sopenharmony_ci``` 1276e41f4b71Sopenharmony_ci 1277e41f4b71Sopenharmony_ci## usageStatistics.queryModuleUsageRecords 1278e41f4b71Sopenharmony_ci 1279e41f4b71Sopenharmony_ciqueryModuleUsageRecords(maxNum: number): Promise<Array<HapModuleInfo>> 1280e41f4b71Sopenharmony_ci 1281e41f4b71Sopenharmony_ci根据设置的maxNum,查询FA模型下各应用不用Hap包的使用记录。若Hap包中存在FA卡片,使用信息中也包含卡片信息。使用Promise异步回调。 1282e41f4b71Sopenharmony_ci 1283e41f4b71Sopenharmony_ci**需要权限**:ohos.permission.BUNDLE_ACTIVE_INFO 1284e41f4b71Sopenharmony_ci 1285e41f4b71Sopenharmony_ci**系统能力**:SystemCapability.ResourceSchedule.UsageStatistics.App 1286e41f4b71Sopenharmony_ci 1287e41f4b71Sopenharmony_ci**参数**: 1288e41f4b71Sopenharmony_ci 1289e41f4b71Sopenharmony_ci| 参数名 | 类型 | 必填 | 说明 | 1290e41f4b71Sopenharmony_ci| ------ | ------ | ---- | ---------------------------------- | 1291e41f4b71Sopenharmony_ci| maxNum | number | 是 | 使用记录的条数,取值范围为[1,1000]。 | 1292e41f4b71Sopenharmony_ci 1293e41f4b71Sopenharmony_ci**返回值**: 1294e41f4b71Sopenharmony_ci 1295e41f4b71Sopenharmony_ci| 类型 | 说明 | 1296e41f4b71Sopenharmony_ci| ---------------------------------------- | ---------------------------------- | 1297e41f4b71Sopenharmony_ci| Promise<Array<[HapModuleInfo](#hapmoduleinfo)>> | Promise对象,返回不超过maxNum条,FA模型下各应用不用Hap包的使用记录。 | 1298e41f4b71Sopenharmony_ci 1299e41f4b71Sopenharmony_ci**错误码**: 1300e41f4b71Sopenharmony_ci 1301e41f4b71Sopenharmony_ci以下错误码的详细介绍请参见[设备信息使用统计错误码](errorcode-DeviceUsageStatistics.md)和[通用错误码](../errorcode-universal.md)。 1302e41f4b71Sopenharmony_ci 1303e41f4b71Sopenharmony_ci| 错误码ID | 错误信息 | 1304e41f4b71Sopenharmony_ci| ---- | --------------------- | 1305e41f4b71Sopenharmony_ci| 201 | Permission denied. | 1306e41f4b71Sopenharmony_ci| 202 | Not System App. | 1307e41f4b71Sopenharmony_ci| 401 | Parameter error. Possible cause: 1. Mandatory parameters are left unspecified; 2. Incorrect parameters types; 3. Parameter verification failed. | 1308e41f4b71Sopenharmony_ci| 801 | Capability not supported.| 1309e41f4b71Sopenharmony_ci| 10000001 | Memory operation failed. | 1310e41f4b71Sopenharmony_ci| 10000002 | Parcel operation failed. | 1311e41f4b71Sopenharmony_ci| 10000003 | System service operation failed. | 1312e41f4b71Sopenharmony_ci| 10000004 | IPC failed. | 1313e41f4b71Sopenharmony_ci| 10000006 | Failed to get the application information. | 1314e41f4b71Sopenharmony_ci| 10000007 | Failed to get the system time. | 1315e41f4b71Sopenharmony_ci 1316e41f4b71Sopenharmony_ci**示例**: 1317e41f4b71Sopenharmony_ci 1318e41f4b71Sopenharmony_ci```ts 1319e41f4b71Sopenharmony_ciimport { BusinessError } from '@kit.BasicServicesKit'; 1320e41f4b71Sopenharmony_ci 1321e41f4b71Sopenharmony_ciusageStatistics.queryModuleUsageRecords(1000).then((res: Array<usageStatistics.HapModuleInfo>) => { 1322e41f4b71Sopenharmony_ci console.log('BUNDLE_ACTIVE queryModuleUsageRecords promise succeeded'); 1323e41f4b71Sopenharmony_ci for (let i = 0; i < res.length; i++) { 1324e41f4b71Sopenharmony_ci console.log('BUNDLE_ACTIVE queryModuleUsageRecords promise number : ' + (i + 1)); 1325e41f4b71Sopenharmony_ci console.log('BUNDLE_ACTIVE queryModuleUsageRecords promise result ' + JSON.stringify(res[i])); 1326e41f4b71Sopenharmony_ci } 1327e41f4b71Sopenharmony_ci}).catch((err: BusinessError) => { 1328e41f4b71Sopenharmony_ci console.log('BUNDLE_ACTIVE queryModuleUsageRecords promise failed. code is: ' + err.code + ',message is: ' + err.message); 1329e41f4b71Sopenharmony_ci}); 1330e41f4b71Sopenharmony_ci``` 1331e41f4b71Sopenharmony_ci 1332e41f4b71Sopenharmony_ci## usageStatistics.queryModuleUsageRecords 1333e41f4b71Sopenharmony_ci 1334e41f4b71Sopenharmony_ciqueryModuleUsageRecords(maxNum: number, callback: AsyncCallback<Array<HapModuleInfo>>): void 1335e41f4b71Sopenharmony_ci 1336e41f4b71Sopenharmony_ci根据设置的maxNum,查询FA模型下各应用不用Hap包的使用记录。若Hap包中存在FA卡片,使用信息中也包含卡片信息。使用Callback异步回调。 1337e41f4b71Sopenharmony_ci 1338e41f4b71Sopenharmony_ci**需要权限**:ohos.permission.BUNDLE_ACTIVE_INFO 1339e41f4b71Sopenharmony_ci 1340e41f4b71Sopenharmony_ci**系统能力**:SystemCapability.ResourceSchedule.UsageStatistics.App 1341e41f4b71Sopenharmony_ci 1342e41f4b71Sopenharmony_ci**参数**: 1343e41f4b71Sopenharmony_ci 1344e41f4b71Sopenharmony_ci| 参数名 | 类型 | 必填 | 说明 | 1345e41f4b71Sopenharmony_ci| -------- | ---------------------------------------- | ---- | ----------------------------------- | 1346e41f4b71Sopenharmony_ci| maxNum | number | 是 | 使用记录的条数,取值范围为[1,1000]。 | 1347e41f4b71Sopenharmony_ci| callback | AsyncCallback<Array<[HapModuleInfo](#hapmoduleinfo)>> | 是 | 回调方法,返回不超过maxNum条,FA模型下各应用不用Hap包的使用记录。 | 1348e41f4b71Sopenharmony_ci 1349e41f4b71Sopenharmony_ci**错误码**: 1350e41f4b71Sopenharmony_ci 1351e41f4b71Sopenharmony_ci以下错误码的详细介绍请参见[设备信息使用统计错误码](errorcode-DeviceUsageStatistics.md)和[通用错误码](../errorcode-universal.md)。 1352e41f4b71Sopenharmony_ci 1353e41f4b71Sopenharmony_ci| 错误码ID | 错误信息 | 1354e41f4b71Sopenharmony_ci| ---- | --------------------- | 1355e41f4b71Sopenharmony_ci| 201 | Permission denied. | 1356e41f4b71Sopenharmony_ci| 202 | Not System App. | 1357e41f4b71Sopenharmony_ci| 401 | Parameter error. Possible cause: 1. Mandatory parameters are left unspecified; 2. Incorrect parameters types; 3. Parameter verification failed. | 1358e41f4b71Sopenharmony_ci| 801 | Capability not supported.| 1359e41f4b71Sopenharmony_ci| 10000001 | Memory operation failed. | 1360e41f4b71Sopenharmony_ci| 10000002 | Parcel operation failed. | 1361e41f4b71Sopenharmony_ci| 10000003 | System service operation failed. | 1362e41f4b71Sopenharmony_ci| 10000004 | IPC failed. | 1363e41f4b71Sopenharmony_ci| 10000006 | Failed to get the application information. | 1364e41f4b71Sopenharmony_ci| 10000007 | Failed to get the system time. | 1365e41f4b71Sopenharmony_ci 1366e41f4b71Sopenharmony_ci**示例**: 1367e41f4b71Sopenharmony_ci 1368e41f4b71Sopenharmony_ci```ts 1369e41f4b71Sopenharmony_ciimport { BusinessError } from '@kit.BasicServicesKit'; 1370e41f4b71Sopenharmony_ci 1371e41f4b71Sopenharmony_ciusageStatistics.queryModuleUsageRecords(1000, (err: BusinessError, res: Array<usageStatistics.HapModuleInfo>) => { 1372e41f4b71Sopenharmony_ci if(err) { 1373e41f4b71Sopenharmony_ci console.log('BUNDLE_ACTIVE queryModuleUsageRecords callback failed. code is: ' + err.code + ',message is: ' + err.message); 1374e41f4b71Sopenharmony_ci } else { 1375e41f4b71Sopenharmony_ci console.log('BUNDLE_ACTIVE queryModuleUsageRecords callback succeeded.'); 1376e41f4b71Sopenharmony_ci for (let i = 0; i < res.length; i++) { 1377e41f4b71Sopenharmony_ci console.log('BUNDLE_ACTIVE queryModuleUsageRecords callback number : ' + (i + 1)); 1378e41f4b71Sopenharmony_ci console.log('BUNDLE_ACTIVE queryModuleUsageRecords callback result ' + JSON.stringify(res[i])); 1379e41f4b71Sopenharmony_ci } 1380e41f4b71Sopenharmony_ci } 1381e41f4b71Sopenharmony_ci}); 1382e41f4b71Sopenharmony_ci``` 1383e41f4b71Sopenharmony_ci 1384e41f4b71Sopenharmony_ci## usageStatistics.registerAppGroupCallBack 1385e41f4b71Sopenharmony_ci 1386e41f4b71Sopenharmony_ciregisterAppGroupCallBack(groupCallback: Callback<AppGroupCallbackInfo>): Promise<void> 1387e41f4b71Sopenharmony_ci 1388e41f4b71Sopenharmony_ci注册应用分组变化监听,即用户名下的某个应用分组发生变化时,向所有已注册分组变化监听的应用返回[AppGroupCallbackInfo](#appgroupcallbackinfo)信息。使用Promise异步回调。 1389e41f4b71Sopenharmony_ci 1390e41f4b71Sopenharmony_ci**需要权限**:ohos.permission.BUNDLE_ACTIVE_INFO 1391e41f4b71Sopenharmony_ci 1392e41f4b71Sopenharmony_ci**系统能力**:SystemCapability.ResourceSchedule.UsageStatistics.AppGroup 1393e41f4b71Sopenharmony_ci 1394e41f4b71Sopenharmony_ci**参数**: 1395e41f4b71Sopenharmony_ci 1396e41f4b71Sopenharmony_ci| 参数名 | 类型 | 必填 | 说明 | 1397e41f4b71Sopenharmony_ci| -------- | ------------------------------------------------------------ | ---- | ------------------------------------------ | 1398e41f4b71Sopenharmony_ci| groupCallback | Callback<[AppGroupCallbackInfo](#appgroupcallbackinfo)> | 是 | 返回的应用分组变化信息。 | 1399e41f4b71Sopenharmony_ci 1400e41f4b71Sopenharmony_ci**返回值**: 1401e41f4b71Sopenharmony_ci 1402e41f4b71Sopenharmony_ci| 类型 | 说明 | 1403e41f4b71Sopenharmony_ci| ------------- | ----------------------- | 1404e41f4b71Sopenharmony_ci| Promise<void> | 无返回结果的Promise对象。 | 1405e41f4b71Sopenharmony_ci 1406e41f4b71Sopenharmony_ci**错误码**: 1407e41f4b71Sopenharmony_ci 1408e41f4b71Sopenharmony_ci以下错误码的详细介绍请参见[设备信息使用统计错误码](errorcode-DeviceUsageStatistics.md)和[通用错误码](../errorcode-universal.md)。 1409e41f4b71Sopenharmony_ci 1410e41f4b71Sopenharmony_ci| 错误码ID | 错误信息 | 1411e41f4b71Sopenharmony_ci| ---- | --------------------- | 1412e41f4b71Sopenharmony_ci| 201 | Permission denied. | 1413e41f4b71Sopenharmony_ci| 202 | Not System App. | 1414e41f4b71Sopenharmony_ci| 401 | Parameter error. | 1415e41f4b71Sopenharmony_ci| 801 | Capability not supported.| 1416e41f4b71Sopenharmony_ci| 10000001 | Memory operation failed. | 1417e41f4b71Sopenharmony_ci| 10000002 | Parcel operation failed. | 1418e41f4b71Sopenharmony_ci| 10000003 | System service operation failed. | 1419e41f4b71Sopenharmony_ci| 10000004 | IPC failed. | 1420e41f4b71Sopenharmony_ci| 10100001 | Repeated operation on the application group. | 1421e41f4b71Sopenharmony_ci 1422e41f4b71Sopenharmony_ci 1423e41f4b71Sopenharmony_ci**示例**: 1424e41f4b71Sopenharmony_ci 1425e41f4b71Sopenharmony_ci```ts 1426e41f4b71Sopenharmony_ciimport { BusinessError } from '@kit.BasicServicesKit'; 1427e41f4b71Sopenharmony_ci 1428e41f4b71Sopenharmony_cifunction onBundleGroupChanged(res: usageStatistics.AppGroupCallbackInfo) { 1429e41f4b71Sopenharmony_ci console.log('BUNDLE_ACTIVE registerAppGroupCallBack RegisterGroupCallBack callback success.'); 1430e41f4b71Sopenharmony_ci console.log('BUNDLE_ACTIVE registerAppGroupCallBack result appOldGroup is : ' + res.appOldGroup); 1431e41f4b71Sopenharmony_ci console.log('BUNDLE_ACTIVE registerAppGroupCallBack result appNewGroup is : ' + res.appNewGroup); 1432e41f4b71Sopenharmony_ci console.log('BUNDLE_ACTIVE registerAppGroupCallBack result changeReason is : ' + res.changeReason); 1433e41f4b71Sopenharmony_ci console.log('BUNDLE_ACTIVE registerAppGroupCallBack result userId is : ' + res.userId); 1434e41f4b71Sopenharmony_ci console.log('BUNDLE_ACTIVE registerAppGroupCallBack result bundleName is : ' + res.bundleName); 1435e41f4b71Sopenharmony_ci}; 1436e41f4b71Sopenharmony_ciusageStatistics.registerAppGroupCallBack(onBundleGroupChanged).then( () => { 1437e41f4b71Sopenharmony_ci console.log('BUNDLE_ACTIVE registerAppGroupCallBack promise succeeded.'); 1438e41f4b71Sopenharmony_ci}).catch((err: BusinessError) => { 1439e41f4b71Sopenharmony_ci console.log('BUNDLE_ACTIVE registerAppGroupCallBack promise failed. code is: ' + err.code + ',message is: ' + err.message); 1440e41f4b71Sopenharmony_ci}); 1441e41f4b71Sopenharmony_ci``` 1442e41f4b71Sopenharmony_ci 1443e41f4b71Sopenharmony_ci## usageStatistics.registerAppGroupCallBack 1444e41f4b71Sopenharmony_ci 1445e41f4b71Sopenharmony_ciregisterAppGroupCallBack(groupCallback: Callback<AppGroupCallbackInfo>, callback: AsyncCallback<void>): void 1446e41f4b71Sopenharmony_ci 1447e41f4b71Sopenharmony_ci应用注册分组变化监听,即用户名下的某个应用分组发生变化时,向所有已注册分组变化监听的应用返回[AppGroupCallbackInfo](#appgroupcallbackinfo)信息。使用Callback异步回调。 1448e41f4b71Sopenharmony_ci 1449e41f4b71Sopenharmony_ci**需要权限**:ohos.permission.BUNDLE_ACTIVE_INFO 1450e41f4b71Sopenharmony_ci 1451e41f4b71Sopenharmony_ci**系统能力**:SystemCapability.ResourceSchedule.UsageStatistics.AppGroup 1452e41f4b71Sopenharmony_ci 1453e41f4b71Sopenharmony_ci**参数**: 1454e41f4b71Sopenharmony_ci 1455e41f4b71Sopenharmony_ci| 参数名 | 类型 | 必填 | 说明 | 1456e41f4b71Sopenharmony_ci| -------- | ------------------------------------------------------------ | ---- | -------------------------------------------- | 1457e41f4b71Sopenharmony_ci| groupCallback | Callback<[AppGroupCallbackInfo](#appgroupcallbackinfo)> | 是 | 返回的应用分组变化信息。 | 1458e41f4b71Sopenharmony_ci| callback | AsyncCallback<void> | 是 | 回调函数,返回注册监听是否成功。 | 1459e41f4b71Sopenharmony_ci 1460e41f4b71Sopenharmony_ci**错误码**: 1461e41f4b71Sopenharmony_ci 1462e41f4b71Sopenharmony_ci以下错误码的详细介绍请参见[设备信息使用统计错误码](errorcode-DeviceUsageStatistics.md)。和[通用错误码](../errorcode-universal.md)。 1463e41f4b71Sopenharmony_ci 1464e41f4b71Sopenharmony_ci| 错误码ID | 错误信息 | 1465e41f4b71Sopenharmony_ci| ---- | --------------------- | 1466e41f4b71Sopenharmony_ci| 201 | Permission denied. | 1467e41f4b71Sopenharmony_ci| 202 | Not System App. | 1468e41f4b71Sopenharmony_ci| 401 | Parameter error. | 1469e41f4b71Sopenharmony_ci| 801 | Capability not supported.| 1470e41f4b71Sopenharmony_ci| 10000001 | Memory operation failed. | 1471e41f4b71Sopenharmony_ci| 10000002 | Parcel operation failed. | 1472e41f4b71Sopenharmony_ci| 10000003 | System service operation failed. | 1473e41f4b71Sopenharmony_ci| 10000004 | IPC failed. | 1474e41f4b71Sopenharmony_ci| 10100001 | Repeated operation on the application group. | 1475e41f4b71Sopenharmony_ci 1476e41f4b71Sopenharmony_ci 1477e41f4b71Sopenharmony_ci**示例**: 1478e41f4b71Sopenharmony_ci 1479e41f4b71Sopenharmony_ci```ts 1480e41f4b71Sopenharmony_ciimport { BusinessError } from '@kit.BasicServicesKit'; 1481e41f4b71Sopenharmony_ci 1482e41f4b71Sopenharmony_cifunction onBundleGroupChanged(res: usageStatistics.AppGroupCallbackInfo) { 1483e41f4b71Sopenharmony_ci console.log('BUNDLE_ACTIVE onBundleGroupChanged RegisterGroupCallBack callback success.'); 1484e41f4b71Sopenharmony_ci console.log('BUNDLE_ACTIVE registerAppGroupCallBack result appOldGroup is : ' + res.appOldGroup); 1485e41f4b71Sopenharmony_ci console.log('BUNDLE_ACTIVE registerAppGroupCallBack result appNewGroup is : ' + res.appNewGroup); 1486e41f4b71Sopenharmony_ci console.log('BUNDLE_ACTIVE registerAppGroupCallBack result changeReason is : ' + res.changeReason); 1487e41f4b71Sopenharmony_ci console.log('BUNDLE_ACTIVE registerAppGroupCallBack result userId is : ' + res.userId); 1488e41f4b71Sopenharmony_ci console.log('BUNDLE_ACTIVE registerAppGroupCallBack result bundleName is : ' + res.bundleName); 1489e41f4b71Sopenharmony_ci}; 1490e41f4b71Sopenharmony_ciusageStatistics.registerAppGroupCallBack(onBundleGroupChanged, (err: BusinessError) => { 1491e41f4b71Sopenharmony_ci if(err) { 1492e41f4b71Sopenharmony_ci console.log('BUNDLE_ACTIVE registerAppGroupCallBack callback failed. code is: ' + err.code + ',message is: ' + err.message); 1493e41f4b71Sopenharmony_ci } else { 1494e41f4b71Sopenharmony_ci console.log('BUNDLE_ACTIVE registerAppGroupCallBack callback success.'); 1495e41f4b71Sopenharmony_ci } 1496e41f4b71Sopenharmony_ci}); 1497e41f4b71Sopenharmony_ci``` 1498e41f4b71Sopenharmony_ci 1499e41f4b71Sopenharmony_ci## usageStatistics.unregisterAppGroupCallBack 1500e41f4b71Sopenharmony_ci 1501e41f4b71Sopenharmony_ciunregisterAppGroupCallBack(): Promise<void> 1502e41f4b71Sopenharmony_ci 1503e41f4b71Sopenharmony_ci应用解除分组变化监听。使用Promise异步回调。 1504e41f4b71Sopenharmony_ci 1505e41f4b71Sopenharmony_ci**需要权限**:ohos.permission.BUNDLE_ACTIVE_INFO 1506e41f4b71Sopenharmony_ci 1507e41f4b71Sopenharmony_ci**系统能力**:SystemCapability.ResourceSchedule.UsageStatistics.AppGroup 1508e41f4b71Sopenharmony_ci 1509e41f4b71Sopenharmony_ci**返回值**: 1510e41f4b71Sopenharmony_ci 1511e41f4b71Sopenharmony_ci| 类型 | 说明 | 1512e41f4b71Sopenharmony_ci| ------------- | ------------------------ | 1513e41f4b71Sopenharmony_ci| Promise<void> | 无返回结果的Promise对象。 | 1514e41f4b71Sopenharmony_ci 1515e41f4b71Sopenharmony_ci**错误码**: 1516e41f4b71Sopenharmony_ci 1517e41f4b71Sopenharmony_ci以下错误码的详细介绍请参见[设备信息使用统计错误码](errorcode-DeviceUsageStatistics.md)和[通用错误码](../errorcode-universal.md)。 1518e41f4b71Sopenharmony_ci 1519e41f4b71Sopenharmony_ci| 错误码ID | 错误信息 | 1520e41f4b71Sopenharmony_ci| ---- | --------------------- | 1521e41f4b71Sopenharmony_ci| 201 | Permission denied. | 1522e41f4b71Sopenharmony_ci| 202 | Not System App. | 1523e41f4b71Sopenharmony_ci| 401 | Parameter error. | 1524e41f4b71Sopenharmony_ci| 801 | Capability not supported.| 1525e41f4b71Sopenharmony_ci| 10000001 | Memory operation failed. | 1526e41f4b71Sopenharmony_ci| 10000002 | Parcel operation failed. | 1527e41f4b71Sopenharmony_ci| 10000003 | System service operation failed. | 1528e41f4b71Sopenharmony_ci| 10000004 | IPC failed. | 1529e41f4b71Sopenharmony_ci| 10100001 | Repeated operation on the application group. | 1530e41f4b71Sopenharmony_ci 1531e41f4b71Sopenharmony_ci**示例**: 1532e41f4b71Sopenharmony_ci 1533e41f4b71Sopenharmony_ci```ts 1534e41f4b71Sopenharmony_ciimport { BusinessError } from '@kit.BasicServicesKit'; 1535e41f4b71Sopenharmony_ci 1536e41f4b71Sopenharmony_ciusageStatistics.unregisterAppGroupCallBack().then( () => { 1537e41f4b71Sopenharmony_ci console.log('BUNDLE_ACTIVE unregisterAppGroupCallBack promise succeeded.'); 1538e41f4b71Sopenharmony_ci}).catch((err: BusinessError) => { 1539e41f4b71Sopenharmony_ci console.log('BUNDLE_ACTIVE unregisterAppGroupCallBack promise failed. code is: ' + err.code + ',message is: ' + err.message); 1540e41f4b71Sopenharmony_ci}); 1541e41f4b71Sopenharmony_ci``` 1542e41f4b71Sopenharmony_ci 1543e41f4b71Sopenharmony_ci## usageStatistics.unregisterAppGroupCallBack 1544e41f4b71Sopenharmony_ci 1545e41f4b71Sopenharmony_ciunregisterAppGroupCallBack(callback: AsyncCallback<void>): void; 1546e41f4b71Sopenharmony_ci 1547e41f4b71Sopenharmony_ci应用解除分组变化监听。使用callback异步回调。 1548e41f4b71Sopenharmony_ci 1549e41f4b71Sopenharmony_ci**需要权限**:ohos.permission.BUNDLE_ACTIVE_INFO 1550e41f4b71Sopenharmony_ci 1551e41f4b71Sopenharmony_ci**系统能力**:SystemCapability.ResourceSchedule.UsageStatistics.AppGroup 1552e41f4b71Sopenharmony_ci 1553e41f4b71Sopenharmony_ci**参数**: 1554e41f4b71Sopenharmony_ci 1555e41f4b71Sopenharmony_ci| 参数名 | 类型 | 必填 | 说明 | 1556e41f4b71Sopenharmony_ci| -------- | ------------------- | ---- | -------------- | 1557e41f4b71Sopenharmony_ci| callback | AsyncCallback<void> | 是 | 回调函数,返回是否成功解除监听。 | 1558e41f4b71Sopenharmony_ci 1559e41f4b71Sopenharmony_ci**错误码**: 1560e41f4b71Sopenharmony_ci 1561e41f4b71Sopenharmony_ci以下错误码的详细介绍请参见[设备信息使用统计错误码](errorcode-DeviceUsageStatistics.md)和[通用错误码](../errorcode-universal.md)。 1562e41f4b71Sopenharmony_ci 1563e41f4b71Sopenharmony_ci| 错误码ID | 错误信息 | 1564e41f4b71Sopenharmony_ci| ---- | --------------------- | 1565e41f4b71Sopenharmony_ci| 201 | Permission denied. | 1566e41f4b71Sopenharmony_ci| 202 | Not System App. | 1567e41f4b71Sopenharmony_ci| 401 | Parameter error. | 1568e41f4b71Sopenharmony_ci| 801 | Capability not supported.| 1569e41f4b71Sopenharmony_ci| 10000001 | Memory operation failed. | 1570e41f4b71Sopenharmony_ci| 10000002 | Parcel operation failed. | 1571e41f4b71Sopenharmony_ci| 10000003 | System service operation failed. | 1572e41f4b71Sopenharmony_ci| 10000004 | IPC failed. | 1573e41f4b71Sopenharmony_ci| 10100001 | Repeated operation on the application group. | 1574e41f4b71Sopenharmony_ci 1575e41f4b71Sopenharmony_ci**示例**: 1576e41f4b71Sopenharmony_ci 1577e41f4b71Sopenharmony_ci```ts 1578e41f4b71Sopenharmony_ciimport { BusinessError } from '@kit.BasicServicesKit'; 1579e41f4b71Sopenharmony_ci 1580e41f4b71Sopenharmony_ciusageStatistics.unregisterAppGroupCallBack((err: BusinessError) => { 1581e41f4b71Sopenharmony_ci if(err) { 1582e41f4b71Sopenharmony_ci console.log('BUNDLE_ACTIVE unregisterAppGroupCallBack callback failed. code is: ' + err.code + ',message is: ' + err.message); 1583e41f4b71Sopenharmony_ci } else { 1584e41f4b71Sopenharmony_ci console.log('BUNDLE_ACTIVE unregisterAppGroupCallBack callback success.'); 1585e41f4b71Sopenharmony_ci } 1586e41f4b71Sopenharmony_ci}); 1587e41f4b71Sopenharmony_ci``` 1588e41f4b71Sopenharmony_ci 1589e41f4b71Sopenharmony_ci## HapModuleInfo 1590e41f4b71Sopenharmony_ci 1591e41f4b71Sopenharmony_ciFA模型的使用信息属性集合。 1592e41f4b71Sopenharmony_ci 1593e41f4b71Sopenharmony_ci**系统能力**:以下各项对应的系统能力均为SystemCapability.ResourceSchedule.UsageStatistics.App 1594e41f4b71Sopenharmony_ci 1595e41f4b71Sopenharmony_ci| 名称 | 类型 | 必填 | 说明 | 1596e41f4b71Sopenharmony_ci| -------------------- | ---------------------------------------- | ---- | ----------------------------- | 1597e41f4b71Sopenharmony_ci| deviceId | string | 否 | 设备Id。 | 1598e41f4b71Sopenharmony_ci| bundleName | string | 是 | 应用名称。 | 1599e41f4b71Sopenharmony_ci| moduleName | string | 是 | FA所属module名。 | 1600e41f4b71Sopenharmony_ci| abilityName | string | 否 | FA的MainAbility名。 | 1601e41f4b71Sopenharmony_ci| appLabelId | number | 否 | FA的应用labelId。 | 1602e41f4b71Sopenharmony_ci| labelId | number | 否 | FA所属module的labelId。 | 1603e41f4b71Sopenharmony_ci| descriptionId | number | 否 | FA所属的应用descriptionId。 | 1604e41f4b71Sopenharmony_ci| abilityLableId | number | 否 | FA的MainAbility labelId。 | 1605e41f4b71Sopenharmony_ci| abilityDescriptionId | number | 否 | FA的MainAbility descriptionId。 | 1606e41f4b71Sopenharmony_ci| abilityIconId | number | 否 | FA的MainAbility iconId。 | 1607e41f4b71Sopenharmony_ci| launchedCount | number | 是 | FA的启动次数。 | 1608e41f4b71Sopenharmony_ci| lastModuleUsedTime | number | 是 | FA的上一次使用时间。 | 1609e41f4b71Sopenharmony_ci| formRecords | Array<[HapFormInfo](#hapforminfo)> | 是 | FA中卡片的使用记录。 | 1610e41f4b71Sopenharmony_ci 1611e41f4b71Sopenharmony_ci## HapFormInfo 1612e41f4b71Sopenharmony_ci 1613e41f4b71Sopenharmony_ciFA卡片的使用信息属性集合。 1614e41f4b71Sopenharmony_ci 1615e41f4b71Sopenharmony_ci**系统能力**:以下各项对应的系统能力均为SystemCapability.ResourceSchedule.UsageStatistics.App 1616e41f4b71Sopenharmony_ci 1617e41f4b71Sopenharmony_ci| 名称 | 类型 | 必填 | 说明 | 1618e41f4b71Sopenharmony_ci| ---------------- | ------ | ---- | ----------- | 1619e41f4b71Sopenharmony_ci| formName | string | 是 | 卡片名称。 | 1620e41f4b71Sopenharmony_ci| formDimension | number | 是 | 卡片尺寸。 | 1621e41f4b71Sopenharmony_ci| formId | number | 是 | 卡片Id。 | 1622e41f4b71Sopenharmony_ci| formLastUsedTime | number | 是 | 卡片的上一次点击时间。 | 1623e41f4b71Sopenharmony_ci| count | number | 是 | 卡片的点击次数。 | 1624e41f4b71Sopenharmony_ci 1625e41f4b71Sopenharmony_ci## AppGroupCallbackInfo 1626e41f4b71Sopenharmony_ci 1627e41f4b71Sopenharmony_ci应用分组变化回调返回的属性集合 1628e41f4b71Sopenharmony_ci 1629e41f4b71Sopenharmony_ci**系统能力**:以下各项对应的系统能力均为SystemCapability.ResourceSchedule.UsageStatistics.AppGroup 1630e41f4b71Sopenharmony_ci 1631e41f4b71Sopenharmony_ci| 名称 | 类型 | 必填 | 说明 | 1632e41f4b71Sopenharmony_ci| ---------------- | ------ | ---- | ---------------- | 1633e41f4b71Sopenharmony_ci| appOldGroup | number | 是 | 变化前的应用分组。 | 1634e41f4b71Sopenharmony_ci| appNewGroup | number | 是 | 变化后的应用分组。| 1635e41f4b71Sopenharmony_ci| userId | number | 是 | 用户id。 | 1636e41f4b71Sopenharmony_ci| changeReason | number | 是 | 分组变化原因。<br>- 256:使用记录初创建时,默认匹配的原因。<br>- 512:计算优先级分组时异常。<br>- 768:使用时长变化。 <br>- 1024:有其他应用为当前应用强制设置优先级分组。| 1637e41f4b71Sopenharmony_ci| bundleName | string | 是 | 应用名称。 | 1638e41f4b71Sopenharmony_ci 1639e41f4b71Sopenharmony_ci## BundleStatsInfo 1640e41f4b71Sopenharmony_ci 1641e41f4b71Sopenharmony_ci应用使用时长的具体信息。 1642e41f4b71Sopenharmony_ci 1643e41f4b71Sopenharmony_ci**系统能力**:以下各项对应的系统能力均为SystemCapability.ResourceSchedule.UsageStatistics.App 1644e41f4b71Sopenharmony_ci 1645e41f4b71Sopenharmony_ci| 名称 | 类型 | 必填 | 说明 | 1646e41f4b71Sopenharmony_ci| ------------------------ | ------ | ---- | ---------------------------------------- | 1647e41f4b71Sopenharmony_ci| bundleName | string | 否 | 应用包名。 | 1648e41f4b71Sopenharmony_ci| abilityPrevAccessTime | number | 否 | 应用最后一次使用的时间。 | 1649e41f4b71Sopenharmony_ci| abilityInFgTotalTime | number | 否 | 应用在前台使用的总时间。 | 1650e41f4b71Sopenharmony_ci| id | number | 是 | 用户id。 | 1651e41f4b71Sopenharmony_ci| abilityPrevSeenTime | number | 否 | 应用最后一次在前台可见的时间。 | 1652e41f4b71Sopenharmony_ci| abilitySeenTotalTime | number | 否 | 应用在前台可见的总时间。 | 1653e41f4b71Sopenharmony_ci| fgAbilityAccessTotalTime | number | 否 | 应用访问前台的总时间。 | 1654e41f4b71Sopenharmony_ci| fgAbilityPrevAccessTime | number | 否 | 应用最后一次访问前台的时间。| 1655e41f4b71Sopenharmony_ci| infosBeginTime | number | 否 | BundleActiveInfo对象中第一条应用使用统计的记录时间。 | 1656e41f4b71Sopenharmony_ci| infosEndTime | number | 否 | BundleActiveInfo对象中最后一条应用使用统计的记录时间。 | 1657e41f4b71Sopenharmony_ci 1658e41f4b71Sopenharmony_ci## BundleEvents 1659e41f4b71Sopenharmony_ci 1660e41f4b71Sopenharmony_ci应用事件的具体信息。 1661e41f4b71Sopenharmony_ci 1662e41f4b71Sopenharmony_ci**系统能力**:以下各项对应的系统能力均为SystemCapability.ResourceSchedule.UsageStatistics.App 1663e41f4b71Sopenharmony_ci 1664e41f4b71Sopenharmony_ci| 名称 | 类型 | 必填 | 说明 | 1665e41f4b71Sopenharmony_ci| --------------------- | ------ | ---- | ---------------------------------------- | 1666e41f4b71Sopenharmony_ci| bundleName | string | 否 | 应用包名。 | 1667e41f4b71Sopenharmony_ci| eventId | number | 否 | 应用事件类型。 | 1668e41f4b71Sopenharmony_ci| eventOccurredTime | number | 否 | 应用事件发生的时间戳。 | 1669e41f4b71Sopenharmony_ci| appGroup | number | 否 | 应用程序的使用优先级组。| 1670e41f4b71Sopenharmony_ci| indexOfLink | string | 否 | 快捷方式id。| 1671e41f4b71Sopenharmony_ci| nameOfClass | string | 否 | 类名。| 1672e41f4b71Sopenharmony_ci 1673e41f4b71Sopenharmony_ci## BundleStatsMap 1674e41f4b71Sopenharmony_ci 1675e41f4b71Sopenharmony_ci应用使用时长的具体信息。 1676e41f4b71Sopenharmony_ci 1677e41f4b71Sopenharmony_ci**系统能力**:SystemCapability.ResourceSchedule.UsageStatistics.App 1678e41f4b71Sopenharmony_ci 1679e41f4b71Sopenharmony_ci|名称 | 描述 | 1680e41f4b71Sopenharmony_ci| ------------------------------ | ---------------------------------------- | 1681e41f4b71Sopenharmony_ci| Record<string, [BundleStatsInfo](#bundlestatsinfo)> | 不同应用的使用时长统计信息 | 1682e41f4b71Sopenharmony_ci 1683e41f4b71Sopenharmony_ci## DeviceEventStats 1684e41f4b71Sopenharmony_ci 1685e41f4b71Sopenharmony_ci提供通知、系统事件的统计信息。 1686e41f4b71Sopenharmony_ci 1687e41f4b71Sopenharmony_ci**系统能力**:以下各项对应的系统能力均为SystemCapability.ResourceSchedule.UsageStatistics.App 1688e41f4b71Sopenharmony_ci 1689e41f4b71Sopenharmony_ci| 名称 | 类型 | 必填 | 说明 | 1690e41f4b71Sopenharmony_ci| ------- | ------ | ---- | ----------------- | 1691e41f4b71Sopenharmony_ci| name | string | 是 | 通知应用包名或者系统事件名。 | 1692e41f4b71Sopenharmony_ci| eventId | number | 是 | 通知、系统事件类型。 | 1693e41f4b71Sopenharmony_ci| count | number | 是 | 应用通知次数或者系统事件触发次数。 | 1694e41f4b71Sopenharmony_ci 1695e41f4b71Sopenharmony_ci## IntervalType 1696e41f4b71Sopenharmony_ci 1697e41f4b71Sopenharmony_ci应用使用时长的查询类型。 1698e41f4b71Sopenharmony_ci 1699e41f4b71Sopenharmony_ci**系统能力**:以下各项对应的系统能力均为SystemCapability.ResourceSchedule.UsageStatistics.App 1700e41f4b71Sopenharmony_ci 1701e41f4b71Sopenharmony_ci| 名称 | 值 | 说明 | 1702e41f4b71Sopenharmony_ci| ------------ | ---- | ---------------------------------------- | 1703e41f4b71Sopenharmony_ci| BY_OPTIMIZED | 0 | 表示系统自行判断最合适的查询类型(天、周、月、年)去查询指定时间段间隔的应用使用时长信息。 | 1704e41f4b71Sopenharmony_ci| BY_DAILY | 1 | 表示系统按照天去查询指定时间段间隔的应用使用时长信息。 | 1705e41f4b71Sopenharmony_ci| BY_WEEKLY | 2 | 表示系统按照周去查询指定时间段间隔的应用使用时长信息。 | 1706e41f4b71Sopenharmony_ci| BY_MONTHLY | 3 | 表示系统按照月去查询指定时间段间隔的应用使用时长信息。 | 1707e41f4b71Sopenharmony_ci| BY_ANNUALLY | 4 | 表示系统按照年去查询指定时间段间隔的应用使用时长信息。 | 1708e41f4b71Sopenharmony_ci 1709e41f4b71Sopenharmony_ci## GroupType 1710e41f4b71Sopenharmony_ci 1711e41f4b71Sopenharmony_ci应用分组的设置类型。 1712e41f4b71Sopenharmony_ci 1713e41f4b71Sopenharmony_ci**系统能力**:以下各项对应的系统能力均为SystemCapability.ResourceSchedule.UsageStatistics.AppGroup 1714e41f4b71Sopenharmony_ci 1715e41f4b71Sopenharmony_ci| 名称 | 值 | 说明 | 1716e41f4b71Sopenharmony_ci| ------------------ | ---- | ----------------- | 1717e41f4b71Sopenharmony_ci| ALIVE_GROUP | 10 | 活跃分组。 | 1718e41f4b71Sopenharmony_ci| DAILY_GROUP | 20 | 经常使用,但当前并未在活跃态。 | 1719e41f4b71Sopenharmony_ci| FIXED_GROUP | 30 | 常用分组,定期使用,但不是每天使用。 | 1720e41f4b71Sopenharmony_ci| RARE_GROUP | 40 | 极少使用分组,不经常使用。 | 1721e41f4b71Sopenharmony_ci| LIMITED_GROUP | 50 | 受限使用分组。 | 1722e41f4b71Sopenharmony_ci| NEVER_GROUP | 60 | 从未使用分组,安装但是从未运行过。 |