Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

After updating Google play services to 8.4.0 push notifications displayed by themselves [duplicate]

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

like image 371
Rafael Avatar asked Dec 28 '15 09:12

Rafael


People also ask

What is Inapp notification?

In-app notifications are messages that app creators can send to users within their app. They're commonly used to direct users toward points of interest to boost usage, retention, and lifetime value (LTV). Used properly, in-app notifications help users find what they're looking for and increase their satisfaction.

Is Google push notification delivery guaranteed?

Push notifications may not be totally reliable due to possible gateways issues and device OS features such as power saver mode which can also hinder timely delivery. Loss of internet connectivity or users disabling notifications can also prevent push notifications delivery.


1 Answers

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.

like image 106
dblank Avatar answered Oct 09 '22 18:10

dblank