gpt4 book ai didi

android - 没有用于通知 Android 的 LED 灯

转载 作者:行者123 更新时间:2023-11-29 02:35:41 28 4
gpt4 key购买 nike

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

最佳答案

我有同样的问题,我发现一旦我们给一个 channel NotificationManager.IMPORTANCE_LOW 对于一个特定的 channel ID, channel 保持那个重要性,即使我们稍后改变重要性,即使重新启动也不会改变那个特定 channel ID。当我们重视 NotificationManager.IMPORTANCE_LOW 时,对于特定 channel ID,我们没有收到通知 LED 灯,它保持这种状态,所以我找到的解决方案是卸载应用程序并重新安装但是这次赋予 NotificationManager.IMPORTANCE_DEFAULT 或更高的重要性,或者我们可以完全更改 channel ID。不仅重要性保持不变,对特定 channel ID 的 channel 上其他方法的任何调用也保持不变。

                    mChannel.enableLights(true);
mChannel.setLightColor(Color.RED);
mChannel.setSound(Uri.parse("android.resource://" + getPackageName() + "/" + R.raw.silent),null);

关于android - 没有用于通知 Android 的 LED 灯,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/47257067/

28 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com