3

I've implemented MyFirebaseMessagingService and I'm trying to get data passed in push notification.

In onMessageReceived I can see in the debugger that data is here:

enter image description here

The exact data I need is in "value[2]".

The entity called "value[2]" is pretty strange to me, what exactly is the key then? Is it 2?

remoteMessage.getData().get(2)

returns null...

Even

remoteMessage.getData()

returns an empty array:

System.out.println("DATA DUMP: " + remoteMessage.getData());

I/System.out: DATA DUMP: {}

Why is it empty when I can see it in debugger and how can I access this data?

Makalele
  • 7,431
  • 5
  • 54
  • 81
  • The data payload returned by `getData()` is a `Map`. Entries in the map are obtained using their String key, e.g. `getData().get("uid")`. Can you post the code that sets the data fields in the message when you send it? – Bob Snyder Oct 16 '17 at 21:40
  • I know it's a map, but no matter in which way I'm trying to print from it, it seems to be blank, but in debugger I can see data. I don't directly set data fields in the message. I'm using the following code: https://stackoverflow.com/questions/37435750/how-to-send-device-to-device-messages-using-firebase-cloud-messaging I've just added one more field in NotifyData class and this data is present in debugger in "value[2]". However getData() gives me nothing.. I'm stuck. – Makalele Oct 17 '17 at 17:37

1 Answers1

0

Figured it out.

It's all due to data being wrongly sent. It has to have a name "data" or it won't be returned in remoteMessage.getData(). getData() will only look for that, but debugger can see more. So if you'd sent data, but in other field name app will get it, but there's no way to access it as only method is getData and it requires field named "data".

Makalele
  • 7,431
  • 5
  • 54
  • 81