B4J Question fcm not push through b4j

Discussion in 'B4J Questions' started by jimich, Mar 2, 2018.

Tags:
  1. jimich

    jimich Member Licensed User

    Hi to all!

    I can receive notification (in b4a) through firebase notification console but I can't receive when it send through b4j.

    Here's my code:

    Code:
    'libraries:
    'jCore(Version:6.00)
    'jOkHttpUtils2_NONUI (Version 2.62)
    'Json (Version 1.10)
    'OkHttp (Version 1.20)

    'Non-UI application (console / server application)
    #Region  Project Attributes
        
    #CommandLineArgs:
        
    #MergeLibraries: True
    #End Region

    Sub Process_Globals
    'replaced last 8 with X:
        Private const API_KEY As String = "AIzaSyAj3llxMqUGGPlJhGyerIfd8FNnXXXXXXXX"
    End Sub

    Sub AppStart (Args() As String)
        SendMessage(
    "general""Title""Hello")
        StartMessageLoop
    End Sub

    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)
        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

    Sub JobDone(job As HttpJob)
        
    Log(job)
        
    If job.Success Then
            
    Log(job.GetString)
        
    End If
        job.Release
        StopMessageLoop 
    '<-- non ui app only
    End Sub
    And here's my log:

    [jobname=fcm, success=true, username=
    , password=, errormessage=, target=class jimich.com.myapp.main
    , taskid=1, req=anywheresoftware.b4h.okhttp.OkHttpClientWrapper$OkHttpRequest@23ab930d, tag=java.lang.Object@4534b60d
    , httputils2service=null]
    {"message_id":4691947009315506765}


    Thank you for kind replies and God bless!
     
    Last edited: Mar 2, 2018
  2. Erel

    Erel Administrator Staff Member Licensed User

    The message was sent properly. Check your B4A or B4i implementation.
     
  3. jimich

    jimich Member Licensed User

    Thank you Erel for your reply. I'll check my B4A code.
     
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