DEV Community

Cover image for How to integrate push notifications for Amazon Appstore
Giovanni Laquidara for Amazon Appstore Developers

Posted on • Updated on

How to integrate push notifications for Amazon Appstore

Recently I was at Droidcon London catching up ✨ in-person ✨ with Android developers and longtime friends. The event was well-run, full of engaging technical talks and great conversations.

Image description

One particular conversation I had was with an Android + iOS app developer who found a way to sustainably freelance by launching multiple revenue streams: Ads, In App Purchasing (IAP), and selling online programming courses (...a dream of mine to do someday when I have the time... 😉⏳ ).

He was building everything from games to utility apps and was confronted with a recurring issue: The app user base would steadily grow until hitting a plateau after a variable amount of time (months). Once new interest peaked, less new users were discovering and installing his apps.

While I don't pretend to have a magic solution, I shared a suggestion based on a talk my colleague and I delivered hours earlier:

Launch your app in multiple app stores.

...and in my role as a Developer Advocate, I have to recommend these apps should definitely be the Amazon Appstore! 🥳📲

The Amazon Appstore offers an active global user base and one of the coolest features: existing apps can be installed directly on Windows 11.

What if your app could now reach millions of new desktop/laptop Windows 11 users around the world?

This developer then asked the standard software engineering questions:

"Yes but...
Are all the features I already developed going to be supported on the new system? How much effort is involved to port the app?"

The classic yet honest answer to this is:

"it depends!" 🤷

So let's dive in.

Porting Android apps to Amazon Appstore

Image description

Amazon Appstore runs on Fire OS devices (Fire Tablets, Fire TVs...) and can be installed on directly on Android devices. Fire OS is based on AOSP (Android Open Source Project) and without Google Play Services running on it. So for developers with app features dependent on Google Play Services, some migration work is needed.

For example, if your app relies on Firebase Cloud Messaging (FCM) for push notifications, this should be updated. Specifically in Fire OS, push notifications function through Amazon Device Messaging (ADM). Integrating the ADM SDK will allow your app to run smoothly in Fire OS.

To support both FCM and ADM, the Amazon Appstore team also created Amazon Appstore Abstraction Library A3L - an SDK to reduce porting time and code maintenance needs for notifications and messaging.

Integrating your app with A3L

Step 0: Download the A3L SDK

Download the A3L SDK from our developer documentation

Afterwards, make sure to add the downloaded .aar to the app/libs directory of your Android project.

Step 1: Add the A3L dependency to your project

After this, you will have to add the dependency on this file of the project. Open the build.gradle file and insert the following line:

dependencies {
     ...
     implementation files("libs/A3L-Messaging-1.0.0.aar")
 }
Enter fullscreen mode Exit fullscreen mode

Step 2: Obtain the credentials

Similar to what you already have done with Firebase through the google-services.json file, you have to obtain ADM credentials in order to uniquely identify your app the web service.

Once you have credentials, follow the instructions in our ADM docs.

Step 3: Define the messaging service

Now you will should create the Service that listens for messages and tokens from ADM.

To do this, you will have to extend the class A3LMessagingService and override these 2 methods:

class MyA3LMessagingService : A3LMessagingService() {

    override fun onMessageReceived(context: Context, remoteMessage: RemoteMessage) {
        Log.d(TAG, "From: ${remoteMessage.from}")
    }

    override fun onNewToken(context: Context, token: String) {
        Log.d(TAG, "Refreshed token: $token")
    }
Enter fullscreen mode Exit fullscreen mode

To Enable this service you will need to declare in the AndroidManifest.xml:

<application>
    <receiver android:name=".MyA3LMessagingService"
        android:exported="false"
        android:enabled="true">
        <intent-filter>
            <action android:name="com.amazon.A3L.messaging.intent.REGISTRATION"/>
            <action android:name="com.amazon.A3L.messaging.intent.MESSAGE"/>
        </intent-filter>
    </receiver>

    <meta-data android:name="com.a3l.clsName" 
    android:value="com.example.mya3lapp.MyA3LMessagingService" />

 </application>
Enter fullscreen mode Exit fullscreen mode

Step 4: Initialize the Service

Now you define the callback MainActivity to handle the registration phase and initialize the service:

class MainActivity : AppCompatActivity() {

    private val TAG = "MainActivity"

    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)

        setContentView(R.layout.activity_main)

        val onInitCallback: OnInitCallback = object : OnInitCallback() {
            override fun onReady(initCallbackResponse: InitCallbackResponse) {
                if (initCallbackResponse.isSuccessFul) {
                    Log.d(TAG, "Device Id: " + initCallbackResponse.token)
                } else {
                    Log.d(
                        TAG, "Registration failed with Error: " +
                                initCallbackResponse.errorMessage
                    )
                }
            }
        }
        A3LMessaging.init(applicationContext, onInitCallback)

        if (savedInstanceState == null) {
            supportFragmentManager.beginTransaction()
                .replace(R.id.container, EggTimerFragment.newInstance())
                .commitNow()
        }
    }
}
Enter fullscreen mode Exit fullscreen mode

and with that update, you are all set! Let's see how to test this implementation.

Testing

You have three ways to test this integration:

  • The Web Console
  • Server-side scripts
  • Solution-specific APIs

For our use-case, the easiest way is with the Amazon Appstore ADM Web Console. I suggest running the app on a Fire Tablet in order get the Device registration ID.
This will be available in the onReady of the onInitCallback.
Copy the ID and head to the Appstore ADM Web Console:

Image description

Select your target app to test and enter the Client ID and secret for your app. (You should have these saved from when you obtained your ADM credentials)

In the Device registration ID field, enter the value previously saved.

  1. Choose Notification message
  2. Populate the fields Notification Title and Body content
  3. Click Send test message

You should then receive an app notifications appearing on your Fire Device.

For the other ways of testing, you can check the official documentation.

Wrap up

I hope the Droidcon developer I spoke with and you are able to quickly launch existing apps for Amazon Appstore.

Using A3L will allow your app to support both FCM and ADM. If you want to try an A3L sample project with support for both Firebase Cloud Messaging and Amazon Device Messaging, check out my recent repo on GitHub and our related documentation.

Make sure to review the full pre-submission checklist when you’re ready to submit your app in the Amazon Appstore.

Stay connected

For the latest Amazon Appstore developer news, product releases, tutorials, and more:

📣 Follow @AmazonAppDev and our team on Twitter

📺 Subscribe to our Youtube channel

Top comments (0)