Android Question sending a specific message firebase

Makumbi

Well-Known Member
Licensed User
I have successfully managed to send message to all devices using firebase . Now how can i send a specific message to a registered user using his or her registered mobile telephone number using firebase thanks in advance

B4X:
Sub AppStart (Args() As String)
    SendMessage("general", "This is the title", "Hello goodwork man!!!!")
    StartMessageLoop
End Sub

[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)
    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")
    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
[/CODE]
 

DonManfred

Expert
Licensed User
Longtime User
his or her registered mobile telephone number using firebase
You can´t! You only can send to a token or to a Topic.
You can for sure register the Phonenumber as a Topic and send to this Topic.

PD: If you plan not to give away any LIKE for the help you get then please expect not to get much help (at least not from me) in the future.
 
Upvote 0

Makumbi

Well-Known Member
Licensed User
You can´t! You only can send to a token or to a Topic.
You can for sure register the Phonenumber as a Topic and send to this Topic.

so you mean it should be this
B4X:
CallSubDelayed(Firebasemessaging, "SubscribeToTopics")
and then change it to
B4X:
CallSubDelayed(Firebasemessaging, "077777765")
 
Upvote 0

DonManfred

Expert
Licensed User
Longtime User
No! Why do you think this way??????
Start NOW learning the language and what the commands do you are using...

It is mandatory to understand what exactly you are doing there!

CallSubDelayed(Firebasemessaging, "SubscribeToTopics")
WHAT does this command do?
 
Upvote 0

Makumbi

Well-Known Member
Licensed User
Another question:

How does the Tutorial register the Topic "general"?
What are the notes there?
That is what i got from the notes

but according to what you are saying i think it should like
B4X:
Sub AppStart (Args() As String)
    SendMessage("general", "This is the title", "Hello goodwork man!!!!")
    StartMessageLoop
End Sub

to be changed to a mobile number like

B4X:
Sub AppStart (Args() As String)
    SendMessage("0777776", "This is the title", "Hello goodwork man!!!!")
    StartMessageLoop
End Sub
B4X:
#Region  Service Attributes
    #StartAtBoot: False
    
#End Region

Sub Process_Globals
    Private fm As FirebaseMessaging
End Sub

Sub Service_Create
    fm.Initialize("fm")
End Sub

Public Sub SubscribeToTopics
    fm.SubscribeToTopic("general") 'you can subscribe to more topics
End Sub

Sub Service_Start (StartingIntent As Intent)
    If StartingIntent.IsInitialized Then fm.HandleIntent(StartingIntent)
    Sleep(0)
    Service.StopAutomaticForeground 'remove if not using B4A v8+.
End Sub

Sub fm_MessageArrived (Message As RemoteMessage)
    Log("Message arrived")
    Log($"Message data: ${Message.GetData}"$)
    Dim n As Notification
    n.Initialize
    n.Icon = "icon"
    n.SetInfo(Message.GetData.Get("title"), Message.GetData.Get("body"), Main)
    n.Notify(1)
End Sub

Sub Service_Destroy

End Sub
 
Upvote 0

DonManfred

Expert
Licensed User
Longtime User
to be changed to a mobile number like
that´s one step needed, yes. But that´s not all. You need to register the Topic 0777776 too.

If it does not make a LOUD CLICK now after my questions i´ll give up.... It is not worth the time i investigate to help you.
 
Upvote 0
Top