Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

FCM Notification in System Tray when App is in Foreground

I'm able to see the notification in system tray when the app is in Background.

But, I would like the notification to be visible in system tray even if the app is in Foreground.

I tried the following on Android:

  • Sending notification from Firebase console: I can see the notification in system tray only when the app is in background.
  • Sending a post request to https://fcm.googleapis.com/fcm/send as described here with both data and notification paylods: Again, I can only see the notification in system tray when the app is in background.

This document mentions:

Messages with both notification and data payload, both background and foreground. In this case, 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.

What am I missing?

I'm using Android and Cordova/Ionic.

like image 568
Ari Avatar asked Dec 17 '17 19:12

Ari


1 Answers

If you want a notification to appear when the app is in the foreground, you will have to send a message with a data payload, then write code to handle that in your app, as described by the documentation you referenced.

When you send a message with a notification payload, FCM works exactly as you described. When then app is in the background, it will display a notification for you. When in the foreground, it will not.

Please note that data and notification payloads behave differently, as described in the documentation.

like image 167
Doug Stevenson Avatar answered Oct 17 '22 02:10

Doug Stevenson