Android Question Addressing Firebase Messages to Particular Users

NetChain

Member
It might be a simple question, but what is the best practice to send messages addressed only to a particular user?

I've successfully tested delivery Firebase messages to my phone. I've made a test sending program in B4J and an app in B4A and they both work. But I couldn't find any information on how to separate messages per users?

In a production environment, most apps should receive only messages addressed to them. I'm planning on having a user registration/management system using my own web/db servers. So every user of my app would have to register either within the app or on the web (that's not important here), but what's important is that I will have the unique identity for every user of my app. Based on the logic of my business, my application server, running in the cloud will "talk" directly to Firebase when it needs to reach a particular user.

The question is: what would be the best method of sending messages to individual users of my app?
 

MarcoRome

Expert
Licensed User
Longtime User
You must have a topic assigned for the specific user.
For example, if you send a notification to all users they will be registered in the "general" topic, if you have a user who for example has id 100, you will have him registered (if ever at the time of login ?) to a general_100 topic. At this point, if you send a notification on that topic, only your customer or group of customers if registered on the same topic will receive it
 
Upvote 0

Erel

B4X founder
Staff member
Licensed User
Longtime User
Another option is to get the device token with FirebaseMessaging.Token, send it to your server and use it to send messages to this specific device.

You should then replace in the B4J code:
B4X:
Dim message As Map = CreateMap("topic": Topic, "data": data)
With:
B4X:
Dim message As Map = CreateMap("token": Token, "data": data)
 
Upvote 0

ilan

Expert
Licensed User
Longtime User
You must have a topic assigned for the specific user.
For example, if you send a notification to all users they will be registered in the "general" topic, if you have a user who for example has id 100, you will have him registered (if ever at the time of login ?) to a general_100 topic. At this point, if you send a notification on that topic, only your customer or group of customers if registered on the same topic will receive it
i think the main issue for him is how to chain the topic to the specific user?
if a user download the app how do i know what id he has?
i would register all users to the same topic but inside the data map i can filter the user by id/email/... (unique information)

like if i want to send a notification to user that has the email [email protected] i can add it in the data map and when the noti is received i check if it is the correct user and show the noti.
OR after the user register from the app he subscribe to a topic with his unique info and like this i can send the noti to that user only. the main important thing is to let the user register from your app so you have track of all your users.

i have an app where i inform the user that he won a reward by sending him a notification and i use this approach (add userid inside data map)
 
Upvote 0

MarcoRome

Expert
Licensed User
Longtime User
i think the main issue for him is how to chain the topic to the specific user?
if a user download the app how do i know what id he has?
i would register all users to the same topic but inside the data map i can filter the user by id/email/... (unique information)

like if i want to send a notification to user that has the email [email protected] i can add it in the data map and when the noti is received i check if it is the correct user and show the noti.
OR after the user register from the app he subscribe to a topic with his unique info and like this i can send the noti to that user only. the main important thing is to let the user register from your app so you have track of all your users.

i have an app where i inform the user that he won a reward by sending him a notification and i use this approach (add userid inside data map)

Hello dear Ilan.
Mine was a generic answer, to make it clear that other topics can be created in which to connect different users or have a specific topic for the user.
For example, in many of our apps, after the user has registered and logged in, we obviously know their ID and in this way when we send a notification, we can send it to their registered "topic" ( general_100 ) .
 
Upvote 0
Top