Android Question How can i pass parameter from firebase messaging to a layout activity in my app

Makumbi

Well-Known Member
Licensed User
Example iam currently using NB6 for notification alerts now i to to pass the message from firebase to NB6
B4X:
Dim n As NB6
                n.Initialize("default", Application.LabelName, "HIGH").SmallIcon(smiley)
                n.Build(quot.Get("sms"), "Kabojja Junior School", quot.Get("sms"), Sendsms).Notify(9)
 

DonManfred

Expert
Licensed User
Longtime User
Add additional Values when sending the Notification from your Serverside
B4X:
Private Sub SendMessage(Topic As String, Title As String, Body As String)
    Dim Job As HttpJob
    Job.Initialize("fcm", Me)
    Dim m As Map = CreateMap("to": $"/topics/${Topic}"$)
    Dim data As Map = CreateMap("title": Title, "body": Body) ' Add more Data to this Map
    If Topic.StartsWith("ios_") Then
        Dim iosalert As Map =  CreateMap("title": Title, "body": Body, "sound": "default")
        m.Put("notification", iosalert)
        m.Put("priority", 10)
    End If
    m.Put("data", data)
    Dim jg As JSONGenerator
    jg.Initialize(m)
    Job.PostString("https://fcm.googleapis.com/fcm/send", jg.ToString)
    Job.GetRequest.SetContentType("application/json;charset=UTF-8")
    Job.GetRequest.SetHeader("Authorization", "key=" & API_KEY)
End Sub

The Data can be extracted in the sub fm_MessageArrived (Message As RemoteMessage)

for ex.
B4X:
    If Message.GetData.ContainsKey("sms") Then
               dim sms as string = Message.GetData.Get("sms")
        End if
It is up to you then to decide what to do with the additional Infos you get.

NOTE that the Messagepayload is limited. You can not transfer unlimited Data.


It is helpful if you just understand how the FirebaseNotification System is working.
 
Last edited:
Upvote 0
Top