1

I'm using Firebase Cloud Messaging in my Dart/Flutter app. The code below updates a user doc with a retrieved android notification token.

FirebaseMessaging().getToken().then((token) {
  _usersRef.doc(user.id).update({
    "notificationAndroidToken": token,
  });
});

I then read the notificationAndroidToken in my cloud functions. Works great except I had wrongly assumed the token would be invalid if the user had shut off their notifications (e.g., empty or null). What's the best way for determining if notifications are enabled for my app in cloud functions? I'm finding some hits in my searches but many are outdate or for a different dev environment.

buttonsrtoys
  • 2,359
  • 3
  • 32
  • 52
  • 1
    Does this answer your question? [Firebase Cloud Messaging - How to validate Tokens?](https://stackoverflow.com/questions/38442434/firebase-cloud-messaging-how-to-validate-tokens) – Rafal Dec 28 '20 at 18:22

1 Answers1

1

The firebase_messaging package does not provide any method for checking if notifications are enabled by calling NotificationManagerCompat.areNotificationsEnabled on the platform. The awesome_notifications package provides such a isNotificationAllowed method.

lukasl
  • 436
  • 2
  • 6