Android Question Anyone have a working example of how to collect token and use firebase push messages?

tsteward

Well-Known Member
Licensed User
Longtime User
I'd like to be able to send notification to an individual user.
I have read this involves me collecting a token for the device, but this is way out of my league.

Users can leave comments on items in my app. I can then email others in the same thread that there have been changes. I'd like to send a notification instead.
My app is both b4a and b4i.
 

Mehrzad238

Active Member
I use this sub

B4X:
Sub fm_TokenRefresh (Token As String)
    
End Sub

In the FirebaseMessaging module receiver, to get a unique token from users and store it in my online database the rest is done in the host by PHP.

If you do not want to do this in receiver you can create a sub in one of your pages like

B4X:
Sub TokenRefresh(Token As String)
'    Log(Token)
End Sub

And change the Sub fm_TokenRefresh (Token As String), so can be used everywhere like this:

B4X:
Sub fm_TokenRefresh (Token As String)
    CallSub2(yourpagename or activity,"TokenRefresh",Token)
End Sub
 
Upvote 0

mcqueccu

Well-Known Member
Licensed User
Longtime User
The simplest way I implemented in my apps is to use the login information of the User. Example if the user registers with phone number or email, it means you already have these information on your database online.

So when the user login to your app, and it is successful, you just use his phone number or email or user id and subscribe that to your topic.

B4X:
Public Sub SubscribeToTopics
    fm.SubscribeToTopic("general") 'you can subscribe to more topics
    Sleep(0)
    fm.SubscribeToTopic("USERS-INFO-EXAMPLE-PHONE-NUMBER")
End Sub
 
Upvote 0

tsteward

Well-Known Member
Licensed User
Longtime User
The simplest way I implemented in my apps is to use the login information of the User. Example if the user registers with phone number or email, it means you already have these information on your database online.

So when the user login to your app, and it is successful, you just use his phone number or email or user id and subscribe that to your topic.

B4X:
Public Sub SubscribeToTopics
    fm.SubscribeToTopic("general") 'you can subscribe to more topics
    Sleep(0)
    fm.SubscribeToTopic("USERS-INFO-EXAMPLE-PHONE-NUMBER")
End Sub
Beautiful, I like it. Now how do I send the individual a message. Ie. php script to send notification?
 
Upvote 0

Alexander Stolte

Expert
Licensed User
Longtime User
you just use his phone number or email
sounds like a security hole if you use the email or phone number for this. It is safer to use a GUID and store it on the device and an online database in case the app is uninstalled and reinstalled later.
 
Upvote 0
Top