I faced 2 issues in Android with the latest update to GCM. As per GCM, it will automatically display notification in the tray if the payload contains 'notification' attribute. But they have not mentioned how to handle on tap event for that notification. If the payload contains only data attribute, 'onMessageReceived' of GCMListenerService is invoked. But if the payload contains both notification and data attributes, the method is not invoked. Any idea how to resolve? I have to check iOS as well to see how it behaves there.
Handle notification messages in a backgrounded appA user tap on the notification opens the app launcher by default. This includes messages that contain both notification and data payload (and all messages sent from the Notifications console).
Status bar and notification drawer When you issue a notification, it first appears as an icon in the status bar. Users can swipe down on the status bar to open the notification drawer, where they can view more details and take actions with the notification.
Notification messages When your app is in the foreground, the FCM notification message is delivered to the onMessageReceived() handler and you can handle it by posting a notification if needed or update the app content with the FCM payload data (Max 4KB) or fetch content from app server.
You need to set a click_action in the notification payload. Then when the user opens/clicks on the notification, an Activity in your app declared with that action will be launched.
e.g set click_action: OPEN_ACTIVITY_1, and add the following intent filter to the desired Activity:
<intent-filter>
<action android:name="OPEN_ACTIVITY_1" />
<category android:name="android.intent.category.DEFAULT" />
</intent-filter>
Then you can extract the data from the message in the Activity, by using getIntent() and then looking at the intent extras.
See the entry here: https://developers.google.com/cloud-messaging/server-ref#notification-payload-support
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With