【问题标题】:OneSignal push notification | disable them for a chat when in the chat | AndroidOneSignal 推送通知 |在聊天时禁用它们进行聊天|安卓
【发布时间】:2019-10-03 10:52:58
【问题描述】:

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

示例: 我正在与 B 通话,B 向我发送了一条消息,我在聊天视图中看到了这条消息,但我也收到了通知,告诉我 B 向你发送了一条消息。

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

【问题讨论】:

  • 你如何显示通知?
  • 如果没有后端,我怀疑是否有解决方案。如果您有后端,您可以向设备发送“idChat”之类的内容,如果在通知中收到的 idChat 与您所在的 idChat 相同,请阻止在 NotificationExtenderService 中显示通知

标签: android kotlin push-notification chat onesignal


【解决方案1】:

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

class NotificationWillShowInForegroundHandler : OneSignal.OSNotificationWillShowInForegroundHandler {

    override fun notificationWillShowInForeground(notificationReceivedEvent: OSNotificationReceivedEvent?) {
        when (isHideInForeground) {
            true -> {
                notificationReceivedEvent?.complete(null)
            }
            else -> {
                notificationReceivedEvent?.complete(notificationReceivedEvent.notification)
            }
        }
    }
}

初始化

OneSignal.setNotificationWillShowInForegroundHandler(NotificationWillShowInForegroundHandler())

【讨论】:

    猜你喜欢
    • 2016-09-25
    • 2018-01-20
    • 1970-01-01
    • 2015-11-20
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2017-08-13
    • 1970-01-01
    相关资源
    最近更新 更多