Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Cannot use yellow with Android Nougat notification's small icon

I've a problem setting the notification small icon to yellow in Android 7.x

I'm using notification.setColor(Color.YELLOW); while building the notification object. It shows that olive(ish) color instead of yellow.

Also tried to use notification.setColor(Color.argb(255,255,255,0)); but no luck, it shows the same olive(ish) color.

This is how it looks like in Android 7.x

Android 7.1

This is how it looks like in Android 6.x, which is the correct color

Android 6.x

Both images display the same notification with the same code base, but using different Android devices.

I'm using PushWoosh to send/receive push notifications, bellow is the exact code I'm using to create the notification object.

public class NotificationFactory extends AbsNotificationFactory {
@Override
public Notification onGenerateNotification(PushData pushData) {
    PushwooshUserdata pushwooshUserdata = GsonUtil.fromJson(pushData.getExtras().getString("u"), PushwooshUserdata.class);

    //create notification builder
    NotificationCompat.Builder notificationBuilder = new NotificationCompat.Builder(getContext());
    notificationBuilder.setContentTitle("Header");
    notificationBuilder.setContentText("Message");

    //set small icon (usually app icon)
    notificationBuilder.setSmallIcon(R.drawable.notification_icon);
    notificationBuilder.setColor(Color.argb(255,255,255,0));

    //set ticket text
    notificationBuilder.setTicker(getContentFromHtml(pushData.getTicker()));

    //display notification now
    notificationBuilder.setWhen(System.currentTimeMillis());

    //build the notification
    final Notification notification = notificationBuilder.build();

    //add sound
    addSound(notification, pushData.getSound());

    //add vibration
    addVibration(notification, pushData.getVibration());

    //make it cancelable
    addCancel(notification);

    //all done!
    return notification;
}

@Override
public void onPushReceived(PushData pushData) {
}

@Override
public void onPushHandle(Activity activity) {
}
}
like image 513
Ahmed Youssef Avatar asked Nov 29 '16 23:11

Ahmed Youssef


People also ask

How do I change the notification icon on my Android?

1 Tap Notification Settings on the notification panel or tap the Settings app. 2 Tap Notifications. 3 Tap App icon badges.

How do I get rid of the notification icon on my Android?

Tap Notifications > App Settings. In some versions of Android, you'll see your list of apps on the Notifications screen. Tap See All. Find the app with the notifications you want to turn off, and tap the toggle to turn off notifications.

What is the dot icon on Android phone?

While the green dot serves as a useful privacy indicator, not all Android phones have received an upgrade to Android 12. Fortunately, Google makes it easy to control app permissions via Settings. To do this, open the Settings app on an Android phone, tap on Privacy, and then click on Permission Manager.

What's a notification dot?

Starting with 8.0 (API level 26), notification badges (also known as notification dots) appear on a launcher icon when the associated app has an active notification. Users can long-press on the app icon to reveal the notifications (alongside any app shortcuts), as shown in figure 1.


1 Answers

Android is ensuring a minimum contrast ratio between the foreground color and background color.

With the yellow (#ffff35) foreground and a white background, the contrast ratio is only 1.07:1.

The olive foreground (#717d13) has the minimum contrast ratio of 4.5:1.

This is the relevant patch in the Android source: https://android.googlesource.com/platform/frameworks/base.git/+/4ff3b120ff8a788e3afeb266d18caf072f0b8ffb%5E%21/

I calculated the above contrast ratios using http://webaim.org/resources/contrastchecker/.

like image 136
Eric Fikus Avatar answered Nov 15 '22 12:11

Eric Fikus