Android Question Firebase Notification - access notification payload

FabioC6

Member
Licensed User
Hi, I've been experimenting with Firebase cloud messaging and I'm able to receive notifications on B4A, however with the following payload the notification on screen appears with both title and body null, I imagine it's because the method Message.GetData("title") reads informations only inside the object data.

Is there any way to access the properties title and body nested in the object notification?

{
"message":{
"token":"...",
"notification":{
"title":"Portugal vs. Denmark",
"body":"great match!"
},
"data" : {
"Nick" : "Mario",
"Room" : "PortugalVSDenmark"
}
}
}

this is the code I'm using when the message arrives

B4X:
Sub fm_MessageArrived (Message As RemoteMessage)
    Log("Message arrived")
    Log($"Message data: ${Message.GetData}"$)
    Dim n As Notification
    n.Initialize
    n.Icon = "icon"
    n.SetInfo(Message.GetData.Get("title"), Message.GetData.Get("body"), Main)
    n.Notify(1)
End Sub
 

DonManfred

Expert
Licensed User
Longtime User
See the Firebase notification tutorial. Use the B4J code to send the Notification,

My guess is that the format of the payload you are sending is wrong.
 
Upvote 0

FabioC6

Member
Licensed User
It works with your tutorial, however I'm sending the message using a .NET application and I need to receive the message on iOS (Xcode) as well and it doesn't work with the payload in the B4J tutorial, I need to put title and body inside "notification"

"notification":{
"title":"Portugal vs. Denmark",
"body":"great match!"
},

it's not pretty but copying title and body in both data and notification does the trick.

{
"message":{
"token":"...",
"notification":{
"title":"Portugal vs. Denmark",
"body":"great match!"
},
"data" : {
"Nick" : "Mario",
"Room" : "PortugalVSDenmark"
"title":"Portugal vs. Denmark",
"body":"great match!"
}
}
 
Upvote 0
Top