I am developing an app to detect all the user actions performed on the screen. So how can I check if the user pulls down the notification bar?
Will this be possible with accessibility service??
As far as i know, there is no proper way to add a callback or any kinds of detection when the notification bar is pulled down.
That is because Android apps are meant to be designed in such a way that the interaction between the notification bar does not affect the functioning of the applications being used in any way.
Related
I'm trying to create a custom notification in my android app with an image that will also be visible when the phone is locked.
Right now, Im building push notifications which are visible on the notification bar only, in which only my app icon is visible and on clicking which a certain pending intent is executed.
Is there a way through which i can show, my notifications with an image and a headline with it and also it gets visible on locked screen .
Also is there any widgets available or particular libraries through which i can implement my custom notifications?
Try using alertdialog with a flag. The flag_show_when_locked is the thing you trying to do I suppose. Please refer to this answer here.
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.
Is it possible to post a notification which if displayed on the lock screen cannot be swiped away by the user, but it can be swiped away if accessed via the notification bar?
(This is for Lollipop)
There isn't such API, so the answer is no, it's not possible.
My app issues multiple notifications that all may have Jelly Bean style actions [1].
It seems that when I issue multiple notifications, only the last one will have action buttons and I cannot figure out why.
I use a custom intent action for the pendingIntents of every notification and action.
Does anybody know how to create two notifications at the same time that both have action buttons visible?
[1] http://developer.android.com/reference/android/app/Notification.Builder.html#addAction(int,%20java.lang.CharSequence,%20android.app.PendingIntent)
Per the Notification's documentation,
A notification's big view appears only when the notification is expanded, which happens when the notification is at the top of the notification drawer, or when the user expands the notification with a gesture
If you have multiple notifications, be sure to expand the lower ones using one of the gestures as explained on the design page for notifications - I expect that they do have the action controls but are just not expanded.
This is an interesting question. Is there a reason you need more than one notification with an action button? Although action buttons are a nice way of connecting "instantly" with an app, they're primarily for use with something that's running even though you want the UI to be minimal. The best example of this is a media player: you don't want to shut it down, but you don't want to force users to go to the app to control play/pause.
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.