0

I'm working on a doorbell project in which I want to send Push Notification to user when a guest come and ring the doorbell, it should send a Push Notification to the user (i.e owner of house). I want to use Firebase Cloud Messaging for this in my android app.

We are using RaspberryPi as the hardware controller. It will trigger notification to user using FCM on their android device when someone presses their doorbell.(which is not a point of concern.)

My confusion is:

According to this post on SO, FCM will send Push Notification to the predefined 'registration_ids' which we have mentioned in the app. But in my case, every user will have their different registration ids. Also the number of users are not fixed.

It could be any number of users. Whoever uses the doorbell will have their own id.

So it will be a possible scenario like:

  1. suppose I have not mentioned any registration id in app. 10 users have installed this doorbell at home and someone on the house no 1 presses doorbell button, the FCM will send push notification to all the 10 users. Reason is, the registration id will be same for all the devices who have installed app from PlayStore.

  2. suppose I have mentioned 3 registration id in app. So 3 users will be getting the same Push Notification at the same time.

  3. And if i'm not wrong, if i put only 1 registration id, only 1 user will get notification even if 5 different house's doorbell are pressed, the same user will be notified 5 times.

  4. If i declare a specific registration id to be notified in server side (i.e RaspberryPi), I have to regularly add new registration ids as the number of users increases in my app and update it frequently.

So how do I resolve this problem ?

I haven't started developing this app till now because I'm confused with the first step itself.

If I've gone wrong somewhere, please guide me as I'm new to Push Notifications or FCM. I may not have understood concept of FCM, which is possible but I'm not sure. If this solution is not possible using FCM, suggest me some other options to achieve this please.

Community
  • 1
  • 1
Test Test
  • 43
  • 7

1 Answers1

1

A Registration token corresponds to a single app instance (see my answer here).

In your post, it seems like you were confusing the registration id as something that is permanent in the app, which is not.

Whenever a user installs your app, on the first initialization, it should generate it's own Registration token, where you'll have to save that token to your App Server, making sure that you associate it with the corresponding user details.

For your use-case, you could make use of Topic Messaging, where you simply subscribe the user to their corresponding doorbell topic, and every time that specific doorbell is triggered, you send a message to the corresponding topic.

Community
  • 1
  • 1
AL.
  • 36,815
  • 10
  • 142
  • 281