Developer Console

Integrate the A3L Messaging SDK

This page describes how to integrate the A3L Messaging SDK into your project.

Extend the A3LMessagingService class

The A3LMessagingService class is part of the A3L Messaging SDK. You must extend from this class to allow your app to receive messages. The following table describes the methods you must override in your implementation.

Method Description
onMessageReceived() Called when a message is delivered to your app instance.
onNewToken() Called when a new device ID for the app instance is ready.

The following code shows an example implementation with a class named MyA3LMessagingService.

public class MyA3LMessagingService extends A3LMessagingService {

    private final String TAG = "MyA3LMessagingService";

    @Override
    public void onMessageReceived(Context context, RemoteMessage remoteMessage){
        Log.d(TAG, "In onNewMessage");
        // Process message here. For example, start an async task.
    }

    @Override
    public void onNewToken(Context context, String token){
            Log.d(TAG, "In onNewDeviceId");
        // Process device ID here. For example, store it on your server.
    }
}

Update your app manifest

You must update your app's AndroidManifest.xml file to receive messages. The following examples use MyA3LMessagingService as a placeholder for your implementation of the A3LMessagingService class.

  1. Declare your implementation of the A3LMessagingService class as a receiver. This allows you to handle REGISTRATION and MESSAGE intents.

     <application>
     <!--  Configuration for A3LMessaging start  -->
             <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>
     </application>
    
  2. Add details about your implementation of A3LMessagingService as metadata. This allows proper initialization of A3L Messaging.

     <application>
     <!--  Configuration for A3LMessaging start  -->
        
             <meta-data android:name="com.a3l.clsName"
                 android:value="com.example.mya3lapp.MyA3LMessagingService" />
        
     </application>
    

Retrieve the registration token

On initial startup of your app, the A3L Messaging library generates a registration token for the client app instance. This token is delivered in your overridden onNewToken() method of the A3LMessagingService class.

To get the current registration token, call A3LMessaging.getToken(), as shown in the following example.

A3LMessaging.getToken()
                .addOnCompleteListener(new OnCompleteListener<String>() {
                    @Override
                    public void onComplete(Task<String> task) {
                        if (!task.isSuccessful()) {
                            Log.w(TAG, "Fetching registration token failed", task.getException());
                            return;
                        }

                        // Get new FCM/ADM registration token
                        String token = task.getResult();

                        Log.d(TAG, token);
                    }
                });

Optional - Create an escape hatch

If you have a special use case and want to create a custom method, you can create an escape hatch for that scenario. The A3LMessaging class provides you with an instance of an ADM object and a FirebaseMessaging object that you can make calls from.

  1. Use A3LMessaging.getCurrentPlatform() to get the current messaging solution as a String.
    • If FCM_PLATFORM is returned, use A3LMessaging.getFCMInstance() to get the instance.
    • If ADM_PLATFORM is returned, use A3LMessaging.getADMInstance().
  2. Now you can make calls directly with the FirebaseMessaging and ADM objects. See the following example.

     String currentPlatform = A3LMessaging.getCurrentPlatform();
     if(A3LMessagingConstants.ADM_PLATFORM.equals(currentPlatform)){
         ADM adm = A3LMessaging.getADMInstance();
         // Do something with ADM instance.
     }
     else if (A3LMessagingConstants.FCM_PLATFORM.equals(currentPlatform)){
         FirebaseMessaging firebaseMessaging = A3LMessaging.getFCMInstance();
         // Do something with FCM instance.
     }
    
  3. If you need to override methods which are unsupported by the A3LMessagingService, you can create your own custom class. To do this, inherit from the solution-specific API and override the method you need access to.

    For example, if your app needs access to the onDeletedMessages() method from FirebaseMessagingService, you could create a class like the one in the following example.

     import com.google.firebase.messaging.FirebaseMessagingService;
    
     public class MyCustomService extends FirebaseMessagingService {
         @Override
         public void onDeletedMessages(){
             // Custom handling of the function
         }
     }
    

    You must also set up your app to listen for the events of this API. The setup required might vary based on the messaging solution and API.

A3L Messaging API reference

For details on the classes and methods contained in the A3L Messaging SDK, see the complete A3L Messaging API reference.

Next steps

See Test A3L Messaging.


Last updated: Feb 27, 2023