【问题标题】:How can I disable firebase notification on android client app如何在 android 客户端应用程序上禁用 firebase 通知
【发布时间】:2017-01-27 11:11:54
【问题描述】:

当用户通过设置关闭通知时,我想禁用 Firebase 通知服务。

我发现了关于这个主题的问题:

Firebase on Android - I want to disable firebase notifications on Android client

android FCM enable/disable from application settings

但答案是忽略通知的另一种方式。

还有其他方法可以取消注册 Firebase 通知吗?

谢谢

【问题讨论】:

    标签: android firebase notifications firebase-cloud-messaging


    【解决方案1】:

    使用这个。

    FirebaseMessaging.getInstance().unsubscribeFromTopic("X");
    

    【讨论】:

    • 感谢您的回复,但我没有使用任何主题来通知退订。我想取消订阅特定用户。
    • 来自应用程序的一些功能?
    • @josedlujan 你搞定了吗?我也遇到了同样的问题。你能帮帮我吗?
    • 也许我误解了 FCM 的用例,但如果你没有启用主题消息传递,没有更直接的方法可以做到这一点,这真的很愚蠢
    【解决方案2】:

    我花了很多时间来了解如何在应用程序处于后台时禁用显示推送通知。当应用程序在前台时一切都很清楚,您可以处理应用程序中的所有内容 - 当用户在应用程序设置中关闭通知时,您只是不显示通知。但是当应用程序在后台运行时,Firebase 会在后台处理所有事情,您不能覆盖 FirebaseMessagingService 的方法,因为它们是最终的。 我找到了一些非常肮脏的解决方案,可能有人说这很愚蠢,但我所做的是覆盖了FirebaseMessagingService 的 onCreate 并做了下一步:

        private void removePush(){
            new Handler().postDelayed(() -> {
                NotificationManager manager = (NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE);
                if (Build.VERSION.SDK_INT >= 23) {
                    StatusBarNotification[] notifications = manager.getActiveNotifications();
                    for (StatusBarNotification n : notifications) {
                        if (n.getTag().contains("campaign_collapse_key_")) {
                            Logger.logD(TAG + ": Found firebase push. remove it.");
                            manager.cancel(n.getTag(), n.getId());
                        }
                    }
                }
                else{
                    manager.cancelAll();
                }
            }, 500);
        }
    

    如果此解决方案对某人有帮助 - 很好。如果您找到了更好的解决方案,请告诉大家;)

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2019-10-04
      • 2022-01-01
      • 1970-01-01
      • 2017-04-04
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多