In my application I’m displaying notification text and icon on the notification bar but my problem is that when the user presses clear on the notification bar it gets cleared. I want to prevent it!? And some other issues too:
- I want to create notifications for my application by different activities, say one on start it displays “Welcome to app”, the second activity displays “please select”, in “Data send activity” it displays “Records sent successfully”!!
- How to remove the notification on application exit.
- How to disable users to clear the notification when they press the clear button on the notification bar
- How to remove a notification from the status bar when the user presses it to open an activity?
Any help?
My current code
private void Notification(String notificationTickerText, String Title,
String text, Notification nt) {
notificationManager = (NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE);
int icon = R.drawable.nicon;
CharSequence tickerText = notificationTickerText;
long when = System.currentTimeMillis();
nt = new Notification(icon, tickerText, when);
Context context = getApplicationContext();
CharSequence contentTitle = Title;
CharSequence contentText = text;
Intent notificationIntent = new Intent(this, frmLogin.class);
PendingIntent contentIntent = PendingIntent.getActivity(this, 0,
notificationIntent, 0);
nt.setLatestEventInfo(context, contentTitle, contentText, contentIntent);
notificationManager.notify(1, nt);
}
If you read http://developer.android.com/guide/topics/ui/notifiers/notifications.html that will probably answer all your questions.
It mentions that you can use the following to prevent a notification from being cleared:
You can use the FLAG_AUTO_CANCEL to cancel your notifications, but I’m not entirely sure if that will work when combined with FLAG_NO_CLEAR. If it doesn’t you’ll have to cancel the notification manually.