Skip to main content
This page applies to MoEngage Android SDK versions below 15.03.00.From MoEngage Android SDK 15.03.00, push token registration by the MoEngage SDK is no longer supported. Refer to Push Token Registration and Display for the current integration, and Migrating to Firebase Installation ID if you are upgrading.

Prerequisites

Complete the following setup before you begin:

Overview

Push notifications require two mandatory steps:
  1. Push token registration. The device registers for push, and Firebase generates a push token.
  2. Push display. The application receives the push payload from Firebase Cloud Messaging (FCM) and displays the notification on the device.
MoEngage recommends that the SDK handle both steps. The SDK retries token registration when it fails because of FCM downtime or a network error. The SDK also supports an integration in which your application registers the token and receives the notification payload. This document covers both integrations:

Push Token Registration and Display by the MoEngage SDK

Critical
  • Use com.google.firebase:firebase-messaging 23.0.0 or higher when the MoEngage SDK registers the token.
  • Declare only one service with the com.google.firebase.MESSAGING_EVENT intent filter in your application manifest file. If the manifest declares more than one such service, only the first service receives the callback. The MoEngage SDK then never receives the push payload, and delivery rates decline.
Add the following service to the manifest file so that the MoEngage SDK receives the notification.
The two sections that follow are optional. Apply them only if your application requires the behavior they describe.

Token Callback

Implement a token callback to access the push token that MoEngage registers on behalf of your application. When the MoEngage SDK handles registration, it provides a callback each time it registers or refreshes a token. Implement the TokenAvailableListener interface and register it using MoEFireBaseHelper.getInstance().addTokenListener(). Register the callback in the onCreate() method of your Application class, because the SDK can invoke it while the application is in the background.

Push Display for Non-MoEngage Payloads

Implement this callback if your application handles notifications that originate outside MoEngage. When you declare the SDK service in your manifest file, the SDK provides a callback for each push payload it receives from a server other than the MoEngage platform. Implement the NonMoEngagePushListener interface and register it using MoEFireBaseHelper.getInstance().addNonMoEngagePushListener(). Register the callback in the onCreate() method of your Application class, because the SDK can invoke it while the application is in the background.

Push Token Registration and Payload Handling by the Application

Skip this section if the MoEngage SDK handles push token registration and display. The MoEngage SDK registers for a push token by default. If your application registers the token, opt out of MoEngage token registration first.

Opt Out of MoEngage Token Registration

Disable token registration through the configureFcm() API on the MoEngage.Builder object.

Pass the Push Token to the MoEngage SDK

Your application must pass the push token it receives from FCM to the MoEngage SDK, because the MoEngage platform requires the token to deliver notifications to the device. Use the passPushToken() API.
Pass the token to the MoEngage SDK every time FCM refreshes it. Passing the token on application update is required for migration to the MoEngage platform.

Pass the Push Payload to the MoEngage SDK

Pass payloads from the MoEngage platform to the MoEngage SDK even when your application declares its own service, because the SDK renders the notification, including rich push notifications. Call the passPushPayload() API from the onMessageReceived() method of your Firebase service. Check whether the payload originates from the MoEngage platform using the isFromMoEngagePlatform() API before you pass it.

Rich Landing

A rich landing page opens a web URL inside the application from a push campaign. This step is required to display rich landing pages, regardless of which component handles push token registration and display.
The following declaration is included in current SDK versions. Add it only if you need to change the parent activity of MoEActivity.
Add the following activity to the AndroidManifest.xml file.