1# @ohos.bundle.bundleMonitor (bundleMonitor) 2 3The **Bundle.bundleMonitor** module provides APIs for listens for bundle installation, uninstall, and updates. 4 5> **NOTE** 6> 7> The initial APIs of this module are supported since API version 9. Newly added APIs will be marked with a superscript to indicate their earliest API version. 8 9## Modules to Import 10 11```ts 12import bundleMonitor from '@ohos.bundle.bundleMonitor'; 13``` 14 15## Required Permissions 16 17| Permission | Permission Level | Description | 18| ------------------------------------ | ----------- | ------------------------------ | 19| ohos.permission.LISTEN_BUNDLE_CHANGE | system_core | Permission to listen for bundle installation, uninstall, and updates.| 20 21For details, see [Permission Levels](../../security/accesstoken-overview.md). 22 23## BundleChangeInfo 24 25**System capability**: SystemCapability.BundleManager.BundleFramework.Core 26 27**System API**: This is a system API and cannot be called by third-party applications. 28 29| Name | Template | Readable| Writable| Description | 30| ---------- | ------ | ---- | ---- | -------------------------- | 31| bundleName | string | Yes | No | Name of the bundle whose status changes.| 32| userId | number | Yes | No | ID of the user whose bundle status changes. | 33 34## bundleMonitor.on 35 36on(type: BundleChangedEvent, callback: Callback\<BundleChangedInfo>): void; 37 38Subscribes to bundle installation, uninstall, and update events. 39 40**Required permissions**: ohos.permission.LISTEN_BUNDLE_CHANGE 41 42**System API**: This is a system API and cannot be called by third-party applications. 43 44**System capability**: SystemCapability.BundleManager.BundleFramework.Core 45 46**Parameters** 47 48| Name | Type | Mandatory| Description | 49| ---------------------------- | -------- | ---- | ------------------ | 50| type| BundleChangedEvent| Yes | Type of the event to subscribe to.| 51| callback | callback\<BundleChangedInfo>| Yes | Callback used for the subscription.| 52 53**Example** 54 55```ts 56import bundleMonitor from '@ohos.bundle.bundleMonitor'; 57 58try { 59 bundleMonitor.on('add', (bundleChangeInfo) => { 60 console.info(`bundleName : ${bundleChangeInfo.bundleName} userId : ${bundleChangeInfo.userId}`); 61 }) 62} catch (errData) { 63 console.log(`errData is errCode:${errData.errCode} message:${errData.message}`); 64} 65``` 66 67## bundleMonitor.off 68 69off(type: BundleChangedEvent, callback?: Callback\<BundleChangedInfo>): void; 70 71Unsubscribes from bundle installation, uninstall, and update events. 72 73**Required permissions**: ohos.permission.LISTEN_BUNDLE_CHANGE 74 75**System API**: This is a system API and cannot be called by third-party applications. 76 77**System capability**: SystemCapability.BundleManager.BundleFramework.Core 78 79**Parameters** 80 81| Name | Type | Mandatory| Description | 82| ---------------------------- | -------- | ---- | ---------------------------------------------------------- | 83| type| BundleChangedEvent| Yes | Type of the event to unsubscribe from. | 84| callback | callback\<BundleChangedInfo>| No | Callback used for the unsubscription. If this parameter is left empty, all callbacks of the current event are unsubscribed from.| 85 86**Example** 87 88```ts 89import bundleMonitor from '@ohos.bundle.bundleMonitor'; 90 91try { 92 bundleMonitor.off('add'); 93} catch (errData) { 94 console.log(`errData is errCode:${errData.errCode} message:${errData.message}`); 95} 96``` 97