Android SDK messaging API

New interface method for customers using their own FCM implementation

Step-by-step

1. Call new token

The sdk messaging api has new interface method for customers that use their own fcm implementation:

co.acoustic.mobile.push.sdk.api.MessagingApi.reportToken(Context, token) - should be called when a new registration token is detected.

Sample of how a customer FCM implementation should look:

import androidx.annotation.NonNull;

import com.google.firebase.messaging.FirebaseMessagingService;
import com.google.firebase.messaging.RemoteMessage;
import com.ibm.mce.sdk.api.MessagingApi;
import com.ibm.mce.sdk.api.fcm.FcmApi;

public class CustomFcmMessagingService extends FirebaseMessagingService {

@Override
public void onMessageReceived(@NonNull RemoteMessage remoteMessage) {
if(FcmApi.isFcmMessage(remoteMessage)) {
FcmApi.handleMceFcmMessage(getApplicationContext(), remoteMessage);
} else {
// this is not sdk message. Handle it here
}
}

@Override
public void onNewToken(@NonNull String token) {
MessagingApi.reportToken(getApplicationContext(), token);
// any other code that uses the token goes here
}
}

If you are using an external Firebase messaging service instead of the SDK’s Firebase messaging service, you can use co.acoustic.mobile.push.sdk.api.fcm.FcmApi API. This API provides two methods that let you pass FCM messages to the SDK:

  • public static boolean isFcmMessage(RemoteMessage remoteMessage)
    Checks if a remote message is an Acoustic Campaign generated message
  • public static void handleMceFcmMessage(Context context, RemoteMessage remoteMessage)
    Handles an MCE FCM message in the SDK

For example, add the following to the sample app:

package co.acoustic.mobile.push.samples.gcm;

import com.google.firebase.messaging.FirebaseMessagingService;
import com.google.firebase.messaging.RemoteMessage;
import co.acoustic.mobile.push.sdk.api.fcm.FcmApi;

public class SampleFirebaseMessagingService extends FirebaseMessagingService {

    @Override
    public void onMessageReceived(RemoteMessage remoteMessage) {
        if(FcmApi.isFcmMessage(remoteMessage)) {
            FcmApi.handleMceFcmMessage(getApplicationContext(), remoteMessage);
        }
    }
}