1

I need to display a notification with text, image and two buttons. I'm using NotificationCompat from support library and everything works great until I start to test it on different devices.

Here's the same notification on 3 different devices:

Screenshots of 3 different devices

There are some problems here:

Device 1 (Nexus 5, 6.0): message text is missing, image is cropped.
Device 2 (Emulator, 7.0): image is heavily cropped
Device 3 (Xiaomi mi5s, 6.0): message text is missing, action text is black and is almost invisible

Other defects I was able to reproduce: white action icons on white background; image not being displayed (samsung galaxy s8 plus, android 7.0); action buttons not being displayed.

In the end, two biggest problems are: some parts of notification not showing and action icons or action texts having almost the same color as background.

Here's my code to show the notification:

    NotificationCompat.Builder builder = new NotificationCompat.Builder(context);
    builder.setContentTitle("Test title");
    builder.setContentText("Test notification text description");
    builder.setAutoCancel(true);
    builder.setSmallIcon(R.drawable.ic_launcher);
    builder.setSound(Settings.System.DEFAULT_NOTIFICATION_URI);
    builder.setContentIntent(pendingIntentContent);

    NotificationCompat.Style style;
    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN && image != null) {
        style = new NotificationCompat.BigPictureStyle().bigPicture(image);
        builder.setStyle(style);
    }

    builder.addAction(R.drawable.ic_share_vector, "SHARE", pendingIntentShare);

    if(pendingIntentBookMark != null){
        builder.addAction(R.drawable.ic_bookmark, "SAVE", pendingIntentBookMark);
    }
    return builder.build();

I was considering using my own layout, but I can't find a way to understand what is the main color of the device. Some devices use white notifications on black background, some use black notifications on black background and so on. Notification will look alien if it uses a different color.

I understand that I can blame particular devices for this problems, but I still need my notifications to work pretty much anywhere and look more or less consistently (without major glitches such as invisible text or missing elements).

Is there a way to set action buttons background and text color so they will always be visible?

Is there a way to know which colors does device use for its notifications area and for notification backgrounds?

Is there something other than BigPictureStyle that I can use?

I just hope that somebody had the same issues and found any sort of workaround.

Alexey
  • 7,262
  • 4
  • 48
  • 68
  • Asking for recommendations of libraries is considered to be off-topic on Stack Overflow. Beyond that, your problem has little to do with a library, other than perhaps whatever version of the support libraries (`NotificationCompat.Builder`, etc.) you are using. You do not control absolute formatting over the `Notification`, except if you use the `RemoteViews` option. The OS controls things like maximum height. Xiaomi is probably expecting an image with a light background and has bugs when the image has a dark background. – CommonsWare May 29 '17 at 15:38

0 Answers0