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.
Related
I am using Firebase with OneSignal within an hybrid application (Android + JS with cordova app). In some cases the user may become offline and online while he is still using the application.
Note that you can't retrieve a push notification if you don't have connectivity.
So my question is, is it possible to retrieve a push notification if the another user sends a push notification while the first user is offline, and later on this first user retrieves the connectivity (As a delayed push notification)?
Thanks!
Internally, OneSignal uses Firebase Messaging Service, so the constraints should be looked for there.
Firebase has 2 types of pushes: notification messages and data messages. That matters if you want to show a notification straight when a push comes, or you'd like to do some additional processing beforehand.
Then, you can configure Firebase to store and resend every message up to 28 days. Of course, losing a network connection for some time does not prevent a message to arrive.
There is another limitation though: up to 100 messages can be stored per client. So, if there are more than a hundred, it's better to re-request the diff.
And then, when the device finally comes back to the network, you should decide if you'd like the notification to come immediately even if the app is already minimized or the device is sleeping. Here is a part about push priorities.
Finally, to be able to work with Firebase on this lower level, you may need to configure OneSignal accordingly. Here is an instruction telling how to work with the background notifications, if you need them.
I have an app with different notification types it can receive (for example News and Podcast). Currently it has two simple switches where the user can enable and disable those different notification types. It works by just subscribing and unsubscribing from the corresponding Firebase Topic for the type. The clear advantage is that the device only receives the notification the user wants and does not have to filter them locally => battery and data efficient.
Problem is, I want to combine it with the new android O notification channels. Am I right to assume that the only way is to just subscribe to all topics in Firebase and have the user manually disable unwanted ones in the android settings?
Is there a better way that saves more battery life (by not receiving all notifications)?
The Notification Channel (a feature only needed for Android O -- presumably onwards) is (like) a parameter that you would (typically) use to sort/manage the notifications you build locally. --
Android O introduces notification channels to provide a unified system to help users manage notifications.
It doesn't necessarily disable receiving the notifications that you don't want to receive, but (AFAIK) notifications built without the Notification Channel won't show up/display in Android O (not received != not displayed). i.e. Your device may actually still be receiving the notifications, but just isn't displayed.
For Notifications sent through topics, so long as the corresponding registration token is subscribed, it is the expected behavior that the client would handle it accordingly.
With all that said, what you already have implemented (if I understand your post correctly -- subscribe and unsubscribe to topics based on a switch of some sort) is already the simplest as it could get.
If you want to totally disable notifications completely, you could call deleteInstanceId(). See my answers here and here for some additional info.
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.
In my delphi code app, Is possible I change the settings of my pending intent used to handle push notifications when It arrives? I´d like to change your behaviour. Instead I have many push icons notifiactions on status bar when each new push messages arrive, I´d like to have only one with a counter increasing when new push messsages arrive. I´d like something as https://developer.android.com/training/wearables/notifications/stacks.html
Luiz
You can implement the logic you want.
When you receive a push, it carries various data.
If a notification is already displaying such data, you can cancel the existing notification and create a new one.
In any way, the notification manager of android will be able to stack notifications by itself for you.
So i suggest, when you receive data from a push:
Store it to sqlite
Calculate the notification ID you need to display that notification (can be a hashCode of the notification type ?)
Fetch all notif for that type from sqlite
Cancel the notification with this ID (don't worry, cancelling a non existing notification won't make your app crash)
Create a shiny new notification with all the data you fetched, if you have more than one, you might want to display "+X other".
EDIT: With my answer, i assumed you can do as much as thing in "delphi to android" than in native android. Hence, i can't provide code for you, but the idea does not depend of the language you are using.
So, whenever someone creates a Post, I want others notified. Hence, I send out a Notification.
I know the logistics of setting the number with setNumber(int num), and how to create an InboxStyle to display multiple posts.
The problem is if a new notification comes in, it has no knowledge of whether or not another notification exists. I can't just request that Notification by its notification_id that I assigned it and then append a String with addLine(String string), nor can I update the number of posts with the setNumber method above. I'm new to creating Notifications and I've been reading about InboxStyle, using it, but every guide leaves out how to keep in sync with if that notification is still up, and how to update it. They brush that off as a trivial matter.
Yes, I understand a Notification can be updated via the NotificationManager.notify(int, notification) method, but unless you recreate what the new notification will look like, it simply overwrites your current notification.
Is there something I'm missing or not understanding about how to simply update notifications?
You should not be trying to "keep in sync with if that notification is still up". Your Notification should reflect the contents of your data model, and it should be updated when the data model changes.
For example, suppose you are writing an email client. You want a Notification for unread messages. When there are no unread messages, you have no Notification. When your background logic retrieves new messages, you update your data store to reflect those messages, and you call some heyLetTheUserKnowBoutDemEmails() method. That method queries the data store, finds out how many unseen messages there are, and calls notify() on NotificationManager to post a suitable Notification, using setNumber(), addLine(), and so forth, based on what is in the data store. Whether or not there happens to already be a Notification, for some previous heyLetTheUserKnowBoutDemEmails() call, is immaterial. When the user responds to the Notification, or otherwise opens up the inbox, your UI would then update the data store to mark the messages as seen (i.e., no longer need to be notified about) and clears the Notification. Lather, rinse, repeat.
So, it's not so much that it is a "trivial matter", but that:
It is merely a matter of replacing the existing Notification, and
The rules for when you should replace the existing Notification are almost completely dependent upon your app and its business rules, which are outside the scope of Android documentation and many blog posts, Stack Overflow answers, and the like.