Reputation: 47
I want to show notifications on lock screen, but I'm unable to get it to work.
This is my code that I have;
.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);
}
The notifications is not showing on the lock screen. The settings for the app allows to show notifications on lock screen.
Any advice?
Upvotes: 2
Views: 2291
Reputation: 469
builder.setOngoing(true)
makes the notification shown on the lock screen.
Upvotes: 4