8

I'm trying to use a Notification that also uses the Notification LED on my S3, but for some reason the color will always be blue (I guess it's the default?). I tried to use different colors but nothing changes. Other apps (like Whatsapp, Gmail and Facebook have no problems with showing a different color light).

Notification.Builder noteBuilder = new Notification.Builder(context)
                .setAutoCancel(true)
                .setPriority(Notification.PRIORITY_DEFAULT)
                .setSmallIcon(R.drawable.ic_launcher)
                .setContentTitle(ContentTitle)
                .setContentText(ContentText)
                .setLights(Color.YELLOW, 500, 500)
                ;

Intent noteIntent = new Intent(context,HoofdScherm.class);
PendingIntent notePendingIntent = PendingIntent.getActivity(context, 0, noteIntent, PendingIntent.FLAG_CANCEL_CURRENT);
noteBuilder.setContentIntent(notePendingIntent);

Notification note = noteBuilder.build();
note.ledARGB = Color.YELLOW;
NotificationManager mgr = (NotificationManager)context.getSystemService(Context.NOTIFICATION_SERVICE);
mgr.notify(0,note);
Luc Kolen
  • 123
  • 1
  • 3
  • 8
  • despite setting color of the LED is part of the API it really works very different on most devices and it wont work on every device. Some use the main color of the launcher icon of the app, some use the type of notification / priority. – Yalla T. Feb 19 '13 at 09:50
  • any changes if you dont set a Priority? also, since you are changing the notification after being build, you should add all steps to create LED light there, too `notification.ledARGB = 0xff00ff00; notification.ledOnMS = 300; notification.ledOffMS = 1000; notification.flags |= Notification.FLAG_SHOW_LIGHTS;` – Yalla T. Feb 19 '13 at 10:01
  • I tried to change the priority (I used DEFAULT, HIGH and I alzo tried not setting it). It didn't make a difference. Next I'll try to use a different icon, but I don't think it will make a difference because apps like light manager can set the notification color on my S3. – Luc Kolen Feb 19 '13 at 10:04
  • adding `notification.defaults = 0;` might also help. – Yalla T. Feb 19 '13 at 10:08
  • 1
    notification.defaults = 0; Worked and my LED is Yellow (the color I wanted) now. Thank you every much, I was stuck on this for over 3 hours – Luc Kolen Feb 19 '13 at 12:31
  • Glad it worked.I added this as an anwser, because the solution hidden somewhere in the comments is not good for other users with the same problem. feel free to accept it. – Yalla T. Feb 19 '13 at 12:43

2 Answers2

11

You need to make sure all the defaults are overridden by setting

notification.defaults = 0;

Yalla T.
  • 3,567
  • 3
  • 19
  • 36
  • this doesnt seem to work for me. where are you setting the defaults to 0? after `Notification note = noteBuilder.build();` but before the `note.ledARGB = Color.YELLOW;` ? i have my priority set to max and I am testing on a nexus 5. – toobsco42 Feb 28 '14 at 09:42
  • So i figured out my issue is that my device was not in sleep mode. You have to make sure the notifications tray has not been pulled down already (i.e. user hasn't looked that the notification). The LED will only flash in this case. http://stackoverflow.com/questions/3297835/how-can-i-enable-vibration-and-lights-using-the-android-notifications-api – toobsco42 Feb 28 '14 at 09:53
  • Still does not work for me. My code: NotificationCompat.Builder notif = new NotificationCompat.Builder(Main.context); notif.setDefaults(0); notif.setLights(Color.YELLOW, 500, 500); notif.notify(); – Tina Mar 14 '18 at 13:57
-1

Have a look on source below. Working perfectly on S3:

 NotificationCompat.Builder mBuilder =
                new NotificationCompat.Builder(ctx)
                        .setPriority(Notification.PRIORITY_HIGH)
                        .setSmallIcon(getNotificationIcon())
                        .setColor(0xff493C7C)
                        .setContentTitle(ctx.getString(R.string.app_name))
                        .setContentText(msg)
                        .setDefaults(Notification.DEFAULT_SOUND)
                        .setLights(0xff493C7C, 1000, 1000)
                        .setStyle(new NotificationCompat.BigTextStyle().bigText(styledMsg));
Ahsanwarsi
  • 963
  • 8
  • 17