Skip to content

How to configure the LED

The LED on the Famoco devices can be used for notification purposes by varying the duration and color.

The colour

The color can be modified by changing the value of the notif.ledARGB variable.

The prefix, 0x, never changes, it indicates that the following values are hexadecimal numbers. The following 6 digits correspond to RGB values and the last 2 correspond to the overall transparency.

Here is an example for a simple red color:

prefix R G B Transparency
0x ff 00 00 00

The duration

The duration of the led can be controlled by changing the notif.ledOnMS which controls the "on time" and the notif.ledOffMS which controls the "off time"

Here is a sample code for android 6 and 8. It is no longer possible to control the LEDs on Android 10.

Code Snippet

     public static Notification creatNotification(Context context, int color) {
         if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O_MR1) {
             return createNotificationWithNotificationChannel(context, color);
         } else {
             return createNotification(context, color);
         }
     }

     private static Notification createNotificationWithNotificationChannel(Context context, int color) {
         NotificationManager nm = (NotificationManager) context.getSystemService(Context.NOTIFICATION_SERVICE);

         NotificationChannel channel = new NotificationChannel(LED_NOTIFICATION_CHANNEL_ID,
                 LED_NOTIFICATION_CHANNEL_NAME, NotificationManager.IMPORTANCE_DEFAULT);
         channel.enableLights(true);
         channel.setLightColor(color);
         channel.setSound(null, null);
         nm.createNotificationChannel(channel);

         Notification.Builder b = new Notification.Builder(context, LED_NOTIFICATION_CHANNEL_ID);
         Notification notif = b
                 .setSmallIcon(R.drawable.icon)
                 .build();
         return notif;
     }

     private static Notification createNotification(Context context, int color) {
         NotificationCompat.Builder b = new NotificationCompat.Builder(context);
         // Android 6.0 requires that the notification has a small icon
         b.setSmallIcon(R.drawable.icon);

         Notification notif = b.build();
         notif.defaults = 0;
         notif.ledARGB = color;
         notif.flags = Notification.FLAG_SHOW_LIGHTS;
         notif.ledOnMS = 100;
         notif.ledOffMS = 100;

         return notif;
    }

Note: This function is not available when the device is charging.