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.