Android Question B4A FireBase Push Notification to Specific Device - Get the Id

George_G

Member
Licensed User
Hello everyone!

I am trying to send a notification (I am using firebase push notification), to a specific device.
I found on forum, that I can do this using "fm.Token".

But, how can I get this Id to send a notification specific to this device?

Thank you in Advance.
 

DonManfred

Expert
Licensed User
Longtime User
But, how can I get this Id to send a notification specific to this device?
You need to send this token after your app starts (and get the token) and send it to your server to know it.
 
Upvote 0

DonManfred

Expert
Licensed User
Longtime User
Example:
B4X:
Public Sub SubscribeToTopics
    topic = Starter.DeviceID
    Log("SubscribeToTopics = fbdnkv2,"&topic)
    Sleep(0)
    If fm.IsInitialized Then
        'Log("SubscribeToTopics fm isInitialized")
    End If
    'Log("SubscribeToTopics check token")
    Dim token As String = fm.Token
    Log("SubscribeToTopics fm-token = "&token)
    

    If fm.Token <> "" Then
        'Log("Register Device with Token: "&FirebaseMessaging.fm.Token)
        Dim j As HttpJob
        j.Initialize("",Me)
        Log(Starter.BridgeURL&"?action=register&token="&fm.Token&"&deviceID="&Starter.DeviceID)
        j.Download2(Starter.BridgeURL,Array As String("action","register","token",fm.Token,"deviceID",Starter.DeviceID, "modul","Service2Mobil", "uid",Starter.logged_userid))
        wait for (j) JobDone(job As HttpJob)
        If job.Success Then
            Dim res As String = job.GetString
            Log("Register Successfully")
            Log(job.GetString)

            job.Release
        Else
            LogColor("Error: "&job.ErrorMessage, Colors.Red)
            job.Release
        End If
    End If
    fm.SubscribeToTopic(topic) 'you can subscribe to more topics
End Sub
 
Upvote 1
Top