Setting up Push Notifications

Lucra can setup push notifications for your app to notify users of important events throughout the lifecycle of a Matchup.

Lucra SDK's push notification works with your existing Firebase push notification solution.

NOTE: Please reach out to Lucra support to start the process of notification setup. This document walks through the steps required after Lucra setup is complete.

class MyFirebaseMessagingService : FirebaseMessagingService() {

    override fun onNewToken(token: String) {
        super.onNewToken(token)
        // This method is called when a new token is generated.
        LucraPushNotificationService.refreshFirebaseToken(token)
    }

    override fun onMessageReceived(message: RemoteMessage) {
        super.onMessageReceived(message)

        // Determines if this push notification is Lucra-specific. We will show the resulting notification if it is
        if (!LucraPushNotificationService.handlePushNotification(
                context = this,
                remoteMessage = message,
                activityClass = MainActivitySdk::class.java,
                smallIcon = R.drawable.lucra_letter_landing
            )
        ) {
            showNotification(message)
        }
    }

    private fun showNotification(message: RemoteMessage) {
        //Show your app specific notifications
    }
}

LucraPushNotificationService.refreshFirebaseToken(token)

Pass in the unique device token that's generated by Firebase.

The Firebase token can also be retrieved from your Activity via...

LucraPushNotificationService.handlePushNotification(...)

This function will return true if the incoming push notification is Lucra-specific. The Lucra SDK will consume and display the notification to the user.

  • Parameters:

    • context: Context Context of the Service

    • remoteMessage: RemoteMessage The push notification data from Firebase

    • activityClass: Class<*> The Java class of the Activity that you want the push notification to open after a click.

    • smallIcon: Int The drawable resource id of the icon you want to display next to the Lucra notification

The function also automatically creates a Lucra-specific default notification channel if one doesn't already exist. This channel is created with high importance and is used for all Lucra SDK notifications.

Handling Lucra push notification click events

Within the activityClass Activity you specified above, handle the incoming Intent and parse the Lucra-specific notification to show a LucraFlow. Add handleNotificationIntent to the following locations.

onNewIntent contains the notification data when the Android app is in the background and the notification is clicked.

onCreate contains the notification data when the app is dead and the notification is clicked

Last updated