Push messages

The SDK automatically registers your app to receive push messages through FCM.

Should you need access to the raw push messages to process some custom logic around the data in the push you can obtain it by either registering a PushMessageListener when initializing SDK, or the System Tray Intent used to open Launcher Activity.

App state

Notification

Data

Both

Foreground

PushMessageListener

PushMessageListener

PushMessageListener

Background

System tray

PushMessageListener

Notification: system tray; Data: in extras of the intent.

PushMessageListeners simply redirects messages from internally registered FirebaseMessagingService (see Firebase)

📘

Deep links

If a push notification is delivered while the app is in the foreground, you can build your own in the 'onMessageReceived()` method that creates a link to a particular activity in your app.

public class PushHandler implements PushMessageListener {

    @Override
    public void onMessageReceived(RemoteMessage message) {
      // Check if message contains a notification payload.
        if (message.getNotification() != null) {
        Log.i("TAG", "Push notification: " + message.getNotification().getBody());
      // Do something with the message to notify the user
          // Example
          createNotificationChannel(context);
          Notification.Builder b = new Notification.Builder(context);
          b.setAutoCancel(true)
            .setDefaults(NotificationCompat.DEFAULT_ALL)
            .setWhen(System.currentTimeMillis())
            .setSmallIcon(R.drawable.common_google_signin_btn_icon_dark)
            .setContentTitle("foreground message")
            .setContentText(body)
            .setContentInfo("INFO");
          if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
            b.setChannelId("test_channel_id1");
          }
          NotificationManager nm = (NotificationManager) context.getSystemService(Context.NOTIFICATION_SERVICE);
          nm.notify(1, b.build());
        }
    }
}

private void createNotificationChannel(Context context) {
        // Create the NotificationChannel, but only on devices that have the Google API 26+ because the NotificationChannel class is new and not in supported in older libraries
        if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
            CharSequence name = "test channel";
            String description = "some description";
            int importance = NotificationManager.IMPORTANCE_DEFAULT;
            NotificationChannel channel = new NotificationChannel("test_channel_id1", name, importance);
            channel.setDescription(description);
            // Register the channel with the system; you can't change the importance
            // or other notification behaviors after this
            NotificationManager notificationManager = context.getSystemService(NotificationManager.class);
            notificationManager.createNotificationChannel(channel);
        }
}
  1. Pass your class to the pushMessageListener() on the ComapiConfig object
config.pushMessageListener(new PushHandler());