无论我尝试了什么,但没有通知灯。我正在运行Android 26 Oreo。我的手机仅显示消息和未接来电的闪烁指示灯。
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);
反正有控制LED灯吗?
我遇到了同样的问题,我发现一旦我们为特定的频道ID提供了一个频道NotificationManager.IMPORTANCE_LOW,即使我们稍后改变了重要性,频道仍然具有该重要性,即使重启也不会改变该特定频道ID的重要性。当我们重视NotificationManager.IMPORTANCE_LOW时,对于特定的渠道ID,我们没有得到通知指示灯,并且它保持这种状态,所以我找到的解决方案是卸载应用程序并重新安装它,但这一次重视NotificationManager.IMPORTANCE_DEFAULT或更高版本,或者我们可以完全更改频道ID。并且不仅重要性保持这种方式,对于特定通道ID,对通道上的其他方法的任何调用也保持相同。
mChannel.enableLights(true);
mChannel.setLightColor(Color.RED);
mChannel.setSound(Uri.parse("android.resource://" + getPackageName() + "/" + R.raw.silent),null);