CompatibilityStreamNotificationHandler
Compatibility notification handler that bridges the new notification system with the legacy notification handler behavior.
This class allows applications that previously relied on the old notification handler APIs to continue working while adopting the new notification interception mechanism.
Usage
notificationHandler = CompatibilityStreamNotificationHandler(
context.app,
initialNotificationBuilderInterceptor =
object : StreamNotificationBuilderInterceptors() {
override fun onBuildIncomingCallNotification(
builder: NotificationCompat.Builder,
fullScreenPendingIntent: PendingIntent,
acceptCallPendingIntent: PendingIntent,
rejectCallPendingIntent: PendingIntent,
callerName: String?,
shouldHaveContentIntent: Boolean
): NotificationCompat.Builder {
builder.setContentTitle("My new and shiny incoming call")
builder.setContentText(
"This is my new content text that I've changed!!!"
)
return builder
}
},
updateNotificationBuilderInterceptor =
object : StreamNotificationUpdateInterceptors() {
private suspend fun loadBitmapFromUrl(url: String): Bitmap =
withContext(Dispatchers.IO) {
URL(url).openStream().use {
BitmapFactory.decodeStream(it)
}
}
override suspend fun onUpdateIncomingCallNotification(
builder: NotificationCompat.Builder,
callDisplayName: String?,
call: Call
): NotificationCompat.Builder {
// For demonstration purposes, a delay can be added here.
// delay(4_000)
val userImageUrl = "MyImageURL"
val bitmap = loadBitmapFromUrl(userImageUrl)
builder.setContentText("My new notification with my image!!")
builder.setLargeIcon(bitmap)
return builder
}
}
)See also
Constructors
Functions
Customize the notification when you receive a push notification for ringing call with type RingingState.Incoming
Customize the notification when you receive a push notification for Missed Call
Get subsequent updates to notifications. Initially, notifications are posted by one of the other methods, and then this method can be used to re-post them with updated content.
Customize the notification when you receive a push notification for ringing call with type RingingState.Outgoing and RingingState.Active
Customize the notification when you receive a push notification for ringing call
Temporary notification. Sometimes the system needs to show a notification while the call is not ready. This is the notification that will be shown.
Get subsequent updates to notifications. Initially, notifications are posted by one of the other methods, and then this method can be used to re-post them with updated content.
Customize the notification when you receive a push notification for Live Call
Customize the notification when you receive a push notification for Missed Call
Customize the notification when you receive a push notification for general usage
Customize the notification when you receive a push notification for ringing call, which has further two types RingingState.Incoming and RingingState.Outgoing
Update the ringing call notification.
Update the ongoing call notification.
Update the ringing call notification.