- Send a regular notification (has "notification" in JSON body, not a custom data notification)
- Have app in background so onMessageReceived() implementation in app is not triggered and system takes care of displaying the notification.
- When notification is clicked, MainActivity is triggered. There appears to be no way to retrieve notification title and body (the
notification
JSON part) in Acivity, only thedata
part can be retrieved from Bundle in extras.
My MainActivity:
Intent intent = getIntent();
if (intent.getExtras() != null) {
debug("Intent with extras");
Bundle b = getIntent().getExtras();
for (String key : b.keySet()) {
Object value = b.get(key);
Log.d(TAG, String.format("%s %s (%s)", key,
value.toString(), value.getClass().getName()));
}
}
Log output:
Intent with extras google.sent_time 1487153876625 (java.lang.Long) openUrl http://192.168.29.121:8083/v1/messages/87046D17-6470-427C-A046-2E1C92E21D23/open (java.lang.String) customProperties {"big_icon_urll":"link"} (java.lang.String) from 814199820217 (java.lang.String) google.message_id 0:1487153876640504%a38586a6a38586a6 (java.lang.String) collapse_key com.kumuluz.ccm.android.sample (java.lang.String)
As you can see, only the data part is given (openUrl, customProperties...).
If I handle a custom notification manually this is not a problem because I can push title and body to extras and they are then present in the Bundle. But how can you get title and body from a notification that is handled by system when app is in background?
I don't see any suitable methods on Intent
to retrieve this.