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
Related
I'm developing an application for my College:
Users (students) login on it with their college credentials, once they are authenticated, the app creates a Firebase Database data for that user containing al his info, including the disciplines(subjects) that he is on course.
Then comes the Firebase Cloud Messaging part, the users can send notifications for other users that are on the same disciplines.
Example: I'm coursing Math, then can I send a notification to the others users that are also doing Math. There are hundreds of disciplines in my College.
My idea is to send the notification to all of my app's users then, before notifying, handle with some code to check if the user is registered to the notification's target discipline or not, if he is, send notification, else, do not send anything, in others words, filter the message before showing the notification!
I studied several Firebase Cloud Messaging docs and examples but I couldn't find a way how to do it... Can somebody give a light?
Yes, actually, it'd be best to decide server-side on the group of users that will receive the notification, meaning, you need to have them in some sort of group. Firebase has a concept of group and subscription for messaging. And you can setup a cloud function to actually send the message to the clients
https://firebase.google.com/docs/cloud-messaging/js/send-multiple
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.
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 .
I want to build an Android app that allows a user to send notification and data messages to other users. I've started using Firebase only recently, and Firebase Cloud Messaging is still pretty confusing to me.
I have already implemented sending a message to a specific device using the Firebase Instance Id. However, in my app, a user can log out and log into their accounts using different devices, so this isn't really what I want. I read the documentation and it's pretty confusing, they mention sending messages to user groups, and topics (which only apps can subscribe to, not users).
Is there a way to send a push notification directly to another user or a group of users using only their UIDs? If not, is there any other way I can implement this?
I did it storing the FCM Token in a device structure by user. When the user login, add the deviceData to the userToken structure. You need clear deviceData when the user logout. This way, you will only send notifications to logged devices.
Ex (This is not like mine structure, but it can help you to wondering a good way to do this):
-userToken
-idUser1
-device
-idDevice1
-fcmToken: "xxxxx"
-idDevice2
-fcmToken: "YYYYY"
Hope that I helped you
Alright, so to make sure this works across multiple devices when a user logs in, I just make the device subscribe to a topic with the name equal to the user's UID. Now if I want to send a notification to a user, I just send an FCM message on the topic with the name equal to the user's UID!
Example: If my UID is equal to "asdf", whenever I login using multiple devices, each of the devices automatically subscribes to the topic with name "asdf". So now, if I send an FCM from the server on this topic, all the devices from which I am logged on to obtain this notification.
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