Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Firebase RemoteMessage has filled Bundle but getData() is empty

My firbase RemoteMessage has a mBundle with 12 key value pairs, according to debugger, those field were filled enter image description here.

But when I say: remoteMessage.getData(); the resulting ArrayMap Map<String, String> has size 0 and thus no elements.

How can I access the Map of remoteMessage?

like image 279
Ralf Wickum Avatar asked Aug 28 '17 10:08

Ralf Wickum


People also ask

What is onMessageReceived?

onMessageReceived is provided for most message types, with the following exceptions: Notification messages delivered when your app is in the background. In this case, the notification is delivered to the device's system tray. A user tap on a notification opens the app launcher by default.

What is Firebasemessagingservice?

Firebase Cloud Messaging Platform (formerly named as GCM) is a free mobile notification service by Google that enables (third-party) app developers to send notifications from GCM (Google Cloud Messaging) servers to their users.

How do I handle background notifications on Android?

To get notification data when your app in the background, you should add click_action inside notification payload. "Put that intent-filter on your manifest, inside application tag." you can't put intent-filter inside application tag. your JSON dows not show where the click_action key goes.

What is remote message?

interface. The RemoteMessage interface describes an outgoing & incoming message from the remote FCM server.


2 Answers

I know this might be late but You can get the data from Notification Object in RemoteMessage

String title = remoteMessage.getNotification().getTitle();
String body = remoteMessage.getNotification().getBody();

hope this helps

like image 106
Richard K Maleho Avatar answered Oct 14 '22 14:10

Richard K Maleho


I also encountered same problem.
And finally fixed this problem.
In my case, server side's sending FCM payload problem.
like this.

options = {
  priority: 'high',
  notification: {
    title: "title",
    body: "message",
    url: "some_url",
    image_url: "some_image_url"
  }

And I updated like following,

options = {
  priority: 'high',
  notification: {
    title: "title",
    body: "message",
  },
  data: {
    url: "some_url",
    image_url: "some_image_url"
  }

After that, I could get payload values by remoteMessage.getData().

like image 38
sampo02 Avatar answered Oct 14 '22 14:10

sampo02