I have a need to activate the notification LED (if equipped) on Android. Ideally, I can do this in my activity while it is resumed. However API 26 introduced notifications channels, and this has complicated the picture some what. I do not know if it is possible to light the LED while the activity that set it is resumed? It is playing the notification sound and displaying the notification on screen, but the LED is not lighting up.
I create the notification channel in the Application onCreate() by calling this function:
private void createNotificationChannel() {
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
NotificationChannel channel = new NotificationChannel(
CHANNEL_ID,
"NAME",
NotificationManager.IMPORTANCE_HIGH
);
channel.setDescription("Notification Channel");
channel.enableLights(true);
channel.setLightColor(0xFFFFFFFF);
NotificationManager manager = getSystemService(NotificationManager.class);
manager.createNotificationChannel(channel);
}
}
I create the actual notification like this:
Notification n = new NotificationCompat.Builder(this, CHANNEL_ID)
.setContentTitle("RFA")
.setContentText("RFA LED TEST")
.setSmallIcon(R.drawable.icon)
.setPriority(NotificationCompat.PRIORITY_DEFAULT)
.setTimeoutAfter(1000)
.setAutoCancel(true)
.setColor(0xFFFFFFFF)
.setLights(0xFFFFFFFF, 1000, 0)
.build();
NotificationManager notificationManager = (NotificationManager) getSystemService(NOTIFICATION_SERVICE);
notificationManager.notify(0, n);
User contributions licensed under CC BY-SA 3.0