Notification LED in Android
Note: The device I was testing this on was a Motorola Moto G (XT1045) running Android 4.4.4 (API 19).
I’ve never had to do Google Cloud Messaging on Android before, but it’s fairly straightforward. I did have problems with one minor thing, though – for some reason, while I could make the Notification sound chime and the vibrate go when I created a notification to show the message I received, I couldn’t seem to get the notification LED to blink. I could hard-code it with setLights, but I didn’t want to do that, I wanted to be able to make it behave like any other notifications received on the device.
So, what I was trying to do was build it normally with NotificationCompat.Builder, and then just doing this:
Notification notif = mBuilder.build();
notif.defaults |= Notification.DEFAULT_SOUND;
notif.defaults |= Notification.DEFAULT_VIBRATE;
notif.defaults |= Notification.DEFAULT_LIGHTS;
But as I said, the sound and vibrate worked, but lights didn’t. Asking in #android-dev on Freenode, it was suggested I try using
.setDefaults(Notification.DEFAULT_ALL). Amusingly, even though it seems like it should be the same thing effectively, it works.
Searching around, I hadn’t found anything that would have led me to this, so I thought I’d share in case some other poor soul out there faces a similar problem.