How to handle notification of appearance on Android if it is displayed automatically by GCM

I ran into two problems in Android with the latest GCM update. According to GCM, it automatically displays a notification in the tray if the payload contains the notification attribute. But they did not mention how to handle the tap event for this notice. If the payload contains only the data attribute, "onMessageReceived" is called from the GCMListenerService. But if the payload contains notification and data attributes, the method is not called. Any idea how to solve? I have to check iOS, and also see how it behaves there.

+6
source share
2 answers

You need to set click_action in the notification payload. Then, when the user opens / clicks on the notification, an Activity will be launched in your ad with this action.

for example, set click_action: OPEN_ACTIVITY_1 and add the following intent filter to the desired operation:

<intent-filter> <action android:name="OPEN_ACTIVITY_1" /> <category android:name="android.intent.category.DEFAULT" /> </intent-filter> 

You can then retrieve the data from the message in the Activity using getIntent () and then looking at additional intentions.

See here: https://developers.google.com/cloud-messaging/server-ref#notification-payload-support

+11
source

If you send push with the notification parameter, then you cannot process using onMessageReceived

If you want to process the notification, send push with the data option, now you can process GCM and onMessageReceived .

Please note: ios processes notifications using the notifications key.

Send push for ios with the notification key, for the android data button.

For android;

{"data":{"message":"hey"}},registration_ids":["device token"]

For ios:

{"notification":{"title":"Hey title", "body":" Hey body"},"to":"device token"}

0
source

Source: https://habr.com/ru/post/988936/


All Articles