1

My app is running I just screen off the device and no notification event is coming inside FirebaseMessagingService.

The notification is also not showing in the notification tray. Is that some bug with FCM or I am doing something wrong.

Please find attached code for FCMService.

public class FCMService extends FirebaseMessagingService {
    private static final Logger LOGGER = LoggerFactory.createLogger(FCMService.class);

    @Override
    public void onMessageReceived(RemoteMessage message) {
        if (null != message) {
            onNotificationReceived(message.getNotification(), message.getData());
        }
    }

    /**
     * Create and show a simple notification containing the received FCM message.
     * @param messageBody FCM message body received.
     * @param data Notification Data
     */
    private void onNotificationReceived(RemoteMessage.Notification messageBody, final Map<String, String> data) {
        LOGGER.info("Notification received... for data %s", data);
        if (AppPreferences.getInstance().isUserLogin()) {
            if (null != messageBody) {
               LOGGER.info("Notification received... Foreground Notification...%");
            } else {
               LOGGER.info("Notification received... Silent Notification...%");    
            }
        }
    }
}
Frank van Puffelen
  • 565,676
  • 79
  • 828
  • 807
VikasGoyal
  • 3,308
  • 1
  • 22
  • 42
  • If you are receiving the notification when your app is in the foreground then you should receive it when it is in the background. What device are you using? – Arthur Thompson Jan 10 '17 at 22:10

2 Answers2

0

Your code is correct. You just have to set the priority to your message sent from you server and set it to high. In you server end add following key to the message:

"priority" : "high",

And notification start working at android end.

Marcin Orlowski
  • 72,056
  • 11
  • 123
  • 141
Anjali
  • 1
  • 1
  • 13
  • 20
0

Did you fire notification in app after getting message from firebase like

public void showNotification(String msg)
{
  Intent intent = new Intent(this, Home.class);
    PendingIntent pIntent = PendingIntent.getActivity(this, (int) System.currentTimeMillis(), intent, 0);

    // Build notification
    // Actions are just fake
    Notification noti = new Notification.Builder(this)
            .setContentTitle("title")
            .setContentText(msg).setSmallIcon(R.drawable.original_logo)
            .setContentIntent(pIntent)
            .addAction(R.drawable.original_logo, "Call", pIntent)
            .addAction(R.drawable.original_logo, "More", pIntent)
            .addAction(R.drawable.original_logo, "And more", pIntent).build();
    NotificationManager notificationManager = (NotificationManager) getSystemService(NOTIFICATION_SERVICE);
    // hide the notification after its selected
    noti.flags |= Notification.FLAG_AUTO_CANCEL;

    notificationManager.notify(0, noti);

}
Sushant Gosavi
  • 3,647
  • 3
  • 35
  • 55