Skip to content

Commit

Permalink
Merge pull request #204 from SuhasDissa/main
Browse files Browse the repository at this point in the history
Silent any notification sounds for the alarm notification
  • Loading branch information
SuhasDissa authored Nov 10, 2023
2 parents c21d1ce + 79ec4a5 commit 4efe529
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 27 deletions.
5 changes: 2 additions & 3 deletions app/src/main/java/com/bnyro/clock/services/AlarmService.kt
Original file line number Diff line number Diff line change
Expand Up @@ -114,8 +114,6 @@ class AlarmService : Service() {
}

private fun createNotification(context: Context, alarm: Alarm): Notification {
NotificationHelper.createAlarmNotificationChannel(context, alarm)

val pendingIntent = PendingIntent.getActivity(
context,
0,
Expand All @@ -132,8 +130,9 @@ class AlarmService : Service() {
val builder = NotificationCompat.Builder(context, NotificationHelper.ALARM_CHANNEL)
.setSmallIcon(R.drawable.ic_notification)
.setContentTitle(alarm.label ?: context.getString(R.string.alarm))
.setSilent(true)
.setAutoCancel(true)
.setPriority(NotificationCompat.PRIORITY_HIGH)
.setPriority(NotificationCompat.PRIORITY_MAX)
.setCategory(NotificationCompat.CATEGORY_ALARM)
.setFullScreenIntent(pendingIntent, true)
return builder.build()
Expand Down
30 changes: 6 additions & 24 deletions app/src/main/java/com/bnyro/clock/util/NotificationHelper.kt
Original file line number Diff line number Diff line change
@@ -1,15 +1,10 @@
package com.bnyro.clock.util

import android.app.NotificationChannel
import android.app.NotificationManager
import android.content.Context
import android.media.AudioAttributes
import android.os.Build
import androidx.core.app.NotificationChannelCompat
import androidx.core.app.NotificationManagerCompat
import androidx.core.net.toUri
import com.bnyro.clock.R
import com.bnyro.clock.obj.Alarm

object NotificationHelper {
const val STOPWATCH_CHANNEL = "stopwatch"
Expand Down Expand Up @@ -53,28 +48,15 @@ object NotificationHelper {
)
.setName(context.getString(R.string.timer_finished))
.setSound(RingtoneHelper.getDefault(context), audioAttributes)
.build(),
NotificationChannelCompat.Builder(
ALARM_CHANNEL,
NotificationManagerCompat.IMPORTANCE_MAX
)
.setName(context.getString(R.string.alarm))
.build()
)

nManager.createNotificationChannelsCompat(channels)
}

fun createAlarmNotificationChannel(context: Context, alarm: Alarm) {
val nManager = NotificationManagerCompat.from(context)

if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
NotificationChannel(
ALARM_CHANNEL,
context.getString(R.string.alarm),
NotificationManager.IMPORTANCE_HIGH
).apply {
val soundUri = alarm.soundUri?.toUri() ?: RingtoneHelper.getDefault(context)
setBypassDnd(true)
setSound(soundUri, audioAttributes)
vibrationPattern = if (alarm.vibrate) this.vibrationPattern else null
}.let {
nManager.createNotificationChannel(it)
}
}
}
}

0 comments on commit 4efe529

Please sign in to comment.