Custom Push Amplification Handling

  1. In your custom FCM Receiver class, add the following code snippet when you receive the RemoteMessage object from Firebase. This method allows you to ensure that duplicate Push notification is not rendered on your device via Push Amplification.
if (message.getData().size() > 0) {
                Bundle extras = new Bundle();
                Iterator var = message.getData().entrySet().iterator();

                while(var.hasNext()) {
                    Map.Entry entry = (Map.Entry);
                    extras.putString((String)entry.getKey(), (String)entry.getValue());
                    //write push notification rendering logic here
if (message.getData().size() > 0)
  val extras = Bundle()
  val `var` = message.getData().entrySet().iterator()
  while (`var`.hasNext())
    val entry = `var`.next() as Map.Entry
    extras.putString(entry.getKey() as String, entry.getValue() as String)
  CleverTapAPI.processPushNotification(getApplicationContext(), extras)

From CleverTap Android SDK v4.4.0 onwards, you can replace the above code with the following

CTFcmMessageHandler().processPushAmp(getApplicationContext(), message);
CTFcmMessageHandler().processPushAmp(applicationContext, message)
  1. In your Application class, implement the CTPushAmpListener interface.
public class MyApplication extends Application implements CTPushAmpListener {

// your application class code
class MyApplication:Application(), CTPushAmpListener// your application class code
  1. In the onCreate() method of your Application class, create an instance of CleverTapAPI and set the CTPushAmpListener as following:
CleverTapAPI cleverTapAPI = CleverTapAPI.getDefaultInstance(getApplicationContext());
val cleverTapAPI = CleverTapAPI.getDefaultInstance(getApplicationContext())
  1. After the listener is set, whenever a Push Notification is sent to the device via Push Amplification, the app will receive the payload in the onPushPayloadReceived method. Implement this method as follows and ensure that your rendering logic of the Push Notification is written here:
public void onPushPayloadReceived(Bundle bundle) {
    //write push notification rendering logic here
fun onPushPayloadReceived(bundle:Bundle) {
  //write push notification rendering logic here

Did this page help you?