Customer Engagement

Using the CEE 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 CEE 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:<<push_sdk_android_version>>'
  1. Perform Gradle Sync to build your project and incorporate the dependency additions noted above.

Step 3: Setting up Proguard rules

Add the following lines in proguard-rules.pro to retain Smartech Push files during the proguard process.

# Smartech Push SDK
-dontwarn com.netcore.android.smartechpush.**
-keep class com.netcore.android.smartechpush.**{*;}
-keep class * implements com.netcore.android.smartechpush.**.* {*;}
-keep class * extends com.netcore.android.smartechpush.**.* {*;}

Step 4: 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 5: Send FCM token to CEE SDK

Call the following method in onCreate function of your Application class after initializing the CEE SDK to allow CEE 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 isPushFromSmartech = SmartPush.getInstance(new WeakReference<Context>(context)).isNotificationFromSmartech(new JSONObject(remoteMessage.getData().toString()));
          if(isPushFromSmartech){
            SmartPush.getInstance(new WeakReference<>(getApplicationContext())).handlePushNotification(remoteMessage.getData().toString());
          } else {
            // Notification received 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)
        val isPushFromSmartech:Boolean = SmartPush.getInstance(WeakReference(context)).isNotificationFromSmartech(
            JSONObject(remoteMessage.data.toString()))
        if(isPushFromSmartech){
          SmartPush.getInstance(WeakReference(applicationContext)).handlePushNotification(remoteMessage.data.toString())
        } else {
           // Notification received from other sources
        }
    }
}

Step 6: Retrieving Deeplink Data

Implement a BroadcastReceiver for the Deeplinks.

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

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

            if (bundleExtra.containsKey(SMTBundleKeys.SMT_BUNDLE_KEY_CLICK_DEEPLINK)) {
                String deepLinkvalue = bundleExtra.getString(SMTBundleKeys.SMT_BUNDLE_KEY_CLICK_DEEPLINK);
              // handle null or empty check before use the deepLinkValue for redirection
            } 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);
              // handle null or empty check before use the customPayloadvalue for redirection
            } 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)
                  // handle null or empty check before use the deepLinkValue for redirection
            } 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)
                  // handle null or empty check before use the customPayloadvalue for redirection
            } else {
                Log.v("Activity", "Does not have custom payload.")
            }
        }
    }
}
SmartPush.addListener(Smartech.SmartPushDeeplinkNotification, handleDeeplinkWithPayload);
    SmartPush.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.

When targetSdkVersion >= 34 (Android 14 and above)

DeeplinkReceiver deeplinkReceiver = new DeeplinkReceiver();
IntentFilter filter = new IntentFilter("com.smartech.EVENT_PN_INBOX_CLICK");
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.UPSIDE_DOWN_CAKE) {
   context.registerReceiver(deeplinkReceiver, filter, Context.RECEIVER_EXPORTED);
} else {
   context.registerReceiver(deeplinkReceiver, filter);
}

val deeplinkReceiver = DeeplinkReceiver()
val filter = IntentFilter("com.smartech.EVENT_PN_INBOX_CLICK")
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.UPSIDE_DOWN_CAKE) {
   context.registerReceiver(deeplinkReceiver, filter, RECEIVER_EXPORTED)
} else {
   context.registerReceiver(deeplinkReceiver, filter)
}

When targetSdkVersion <= 33 (Android 13 and below)

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")
        context.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 7: Customizing Notification Appearance

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

Add the given snippet inside the onCreate() method of the Application Class​​ to set brand logo, large icon, small icon, transparent icon and icon color for your notifications.

📘

If you are using Android CEE Push SDK 3.2.7 and above, please follow below steps:

SMTNotificationOptions options = new SMTNotificationOptions(this);
options.setBrandLogo("logo"); //e.g.logo is sample name for brand logo
options.setLargeIcon("icon_nofification");//e.g.ic_notification is sample name for large icon
options.setSmallIcon("ic_action_play"); //e.g.ic_action_play is sample name for icon
options.setSmallIconTransparent("ic_action_play"); //e.g.ic_action_play is sample name for transparent small icon
options.setTransparentIconBgColor("#FF0000");
options.setPlaceHolderIcon("ic_notification");//e.g.ic_notification is sample name for placeholder icon
SmartPush.getInstance(new WeakReference(context)).setNotificationOptions(options);
val options = SMTNotificationOptions(context)
options.brandLogo = "logo"//e.g.logo is sample name for brand logo
options.largeIcon = "icon_nofification"//e.g.ic_notification is sample name for large icon
options.smallIcon = "ic_action_play"//e.g.ic_action_play is sample name for icon
options.smallIconTransparent = "ic_action_play"//e.g.ic_action_play is sample name for transparent small icon
options.transparentIconBgColor = "#FF0000"
options.placeHolderIcon = "ic_notification"//e.g.ic_notification is sample name for placeholder icon
SmartPush.getInstance(WeakReference(context)).setNotificationOptions(options)

🚧

If you are using Android CEE Push SDK 3.2.6 and below, please use below steps:

SMTNotificationOptions options = new SMTNotificationOptions(context);
options.setBrandLogoId(R.drawable.logo);
options.setLargeIconId(R.drawable.icon_nofification);
options.setSmallIconId(R.drawable.ic_action_play);
options.setSmallIconTransparentId(R.drawable.ic_action_play);
options.setTransparentIconBgColor("#FF0000");
options.setPlaceHolderIcon(R.drawable.ic_notification);
SmartPush.getInstance(new WeakReference(context)).setNotificationOptions(options);
val options = SMTNotificationOptions(context)
options.brandLogo = R.drawable.ic_notif
options.largeIcon = R.drawable.icon_nofification
options.smallIcon = R.drawable.ic_notif
options.smallIconTransparent = R.drawable.ic_notif
options.transparentIconBgColor = "#FF0000"
options.placeHolderIcon = R.drawable.ic_notification
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

🚧

Though we encourage SDK versions greater than 3.2.x, those currently on 3.1.x should continue to use "Smartech" rather than "SmartPush."

Step 8: Backward compatibility of notification permissions

Apps targeting android 12(API level 32) or below, which are installed on android 13 devices, then notification permission is required for push notifications. So Smartech SDK internally handles the notification permissions.

Control auto-create notification channel

Smartech SDK requires a notification channel to push notifications on Android 8.0 and above. So Smartech SDK creates a default notification channel with the below-mentioned details.

Channel Id: smtDefault
Channel Name: Smartech Default
Channel Description: Smartech default notification configuration

If you want to modify the above channel configuration, please add the following metadata within the tag of the AndroidManifest.xml

<meta-data
   android:name="SMT_DEFAULT_CHANNEL_ID"
   android:value="<Your Channel Id here>" />
<meta-data
   android:name="SMT_DEFAULT_CHANNEL_NAME"
   android:value="<Your Channel Name here>" />
<meta-data
   android:name="SMT_DEFAULT_CHANNEL_DESC"
   android:value="<Your Channel description here>" />

Note: Also, the notification channel helps to ask POST_NOTIFICATION permission prompt when the app target SDK 32 or below.

Control auto asks notification permission on Android 13

POST_NOTIFICATIONS permission is required On Android 13(API level 33) and above to publish notifications.

So smartech SDK is requesting post notification permissions on initialising SmartPush SDK. As per the best practices app should ask permission after some usage of the app by the user. So there is a control to turn off/on auto-ask notification permission on SDK.

Add the below code to not ask notification permission automatically by SmartPush SDK.

<meta-data
   android:name="SMT_IS_AUTO_ASK_NOTIFICATION_PERMISSION"
   android:value="0" />

0 - Smart Push SDK will not ask notification permission automatically, so you have to implement notifications permission as per the below step(Step 9)
1- Smart Push SDK will ask for notification permissions automatically. You are not required to handle on the app side.

Step 9: Notifications Permissions for Android 13 (API level 33)

Notification runtime permission

Android 13 (API level 33) and higher supports runtime permission for sending notifications from an app POST_NOTIFICATIONS. This change helps users focus on the notifications that are most important to them.

Refer to the official documentation for more details.

The below-mentioned APIs are supported from Smartech push SDK version 3.2.16

When the application is running on Android 13 to show notifications to the user, applications would need to request the user for notification permission.

For applications integrating the Smartech Push SDK, need to:

  • Notify the SDK of the permission request's response from the user.
  • If the application has already requested for the push permission(before Smartech integration) help Smartech setup notification channels for notification display.

Notify SDK of permission result
Once the application requests the user for notification permission, notify the SDK of the user response using the below API.

SmartPush.getInstance(WeakReference(context)).updateNotificationPermission(SMTPNPermissionConstants.SMT_PN_PERMISSION_GRANTED)
SmartPush.getInstance(new WeakReference<>(context)).updateNotificationPermission(SMTPNPermissionConstants.SMT_PN_PERMISSION_GRANTED);

//SMT_PN_PERMISSION_GRANTED - pass this when user granted post notification permission
// SMT_PN_PERMISSION_DENIED - pass this when user denied post notification permission

Request permission prompt from smartech SDK

Use the below API to show the permission request dialog to the user.
When using the below API SDK automatically tracks the response, so no need to update the permission result.
Add the below code in any of the Activity onCreate() where ever you want to show this permission.

SmartPush.getInstance(WeakReference(context)).requestNotificationPermission(notificationPermissionCallback or null)

//Pass the below callback if your app require notification permission granted status else pass null

private val notificationPermissionCallback = object : SMTNotificationPermissionCallback {
   override fun notificationPermissionStatus(status: Int) {
       if(status == SMTPNPermissionConstants.SMT_PN_PERMISSION_GRANTED){
           //Handle the status if needed
       } else {
           //Handle the status if needed
       }
   }
}
SmartPush.getInstance(new WeakReference<>(context)).requestNotificationPermission(callback or null);

//Pass the below callback if your app require notification permission granted status else pass null

private SMTNotificationPermissionCallback notificationPermissionCallback = new SMTNotificationPermissionCallback() {

   @Override
   public void notificationPermissionStatus(int status) {
       if(status == SMTPNPermissionConstants.SMT_PN_PERMISSION_GRANTED){
           //Handle the status if needed
       } else {
           //Handle the status if needed
       }
   }
};