Advanced CustomizationSupport for advanced use cases where the application wants to customize or alter the default behavior of the MoEngage SDK.
Extending PushMessageListener
The first thing required to customize the notification is creating a class that extends PushMessageListener. We will call this class CustomPushMessageListener (only for illustration purposes you can have any class name you want). The barebones of this class would look something like below.Passing the instance of CustomPushMessageListener to MoEngage SDK
You need to pass on the instance of CustomPushMessageListener to the MoEngage SDK in the onCreate() of the Application class. You need to pass the instance to MoEPushHelper.getInstance().registerMessageListener() API. A sample call is described.Optionally control notification display
To control whether a notification is shown to the user or not, you need to override isNotificationRequired() in the CustomPushMessageListener class created above.If you intend to show the notification overridden, the implementation should return true or false. The structure for implementation is described as follows:
If this method returns false, this notification is discarded by the SDK; that is, the notification will not be displayed on the device, and the impression will not be tracked.
Notification Received Callback
To receive a callback whenever a push is received, override the onNotificationReceived() in the CustomPushMessageListener class.Notification Clicked Callback
To receive a callback whenever a push is clicked, override the onNotificationClicked() in the CustomPushMessageListener class created as described in the Notification Received Callback.This method doubles as a callback and can be used for handling redirection. If you want to handle redirection on notification, click the method should return true, or else false.
Notification Cleared Callback
To receive a callback whenever a push is cleared, override the onNotificationCleared() in the CustomPushMessageListener class created above.Custom Action on Action Button Click
To use a custom action on the Action Button click override the handleCustomAction() in the CustomPushMessageListener class created above.Customize Notification
To further customize the notification object, override the customizeNotification(). This allows for additional settings to be added or modified, such as vibration patterns/LED colors, etc. It is important to note that the super method should be called before adding any customizations to ensure that the default settings are applied.Customize Notification Builder
The SDK provides the customizeNotificationBuilder() callback to customize the notification builder object as needed. This feature allows developers to update various properties of the notification builder, such as the channel ID, the auto-dismiss time, etc. It is important to note that the super method should be called before adding any customizations to ensure that the default settings are applied.Self-handled Notification Received Callback
When you use the SDK callback approach by registering aPushMessageListener, the MoEngage SDK provides a dedicated method for self-handled notifications.
SDK version: The self-handled notification check is supported starting from Android SDK version 14.06.00.Automatic Impression Tracking: When using this callback, the MoEngage SDK automatically tracks notification impressions. You do not need to call
logNotificationReceived. You only need to handle the display and manually track clicks if a custom UI is shown.onSelfHandledNotificationReceived() in your custom listener class:
Bundle, refer to Background Update Templates.