gpt4 book ai didi

java - 奥利奥 - 闪烁通知 LED

转载 作者:行者123 更新时间:2023-11-30 10:07:47 25 4
gpt4 key购买 nike

在 oreo 中如何启用通知 LED 闪烁而没有通知声音,如果我禁用通知声音 LED 不闪烁

  Notification notification = new NotificationCompat.Builder(this)
.setLights(0xff00ff00, 3000, 100)
// .setContentTitle("title")
.setSmallIcon(R.drawable.cubs)
.setOngoing(false)
.setSound(null)
.setPriority(Notification.PRIORITY_MAX).build();
NotificationManager notificationManager =
(NotificationManager) getSystemService(NOTIFICATION_SERVICE);
notificationManager.notify(notification_id, notification);

最佳答案

从Oreo开始,引入了NotificationChannel的机制。您必须像这样设置 channel 并启用灯光,

NotificationManager notificationManager = (NotificationManager) getSystemService(NOTIFICATION_SERVICE);

if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
CharSequence name = "Notification";
String description = "Notification";
int importance = NotificationManager.IMPORTANCE_DEFAULT;
NotificationChannel mChannel = new NotificationChannel("someChannelID", name, importance);
mChannel.setDescription(description);
mChannel.setShowBadge(true);
mChannel.enableLights(true);
mChannel.setLightColor(Color.RED);
mChannel.setSound(uri);
if (notificationManager != null) notificationManager.createNotificationChannel(mChannel);
Notification notification = new Notification.Builder(context, "someChannelID")
.setContentTitle(contentTitleText)
.setContentText(contentContentText)
.setNumber(1)
.setSmallIcon(whiteLogo)
.setBadgeIconType(whiteLogo)
.setAutoCancel(true)
.setContentIntent(pendingIntent)
.build();
if (notificationManager != null) {
notificationManager.notify(notification_id, notification);
}
}

else {
NotificationCompat.Builder notification = new NotificationCompat.Builder(this)
.setSmallIcon(whiteLogo)
.setLargeIcon(largeIcon)
.setContentTitle(contentTitleText)
.setContentText(contentContentText)
.setOngoing(false)
.setNumber(1)
.setPriority(NotificationCompat.PRIORITY_DEFAULT)
.setAutoCancel(true)
.setLights(colorPPDOrange, 1000, 2000);
.setSound(uri);
.setContentIntent(pendingIntent)
.build();
if (notificationManager != null) {
notificationManager.notify(notification_id, notification);
}
}

关于java - 奥利奥 - 闪烁通知 LED,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/54089351/

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