1# Device Usage Statistics Development 2 3## When to Use 4 5With device usage statistics APIs, you can have a better understanding of the application, notification, and system usage. For example, in application usage statistics, you can query the application usage, event log, and application group. 6The application records (usage history statistics and event records) cached by components are updated to the database for persistent storage within 30 minutes after an event is reported. 7 8## Available APIs 9Import the **stats** package to implement registration: 10```ts 11import usageStatistics from '@ohos.resourceschedule.usageStatistics'; 12``` 13 14**Table 1** Major APIs for device usage statistics 15 16| API| Description| 17| -------- | -------- | 18| function queryBundleEvents(begin: number, end: number, callback: AsyncCallback<Array<BundleEvents>>): void | Queries events of all applications based on the specified start time and end time.| 19| function queryBundleStatsInfos(begin: number, end: number, callback: AsyncCallback<BundleStatsMap>): void | Queries the application usage duration statistics based on the specified start time and end time.| 20| function queryCurrentBundleEvents(begin: number, end: number, callback: AsyncCallback<Array<BundleEvents>>): void | Queries events of this application based on the specified start time and end time.| 21| function queryBundleStatsInfoByInterval(byInterval: IntervalType, begin: number, end: number, callback: AsyncCallback<Array<BundleStatsInfo>>): void | Queries the application usage duration statistics in the specified time frame at the specified interval (daily, weekly, monthly, or annually).| 22| function queryAppGroup(callback: AsyncCallback<number>): void | Queries the priority group of this application. This API uses an asynchronous callback to return the result.| 23| function queryAppGroup(): Promise<number>; | Queries the priority group of this application. This API uses a promise to return the result.| 24|function queryAppGroupSync(): number; | Queries the priority group of this application. This is a synchronous API.| 25| function queryAppGroup(bundleName : string, callback: AsyncCallback<number>): void | Queries the priority group of the application specified by **bundleName**. This API uses an asynchronous callback to return the result.| 26| function queryAppGroup(bundleName : string): Promise<number>; | Queries the priority group of the application specified by **bundleName**. If **bundleName** is not specified, the priority group of the current application is queried. This API uses a promise to return the result.| 27|function queryAppGroupSync(bundleName: string): number; | Queries the priority group of the application specified by **bundleName**. If **bundleName** is not specified, the priority group of the current application is queried. This is a synchronous API.| 28| function isIdleState(bundleName: string, callback: AsyncCallback<boolean>): void | Checks whether the application specified by **bundleName** is in the idle state. | 29|function isIdleStateSync(bundleName: string): boolean; | Checks whether the application specified by **bundleName** is in the idle state. This is a synchronous API.| 30| function queryModuleUsageRecords(callback: AsyncCallback<HapModuleInfo>): void | Obtains a maximum of 1000 FA usage records.| 31| function queryModuleUsageRecords(maxNum: number, callback: AsyncCallback<HapModuleInfo>): void | Obtains the number of FA usage records specified by **maxNum**, which cannot exceed 1000.| 32| function queryNotificationEventStats(begin: number, end: number, callback: AsyncCallback<Array<DeviceEventStats>>): void | Queries the number of notifications from all applications based on the specified start time and end time.| 33| function queryDeviceEventStats(begin: number, end: number, callback: AsyncCallback<Array<DeviceEventStats>>): void | Queries statistics about system events (hibernation, wakeup, unlocking, and screen locking) that occur between the specified start time and end time.| 34| function setAppGroup(bundleName : string, newGroup: GroupType, callback: AsyncCallback<void>): void | Sets the group for the application specified by **bundleName**. This API uses an asynchronous callback to return the result.| 35| function setAppGroup(bundleName : string, newGroup : GroupType): Promise<void>; | Sets the group for the application specified by **bundleName**. This API uses a promise to return the result.| 36| function registerAppGroupCallBack(groupCallback: Callback<AppGroupCallbackInfo>, callback: AsyncCallback<void>): void | Registers a callback for application group changes. When an application group of the user changes, the change is returned to all applications that have registered the callback. This API uses an asynchronous callback to return the result.| 37| function registerAppGroupCallBack(groupCallback: Callback<AppGroupCallbackInfo>): Promise<void>; | Registers a callback for application group changes. When an application group of the user changes, the change is returned to all applications that have registered the callback. This API uses a promise to return the result.| 38| function unregisterAppGroupCallBack(callback: AsyncCallback<void>): void | Deregisters the callback for application group changes. This API uses an asynchronous callback to return the result.| 39| function unregisterAppGroupCallBack(): Promise<void>; | Deregisters the callback for application group changes. This API uses a promise to return the result.| 40 41## How to Develop 42 431. Before obtaining the device usage statistics, check whether the **ohos.permission.BUNDLE_ACTIVE_INFO** permission is configured. 44 45 For details about how to configure a permission, see [Declaring Permissions](../security/accesstoken-guidelines.md). 46 472. Query events of all applications based on the specified start time and end time. This requires the **ohos.permission.BUNDLE_ACTIVE_INFO** permission to be configured. 48 49 ```ts 50 import { BusinessError } from '@ohos.base'; 51 52 // Promise mode 53 usageStatistics.queryBundleEvents(0, 20000000000000).then( (res : Array<usageStatistics.BundleEvents>) => { 54 console.log('BUNDLE_ACTIVE queryBundleEvents promise success.'); 55 for (let i = 0; i < res.length; i++) { 56 console.log('BUNDLE_ACTIVE queryBundleEvents promise number : ' + (i + 1)); 57 console.log('BUNDLE_ACTIVE queryBundleEvents promise result ' + JSON.stringify(res[i])); 58 } 59 }).catch((err : BusinessError)=> { 60 console.log('BUNDLE_ACTIVE queryBundleEvents promise failed. code is: ' + err.code + ',message is: ' + err.message); 61 }); 62 63 // Asynchronous callback mode 64 usageStatistics.queryBundleEvents(0, 20000000000000, (err : BusinessError, res : Array<usageStatistics.BundleEvents>) => { 65 if (err) { 66 console.log('BUNDLE_ACTIVE queryBundleEvents callback failed. code is: ' + err.code + ',message is: ' + err.message); 67 } else { 68 console.log('BUNDLE_ACTIVE queryBundleEvents callback success.'); 69 for (let i = 0; i < res.length; i++) { 70 console.log('BUNDLE_ACTIVE queryBundleEvents callback number : ' + (i + 1)); 71 console.log('BUNDLE_ACTIVE queryBundleEvents callback result ' + JSON.stringify(res[i])); 72 } 73 } 74 }); 75 ``` 76 773. Query the application usage duration statistics based on the specified start time and end time. This requires the **ohos.permission.BUNDLE_ACTIVE_INFO** permission to be configured. 78 79 ```ts 80 import { BusinessError } from '@ohos.base'; 81 82 // Promise mode 83 usageStatistics.queryBundleStatsInfos(0, 20000000000000).then( (res : usageStatistics.BundleStatsMap) => { 84 console.log('BUNDLE_ACTIVE queryBundleStatsInfos promise success.'); 85 console.log('BUNDLE_ACTIVE queryBundleStatsInfos callback result ' + JSON.stringify(res)); 86 }).catch( (err : BusinessError) => { 87 console.log('BUNDLE_ACTIVE queryBundleStatsInfos promise failed. code is: ' + err.code + ',message is: ' + err.message); 88 }); 89 90 // Asynchronous callback mode 91 usageStatistics.queryBundleStatsInfos(0, 20000000000000, (err : BusinessError, res : usageStatistics.BundleStatsMap) => { 92 if (err) { 93 console.log('BUNDLE_ACTIVE queryBundleStatsInfos callback failed. code is: ' + err.code + ',message is: ' + err.message); 94 } else { 95 console.log('BUNDLE_ACTIVE queryBundleStatsInfos callback success.'); 96 console.log('BUNDLE_ACTIVE queryBundleStatsInfos callback result ' + JSON.stringify(res)); 97 } 98 }); 99 ``` 100 1014. Query events of this application based on the specified start time and end time. This requires no permission to be configured. 102 103 ```ts 104 import { BusinessError } from '@ohos.base'; 105 106 // Promise mode 107 usageStatistics.queryCurrentBundleEvents(0, 20000000000000).then( (res : Array<usageStatistics.BundleEvents>) => { 108 console.log('BUNDLE_ACTIVE queryCurrentBundleEvents promise success.'); 109 for (let i = 0; i < res.length; i++) { 110 console.log('BUNDLE_ACTIVE queryCurrentBundleEvents promise number : ' + (i + 1)); 111 console.log('BUNDLE_ACTIVE queryCurrentBundleEvents promise result ' + JSON.stringify(res[i])); 112 } 113 }).catch( (err : BusinessError) => { 114 console.log('BUNDLE_ACTIVE queryCurrentBundleEvents promise failed. code is: ' + err.code + ',message is: ' + err.message); 115 }); 116 117 // Asynchronous callback mode 118 usageStatistics.queryCurrentBundleEvents(0, 20000000000000, (err : BusinessError, res : Array<usageStatistics.BundleEvents>) => { 119 if (err) { 120 console.log('BUNDLE_ACTIVE queryCurrentBundleEvents callback failed. code is: ' + err.code + ',message is: ' + err.message); 121 } else { 122 console.log('BUNDLE_ACTIVE queryCurrentBundleEvents callback success.'); 123 for (let i = 0; i < res.length; i++) { 124 console.log('BUNDLE_ACTIVE queryCurrentBundleEvents callback number : ' + (i + 1)); 125 console.log('BUNDLE_ACTIVE queryCurrentBundleEvents callback result ' + JSON.stringify(res[i])); 126 } 127 } 128 }); 129 ``` 130 1315. Query the application usage duration statistics in the specified time frame at the specified interval (daily, weekly, monthly, or annually). This requires the **ohos.permission.BUNDLE_ACTIVE_INFO** permission to be configured. 132 133 ```ts 134 import { BusinessError } from '@ohos.base'; 135 136 // Promise mode 137 usageStatistics.queryBundleStatsInfoByInterval(0, 0, 20000000000000).then( (res : Array<usageStatistics.BundleStatsInfo>) => { 138 console.log('BUNDLE_ACTIVE queryBundleStatsInfoByInterval promise success.'); 139 for (let i = 0; i < res.length; i++) { 140 console.log('BUNDLE_ACTIVE queryBundleStatsInfoByInterval promise number : ' + (i + 1)); 141 console.log('BUNDLE_ACTIVE queryBundleStatsInfoByInterval promise result ' + JSON.stringify(res[i])); 142 } 143 }).catch( (err : BusinessError) => { 144 console.log('BUNDLE_ACTIVE queryBundleStatsInfoByInterval promise failed. code is: ' + err.code + ',message is: ' + err.message); 145 }); 146 147 // Asynchronous callback mode 148 149 usageStatistics.queryBundleStatsInfoByInterval(0, 0, 20000000000000, (err : BusinessError, res : Array<usageStatistics.BundleStatsInfo>) => { 150 if (err) { 151 console.log('BUNDLE_ACTIVE queryBundleStatsInfoByInterval callback failed. code is: ' + err.code + ',message is: ' + err.message); 152 } else { 153 console.log('BUNDLE_ACTIVE queryBundleStatsInfoByInterval callback success.'); 154 for (let i = 0; i < res.length; i++) { 155 console.log('BUNDLE_ACTIVE queryBundleStatsInfoByInterval callback number : ' + (i + 1)); 156 console.log('BUNDLE_ACTIVE queryBundleStatsInfoByInterval callback result ' + JSON.stringify(res[i])); 157 } 158 } 159 }); 160 ``` 161 1626. Query the priority group of the current application. This requires no permission to be configured. 163 164 ```ts 165 import { BusinessError } from '@ohos.base'; 166 167 // Promise mode 168 usageStatistics.queryAppGroup().then( (res : number) => { 169 console.log('BUNDLE_ACTIVE queryAppGroup promise succeeded. result: ' + JSON.stringify(res)); 170 }).catch( (err : BusinessError) => { 171 console.log('BUNDLE_ACTIVE queryAppGroup promise failed. code is: ' + err.code + ',message is: ' + err.message); 172 }); 173 174 // Callback mode 175 usageStatistics.queryAppGroup((err : BusinessError, res : number) => { 176 if(err) { 177 console.log('BUNDLE_ACTIVE queryAppGroup callback failed. code is: ' + err.code + ',message is: ' + err.message); 178 } else { 179 console.log('BUNDLE_ACTIVE queryAppGroup callback succeeded. result: ' + JSON.stringify(res)); 180 } 181 }); 182 183 // Synchronous API 184 let priorityGroup = usageStatistics.queryAppGroupSync(); 185 186 ``` 187 1887. Check whether the application specified by **bundleName** is in the idle state. This requires the **ohos.permission.BUNDLE_ACTIVE_INFO** permission to be configured. 189 190 ```ts 191 import { BusinessError } from '@ohos.base'; 192 193 // Promise mode 194 usageStatistics.isIdleState("com.ohos.camera").then( (res : boolean) => { 195 console.log('BUNDLE_ACTIVE isIdleState promise succeeded, result: ' + JSON.stringify(res)); 196 }).catch( (err : BusinessError) => { 197 console.log('BUNDLE_ACTIVE isIdleState promise failed. code is: ' + err.code + ',message is: ' + err.message); 198 }); 199 200 // Asynchronous callback mode 201 usageStatistics.isIdleState("com.ohos.camera", (err : BusinessError, res : boolean) => { 202 if (err) { 203 console.log('BUNDLE_ACTIVE isIdleState callback failed. code is: ' + err.code + ',message is: ' + err.message); 204 } else { 205 console.log('BUNDLE_ACTIVE isIdleState callback succeeded, result: ' + JSON.stringify(res)); 206 } 207 }); 208 209 // Synchronous API 210 let isIdleState = usageStatistics.isIdleStateSync("com.ohos.camera"); 211 ``` 212 2138. Obtain the number of FA usage records specified by **maxNum**. If **maxNum** is not specified, the default value **1000** is used. This requires the **ohos.permission.BUNDLE_ACTIVE_INFO** permission to be configured. 214 215 ```ts 216 import { BusinessError } from '@ohos.base'; 217 218 // Promise mode 219 usageStatistics.queryModuleUsageRecords(1000).then( (res : Array<usageStatistics.HapModuleInfo>) => { 220 console.log('BUNDLE_ACTIVE queryModuleUsageRecords promise succeeded'); 221 for (let i = 0; i < res.length; i++) { 222 console.log('BUNDLE_ACTIVE queryModuleUsageRecords promise number : ' + (i + 1)); 223 console.log('BUNDLE_ACTIVE queryModuleUsageRecords promise result ' + JSON.stringify(res[i])); 224 } 225 }).catch( (err : BusinessError)=> { 226 console.log('BUNDLE_ACTIVE queryModuleUsageRecords promise failed. code is: ' + err.code + ',message is: ' + err.message); 227 }); 228 229 // Promise mode when maxNum is not specified 230 usageStatistics.queryModuleUsageRecords().then( (res : Array<usageStatistics.HapModuleInfo>) => { 231 console.log('BUNDLE_ACTIVE queryModuleUsageRecords promise succeeded'); 232 for (let i = 0; i < res.length; i++) { 233 console.log('BUNDLE_ACTIVE queryModuleUsageRecords promise number : ' + (i + 1)); 234 console.log('BUNDLE_ACTIVE queryModuleUsageRecords promise result ' + JSON.stringify(res[i])); 235 } 236 }).catch( (err : BusinessError)=> { 237 console.log('BUNDLE_ACTIVE queryModuleUsageRecords promise failed. code is: ' + err.code + ',message is: ' + err.message); 238 }); 239 240 // Asynchronous callback mode 241 usageStatistics.queryModuleUsageRecords(1000, (err : BusinessError, res : Array<usageStatistics.HapModuleInfo>) => { 242 if(err) { 243 console.log('BUNDLE_ACTIVE queryModuleUsageRecords callback failed. code is: ' + err.code + ',message is: ' + err.message); 244 } else { 245 console.log('BUNDLE_ACTIVE queryModuleUsageRecords callback succeeded.'); 246 for (let i = 0; i < res.length; i++) { 247 console.log('BUNDLE_ACTIVE queryModuleUsageRecords callback number : ' + (i + 1)); 248 console.log('BUNDLE_ACTIVE queryModuleUsageRecords callback result ' + JSON.stringify(res[i])); 249 } 250 } 251 }); 252 253 // Asynchronous callback mode when maxNum is not specified 254 usageStatistics.queryModuleUsageRecords((err : BusinessError, res : Array<usageStatistics.HapModuleInfo>) => { 255 if(err) { 256 console.log('BUNDLE_ACTIVE queryModuleUsageRecords callback failed. code is: ' + err.code + ',message is: ' + err.message); 257 } else { 258 console.log('BUNDLE_ACTIVE queryModuleUsageRecords callback succeeded.'); 259 for (let i = 0; i < res.length; i++) { 260 console.log('BUNDLE_ACTIVE queryModuleUsageRecords callback number : ' + (i + 1)); 261 console.log('BUNDLE_ACTIVE queryModuleUsageRecords callback result ' + JSON.stringify(res[i])); 262 } 263 } 264 }); 265 ``` 266 2679. Query the number of notifications from all applications based on the specified start time and end time. This requires the **ohos.permission.BUNDLE_ACTIVE_INFO** permission to be configured. 268 269 ```ts 270 import { BusinessError } from '@ohos.base'; 271 272 // Promise mode 273 usageStatistics.queryNotificationEventStats(0, 20000000000000).then( (res : Array<usageStatistics.DeviceEventStats>) => { 274 console.log('BUNDLE_ACTIVE queryNotificationEventStats promise success.'); 275 console.log('BUNDLE_ACTIVE queryNotificationEventStats promise result ' + JSON.stringify(res)); 276 }).catch( (err : BusinessError) => { 277 console.log('BUNDLE_ACTIVE queryNotificationEventStats promise failed. code is: ' + err.code + ',message is: ' + err.message); 278 }); 279 280 // Asynchronous callback mode 281 usageStatistics.queryNotificationEventStats(0, 20000000000000, (err : BusinessError, res : Array<usageStatistics.DeviceEventStats>) => { 282 if(err) { 283 console.log('BUNDLE_ACTIVE queryNotificationEventStats callback failed. code is: ' + err.code + ',message is: ' + err.message); 284 } else { 285 console.log('BUNDLE_ACTIVE queryNotificationEventStats callback success.'); 286 console.log('BUNDLE_ACTIVE queryNotificationEventStats callback result ' + JSON.stringify(res)); 287 } 288 }); 289 ``` 290 29110. Query statistics about system events (hibernation, wakeup, unlocking, and screen locking) that occur between the specified start time and end time. This requires the **ohos.permission.BUNDLE_ACTIVE_INFO** permission to be configured. 292 293 ```ts 294 import { BusinessError } from '@ohos.base'; 295 296 // Promise mode 297 usageStatistics.queryDeviceEventStats(0, 20000000000000).then( (res : Array<usageStatistics.DeviceEventStats>) => { 298 console.log('BUNDLE_ACTIVE queryDeviceEventStates promise success.'); 299 console.log('BUNDLE_ACTIVE queryDeviceEventStates promise result ' + JSON.stringify(res)); 300 }).catch( (err : BusinessError) => { 301 console.log('BUNDLE_ACTIVE queryDeviceEventStats promise failed. code is: ' + err.code + ',message is: ' + err.message); 302 }); 303 304 // Asynchronous callback mode 305 usageStatistics.queryDeviceEventStats(0, 20000000000000, (err : BusinessError, res : Array<usageStatistics.DeviceEventStats>) => { 306 if(err) { 307 console.log('BUNDLE_ACTIVE queryDeviceEventStats callback failed. code is: ' + err.code + ',message is: ' + err.message); 308 } else { 309 console.log('BUNDLE_ACTIVE queryDeviceEventStats callback success.'); 310 console.log('BUNDLE_ACTIVE queryDeviceEventStats callback result ' + JSON.stringify(res)); 311 } 312 }); 313 ``` 314 31511. Query the priority group of the application specified by **bundleName**. This requires the **ohos.permission.BUNDLE_ACTIVE_INFO** permission to be configured. 316 317 ```ts 318 import { BusinessError } from '@ohos.base'; 319 320 // Promise mode when bundleName is specified 321 let bundleName = "com.ohos.camera"; 322 usageStatistics.queryAppGroup(bundleName).then( (res : number) => { 323 console.log('BUNDLE_ACTIVE queryAppGroup promise succeeded. result: ' + JSON.stringify(res)); 324 }).catch( (err : BusinessError) => { 325 console.log('BUNDLE_ACTIVE queryAppGroup promise failed. code is: ' + err.code + ',message is: ' + err.message); 326 }); 327 328 // Asynchronous callback mode when bundleName is specified 329 let bundleName = "com.ohos.camera"; 330 usageStatistics.queryAppGroup(bundleName, (err : BusinessError, res : number) => { 331 if(err) { 332 console.log('BUNDLE_ACTIVE queryAppGroup callback failed. code is: ' + err.code + ',message is: ' + err.message); 333 } else { 334 console.log('BUNDLE_ACTIVE queryAppGroup callback succeeded. result: ' + JSON.stringify(res)); 335 } 336 }); 337 ``` 338 33912. Set the priority group of for application specified by **bundleName**. This requires the **ohos.permission.BUNDLE_ACTIVE_INFO** permission to be configured. 340 341 ```ts 342 import { BusinessError } from '@ohos.base'; 343 344 // Promise mode 345 let bundleName = "com.example.deviceUsageStatistics"; 346 let newGroup = usageStatistics.GroupType.DAILY_GROUP; 347 348 usageStatistics.setAppGroup(bundleName, newGroup).then( () => { 349 console.log('BUNDLE_ACTIVE setAppGroup promise succeeded.'); 350 }).catch( (err : BusinessError) => { 351 console.log('BUNDLE_ACTIVE setAppGroup promise failed. code is: ' + err.code + ',message is: ' + err.message); 352 }); 353 354 // Asynchronous callback mode 355 let bundleName = "com.example.deviceUsageStatistics"; 356 let newGroup = usageStatistics.GroupType.DAILY_GROUP; 357 usageStatistics.setAppGroup(bundleName, newGroup, (err : BusinessError) => { 358 if(err) { 359 console.log('BUNDLE_ACTIVE setAppGroup callback failed. code is: ' + err.code + ',message is: ' + err.message); 360 } else { 361 console.log('BUNDLE_ACTIVE setAppGroup callback succeeded.'); 362 } 363 }); 364 ``` 365 36613. Register a callback for application group changes. When an application group of the user changes, the change is returned to all applications that have registered the callback. This requires the **ohos.permission.BUNDLE_ACTIVE_INFO** permission to be configured. 367 368 ```ts 369 import { BusinessError } from '@ohos.base'; 370 371 // Promise mode 372 function onBundleGroupChanged (res : usageStatistics.AppGroupCallbackInfo) { 373 console.log('BUNDLE_ACTIVE registerAppGroupCallBack RegisterGroupCallBack callback success.'); 374 console.log('BUNDLE_ACTIVE registerAppGroupCallBack result appOldGroup is : ' + res.appOldGroup); 375 console.log('BUNDLE_ACTIVE registerAppGroupCallBack result appNewGroup is : ' + res.appNewGroup); 376 console.log('BUNDLE_ACTIVE registerAppGroupCallBack result changeReason is : ' + res.changeReason); 377 console.log('BUNDLE_ACTIVE registerAppGroupCallBack result userId is : ' + res.userId); 378 console.log('BUNDLE_ACTIVE registerAppGroupCallBack result bundleName is : ' + res.bundleName); 379 }; 380 usageStatistics.registerAppGroupCallBack(onBundleGroupChanged).then( () => { 381 console.log('BUNDLE_ACTIVE registerAppGroupCallBack promise succeeded.'); 382 }).catch( (err : BusinessError) => { 383 console.log('BUNDLE_ACTIVE registerAppGroupCallBack promise failed. code is: ' + err.code + ',message is: ' + err.message); 384 }); 385 386 // Asynchronous callback mode 387 function onBundleGroupChanged (res : usageStatistics.AppGroupCallbackInfo) { 388 console.log('BUNDLE_ACTIVE onBundleGroupChanged RegisterGroupCallBack callback success.'); 389 console.log('BUNDLE_ACTIVE registerAppGroupCallBack result appOldGroup is : ' + res.appOldGroup); 390 console.log('BUNDLE_ACTIVE registerAppGroupCallBack result appNewGroup is : ' + res.appNewGroup); 391 console.log('BUNDLE_ACTIVE registerAppGroupCallBack result changeReason is : ' + res.changeReason); 392 console.log('BUNDLE_ACTIVE registerAppGroupCallBack result userId is : ' + res.userId); 393 console.log('BUNDLE_ACTIVE registerAppGroupCallBack result bundleName is : ' + res.bundleName); 394 }; 395 usageStatistics.registerAppGroupCallBack(onBundleGroupChanged, (err : BusinessError) => { 396 if(err) { 397 console.log('BUNDLE_ACTIVE registerAppGroupCallBack callback failed. code is: ' + err.code + ',message is: ' + err.message); 398 } else { 399 console.log('BUNDLE_ACTIVE registerAppGroupCallBack callback success.'); 400 } 401 }); 402 ``` 403 40414. Deregister the callback for application group changes. This requires the **ohos.permission.BUNDLE_ACTIVE_INFO** permission to be configured. 405 406 ```ts 407 import { BusinessError } from '@ohos.base'; 408 409 // promise 410 usageStatistics.unregisterAppGroupCallBack().then( () => { 411 console.log('BUNDLE_ACTIVE unregisterAppGroupCallBack promise succeeded.'); 412 }).catch( (err : BusinessError) => { 413 console.log('BUNDLE_ACTIVE unregisterAppGroupCallBack promise failed. code is: ' + err.code + ',message is: ' + err.message); 414 }); 415 416 // callback 417 usageStatistics.unregisterAppGroupCallBack((err : BusinessError) => { 418 if(err) { 419 console.log('BUNDLE_ACTIVE unregisterAppGroupCallBack callback failed. code is: ' + err.code + ',message is: ' + err.message); 420 } else { 421 console.log('BUNDLE_ACTIVE unregisterAppGroupCallBack callback success.'); 422 } 423 }); 424 ``` 425