1. *** New version of B4J is available ***
    B4J v7.8
    Dismiss Notice

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

Discussion in 'Android Questions' started by Makumbi, Aug 5, 2019.

  1. Makumbi

    Makumbi Active Member Licensed User

    Example iam currently using NB6 for notification alerts now i to to pass the message from firebase to NB6
    Code:
    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)
     
  2. DonManfred

    DonManfred Expert Licensed User

    Add additional Values when sending the Notification from your Serverside
    Code:
    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.
    Code:
    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: Aug 5, 2019
    Erel, mangojack, BillMeyer and 2 others like this.
Loading...
  1. This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
    By continuing to use this site, you are consenting to our use of cookies.
    Dismiss Notice