addLED

protected fun addLED(notification: Notification, color: Integer, ledOnMs: Int, ledOffMs: Int)

Adds LED blinking effect to the notification.

On devices with notification LEDs, this method configures the LED color and blink pattern. The LED provides a visual indicator that a notification has arrived, useful when the device screen is off.

Android 8.0+ Note: LED settings are controlled by notification channels and cannot be changed after the channel is created. This method works best for new channels or on devices running Android 7.1 and lower.

Important: LED functionality depends on the device having a notification LED and the user's system settings. Many modern devices have removed physical notification LEDs. Example - Add custom LED color:


	  
	  public Notification onGenerateNotification(@NonNull PushMessage data) {
	      String channelId = addChannel(data);
	      NotificationCompat.Builder builder = new NotificationCompat.Builder(
	          getApplicationContext(), channelId)
	          .setContentTitle(data.getHeader())
	          .setContentText(data.getMessage())
	          .setSmallIcon(R.drawable.ic_notification);
	
	      Notification notification = builder.build();
	
	      // Blue LED blinking: 1 second on, 2 seconds off
	      addLED(notification, 0xFF0000FF, 1000, 2000);
	
	      return notification;
	  }
	
Example - Use LED from push payload:

	  
	  public Notification onGenerateNotification(@NonNull PushMessage data) {
	      String channelId = addChannel(data);
	      NotificationCompat.Builder builder = new NotificationCompat.Builder(
	          getApplicationContext(), channelId)
	          .setContentTitle(data.getHeader())
	          .setContentText(data.getMessage())
	          .setSmallIcon(R.drawable.ic_notification);
	
	      Notification notification = builder.build();
	
	      // Use LED settings from push payload
	      addLED(notification, data.getLed(), data.getLedOnMS(), data.getLedOffMS());
	
	      return notification;
	  }
	

Parameters

notification

The notification to add LED effect to

color

LED color in ARGB format (e.g., 0xFFFF0000 for red), or null to use default color

ledOnMs

Duration the LED should be lit in milliseconds

ledOffMs

Duration the LED should be off in milliseconds

See also