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 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:
- Set up authentication in your app. To learn more, see Authentication with the for Android for Android.
-
Add FCM (Firebase Cloud Messaging) to your app. To learn more, see Google's
documentation, Add Firebase to Your Android Project.
-
Add a connected-app dependency in your module's
build.gradle file.
Service Chat SDK
dependencies { // Add the connected-app dependency implementation "com.salesforce.service:connected-app:8.0.6" // ... your other dependencies go here too ... } - 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.
- Implement PushNotificationListener and handle the push notification event in the onPushNotificationReceived method.
-
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:
// Create a connected app object SalesforceConnectedApp connectedApp = SalesforceConnectedApp.create(this, new ConnectedAppConfiguration.Builder() .gcmSenderId(uniqueProjectId) .salesforceInstanceURL(siteUrl) .authTokenProvider(authProvider) .build()); // Add the push notification listener connectedApp.addPushNotificationListener(myPushNotificationListener); // Register for push notifications connectedApp.registerDeviceForPushNotifications().onError(new Async.ErrorHandler() { @Override public void handleError (Async<?> operation, @NonNull Throwable throwable) { // TO DO: Handle error } });
In Kotlin:
// Create a connected app object val connectedApp = SalesforceConnectedApp.create(this, ConnectedAppConfiguration.Builder() .gcmSenderId(uniqueProjectId) .salesforceInstanceURL(siteUrl) .authTokenProvider(authProvider) .build()) // Add the push notification listener connectedApp.addPushNotificationListener(myPushNotificationListener) // Register for push notifications connectedApp.registerDeviceForPushNotifications().onError(object: Async.ErrorHandler { override fun handleError(operation: Async<*>?, throwable: Throwable) { // TO DO: Handle error } })