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.
In your broadcast receiver make a new instance of the 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:
Local Push Notifications
Local notifications will be shown if the config flag is set to 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.
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
:
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:
Last updated