Configuring Push Notifications
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 5 steps process.
Step 1: Complete basic setup
Go to Basic Setup to start integrating your Android project with CEE SDK.
Step 2: 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 3: 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 {
smartech.fetchAlreadyGeneratedTokenFromFCM();
} catch (Exception e) {
Log.e(TAG, "Fetching FCM token failed.");
}
try {
smartech.fetchAlreadyGeneratedTokenFromFCM()
} catch (e: Exception) {
Log.e(TAG, "Fetching FCM token failed.")
}
Provide token via setDevicePushToken() and notification payload via handlePushNotification() methods to CEE 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);
Smartech.getInstance(new WeakReference<Context>(this)).setDevicePushToken(token);
//<Your code>
}
@Override
public void onMessageReceived(@NonNull RemoteMessage remoteMessage) {
super.onMessageReceived(remoteMessage);
boolean pushHandledBySmartech = Smartech.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)
Smartech.getInstance(WeakReference(this)).setDevicePushToken(token)
}
override fun onMessageReceived(remoteMessage: RemoteMessage) {
super.onMessageReceived(remoteMessage)
Smartech.getInstance(WeakReference(applicationContext)).handlePushNotification(remoteMessage.data.toString())
}
}
Step 4: 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 5: 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. This push notification icon will be shown on the left-hand side of the app name in the notification header section.
SMTNotificationOptions options = new SMTNotificationOptions(this);
options.setSmallIconTransparentId(R.drawable.ic_notif);
Smartech.getInstance(new WeakReference<>(context)).setNotificationOptions(options);
val options = SMTNotificationOptions(this)
options.smallIconTransparentId = R.drawable.ic_notif
Smartech.getInstance(WeakReference(context)).setNotificationOptions(options)
Push Notification Brand Logo
You can use the following code in order to change the push notification brand logo. This brand logo will appear on the right-hand side of the notification's title and message body.
SMTNotificationOptions options = new SMTNotificationOptions(this);
options.setBrandLogoId(R.drawable.ic_notif);
Smartech.getInstance(new WeakReference<>(context)).setNotificationOptions(options);
val options = SMTNotificationOptions(this)
options.brandLogoId = R.drawable.ic_notif
Smartech.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");
Smartech.getInstance(new WeakReference<>(context)).setNotificationOptions(options);
val options = SMTNotificationOptions(this)
options.transparentIconBgColor = "#007AFF"
Smartech.getInstance(WeakReference(context)).setNotificationOptions(options)
Updated 4 months ago
Choose from below options to setup further features of your app's push notifications!