Set Up Messaging Push Notifications for Android

With push notifications, your customers can be alerted about messaging activity even when they aren't viewing the conversation. When an agent sends a message, your customer receives a notification on their device.

This article applies to the following implementations:

UI SDKCore SDK

Before you add code in your app for notifications, set up your Firebase project for notifications. Then follow Salesforce org setup instructions at Set Push Notifications for Messaging for In-App.

Notifications don't appear under these circumstances.

  • The app isn't installed.
  • The device isn't online.
  • The conversation is already displayed in the foreground.
  1. Implement FirebaseMessagingService to receive notification information.

  2. When implementing the onNewToken method, call the CoreClient.provideDeviceToken(applicationContext, token) method. This method should only be called one time per token. See the provideDeviceToken reference documentation.

By default, when a user taps on the notification, your app launches to the launcher activity (typically this activity is set up as the MainActivity in your app). If you want to take them to the updated conversation, extract the conversation_id property, and then use that value to open the correct messaging conversation.

To handle an incoming notification when the app is in the foreground, implement the onMessageReceived method in the FirebaseMessagingService. The notification can be found in the notification payload of the remoteMessage. To learn more, see Handling messages in the Firebase documentation.

To handle an incoming notification when the app is in the background, capture the extra argument that was passed to the MainActivity as part of the intent.

To learn more, see Handle notification messages in a backgrounded app in the Firebase documentation.