Customer Engagement

Using the Netcore CE dashboard, 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 process.

Complete Basic Setup

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

Adding SmartPush SDK Dependency

  1. 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.

Set 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.**.* {*;}

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.

Send FCM token to Netcore CE SDK

📘

Important

This step is required only for SmartPush - version 3.3.1 and below.

Call the following method in onCreate function of your Application class after initializing the Netcore CE SDK to allow CE 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.")
}

For SmartPush 3.5.0 version

For SmartPush version 3.5.0 and above, the methods isNotificationFromSmartech and handlePushNotification are deprecated. Two new methods have been introduced, where customers must now pass a remoteMessage object directly: isRemoteNotificationFromSmartech and handleRemotePushNotification. Customers are not required to check isRemoteNotificationFromSmartech every time, as it is internally handled by handleRemotePushNotification.

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 isPnHanledBySmartech = SmartPush.getInstance(new WeakReference<Context>(context)).handleRemotePushNotification(remoteMessage);
          if(!isPnHanledBySmartech){
           // Notification from other sources, handle yourself
          }
    }
}
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 isPnHanledBySmartech:Boolean = SmartPush.getInstance(WeakReference(context)).handleRemotePushNotification( remoteMessage))
        if (!isPnHanledBySmartech){
     	// Notification from other sources, handle yourself
        }
    }
}

For versions below SmartPush 3.5.0

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 it 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
        }
    }
}

Retreive Deeplink Data

🚧

Reminder

Kindly ignore this step if it is already handled through the basic setup.

Implement a BroadcastReceiver for the Deeplinks.

public class DeeplinkReceiver extends BroadcastReceiver {
   @Override
   public void onReceive(Context context, Intent intent) {
       try {
           Bundle bundleExtra = intent.getExtras();
           if (bundleExtra != null) {
               String deepLinkSource = bundleExtra.getString(SMTBundleKeys.SMT_KEY_DEEPLINK_SOURCE);
               String deepLink = bundleExtra.getString(SMTBundleKeys.SMT_KEY_DEEPLINK);
               String customPayload = bundleExtra.getString(SMTBundleKeys.SMT_KEY_CUSTOM_PAYLOAD);
               if (deepLink != null && !deepLink.isEmpty()) {
                   // handle deepLink for redirection. Here you can use deepLinkSource for redirection if required
               }
               if (customPayload != null && !customPayload.isEmpty()) {
                   // handle your custom payload based on deeplink source like below if required
               }
           }
       } catch (Throwable t) {
           Log.e("DeeplinkReceiver", "Error occurred in deeplink:" + t.getLocalizedMessage());
       }
   }
}

class DeeplinkReceiver : BroadcastReceiver() {
   override fun onReceive(context: Context?, intent: Intent?) {
       try {
           val bundleExtra = intent?.extras
           bundleExtra?.let {
               val deepLinkSource = it.getString(SMTBundleKeys.SMT_KEY_DEEPLINK_SOURCE)
               val deepLink = it.getString(SMTBundleKeys.SMT_KEY_DEEPLINK)
               val customPayload = it.getString(SMTBundleKeys.SMT_KEY_CUSTOM_PAYLOAD)
               if (deepLink != null && deepLink.isNotEmpty()) {
                   // handle deepLink for redirection. Here you can use deepLinkSource for redirection if required
               }
               if (customPayload != null && customPayload.isNotEmpty()) {
                   // handle your custom payload based on deeplink source like below if required
               }
           }
       } catch (t: Throwable) {
           Log.e("DeeplinkReceiver", "Error occurred in deeplink:${t.localizedMessage}")
       }
   }
}

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)

🚧

Caution

Add the following code in the onCreate function of the launcher activity of your application only if you are using the SDK version below 3.5.0.

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

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 Netcore CE 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 Netcore CE 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

According to Google’s UI guidelines, the notification icon must be in .png format. The recommended size for push notification icons is specified 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

📘

Note

While we encourage using SDK versions above 3.2.x, those still on 3.1.x should continue using Smartech instead of SmartPush.

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.

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
       }
   }
};