Chat SDK v4 2x

Swift, Kotlin, and TypeScript SDKs

Build in-app chat, calls, and live streaming

On This Page

Troubleshooting Android chat push notifications in Sendbird

Alex Preston, Solutions Engineer
Alex Preston
Solutions Engineer
  • Tutorial Type: Basic
  • Reading Time: 20 mins
  • Building Time: N/A
Chat SDK v4 2x

Swift, Kotlin, and TypeScript SDKs

Build in-app chat, calls, and live streaming

Chat SDK v4 2x

Swift, Kotlin, and TypeScript SDKs

Build in-app chat, calls, and live streaming

On This Page

Introduction

Push notifications are vital prompts that deliver important information while serving as a gentle reminder to users to engage with the content in your app. Push notifications are important because they deliver important information, updates, and increase user engagement with your app. Our guide to mobile push notifications has everything you need to know about push notifications, their benefits, and how they can be used.

However, troubleshooting push notifications issues isn’t always easy. To simplify the task of debugging and troubleshooting push notifications, we have created a new tester tool. This guide is supplemental to our tester tool. In this guide, we’ll help you understand how push notifications work with Sendbird, and we’ll also provide additional guidance in troubleshooting issues. Please note that this guide reviews push notifications for the Android SDK only and is supplemental to the Android docs.

We’ll start with some preliminary checks before discussing best practices for device tokens. Then we’ll talk about troubleshooting some common scenarios. We’ll also discuss some basic tests to diagnose a specific cause and find solutions to fix the problem.

All set? Let’s begin. 👨‍💻

Basic checks

Please check with your development team to verify the following:

  1. You have enabled push notifications on the Sendbird dashboard for Firebase Cloud Messaging (FCM) or Huawei Mobile Services (HMS). Please refer to our tutorial to understand how to implement push notifications for Android apps.
  2. Your app has registered a push token for your user. The top issue faced by most app developers is that the push token for the user is not properly registered or is no longer valid. To check the user’s push token on the Sendbird Dashboard, go to the “Dashboard” > “Users” section, select your user, and look for “Push Token” in the “Chat” section.
  3. You are testing push notifications in Group Channels (push notifications are not supported in Open Channels).
  4. Your app does not disconnect() the user and unregister the device token when the app goes into the background. Using disconnect() and unregistering the token is mainly recommended when the user logs out of the device and no longer needs to receive notifications.
  5. Your device has the app running in the background or closed to receive remote notifications from FCM via Sendbird. Please note the push notification setting on the app dashboard in this case:
    1. With the ‘Send as long as one device is offline’ setting, the Sendbird server tries to send a notification to any device. Still, only devices in the background can receive the remote notification because the Chat SDK detects when the user is disconnected and offline.
    2. With the ‘Send when all devices are offline setting, every single device running the app with the connected user must be running in the background or closed.
  6. You are testing with the latest version of the Sendbird Android SDK.

If you confirm all of the above and the problem still persists, please contact Sendbird support on your Sendbird dashboard (Dashboard > Your Organization Name (at the top right) > Contact Us). In your description of the issue, please share the app id, Android Chat SDK version number, user id and device token for that user, channel_url, and a timestamp of the last push notification test performed so we can investigate further. Screenshots, GIFs, or videos of the issue can also help in an investigation.

Best practices for device tokens

Sendbird follows this FCM guideline: “Because the token could be rotated after initial startup, you are strongly recommended to retrieve the latest updated registration token.” We recommend registering your user’s push token to Sendbird every single time the user connects to Sendbird.

The list below specifies when the token may be updated on the device:

  1. The app deletes Instance ID.
  2. The app is restored on a new device.
  3. The user uninstalls/reinstalls the app.
  4. The user clears app data.

Troubleshooting by case

  1. User is not offline: It’s easiest to test push notifications when your user is offline and the app is not in the foreground on any device. Check that user’s offline status in the Users section of the Sendbird dashboard.
  2. Device token issues: Ensure the user has a device token registered. To check the user’s push token on the Sendbird dashboard, go to the Users section under your app. Select your user and look for Push Token in the Chat section. If the user has multiple device tokens (as seen through the platform API here), please try to unregister all of the user’s current device tokens by calling the platform API. Add a new token by calling the platform API or by rerunning the app. This registers the user’s device token via the SDK. Check the Sendbird dashboard for the user’s latest token.
  3. Specific user cannot receive a push notification: Check that the test user does not have push notifications disabled. Our platform API makes it easy to:
    1. Check the user’s push preferences through the platform API.
    2. Check the is_push_enabled channel property of your test channel when you fetch the user’s group channels list through our platform API. If is_push_enabled is ‘false’, update the user’s push preferences for a specific channel to see that the test channel where the push notification should be received is a group channel and does not have push notifications disabled for this user.
  4. User sometimes receives a push: Check for local or remote notification support. If your app is explicitly generating notifications locally while the app is in the foreground, then these local notifications are NOT triggered by FCM/HMS as push notifications sent by Sendbird. Your application may be listening to the message received event handler in the app and triggering a local notification that looks like a push notification.
    1. FCM: Check that the FCM notification payload from Sendbird is handled by the onMessageReceived (RemoteMessage remoteMessage) method in your own MyFirebaseMessagingService.java class. The onMessageReceived method outside of this class is an event handler that will be fired for messages received while the user is online and may trigger local notifications only.
  5. User can receive notifications on one device, but not another (multi-device support): One device may receive a push notification for the user while another does not. Ensure you have selected the ‘Send as long as one device is offline’ setting on your Sendbird dashboard > Settings > Notifications. Additional code is required to support push notifications on multiple devices from Firebase Cloud Messaging (FCM) and from Huawei Mobile Service (HMS).

Testing

When debugging, it helps to add in a debug log message in the MyFirebaseMessagingService class onMessageReceived method. This will help you identify if a remote notification was received on the device but was not displayed successfully.

Test to determine if your Sendbird application can receive notifications from Sendbird’s server

  1. Download Sendbird’s Android sample app and change the application ID to your Sendbird app ID.
  2. Change the package name to your app’s package name that matches the certificate uploaded to the Sendbird dashboard.

    Note: If you are using a deprecated Google Cloud Messaging (GCM) project, we recommend migrating the project to a Firebase Cloud Message (FCM) project to send push notifications or fetch the device token from the GCM project and register that token to Sendbird. More information and steps can be found here.

  3. Sign in as a user (user A).
  4. Quit the app. Ensure that the app is not in the background and that user A is offline.
  5. On another device, send a message to the user (user A) from another user (user B). Did the first user (user A) receive the notification? If yes, then push notifications can be sent by the Sendbird server to your application. In your application, check that your application is registering a device token for your user and that your application implements the onMessageReceived(RemoteMessage remoteMessage) method in your own MyFirebaseMessagingService.java class.

Development testing with a production app user

It’s possible to test push notifications in development against a production app user.

  1. Start with a production app user ‘Bob’ and ensure ‘Bob’ is offline.
  2. Under the current production app, device token A is associated with the production certificate for ‘Bob’.
  3. Next, upload your FCM or HMS development credentials to the Sendbird dashboard.
  4. Run the app in Android Studio on your own test device to test with the development credentials. Connect as user ‘Bob’ and ensure your application registers a new device token B for the development credentials.
  5. Sendbird tries to send a push notification to device token B for the production credentials and the development credentials. Only the development credentials succeed, and now device token B is associated with the development credentials.
  6. User ‘Bob’ will still have device token A associated with the production credentials unless that token is unregistered or a new token is registered for Bob’s device.

Other notes

Language Translation: When message translation is enabled for your application, push notifications can be translated to other languages by specifying the user’s preferred_languages through the platform API or by adding these languages through the SDK.

Conclusion

Troubleshooting push notifications can be complex; that’s why, in addition to our tester tool, you may find the guidance on this page to be useful. Between this guide, the tester tool, and the docs for FCM and HMS, you’ll be building and testing push notifications in no time!

As always, for additional guidance, please don’t hesitate to reach out to us.

Happy push notifications testing! 💻