Android Question Firebase store Token

paul fredrick

Member
Licensed User
Longtime User
i have tested FirebaseNotification and FirebaseAuth... works, but i would like to store the token when user subscribe with google-service or with another metod

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

when user sign in store ID in authentication tab, but this ID not works to SendMessageToSingleDevice

B4X:
Sub Auth_SignedIn (User As FirebaseUser)
Log("SignedIn: " & User.DisplayName)
lblName.Text = "Hello: " & User.DisplayName
auth.GetUserTokenId(User,False)
End Sub

Thanks

Grazie

P.S.: Sorry Erel, but i don't know how to tag code :(
 
Last edited:

DonManfred

Expert
Licensed User
Longtime User
P.S.: Sorry Erel, but i don't know how to tag code :(

codetag.jpg
 
Upvote 0

paul fredrick

Member
Licensed User
Longtime User
thanks for reply Erel...
the problem for me is how to store the token on database server.
Can you give me example code and wich service set up in firebase console, if necessary, please.
 
Upvote 0

DonManfred

Expert
Licensed User
Longtime User
B4X:
Public Sub SubscribeToTopics
    Log("SubscribeToTopics")
    fm.SubscribeToTopic(starter.Phone.GetSettings("android_id")) 'you can subscribe to more topics
    fm.SubscribeToTopic("general") 'you can subscribe to more topics
    CheckToken
End Sub
Sub CheckToken
    Log("CheckToken: "&fm.Token)
    Do While fm.Token = ""
        Log("Sleep250")
        Sleep(250)       
    Loop
    If fm.Token <> "" Then
        Log("Register Device with Token: "&fm.Token)
        Dim j As HttpJob
        j.Initialize("",Me)
        j.Download2("http://yourdomain.com",Array As String("action","register","token",fm.Token,"deviceID",starter.Phone.GetSettings("android_id")))
        Wait For (j) JobDone(j As HttpJob)
        If j.Success Then
            Log(j.GetString)
        Else
            Log(j.ErrorMessage)
        End If
        j.Release
    End If

End Sub
 
Upvote 0

paul fredrick

Member
Licensed User
Longtime User
sorry, only another little question...
in this line
B4X:
fm.SubscribeToTopic(starter.Phone.GetSettings("android_id"))
and
B4X:
j.Download2("http://yourdomain.com",Array As String("action","register","token",fm.Token,"deviceID",starter.Phone.GetSettings("android_id")))
"Phone" is not found, maybe i miss something ?
 
Upvote 0
Top