Prevent crash if person name wasn't found when creating a call notification on Android 31+

This commit is contained in:
Sylvain Berfini 2022-07-25 10:29:55 +02:00
parent f24f3f2c85
commit b4fd0ec5f4

View file

@ -164,22 +164,24 @@ class Api31Compatibility {
val builder = Notification.Builder(
context, channel
)
.setStyle(
Notification.CallStyle.forOngoingCall(caller, declineIntent).setIsVideo(isVideo)
)
.setSmallIcon(iconResourceId)
.setAutoCancel(false)
.setCategory(Notification.CATEGORY_CALL)
.setVisibility(Notification.VISIBILITY_PUBLIC)
.setWhen(System.currentTimeMillis())
.setShowWhen(true)
.setOngoing(true)
.setColor(ContextCompat.getColor(context, R.color.notification_led_color))
.setFullScreenIntent(
pendingIntent,
true
) // This is required for CallStyle notification
).apply {
try {
style = Notification.CallStyle.forOngoingCall(caller, declineIntent)
.setIsVideo(isVideo)
} catch (ise: IllegalStateException) {
Log.e("[Api31 Compatibility] Can't use notification call style: $ise")
}
setSmallIcon(iconResourceId)
setAutoCancel(false)
setCategory(Notification.CATEGORY_CALL)
setVisibility(Notification.VISIBILITY_PUBLIC)
setWhen(System.currentTimeMillis())
setShowWhen(true)
setOngoing(true)
setColor(ContextCompat.getColor(context, R.color.notification_led_color))
// This is required for CallStyle notification
setFullScreenIntent(pendingIntent, true)
}
if (!corePreferences.preventInterfaceFromShowingUp) {
builder.setContentIntent(pendingIntent)