Reputation: 133
I'm building a One-to-one chat app in Android. Everything is working fine but I wonder how I can do to avoid receiving notifications for a conversation when this conversation is open.
Example: I'm speaking with B and B sends me a message, I see the message in the chat view BUT I also receive the notification telling me B sent you a message.
How can I avoid that? I can't think of a working and efficient solution.
Upvotes: 0
Views: 902
Reputation: 180
You can use this handler to decide if the notification should show or not
class NotificationWillShowInForegroundHandler : OneSignal.OSNotificationWillShowInForegroundHandler {
override fun notificationWillShowInForeground(notificationReceivedEvent: OSNotificationReceivedEvent?) {
when (isHideInForeground) {
true -> {
notificationReceivedEvent?.complete(null)
}
else -> {
notificationReceivedEvent?.complete(notificationReceivedEvent.notification)
}
}
}
}
Initialization
OneSignal.setNotificationWillShowInForegroundHandler(NotificationWillShowInForegroundHandler())
Upvotes: 1