The Android Management API (AMAPI) SDK enables specific apps to communicate directly with Android Device Policy (ADP). It includes support for:
- Local execution of Commands
- Migrate devices managed with a custom DPC to AMAPI
- Device Trust from Android Enterprise
- New device enrollment flow that also supports adding managed Google Accounts
- Manage custom apps with AMAPI
- Manage application roles.
The following steps must be taken to integrate the AMAPI SDK with your application:
- Add the AMAPI SDK library.
- Add the queries element, if target SDK >= 30.
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 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 for more information.
Implement a NotificationReceiverService
Some features require creating a
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 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.