In the Android application, I have a service that listens to alerts.
@Override public void onMessageReceived(String from, Bundle data) { Log.e(TAG, "New message: " + data); String message = data.getString("message"); Log.d(TAG, "From: " + from); Log.d(TAG, "Message: " + message); sendNotification(message); } the problem is that this method can only listen to messages of this type.
var message = new gcm.Message({ collapseKey: 'data', priority: 'high', contentAvailable: true, delayWhileIdle: false, timeToLive: 10000, data: { message: 'Message from gcm server', } }); Those. I can catch this message in the application and issue the necessary notification myself.
But if I send a message in this format
var message = new gcm.Message({ collapseKey: 'data', priority: 'high', contentAvailable: true, delayWhileIdle: false, timeToLive: 10000, notification: { title: "Hello, World", icon: "ic_launcher", body: "This is a notification that will be displayed ASAP." } }); In the application, the onMessageReceived() method generally turns out that it does not work.
The documentation says that I can send hybrid messages that I understand should be processed by the onMessageReceived() method
Hybrid messages with both notification and data payload
This is the case when it comes to the background, or the foreground — whether it is active or not, it is active at the time of receipt.
If you’re in the background, you’ll receive your data payload. When in the foreground, your payloads are available. Here is a JSON-formatted message that can contain both notification and data:
{"to": "APA91bHun4MxP5egoKMwt2KZFBaFUH-1RYqx ...", "notification": {"body": "great match!", "title": "Portugal vs. Denmark", "icon": "myicon"}, " data ": {" Nick ":" Mario "," Room ":" PortugalVSDenmark "}}
The question is how can this be, and how can I catch messages of the latter type?
click_action(see the docks for details) and that's it. Send the rest and process via data ... - Yura Ivanov