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 Netcore 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();
NetcoreSDK.register(this);
NetcoreSDK.setSMTNotificationListener(this);
}
@Override
public void getSmartechNotifications(JSONObject data, int from) {
NetcoreSDK.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 = NetcoreSDK.isNotificationFromNetcore(remoteMessage.getData());
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 Netcore SDK.
NetcoreSDK.deliverNotificationEvent(context, json, isAmplified);
Send the open event to Smartech server
Call the openNotificationEvent()
method inside the implementation of click event of notification. You can retrieve TRID, Deeplink and customPayload from Notification payload.
NetcoreSDK.openNotificationEvent(context, trID, deeplink, jsonPayload);
Updated over 4 years ago