【问题标题】:Android app cannot handle Firebase push notifications when in backgroundAndroid 应用在后台时无法处理 Firebase 推送通知
【发布时间】:2016-08-29 16:35:48
【问题描述】:

我和我的团队正在使用 Firebase 云消息向我们的 iOS 和 Android 应用发送推送通知。我们 POSThttps://fcm.googleapis.com/fcm/send 端点的 JSON 有效负载包含以下字段:

{
    registration_ids: FCMTokenArray,
    data: ourCustomData,
    notification: {
        title:  '',
        body:   aString,
        sound : 'default'
    }
}

当我们的 Android 应用在后台(或关闭)时,虽然手机收到推送通知,但应用看不到它,因此无法处理。如果我们删除 notification 键,一切正常,但 iOS 抱怨它需要它(基本上由 Firebase 翻译为 aps)...

我不认为 Android 在后台不将推送通知转发给我的应用程序的处理程序是预期的行为。有人知道我们缺少什么吗?

【问题讨论】:

  • 如果您的应用不在前台并且收到您的应用的通知消息,系统会自动在系统托盘中显示通知。在这种情况下,您的应用程序的 onMessageReceived() 将不会被调用。见this section in the docsthis question

标签: android firebase push-notification firebase-cloud-messaging firebase-notifications


【解决方案1】:

也许您缺少 android 的键“click_action”。 试试这个:

"notification":{
    "title":"Notification title",  //Any value
    "body":"Notification body",  //Any value
    "sound":"default", //If you want notification sound
    "click_action":"FCM_PLUGIN_ACTIVITY",  //Must be present for Android
    "icon":"fcm_push_icon"  //White icon Android resource
},

来源: https://github.com/fechanique/cordova-plugin-fcm

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2019-11-10
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多