Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Notification Auto Cancel at a Particular Time

I am a beginner for Java Coding and is currently coding an Android Project. Right now, I am facing an issue. I want my application to auto remove the notification at a particular time.

I've managed to dismiss the notification after user click on the notification. However, at the same time, I also want the notification to auto disappear after a specific time if the user did not react to the notification.

Please advise me on how should I do it. If possible, please provide me some examples.

like image 315
redblackwhite Avatar asked Nov 08 '22 23:11

redblackwhite


1 Answers

You can start a timer for required seconds as soon you call the method to show notification and inside onFinish() of the timer you can add something like this :

NotificationManager nMgr = (NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE);
nMgr.cancelAll();
like image 106
rahul Avatar answered Nov 15 '22 12:11

rahul