Reputation: 7613
no matter what I tried but there is no notification light. I'm running Android 26 Oreo. My phone only displays blink light for messages and missed calls.
String CHANNEL_ID = "my_channel_01";
NotificationManager nm = (NotificationManager) getSystemService(NOTIFICATION_SERVICE);
CharSequence name = "Name"; // The user-visible name of the channel.
int importance = NotificationManager.IMPORTANCE_HIGH;
NotificationChannel mChannel = null;
if (android.os.Build.VERSION.SDK_INT >= android.os.Build.VERSION_CODES.O) {
mChannel = new NotificationChannel("my_channel_01", name, importance);
mChannel.enableLights(true);
mChannel.setLightColor(Color.GREEN);
mChannel.shouldShowLights();
nm.createNotificationChannel(mChannel);
}
Notification notif = new Notification.Builder(MainActivity.this)
.setSmallIcon(R.mipmap.ic_launcher_2)
.setContentTitle("Blhas")
.setContentText("Subject")
.setSubText("Subtext")
.setColor(Color.RED)
.setLights(255, 0, 0)
.setContentIntent(pIntent)
.setStyle(new Notification.BigTextStyle().bigText("..."))
.setChannelId(CHANNEL_ID)
.setPriority(Notification.PRIORITY_HIGH)
.build();
nm.notify(LED_NOTIFICATION_ID, notif);
Is there anyway to control the LED light?
Upvotes: 4
Views: 1461
Reputation: 1341
I had the same problem,I found out that once we give a channel NotificationManager.IMPORTANCE_LOW for a particular channel ID,the channel remains with that importance,even if we change the importance later,even reboot would not change that for that particular channel ID.When we give the importance to NotificationManager.IMPORTANCE_LOW ,for a particular channel ID,we don't get the notification led light,and it stays that way,so the solutions I found were to uninstall the app and reinstall it again but this time giving the importance to NotificationManager.IMPORTANCE_DEFAULT or higher,or we can change the channel ID completely. And not only importance stays that way,also any call to the other methods on the channel stays the same for a particular channel ID.
mChannel.enableLights(true);
mChannel.setLightColor(Color.RED);
mChannel.setSound(Uri.parse("android.resource://" + getPackageName() + "/" + R.raw.silent),null);
Upvotes: 3