Flashing the Lights

Notifications also include properties to configure the color and flash frequency of the device's LED.

Each device may have different limitations with regard to control over the LED. Where the color you specify is not available, as close an approximation as possible will be used. When using LEDs to convey information to the user keep this limitation in mind and avoid making it the only way such information is made available.

The ledARGB property can be used to set the LED's color, while thdedOffMS and ledOnMS properties let you set the frequency and pattern of the flashing LED. You can turn the LED on by setting the ledOnMS property to 1 and the ledOffMS property to 0, or turn it off by setting both properties to 0.

Once you have configured the LED settings you must also add the flag_show_lights flag to the Noti-fication'flags property.

The following code snippet shows how to turn on the red device LED:

notification.ledARGB = Color.RED; notification.ledOffMS =0; notification.ledOnMS = 1;

notification.flags = notification.flags | Notification.FLAG_SHOW_LIGHTS;

Controlling the color and flash frequency gives you another opportunity to pass additional information to users.

In the earthquake-monitoring example you can help your users perceive the nuances of an exponential scale by also using the device's LED to help convey the magnitude. In the following snippet the color of the LED depends on the size of the quake, and the frequency of the flashing is inversely related to the power of the quake:

int color;

color = Color.GREEN; else if (quake.getMagnitude() < 6)

color = Color.YELLOW; else color = Color.RED;

newEarthquakeNotification.ledARGB = color; newEarthquakeNotification.ledOffMS = (int)vibrateLength; newEarthquakeNotification.ledOnMS = (int)vibrateLength; newEarthquakeNotification.flags = newEarthquakeNotification.flags |

Notification.FLAG_SHOW_LIGHTS;

The current Android Emulator does not visually illustrate the LEDs.

Mobile Apps Made Easy

Mobile Apps Made Easy

Quick start guide to skyrocket your offline and online business success with mobile apps. If you know anything about mobile devices, you’ve probably heard that famous phrase coined by one of the mobile device’s most prolific creators proclaiming that there’s an app for pretty much everything.

Get My Free Training Guide


Post a comment