Push Notifications Guide

Push Notifications Guide

The StreamLayer SDK for Android supports push notifications via the Firebase Cloud Messaging service. Push Notifications are used to notify incoming chat messages and Watch Parties.

Prerequisites

  1. Register your app on Firebase via the Firebase Console
  2. Setup the host app to listen for new FCM messages and FCM tokens.

Integration with StreamLayer

In order to send push notifications to your host app device, we require an FCM token. Use the StreamLayer.uploadFCMToken() function to register the host app with the StreamLayer service. When push notifications are received, call StreamLayer.handlePush() function to check if it needs to be processed by the StreamLayer SDK or in your host apps notification code block.

Here is an example in your extended FirebaseMessagingService class.

import io.streamlayer.sdk.StreamLayer

class HostAppFirebaseMessagingService : FirebaseMessagingService() {

    override fun onNewToken(s: String) {
        super.onNewToken(s)

        // upload token to StreamLayer service
        StreamLayer.uploadDeviceFCMToken(application, s)
    }

    override fun onMessageReceived(remoteMessage: RemoteMessage) {
        
        // when push notification received, let StreamLayer SDK check if the push was sent from StreamLayer service.
        if (!StreamLayer.handlePush(application, remoteMessage.data)) {
            // if this was not a StreamLayer notification, handle your host app notifications
        }
    }
}

Notification Settings

The StreamLayer SDK creates two notification channels in your app settings - StreamLayer and StreamLayer Watch Party. Users also have the option to customize notification settings inside the StreamLayer SDK overlays.


Further Reading

When a user taps on a notification, the host app will open by default. To set up deep linking so the user is navigated directly to the StreamLayer overlay, follow our Deep Links Guide.

Examples of usage FirebaseMessagingService can be found here