Raf*_*ael 8 android push-notification google-cloud-messaging google-play-services
对于推送通知,我们使用GCM(Google云消息传递).当我们使用播放服务时它工作正常:8.3.0.我们使用自己的接收器处理推送通知.升级到com.google.android.gms:play-services:8.4.0
Push后不到我的myGcmListenerService,而是在通知栏中单独显示.它还在Log中显示此错误
GcmAnalytics: Error while parsing timestamp in GCM event.
在8.3.0中,我们收到了这样的推送:
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}, badge=1, sound=default}], collapse_key=com.domain.app.debug}]
在您的服务器中,只需将e字段发送到字段zero内即可notification。
{\n "to": "APA91bHun4MxP5egoKMwt2KZFBaFUH-1RYqx...",\n "content_available": true,\n "notification": {\n "e": 0\n },\n "data": {\n "key": "value"\n }\n}\nRun Code Online (Sandbox Code Playgroud)\n\n然后在 android 中,捆绑包将是:
\n\nBundle[{gcm.notification.e=0, key=value, ...}]\nRun Code Online (Sandbox Code Playgroud)\n\n因此,现在如果您的应用程序处于后台,它本身不会显示通知,并将在您的GcmListenerService.
但是,如果您同时具有通知和数据负载,并且您的应用程序位于后台,则它将自行显示通知,如此处所述。
\n\n\n\n具有通知和数据负载的混合消息
\n\n接收包含通知和数据有效负载的消息时的应用程序行为取决于应用程序是在后台还是前台 \xe2\x80\x94 本质上取决于应用程序在接收时是否处于活动状态。
\n\n\n
\n- \n
在后台时,应用程序会在通知托盘中接收通知负载,并且仅在用户点击通知时处理数据负载。
- \n
当在前台时,您的应用程序会收到一个包含两个可用负载的包。