I use firebase to send notifications to my application. I want to save notifications received on each device in a local database. The problem is that when the application is in the background and a notification is received, the onMessageReceived() method will not be called, but instead the notification will be added to the system tray according to the documentation. The documentation also mentions the following to be notified when the application is in the background:
In these cases, a notification is delivered to the device’s system tray, and a data payload is delivered in addition to assigning your launch activity.
So, when I try to access additional features in intent, notification keys were not found. My code in MainActivity.java :
if (getIntent().getExtras() != null) { for (String key : getIntent().getExtras().keySet()) { Object value = getIntent().getExtras().get(key); Toast.makeText(this, "Key: " + key + " Value: " + value, Toast.LENGTH_LONG).show(); } }
The notification we send from the server:
{ "to" : "bk3RNwTe3H0:CI2k_HHwgIpoDKCIZvvDMExUdFQ3P1...", "notification" : { "body" : "great match!", "title" : "Portugal vs. Denmark", "icon" : "myicon" } }
Does anyone have an idea on how I can get the values inside the notification?
source share