Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Why LED setting for android notification doesn't work

I try to set the LED to a different color and speed for my notification it works on one device (running Lolipop) but not work on other device (running Marshmallow).

Can this be because the Android version or is my code setting incorrect?

NotificationCompat.Builder mBuilder = new NotificationCompat.Builder(context)
            .setContentTitle(title)
            .setSmallIcon(notify)
            .setContentText(body)
            .setPriority(2)
            .setTicker("Notification received")
            .setAutoCancel(true)
            .setLights(Color.WHITE, 250, 250)
            .setVibrate(pattern);

Please forgive me for my English and maybe improper question format.

Thank you very much for an explanation of my problem!


1 Answers

I had a similar issue that was discovered long after the app was pushed to the users. As CommonsWare stated, I would highly recommend that you do not rely on the vibration or LED too heavily. You can use it, but don't use it as the primary feature that differentiates between notifications.

As for the reason why it doesn't work consistently, this is just normal Android behavior. Different manufacturers create their devices differently and code that is affecting hardware like this will not always provide consistent results.

I will say, however, that my particular issue was fixed by using:

notifications.ledARGB = 0xffffffff;

for a white LED. This is what worked for my Marshmallow version on a Galaxy S6 from AT&T while different code worked for my Note 3 Verizon device running Lolipop at the time. (I don't remember the exact code I used for that though).

Either way, try a few different things. You might have to do a version check in your code and code accordingly.

Disclaimer: I am no expert. I code as a hobby, so if someone else has a better answer and higher rep you will most likely want to go with their answer ;)

like image 125
Ryan Avatar answered Apr 16 '26 01:04

Ryan



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!