9
votes

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);
2
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.
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.
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
adding notification.defaults = 0; might also help. - Yalla T.
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

2 Answers

11
votes

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

notification.defaults = 0;

-1
votes

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));