Hi All, i am working on a personal project i started a few years ago, I finally found some time to get somethings going but I am a little confused about a few things regarding FireBase Messaging TokenID.
I have a B4J Non_UI application running in a google cloud virtual machine which receives requests from my android app, the information i pass to the B4J app is the TokenID and message so that it can be distributed to a single device based on the unique TokenID, the B4J app when it receives these requests via POST method and then makes the calls to the Google API
The TokenID string is saved in a remote database, as I understand this string should be a unique String assigned to every device.
Below is part of the code i am using.
This part is self explanatory and seems to work just fine.
My confusion is that when I test and send a message to to my device I receive the notification just fine inside the FireBaseMessaging Service of my Android app, but when I test with my cousin's device he never receives the notification. I just figured that every time he opens the app on his device the TokenID String is different everytime, so it seems like when the B4J app sends the notification it sends it to the TokenID that was initially saved when he signs up with his email and password.
Is this normal? should I not be using the TokenID to send individual notifications to single devices, is there any other way to accomplish this, am i doing this the wrong way?
Thoughts?
Walter
I have a B4J Non_UI application running in a google cloud virtual machine which receives requests from my android app, the information i pass to the B4J app is the TokenID and message so that it can be distributed to a single device based on the unique TokenID, the B4J app when it receives these requests via POST method and then makes the calls to the Google API
The TokenID string is saved in a remote database, as I understand this string should be a unique String assigned to every device.
Below is part of the code i am using.
B4X:
Sub Handle(req As ServletRequest, resp As ServletResponse)
Dim start As Long = DateTime.Now
resp.ContentType = "text/html;charset=utf-8"
response = resp
Dim messageto As String = req.GetParameter("messageto")
Select messageto
Case "Chofer"
Case "Owner"
SendMessageToOwnerDevice(req.GetParameter("fcmtoken"), req.GetParameter("data"))
Case "Cliente"
End Select
StartMessageLoop 'we need this here, for the wait for
End Sub
B4X:
Private Sub SendMessageToOwnerDevice(FCMToken As String, datamessage As String)
Dim Job1 As HttpJob
Job1.Initialize("SendMessageOwner", Me)
DateTime.DateFormat="dd.MM.yyyy"
Dim DatumZeit As String
DatumZeit=DateTime.Date(DateTime.Now)
DatumZeit=DatumZeit & " " & DateTime.Time(DateTime.Now)
Dim m As Map = CreateMap("to": $"${FCMToken}"$)
Dim data As Map = CreateMap("data": datamessage)
m.Put("data", data)
m.Put("content_available", True)
Dim jg As JSONGenerator
jg.Initialize(m)
Job1.Tag=jg
Log(jg.ToString)
Job1.PostString("https://fcm.googleapis.com/fcm/send", jg.ToString)
Job1.GetRequest.SetContentType("application/json;charset=UTF-8")
Job1.GetRequest.SetHeader("Authorization", "key=" & Main.API_KEY)
End Sub
This part is self explanatory and seems to work just fine.
My confusion is that when I test and send a message to to my device I receive the notification just fine inside the FireBaseMessaging Service of my Android app, but when I test with my cousin's device he never receives the notification. I just figured that every time he opens the app on his device the TokenID String is different everytime, so it seems like when the B4J app sends the notification it sends it to the TokenID that was initially saved when he signs up with his email and password.
Is this normal? should I not be using the TokenID to send individual notifications to single devices, is there any other way to accomplish this, am i doing this the wrong way?
Thoughts?
Walter