I have some code that creates some notifications, it's really basic.
int icon = R.drawable.notification;
CharSequence tickerText = "Text";
long when = System.currentTimeMillis();
Notification notification = new Notification(icon, tickerText, when);
Context context = getApplicationContext();
CharSequence contentTitle = "Text";
CharSequence contentText = "Text";
Intent notificationIntent = new Intent(this, RequestActivity.class);
PendingIntent contentIntent = PendingIntent.getActivity(this, 0, notificationIntent, 0);
notification.setLatestEventInfo(context, contentTitle, contentText, contentIntent);
notification.flags |= Notification.DEFAULT_SOUND;
notification.flags |= Notification.DEFAULT_VIBRATE;
notification.flags |= Notification.DEFAULT_LIGHTS;
notification.flags |= Notification.FLAG_AUTO_CANCEL;
mNotificationManager.notify(notificationID, notification);
It all works fine in 2.1. In 4.0, it all works fine except the swipe-to-dismiss action doesn't work. The notification goes slightly to the side then sticks and bounces back. Any idea? Thanks.
You can't swipe away your notification, because it is in an "ONGOING"-State.
First the solution:
Replace setting flags with following code:
Defaults are for the defaults-section, flags for the flags-section.
And now the reason why it was ongoing?
As you might already know flags (and defaults) for notifications are set by a bitwise operation. Means each flag has a constant value which is a power of 2. Adding them results in an unique number for a set of flags which makes it real fast to calculate which flags are actually set.
Notification.DEFAULT_VIBRATE and Notification.FLAG_ONGOING_EVENT have the same contant value of 2.
Just insert this line when you make the notification...
You should use setOngoing (boolean ongoing)
You can use