Use Settings.System.DEFAULT_RINGTONE_URI for ringing notifications (#4310)

* Use `Settings.System.DEFAULT_RINGTONE_URI` for ringing notifications

This replaces `RingtoneManager.getActualDefaultRingtoneUri`, it should get the same audio file and avoid some reported issues about not having permission to load the audio file.
This commit is contained in:
Jorge Martin Espinosa 2025-02-27 13:57:43 +01:00 committed by GitHub
parent 408b367d31
commit f029c4dd09
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
4 changed files with 12 additions and 27 deletions

View file

@ -11,7 +11,7 @@ import android.app.PendingIntent
import android.content.Context
import android.content.Intent
import android.media.AudioManager
import android.media.RingtoneManager
import android.provider.Settings
import androidx.core.app.NotificationCompat
import androidx.core.app.PendingIntentCompat
import androidx.core.app.Person
@ -109,8 +109,6 @@ class RingingCallNotificationCreator @Inject constructor(
false
)
// TODO use a fallback ringtone if the default ringtone is not available
val ringtoneUri = runCatching { RingtoneManager.getActualDefaultRingtoneUri(context, RingtoneManager.TYPE_RINGTONE) }.getOrNull()
return NotificationCompat.Builder(context, notificationChannelId)
.setSmallIcon(CommonDrawables.ic_notification_small)
.setPriority(NotificationCompat.PRIORITY_MAX)
@ -126,10 +124,8 @@ class RingingCallNotificationCreator @Inject constructor(
setContentText(textContent)
// Else the content text is set by the style (will be "Incoming call")
}
if (ringtoneUri != null) {
setSound(ringtoneUri, AudioManager.STREAM_RING)
}
}
.setSound(Settings.System.DEFAULT_RINGTONE_URI, AudioManager.STREAM_RING)
.setTimeoutAfter(ElementCallConfig.RINGING_CALL_DURATION_SECONDS.seconds.inWholeMilliseconds)
.setContentIntent(answerIntent)
.setDeleteIntent(declineIntent)