如何禁用来自 FCM 的提醒通知并仅使用 onMessage 和 onBackgroundMessageHanlder

How can I disable headsup notification from FCM and only work with onMessage and onBackgroundMessageHanlder

如何禁用来自 FCM 的提示通知并仅使用

  onMessage()

  onBackgroundMessageHanlder()

显示自动通知是因为您正在发送通知消息。对于通知消息,FCM 会代表客户端应用自动向最终用户设备显示消息。

解法:

您可以发送不显示自动通知且需要客户端应用程序处理数据的数据消息。

这是一个示例通知消息:

{
  "message":{
    "token":"bk3RNwTe3H0:CI2k_HHwgIpoDKCIZvvDMExUdFQ3P1...",
    "notification":{
      "title":"Portugal vs. Denmark",
      "body":"great match!"
    }
  }
}

这是一个示例数据消息:

{
  "message":{
    "token":"bk3RNwTe3H0:CI2k_HHwgIpoDKCIZvvDMExUdFQ3P1...",
    "data":{
      "Nick" : "Mario",
      "body" : "great match!",
      "Room" : "PortugalVSDenmark"
    }
  }
}

更多阅读:https://firebase.flutter.dev/docs/messaging/usage and https://firebase.google.com/docs/cloud-messaging/concept-options