How to remove an ongoing notification programmatically? - android

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

Related

Custom Notification Manager

I can't remove my app notification from notification bar by sliding/swiping or with default "clear all" option in android.
I got .setAutoCancel(true) in code as well.
But it seems that doesn't work.
anyway to make it removable by swiping like I can do on other app notification. Mine just stuck there.
I know the cancel() and cancelAll(), and giving an intent method to remove by touch (from other stackflow posts).
I just found an help in another stackflow post..(was opposite of my requirement).
For me, I needed to make false in ongoing
nBuilder.setOngoing(false);
where, nBuilder is my Notification.builder

How do I display hidden notifications?

I am developing a simple app that starts a service when a button is tapped... The service create an ongoing notification but I don't want it to display any icon in the status bar...
In this picture you can see WiFi ADB has a standard ongoing notification that cannot be dismissed...
Google Now (The 62 Cloudy), Automatic, and Automate do not display any icon when the notification bar is closed and they are in a separate group (under that grey line).
I looked everywhere for how to achieve that but can't find anything... Even the Android documentation which is usually quite exhaustive doesn't provide any information about it.
EDIT:
Right now this is how I display my notification:
Notification notification = new NotificationCompat.Builder(this)
.setContentTitle("Power Napp")
.setContentText("Napping...")
.setSmallIcon(R.drawable.ic_notification)
.setContentIntent(pendingIntent)
.setOngoing(true)
.build();
There's a simple trick. Add:
.setPriority(Notification.PRIORITY_MIN)
And the notification won't show the icon in the status bar.
http://developer.android.com/reference/android/app/Notification.html#PRIORITY_MIN
isn't very clear about this but it's documented here:
http://developer.android.com/design/patterns/notifications.html#correctly_set_and_manage_notification_priority

I am getting pushwoosh response null

I have integrated pushwoosh in android application (not in titanium)..
I am successfully getting notification also..
My issue is,
Text is displayed on notification area which I passed from woosh..
BUT NOT ABLE to extract it from intent
intent.getExtras().getString(PushManager.PUSH_RECEIVE_EVENT)
Also my notification does not remain on notification area..
it only displayed once and disappear, I am not able to click on that
because it is not staying there..as like other notification..!!??
Please can anybody suggest any thing..?
For notification to remain on the notification bar there is falg to set in Android Notification.
Notification not= new Notification(R.drawable.icon,title+" "+context.getString(R.string.Start_in),System.currentTimeMillis());
not.flags=Notification.FLAG_NO_CLEAR;
For Android Notification there is One falg to Clear the notification or not. So I think there will some flag to Not clear the Notification when it arrives.
So Try to find out the flag for not clearing the Notification.
As you are setting flag for sound
pushManager.setSoundNotificationType(SoundType.ALWAYS);

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;

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