Reputation: 57
I have here a code by which a broadcast receiver will toast. However this is not my concern, I would want to know how to(inside) the broadcast receiver class to get the notification and dismiss it while writing the addaction code in the original class, in the addAction method would I specify what notification is being passed? I am lost there I only know the code for the toast I'm showing here.....how would I pass info to dismiss the notification on the broadcast receiver, thanks or if there is a post regarding this can you link it I couldn't find any.
.addAction(android.R.drawable.ic_menu_close_clear_cancel,"Close",PendingIntent.getBroadcast(
this,
0,
new Intent(getString(R.string.notification_broadcast))
.putExtra(NotificationAssignment.TOAST_TEXT,
"Why would you Toast on a notification???"),
PendingIntent.FLAG_UPDATE_CURRENT)))
Upvotes: 0
Views: 1475
Reputation: 6409
When you show the notification, assign it an ID. Then in your broadcast receiver, dismiss it using the same ID.
In res/
somewhere:
<item name="notification.blah" type="id" />
In wherever you show your notification:
nm.notify(R.id.notification_blah, notification);
In your receiver:
NotificationManager nm = context.getSystemService(Context.NOTIFICATION_MANAGER);
nm.cancel(R.id.notification_blah);
Upvotes: 2