0

I'm working with Firebase Cloud Messaging. I have a couple of question I was not able to understand from the documentation:

  1. Android: Lets suppose the app is closed (not backgrounded: closed). If I send a notification with also the data payload, this data payload is passed to the activity through the Intent Extra

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 if the user does not tap on the notification? Is the data payload lost? Is there a way to retrieve it?

  1. iOS/Android. Lets suppose the user disabled the notification and I sent a notification to the client: is there a way to retrieve (pull) the notification at the application start?

Thanks very much

Stefano Giacone
  • 1,824
  • 2
  • 23
  • 46

2 Answers2

1

If the app is closed (not in background) the onMessageReceived method is called when the notification is received and there you can retrieve the data payload with remoteMessage.getData().get("key_for_parameter"); where key_for_parameter is the name of the parameter that you send in the notification. This method is called even if the application is closed. However, take into account that the "onMessageReceived" is called only if you omit the "notification" param in the notification (look this post)

So once you have the params in the onMessageReceived you can look for an strategy to use them in your application like storing in the DB and you are not going to lose the data if the user does not click on the notification.

Community
  • 1
  • 1
GeorgeLBA
  • 324
  • 1
  • 3
  • That's great! I missed the fact that "onMessageReceived" is called only if "notification" is omitted. Isn't it weird? I didn't find this in the documentation. – Stefano Giacone Aug 17 '16 at 14:13
0

if your app in background, Firebase will not trigger onMessageReceived(). Why.....? I have no idea. In this situation, I do not see any point in implementing FirebaseMessagingService.

According to docs, if you want to process background message arrival, you have to send 'click_action' with your message. But it is not possible if you send message from Firebase console, only via Firebase API. It means you will have to build your own "console" in order to enable marketing people to use it. So, this makes Firebase console also quite useless!

There is really good, promising, idea behind this new tool, but executed badly.

I suppose we will have to wait for new versions and improvements/fixes

Damini Mehra
  • 3,094
  • 3
  • 11
  • 24