Search code examples
javaandroidcolorsnotificationslight

Nexus 5 Notification Light Color


I am using a Nexus 5 (SDK 4.4.4) and I try to send some notifications with different colors. I tried to test the colors with a simple code :

 @Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);

    NotificationManager notif = (NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE);

    for (int i = 0; i < 8; i++) {
        notif.cancel(1); // clear previous notification
        final Notification notification = new Notification();
        if (i == 0){
            notification.ledARGB = Color.MAGENTA;
        }else if (i == 1){
            notification.ledARGB = Color.BLUE;
        }else if (i == 2){
            notification.ledARGB = Color.CYAN;
        }else if (i == 3){
            notification.ledARGB = Color.GRAY;
        }else if (i == 4){
            notification.ledARGB = Color.GREEN;
        }else if (i == 5){
            notification.ledARGB = Color.RED;
        }else if (i == 6){
            notification.ledARGB = Color.WHITE;
        }else if (i == 7){
            notification.ledARGB = Color.YELLOW;
        }
        notification.ledOnMS = 1000;
        notification.flags |= Notification.FLAG_SHOW_LIGHTS;
        notif.notify(1, notification);
        try {
            Thread.sleep(1000);
        } catch (InterruptedException e) {
            e.printStackTrace();
        }
    }
}

This code is supposed to send 8 different color notifications. What my mobile actually does, is to replicate 3 colors, blue, red and magenta. The rest of the colors doesn't seems to work.

Of course, the other colors should actually work, as Light Flow application succeeds to send notifications with colors like Green, etc.

What could be the problem here? Is there another code that could actually work?


Solution

  • I tried again to compile this program and I figured out the solution.

    For everyone else having the same problem, after I ran the program multiple times, colors started to show and after a restart of my phone this program works perfectly now.