Amazon Developer

as

Settings
Sign out
Notifications
Alexa
Amazon Appstore
Ring
AWS
Documentation
Support
Contact Us
My Cases
Develop
Test
Publish
Monetize
Engage users
Device specifications
Resources
Skip to main content
1. Explore - Know your options2. Choose - Find a solution3. Fit - Update your code4. Verify - Test your app5. Push - Submit your app
On this page, learn how to register your app with Amazon Device Messaging (ADM) and handle incoming messages.

Get registration ID

Before receiving messages, your app must obtain a registration ID. The registration ID in ADM is similar to the device registration token in Firebase - it uniquely identifies the installation of your app on a particular device. In Firebase, you can call FirebaseMessaging.getInstance().getToken() to retrieve the device registration token. ADM has a similar method, getRegistrationId(). The following code shows how to use the methods in the com.amazon.device.messaging.ADM class to:
  • Create an instance of an ADM context
  • Initiate registration with ADM for this instance of your app
You should run this code each time your app starts, for example, by placing it within your onCreate() method. If your app is already registered, getRegistrationId() returns the registration ID for this instance of the app, and startRegister() isn’t called. If this is the first startup of the app on a given device or if a previous registration failed, this code begins the registration process.

Implement registration and message handling

ADM has three classes that you must extend. Refer to the following table to understand the function of each. You can also review the ADM API reference.
ClassDescription
com.amazon.device.messaging.ADMMessageHandlerJobBaseFor handling messages on the latest Fire devices
com.amazon.device.messaging.ADMMessageHandlerBaseFor handling messages on older Fire devices
com.amazon.device.messaging.ADMMessageReceiverFor forwarding messages to the appropriate message handling class
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 the com.amazon.device.messaging.ADMMessageHandlerJobBase and com.amazon.device.messaging.ADMMessageHandlerBase classes:
Callback MethodDescription
onRegisteredCalled 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.
onUnregisteredCalled if your app instance becomes unregistered from ADM.
onRegistrationErrorCalled if your app’s ADM registration request fails for any reason, such as no Amazon user being signed in to the device.
onMessageCalled when the ADM client delivers a message to your app instance.
Your app must override these callbacks when you implement subclasses of com.amazon.device.messaging.ADMMessageHandlerJobBase, com.amazon.device.messaging.ADMMessageHandlerBase and com.amazon.device.messaging.ADMMessageReceiver, as shown in the following code examples:
  1. Check if the current device has been updated to support new ADM service.
  2. Create your receiver and service implementations.

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:
  1. Use code similar to the following to check for ADM.
  2. Add the following code to any of your code that requires the ADM library runtime.
  3. In your AndroidManifest.xml file, verify that the application element specifies:

Server-side integration

Use the following guides to make sure your server is set up to work with ADM. To send a message to a single device, you can use the Developer Console. For more details, see Verify.

Next steps

Go to the next step: Step 4: Verify - Test Your App.
Last modified on March 24, 2022