Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Android max. size of custom notification

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?

like image 877
Michael Tran Avatar asked Jan 29 '19 08:01

Michael Tran


1 Answers

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

like image 183
Liar Avatar answered Oct 13 '22 13:10

Liar