1# EnterpriseAdminExtensionAbility Development 2 3## Introduction 4 5**EnterpriseAdminExtensionAbility** is an essential component for device administrator applications. When developing a Mobile Device Management (MDM) application, you need to create an **EnterpriseAdminExtensionAbility** instance and implement MDM service logic in this instance. The **EnterpriseAdminExtensionAbility** instance implements notifications of system management status changes and defines the related callbacks to be invoked when a device administrator application is enabled or disabled or when an application is installed or uninstalled. 6 7### Available APIs 8 9| Class | API | Description | 10| ------------------------------- | ----------------------------------------- | ---------------------------- | 11| EnterpriseAdminExtensionAbility | onAdminEnabled(): void | Called when a device administrator application is disabled. | 12| EnterpriseAdminExtensionAbility | onAdminDisabled(): void | Called when a device administrator application is disabled. | 13| EnterpriseAdminExtensionAbility | onBundleAdded(bundleName: string): void | Called when an MDM application is installed. | 14| EnterpriseAdminExtensionAbility | onBundleRemoved(bundleName: string): void | Called when an MDM application is uninstalled. | 15 16**onAdminEnabled**: This callback is invoked when an enterprise administrator or employee deploys an MDM application and activates the device administrator. The system notifies the device administrator application that the DeviceAdmin permission has been activated. The device administrator application can set initialization policies in the **onAdminEnabled** callback. 17 18**onAdminDisabled**: This callback is invoked when the system or an employee deactivates the device administrator. It notifies the application that the DeviceAdmin permission is revoked. The application can inform the enterprise administrator that the device is not under management. 19 20**onBundleAdded**: The enterprise administrator can subscribe to application installation events. When an application is installed on an enterprise device, the device administrator application reports the event in this callback to notify the enterprise administrator. 21 22**onBundleRemoved**: The enterprise administrator can subscribe to application uninstallation events. When an application is uninstalled from an enterprise device, the device administrator application reports the event in this callback to notify the enterprise administrator. 23 24## How to Develop 25 261. Create a project. 27 28 The project structure is as follows: 29 30  31 322. Create an **ExtensionAbility** of the **EnterpriseAdmin** type, that is, an **EnterpriseAdminExtensionAbility** instance. 33 34  35 363. Open the **EnterpriseAdminAbility.ets** file, import the **EnterpriseAdminExtensionAbility** module, enable it to inherit from the **EnterpriseAdminExtensionAbility** module, and define callbacks such as **onAdminEnabled()** and **onAdminDisabled()**. When the device administrator application is enabled or disabled, the callback will be invoked to receive notifications. 37 38 ```ts 39 import { EnterpriseAdminExtensionAbility } from '@kit.MDMKit'; 40 41 export default class EnterpriseAdminAbility extends EnterpriseAdminExtensionAbility { 42 // Callback to be invoked when the device administrator application is enabled. Initialization policy can be set in this callback. 43 onAdminEnabled() { 44 console.info("onAdminEnabled"); 45 } 46 47 // Callback to be invoked when the device administrator application is disabled. This callback can be used to notify the enterprise administrator application that the device is no longer under management. 48 onAdminDisabled() { 49 console.info("onAdminDisabled"); 50 } 51 52 // Callback to be invoked when an application is installed. This callback can be used to report events. 53 onBundleAdded(bundleName: string) { 54 console.info("EnterpriseAdminAbility onBundleAdded bundleName:" + bundleName); 55 } 56 57 // Callback to be invoked when an application is uninstalled. This callback can be used to report events. 58 onBundleRemoved(bundleName: string) { 59 console.info("EnterpriseAdminAbility onBundleRemoved bundleName" + bundleName); 60 } 61 }; 62 ``` 63 644. In the [module.json5](https://developer.huawei.com/consumer/en/doc/harmonyos-guides-V2/module-configuration-file-0000001427744540-V2) file of the project module, register **EnterpriseAdminAbility** as **ExtensionAbility**, and set type to **enterpriseAdmin** and **srcEntry** to the code path of the **ExtensionAbility** component. 65 66```ts 67"extensionAbilities": [ 68 { 69 "name": "EnterpriseAdminAbility", 70 "type": "enterpriseAdmin", 71 "exported": true, 72 "srcEntry": "./ets/enterpriseadminability/EnterpriseAdminAbility.ets" 73 } 74] 75``` 76 77