No se han encontrado resultados

Prueba una consulta diferente o más específica
Developer Console
Gracias por tu visita. Esta página solo está disponible en inglés.

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 meta-data. 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>
    

Initialize A3L Messaging

In the onCreate() method, you must initialize A3L Messaging and retrieve the device ID. Create an instance of the abstract class OnInitCallback and pass it to A3LMessaging.init() as seen in the following example.

import com.amazon.A3L.messaging.A3LMessaging;
import com.amazon.A3L.messaging.InitCallbackResponse;
import com.amazon.A3L.messaging.OnInitCallback;

public class MainActivity extends AppCompatActivity {

    private final String TAG = "MainActivity";

    @Override
    protected void onCreate(Bundle savedInstanceState) {

        OnInitCallback onInitCallback = new OnInitCallback() {
            @Override
            public void onReady(InitCallbackResponse initCallbackResponse) {
                if (initCallbackResponse.isSuccessFul()){
                    Log.d(TAG, "Device Id: " + initCallbackResponse.getToken());
                }
                else {
                    Log.d(TAG, "Registration failed with Error: " +
                            initCallbackResponse.getErrorMessage());
                }
            }
        };
        A3LMessaging.init(getApplicationContext(), onInitCallback);
    }
}

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: Jun 06, 2022