blob: c903ff72d7d22e8760da35cef47c7347bfb63d31 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
|
package com.pitchedapps.frost.services
import android.app.PendingIntent
import android.content.BroadcastReceiver
import android.content.Context
import android.content.Intent
import android.support.v4.app.NotificationManagerCompat
import com.pitchedapps.frost.utils.L
/**
* Created by Allan Wang on 2017-08-04.
*
* Cancels a notification
*/
private const val NOTIF_TAG_TO_CANCEL = "notif_tag_to_cancel"
private const val NOTIF_ID_TO_CANCEL = "notif_id_to_cancel"
class NotificationReceiver : BroadcastReceiver() {
override fun onReceive(context: Context, intent: Intent) {
L.d("NotificationReceiver triggered")
val notifTag = intent.getStringExtra(NOTIF_TAG_TO_CANCEL)
val notifId = intent.getIntExtra(NOTIF_ID_TO_CANCEL, -1)
if (notifId != -1) {
L.d("NotificationReceiver: Cancelling $notifTag $notifId")
NotificationManagerCompat.from(context).cancel(notifTag, notifId)
}
}
}
fun Context.getNotificationPendingCancelIntent(tag: String?, notifId: Int): PendingIntent {
val cancelIntent = Intent(this, NotificationReceiver::class.java)
.putExtra(NOTIF_TAG_TO_CANCEL, tag).putExtra(NOTIF_ID_TO_CANCEL, notifId)
return PendingIntent.getBroadcast(this, 0, cancelIntent, 0)
}
|