Send notification to only one user in firebase - android

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?

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 .

Related

Can one FCM token be used for multiple devices of same user?

I am working on implementing Notification System using Firebase Cloud Messaging. I want to know if the FCM token that is used by Firebase to send notifications can be the same for multiple devices of the same user? Is it possible to do so?
For example, we have an user. I want to generate a single token and store it with the user's profile and send notification to the user on that user's each device using the same token. If the user is logged in on web, as well as app, I want to send notification on both devices using the same token.
Is it possible, if yes then please share any link/doc that may be helpful for me.
Thank you in advance!
Each device has diffirent FCM token. If you want to send notification to multi devices, you can send by topic

FCM Notification to specific wordpress user

i am developping an android application based on a wordpress blog where users can post their own articles, i work with WP REST API to get posts , comments and users ...
I would like to send a notification automatically to the user when his article got a new comment , i have installed FCM correctly and tested the simple forme of notifications but i need to :
Trigger FCM Notification on new comment sent ( Or just on a button click )
Specify receiver so the notification is sent to logged in user with the right email/username
I thought of
working with setting User Property for every user logged like this :
mFirebaseAnalytics.setUserProperty("user_name_for_notification", "the_username");
Sending notification for all devices then handle it in onMessageReceived
but i don't think those are good ideas
So , any ideas where to start
thank you
FCM can send notifications with three different targeting methods:
to a specific FCM token/instance ID token, which identifies an installation of a specific application on a specific device.
to a group of such device/instance IDs.
to a specific topic, which FCM clients can subscribe to.
Firebase Cloud Messaging does not have the concept of a user, therefor it cannot target users directly. If you want to target users, you will have to map them to one of the targeting methods outline above.
The most common ways that I know of:
Store the token(s) for a user in a database under their UID, and then send to the user's token(s) when you need to target the user.
Give each user their own topic, based on their UID. Have the app subscribe to that topic, and send message to the user's topic when you need to target them.
Also see:
How to send one to one message using Firebase Messaging
Sending message to custom user using firebase
Send Firebase Cloud Messaging notification to users by user property
how to send data message to user segment From Rest API

FCM push notification to all devices which will be filtered on client side

Okay, I know the question may sound stupid. I’m building an app where there are pages that publish posts and users can subscribe/unsubscribe to those pages.
The goal here is to find a way to send notifications whenever a new post is published but only to the subscribed users. I though that I can do this by sending a push notification to all the devices on my app whenever the “Posts” reference is updated on Firebase database, and then choose whether to show this notification or not if the user is subscribed (on client side)
Is this a good idea? And if yes, how can I accomplish that?
Is this a good idea?
Yes, the idea is not bad. However, filtering notification to be shown in client side is done in many cases.
And if yes, how can I accomplish that?
I hope you already have a login or authentication system using Firebase authentication or any other server side authentication. When you have this, you might have already considered sending a push registration id to your server or firebase when a user signs up in your application and save it in your firebase database.
Now when its time to send a push notification, you are planning to send the push notification to all of your registered devices and you want to filter the notification will be shown or nor in the client side.
This can be achieved by keeping a flag in the client side, for example a SharedPreference having the id or tag of the last post. If you have an incremental id for each post, then it will be a lot easier to implement. When a user launches your application, it pulls the posts from your firebase database as I can think of. Just save the latest id of the post in your SharedPreference and when a push is received, match the id of the post that came along with the push notification with the latest id stored locally.
If the id received via push notification is greater than the id stored in your SharedPreference, you will show the notification in system tray and the notification will not be shown otherwise.
Hope that helps.
You can push notification to only subscribed users if you are maintaining a list of subscribed users FCM token in your database
Your approach is correct, what you would need to do is that maintain different database tables for all pages where users are inserted when they subscribe to that particular group/table.
So, let's suppose when a person subscribes to the page containing information about Sports, you add him to that group. Later, when you are sending update/notifications related to 'Sports' you would only send those push notifications to the user-tokens in 'Sports' table.
In this way, only relevant subscribers would receive those push notifications.

How to send notification from one user to another using firebase?

I am trying to send the notification from one user to another user of the same app.
I am following this article : https://firebase.googleblog.com/2016/08/sending-notifications-between-android.html
Here it takes username and message. But the username is plain name, how it will identify the which device it needs to send the notifications.
Or it is firebase id: FirebaseInstanceId.getInstance().getToken()
Or I have to manage mapping of user to device on the server.
And what is FIREBASE_URL?
The article you read uses FCM topics to identify users. This is a naïve-but-simple way of addressing users. If your needs are more complex, you will need to manage your own mapping of users to tokens on your server.
For an example of using Cloud Functions to send FCM messages to tokens, see this sample in the Firebase documentation.

How to make an user send an invitation to chat to another user in firebase android

I have my list of events in Firebase Database, in a field "interesados", the users who press like buton to that event.
How events are in my DataBase
In Android, I have my RecyclerVview with that list of users, I want my application make the "current user" make an invitation to chat to anyone in the list. (the list of "interesados")
I already have the code in android to chat between users. But What i look for is user1(im logged as users1), after see the list of people interested in that event, make an invitation to user3 to start a chat.
How i send this notification to user3, that user1 want to start a chat: Accept or Decline.
In the list of users, I already the uid(taken from facebook auth), name, etc.
I've been looking for but I only found "Send notificacion to all users from writing especific text in Firebase Notification", but I don't want this.
Maybe I'm looking with a wrong tittle,If so I'd like to know how should I look for.
I think you need to send user targeted push notifications.
You can achieve this in two ways.
Send notification to token: When you receive registration token from GCM server, map it with the corresponding user id in your application server. Say, something like creating an API registerUser(userID, token). Later send notification by calling an API sendNotification(userID). In this API, you simply fetch the token corresponding to that user id and send a notification to that token from your app server. Visit here to setup an android client: https://firebase.google.com/docs/cloud-messaging/android/client
2.Send notification to topic: When you create a firebase user, simply subscribe the user in his UID.
FirebaseMessaging.getInstance().subscribeToTopic(userUID). Later send notification to that user by sending notification to topic(here our topic is the user's UID) method. See this link for topic subscription: https://firebase.google.com/docs/cloud-messaging/android/topic-messaging
The notification sending options, which should be done from your application server, are described here: https://firebase.google.com/docs/cloud-messaging/send-message

Categories

Resources