3

I'm trying to do some customization regarding the FCM of firebase Notification. Is it possible to do it?

DreamBigAlvin
  • 864
  • 3
  • 12
  • 34

2 Answers2

11

Please, make a difference between Firebase Notifications and Firebase Cloud Messaging. https://firebase.google.com/support/faq/#notifications-difference

With notifications, you have small manoeuvre space. Key points are:

  1. If your app is in foreground, message will not be delivered to notification tray but in your service FireBaseMessagingService so you can do what ever you want with payload/notification.
  2. If your app is in background, your notification will be delivered to notification tray (with default look & feel) and FireBaseMessagingService will NOT be called. All payload you send via that push message will be delivered to intent user open via clicking on notification.
  3. So, in case of point 2, you can NOT customise notification according your needs.
Bozic Nebojsa
  • 3,185
  • 1
  • 15
  • 16
1

Yes it is possible Just override onMessageReceived in your service extending FireBaseMessagingService You get the data here in this function Then customize your notification using this data

Yash Jain
  • 376
  • 1
  • 3
  • 12
  • 2
    If your app is in background, FireBaseMessagingService will not be triggered. – Bozic Nebojsa Jun 14 '16 at 09:09
  • 1
    No it will be Thats why the service is for. For Background data – Yash Jain Jun 14 '16 at 09:17
  • 3
    From doc: If you want to receive notifications when your app is in the foreground, you need to add some message handling logic. To receive messages, use a service that extends FirebaseMessagingService. When your app is in the background, Android directs notification messages to the system tray. 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. – Bozic Nebojsa Jun 14 '16 at 09:28
  • When in Background the app receives the notification payload but not the data payload. – Yash Jain Jun 14 '16 at 09:32
  • is it possible to make the service alive either foreground or background. it's like something i'll try to add some wrap withing the service of the firebase..? – DreamBigAlvin Jun 14 '16 at 09:33
  • Ya you can surely do that. – Yash Jain Jun 14 '16 at 09:35
  • 3
    And again from docs: App behavior when receiving messages that include both notification and data payloads depends on whether the app is in the background or the foreground—essentially, whether or not it is active at the time of receipt. When in the background, apps receive the notification payload in the notification tray, and only handle the data payload when the user taps on the notification. When in the foreground, your app receives a message object with both payloads available. So, FireBaseMessagingService will be useful only when the app is in foreground. – Bozic Nebojsa Jun 14 '16 at 09:45
  • 1
    @Yash Jain I think problem here is that you are addressing Firebase Cloud Messaging, and I am talking about Firebase Notifications. – Bozic Nebojsa Jun 14 '16 at 09:55