Stop alarm when notification is dismissed

This commit is contained in:
Brandon Presley 2022-08-30 21:42:38 +12:00
parent 26f54e43e0
commit 81fd21be48
1 changed files with 9 additions and 0 deletions

View File

@ -70,6 +70,14 @@ class TimerService : Service() {
finishIntent,
PendingIntent.FLAG_IMMUTABLE
)
val stopIntent = Intent(applicationContext, StopTimer::class.java)
val pendingStop =
PendingIntent.getService(
applicationContext,
0,
stopIntent,
PendingIntent.FLAG_IMMUTABLE
)
builder.setContentText("Timer finished.")
.setAutoCancel(true)
.setProgress(0, 0, false)
@ -77,6 +85,7 @@ class TimerService : Service() {
.setContentIntent(finishPending)
.setChannelId(CHANNEL_ID_DONE)
.setCategory(NotificationCompat.CATEGORY_ALARM)
.setDeleteIntent(pendingStop)
.priority = NotificationCompat.PRIORITY_HIGH
manager?.notify(NOTIFICATION_ID_DONE, builder.build())
manager?.cancel(NOTIFICATION_ID_PENDING)