-1

so I'd like to know how I could remove the pending notification in the NotificationCenter after the user clicks it. Here's my BroadcastReceiver:

public class MyBroadcastReceiver extends BroadcastReceiver {
@Override
public void onReceive(Context context, Intent intent) {
    Intent startServiceIntent = new Intent(context, BackgroundChecks.class);
    startServiceIntent.putExtra("notificationActivityAmtsblatt", AmtsblattActivity.class.getName());
    startServiceIntent.putExtra("notificationActivityAmtstafel", AmtsblattActivity.class.getName());
    context.startService(startServiceIntent);
}
}

Can I put it somewhere in that BCReceiver? Thank you

mrousavy
  • 311
  • 1
  • 8
  • Possible duplicate of [Remove notification after clicking](http://stackoverflow.com/questions/15120821/remove-notification-after-clicking) – ingh.am Oct 31 '15 at 15:09
  • @ing0 Because I'm a programming beginner, the link you posted was not really understandable for me. I'm sorry for the repost – mrousavy Oct 31 '15 at 15:17

1 Answers1

1

The easiest solution is to set the autoCancel attribute of your notification to true when you build your notification like :

yourNotification.setAutoCancel(true);

But if you want to dismiss the notification in your BCReceiver, you can use the cancel(int notificationId) method of NotificationManager like :

NotificationManager mNotifyMgr = (NotificationManager)getSystemService(NOTIFICATION_SERVICE);
mNotifyMgr.cancel(youNotificationId);
Bubu
  • 1,533
  • 14
  • 14