Android Question [SOLVED] Error receiving firebase notification

ermales

Member
Licensed User
I sent a notification from the firebase console if the application is closed there is no error but when the application is open I have the following error .
what should I do?


this is the code, guided in this tutorial -> https://www.b4x.com/android/forum/t...-messages-firebase-cloud-messaging-fcm.67716/

B4X:
#Region  Service Attributes
    #StartAtBoot: False
   
#End Region

Sub Process_Globals
    Private fm As FirebaseMessaging
   
End Sub

Sub Service_Create
    fm.Initialize("fm")
End Sub

Public Sub SubscribeToTopics
    fm.SubscribeToTopic("general") 'you can subscribe to more topics
End Sub

Sub Service_Start (StartingIntent As Intent)
    If StartingIntent.IsInitialized Then fm.HandleIntent(StartingIntent)
    Sleep(0)
    Service.StopAutomaticForeground 'remove if not using B4A v8+.
End Sub

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"), Menu)
    n.AutoCancel=True
    n.Notify(1)
   
End Sub

Sub Service_Destroy

End Sub
 

josejad

Expert
Licensed User
Longtime User
Not sure if can be your problem, but I’ve read some place “SetInfo” must be the last command before call the notificatin.
Try to move it down “Autocancel”
 
Upvote 0

DonManfred

Expert
Licensed User
Longtime User
I sent a notification from the firebase console
Here the problem starts.
Send the Notifiction with the B4J App

Message data: {}
There is no data. Even if you use the Notication right (see answer from @José J. Aguilar too) it will be empty as there is no text and body inside the Message arrived.
 
Upvote 0

ermales

Member
Licensed User
the problem is solved when “SetInfo” to move it down “Auto Cancel”

B4X:
#Region  Service Attributes
    #StartAtBoot: False
    
#End Region

Sub Process_Globals
    Private fm As FirebaseMessaging
    
End Sub

Sub Service_Create
    fm.Initialize("fm")
End Sub

Public Sub SubscribeToTopics
    fm.SubscribeToTopic("general") 'you can subscribe to more topics
End Sub

Sub Service_Start (StartingIntent As Intent)
    If StartingIntent.IsInitialized Then fm.HandleIntent(StartingIntent)
    Sleep(0)
    Service.StopAutomaticForeground 'remove if not using B4A v8+.
End Sub

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"), Menu)
    n.AutoCancel=True
    n.SetInfo(Message.GetData.Get("title"), Message.GetData.Get("body"), Menu)
    n.Notify(1)
    
End Sub

Sub Service_Destroy

End Sub

but when the app is open the notification does not arrive, the null message arrives, what could it do?

 
Upvote 0

DonManfred

Expert
Licensed User
Longtime User
but when the app is open the notification does not arrive, the null message arrives, what could it do?
New issue -> Create a new thread posting all relevant info. Message data: {} means the pushnotification you got does not contain the relevant data. Send the Notification with the B4J App and NOT with the console
 
Upvote 0

Andrew (Digitwell)

Well-Known Member
Licensed User
Longtime User
It is possible to use the Firebase console.
It seems that B4X only picks up the custom data fields, so you need to place your data there.
the standard fields are ignored.
Using the B4J tool is much simpler.

Don't forget to set the topic also.

 
Upvote 0
Cookies are required to use this site. You must accept them to continue using the site. Learn more…