NotificationCompat.Builder setLights (); does not work

I am trying to use the LED on my notification and it does not work, I have this code:

NotificationCompat.Builder nBuilder = new NotificationCompat.Builder(getApplicationContext()); nBuilder.setLights(Color.CYAN, 1000, 500); 

All notification works, for example ContentTitle, ContentText, and a notification is displayed, but only the LED does not work.

Is there something wrong with my code? Should I use Notification instead of NotificationCompact.Builder ?

+5
source share
2 answers

The notification LED is turned on by the operating system on the device only if the notification is activated when the device screen is off.

+12
source

Your code cannot work because you need to pass three variables:

  • color
  • if you turn on the LED
  • if the LED is off

if you turn on 2 and 3, your LED will blink; if you turn off 2 and 3, the LED will be off.

 NotificationCompat.Builder mBuilder = new NotificationCompat.Builder(context ); mBuilder.setLights(Color.RED, 1, 1); // will blink 
+3
source

Source: https://habr.com/ru/post/1200171/


All Articles