如何在Kotlin的特定活动中禁用接收通知?
我有一个聊天应用程序,但我在聊天活动中收到通知。 我想禁用它,并在我不在聊天活动中时收到通知。
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
我有一个聊天应用程序,但我在聊天活动中收到通知。 我想禁用它,并在我不在聊天活动中时收到通知。
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
接受
或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
发布评论
评论(1)
虽然您可以以某种方式将应用程序实例标记为在显示特定活动时不接收来自 FCM 的消息,但这可能非常不可靠,因为影响交付的因素有很多。
更好的方法是接收消息,但在显示活动时忽略它,无论是在您的
onMessageReceived
方法 或在处理它的下游代码中。由于系统仅在您的应用未活动时显示通知,因此在应用活动时忽略消息将与不接收消息具有相同的效果,并且更可靠。While you could somehow flag the app instance to not receive messages from FCM while it's showing a specific activity, that would be likely be quite unreliable as there are many factors affecting delivering.
The better approach would be to receive the message, but ignore it while the activity is showing, either in your
onMessageReceived
method or in code further downstream that handles it. Since notifications are only displayed by the system when your app is not active, ignoring the messages while the app is active will have the same effect as not receiving them, and is more reliable.