JIAJIA LI
JIAJIA LI

Reputation: 1

How to fully customize notifications

When I try to create a custom notification, there is always an expand button in the upper right corner,And I've seen notifications from other software that are custom layouts,And there is no expand button,This is all on Android 14.

This is my code:

val remoteViews = RemoteViews(
    context.packageName,
    R.layout.test_layout
)

val decoratedCustomViewStyle = NotificationCompat.DecoratedCustomViewStyle()
val build = NotificationCompat.Builder(context, channelId)
    .setSmallIcon(R.drawable.test_icon)
    .setDefaults(0)
    .setCustomContentView(
        remoteViews
    )
    .build()

notificationManager.notify(1, build)

Here is a comparison picture, the first one is my notice:enter image description here,

I've seen the message :Apps targeting Android 12 (API level 31) or later can't create fully custom notifications. Instead

Upvotes: 0

Views: 21

Answers (0)

Related Questions