mirror of
https://github.com/Novaloop-AG/element-x-android.git
synced 2026-11-03 16:10:00 +00:00
Fix crash when getting the system ringtone for ringing calls (#3131)
This commit is contained in:
committed by
GitHub
parent
32a374d836
commit
05df1f2065
+7
-2
@@ -116,7 +116,8 @@ class RingingCallNotificationCreator @Inject constructor(
|
|||||||
false
|
false
|
||||||
)
|
)
|
||||||
|
|
||||||
val ringtoneUri = RingtoneManager.getActualDefaultRingtoneUri(context, RingtoneManager.TYPE_RINGTONE)
|
// 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)
|
return NotificationCompat.Builder(context, notificationChannelId)
|
||||||
.setSmallIcon(CommonDrawables.ic_notification_small)
|
.setSmallIcon(CommonDrawables.ic_notification_small)
|
||||||
.setPriority(NotificationCompat.PRIORITY_MAX)
|
.setPriority(NotificationCompat.PRIORITY_MAX)
|
||||||
@@ -127,7 +128,11 @@ class RingingCallNotificationCreator @Inject constructor(
|
|||||||
.setWhen(timestamp)
|
.setWhen(timestamp)
|
||||||
.setOngoing(true)
|
.setOngoing(true)
|
||||||
.setShowWhen(false)
|
.setShowWhen(false)
|
||||||
.setSound(ringtoneUri, AudioManager.STREAM_RING)
|
.apply {
|
||||||
|
if (ringtoneUri != null) {
|
||||||
|
setSound(ringtoneUri, AudioManager.STREAM_RING)
|
||||||
|
}
|
||||||
|
}
|
||||||
.setTimeoutAfter(ElementCallConfig.RINGING_CALL_DURATION_SECONDS.seconds.inWholeMilliseconds)
|
.setTimeoutAfter(ElementCallConfig.RINGING_CALL_DURATION_SECONDS.seconds.inWholeMilliseconds)
|
||||||
.setContentIntent(answerIntent)
|
.setContentIntent(answerIntent)
|
||||||
.setDeleteIntent(declineIntent)
|
.setDeleteIntent(declineIntent)
|
||||||
|
|||||||
+14
-9
@@ -162,7 +162,8 @@ class DefaultNotificationChannels @Inject constructor(
|
|||||||
)
|
)
|
||||||
|
|
||||||
// Register a channel for incoming call notifications which will ring the device when received
|
// Register a channel for incoming call notifications which will ring the device when received
|
||||||
val ringtoneUri = RingtoneManager.getActualDefaultRingtoneUri(context, RingtoneManager.TYPE_RINGTONE)
|
// TODO use a fallback ringtone if the default ringtone is not available
|
||||||
|
val ringtoneUri = runCatching { RingtoneManager.getActualDefaultRingtoneUri(context, RingtoneManager.TYPE_RINGTONE) }.getOrNull()
|
||||||
notificationManager.createNotificationChannel(
|
notificationManager.createNotificationChannel(
|
||||||
NotificationChannelCompat.Builder(
|
NotificationChannelCompat.Builder(
|
||||||
RINGING_CALL_NOTIFICATION_CHANNEL_ID,
|
RINGING_CALL_NOTIFICATION_CHANNEL_ID,
|
||||||
@@ -170,14 +171,18 @@ class DefaultNotificationChannels @Inject constructor(
|
|||||||
)
|
)
|
||||||
.setName(stringProvider.getString(R.string.notification_channel_ringing_calls).ifEmpty { "Ringing calls" })
|
.setName(stringProvider.getString(R.string.notification_channel_ringing_calls).ifEmpty { "Ringing calls" })
|
||||||
.setVibrationEnabled(true)
|
.setVibrationEnabled(true)
|
||||||
.setSound(
|
.apply {
|
||||||
ringtoneUri,
|
if (ringtoneUri != null) {
|
||||||
AudioAttributes.Builder()
|
setSound(
|
||||||
.setContentType(AudioAttributes.CONTENT_TYPE_SONIFICATION)
|
ringtoneUri,
|
||||||
.setLegacyStreamType(AudioManager.STREAM_RING)
|
AudioAttributes.Builder()
|
||||||
.setUsage(AudioAttributes.USAGE_NOTIFICATION_RINGTONE)
|
.setContentType(AudioAttributes.CONTENT_TYPE_SONIFICATION)
|
||||||
.build()
|
.setLegacyStreamType(AudioManager.STREAM_RING)
|
||||||
)
|
.setUsage(AudioAttributes.USAGE_NOTIFICATION_RINGTONE)
|
||||||
|
.build()
|
||||||
|
)
|
||||||
|
}
|
||||||
|
}
|
||||||
.setDescription(stringProvider.getString(R.string.notification_channel_ringing_calls))
|
.setDescription(stringProvider.getString(R.string.notification_channel_ringing_calls))
|
||||||
.setLightsEnabled(true)
|
.setLightsEnabled(true)
|
||||||
.setLightColor(accentColor)
|
.setLightColor(accentColor)
|
||||||
|
|||||||
Reference in New Issue
Block a user