albert kim
albert kim

Reputation: 333

Sending a push notification to a user in the database

I am trying to implement push notification using Firebase Cloud Messaging but it seems as if you have to register the device to receive push notifications. I am trying to make it so when there is action in the database, such as an inbox reply, send a push notification to the user who received the message.

Is there a way to send the push notification with Firebase to a particular user, not a particular device?

Upvotes: 0

Views: 1870

Answers (2)

Arthur Thompson
Arthur Thompson

Reputation: 9225

FCM provides several ways for you to send notifications to your users. You can send messages directly to devices via an Instance ID token, you can send messages to a topic that your user has subscribed to, and you can also send messages to groups of users eg: country/language etc.

Have a look at this sample which demonstrates sending to a device and topic. Also have a look at the docs for more details on sending and receiving messages.

Upvotes: 0

Micro
Micro

Reputation: 10891

You don't send push notifications to a user, you send them to a device.

Somewhere in your code (maybe when your user signs up/ logs in to your app), you have to execute the code to get a GCM registration token. This token is unique to your Android app and that specific Android device.

With that token, you can send push notifications to that device using any method you want (from an app, from a website, etc. If you have a GCM reg token you can even send pushes from this handy website: http://1-dot-sigma-freedom-752.appspot.com/).

It is now your responsibility to keep a database of your users and their GCM registration tokens. When a user wants to send a push to another user, you would find the corresponding registration token in your database and then execute the code to send them the push using that token.

Upvotes: 3

Related Questions