作者热门文章
- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
在 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/
我是一名优秀的程序员,十分优秀!