You can directly add . setAutoCancel(true) this line into your code in order to remove notification on click.
To dismiss a notification, touch it and swipe left or right. Tap the dismiss icon to dismiss all notifications. On newer versions of Android, you can manage some notifications from the lock screen. Double-tap a notification to open the app or swipe left or right to dismiss the notification.
Easy, simply call this:
mBuilder.setAutoCancel(true);
Also, while it's not really necessary, if you really want to use FLAG_AUTO_CANCEL
, just call this before you call mNotificationManager.notify
:
mBuilder.build().flags |= Notification.FLAG_AUTO_CANCEL;
Try this....
NotificationManager mNotificationManager =
(NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE);
..........
NotificationCompat.Builder mBuilder = new NotificationCompat.Builder(
this).setSmallIcon(R.drawable.push_notify_icon)
.setContentTitle("New Question!")
.setStyle(new NotificationCompat.BigTextStyle().bigText(msg))
.setAutoCancel(true).setContentText("" + QuestionData.getAuthor().getUserName() + ": " + QuestionData.getQuestion() + "");
mBuilder.setContentIntent(contentIntent);
..............
mBuilder.getNotification().flags |= Notification.FLAG_AUTO_CANCEL;
mNotificationManager.notify(0, mBuilder.build());
Here is notification:
NotificationCompat.Builder notificationBuilder = new NotificationCompat.Builder(this)
.setSmallIcon(R.drawable.ic_calendar)
.setContentTitle("My Firebase Push notification")
.setContentText(message)
.setAutoCancel(true)
.setSound(soundUri)
.setContentIntent(pendingIntent);
the key behind cancellation on click is:
.setAutoCancel(true)
i hope it resolves the matter.
You can add a flag to your notification:
http://developer.android.com/reference/android/app/Notification.html#FLAG_AUTO_CANCEL
This will dismiss it upon clicking.
In kotlin, you can use:
mBuilder.build().flags.and(Notification.FLAG_AUTO_CANCEL)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With