The [Android Management API (AMAPI) SDK](https://maven.google.com/web/index.html#com.google.android.libraries.enterprise.amapi) enables specific apps to
communicate directly with Android Device Policy (ADP). It includes support for:

- [Local execution of Commands](https://developers.google.com/android/management/sdk-local-commands)
- [Migrate devices managed with a custom DPC to AMAPI](https://developers.google.com/android/management/dpc-migration)
- [Device Trust from Android Enterprise](https://developers.google.com/android/management/device-trust-api)
- New device enrollment flow that also supports adding managed Google Accounts
- [Manage custom apps with AMAPI](https://developers.google.com/android/management/manage-custom-apps)
- [Manage application roles](https://developers.google.com/android/management/app-roles).
- [Manage updates with Unified Update Controls](https://developers.google.com/android/management/unified-update-controls-sdk).
- Read device EID.

The following steps must be taken to integrate the AMAPI SDK with your
application:

1. [Add the AMAPI SDK library](https://developers.google.com/android/management/sdk-release-notes#declare_dependencies).
2. [Add the queries element](https://developers.google.com/android/management/sdk-integration#add_queries), if target SDK \>= 30.

> [!NOTE]
> **Note:** If you are developing an extension app, you will also need to provision the device with an [extensibility policy](https://developers.google.com/android/management/sdk-local-commands#policy).

## Prerequisites

- Verify that your app's `minSdkVersion` is set to at least API level 21.
- Add the dependencies for the latest version of the AMAPI SDK to your application. You can find the version of the latest available library, and how to add it to your application, in the [AMAPI SDK's release notes](https://developers.google.com/android/management/sdk-release-notes) page.

### Add queries element

If your app targets SDK 30 or later, then queries element is needed in the
`AndroidManifest.xml` to specify that it will interact with ADP.

    <queries>
        <package android:name="com.google.android.apps.work.clouddpc" />
    </queries>

See [Package visibility filtering on Android](https://developer.android.com/training/package-visibility) for more information.

### Implement a NotificationReceiverService

Some features require creating a
[`NotificationReceiverService`](https://developers.google.com/android/management/reference/amapi/com/google/android/managementapi/notification/NotificationReceiverService), and some features
make optional use of it. To use it, define a class extending
`NotificationReceiverService`, add it as a `service` to your
`AndroidManifest.xml`, and make sure it is exported.


    import com.google.android.managementapi.notification.NotificationReceiverService;

    ...

    public final class MyAppNotificationReceiverService extends NotificationReceiverService {

      @Override
      protected void setupInjection() {
        // This method can be optionally used to inject dependencies at the
        // beginning of the service lifecycle.
      }
    }

You must provide the ADP app with the `ComponentName` of your
`NotificationReceiverService` class. There are two approaches for doing this.
The documentation for each feature specifies which approach to use.

#### Explicit API

In this case, the `ComponentName` is passed to the ADP app through a suitable
API. The documentation of the feature in question has the details.
In your `AndroidManifest.xml`, add:

    <service
     android:name = ".MyAppNotificationReceiverService"
     android:exported = "true" />

#### Automatic discovery

With this approach, you must tag your service so that it can be automatically
discovered. In your `AndroidManifest.xml`, add:

    <service
     android:name = ".MyAppNotificationReceiverService"
     android:exported = "true" >
        <meta-data android:name="Insert name here" android:value=""/>
    </service>

The specific string to use for `android:name` of the `meta-data` is documented
for each feature which uses this approach (see
[Manage application roles](https://developers.google.com/android/management/app-roles) for an example).
For this tagging to be valid, your app must have exactly one service which is
enabled and has `meta-data` whose `android:name` is this specific string and
`android:value` is an empty string. You can add multiple `meta-data` to the same
service.

> [!IMPORTANT]
> **Key Point:** In both cases the service must have `android:exported` set to `true`.

> [!NOTE]
> **Note:** The `NotificationReceiverService` base class automatically handles security protections. It ensures that only the Android Device Policy (ADP) app can securely communicate with this service. You don't need to declare a custom `BIND` permission or manually verify the calling package.