How to handle notifications from the system tray

I know that process messages in the background application

When your application is in the background, Android sends notifications to the system tray. The user, by clicking on the notification, opens the default application launcher.

This includes messages that contain both the notification payload and data. In these cases, a notification is delivered to the device’s system tray, and a data payload is delivered in addition to the purpose of your launch activity.

but my application must detect when a notification arrives in order to perform the operation (to receive data from the server), because when the notification arrives, it is necessary to download the data, but when the application is in the background I cannot know that the notification arrives until the user notification notification will be open, and I will upload the data, but in some cases the user does not click on the notification, so the data does not load

so my question is KNOW in any way when the application receives a notification in case the application is in the background?

+5
source share
1 answer

You will receive a call to the onMessageReceived callback method in the FirebaseMessagingService in any case, when the application is in the background or in the foreground, if and only if you send data to "data". For instance -

 { "message":{ "token":"bk3RNwTe3H0:CI2k_HHwgIpoDKCIZvvDMExUdFQ3P1...", "data":{ "Nick" : "Mario", "body" : "great match!", "Room" : "PortugalVSDenmark" } } } 

You can show your own notification by creating it using the onMessageReceived callback method

0
source

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


All Articles