【发布时间】:2019-08-02 19:05:23
【问题描述】:
我想在锁定屏幕上显示通知,但我无法让它工作。
这是我的代码;
.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);
}
通知未显示在锁定屏幕上。该应用的设置允许在锁定屏幕上显示通知。
有什么建议吗?
【问题讨论】:
-
设置中是否启用了在锁屏中显示通知???
标签: java android android-notifications lockscreen