How to delete a notification after a certain time in android?

I am creating a simple Android application in which a notification is created.

Now I want to delete the notification if the user is not responsible for a certain time

This means that I want to delete the notification in five minutes

+3
source share
2 answers

You need a combination of Alarmmanager and alerts.

Register an alarm manager that will call the service in 5 minutes and use the NotificationManager.cancel function in the service implementation.

An example of an alarm service is here . I suppose you know that you are using Notification Manager .

+2
source

AlarmManager , . Java Runnable Handler .

Handler h = new Handler();
    long delayInMilliseconds = 5000;
    h.postDelayed(new Runnable() {
        public void run() {
            mNotificationManager.cancel(id);
        }
    }, delayInMilliseconds);

:

TimerTask-Class.

0

All Articles