I want to develop a new feature in my app which lets me send notifications to all users with that app installed. I have been searching and found information on how to send upstream messages to Firebase Cloud Messaging, but found nothing explaining how to directly send notifications to other users.

- 7,576
- 2
- 16
- 31

- 545
- 1
- 7
- 27
-
1Related: https://stackoverflow.com/q/37435750/4815718 – Bob Snyder Nov 27 '17 at 19:22
-
re Bob's link, the solution is to use firebase cloud functions – Shmuel Nov 27 '17 at 19:57
3 Answers
There is a way to do that. You could accomplish that using Firebase database, Cloud Messaging and Node.js. You can find how to do that in this article: https://firebase.googleblog.com/2016/08/sending-notifications-between-android.html
But if you see this as too much complicated you can use some another providers like OneSignal
or Back4app
which is based on parse platform and pretty much simpler then this example above and also has a free plain. How to setup notifications using Cloud code in Back4app take a look on this example:
https://docs.back4app.com/docs/android/push-notification/push-cloud-code/

- 4,402
- 3
- 18
- 37
Option 1 - Send messages directly from Firebase
If you are trying to send out messages to all users of your Android app using Firebase, you should look at the documentation on how to "Send Messages with the Firebase Console".
Option 2 - Send messages from the app to a service; then to Firebase
If you are trying to send a message from your Android app to Firebase and then from firebase to other users, you may be missing a key component of your stack/infrastructure, a web service. The service acts as a middle man between Firebase Cloud Messaging and your app, effectively making the decisions on how to handle messages from the app, and how to send commands to firebase, including who (which devices) to target. You have options for this kind of service:
- An app server (written in whatever environment you know best or is most appropriate)
- Some other trusted environment such as Cloud Functions for Firebase
Take a look at the documentation on interacting with the Firebase Cloud Messaging Server for more details.
Once you have that set up, your flow looks more like this:
Android App (Message Sender) -> Message Handling Service -> Firebase Cloud Messaging -> Android App (Targeted Device(s))
Option 3 - Use Upstream Messages
Upstream messages still use a separate app server to handle messages sent by the device. In this case, the app sends an upstream message through FCM to the service, the service then does something with that upstream message and sends back an ACK (acknowledgment) message back to the sending device, so it can handle it with a callback. The app service, when handling the upstream message, could then command firebase to send out push notifications to targeted devices.
Overall, it's likely you have some more steps to complete.
You can also find more directly on the Firebase Cloud Messaging page or in the youtube video giving a general background to FCM.
There's also a video demoing upstream and downstream messages using firebase on youtube called Upstream and Downstream messages using FCM - Android.

- 1
- 1

- 181
- 1
- 5
You can do so by sending POST to https://fcm.googleapis.com/fcm/send with Server key as Authorization. But you need to know recipient token or topic.
https://firebase.google.com/docs/cloud-messaging/http-server-ref https://firebase.google.com/docs/cloud-messaging/auth-server#authorize-http-requests
-
I see one big issue here related to security: this would imply that all users of the Android application would have access to my server key, which is intended to stay confidential. – Alejandro Bertinelli Jun 27 '21 at 10:53
-
@AlejandroBertinelli I guess, you can encode it to keep it confidential. And yeah, if we talk about architecture this is not the best practice, but the question was "how to...". – ForegroundGravity Jun 28 '21 at 20:19