Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/android/218.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
OneSignal推送通知|在聊天时禁用它们| Android_Android_Kotlin_Push Notification_Chat_Onesignal - Fatal编程技术网

OneSignal推送通知|在聊天时禁用它们| Android

OneSignal推送通知|在聊天时禁用它们| Android,android,kotlin,push-notification,chat,onesignal,Android,Kotlin,Push Notification,Chat,Onesignal,我正在安卓系统中构建一对一聊天应用程序。 一切正常,但我想知道如何避免在对话打开时收到对话通知 例如: 我正在与B通话,B向我发送消息,我在聊天视图中看到消息,但我也收到通知,告诉我B向您发送了消息 我怎样才能避免呢?我想不出一个有效的解决方案。您可以使用此处理程序来决定是否显示通知 class NotificationWillShowInForegroundHandler : OneSignal.OSNotificationWillShowInForegroundHandler {

我正在安卓系统中构建一对一聊天应用程序。 一切正常,但我想知道如何避免在对话打开时收到对话通知

例如: 我正在与B通话,B向我发送消息,我在聊天视图中看到消息,但我也收到通知,告诉我B向您发送了消息


我怎样才能避免呢?我想不出一个有效的解决方案。

您可以使用此处理程序来决定是否显示通知

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服务中显示通知