How to make custom notification view with jetpack compose?
Asked Answered
U

1

9

I wanted to make a custom notification view with content being updated in interval of time. The custom view might contain the action button. In android documentation, we can create custom view using XML layout docs: https://developer.android.com/training/notify-user/custom-notification

// Get the layouts to use in the custom notification
val notificationLayout = RemoteViews(packageName, R.layout.notification_small)
val notificationLayoutExpanded = RemoteViews(packageName, R.layout.notification_large)

// Apply the layouts to the notification
val customNotification = NotificationCompat.Builder(context, CHANNEL_ID)
        .setSmallIcon(R.drawable.notification_icon)
        .setStyle(NotificationCompat.DecoratedCustomViewStyle())
        .setCustomContentView(notificationLayout)
        .setCustomBigContentView(notificationLayoutExpanded)
        .build()

So can we make our own custom notification view using jetpack compose ?

Unhelm answered 28/2, 2022 at 3:5 Comment(0)
P
5

As of now, we can't use androidx.compose.ui.platform.ComposeView in custom remote view layout file. And currently, there is no alternative to it also

The only way we achieve custom notification is via remote views but currently, remote view doesn't support ComposeView ... even if it supports it will not be worth since it wont support all API levels

For more info here are the widgets/views supported in remote views

https://developer.android.com/reference/android/widget/RemoteViews

Pasquale answered 24/3, 2022 at 13:46 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.