Platform docs
Auth, users, webhooks & more

Firebase Cloud Messaging

Configure Stream Video push notifications using Firebase Cloud Messaging.

Get the Firebase Credentials

Provide your Firebase credentials to Stream to enable push notifications.

  1. Go to the Firebase Console and select your project (or create one if needed).

  2. Open Service accounts in the Google Cloud console for the same project, and click Create service account. Grant it only the Firebase Cloud Messaging API Admin role.

  3. Open the service account, go to Keys, and click Add key > Create new key > JSON to download the credentials JSON file.

Stream only sends messages, so the service account needs no other role. Don't use Generate new private key under Firebase Admin SDK in the Firebase console: that service account can read and change your whole Firebase project.

Upload the credentials and create a push provider

In the Stream Dashboard, select Push Notifications:

Selecting Push Notifications menu in Stream Dashboard

Click New Configuration and select the Firebase provider. Configure these fields:

Field Name Description
Name Provider identifier used in SDK/API calls
Description Optional description for identifying this configuration
Credentials JSON Firebase credentials for sending push notifications

Configuration steps:

  1. Enter a name in the Name field (referenced in your code)
  2. Upload the Firebase credentials JSON file
  3. Enable the provider using the toggle
  4. Click Create

Example configuration using firebase as the name:

Setting up your Firebase Credentials on the Stream Dashboard

Receiving Notifications in the Client

We provide an artifact with all the implementation needed to work with Firebase. To use it follow the next steps:

Start by adding Firebase to your Android project. You only need to set up the FCM dependencies and add a google-services.json file to your project source directory.

Next, add the Stream Firebase push provider artifact to your app's build.gradle file:

dependencies {
    implementation "io.getstream:stream-android-push-firebase:1.3.5"
}

The push provider artifacts are versioned separately from the Video SDK. Use the same version as the stream-android-push artifacts that your Video SDK version depends on (1.3.5 for Video 1.37.0).

Finally, add the FirebasePushDeviceGenerator to your NotificationConfig and pass it into the StreamVideoBuilder when you initialize the SDK:

import io.getstream.android.push.firebase.FirebasePushDeviceGenerator
import io.getstream.video.android.core.StreamVideoBuilder
import io.getstream.video.android.core.notifications.NotificationConfig

val notificationConfig = NotificationConfig(
    pushDeviceGenerators = listOf(
        FirebasePushDeviceGenerator(
            context = context,
            providerName = "firebase"
        )
    )
)
StreamVideoBuilder(
    context = context,
    user = user,
    token = token,
    apiKey = apiKey,
    notificationConfig = notificationConfig,
).build()
Warning:

Make sure that StreamVideo is always initialized before handling push notifications. We highly recommend initializing it in the Application class.

That's it. You can now receive push notifications from Stream via Firebase.

Using a Custom Firebase Messaging Service

The Stream Firebase push provider artifact includes ChatFirebaseMessagingService, a FirebaseMessagingService implementation that will send new Firebase tokens and incoming push messages to the Stream SDK.

Info:

The Chat prefix in the class name is legacy naming. This service works with all Stream SDKs including Video and Chat. The naming will be updated in a future release.

If you're also using Firebase notifications for other things in your app, you can use your own custom service to replace ChatFirebaseMessagingService. This should make the following calls to the FirebaseMessagingDelegate class:

class CustomFirebaseMessagingService : FirebaseMessagingService() {

    override fun onNewToken(token: String) {
        // Update device's token on Stream backend
        try {
            FirebaseMessagingDelegate.registerFirebaseToken(token, "firebase")
        } catch (exception: IllegalStateException) {
            // StreamVideo was not initialized
        }
    }

    override fun onMessageReceived(message: RemoteMessage) {
        try {
            if (FirebaseMessagingDelegate.handleRemoteMessage(message)) {
                // RemoteMessage was from Stream and it is already processed
            } else {
                // RemoteMessage wasn't sent from Stream and it needs to be handled by you
            }
        } catch (exception: IllegalStateException) {
            // StreamVideo was not initialized
        }
    }
}
Note:

Make sure that your custom service has an <intent-filter> priority higher than -1 to override our default service. (This priority is 0 by default.)

Push Notification Payload

Push notifications are delivered as data payloads that the SDK can use to convert into the same data types that are received when working with the APIs.

When a call is started, Stream Server kicks a job that sends a regular data message (as below) to configured push providers on your app. When a device receives the payload, it's passed to the SDK which connects to Stream Video Server to process the the call and show the notification to the final user.

This is the main payload which will be sent to each configured provider:

{
  "sender": "stream.video",
  "type": "call.ring | call.notification | call.live_started",
  "call_display_name": "Jc Miñarro",
  "call_cid": "default:77501ea4-0bd7-47d1-917a-e8dc7387b87f",
  "version": "v2",
}