OneSignal推送通知|在聊天时禁用它们| Android
我正在安卓系统中构建一对一聊天应用程序。 一切正常,但我想知道如何避免在对话打开时收到对话通知 例如: 我正在与B通话,B向我发送消息,我在聊天视图中看到消息,但我也收到通知,告诉我B向您发送了消息OneSignal推送通知|在聊天时禁用它们| Android,android,kotlin,push-notification,chat,onesignal,Android,Kotlin,Push Notification,Chat,Onesignal,我正在安卓系统中构建一对一聊天应用程序。 一切正常,但我想知道如何避免在对话打开时收到对话通知 例如: 我正在与B通话,B向我发送消息,我在聊天视图中看到消息,但我也收到通知,告诉我B向您发送了消息 我怎样才能避免呢?我想不出一个有效的解决方案。您可以使用此处理程序来决定是否显示通知 class NotificationWillShowInForegroundHandler : OneSignal.OSNotificationWillShowInForegroundHandler {
我怎样才能避免呢?我想不出一个有效的解决方案。您可以使用此处理程序来决定是否显示通知
class NotificationWillShowInForegroundHandler : OneSignal.OSNotificationWillShowInForegroundHandler {
override fun notificationWillShowInForeground(notificationReceivedEvent: OSNotificationReceivedEvent?) {
when (isHideInForeground) {
true -> {
notificationReceivedEvent?.complete(null)
}
else -> {
notificationReceivedEvent?.complete(notificationReceivedEvent.notification)
}
}
}
}
初始化
OneSignal.setNotificationWillShowInForegroundHandler(NotificationWillShowInForegroundHandler())
你是如何显示通知的?如果没有后端,我怀疑是否有解决方案。如果您有后端,您可以向设备发送类似“idChat”的内容,如果在通知中接收到的idChat与您所在的idChat相同,请防止在NotificationExtender服务中显示通知