Firebase Cloud Messaging: how to send data message to all users? [duplicate] - android

This question already has answers here:
How do you send a Firebase Notification to all devices via CURL?
(10 answers)
Closed 3 years ago.
I would like to send data messages to all users.
Is it possible to do it programmatically, without using the Firebase Notifications Console?
The problem with the Console is that the "message text" field at the beginning of the form is compulsory. So, even if I add the custom data key/values, there will also be the standard notification component.
As stated here, when the message includes both notification and data, in case the app is in the background, a standard notification message will be notified to the system tray.
I would like instead to deliver only a notification based on the custom data (trigged by OnMessageReceived).
How can I achieve that? Programmatically, I can correctly send data messages to specific users, but I cannot find a way to send data messages to ALL users.

Use topic messaging. You can define the name of a topic that all installations of your app will subscribe to, then send the message to that topic.
You can use the Firebase Admin SDK from your server to send that message. Or you can use the FCM HTTP API to send that message.

Related

Sending notifications from angular website to android app [duplicate]

This question already has answers here:
How to send one to one message using Firebase Messaging
(5 answers)
How can I send a Firebase Cloud Messaging notification without use the Firebase Console?
(17 answers)
Closed 2 years ago.
This might be a duplicate questions, but still. I have seen many tutorials on sending notifications from Firebase Cloud Messaging to an android app, but I don't understand how to send notifications from my angular website to firebase, which will then push these notifications to android app. In all these tutorials, they have sent notifications by manually typing messages in the firebase UI.
My question how do I send notification data from my angular website to FCM, which will then send these notifications to my android app? Any references for this? Any procedure to follow?
In your case, you might consider having your own app server that will provide an API for your angular app to send notification. Here's a documentation on how you can send a notification to a device from your server.
https://firebase.google.com/docs/cloud-messaging/send-message
There are different parts of this implementation actually. First, your app server needs to provide an API to the Android app that will be used to send the firebase registration token from your app when the app is launched. You might consider storing those registration tokens in your backend database.
Then the other API that your server will provide, to send notification, can be integrated in your angular app. The server API should be able to find the exact registration token of the device where you need to send the notification and will call the API from FCM to send the notification to the device. Here's the API doc that you might consider taking a look into.
https://firebase.google.com/docs/cloud-messaging/http-server-ref
Here is a good tutorial that shows how you can implement the server side implementation to send the notification.
https://www.pluralsight.com/guides/push-notifications-with-firebase-cloud-messaging

What is the alternative of Using FCM Server Key in Client Code? [duplicate]

This question already has answers here:
How to send one to one message using Firebase Messaging
(5 answers)
Closed 3 years ago.
I have build an android app to send the user to user notification using Firebase Cloud Messaging for that I have included FCM Server Key in client code.
Recently, I came to know about this that it is a security risk, that there could be malicious attack and the attacker can send the messages using that FCM server Key(if he comes to know about it). I am looking for the alternative for the same, can you guide me ?
I am using this tutorial Notification Tutorial
I agree that including the key in your client is a security risk!
One option you have is to send the notification via a cloud function. The cloud function would have the responsibility of all the interaction with FCM -- thus you keep the key secret. At the same time the function is able to do any necessary validation that the user is allowed to send the notification (e.g. authentication, rate limiting, formatting the message properly, etc).
Then have your app call the cloud function instead of trying to call FCM itself directly.

Send android push notification to all except one user [duplicate]

This question already has answers here:
Push notification to all the users subscribed to the topic except login user using FCM Firebase
(2 answers)
Closed 4 years ago.
I am using firebase and I have an application where I need to send notification to all users. So to achieve that I have created a topic allUsers to which every device subscribes. Now if I send push notification to this topic, every device received it. I want to exclude one device, which is indirectly creating push notification to /topics/allUsers.
Is this achievable.?
Update:
For Android, what I do is, I include a sender custom value in the payload, check if the value is the same as the current user's id, if it is, I don't show the notification.
Topics Messaging works simply that all subscribers would receive the message sent to the corresponding topic.
You can't exclude a specific subscriber. You're going to have to:
create a separate topic where the user won't be subscribed
unsubscribe the user to the corresponding topic
or send the message to the specific users only using registration_ids instead
Other than that, there is currently no other workaround on what you want to do.
Might be a little late, but after reading FrankĀ“s post, I came with the idea to create your topic for all users and then a topic for each user, then when sending a message, you can add topic conditions such as:
('AllUsers' in topics) && !('user_foo' in topics)
Yes, you can do this. Go to your Firebase console, click on your project panel and there navigate to Grow/Notifications tab. There you can send messages (push notifications) to your app users and adjust everything related to the message and targeting there:

send push notification using firebase among multiple android devices [duplicate]

This question already has answers here:
How to send Device to device notification by using FCM without using XMPP or any other script.?
(3 answers)
Closed 5 years ago.
I have seen that most of the android tutorial are sending a push notificaiton using an website system to control how to send to the devices. Is there a method to send from an android device to another android device and the device can automatically compose the message to the other devices without extra setting?? Thank you.
Sure create a custom server, send the token and message to server, the token must identify the user device that will compose the message. When the message is received on the composer end, send another token and message to the server, this time along with a field(composer) thus identifying and agreeing that this token will compose a message. use appropriate mechanisms to handle such a request. Make sense? so basically it's just sending multiple but from different and each device creates special field identifying the intent of the message.

Firebase for chat message alert (push notification) [duplicate]

This question already has answers here:
How to send device to device messages using Firebase Cloud Messaging?
(14 answers)
Closed 6 years ago.
I am developing a chat app using firebase real-time database. I am able to exchange messages but i want to have a message alert notification for new messages.
Sending notifications using firebase console is working but now i want to automate it without firebase console.
Do i need to create my own app server for push notification between android clients? Or is there another way to achieve this instead of creating a server?
Thank you
Firebase realtime database is very useful precisely for its "realtime" aspect.
You could create a Service that listens for changes in the database and create a Notification whenever the client receives a new message.

Categories

Resources