Push Messaging Guide
This guide will show you how to integrate the Webex Connect Push Messaging capability into your Android application.
Please ensure you have integrated the In-App Messaging Module by following the Quick Start Guide.
To register notification channel
Starting in Android 8.0 (API level 26), all notifications must be assigned to a channel or they will not be displayed. Channels allow users greater control over their notifications. Users may disable specific channels or control the visual and auditory options for each channel directly from the Android system settings app. Users may also long-press a notification to change behaviours for the associated channel. For more info on the Notification Channel, refer to the Android official documentation on the notification channel.
// Sample code to register Notification channel:
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
//Provide your channel name & description that will be visible to the user. These will need configuring in your strings.xml
val name = getString(R.string.channel_name)
val description = getString(R.string.channel_description)
//A channel registered with the id of NotificationFactory.DEFAULT_CHANNEL_ID is required as a minimum
val channel = NotificationChannel(NotificationFactory.DEFAULT_CHANNEL_ID, name, NotificationManager.IMPORTANCE_DEFAULT) channel.description = description
// Register the channel with the system
val notificationManager = getSystemService(NOTIFICATION_SERVICE) as NotificationManager notificationManager.createNotificationChannel(channel)
}
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
// Provide your channel name & description that will be visible to the user. These will need configuring in your strings.xml
String name = getString(R.string.channel_name);
String description = getString(R.string.channel_description);
// A channel registered with the id of NotificationFactory.DEFAULT_CHANNEL_ID is required as a minimum.
NotificationChannel channel = new NotificationChannel(NotificationFactory.DEFAULT_CHANNEL_ID, name, NotificationManager.IMPORTANCE_DEFAULT);
channel.setDescription(description);
// Register the channel with the system
NotificationManager notificationManager = (NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE);
notificationManager.createNotificationChannel(channel);
}
Notification Customization
To customize the notification build process, you need to implement and set the callback on the default NotificationFactory
instance as follows:
class MyNotificationBuilder: NotificationBuilderCallback
{
override fun getActionIconId(
context: Context,
message: PushMessage,
action: String,
identifier: String
): Int
{
//Return id of the icon specific to the action
return 0
}
override fun onBuildNotification(
context: Context,
message: PushMessage,
notificationId: Int,
builder: NotificationCompat.Builder
)
{
//Customize notification build process here
}
}
//Set your notification builder callback.
PushMessaging.instance.notificationFactory?.notificationBuilderCallback = MyNotificationBuilder()
Alternatively, to entirely replace the inbuilt notification build process, set PushMessaging.instance.notificationFactory
to your custom implementation, like so:
//Implement your NotificationFactory and override the createNotification method with your custom implementation.
class MyNotificationFactory : NotificationFactory {
}
PushMessaging.instance.notificationFactory = MyNotificationFactory()
Register Push Listener
PushMessaging.instance.registerMessagingListener { pushMessage: PushMessage ->
//Handle push
}
val pushMessage = PushMessaging.instance
PushMessaging.getInstance().registerMessagingListener(pushMessage -> {
//Handle push
return Unit.INSTANCE;
});
With this you have successfully integrated the Push Messaging module in your app.
Updated 8 days ago