简体   繁体   中英

how to make a custom layout notification canceled when a layout button is pressed?

I have a notification with a custom layout and I've set FLAG_AUTO_CANCEL so when the notification is clicked, as the corresponding intent is browsed, the notification is cleared from action bar. I also have a button on the notification's layout. Using setOnClickPendingIntent in RemoteViews, when the button is clicked, another activity is browsed but the notification remains in the action bar. how can make it cleared when on button click?

When you create your notification, you must give it a unique ID:

    mNotificationManager.notify(msg.getId(), mBuilder.build());

then use notification manager to cancel the notification:

    mNotificationManager.cancel(msg.getId());

So the hard part is keeping track of which notifications might be present and sending the proper ID's to cancel them.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM