Skip to content
This repository has been archived by the owner on Dec 30, 2022. It is now read-only.

Commit

Permalink
fix: disable foreground service vibration/sounds
Browse files Browse the repository at this point in the history
  • Loading branch information
marcouberti committed Sep 14, 2020
1 parent 4a96a3a commit 1300632
Showing 1 changed file with 20 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ import android.os.Build
import android.text.format.DateFormat
import androidx.core.app.NotificationCompat
import androidx.core.app.NotificationManagerCompat
import androidx.core.app.NotificationManagerCompat.IMPORTANCE_LOW
import androidx.core.content.ContextCompat
import it.ministerodellasalute.immuni.R
import it.ministerodellasalute.immuni.ui.main.MainActivity
Expand All @@ -37,6 +38,7 @@ class AppNotificationManager(val context: Context) : KoinComponent {

companion object {
const val CHANNEL_ID = "exposure_notification"
const val FOREGROUND_SERVICE_CHANNEL_ID = "fetch_teks_foreground_service"
const val DEBUG_CHANNEL_ID = "debug_channel"
private var DEBUG_ID = 0
const val GROUP_ID = 20000
Expand Down Expand Up @@ -170,9 +172,20 @@ class AppNotificationManager(val context: Context) : KoinComponent {
createChannel(id = CHANNEL_ID, name = channelName)
}

private fun createForegroundServiceChannel() {
val channelName = context.getString(R.string.app_name)
createChannel(
id = FOREGROUND_SERVICE_CHANNEL_ID, name = channelName, mute = true, showBadge = false,
importance = IMPORTANCE_LOW
)
}

private fun createDebugChannel() {
val channelName = "Immuni - Debug"
createChannel(id = DEBUG_CHANNEL_ID, name = channelName, mute = true, showBadge = false)
createChannel(
id = DEBUG_CHANNEL_ID, name = channelName, mute = true, showBadge = false,
importance = IMPORTANCE_LOW
)
}

private fun createChannel(
Expand All @@ -196,14 +209,18 @@ class AppNotificationManager(val context: Context) : KoinComponent {
}

fun fetchKeysForegroundNotification(): Notification {
createExposureNotificationChannel()
return NotificationCompat.Builder(context, CHANNEL_ID)
createForegroundServiceChannel()
return NotificationCompat.Builder(context, FOREGROUND_SERVICE_CHANNEL_ID)
.setContentTitle(context.getString(R.string.app_name))
.setTicker(context.getString(R.string.app_name))
.setContentText(context.getString(R.string.home_view_service_active_title))
.setSmallIcon(R.drawable.ic_notification_app)
.setOnlyAlertOnce(true)
.setColor(ContextCompat.getColor(context, R.color.colorPrimary))
.setOngoing(true)
.setSound(null)
.setVibrate(longArrayOf(0L))
.setBadgeIconType(NotificationCompat.BADGE_ICON_NONE)
.build()
}

Expand Down

0 comments on commit 1300632

Please sign in to comment.