🤖
Android
  • Chat SDK Android
  • Getting Started
    • Chat SDK Quickstart
    • Add the Chat SDK to a Firebase app
    • Add the Chat SDK to a non-Firebase app
  • Setup
    • Add Chat SDK to your project
    • Firebase Setup
    • Chat SDK Initialization
    • Set the Chat SDK Theme
    • Enable Location Messages
    • Authentication Screen
    • Add Additional Modules
    • Module Configuration
    • Proguard
  • API
    • Overriding Activities and Fragments
    • Events
    • Theming
    • Customizing the Icons
    • Tab Customization
    • Add a Chat Option
    • Message Customization
    • Integrating Chat SDK User profiles with your app
    • Overriding the Push Notification Handler
    • Handling Structured Meta Data
  • Chat SDK v4
    • Development Guide
    • Updating from v4 to v5
Powered by GitBook
On this page

Was this helpful?

  1. API

Overriding the Push Notification Handler

In some cases, your app may already use push notifications. In that case, it's useful to be able to take control of the way the Chat SDK handles push notifications.

The first step is to disable the Chat SDK push handling.

ChatSDK.config().setInboundPushHandlingEnabled(false)

In your broadcast receiver make a new instance of the BaseBroadcastHandler:

BaseBroadcastHandler bbc = new BaseBroadcastHandler()

Then in your BroadcastReceiver, onReceive method you need to check to see if the push should be handled by the Chat SDK.

You can do that by checking if the following keys exist:

public void onReceive(Context context, Intent intent) {

    Bundle extras = intent.getExtras();

    final String threadEntityID = extras.getString(Keys.PushKeyThreadEntityID);
    final String userEntityID = extras.getString(Keys.PushKeyUserEntityID);

    if (!StringChecker.isNullOrEmpty(threadEntityID) && !StringChecker.isNullOrEmpty(userEntityID)) {
       // Valid Chat SDK push, send it to the Chat SDK
        bbc.onReceive(context, intent);
    } else {
        // Handle the push yourself
    }
}

Local Push Notifications

Local notifications will be shown if the config flag is set to true:

ChatSDK.config().setShowLocalNotifications(true);

However, what would happen if you're on the ChatActivity and a messages is received for that thread. You don't want the local notification to show! So we have a second layer of control in the form of the local push handler.

ChatSDK.ui().setLocalNotificationHandler(thread -> {
    return false;
});

When deciding whether to show a local push, first the Chat SDK will check to see if this push handler is defined, if it is, it will use that value. It not, it will default back to using the showLocalNotifications value.

As an example, in the ChatActivity there is the following code in onResume:

ChatSDK.ui().setLocalNotificationHandler(thread -> !thread.getEntityID().equals(this.thread.getEntityID()));

This says that we only show a local notification if the thread for the notification is different to the thread currently displayed in the view.

So if you are customizing or building your own main activity, you will need to add some logic into the onResume to decide when pushes should be shown.

The most basic implementation would be:

ChatSDK.ui().setLocalNotificationHandler(thread -> {
    return hatSDK.config().showLocalNotifications;
});
PreviousIntegrating Chat SDK User profiles with your appNextHandling Structured Meta Data

Last updated 4 years ago

Was this helpful?