Android Question Why RemoteMessage.GetData.Get("title") has null value when receiving firebase notification?

Status
Not open for further replies.

Rajesh Gupta

Member
Licensed User
Hello Sir,
I am beginning to use firebase notifications in my app. My code is...


#Region Service Attributes
#StartAtBoot: False
#End Region

<!------------ Process_Globals starts------------------------->

Sub Process_Globals
Private fm As FirebaseMessaging
Public MyFCMToken As String
Public FCM_KEY As String = ""
Public MyName As String ="Suruchi"
End Sub


<!------------ Recieving token------------------------->

Sub Service_Create
fm.Initialize("fm")
MyFCMToken=fm.Token
Log (MyFCMToken)​
End Sub


<!---------------Service_Start------------------------->

Sub Service_Start (StartingIntent As Intent)
If StartingIntent.IsInitialized And fm.HandleIntent(StartingIntent) Then Return​
End Sub


<!---------------for receiving notification------------------------->

Sub fm_MessageArrived (Message As RemoteMessage)
Log("Message arrived")
Log($"Message data: ${Message.GetData.Get("title")}"$)

Dim n As Notification
n.Initialize
n.Icon = "icon"
n.Vibrate=True
n.Sound=True
n.SetInfo(Message.GetData.Get("title"), Message.GetData.Get("body"), Main)
n.Notify(1)​
End Sub


It works well but in notification tray, null value is shown because Message.GetData.Get("title") gives null value. Why this happen?
 
Last edited:

DonManfred

Expert
Licensed User
Longtime User
How do you send the message?

PD: Please use code tags when posting code!
 
Upvote 0

An Schi

Well-Known Member
Licensed User
It is recommended to create a b4j or b4a project to send the push. There are issues using the firebase console to send them.
 
Upvote 0

DonManfred

Expert
Licensed User
Longtime User
Upvote 0

ZenWhisk

Member
Licensed User
Longtime User
Did you find out what the problem was ? I have posted a similar question. I get the title if my app is in the foreground. In background I get a notification but not the title.
 
Upvote 0

KMatle

Expert
Licensed User
Longtime User
Please don't assume you always get title & data (it depends on what the SENDER is sending).

See here: https://www.b4x.com/android/forum/t...oreground-background-data-notification.73356/

You need to know what kind of message you send (yep, there are different ones) and in which state your apps is (foreground/background).

Best practice for me: Just send data messages and handle notifications on your own. Data messages don't hav a title (you just send data). Of course you can send a message which includes a title (e.g. using a map).
 
Upvote 0
Status
Not open for further replies.
Top