Remove firebase notification from android device (sever side) - android

I am using firebase for notification. I want to send notification to the group of users... If any one of them press accept notification action button then, the same notification must be remove from the other users device. Is it possible to do using firebase.
Ex. I want to send notification to 5 delivery boys for collecting parcel from XYZ place, if any of them accept the collecting parcel order notification then the same notification must be remove from other 4 delivery boys autometically.
I study and practically done an example of https://firebase.google.com/docs/cloud-messaging/android/device-group Notification send to all 5 del. boys but notification still there after accepting the collecting order.
Please, help.

Firebase Cloud Messaging has two distinct types of messages:
Notification messages that are handled and displayed by the OS when the app is not active, and handled by your application code when the app is active.
Data messages that are always handled by your application code, which can then choose to display or update UI notifications as needed.
What you're describing sounds like you want to use data messages only, and then use Android's notification UI/API to display, update, or hide a notification.

Related

Send request to an other android device in a app

I am currently trying to make a personal location application between 2 devices on Android.
The concept is simple: I install my application on my phone as well as on that of my wife and each can geolocate the other.
(This application is strictly personal)
To achieve this, I thought of using sending notifications by FCM.
Telephone A sends a request to telephone B which listens via a service for the reception of a message.
When phone B receives the request, it returns the GPS coordinates via FCM so that phone A displays them on a MAP.
(I also have the possibility to store the coordinates in a database instead of sending back an FCM message)
But FCM's documentation says:
"When your app is in the background, notification messages are displayed in the system tray, and onMessageReceived is not called. For notification messages with a data payload, the notification message is displayed in the system tray, and the data that was included with the notification message can be retrieved from the intent launched when the user taps on the notification."
Of course, this reduces the scope since it forces the user of the phone receiving the notification to click on it to activate the actions of the service.
Can FCM still meet my needs through another channel?
Are there other options to send a "request" to another phone?
(I know that this kind of application exists on the PlayStore, but I want to try to make mine :-))
The key word in that section from the documentation you quote is notification messages. Firebase Cloud Messaging supports two types of messages:
Notification messages, which are display by the system when the app is inactive - and delivered to your application code when the app is active.
Data messages, which are always delivered to your application code.
It sounds like you'll want to use data messages for this use-case

Schedule a Notification after app was closed for 5 days

I want to send the "We miss you" notification to the users who haven't user my app in more than 5 days. Can this be done with Firebase notifications?
I haven't noticed any options when creating a new notification that can see if the app wasn't used or anything similar, so I'm wondering is it possible to retrieve the timestamp of when the app was last accessed and schedule a notification (maybe locally?) using the said timestamp?
You can use implement ActivityLifecycleCallbacks.To know how to implement refer -Automatically log Android lifecycle events using ActivityLifecycleCallbacks?
Once you implement ActivityLifecycleCallbacks you will get callback whenever any of the activity is interacted by the user.
You can send this timestamp to the server everytime user interacts with your app.
The server can maintain 5 min timeout logice and send a push notification to the device.
On receiving the push notification your app can show notification to the user.

Know if the app received the notification from server side

I'm building a newspaper-like app and I would like to know how many people received the article's push notification vs how many actually read it.
I was thinking to implement a way in which when the notification is received the app wakes up and send a request to the server saying "Hi I'm _____, I've received the notification of the article ____" and store it in the database. Then afterwards if the user click on the notification and goes to read the article I send another request saying "Hi I'm ____ and I've read the article _____" and I also store it on the database. Afterwards with some queries I'm able to understand the percentage read/received.
I don't understand if it's even possible to wake up the app even if it was not opened by the user in a while and send a request to the server (for background is meant that the application is not launched or that is in the cache ?).
I would like to achieve what they did with Whatsapp:
I receive a new message on Whatsapp
I don't open the app
I go to WhatsApp Web
I open the conversation on WhatsApp Web
The badge and the notification on the phone goes away because I read it somewhere else
I think that that feature is achieved with silent push notifications that just update the app badge and clear the read notification.
Thats a very nice question on how to implement such silent notifications. There are few variables here that we need to consider and deal them in a different way.
Push notifications sent to the users - Some of them would have received it, Some may not have received it at all.
Pushing multiple notifications to the same user in a small amount of time - It becomes difficult here to track the exact notification user opened the app. Because user might have read all the news that received notifications in a single attempt.
The actual content displayed to the user in the app - User might have opened the app because of notifications. Some times he might have seen the notifications and then opened the app directly without interacting with the notifications.
So this is how the implementation can be.
Implement push notifications for the app
User receives the push notifications and the notification badge shows Number (1).
Now when the user views the same news story in any other medium (Your own Mac App or PC app). Server is notified of the users action and the news he/she/whoever just read.
Now the server knows it has sent a notification and it is not read. When you receive the read notification, you can send a remote notification that can be handled by the app in background and update the badge.
Check out this link for more details on how to handle notifications in various modes.
Apple documentation also can be referred here for background mode - remote-notification.
So you will be making your app run in background with certain settings to respond to silent notifications and update the badge just like WhatsApp. I hope this helps.
I've already implemented such thing in one of my app, and it's actually tricky.
You'll have a lot of use cases to handle.
First thing (but you seem to already know it): Apple does not provide
any callback to say : "this notification was sent"
Second thing : when your app is killed (not even in background), nothing at all can be done with your notification, meaning your app won't be able to wake up and read the notification, and therefor do something. The only thing you can do is changing the badge number, even if your app is killed.
Third thing : when your app is in background, you can wake up your app during 30sec. During that time you can send a request to the server, but if it takes too long, the process will be killed by the OS.
Saying that, here is a quick explanation of how you could implement the system:
You'll need on the server side to save in your data base any notifications that were sent. As soon as they are sent, save them as "pending"
On the app side: if your app is in background, as soon as the notification is received, you can wake up your app to send a request to the server. Then in your data base, your notification status will change to "receive" or "notified". If your app was killed, when the user launch your app, send a request to the server to ask for all notification in "pending" state, that way your app will be up to date, as well as your badge number.
If the user click on the notification, this will open your app directly on the article, that way you'll be able to send a request and say to your server that the article was received and read.
If the user read your article on the web side, send a notification. Set the notification badge number with the number of actual "pending" notification in your data base.
Hope this will help you in addition of the answer of #Prav :)
try this Notification Listner service https://github.com/kpbird/NotificationListenerService-Example.
Reply from Apple Developer Technical Support:
Hello Matteo,
Thank you for contacting Apple Developer Technical Support (DTS). Our engineers have reviewed your request and have concluded that there is no supported way to achieve the desired functionality given the currently shipping system configurations.
So at the end of the games IT'S NOT POSSIBLE
You want to sync your app with web app or website than once you send notification to application than set notification to particular ID.If user read that message from your web then send push notification again with different message and handle in service or broadcast receiver after that cancel notification if received message contains different message.you can also use Notification Listener.Refer thislink
Refer this link for ios.
Hi #Smile Applications after reading your question I would suggest you see OneSignal website. OneSignal will allow you to send notifications to your subscribed users. It will also show you how many users are using your app and how many of them have received your notifications. If you want to send notifications and track them from the app itself you can use their API. It is easy and I have implemented this in Android and soon will be implementing in IOS.
Now the second part of your question about knowing how to track how many users have read/opened your notification and on which activity they are on you can use Google Analytics. It will allow you to see from which part of the world your users are using your app and which activities of your app are being opened most. It is also easy and I have implemented this also in Android and soon will be implementing in IOS too.

How to Combine N Number of Related Android Push Notifications

I have been reading many posts/articles/tutorials I can find about updating an active notification. I fear I may have a fundamental misunderstanding about how one may update an Android push notification.
So far: I can update an active notification based on its ID, and I haven't been able to get any results out of Builder.setGroup()
My problem: When I update an active (not dismissed) notification, I want to be able to get the text from the previous, active notification, parse and add the new notification text and update it.
I'm starting to think that this might not be possible without a local DB and that my approach to this problem is no good.
Is there a way to get the content of the last notification (or one with a specific ID)?
EDIT: It seems to me that many of the examples I have seen are grouping a number of notifications all at once rather than successively.
Example
This is an example of what I want to do. The scenario I'm imagining is like this:
The owner of the device gets a notification that he/she has a new message from 'Alex Faaborg'. (See image)
The notification is not dismissed by the device owner
Another notification regarding a new message from 'Jeff Chang' comes in
Get 'Alex Faarborg's' name from the first notification, and 'Jeff Chang' from the second
Parse the info and display a summary of their notifications rather than have multiple notifications build up
4 is what I'd like to do
OK, so I realized I could do what I need to do to combine notifications by keeping track of users' unread messages(or invites etc..) on the backend, then if there's more than one, it will send out a summary of the notifications rather than each individually. On the client, this will overwrite any previous, related notifications (kept track with a JSON field sent to GCM (and subsequently, the client) that represents the 'topic' of the notification)
For whatever reason, I thought I should handle the grouping/summarizing of notifications on the client. I think the API is the way to go.

What is the difference of "Notification" and "Push Notification" in Android

I want to use Notification in my Android app but I don't know what is the difference between Notification and Push Notification in Android.
I searched the web about this title but all of them talk about differences in apple products.
Can anyone remark where I should use Notification and where I should use Push Notification?
The main difference between push notification and notification is that the latter are created internally from an application on the device that wants to show user some information, a reminder, some news or updates, and so on. Push notification are "messages" sent from outside the device, for example a server, that triggers an application of the device (which usually handle the incoming message and transform it in a "normal" notification to be displays in the system tray). This is usually made through a public service such as Firebase Cloud Message ( https://firebase.google.com/docs/cloud-messaging/ ) of Google or a proprietary service such as the one that is used by the most common chatting application (Whatsapp, Telegram, ...) .
Indeed the most common example of push notification is the whatsapp notification of new messages that shows up in your phone when another user has sent you a message (so the message comes from outside your phone). Instead, the basic example for normal notifications are the alarm's notifications or the calendar's notifications.
Notification: When notifies you about the same application state, example: In a game application: "You have 10 days trial, or a product that provides the application".
Push Notification: When notifies you in real time about events related to users, eg solical In an application, "A message from a friend, a new invitation, an event".

Categories

Resources