[Solved] How to remove notifications when touched? [duplicate]


Using flags

 notification.flags = Notification.FLAG_AUTO_CANCEL;

Using Notification builder

NotificationCompat.Builder builder = new NotificationCompat.Builder(context);
builder.setAutoCancel(true);

Using Notification Manager

notificationManager.cancel(NOTIFICATION_ID);

for API level 18 and above

@TargetApi(Build.VERSION_CODES.JELLY_BEAN_MR2)
public class MyNotificationListenerService extends NotificationListenerService {...}
...

private void clearNotificationExample(StatusBarNotification sbn) {
    myNotificationListenerService.cancelNotification(sbn.getPackageName(), sbn.getTag(), sbn.getId());
}

2

solved How to remove notifications when touched? [duplicate]