Update Your App Manifest
Updating yourAndroidManifest.xml file is the first step in receiving messages sent via ADM. Make the following changes to your existing file:
-
Open your
AndroidManifest.xmlfile and add the Amazon namespace: -
To declare the permissions necessary to support ADM, after the
manifestelement, add thepermissionanduses-permissionelements. -
Explicitly enable ADM and declare whether your app requires ADM (
android:required="true") or can work without ADM being present (android:required="false"). If you specifyandroid:required="false", your app must degrade gracefully if ADM is unavailable. In theapplicationnode of the manifest, add theamazon:enable-featureelement . -
Declare a broadcast receiver to handle the
REGISTRATIONandRECEIVEintents that ADM sends. ADM requires that the receiver be defined in the AndroidManifest.xml file, rather than programmatically. Immediately afteramazon:enable-featureadd the following elements. -
After updating your AndroidManifest.xml file, you can confirm that the changes are correct for ADM by calling
ADMManifest.checkManifestAuthoredProperly(). If you receive ajava.lang.NoClassDefFoundError: com.amazon.device.messaging.ADMerror, check your manifest to verify that you have added theamazon:enable-featureelement in the location specified in step 3.
Implement Handling for Registration and Messages
The broadcast receiver declared in your manifest both listens for intents and invokes your app when intents arrive. Your app communicates with the broadcast receiver via the following callback methods defined in thecom.amazon.device.messaging.ADMMessageHandlerBase class:
-
onRegistered. Called when the registration ID for the app instance is ready. Your app must transmit this registration ID to your server. Doing so enables your server to send messages to the app instance. -
onUnregistered. Called if your app instance becomes unregistered from ADM. -
onRegistrationError. Called if your app’s ADM registration request fails for any reason, such as no Amazon user being signed in to the device. -
onMessage. Called when the ADM Client delivers a message to your app instance.
com.amazon.device.messaging.ADMMessageHandlerBase and com.amazon.device.messaging.ADMMessageReceiver, as shown in the following code sample:
Gracefully Degrade If ADM Is Unavailable
In your manifest file, you declare whether your app can (android:required="false") or cannot (android:required="true") work without ADM. If you specify android:required="false", your app must degrade gracefully if ADM is unavailable.
Designing your app to accommodate the absence of ADM allows you to build a single APK that can be installed and run on devices that may or may not include ADM.
To modify your app to gracefully degrade
-
Use code similar to the following to check for ADM.
-
Add the following code to any of your code that requires the ADM library runtime.
-
In your AndroidManifest.xml file, verify that the application element specifies:
Alternatives to ADM
Instead of using ADM to send instructions from your Lambda function to your app, you can also send actions to your app using your own protocol and cloud service. With this option, you own the delivery of commands to your app. The protocol and characteristics of the communication are entirely up to you and can be managed from your Lambda code or from a service call into your infrastructure. This approach requires an identifier unique to this instance of the application to be provided to the Alexa Client upon initialization. This identifier will be used to target this application instance when a directive is sent to your Lambda code. (If you do not already have an identifier for the app instance or do not wish to pass it to Alexa, consider usingANDROID_ID for this purpose.)
If you choose this approach, you will need to work out much of the implementation code on your own. These steps will involve the following:
- Add Alexa Client Library to your project
- Pass an application instance identifier to client library at initialization
- Ensure the application instance identifier is known to your cloud
- Implement the Lambda function and app communication mechanism as you see fit
- Complete application integration requirements for Alexa Client Library

