Skip to main content
This page applies to MoEngage Android SDK 15.03.00 and above. For versions below 15.03.00, refer to Push Token Registration and Display (Legacy).If you are upgrading an existing integration, refer to Migrating to Firebase Installation ID.

Prerequisites

Complete the following setup before you begin:
  • Create a Firebase project for your application and add the google-services.json configuration file. Refer to the Firebase Android setup guide.
  • Use com.google.firebase:firebase-messaging 25.1.2 or higher. This is the minimum version required for the Firebase Installation ID.
  • Generate FCM credentials and add them to the MoEngage dashboard. Refer to FCM Authentication and Push Configuration.

Overview

MoEngage Android SDK 15.03.00 registers devices for push using the Firebase Installation ID. Two flows are available, depending on which component generates the Installation ID:

Flow 1: MoEngage Handles Installation ID Generation

CriticalDeclare 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.

Step 1: Declare the MoEngage Messaging Service

Add MoEFireBaseMessagingService to the manifest file.

Step 2: Enable the Firebase Installation ID

Add the following metadata to the manifest file.

Register for the Installation ID (Optional)

Call the registerForInstallationId() API after MoEngage SDK initialization completes, so that the SDK registers for an Installation ID. This call is required only in the following cases:
  • Firebase auto-initialization is disabled in your application. Refer to the Firebase documentation on preventing auto initialization.
  • MoEngage SDK initialization is delayed, for example when your application initializes the SDK on a worker thread instead of in the onCreate() method of the Application class.
This API does not register an Installation ID if your application has opted out of MoEngage registration.

Get the Installation ID (Optional)

Apply one of the following options if your application needs to read the Installation ID that MoEngage generates.

Option 1: Get the Installation ID Asynchronously

Register an InstallationIdAvailableListener in your Application class using the addInstallationIdListener() API. The SDK triggers the callback only for an Installation ID that it generates or updates after you register the listener. Call removeInstallationIdListener() to stop receiving the callback.

Option 2: Get the Installation ID Synchronously

Call the getInstallationId() API from a worker thread. The API returns null if the Installation ID is not available when you call it.

Push Display for Non-MoEngage Payloads (Optional)

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 in the onCreate method 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.

Flow 2: The Application Handles Installation ID Generation

Skip this section if the MoEngage SDK generates the Installation ID.

Step 1: Opt Out of MoEngage Push Token Registration

The MoEngage SDK registers for push by default. If your application generates the Installation ID, opt out of MoEngage registration first. Disable token registration through the configureFcm() API on the MoEngage.Builder object.
Set up the Installation ID in your application. Refer to the Firebase documentation on accessing the Firebase Installation ID for the FCM setup.

Step 2: Pass the Installation ID to the MoEngage SDK

Your application must pass the Installation ID to the MoEngage SDK using the passInstallationId() API, because the MoEngage platform requires it to deliver notifications to the device.

Step 3: 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 generates the Installation ID.
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.