take back the Firebase notification on the server side - android

In my web app I notify a group of users using FCM. When the first user reacts to the notification, the others loose the chance to respond (Say it is a game).
I want to take back the sent notification to other users and It is obvious that I can not implement the logic inside the android app (Because only the server knows who won the game).
Is there a way to take back the notification sent using Google Firebase on the server side?

Related

Automatic send Notification triggers in every button clicks

I'm currrently working with an android app that provides news, announcements and events updates.
Now I want to send notifications to all app users that there is a new announcement and when they click it they will go to announcement activity.
This is the announcement activity
This is I add announcement
What I want to achieve is, every time that the user (the one who create the announcement) click the button which is "Upload" it will trigger the app to send notification to all the users of my app. if possible I want it to be automatic no need to go to firebase but if it is impossible I'm okay with anything.
I just need an idea how to make it so I will follow but I would be so happy if someone could provide a sample code.
You should do this on the server side. The service that saves the announcement in the data base, can also send an FCM notification to a topic.
You can use the FCM HTTP V1 API to send notifications.

Can I set the "Difference push receive setting in firebase?"

I am now trying to make a mobile app push notification service on Firebase. But the function description is not quite specific as I expected.
I want to know these functions are available on Firebase. If not, It would be pleasure If you tell me other tool.
User can select the push message types they want to receive.(Ex. Receive sale information push, Do not receive game event push)
Instantly send auto push messages when user triggered certain condition.(Ex. Send appreciate push message when user closed their first app-open)
Thank you
Can not tell in much description here:
1. User can select the push message types they want to receive.(Ex.
Receive sale information push, Do not receive game event push)
You can use FCM's channeling feature,
You can set different channels.
Show the list of channels to user.
User can subscribe to the required channel.
User will receive the specific channel notification only.
Please refer : Notification Channel
2. Instantly send auto push messages when user triggered certain condition.(Ex. Send appreciate push message when user closed their first app-open)
You have manage this thing in your front end and backend logic.
Like on app close send request to the backend (can use onDestroy method )server and then the backend server will send notification.
Hope this will help you.
For Feature 1:
You can achieve this without even doing anything. Just send all notifications to everyone. However, use different Notification Channels. Users, can then choose to turn on/off certain notification channels using the Android system features (in relatively newer versions of android).
Another way could be to send these notifications to different FCM Topics. Give the users a settings pages, where there can select what kinds of notifications they would like to receive. In response to their selections, subscribe or unsubscribe them to the respective FCM Topic.
For Feature 2:
There could be several hundred ways of doing this. Can provide better advice if you could provide more information about your requirement.
If you talk about your example requirement
(Send appreciate push message when user closed their first app-open)
You can do it without any server, or push messaging scheme. Just keep track of the first_open event inside the app using Shared Preferences. Once you detect a first_open event, just compose a notification inside of the app locally, and show it whenever you like.

Firebase push notification vs childAdd listener

I'm working in a friend request module for mobile app base on Firebase so I'm considering to choose the way that notification is pushed.
Assume that userA request to be friend with userB. There're 2 ideas now:
- userA send request to a simple server then it will call FCM to send notification to userB.
- Make a service that listen to data changed in Firebase realtime database then userA will make change on that db and notification will be shown on userB device.
I think both are possible to implement but what is better, and why?
Please give me some advice about this..
Thanks in advance.
Using either one should be fine.
However, a point to consider here is when keeping a listener active for the Real-time database, it also keeps an open socket on the user's device which adds to battery consumption.
While for FCM, it will only trigger once there is a notification is needed to be sent. If a friend request isn't really that app critical, I think using FCM is a way to go.
Have you also considered using both? If the user is currently online, it would be good to use the Real-time DB, but the childAdded won't be triggered if the user is offline (not using the app for instance). In that case, you can set it so that a notification will be sent to the user.
The important thing in your scenario is that the friend request should be saved first in your database or app server, so that it will trigger the corresponding action (FCM notification or Real-time DB update).

Data exchange between two users using Firebase

I am not sure how is this process called. Say I am a user of the app and I want to know if there is a message for me (or a status change that I need to know about), I am not sure if this is the best way but I am trying to do it like this:
Firebase Structure
Users > User A > Status = "No messages"
Each user has a node Status as you can see above.
When user A sends a message to user B, user A changes user B's Status node.
User B, that had been listening to his own Status node, is now aware that there is something new and can go read the message.
Is this possible and safe making use of Firebase only?
On a simpler note, and more often used scenario similar to yours is like a Chat Application. User A sends a message to User B, User B then receives a notification from Firebase.
From what you have described, you intend to have a listener in place for the Status node, and inform the user whenever it changes. This seems okay, but from what was advised to me before, keeping the listener active tends to have a corresponding active socket on Android, which adds to battery consumption.
What I suggest you make use of is firebase-cloud-messaging:
Firebase Cloud Messaging is a component of the Firebase suite of tools for cross-platform application development.
Send unlimited upstream/downstream messages
Send messages to individual devices or a user segment
Handle all aspects of queueing and delivery
Optimize for battery efficiency
Using FCM, you can notify a client app that new email or other data is available to sync. You can send notifications to drive user reengagement and retention. For use cases such as instant messaging, a message can transfer a payload of up to 4KB to a client app.
I think this Firebase Codelab for a Chat App might also be helpful.

seen feature in a android chat application

I am developing a chat application in android in which 2 users chat with each other, it is based on sockets.I want to implement the seen feature just like facebook or whatsapp.
I think may be there is an onfocus method associated with an activity so that whenever user opens the chat activity I can set the latest messages as SEEN in the DB, is there any focus method associated with an activity?
2-Do I have to store messages on local sqlite or on mysql remote database? If I will store on local server, how quickly I have to replicate/update remote DB?
Thanks
In Android the onFocus method you talk about would be onResume(), which is called whenever your Activity goes to the foreground.
Ideally the messages are stored on local database only, there's no point in replicating the messages on a remote server. However this depends on how you want to manage your chat.
Facebook, for example, is obviously server based, meaning that you can see your Facebook messages on any device just by logging in. WhatsApp, on the other hand is client based, and if you buy a new phone and install WhatsApp you don't see previous conversations' messages.
Server based messaging is more complicated because you need to replicate messages, but how often is the wrong question, because it's not time based. As soon as the user connects, you replicate, and store the last n messages locally.
Client based messaging doesn't need replicating, just deliver the messages and you're done. Unless you want a user to be able to send messages when his peer is offline. Then you store the messages in the server, and once the recipient connects, you forward the saved messages and delete them from the server.

Categories

Resources