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.
Related
As per Android docs for setFullScreenIntent:
An intent to launch instead of posting the notification to the status bar.
Reality: Fullscreen intent is launched....but notification also gets posted to the status bar.
The screen is locked, so the user is not using the device.
val builder = NotificationCompat.Builder(this, CHANNEL_ID)
.setSmallIcon(android.R.drawable.ic_lock_idle_alarm)
.setContentTitle(timer.title)
.setContentText("Description!")
.setPriority(NotificationCompat.PRIORITY_HIGH)
.setCategory(NotificationCompat.CATEGORY_REMINDER)
.setFullScreenIntent(pendingIntent, true) // tried with false too.
Any ideas why this doesn't work according to the docs?
I know I can remove the notification after it appears but the docs mention clearly that it should not appear.
This is reproducible both on a real device (Android 11) and on an emulator (Android 12).
I also notice the same thing with some other apps from the Play Store. They seem to use such notification (I can't know for sure but they appear on the lockscreen as fullscreen at least).
imho thats some old mistake in docs. I've never read this methods doc so carefully, but my experience says that full screen intent was/is always show Activity ADDITIONALLY to always-present notification. or will not, then freshly posted notification will appear as heads up, e.g. when user is using unlocked device at the moment of notification posting
also docs shows some use cases for such feature
Only for use with extremely high-priority notifications demanding the user's immediate attention, such as an incoming phone call or alarm clock
considering call: user didn't make any touch in GUI, instead just pressed home. Phone is ringing, how to close/reject/get back to managing Activity without Notification left? such Activity won't stay in recents history (noHistory), you may even press this home button accidentally and you don't even know in which app looking for sound source
imho this notification should also appear with started Activity, just like it happens. It isn't even visible on screen when user starts to use your extremely high-priority Activity. When job is done and Activity is finishing then Notification may also disappear, but when user won't take any decision and it is still crucial to pick some option - he need a fast option to get back to (even accidentally) "homed"/closed Activity
is it possible to have notifications pop up, make a sound and be shortly visible at the top of the screen but not be logged via the notification center?
My idea is to have the user be notified of any important actions. But while the user is inside the app the notifications should not pool up inside the notification center. When the user is not actively using the app I will start a background service with a websocket and get further notifications for the user to be shown via the notification center.
So it it possible to differentiate between the two types. Similar to what whatsapp is doing?
One way to achieve the desired effect seems to be to just cancel the notification by ID once it has been passed to the notification manager:
https://developer.android.com/reference/android/app/NotificationManager#cancel(int)
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.
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.
I m a newbie to android development and i wanna know a right way to get notification as an activity instead of statusbar notification.
To be clear, i wanna display an notification on screen instead of adding it to status bar.
In that case you shouldn't call it notification. In Android, a notification is something that ends up in the status bar and that the user can deal with at her own leisure.
An activity will take over the complete screen and force the user to deal with it immediately. That is very intrusive and users will likely get annoyed, unless the information you show is really crucial.
The correct behaviour is to post a notification and bring up your activity when the user clicks on the notification, very much like your messaging client or email client.
Other options are bringing up a dialogue or a toaster message. A dialogue is a message the user will have to interact with to go away, whereas a toaster message will be visible for a short time and then automatically disappear.
Maybe you could be a bit more specific about what sort of information you want to provide to the user?
Surely you can be helped out.
I feel that you are getting notifications from a web service as a response to some request, right?
If yes, then you can display them in a custom made dialog box, or inside an activity whose theme has been set as DIALOG.
maybe I got your question wrong, maybe your talking about the notifications about networks, calls and things.
If its so, correct me.
Thanks!
Android 2.3 introduced a new field on Notification, fullScreenIntent, for exactly this purpose. Place a PendingIntent here that will trigger whatever activity you'd like to display, and the user will be sent to that activity (whether full-screen or dialog-themed) in addition to receiving the usual notification icon in the status bar. As of Gingerbread, this is how the Phone app implements the incoming call screen.