Blinking the Lights Android

Blinking lights are a great way to pass information silently to the user when other forms of alert are not appropriate. The Android SDK provides reasonable control over a multicolored indicator light, when such a light is available on the device. Users might recognize this light as a service indicator or battery level warning. An application can take advantage of this light as well, by changing the blinking rate or color of the light.

You must set a flag on the Notification object to use the indicator light. Then, the color of the light must be set and information about how it should blink. The following block of code configures the indicator light to shine green and blink at rate of 1 second on and 1 second off:

notify.flags |= Notification.FLAG_SHOW_LIGHTS;
notify.ledARGB = Color.GREEN;
notify.ledOnMS = 1000;
notify.ledOffMS = 1000;

Although you can set arbitrary color values, a typical physical implementation of the indicator light has three small LEDs in red, green, and blue. Although the colors blend reasonably well, they won’t be as accurate as the colors on the screen. For instance, on the T-Mobile G1, the color white looks a tad pink.

An application can use different colors and different blinking rates to indicate different information to the user. For instance, the more times an event occurs, the more urgent the indicator light could be. The following block of code shows changing the light based on the number of notifications that have been triggered:

notify.flags |= Notification.FLAG_SHOW_LIGHTS;
if(notify.number < 2) {
notify.ledARGB = Color.GREEN;
notify.ledOnMS = 1000;
notify.ledOffMS = 1000;
} else if (notify.number < 3) {
notify.ledARGB = Color.BLUE;
notify.ledOnMS = 750;
notify.ledOffMS = 750;
} else if (notify.number < 4) {
notify.ledARGB = Color.WHITE;
notify.ledOnMS = 500;
notify.ledOffMS = 500;
} else {
notify.ledARGB = Color.RED;
notify.ledOnMS = 50;
notify.ledOffMS = 50;

The blinking light continues until the Notification is cleared by the user. The use of the Notification.FLAG_INSISTENT flag does not affect this as it does vibration effects.

Color and blinking rates could also be used to indicate other information. For instance, temperature from a weather service could be indicated with red and blue plus blink rate. Use of such colors for passive data indication can be useful even when other forms would work. It is far less intrusive than annoying, loud ringers or harsh, vibrating phone noises. For instance, a simple glance at the handset could tell the user some useful piece of information without the need to launch any applications or change what they are doing.

Face Book Twitter Google Plus Instagram Youtube Linkedin Myspace Pinterest Soundcloud Wikipedia

All rights reserved © 2018 Wisdom IT Services India Pvt. Ltd Protection Status

Android Topics