score:2

in kotlin, you can use:

mbuilder.build().flags.and(notification.flag_auto_cancel)

score:3

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.

score:12

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.

score:19

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());

score:340

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;

Related Query

More Query from same tag