我认为Android 8.0中的抬头通知禁用,但即使在运行Android 8.0时,android的内置消息也具有此功能.我知道如何通过设置振动通知来显示低于8.0设备的抬头通知.但是,运行Oreo的通知上的振动已被弃用.所以我去互联网搜索,有人说启用setVibrationPattern到通知通道将起作用.但遗憾的是,这不起作用.
所以这是我的代码.
Notification builder = new NotificationCompat.Builder(MainActivity.this)
.setAutoCancel(true)
.setWhen(System.currentTimeMillis())
.setSmallIcon(R.drawable.ic_android_black_24dp)
.setChannelId(id)
.setPriority(Notification.PRIORITY_HIGH)
.setColor(setActionColor(counter))
.setColorized(true)
.setContentIntent(pendingIntent)
.build();
//Notification channel code.
NotificationChannel chan2 = new NotificationChannel(SECONDARY_CHANNEL,
getString(R.string.noti_channel_second), NotificationManager.IMPORTANCE_HIGH);
chan2.setLightColor(Color.BLUE);
chan2.setLockscreenVisibility(Notification.VISIBILITY_PUBLIC);
manager.createNotificationChannel(chan2);
manager.notify(notificationID, builder);
Run Code Online (Sandbox Code Playgroud) android ×1