Firebase 推送通知添加操作按钮

Firebase push notification adding action buttons

我正在服务器端发送推送通知,并且我正在使用此 http 协议(https://firebase.google.com/docs/cloud-messaging/http-server-ref) and I want to add action buttons like this in issue https://github.com/FirebaseExtended/flutterfire/issues/1484。 这是我的请求正文

{
  "registration_ids": [
    "secret"
  ],
  "notification": {
    "title": "New Article",
    "body": "Article content",
    "sound": "default",
    "actions": [
      {
        "action": "like-button",
        "title": "Like",
        "url": "https://example.com"
      },
      {
        "action": "read-more-button",
        "title": "Read more",
        "url": "https://example.com"
      }
    ],
    "click_action": "read-more-button"
  },
  "data": {
    "id": "some uuid",
  }
}

我试过了,但没有任何结果。我该如何解决这个问题?提前谢谢你。

FCM 目前不支持此功能。解决方案是通过 FCM 发送数据消息并创建您自己的通知。

  1. 使用您自己的 key-value 对发送数据消息:
  "data": {
    "key": "value",
    "key2": "value2"
  }
  1. 接收消息,使用扩展 FirebaseMessagingService.
  2. 的服务
  3. 覆盖 onMessageReceived 回调以根据您的数据消息创建通知。

https://firebase.google.com/docs/cloud-messaging/android/receive