Push Notifications for Android and Web

Copied!
If you're looking to speed up your Android app development, you can use our Android Chat SDK to get started. It's feature rich and will speed up your development!

Using Firebase, your users can receive push notifications directly to their client app for new messages when offline. In order to send push notifications to Android devices, you need to have an application on Firebase and configure your Stream account using the Firebase server key.

Retrieving the Server Key from Firebase

Copied!

Step 1

Copied!

From the Firebase Console, select the project your app belongs to

Step 2

Copied!

Click on the gear icon next to Project Overview and navigate to Project settings

Step 3

Copied!

Navigate to the Cloud Messaging tab

Step 4

Copied!

Under Project Credentials, locate the Server key and copy it

Step 5

Copied!

Upload the Server Key in your chat dashboard

Step 6

Copied!

Save your push notification settings changes

OR -

Copied!

Upload the Server Key via API call

Remember to add google-services.json file to your project source directory. For more information take a look at Firebase setup tutorial.

Registering a device at Stream Backend

Copied!

Once you configure Firebase server key and set it up on Stream dashboard a device which is supposed to receive push notifications needs to be registered at Stream backend. This is usually done by requesting a Firebase device token and passing it to the backend as follows:

Device registration logic above is also performed automatically when you set up User data in the Chat or ChatClient objects. If you use Android Chat SDK or Android ChatClient low level SDK there is no need to register the device manually.

Setting up notification data payload at Stream Dashboard

Copied!

1. Setup the following push notification data payload at Stream Dashboard:

2. If you are using Stream Chat Android SDK add the following notifications config into your Chat building logic:

Make sure that ChatClient is initialized before push notification is handled.

Handling notifications from multiple providers

Copied!

SDK allows you to handle push notifications from multiple providers in two different ways:

1. Using custom ChatNotificationHandler:

2. Implementing custom FirebaseMessagingService:

Make sure that CustomMessageFirebaseService's priority is higher than -1 to override the default service
Make sure that ChatClient is initialized before push notification is handled.

Redirection from notification to app

Copied!

In order to adjust redirection from notification to the specific Activity in your app (when clicking on the notification), you need to an Intent which will hold a target Activity and metadata of the message. In order to define this Intent you should override ChatNotificationHandler class and pass it to ChatClient.Builder.

Possible issues

Copied!

if RemoteMessage does not arrive (is not intercepted) check if notification template is defined correctly at the Stream Dashboard. Read more about difference between notification and data here.