Android Question B4A, PHP and Firebase

Michel IL

New Member
Licensed User
Hello. I am writinng an app in B4A, one of the functionality of which should be push notifications. I took example with push notifications from the tutorial and it works. But now I need to make a PHP-page from which I could send notifications to one/some/all users of my app. But it needs "client token id`s". In all videos on the youtube used Firebase with Android Studio. In this development environment Firebase already fully integrated and you easy can obtain tokens. But how could I get it in the B4A? Or maybe exists another way to realize push notifications from PHP-page?
 

DonManfred

Expert
Licensed User
Longtime User
You can send the token to your php (or another php which updates your db with the tokens.

B4X:
Public Sub SubscribeToTopics
    topic = Starter.DeviceID
    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(BridgeURL&"?action=register&token="&FirebaseMessaging.fm.Token&"&deviceID="&DeviceID)
        j.Download2(Starter.BridgeURL,Array As String("action","register","token",fm.Token,"deviceID",Starter.DeviceID))
        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 0

Michel IL

New Member
Licensed User
Sorry, but compiler swears on the absence of "DeviceID" and "BridgeURL". If I understand correctly, DeviceID - it is token itself. But I don't know it and the point is to get it somehow. What is the "BridgeURL" I even have no idea.
 
Upvote 0

DonManfred

Expert
Licensed User
Longtime User
If I understand correctly, DeviceID - it is token itself
No. It is p.DeviceID (phone lib). A id which i use to recognize the Device.
The token is given in the String fm.Token

you need to send infos to your server to recognize the user/the device. If you know a name or email for example you can send this name or email to your server (together with the register-call) to connect a token to a user/device.

It all depends on your needs. You need to build a solution by yourself.
 
Upvote 0
Top