I want to be able to programmatically check if there are any notifications present (preferably only non-permanent notifications) in the status bar. This should include all notifications and not just ones created by my app. I don't need information about the specific notifications or even the total number, I just want to know IF there are notifications being displayed in the status bar currently or not.
I have researched and found that I'm likely going to have to deal with the accessibility service. That's fine, but so far I haven't found a solution to check for current notifications, all solutions so far only show how to detect NEW notifications. I want to be able to query at any instant and check for presence of notifications.
One (ugly) option would be to constantly keep track of all new notifications and clearing of notifications, but I fear this may not be reliable. I want to know if there any simpler or cleaner methods.
Any guidance will be really helpful.
Related
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.
I'd like my android auto notification to not have any reply mechanism to it. I just want a notification that you can swipe to dismiss, but the only two options i see for android auto are messaging and audio. The messaging makes the notification have a reply to it like this:
notice how there is a microphone for user to reply. I dont want that on my notification. I only want to display info but no reply mechanism. I am not interested in reply, only to notify user of something. i want it to look like this instead but it seems only system has this kinds of notifications.
Android Auto has defined guidelines for Messaging Apps.
It didn't consider normal notifications as a scenario that needs to be addressed now in Auto environment.
We can hope it may be made more flexible on future along with measures to make sure that distraction is avoided by strict certification process.
So the answer to your question is - Not possible now.
Background
Android Lollipop (API 21) introduced a way to show notifications outside of the status bar (AKA "notifications bar"), so that the user can handle them right away. It's called "Heads-up notifications".
The trigger for showing them may vary between devices/roms/manufacturers.
The problem
Sometimes, showing such notifications can annoy users, and most of the times there are no settings for those cases.
If the user dismisses heads-up notifications, they won't show as a normal notification. There is no way to hide them and continue with what's on the screen. You can only wait (and it's quite a long time of waiting too).
In fact, there are multiple Google-Group issues that were opened about it, just because it can annoy people (link here and here).
What I've found
Starting with API 18, it is possible to listen to notifications events and even read them, by using "NotificationListenerService" and "StatusBarNotification" , and maybe other classes.
However, other than dismissing notifications (of other apps), I can't find any other action that can be done to them.
The question
Is it possible that in the lifetime of my app, I will be able to listen to notifications that are shown as heads-up, and put them back as a status-bar notifications?
Maybe even set a different timeout for them? or choose to convert them to normal status-bar notifications when they get dismissed?
Maybe before even doing those operations, I should ask: how can I know if a notification that I've found (of other apps) is showing as a heads-up notification ?
I don't know how to do implement this. But answering the "Is it possible that...?" question, yes, there are apps like this one that block/only show notifications in the notification bar.
With the new NotificationListenerService introduced in 4.3, it's possible to query all currenty active notifications using NotificationListenerService.getActiveNotifications(). Is something similar possible with the AccessibilityService? I wouldn't mind keeping track of them myself (store them temporarily once a new notification comes in), but it seems that there's no "onRemoved"-event for the AccessibilityService, so it's impossible to keep track of which notifications are still active and which have already been dismissed?
Apparently this isn't possible on pre-4.3. I've resorted to storing the notifications locally as they come in, but this isn't a very good approach since there's no way to tell when a notification was removed.
I am writing an application where I am pushing notifications to the client from the server. If server pushes many notification messages to the user, I see that there are multiple app notification icons in the notification bar(where there are other icons such as battery, connectivity etc) are displayed.
I want to limit it one but I still want to retain notifications in the notification drawer(in pull down pane).
I tried canceling notificationManager.cancel(int id), but it removes notification from the the notification drawer along with notification bar. Is there any extra flag or any api to get around this?
Thanks
You can update the notification content. Here are the docs to do it http://developer.android.com/guide/topics/ui/notifiers/notifications.html#Updating
This is what the SMS/Whatsapp/gmail does. If there's only one message, they display it's content, otherwise they would display the amount of unread messages and or the number of people who wrote them. The point is that they only have one notification on the status bar, and they keep using the same one until the user goes in the app.
As has been pointed out, this is strictly speaking against the android design guidelines. However guidelines are not always right in every situation, and it seems to me that may be possible to do this, at least for some versions of Android.
In 4.4 and 6.0 (I didn't test other versions) some testing seems to indicate that if the notification priority is set to PRIORITY_MIN then the icon will not appear in the notification bar but it will appear in the drawer.
I do not know whether this behaviour is guaranteed though and the docs seem a bit vague. There is also an annoying consequence that the position of the notification in the drawer is affected by this, so this answer is not at all ideal.
I wish there were a better solution for people who actively choose to not follow the guidelines because of specific design requirements.