I\'m trying to send some data to my users via the new Firebase push notifications service.
I\'m adding some \"key-value\" custom data items with \'Message text\' -
In Android , if you want to update someting in the app whether the app is in forground/background/terminated states, then the best way is to remove the notification payload and send only the data payload
{
"to" : "ee8....DYarin",
"data" : {
"key" : "value"
}
}
In this case onMessageReceived()
will get executed.
(In some android devices like xiomi you need to enable autostart for you application to process push in terminated states)
In this case, how will you show notification to user ? You can pass title and body as custom tags in the data payload and generate notification programically. So in Android everything goes well without notification payload.
And if you have notification payload in Android then the problems are:
Also to enable this click functionality on notification, the notification payload should contain key named click_action
:
"notification":{
"title":"Prime",
"body" : "test",
"click_action": "my_click_action_name"
}
And you need to register the action as intent_filter in you activity
When ever user clicks on notification the onNewIntent()
method of the curresponding activity is called and the data payload is available in the curresponding intent.getExtras()