Package 

Class CompatibilityStreamNotificationHandler

  • All Implemented Interfaces:
    io.getstream.android.push.permissions.NotificationPermissionHandler , io.getstream.video.android.core.notifications.NotificationHandler , io.getstream.video.android.core.notifications.StreamNotificationDispatcher , io.getstream.video.android.core.notifications.handlers.StreamNotificationHandler , io.getstream.video.android.core.notifications.handlers.StreamNotificationHandlerWithPayload , io.getstream.video.android.core.notifications.handlers.StreamNotificationProvider , io.getstream.video.android.core.notifications.handlers.StreamNotificationProviderWithPayload , io.getstream.video.android.core.notifications.handlers.StreamNotificationUpdatesProvider , io.getstream.video.android.core.notifications.handlers.StreamSettingUpCallNotificationProvider , io.getstream.video.android.core.notifications.medianotifications.MediaNotificationHandler

    
    public class CompatibilityStreamNotificationHandler
    extends StreamDefaultNotificationHandler implements 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.

    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
                }
            }
    )