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