I am new to Java Coding and am currently coding an Android project. Now I am facing a problem. I want mine to applicationautomatically delete notificationat a specific time.
application
notification
I managed to disconnect notificationafter the user clicks on notification. However, at the same time, I also want it to notificationautomatically disappear after a certain time if the user did not respond to notification.
Please advise me how to do this. If possible, give me some examples.
, , onFinish() - :
NotificationManager nMgr = (NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE); nMgr.cancelAll();
- , , , :
//clear all pending notifications String ns = Context.NOTIFICATION_SERVICE; NotificationManager nMgr = (NotificationManager) context.getSystemService(ns); nMgr.cancelAll();
Timer Notification cancel()
Timer
Notification
cancel()
nMgr.cancel(<notification-id>); // here you have to pass your notification id.
,
nMgr.cancelAll();
2 , :
Timer timer=new Timer(); TimerTask task=new TimerTask() { @Override public void run() { nMgr.cancel(notification-id); } }; timer.schedule(task, 2000);
. miliseconds . .
Handler h = new Handler(); long delayInMilliseconds = 5000; h.postDelayed(new Runnable() { public void run() { mNotificationManager.cancel(YourNotificationId); } }, delayInMilliseconds);
Source: https://habr.com/ru/post/1621582/More articles:The gap between SKSpriteNodes in SpriteKit collision detection - iosHow to enter data in Keras? In particular, what are x_train and y_train if I have more than two columns? - neural-networkAfter installation, mySQL does not start (windows10, initial installation) - mysqlΠΠ΄Π΅ ΡΠΊΠ°ΡΠ°ΡΡ libvlc? - c++Unable to clean form - angularjsLogin working on localhost but login not working remotely yii - phpHow to hide fullscreen.js sliders in a fixed height and fixed width div - javascriptHide DIV based on content - javascriptGetting all emails from Gmail using PHP - phpWhy do we need device drivers when we already have firmware in the hardware? - cAll Articles