How to silently add a notification? - android

I'd like to selectively hide and show a notification based on what a user does.
Since that would happen pretty often, I'd like to have it appear in the notification dropdown without having the text message appear in the status bar every time I show it.
Task manager does it when I toggle it in its preference screen.

When you create the Notification object, pass null for the ticker text.
Notification n = new Notification(R.drawable.icon, null, System.currentTimeMillis());

Related

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);

Switching Android notification from FLAG_ONGOING_EVENT to cancelable

I have an ongoing task and after it finishes, I want the notification to become cancelable.
For that, I create a new notification with notification.flags as zero, but the notification keeps being un-cancelable.
Apparently, FLAG_FOREGROUND_SERVICE prevented the notification from turning into cancelable, even after reseting the flags.
After removing FLAG_FOREGROUND_SERVICE and using only 0 or FLAG_ONGOING_EVENT, the notification could be made cancelable or un-cancelable - respectively.
Please take a look here : Android update notification
In short what you will do is this:
Create your notification first time and assign a notification ID to it.
Once your service is done executing create a new cancelable notification with the same id
fire that notification, it should make the previous notification cancelable .

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;

Create notification without it popping up

I'm trying to add an android notification to the "tray" in android 3, but I don't want it to "pop up" every time I call notify().
I managed to kind of do this by setting the FLAG_ONLY_ALERT_ONCE flag on the notification, but it will still alert when I set it for the first time.
It seems like this is possible, but I'm not sure how to do this (an example is the Prime ROM for the Asus transformer. When you plug in the dock, a new ongoing notification will be added to the notification area, but there is no alert, or "popup" there.. It just adds another icon to the list quietly. How can I do the same?
Just set the tickerText to null. You can do this when creating your notification with:
Notification notification = new Notification( R.drawable.icon, null, System.currentTimeMillis());

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