【问题标题】:Android push does not trigger when app in background after notification clicked单击通知后,应用程序在后台时不会触发 Android 推送
【发布时间】:2017-03-04 11:48:14
【问题描述】:

我有一个 Cordova 应用程序,使用 push plugin
在服务器上,我使用node-gcm 发送 GCM 消息。
对于 iOS 和 Android,我可以正常收到通知,点击后它们会打开应用程序,但在 Android 上不会触发“通知”事件。

push.on('notification', function(data) {
    console.log(data);
    alert('got PUSH!');
});

如果应用程序在前台运行,那么我会收到“得到 PUSH!”警报,但是当应用程序在后台并且当它到达时我单击推送通知时,它会打开应用程序但不会警告“得到了推送!”。

如何在应用打开后触发“通知”事件?


这是我发送到设备的 gcm 消息:

{
  "params": {
    "notification": {
      "title": "SO post demo",
      "body": "THIS IS A TEST!",
      "icon": "ic_launcher",
      "sound": true
    }
  }
}

我相信我需要在通知负载中添加一些东西来解决这个问题,但我没有尝试过在应用从后台打开时触发该事件。


以下是我尝试过的几件事:

使用“内容可用”(建议here),使用message.addData

{
  "params": {
    "notification": {
      "title": "SO post demo",
      "body": "THIS IS A TEST!",
      "icon": "ic_launcher",
      "sound": true
    },
    "data": {
      "info": "super secret info",
      "content-available": "1"
    }
  }
}

再次相同,但将我的参数放在我用来制作消息的 json 中:

{
  "params": {
    "notification": {
      "title": "SO post demo",
      "body": "THIS IS A TEST!",
      "icon": "ic_launcher",
      "sound": true,
      "info": "super secret info",
      "content-available": "1"
    }
  }
}

【问题讨论】:

    标签: android cordova push-notification push node-gcm


    【解决方案1】:

    在有条不紊地提出这个问题时,我找到了答案。
    我需要我的有效载荷看起来像这样:

    {
      "params": {
        "data": {
          "title": "SO post demo",
          "body": "THIS IS A TEST!",
          "icon": "ic_launcher",
          "sound": true
        }
      }
    }
    

    这会弄乱显示的通知图标(它是放大版),但在这个阶段,我可以忍受。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2018-08-04
      • 1970-01-01
      • 1970-01-01
      • 2016-12-07
      相关资源
      最近更新 更多