Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Sending Firebase Cloud Message using UID of user

I want to build an Android app that allows a user to send notification and data messages to other users. I've started using Firebase only recently, and Firebase Cloud Messaging is still pretty confusing to me.

I have already implemented sending a message to a specific device using the Firebase Instance Id. However, in my app, a user can log out and log into their accounts using different devices, so this isn't really what I want. I read the documentation and it's pretty confusing, they mention sending messages to user groups, and topics (which only apps can subscribe to, not users).

Is there a way to send a push notification directly to another user or a group of users using only their UIDs? If not, is there any other way I can implement this?

like image 546
Ashwin Gopi Krishna Avatar asked Feb 07 '17 23:02

Ashwin Gopi Krishna


1 Answers

I did it storing the FCM Token in a device structure by user. When the user login, add the deviceData to the userToken structure. You need clear deviceData when the user logout. This way, you will only send notifications to logged devices.

Ex (This is not like mine structure, but it can help you to wondering a good way to do this):

-userToken
  -idUser1
     -device
         -idDevice1
             -fcmToken: "xxxxx"
         -idDevice2
             -fcmToken: "YYYYY"  

Hope that I helped you

like image 135
Rodrigo Silva Avatar answered Sep 25 '22 14:09

Rodrigo Silva