将Google Play服务更新为自己显示的8.4.0推送通知后 [英] After updating Google play services to 8.4.0 push notifications displayed by themselves

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

问题描述

对于推送通知,我们使用GCM(Google Cloud Messaging)。当我们使用play-services时它工作正常:8.3.0。我们用我们自己的接收器处理推送通知。升级到 com.google.android.gms:play-services:8.4.0
之后,不要进入我的myGcmListenerService,而是在通知栏中单独显示。此外,它在Log
GcmAnalytics:解析GCM事件中的时间戳时出现错误。



8.3.0我们收到了这样的推送:

Bundle [{gcm.notification.e = 1,google.cats = 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.cae = 1,collapse_key = com.domain.app.debug}]



.0推到这样:

Bundle [{通知=捆绑[{sound2 =默认,e = 1,身体=约翰M @绳索,导线和缆绳Rrr,数据= {name:new_chat_message,message_id:490641,channel_id:5366},badge = 1,sound = default}],collapse_key = com.domain.app.debug}]

解决方案

在您的服务器中,将 e 字段作为 zero 通知

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


然后在android中捆绑出来:

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

因此,如果您的应用程序在后台,它将不会自行显示通知,并会在您的 GcmListenerService



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


包含notif的混合信息应用程序和数据有效负载

接收包含通知和数据负载的消息时的应用程序行为取决于应用程序是在后台还是在前台,无论它是否在收到时处于活动状态。




  • 在后台中时,应用程序在通知托盘中接收通知有效内容,并且只在用户点击通知时处理数据有效内容。

  • 在前台中时,您的应用会收到一个包含两种有效负载的捆绑包。 $ b


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.

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}]

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}]

解决方案

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"
    }
}

And then in android the bundle will be:

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

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.

Hybrid messages with both notification and data payload

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.

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

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