Push Notifications with the Service Chat SDK for Android

To take advantage of push notifications from your org to your app, set up an Apex trigger and configure your app for notifications. Pass relevant notification information, such as case feed activity, to the Service Chat SDK using your PushNotificationListener implementation.

The legacy chat product is scheduled for retirement on February 14, 2026, and is in maintenance mode until then. During this phase, you can continue to use chat, but we no longer recommend that you implement new chat channels. To avoid service interruptions to your customers, migrate to Messaging for In-App and Web before that date. Messaging offers many of the chat features that you love plus asynchronous conversations that can be picked back up at any time. Learn about chat retirement in Help.

Important

The following activities can cause notifications:

  • Agent has connected
  • Agent sent a message
  • Agent requested a file transfer
  • Agent canceled a file transfer
  • Agent ended a session

To implement notifications, follow these steps:

  1. Set up authentication in your app. To learn more, see Authentication with the Service Chat SDK for Android.
  2. Add FCM (Firebase Cloud Messaging) to your app. To learn more, see Google's documentation, Add Firebase to Your Android Project.

    Avoid any references to GCM (Google Cloud Messaging) in your build dependencies and your AndroidManifest.xml files. If you experience a NoClassDefError which claims that GcmReceiver is missing, it may be included in your final merged manifest by one of your dependencies, such as the Salesforce Mobile SDK. To resolve the error, add the following remove instruction to your AndroidManifest.xml: <receiver android:name="com.google.android.gms.gcm.GcmReceiver" tools:node="remove"/>.

    Note

  3. Add a connected-app dependency in your module's build.gradle file.
    Service Chat SDK
    1dependencies {
    2            
    3  // Add the connected-app dependency
    4  implementation "com.salesforce.service:connected-app:8.0.6"
    5
    6  // ... your other dependencies go here too ...
    7}

    The version of the connected-app is the same as the version of the Common module used by the Service Chat SDK.

    Note

  4. Create a connected app and an Apex trigger to send a notification from your org. Follow the instructions in the Salesforce Mobile Push Notifications Implementation Guide for Creating a Connected App.
  5. Implement PushNotificationListener and handle the push notification event in the onPushNotificationReceived method.
  6. Configure using the Sender ID, AuthTokenProvider, and the site URL.

    Pass this object your push notification listener and then register your device for push notifications.

    In Java:

    1// Create a connected app object
    2SalesforceConnectedApp connectedApp = 
    3  SalesforceConnectedApp.create(this, new ConnectedAppConfiguration.Builder()
    4    .gcmSenderId(uniqueProjectId)
    5    .salesforceInstanceURL(siteUrl)
    6    .authTokenProvider(authProvider)
    7    .build());
    8
    9// Add the push notification listener
    10connectedApp.addPushNotificationListener(myPushNotificationListener);
    11
    12// Register for push notifications
    13connectedApp.registerDeviceForPushNotifications().onError(new Async.ErrorHandler() {
    14  @Override public void handleError (Async<?> operation, @NonNull Throwable throwable) {
    15    // TO DO: Handle error
    16  }
    17});

    In Kotlin:

    1// Create a connected app object
    2val connectedApp = SalesforceConnectedApp.create(this, ConnectedAppConfiguration.Builder()
    3    .gcmSenderId(uniqueProjectId)
    4    .salesforceInstanceURL(siteUrl)
    5    .authTokenProvider(authProvider)
    6    .build())
    7
    8// Add the push notification listener
    9connectedApp.addPushNotificationListener(myPushNotificationListener)
    10
    11// Register for push notifications
    12connectedApp.registerDeviceForPushNotifications().onError(object: Async.ErrorHandler {
    13  override fun handleError(operation: Async<*>?, throwable: Throwable) {
    14    // TO DO: Handle error
    15  }
    16})