Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Android notificationlight not working

I'm using a notification to let the user now that the service is still running. Now I'd like to use the notificationlight to remind the user. (because it's fancy)

The notification works fine, but the notification light does nothing. Other applications work fine with the notification light, (gtalk, facebook)

it's more or less the example code for notifications with addition of these flags:

notification.ledARGB = 0xff00ff00;
notification.ledOnMS = 100;
notification.ledOffMS = 100;
notification.flags |= Notification.FLAG_SHOW_LIGHTS;

notification.flags |= Notification.FLAG_NO_CLEAR + Notification.FLAG_ONGOING_EVENT;
mNotificationManager.notify(NOTIFICATION_ID, notification);

and

notification.defaults |= Notification.DEFAULT_LIGHTS;

instead doesn't work either.

I'm debugging on a Galaxy Nexus with Android 4.0, but the app's target is Android 2.3.3

EDIT: could this be a problem of permission? If yes, which one? I looked through all and found no matching permission for the notification light.

like image 694
trichner Avatar asked Apr 27 '12 22:04

trichner


2 Answers

I think there is an error with the + operator, you need the OR:

notification.flags |= Notification.FLAG_NO_CLEAR | Notification.FLAG_ONGOING_EVENT;

EDIT: and if you are using flags, I think the right one should be:

notification.flags |= Notification.FLAG_SHOW_LIGHTS
like image 96
nax83 Avatar answered Sep 29 '22 20:09

nax83


On jelly bean devices, led only works if notification priority is set to max or default, please check again. Following snippet of code is working fine for me on jb devices.

notification.setLights(0xFF0000FF,100,3000);
notification.setPriority(Notification.PRIORITY_DEFAULT);

Here I'm showing blue color led for notification which will remain on for 100 ms and off for 3000 ms till user unlocks his device.

And check if you are using NotificationCompat (compatibility) class than ignore setDefaults method and use SetLight, SetSound, Setvibration, etc

like image 25
Pawan Maheshwari Avatar answered Sep 29 '22 21:09

Pawan Maheshwari