我想在锁定屏幕上显示通知,但无法使其正常工作。
这是我的代码;
.setSmallIcon(R.drawable.deleteaccounticon)
.setContentTitle("My notification")
.setContentText("Much longer text that cannot fit one line...")
.setStyle(new NotificationCompat.BigTextStyle()
.bigText("Much longer text that cannot fit one line..."))
.setPriority(NotificationCompat.PRIORITY_HIGH);
builder.setVisibility(NotificationCompat.VISIBILITY_PUBLIC);
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
CharSequence name = "channel1";
String description = "test";
int importance = NotificationManager.IMPORTANCE_HIGH;
NotificationChannel channel = new NotificationChannel(CHANNEL_ID, name, importance);
channel.setDescription(description);
// Register the channel with the system; you can't change the importance
// or other notification behaviors after this
NotificationManager notificationManager = (NotificationManager) getSystemService(NOTIFICATION_SERVICE);
notificationManager.createNotificationChannel(channel);
notificationManager.notify(1,builder.build());
channel.setLockscreenVisibility(VISIBILITY_PUBLIC);
}
通知未在锁定屏幕上显示。该应用程序的设置允许在锁定屏幕上显示通知。
有什么建议吗?
答案 0 :(得分:2)
builder.setOngoing(true)
使通知显示在锁定屏幕上。