更新谷歌播放服务到8.4.0后自己显示的推送通知 [英] After updating Google play services to 8.4.0 push notifications displayed by themselves

查看:32
本文介绍了更新谷歌播放服务到8.4.0后自己显示的推送通知的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

对于推送通知,我们使用 GCM(Google Cloud Messaging).当我们使用 play-services:8.3.0 时它运行良好.我们使用自己的接收器处理推送通知.升级到 com.google.android.gms:play-services:8.4.0 后推送不会进入我的 myGcmListenerService,而是在通知栏中自行显示.它还在日志中显示此错误GcmAnalytics:解析 GCM 事件中的时间戳时出错.

For Push notifications we are using GCM(Google Cloud Messaging). It was working fine when we used play-services:8.3.0 . We process push notifications with our own receiver. After upgrading to com.google.android.gms:play-services:8.4.0 Push not coming to my myGcmListenerService, instead its shown by itself in notification bar. Also it shows this error in Log GcmAnalytics: Error while parsing timestamp in GCM event.

在 8.3.0 中,我们收到了这样的推送:<代码>捆绑[{gcm.notification.e=1, google.cats=234343426, gcm.notification.badge=1, gcm.notification.sound=default, gcm.notification.sound2=default, gcm.notification.body=John M@ 电线、电线和电缆 Ftu,gcm.notification.data={"name":"new_chat_message","message_id":490666,"channel_id":5366},google.cae=1,collapse_key=com.domain.app.调试}]

With 8.3.0 we received push like this: Bundle[{gcm.notification.e=1, google.c.a.ts=234343426, gcm.notification.badge=1, gcm.notification.sound=default, gcm.notification.sound2=default, gcm.notification.body=John M @ Cords, Wires And Cable Ftu, gcm.notification.data={"name":"new_chat_message","message_id":490666,"channel_id":5366}, google.c.a.e=1, collapse_key=com.domain.app.debug}]

8.4.0 的推送是这样的:<代码>Bundle[{notification=Bundle[{sound2=default, e=1, body=John M @ Cords, Wires And Cable Rrr, data={"name":"new_chat_message","message_id":490641,"channel_id":5366},徽章=1,声音=默认}],collapse_key=com.domain.app.debug}]

With 8.4.0 pushes coming like this: Bundle[{notification=Bundle[{sound2=default, e=1, body=John M @ Cords, Wires And Cable Rrr, data={"name":"new_chat_message","message_id":490641,"channel_id":5366}, badge=1, sound=default}], collapse_key=com.domain.app.debug}]

推荐答案

在您的服务器中,只需将 e 字段作为 notification 内的 zero 发送> 字段.

In your server just send the e field as zero inside the notification field.

{
    "to": "APA91bHun4MxP5egoKMwt2KZFBaFUH-1RYqx...",
    "content_available": true,
    "notification": {
        "e": 0
    },
    "data": {
        "key": "value"
    }
}

然后在 android 中,bundle 将是:

And then in android the bundle will be:

Bundle[{gcm.notification.e=0, key=value, ...}]

所以现在如果您的应用程序在后台,它不会自行显示通知,而是会在您的 GcmListenerService 中接收包.

So now if your app is in background it will not show the notification by itself and will receive the bundle in your GcmListenerService.

但是,如果您同时拥有通知和数据负载,并且您的应用程序在后台运行,它将自行显示通知,如此处.

But if you have both notification and data payloads and your app is in background, it will show the notification by itself, as described here.

具有通知和数据负载的混合消息

应用在接收同时包含通知和数据有效载荷的消息时的行为取决于应用是在后台还是前台——本质上,它在接收时是否处于活动状态.

App behavior when receiving messages that include both notification and data payloads depends on whether the app is in the background, or the foreground —essentially, whether or not it is active at the time of receipt.

  • 在后台时,应用会在通知托盘中接收通知负载,并且仅在用户点击通知时处理数据负载.

  • When in the background, apps receive the notification payload in the notification tray, and only handle the data payload when the user taps on the notification.

在前台时,您的应用会收到一个包含两种有效负载的包.

When in the foreground, your app receives a bundle with both payloads available.

这篇关于更新谷歌播放服务到8.4.0后自己显示的推送通知的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆