Reputation: 641
I have a question: I want make a notification in status bar. But when clicking on it, it just clears it and doesn't launch any intent. How can I do this?
Intent intent;
intent= new Intent(myclass.this, myclass.class);
PendingIntent pi = PendingIntent.getActivity(myclass.this, 0, intent, 0);
String body = "This is a test message";
String title = "test msg";
Notification n = new Notification(R.drawable.ic_launcher, body,System.currentTimeMillis());
n.setLatestEventInfo(myclass.this, title, body, pi);
n.defaults = Notification.DEFAULT_ALL;
nm.notify(uniqueID, n);
With this code, when the notification raised and I click on it, the new intent will be created and shown. I don't want to create any new intent. Just clear the notification.
Upvotes: 1
Views: 847
Reputation: 7123
Pass
PendingIntent.getActivity(context, 0, null, PendingIntent. FLAG_ONE_SHOT)
n.flags |= Notification.FLAG_AUTO_CANCEL; // just like that teoRetik says
Upvotes: 1
Reputation: 7916
From the official documentation:
To clear the status bar notification when the user selects it from the notifications window, add the "FLAG_AUTO_CANCEL" flag to your Notification. You can also clear it manually with cancel(int), passing it the notification ID, or clear all your notifications with cancelAll().
Upvotes: 1