android - OneSignal 推送通知 | 在聊天时禁用它们进行聊天| 安卓
问题描述
我正在Android 中构建一个一对一的聊天应用程序。一切正常,但我想知道如何避免在对话打开时收到对话通知。
示例:我正在与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())
推荐阅读
- python - 如何对来自 `image_dataset_from_directory()` 的图像进行图像转换,以便将其转换为 Lab 并返回 L 通道?
- python - 如何修改保存的html页面?
- android - 我如何编码 SplashScreenActivity.kt 因为我的不起作用
- python - 使用 Python 抓取网站时设置代理
- spring-boot - 如何使用 Spring Boot 或 Spring Kafka 集成将消息从多个主题发送到多个主题
- javascript - 如何验证输入值是否确实存在?
- c++ - 是否保证一个线程最终可以看到另一个线程对某个共享变量的写入?
- javascript - 重定向循环passportJS
- algorithm - 通过一次获取整个数据而不是一个文件来压缩文件夹
- ruby-on-rails - 加载数据库定义时获取未定义的方法 oid