Controling Push Notifications

CEE allows you to get full control of push notifications sent from the Netcore Panel. Typical use cases that require the below steps of integration are as follows:

  • If you want to render notification yourself or
  • If you want to either modify the payload
  • If hide/show the notifications based on your internal business logic
  • If you want to get a call back whenever the user gets the notification or clicks on it.

🚧

If you are rendering the notification yourself via the below methods, please ensure you correctly send the delivery event and click event back to Netcore.

Enabling the Notification Listener

To enable the notification listener, set the following flag as 1 in manifest.xml file.

<meta-data
   android:name="SMT_IS_NOTIFICATION_LISTENER_ENABLED"
   android:value="1" />

Handle Notification with CEE FirebaseMessagingService or Notification received through Push Amplification service.

Implement CEE Notification Listener in application class and override the getSmartechNotifications() method.

public class SmartechApplication extends Application implements SMTNotificationListener {

   @Override
   public void onCreate() {
       super.onCreate();
       ...
       SmartPush.getInstance(new WeakReference<Context>(context)).setSMTNotificationListener(this);
   }

   @Override
   public void getSmartechNotifications(JSONObject data, int from) {
            SmartPush.getInstance(new WeakReference<Context>(context)).renderNotification(this, data);
   }
}
class SmartechApplication : Application(), SMTNotificationListener {
    override fun onCreate() {
        super.onCreate()
        SmartPush.getInstance(WeakReference(context)).setSMTNotificationListener(this)
    }

    override fun getSmartechNotifications(data: JSONObject, from: Int) {
        SmartPush.getInstance(WeakReference(context)).renderNotification(this, data)
    }
}

Check if the notification is from CEE

If you want to check that the delivered notification is received through CEE, you can implement the following method.

public class MyFirebaseMessagingService extends FirebaseMessagingService {
    
    @Override
    public void onMessageReceived(RemoteMessage remoteMessage) {
         boolean pushFromSmartPush = SmartPush.getInstance(new WeakReference<Context>(context)).isNotificationFromNetcore(new JSONObject(remoteMessage.getData().toString()));
      if(!pushFromSmartPush){
        // Notification received from other sources
      }
    }
}
class MyFirebaseMessagingService : FirebaseMessagingService() {
    override fun onMessageReceived(remoteMessage:RemoteMessage) {
         val pushFromSmartech:Boolean = Smartech.getInstance(WeakReference(context)).isNotificationFromNetcore(
            JSONObject(remoteMessage.data.toString())
        )
      if(!pushFromSmartech){
        // Notification received from other sources
      }
    }
}

Send the delivery event to CEE server

If you want to render the notification received from CEEPanel, We will recommend you to send the delivery event to the CEE SDK.

SmartPush.getInstance(new WeakReference<Context>(context)).deliverNotificationEvent(context, json, isAmplified);
SmartPush.getInstance(WeakReference(context)).deliverNotificationEvent(context, json, isAmplified)

Send the open event to CEE server

Call the openNotificationEvent() method inside the implementation of click event of notification. You need to pass context and notification payload as arguments.

SmartPush.getInstance(new WeakReference<Context>(context)).openNotificationEvent(context, jsonPayload);
SmartPush.getInstance(WeakReference(context)).openNotificationEvent(context,jsonPayload)

Did this page help you?