Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to handle notifications from the System Tray

I know that Handle messages in a backgrounded app

When your app is in the background, Android directs notification messages to the system tray. A user tap on the notification opens the app launcher by default.

This includes messages that contain both notification and data payload. In these cases, the notification is delivered to the device's system tray, and the data payload is delivered in the extras of the intent of your launcher Activity.

but my app should detect when notification arrive to do operation (get data from server) because when notification arrive must load data but , when app in background i cannot know notification arrive till user click notification will app open and i will load data , but in some case user not click notification so data not loaded

so my question any way to KNOW when app receive notification in case app in background ?

like image 532
user3623824 Avatar asked Oct 01 '16 20:10

user3623824


1 Answers

You will get the call on the callback method onMessageReceived in the FirebaseMessagingService in any case weather the app is in background or in foreground if and only if you are sending the data on "data" key. For example -

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

You can show custom notification by creating it on the callback method onMessageReceived

like image 137
Akash Bisariya Avatar answered Sep 22 '22 06:09

Akash Bisariya