To enable its full functionality (like Push Notifications, InApp Messaging), there are still a couple of steps that you have to take care of in your Android app.
MoEngage SDK depends on the below Jetpack libraries provided by Google for its functioning, make sure you add them if it isn’t already present in the application.
Get Workspace ID from the Settings Page Dashboard --> Settings --> App --> General and initialize the MoEngage SDK in the Application class’s onCreate()Note: It is recommended that you initialize the SDK on the main thread inside onCreate() and not create a worker thread and initialize the SDK on that thread.
// this is the instance of the application class and "XXXXXXXXXXX" is the Workspace ID from the dashboard.MoEngage moEngage = new MoEngage.Builder(this, "XXXXXXXXXXX") .enablePartnerIntegration(IntegrationPartner.SEGMENT) .build();MoEngage.initialise(moEngage);
This is solely required for migration to the MoEngage Platform. We need your help to tell the SDK whether the user is a new user for your application, or an existing user who has updated to the latest version.If the user was already using your application and has just updated to a new version which has MoEngage SDK it is an updated call the below API
Copy the Server Key from the FCM console and add it to the MoEngage Dashboard(Not sure where to find the Server Key refer to Getting FCM Server Key). To upload it, navigate to MoEngage Dashboard —> Settings —> Channel —> Push —> Mobile Push —> Android and add the Server Key and package name.
Ensure you add the keys both in the Test and Live environment.
To show push notifications some metadata regarding the notification is required where the small icon and large icon drawable are the mandatory ones.Use the configureNotificationMetaData() to pass on the configuration to the SDK.
The Application would need to pass the Push Token received from FCM to the MoEngage SDK for the MoEngage platform to send out push notifications to the device. Use the below API to pass the push token to the MoEngage SDK.
Note: Please make sure the token is passed to MoEngage SDK whenever the push token is refreshed and on application update. Passing tokens on application updates is important for migration to the MoEngage Platform.
To pass the push payload to the MoEngage SDK call the MoEngage API from the onMessageReceived() from the Firebase receiver. Before passing the payload to the MoEngage SDK you should check if the payload is from the MoEngage platform using the helper API provided by the SDK.
if (MoEPushHelper.getInstance().isFromMoEngagePlatform(remoteMessage.getData())) { MoEFireBaseHelper.Companion.getInstance().passPushPayload(getApplicationContext(), remoteMessage.getData());}else{ // your app's business logic to show notification}
When MoEngage SDK handles push registration it optionally provides a callback to the Application whenever a new token is registered or token is refreshed. An application can get this callback by implementing FirebaseEventListener and registering for a callback in the Application class’ onCreate() using MoEFireBaseHelper.getInstance().addEventListener()
Add the following snippet and replace [PARENT_ACTIVITY_NAME] with the name of the parent activity; [ACTIVITY_NAME] with the activity name which should be the parent of the Rich Landing Page
You are now all set up to receive push notifications from MoEngage. For more information on features provided in MoEngage Android SDK refer to the following links:
Use Identify to track user-specific attributes. It is equivalent to tracking user attributes on MoEngage. MoEngage supports traits supported by Segment as well as custom traits. If you set traits.id, we set that as the Unique ID for that user.
Use track to track events and user behavior in your app. This will send the event to MoEngage with the associated properties. Tracking events is essential and will help you create segments for engaging users.