Logo Icon Logo
A Crowd-sourced Cookbook on Writing Great Android® Apps
GitHub logo Twitter logo OReilly Book Cover Art
Using LED-Based NotificationsBack to Android Cookbook Home | Up to Chapter: System and Device Control

Author: Rachee Singh ('racheesingh')
In Published Edition? Yes
FormatLanguage: WikiFormat

Using LED-Based Notifications


Some Android phones are equipped with LEDs. An application can flash different color lights using the LED.


Using the NotificationManager and Notification class we can make notifications using the LED on the device.


As is in case of all notifications, we instantiate the NotificationManager class. Then we create a Notification class's object. Using the method ledARGB() we can specify the color of the LED light. The constant ledOnMS is used to specify the time in milliseconds for which the LED will be on and ledOffMS specifies the time in milliseconds for which the LED is off. The notify method starts the notification process. Here's the code corresponding to the actions just described:

NotificationManager notificationManager = (NotificationManager)getSystemService(NOTIFICATION_SERVICE);
Notification notification = new Notification();
notification.ledARGB = 0xff0000ff;          // Blue color light flash
notification.ledOnMS = 1000;                // LED is on for 1 second
notification.ledOffMS = 1000;               // LED is off for 1 second
notification.flags = Notification.FLAG_SHOW_LIGHTS;
notificationManager.notify(0, notification);

See Also