Ad

How To Get Subtitle From Firebase Push Notification

I am getting push notification in this format from server.

{
                title: messageTitle,
                body: messageBody,
               subtitle: messageSubtitle
}

In my android project i read notification by using following code.

remoteMessage.getNotification().getTitle();
remoteMessage.getNotification().getBody(); 

The above 2 lines gives me Title and Body, but i am unable to understand how to read subtitle property.

Ad

Answer

Standard notification format does not include subtitle hence there is no method to fetch it, to get a subtitle message please use data key.

Standard Notification format

{
  "message":{
    "token":"bk3RNwTe3H0:CI2k_HHwgIpoDKCIZvvDMExUdFQ3P1...",
    "notification":{
      "title":"Portugal vs. Denmark",
      "body":"great match!"
    }
  }
}

if you want a subtitle please add subtitle to data field and then then fetch using getData() method

Customized Notification for subtitle

{
  "message":{
    "token":"bk3RNwTe3H0:CI2k_HHwgIpoDKCIZvvDMExUdFQ3P1...",
    "notification":{
      "title":"Portugal vs. Denmark",
      "body":"great match!"
    },
    "data" : {
      "subtitle" : "Mario",
      "subHeading" : "PortugalVSDenmark"
    }
  }
}
Ad
source: stackoverflow.com
Ad