Skip to content

Commit 678d3d4

Browse files
committed
Set a sound to the noisy notification channel
1 parent 6cc7f6d commit 678d3d4

File tree

2 files changed

+20
-1
lines changed

2 files changed

+20
-1
lines changed

libraries/push/impl/src/main/kotlin/io/element/android/libraries/push/impl/notifications/channels/NotificationChannels.kt

Lines changed: 20 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,12 @@
77

88
package io.element.android.libraries.push.impl.notifications.channels
99

10+
import android.content.ContentResolver
11+
import android.content.Context
1012
import android.media.AudioAttributes
13+
import android.media.AudioAttributes.USAGE_NOTIFICATION
1114
import android.media.AudioManager
15+
import android.net.Uri
1216
import android.os.Build
1317
import android.provider.Settings
1418
import androidx.annotation.ChecksSdkIntAtLeast
@@ -19,14 +23,15 @@ import dev.zacsweers.metro.ContributesBinding
1923
import dev.zacsweers.metro.Inject
2024
import dev.zacsweers.metro.SingleIn
2125
import io.element.android.appconfig.NotificationConfig
26+
import io.element.android.libraries.di.annotations.ApplicationContext
2227
import io.element.android.libraries.push.impl.R
2328
import io.element.android.services.toolbox.api.strings.StringProvider
2429

2530
/* ==========================================================================================
2631
* IDs for channels
2732
* ========================================================================================== */
2833
internal const val SILENT_NOTIFICATION_CHANNEL_ID = "DEFAULT_SILENT_NOTIFICATION_CHANNEL_ID_V2"
29-
internal const val NOISY_NOTIFICATION_CHANNEL_ID = "DEFAULT_NOISY_NOTIFICATION_CHANNEL_ID"
34+
internal const val NOISY_NOTIFICATION_CHANNEL_ID = "DEFAULT_NOISY_NOTIFICATION_CHANNEL_ID_V2"
3035
internal const val CALL_NOTIFICATION_CHANNEL_ID = "CALL_NOTIFICATION_CHANNEL_ID_V3"
3136
internal const val RINGING_CALL_NOTIFICATION_CHANNEL_ID = "RINGING_CALL_NOTIFICATION_CHANNEL_ID"
3237

@@ -61,6 +66,8 @@ private fun supportNotificationChannels() = Build.VERSION.SDK_INT >= Build.VERSI
6166
class DefaultNotificationChannels(
6267
private val notificationManager: NotificationManagerCompat,
6368
private val stringProvider: StringProvider,
69+
@ApplicationContext
70+
private val context: Context,
6471
) : NotificationChannels {
6572
init {
6673
createNotificationChannels()
@@ -94,6 +101,7 @@ class DefaultNotificationChannels(
94101
// Migration - Remove deprecated channels
95102
for (channelId in listOf(
96103
"DEFAULT_SILENT_NOTIFICATION_CHANNEL_ID",
104+
"DEFAULT_NOISY_NOTIFICATION_CHANNEL_ID",
97105
"CALL_NOTIFICATION_CHANNEL_ID",
98106
"CALL_NOTIFICATION_CHANNEL_ID_V2",
99107
"LISTEN_FOR_EVENTS_NOTIFICATION_CHANNEL_ID",
@@ -112,6 +120,17 @@ class DefaultNotificationChannels(
112120
NOISY_NOTIFICATION_CHANNEL_ID,
113121
NotificationManagerCompat.IMPORTANCE_DEFAULT
114122
)
123+
.setSound(
124+
Uri.Builder()
125+
.scheme(ContentResolver.SCHEME_ANDROID_RESOURCE)
126+
// Strangely wwe have to provide a "//" before the package name
127+
.path("//" + context.packageName + "/" + R.raw.message)
128+
.build(),
129+
AudioAttributes.Builder()
130+
.setContentType(AudioAttributes.CONTENT_TYPE_SONIFICATION)
131+
.setUsage(USAGE_NOTIFICATION)
132+
.build(),
133+
)
115134
.setName(stringProvider.getString(R.string.notification_channel_noisy).ifEmpty { "Noisy notifications" })
116135
.setDescription(stringProvider.getString(R.string.notification_channel_noisy))
117136
.setVibrationEnabled(true)
21.9 KB
Binary file not shown.

0 commit comments

Comments
 (0)