通知参数仅在应用程序处于前景状态时显示

时间:2019-08-12 15:07:34

标签: android kotlin firebase-cloud-messaging

我正在尝试在onCreate中获取通知参数,但我仅获取google。*字段。

我的FCM服务:

 override fun onMessageReceived(message: RemoteMessage?) {
    Log.e("Push", Gson().toJson(message))
}

这会在应用程序处于前台时向我显示:

{
  "zza": {
    "mMap": {
      "google.delivered_priority": "high",
      "google.sent_time": 1565619574704,
      "google.ttl": 2419200,
      "google.original_priority": "high",
      "gcm.notification.e": "1",
      "gcm.notification.title": "New meeting",
      "from": "308737816494",
      "gcm.notification.booking_id": "339",
      "google.message_id": "0:1565619574708538%545adad5545adad5",
      "gcm.notification.body": ".....",
      "google.c.a.e": "1"
    }
  }
}

注意“ gcm.notification.booking_id”:“ 339”,这是我需要的字段。

当应用程序在后台运行或被杀死时,单击通知,启动器活动中将显示下一个代码:

 private fun checkNotifications(intent: Intent?) {
        val bookingId = intent?.getStringExtra("gcm.notification.booking_id")
        Log.e("Push", "bookind id $bookingId)")
        Log.e("PUSH", Gson().toJson(intent?.extras))

问题出在这里,我没有任何gcm。*过滤器,只有google。*。当然,bookindId为null。

{
  "mMap": {
    "google.delivered_priority": "high",
    "google.sent_time": 1565622016732,
    "google.ttl": 2419200,
    "google.original_priority": "high",
    "from": "308737816494",
    "google.message_id": "0:1565622016737416%545adad5545adad5",
    "collapse_key": "com.wolfpack.planetoffinance"
  }
}

服务器端代码;

 def options
  {
    notification: {
      title: titles[notification.notification_type.to_sym],
      body: bodies[notification.notification_type.to_sym],
      booking_id: notification.booking_id
    }
  }
end


```def call
    @other_user = other_user

    response = FCM_CLIENT.send(registration_ids, options)
    notification.user.devices.where(uuid: response[:not_registered_ids]).destroy_all
  end
def call
@other_user = other_user

response = FCM_CLIENT.send(registration_ids, options)
notification.user.devices.where(uuid: response[:not_registered_ids]).destroy_all

结束

0 个答案:

没有答案