B4J Question fcm not push through b4j

jimich

Member
Licensed User
Longtime 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:

B4X:
'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:
Top