Skip to main content

Push Notifications

Push notifications allow you to engage users and deliver timely updates and alerts, even when your app is not running. This guide outlines the steps to integrate push notification functionality for LikeMinds Feed SDK in your app.

Refer to Notification List to see the list of notifications triggered.

Prerequisites

Before proceeding with the integration, make sure you have the following prerequisites in place:

  • FCM Service Account Keys: Obtain the Firebase Cloud Messaging service account keys from the Firebase Console. Here is the guide to obtain the same.

Implementation

Step 1 - Enable Push Notification and Share Device Id

While setting up LikeMinds Feed SDK in onCreate() method of the Application class, send enablePushNotifications as true and user's deviceId in LMFeedCore.setup()

val application = this
val enablePushNotifications = false
val deviceId = "ENTER USER'S DEVICE ID"
val domain = "ENTER YOUR DOMAIN HERE"

val lmFeedCoreCallback = object : LMFeedCoreCallback {}

LMFeedCore.setup(
application = application,
enablePushNotifications = enablePushNotifications,
deviceId = deviceId,
domain = domain,
lmFeedCoreCallback = lmFeedCoreCallback
)

Step 2 - Handle Notification in FirebaseMessagingService

  1. Create a class which extends FirebaseMessagingService (if not already present) which will receive the triggered notification.
class MessagingService: FirebaseMessagingService() {
override fun onCreate() {
super.onCreate()
}

override fun onMessageReceived(message: RemoteMessage) {
super.onMessageReceived(message)
}
}
  1. Create a instance of LMFeedNotificationHandler in the onCreate() method of the Service
class MessagingService: FirebaseMessagingService() {

private lateinit var mNotificationHandler: LMFeedNotificationHandler

override fun onCreate() {
super.onCreate()
mNotificationHandler = LMFeedNotificationHandler.getInstance()
mNotificationHandler.create(this.application)
}

override fun onMessageReceived(message: RemoteMessage) {
super.onMessageReceived(message)
}
}
  1. Add handleNotification() method in onMessageReceived() method and pass the data received in the same function.
class MessagingService: FirebaseMessagingService() {

private lateinit var mNotificationHandler: LMFeedNotificationHandler

override fun onCreate() {
super.onCreate()
mNotificationHandler = LMFeedNotificationHandler.getInstance()
mNotificationHandler.create(this.application)
}

override fun onMessageReceived(message: RemoteMessage) {
super.onMessageReceived(message)
mNotificationHandler.handleNotification(message.data)
}
}