27

I have an android app and I want to send notifications to only one user when data is change. How can I do that? I don't want to send my message to all users of my app, just the user whose data changed.

Since Firebase returns a unique registration token created for every device after client initialization, is there any way to send the notification to a particular user or only to a group of Users using that token?

mgalgs
  • 15,671
  • 11
  • 61
  • 74
Atif Rizwan
  • 645
  • 2
  • 8
  • 17
  • Do you want to send the push notification to the current user who has called the onDataChange or to some other user? Can you describe your project properly? – Joey Pinto Jul 17 '17 at 04:12
  • What is `OnDataChange()` methode? please put some code. and explain your question. – V-rund Puro-hit Jul 17 '17 at 04:27
  • I have an Attendance app in which faculty member can submit leaves application. When any faculty member submit leave then notification is send to Head Of Department. – Atif Rizwan Jul 17 '17 at 05:47
  • 3
    You can use this https://firebase.google.com/docs/cloud-messaging/send-message#send_messages_to_specific_devices – luizParreira Oct 01 '18 at 14:15

1 Answers1

19

You can make topic for this user and subscribe to that topic then Firebase allow us to send message to specific topic using topic message. Kindly Look at this link

https://firebase.google.com/docs/cloud-messaging/android/topic-messaging

and this

How to send notification to specific users with FCM?

Hope it will help .

Vishal Vaishnav
  • 3,346
  • 3
  • 26
  • 57
Sardar Khan
  • 845
  • 6
  • 16
  • use firebase functions for that https://stackoverflow.com/questions/51853852/unspecified-index-when-searching-data-with-firebase-cloud-function-on-nested-obj – Atif AbbAsi Dec 05 '19 at 11:56
  • 46
    Doesn't one topic per user sound like a misuse of topics API? – Zorayr Jun 01 '20 at 19:33
  • 3
    @Zorayr I know this is an old question, but have you found an answer to your question about whether or not it a misuse of the topics API? – Andrew Heschl May 09 '21 at 16:31
  • 6
    I believe creating a topic per user *is* a misuse of the topics API. Instead, you should store the user's registration tokens and send the message to that user's [device](https://firebase.google.com/docs/cloud-messaging/send-message#send-messages-to-specific-devices) (or [devices](https://firebase.google.com/docs/cloud-messaging/send-message#send-messages-to-multiple-devices)). – mgalgs Apr 22 '22 at 03:25
  • The new authentication method and using the new API /v1, I believe we are not able to send to a single user anymore. we send to a topic with subscribed users. Is there a way to do this? – notify_my_threads Jul 15 '23 at 12:29