Android max. size of custom notification
Asked Answered
A

2

7

I'm trying to create some custom notifications for my app.

Usually collapsed view layouts are limited to 64 dp, and expanded view layouts are limited to 256 dp.

Although I considered these restrictions, it seems that the notification is cut off on several phones as you can see in the screenshots below. I did some research on that because I thought there are also restrictions depending on different manufacturers or UIs, but couldn't find anything.

That's how it is implemented:

// 64dp is set for height
val collapsedView = RemoteViews(packageName, R.layout.custom_notification_collapsed)
// 256dp is set for height
val expandedView = RemoteViews(packageName, R.layout.custom_notification_expanded)

val customNotification: Notification = NotificationCompat.Builder(this, "default")
        .setSmallIcon(R.drawable.ic_launcher_background)
        .addAction(R.drawable.ic_map, "Personal", PendingIntent.getService(this, 0, personalIntent, PendingIntent.FLAG_UPDATE_CURRENT))
        .addAction(R.drawable.ic_map, "Business", PendingIntent.getService(this, 0, businessIntent, PendingIntent.FLAG_UPDATE_CURRENT))
        .addAction(R.drawable.ic_map, "Work", PendingIntent.getService(this, 0, businessIntent, PendingIntent.FLAG_UPDATE_CURRENT))
        .setColor(Color.parseColor("#00D8FF"))
        .setStyle(NotificationCompat.DecoratedCustomViewStyle())
        .setCustomContentView(collapsedView)
        .setCustomBigContentView(expandedView)
        .build()

notificationManager.notify(4, customNotification)

Here's the result:

Xiaomi Mi Mix2

Samsung Galaxy Note 8

Now the questions are: Did I fail the implementation somehow? If not, is there a way to figure out the max. notification height for a current phone programmatically?

Adamec answered 29/1, 2019 at 8:53 Comment(0)
W
2

Notification (your RemoteView) that you see is created by another process and only that process can know the size

There is no official way to get the max height for custom notification. I think the only way you can do is to reduce the text size

Wateriness answered 29/1, 2019 at 9:21 Comment(0)
F
0

They are cut off because of the actions you are adding try to remove the actions you will get your full 256/64 dp.

Finbar answered 3/4, 2020 at 7:49 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.