CompatibilityStreamNotificationHandler

open class CompatibilityStreamNotificationHandler constructor(application: Application, notificationPermissionHandler: NotificationPermissionHandler = DefaultNotificationPermissionHandler.createDefaultNotificationPermissionHandler( application, ), notificationManager: NotificationManagerCompat = NotificationManagerCompat.from( application.applicationContext, ), intentResolver: StreamIntentResolver = DefaultStreamIntentResolver(application, DefaultNotificationIntentBundleResolver()), hideRingingNotificationInForeground: Boolean = (StreamVideo.instanceOrNull() as? StreamVideoClient)?.streamNotificationManager?.notificationConfig?.hideRingingNotificationInForeground == true, initialNotificationBuilderInterceptor: StreamNotificationBuilderInterceptors = StreamNotificationBuilderInterceptors(), updateNotificationBuilderInterceptor: StreamNotificationUpdateInterceptors = StreamNotificationUpdateInterceptors(), mediaSessionController: StreamMediaSessionController = DefaultStreamMediaSessionController( initialNotificationBuilderInterceptor, updateNotificationBuilderInterceptor, ), mediaSessionCallback: MediaSessionCompat.Callback? = null, notificationChannels: StreamNotificationChannels = StreamNotificationChannels( incomingCallChannel = createChannelInfoFromResIds( application.applicationContext, R.string.stream_video_incoming_call_notification_channel_id, R.string.stream_video_incoming_call_notification_channel_title, R.string.stream_video_incoming_call_notification_channel_description, NotificationManager.IMPORTANCE_HIGH, ), ongoingCallChannel = createChannelInfoFromResIds( application.applicationContext, R.string.stream_video_ongoing_call_notification_channel_id, R.string.stream_video_ongoing_call_notification_channel_title, R.string.stream_video_ongoing_call_notification_channel_description, NotificationManager.IMPORTANCE_DEFAULT, ), outgoingCallChannel = createChannelInfoFromResIds( application.applicationContext, R.string.stream_video_outgoing_call_notification_channel_id, R.string.stream_video_outgoing_call_notification_channel_title, R.string.stream_video_outgoing_call_notification_channel_description, NotificationManager.IMPORTANCE_DEFAULT, ), missedCallChannel = createChannelInfoFromResIds( application.applicationContext, R.string.stream_video_missed_call_notification_channel_id, R.string.stream_video_missed_call_notification_channel_title, R.string.stream_video_missed_call_notification_channel_description, NotificationManager.IMPORTANCE_HIGH, ), missedCallLowImportanceChannel = createChannelInfoFromResIds( application.applicationContext, R.string.stream_video_missed_call_low_priority_notification_channel_id, R.string.stream_video_missed_call_notification_channel_title, R.string.stream_video_missed_call_low_priority_notification_channel_description, NotificationManager.IMPORTANCE_DEFAULT, ), incomingCallLowImportanceChannel = createChannelInfoFromResIds( application.applicationContext, R.string.stream_video_incoming_call_low_priority_notification_channel_id, R.string.stream_video_incoming_call_notification_channel_title, R.string.stream_video_incoming_call_low_priority_notification_channel_description, NotificationManager.IMPORTANCE_DEFAULT, ), )) : StreamDefaultNotificationHandler, NotificationHandler

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

Link copied to clipboard
constructor(application: Application, notificationPermissionHandler: NotificationPermissionHandler = DefaultNotificationPermissionHandler.createDefaultNotificationPermissionHandler( application, ), notificationManager: NotificationManagerCompat = NotificationManagerCompat.from( application.applicationContext, ), intentResolver: StreamIntentResolver = DefaultStreamIntentResolver(application, DefaultNotificationIntentBundleResolver()), hideRingingNotificationInForeground: Boolean = (StreamVideo.instanceOrNull() as? StreamVideoClient)?.streamNotificationManager?.notificationConfig?.hideRingingNotificationInForeground == true, initialNotificationBuilderInterceptor: StreamNotificationBuilderInterceptors = StreamNotificationBuilderInterceptors(), updateNotificationBuilderInterceptor: StreamNotificationUpdateInterceptors = StreamNotificationUpdateInterceptors(), mediaSessionController: StreamMediaSessionController = DefaultStreamMediaSessionController( initialNotificationBuilderInterceptor, updateNotificationBuilderInterceptor, ), mediaSessionCallback: MediaSessionCompat.Callback? = null, notificationChannels: StreamNotificationChannels = StreamNotificationChannels( incomingCallChannel = createChannelInfoFromResIds( application.applicationContext, R.string.stream_video_incoming_call_notification_channel_id, R.string.stream_video_incoming_call_notification_channel_title, R.string.stream_video_incoming_call_notification_channel_description, NotificationManager.IMPORTANCE_HIGH, ), ongoingCallChannel = createChannelInfoFromResIds( application.applicationContext, R.string.stream_video_ongoing_call_notification_channel_id, R.string.stream_video_ongoing_call_notification_channel_title, R.string.stream_video_ongoing_call_notification_channel_description, NotificationManager.IMPORTANCE_DEFAULT, ), outgoingCallChannel = createChannelInfoFromResIds( application.applicationContext, R.string.stream_video_outgoing_call_notification_channel_id, R.string.stream_video_outgoing_call_notification_channel_title, R.string.stream_video_outgoing_call_notification_channel_description, NotificationManager.IMPORTANCE_DEFAULT, ), missedCallChannel = createChannelInfoFromResIds( application.applicationContext, R.string.stream_video_missed_call_notification_channel_id, R.string.stream_video_missed_call_notification_channel_title, R.string.stream_video_missed_call_notification_channel_description, NotificationManager.IMPORTANCE_HIGH, ), missedCallLowImportanceChannel = createChannelInfoFromResIds( application.applicationContext, R.string.stream_video_missed_call_low_priority_notification_channel_id, R.string.stream_video_missed_call_notification_channel_title, R.string.stream_video_missed_call_low_priority_notification_channel_description, NotificationManager.IMPORTANCE_DEFAULT, ), incomingCallLowImportanceChannel = createChannelInfoFromResIds( application.applicationContext, R.string.stream_video_incoming_call_low_priority_notification_channel_id, R.string.stream_video_incoming_call_notification_channel_title, R.string.stream_video_incoming_call_low_priority_notification_channel_description, NotificationManager.IMPORTANCE_DEFAULT, ), ))

Functions

Link copied to clipboard
open override fun createMinimalMediaStyleNotification(callId: StreamCallId, mediaNotificationConfig: MediaNotificationConfig, remoteParticipantCount: Int): NotificationCompat.Builder?
Link copied to clipboard
open fun getIncomingCallNotification(fullScreenPendingIntent: PendingIntent, acceptCallPendingIntent: PendingIntent, rejectCallPendingIntent: PendingIntent, callerName: String?, shouldHaveContentIntent: Boolean): Notification?
abstract fun getIncomingCallNotification(fullScreenPendingIntent: PendingIntent, acceptCallPendingIntent: PendingIntent, rejectCallPendingIntent: PendingIntent, callerName: String?, shouldHaveContentIntent: Boolean, payload: Map<String, Any?>): Notification?

Customize the notification when you receive a push notification for ringing call with type RingingState.Incoming

Link copied to clipboard
Link copied to clipboard
open fun getMissedCallNotification(callId: StreamCallId, callDisplayName: String? = null): Notification?
abstract fun getMissedCallNotification(callId: StreamCallId, callDisplayName: String? = null, payload: Map<String, Any?>): Notification?

Customize the notification when you receive a push notification for Missed Call

Link copied to clipboard
open override fun getNotificationUpdates(coroutineScope: CoroutineScope, call: Call, localUser: User, onUpdate: (Notification) -> Unit)

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.

Link copied to clipboard
open fun getOngoingCallNotification(callId: StreamCallId, callDisplayName: String? = null, isOutgoingCall: Boolean = false, remoteParticipantCount: Int = 0): Notification?
abstract fun getOngoingCallNotification(callId: StreamCallId, callDisplayName: String? = null, isOutgoingCall: Boolean = false, remoteParticipantCount: Int = 0, payload: Map<String, Any?>): Notification?

Customize the notification when you receive a push notification for ringing call with type RingingState.Outgoing and RingingState.Active

Link copied to clipboard
open fun getRingingCallNotification(ringingState: RingingState, callId: StreamCallId, callDisplayName: String? = null, shouldHaveContentIntent: Boolean = true): Notification?
abstract fun getRingingCallNotification(ringingState: RingingState, callId: StreamCallId, callDisplayName: String? = null, shouldHaveContentIntent: Boolean = true, payload: Map<String, Any?>): Notification?

Customize the notification when you receive a push notification for ringing call

Link copied to clipboard

Temporary notification. Sometimes the system needs to show a notification while the call is not ready. This is the notification that will be shown.

Link copied to clipboard
abstract suspend fun onCallNotificationUpdate(call: Call): Notification?

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.

Link copied to clipboard
open fun onLiveCall(callId: StreamCallId, callDisplayName: String)
abstract fun onLiveCall(callId: StreamCallId, callDisplayName: String, payload: Map<String, Any?>)

Customize the notification when you receive a push notification for Live Call

Link copied to clipboard
open fun onMissedCall(callId: StreamCallId, callDisplayName: String)
abstract fun onMissedCall(callId: StreamCallId, callDisplayName: String, payload: Map<String, Any?>)

Customize the notification when you receive a push notification for Missed Call

Link copied to clipboard
open fun onNotification(callId: StreamCallId, callDisplayName: String)
abstract fun onNotification(callId: StreamCallId, callDisplayName: String, payload: Map<String, Any?>)

Customize the notification when you receive a push notification for general usage

Link copied to clipboard
abstract fun onPermissionDenied()
Link copied to clipboard
abstract fun onPermissionGranted()
Link copied to clipboard
abstract fun onPermissionRationale()
Link copied to clipboard
abstract fun onPermissionRequested()
Link copied to clipboard
open fun onRingingCall(callId: StreamCallId, callDisplayName: String)
abstract fun onRingingCall(callId: StreamCallId, callDisplayName: String, payload: Map<String, Any?>)

Customize the notification when you receive a push notification for ringing call, which has further two types RingingState.Incoming and RingingState.Outgoing

Link copied to clipboard
abstract suspend fun updateIncomingCallNotification(call: Call, callDisplayName: String): Notification?

Update the ringing call notification.

Link copied to clipboard
abstract suspend fun updateOngoingCallNotification(call: Call, callDisplayName: String): Notification?

Update the ongoing call notification.

Link copied to clipboard
abstract suspend fun updateOutgoingCallNotification(call: Call, callDisplayName: String?): Notification?

Update the ringing call notification.