Reputation: 5856
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 ?
Upvotes: 9
Views: 5012
Reputation: 7240
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
Upvotes: 5