Smartech

Customer Engagement

Using the Smartech panel, you can engage with your app users via channels like push notifications & in-app messages.

Setting up Push Notifications for your Android project is a quick 6 steps process.

Step 1: Complete basic setup

Go to Basic Setup to start integrating your Android project with Smartech SDK.

Step 2: Adding SmartPush SDK dependency

  1. Please add SmartPush dependency inside the app-level build.gradle file.
implementation 'com.netcore.android:smartech-push:3.2.2'
  1. Perform Gradle Sync to build your project and incorporate the dependency additions noted above.

Step 3: Integrate Firebase Cloud Messaging in your app

Please follow Google’s Documentation to set up FCM SDK in your app, if it is not already done.

Step 4: Send FCM token to Smartech SDK

Call the following method in onCreate function of your Application class after initializing the Smartech SDK to allow Smartech to retrieve existing token

try {
  SmartPush smartPush = SmartPush.getInstance(new WeakReference<>(context));
  smartPush.fetchAlreadyGeneratedTokenFromFCM();
} catch (Exception e) {
  Log.e(TAG, "Fetching FCM token failed.");
}
try {
  val smartPush = SmartPush.getInstance(WeakReference(context))
  smartPush.fetchAlreadyGeneratedTokenFromFCM()
} catch (e: Exception) {
  Log.e(TAG, "Fetching FCM token failed.")
}

Provide token via setDevicePushToken() and notification payload via handlePushNotification() methods to SmartPush SDK. handlePushNotification() method will only display a notification if the Notification payload originated from Netcore and will safely ignore if not. The code of the class should look similar to the following:

public class <YourFirebaseMessagingServiceClass> extends FirebaseMessagingService {

    @Override
    public void onNewToken(@NonNull String token) {
        super.onNewToken(token);
        SmartPush.getInstance(new WeakReference<Context>(this)).setDevicePushToken(token);
      
        //<Your code>
    }

    @Override
    public void onMessageReceived(@NonNull RemoteMessage remoteMessage) {
        super.onMessageReceived(remoteMessage);
        boolean pushHandledBySmartech = SmartPush.getInstance(new WeakReference<>(getApplicationContext())).handlePushNotification(remoteMessage.getData().toString())
        if (!pushHandledBySmartech){
       
         // Handle notification from other sources.
            
       }
    }
}
class AppsFirebaseMessagingService : FirebaseMessagingService() {

    override fun onNewToken(token: String) {
        super.onNewToken(token)
        SmartPush.getInstance(WeakReference(this)).setDevicePushToken(token)
    }

    override fun onMessageReceived(remoteMessage: RemoteMessage) {
        super.onMessageReceived(remoteMessage)
        SmartPush.getInstance(WeakReference(applicationContext)).handlePushNotification(remoteMessage.data.toString())
    }
}

Step 5: Retrieving Deeplink Data

Implement a BroadcastReceiver for the Deeplinks.

public class DeeplinkReceiver extends BroadcastReceiver {
    @Override
    public void onReceive(Context context, Intent intent) {

        Bundle bundleExtra = getIntent().getExtras();
        if (bundleExtra != null) {

            if (bundleExtra.containsKey(SMTBundleKeys.SMT_BUNDLE_KEY_CLICK_DEEPLINK)) {
                String deepLinkvalue = bundleExtra.getString(SMTBundleKeys.SMT_BUNDLE_KEY_CLICK_DEEPLINK);
            } else {
                Log.v("Activity", "does not have deeplink path.");
            }

            if (bundleExtra.containsKey(SMTBundleKeys.SMT_BUNDLE_KEY_CLICK_CUSTOM_PAYLOAD)) {
                String customPayloadvalue = bundleExtra.getString(SMTBundleKeys.SMT_BUNDLE_KEY_CLICK_CUSTOM_PAYLOAD);
            } else {
                Log.v("Activity", "does not have custom payload.");
            }

        }
    }
}
class DeeplinkReceiver : BroadcastReceiver() {

    override fun onReceive(context: Context?, intent: Intent?) {
        val bundleExtra = intent?.extras
        if (bundleExtra != null) {
            if (bundleExtra.containsKey(SMTBundleKeys.SMT_BUNDLE_KEY_CLICK_DEEPLINK)) {
                val deepLinkvalue = bundleExtra.getString(SMTBundleKeys.SMT_BUNDLE_KEY_CLICK_DEEPLINK)
            } else {
                Log.v("Activity", "Does not have deeplink path.")
            }
            if (bundleExtra.containsKey(SMTBundleKeys.SMT_BUNDLE_KEY_CLICK_CUSTOM_PAYLOAD)) {
                val customPayloadvalue = bundleExtra.getString(SMTBundleKeys.SMT_BUNDLE_KEY_CLICK_CUSTOM_PAYLOAD)
            } else {
                Log.v("Activity", "Does not have custom payload.")
            }
        }
    }
}
Smartech.addListener(Smartech.SmartechDeeplinkNotification, handleDeeplinkWithPayload);
    Smartech.getDeepLinkUrl(function (_response) {
      console.log('getDeepLinkUrl Initial Deeplink Response ', _response);
      // Handling the SDK Deeplink Callback.
    });
  const handleDeeplinkWithPayload = (deeplinkdata) => {
  };

Register the BroadcastReceiver inside the Application class.

DeeplinkReceiver deeplinkReceiver = new DeeplinkReceiver();
        IntentFilter filter = new IntentFilter("com.smartech.EVENT_PN_INBOX_CLICK");
        context.registerReceiver(deeplinkReceiver, filter);
val deeplinkReceiver = DeeplinkReceiver()
        val filter = IntentFilter("com.smartech.EVENT_PN_INBOX_CLICK")
        registerReceiver(deeplinkReceiver, filter)

Write the following code in the onCreate function of the launcher activity of your application.

new DeeplinkReceiver().onReceive(this, getIntent())
DeeplinkReceiver().onReceive(this, intent)

Step 6: Customizing Notification Appearance

We have created SMTNotificationOptions to provide you the functionality to change your Notifications icons, sound, and color. You can create an object of this class to set the notifications icon, color, and sound and apply these changes using setNotificationOptions() methods that take SMTNotificationOptions object as a parameter.

Push Notification Icon

You need to use the following code in order to change the push notification icon.

SMTNotificationOptions options = new SMTNotificationOptions(this);
options.setSmallIconTransparentId(R.drawable.ic_notif);
SmartPush.getInstance(new WeakReference<>(context)).setNotificationOptions(options);
val options = SMTNotificationOptions(this)
options.smallIconTransparentId = R.drawable.ic_notif
SmartPush.getInstance(WeakReference(context)).setNotificationOptions(options)

Note:
The notification icon being used should strictly be in .png format as per Google’s UI guidelines​. Preferable size for the push notification icons is mentioned below.

drawable-mdpi       :   24 x 24
drawable-hdpi       :   36 x 36 
drawable-xhdpi      :   48 x 48
drawable-xxhdpi     :   72 x 72
drawable-xxxhdpi    :   96 x 96

Changing Push Notification Icon Color

To change the color of notification icon, add given snippet inside the onCreate() method of the Application Class​​.

SMTNotificationOptions options = new SMTNotificationOptions(this);
options.setTransparentIconBgColor("#007AFF");
SmartPush.getInstance(new WeakReference<>(context)).setNotificationOptions(options);
val options = SMTNotificationOptions(this)
options.transparentIconBgColor = "#007AFF"
SmartPush.getInstance(WeakReference(context)).setNotificationOptions(options)

Updated about a month ago


Customer Engagement


Suggested Edits are limited on API Reference Pages

You can only suggest edits to Markdown body content, but not to the API spec.