X-Git-Url: http://git.linex4red.de/pub/Android/ownCloud.git/blobdiff_plain/b515e3a04261255e85c6fdd89f089f87350a868f..17ffd07e36497be3f81b4874229a121f982b2a5e:/src/com/owncloud/android/notifications/NotificationDelayer.java?ds=inline diff --git a/src/com/owncloud/android/notifications/NotificationDelayer.java b/src/com/owncloud/android/notifications/NotificationDelayer.java new file mode 100644 index 00000000..61cb07b2 --- /dev/null +++ b/src/com/owncloud/android/notifications/NotificationDelayer.java @@ -0,0 +1,33 @@ +package com.owncloud.android.notifications; + +import java.util.Random; + +import android.app.NotificationManager; +import android.os.Handler; +import android.os.HandlerThread; +import android.os.Process; + +public class NotificationDelayer { + + public static void cancelWithDelay( + final NotificationManager notificationManager, + final int notificationId, + long delayInMillis) { + + HandlerThread thread = new HandlerThread( + "NotificationDelayerThread_" + (new Random(System.currentTimeMillis())).nextInt(), + Process.THREAD_PRIORITY_BACKGROUND); + thread.start(); + + Handler handler = new Handler(thread.getLooper()); + handler.postDelayed(new Runnable() { + public void run() { + notificationManager.cancel(notificationId); + ((HandlerThread)Thread.currentThread()).getLooper().quitSafely(); + } + }, delayInMillis); + + } + + +}