Android上的Firebase - 我想在Android客户端上禁用Firebase通知 [英] Firebase on Android - I want to disable firebase notifications on Android client
问题描述
我正在使用Firebase控制台向用户发送通知。
但是我想让用户禁用通知。
如何禁用它们?
只有当应用程序处于前台时,才能通过FirebaseMessagingService处理(和停止)通知。但是,当应用程序在后台时,我无法停止通知。
不知道为什么会发生这种情况(代码片段也许? ,但有一个重量级的最终解决方案:在清单中定义您自己的c2dm接收器,并将优先级设置为高(> 0),然后停止处理。
GCM消息按照有序的广播方式进行处理,因此您可以通过调用此方法来停止处理链:
https://developer.android.com/reference/android/content/BroadcastReceiver.html#abortBroadcast()
如果您在接收器中没有做任何事情,则下一个接收器将执行处理,它将成为Firebase接收器。
请注意:尽管这样做可能是安全的,但是您认为没有其他内容是作为推送通知发送的通过Firebase进行。现在可能是这样(虽然我不完全确定),但未来可能会改变。所以,请记住这一点,并广泛地测试解决方案。
I'm using Firebase console to send notifications to users. However I want to let users disable notifications. How can I disable them?
I am able to handle (and stop) notifications through FirebaseMessagingService only when the app is in foreground. But I cannot stop notifications when the app is in background.
Not sure why this happens to you (code snippet maybe?), but there is a heavy weight ultimate solution: define your own c2dm receiver in the manifest and set the priority high (>0) then stop the notification from processing.
GCM messages are processed as ordered broadcasts, so you can stop the processing chain by calling this method:
https://developer.android.com/reference/android/content/BroadcastReceiver.html#abortBroadcast()
If you don't do anything in your receiver then the next receiver will do the processing, which will be the Firebase receiver.
Please note: while it is safe to do this probably, you are assuming that nothing else is sent as push notification by Firebase. It might be true now (although I am not entirely sure), but it might change in the future. So, just keep this in mind and test the solution extensively.
这篇关于Android上的Firebase - 我想在Android客户端上禁用Firebase通知的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!