diff --git a/app/build.gradle b/app/build.gradle index 4ca718c15..8f7cca10a 100644 --- a/app/build.gradle +++ b/app/build.gradle @@ -46,7 +46,7 @@ ext { } dependencies { - implementation 'com.simplemobiletools:commons:3.18.18' + implementation 'com.simplemobiletools:commons:3.18.19' implementation 'joda-time:joda-time:2.9.9' implementation 'com.facebook.stetho:stetho:1.5.0' implementation 'com.android.support:multidex:1.0.3' diff --git a/app/src/main/kotlin/com/simplemobiletools/calendar/extensions/Context.kt b/app/src/main/kotlin/com/simplemobiletools/calendar/extensions/Context.kt index 6a2f994bb..98f689d9b 100644 --- a/app/src/main/kotlin/com/simplemobiletools/calendar/extensions/Context.kt +++ b/app/src/main/kotlin/com/simplemobiletools/calendar/extensions/Context.kt @@ -10,6 +10,7 @@ import android.content.Context import android.content.Intent import android.content.res.Resources import android.database.ContentObserver +import android.media.AudioAttributes import android.media.AudioManager import android.net.Uri import android.os.Bundle @@ -166,8 +167,22 @@ fun Context.notifyEvent(event: Event) { @SuppressLint("NewApi") fun Context.getNotification(pendingIntent: PendingIntent, event: Event, content: String, publicVersion: Boolean = false): Notification { - val channelId = "reminder_channel" + var soundUri = config.reminderSoundUri + if (soundUri == SILENT) { + soundUri = "" + } else { + grantReadUriPermission(soundUri) + } + + val channelId = "my_reminder_channel_$soundUri" if (isOreoPlus()) { + val audioAttributes = AudioAttributes.Builder() + .setUsage(AudioAttributes.USAGE_NOTIFICATION) + .setContentType(AudioAttributes.CONTENT_TYPE_SONIFICATION) + .setLegacyStreamType(AudioManager.STREAM_NOTIFICATION) + .setFlags(AudioAttributes.FLAG_AUDIBILITY_ENFORCED) + .build() + val notificationManager = getSystemService(Context.NOTIFICATION_SERVICE) as NotificationManager val name = resources.getString(R.string.event_reminders) val importance = NotificationManager.IMPORTANCE_HIGH @@ -175,17 +190,11 @@ fun Context.getNotification(pendingIntent: PendingIntent, event: Event, content: enableLights(true) lightColor = event.color enableVibration(false) + setSound(Uri.parse(soundUri), audioAttributes) notificationManager.createNotificationChannel(this) } } - var soundUri = config.reminderSoundUri - if (soundUri == SILENT) { - soundUri = "" - } else { - grantReadUriPermission(soundUri) - } - val contentTitle = if (publicVersion) resources.getString(R.string.app_name) else event.title val contentText = if (publicVersion) resources.getString(R.string.public_event_notification_text) else content