Jatin Patel Jatin Patel - 3 months ago 112x
Android Question

Get value from RemoteMessage from FCM onMessageReceived method

I have migrate

gcm to fcm
for push notification message.
but how I Get bundle data from RemoteMessage received onMesssageReceived method.

Old GCM give bundle data onMessageReceiced method but in FCM there is RemoteMessage data.

So please tell me how I parse remotemessage for get all value of notification.


"message": "Message for new task",
"time": "6/27/2016 5:24:28 PM"
"notification": {
"sound": "simpleSound.wav",
"badge": "6",
"title": "Test app",
"icon": "myicon",
"body": "hello 6 app",
"notification_id" : "1140",
"notification_type" : 1,
"notification_message" : "TEST MESSAGE",
"notification_title" : "APP"
"registration_ids": ["cRz9SJ-gGuo:APA91bFJPX7_d07AR7zY6m9khQro81GmSX-7iXPUaHqqcOT0xNTVsOZ4M1aPtoVloLNq71-aWrMCpIDmX4NhMeDIc08txi6Vc1mht56MItuVDdA4VWrnN2iDwCE8k69-V8eUVeK5ISer"


In FCM you received RemoteMessage instead of Bundle.

Below is the way I used in my application where data is my RemoteMessage

int questionId = Integer.parseInt(data.get("questionId").toString());
String questionTitle = data.get("questionTitle").toString();
String userDisplayName = data.get("userDisplayName").toString();
String commentText = data.get("latestComment").toString();

Below is my notification data which I am sending it from server

  "registration_ids": "",
  "data": {
    "questionId": 1,
    "userDisplayName": "Test",
    "questionTitle": "Test",
    "latestComment": "Test"

So you have to parse each and every field as per your response. As I have debugged the code you will receive map in your RemoteMessage and cast those fields in appropriate data types as all those data comes as string.