如何检查用户是否在 FCM 中禁用了通知?

How to check if user disabled notifications in FCM?

我在 Dart/Flutter 应用中使用 Firebase 云消息传递。下面的代码使用检索到的 android 通知令牌更新用户文档。

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

然后我阅读了我的云函数中的 notificationAndroidToken。效果很好,除非我错误地认为如果用户关闭了他们的通知(例如,空或空),令牌将无效。确定是否在云功能中为我的应用程序启用了通知的最佳方法是什么?我在搜索中找到了一些匹配项,但很多已过时或针对不同的开发环境。

firebase_messaging 包不提供任何方法来检查是否通过调用 NotificationManagerCompat.areNotificationsEnabled on the platform. The awesome_notifications package provides such a isNotificationAllowed 方法启用了通知。