mirror of
https://github.com/SimpleMobileTools/Simple-Calendar.git
synced 2025-06-05 21:59:17 +02:00
make sure the selected notification sound is played
This commit is contained in:
@@ -46,7 +46,7 @@ ext {
|
|||||||
}
|
}
|
||||||
|
|
||||||
dependencies {
|
dependencies {
|
||||||
implementation 'com.simplemobiletools:commons:3.18.18'
|
implementation 'com.simplemobiletools:commons:3.18.19'
|
||||||
implementation 'joda-time:joda-time:2.9.9'
|
implementation 'joda-time:joda-time:2.9.9'
|
||||||
implementation 'com.facebook.stetho:stetho:1.5.0'
|
implementation 'com.facebook.stetho:stetho:1.5.0'
|
||||||
implementation 'com.android.support:multidex:1.0.3'
|
implementation 'com.android.support:multidex:1.0.3'
|
||||||
|
@@ -10,6 +10,7 @@ import android.content.Context
|
|||||||
import android.content.Intent
|
import android.content.Intent
|
||||||
import android.content.res.Resources
|
import android.content.res.Resources
|
||||||
import android.database.ContentObserver
|
import android.database.ContentObserver
|
||||||
|
import android.media.AudioAttributes
|
||||||
import android.media.AudioManager
|
import android.media.AudioManager
|
||||||
import android.net.Uri
|
import android.net.Uri
|
||||||
import android.os.Bundle
|
import android.os.Bundle
|
||||||
@@ -166,8 +167,22 @@ fun Context.notifyEvent(event: Event) {
|
|||||||
|
|
||||||
@SuppressLint("NewApi")
|
@SuppressLint("NewApi")
|
||||||
fun Context.getNotification(pendingIntent: PendingIntent, event: Event, content: String, publicVersion: Boolean = false): Notification {
|
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()) {
|
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 notificationManager = getSystemService(Context.NOTIFICATION_SERVICE) as NotificationManager
|
||||||
val name = resources.getString(R.string.event_reminders)
|
val name = resources.getString(R.string.event_reminders)
|
||||||
val importance = NotificationManager.IMPORTANCE_HIGH
|
val importance = NotificationManager.IMPORTANCE_HIGH
|
||||||
@@ -175,17 +190,11 @@ fun Context.getNotification(pendingIntent: PendingIntent, event: Event, content:
|
|||||||
enableLights(true)
|
enableLights(true)
|
||||||
lightColor = event.color
|
lightColor = event.color
|
||||||
enableVibration(false)
|
enableVibration(false)
|
||||||
|
setSound(Uri.parse(soundUri), audioAttributes)
|
||||||
notificationManager.createNotificationChannel(this)
|
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 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
|
val contentText = if (publicVersion) resources.getString(R.string.public_event_notification_text) else content
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user