These docs are for v1.0. Click to read the latest docs for v2.0.

Controlling Push Notification

Smartech allows you to get full control of push notifications sent from Smartech Panel. Typical use cases that require below steps of integration are as follows: if you want to render notification yourself or you want to either modify the payload or hide/show the notifications based on your internal business logic.

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

Enabling the Notification Listener

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

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

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

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

public class SmartechApplication extends Application implements SMTNotificationListener {

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

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

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

Check if the notification is from Smartech

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

public class MyFirebaseMessagingService extends FirebaseMessagingService {
    
    @Override
    public void onMessageReceived(RemoteMessage remoteMessage) {
         boolean pushFromSmartech = Smartech.getInstance(new WeakReference<Context>(context)).isNotificationFromNetcore(new JSONObject(remoteMessage.getData().toString()));
      if(!pushFromSmartech){
        // 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 Smartech server

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

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

Send the open event to Smartech server

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

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