Clearing Notifications - android

I am making a chat application, I have requirement when the User is logged out of the application, then all the notifications of my application should be removed from the notification bar.
Is it possible??
Thanks

I believe this would do the trick:
http://developer.android.com/reference/android/app/NotificationManager.html#cancelAll()
Or you can cancel them by ID also:
http://developer.android.com/reference/android/app/NotificationManager.html#cancel(int)

Yes, use NotificationManager.cancelAll()
http://developer.android.com/reference/android/app/NotificationManager.html#cancelAll()

Yes,Take a look here:
Remove the notification icon from the status bar
You only need to provide your notification id; to remove only the notifications of your aplication.
When the user logged out or the activity goes to onPause() or onStop() (Depends of your necessity) you use:
public void cancel (String tag, int id)
Cancel a previously shown notification. If it's transient, the view will be hidden. If it's persistent, it will be removed from the status bar.

Related

How to remove an ongoing notification programmatically?

I want to remove the ongoing notification from statusbar.For example whatsapp web notification when whatsapp web is active,usb debugging notification when device is connected to pc which are not removed when swipe.Is it possible or not?If its possible then please help me.Thank u.....
Yes, you can dismiss a notification from statusbar. Just call cancel() for your notification ID.
Check out this link to learn more about removing Notifications: https://developer.android.com/guide/topics/ui/notifiers/notifications.html#Removing
If you are hiding only the notification icon on the notification bar (glance view without pulling down the slide bar to see the whole on going notifications), and its notif view still in the on going list, you can pay attention to the method setPriority of NotificationCompat.Builder.
In my case,the codeblock below saved my day!
NotificationCompat.Builder mBuilderOnGoing = new NotificationCompat.Builder(mContext);
if (Build.VERSION.SDK_INT >=16) {
mBuilderOnGoing.setPriority(NotificationCompat.PRIORITY_MIN);
}
Hope it helps

is there any listener after performing clear notification in android?

Basicly I want to do something after the user clear my notification from the top bar, How do I do that in andorid programmatically?
Basic example or complete code would be nice thanks.
When you create a Notification,setDeleteIntent ,Here is the api:
setDeleteIntent(PendingIntent intent)
Supply a PendingIntent to send when the notification is cleared explicitly by the user.

Is it possible to remove/cancel a notification after the user sees it?

I am currently making an application that uses Notifications.
I was able to display the notifications, and remove them from the notification list when the user taps them. However, I would also like my notifications to disappear if the user sees them but does not act on them.
For instance, the user displays the notification list, then taps on a notification that is not mine, or just closes the notification list. During those cases, I am trying to make my notifications get canceled and not displayed the next time the user displays the notification list even if he did not do anything to my notification.
Is this possible?
Thanks! :D
(edit: if you are wondering why I thought of this, a very simplified explanation would be: think of the notification as a toast instead; a toast that has a longer existence, and makes sure that the user actually saw it before disappearing.)
you may remove a notification by providing its id to the cancel method:
((NotificationManager) getSystemService(NOTIFICATION_SERVICE)).cancel(your_notification);
however, i wouldn't recommend you to do it as it may confuse the user
It is very easy, there is a cancel method for notifications:
public void cancel (int id)
Cancel a previously shown notification. If it's transient, the view will be hidden. If it's persistent, it will be removed from the status bar.
public void cancel (String tag, int id)
Cancel a previously shown notification. If it's transient, the view will be hidden. If it's persistent, it will be removed from the status bar.
public void cancelAll ()
Cancel all previously shown notifications. See cancel(int) for the detailed behavior.
Details are here:
http://developer.android.com/reference/android/app/NotificationManager.html#cancel(int)
Update
If you want to cancel your notification when user sees that notification, there is a flag for that, FLAG_AUTO_CANCEL:
Notification notification1 = new Notification(R.drawable.icon, "test",
System.currentTimeMillis());
notification1.flags |= Notification.FLAG_AUTO_CANCEL;

Android: static status bar notification

How to create a static status bar notification? Like in skype app or others...
It must be visible while app is running, even if it runs in background.
Create a notification and include FLAG_ONGOING_EVENT in the set of flags. Note that when your application is finished, you should cancel the notification.
http://developer.android.com/guide/topics/ui/notifiers/notifications.html

Make a notification dessapear from Status Bar

I was able to send a notification to the Android emulator. When I click on it, the activity opens. But the notification alone remains in status bar. Normally, when you get sms/notifications and click on them, you go to the particular activity and when you expand the status bar, you don't see the notifications, on which you have already clicked.
So, my question is - how can I make the notification dissapear after clicking on it? Is there a special function for this? Thanks.
Add Notification.FLAG_AUTO_CANCEL to the notification when you create it.
To clear the status bar notification when the user selects it from the Notifications window, add the "FLAG_AUTO_CANCEL" flag to your Notification object. You can also clear it manually with cancel(int), passing it the notification ID, or clear all your Notifications with cancelAll().
Reference - http://developer.android.com/guide/topics/ui/notifiers/notifications.html

Categories

Resources