没有LED指示灯的安卓通知

4
无论我尝试了什么,都没有通知灯。 我正在运行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 灯?

一些手机不支持它。 - SpyZip
你解决了这个问题吗? - Nolesh
1个回答

3
我遇到了相同的问题,我发现一旦我们为特定的通道ID提供了NotificationManager.IMPORTANCE_LOW级别,该通道将保持这个重要性,即使我们稍后更改了这个重要性,甚至重启也不会改变那个特定的通道ID。当我们为一个特定的通道ID设置NotificationManager.IMPORTANCE_LOW,我们将无法收到通知LED灯,并且它将保持这种状态,所以我找到的解决方案是卸载应用程序并重新安装,但这次将重要性设置为NotificationManager.IMPORTANCE_DEFAULT或更高,或者我们可以完全更改通道ID。而且,对于一个特定的通道ID,任何对通道上的其他方法的调用都将保持不变。
                    mChannel.enableLights(true);
                    mChannel.setLightColor(Color.RED);
                    mChannel.setSound(Uri.parse("android.resource://" + getPackageName() + "/" + R.raw.silent),null);

非常感谢!!!我已经寻找这个答案半年了。 - yW0K5o

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接