I have already gone to:
However, I am not seeing a notification in the lock screen of my Android phone (Xiaomi Redmi 5A, Nougat). By the way, I am notifying locally. There's no push notification or GCM involved.
I tested the Gmail app, it is working fine. The Gmail notifications are showing in the lock screen.
Did I build the notification incorrectly? How should I build then?
private fun showNotificationWith(message: String) {
val channelId = "com.example.notif.channelId"
val channelName = "App status"
val contentTitle = "Title"
val notificationManager = applicationContext.getSystemService(Context.NOTIFICATION_SERVICE) as NotificationManager
val notificationBuilder = NotificationCompat.Builder(this, channelId)
.setSmallIcon(R.drawable.ic_small_exclamation)
.setContentTitle(contentTitle)
.setContentText(message)
.setPriority(NotificationCompat.PRIORITY_HIGH)
.setVisibility(NotificationCompat.VISIBILITY_PUBLIC)
.setSound(Settings.System.DEFAULT_NOTIFICATION_URI)
if (android.os.Build.VERSION.SDK_INT >= android.os.Build.VERSION_CODES.O) {
val importance = NotificationManager.IMPORTANCE_HIGH
val notificationChannel = NotificationChannel(channelId, channelName, importance)
notificationBuilder.setChannelId(channelName)
notificationManager.createNotificationChannel(notificationChannel)
notificationManager.notify(message.hashCode(), notificationBuilder.build())
} else {
notificationManager.notify(message.hashCode(), notificationBuilder.build())
}
}
Try this...
You can use lockscreenVisibility
property of NotificationChannel.ie.,
notificationChannel.lockscreenVisibility = Notification.VISIBILITY_PUBLIC
For example,
if (android.os.Build.VERSION.SDK_INT >= android.os.Build.VERSION_CODES.O) {
val importance = NotificationManager.IMPORTANCE_HIGH
val notificationChannel = NotificationChannel(channelId, channelName, importance)
notificationChannel.lockscreenVisibility = Notification.VISIBILITY_PUBLIC
notificationBuilder.setChannelId(channelName)
notificationManager.createNotificationChannel(notificationChannel)
notificationManager.notify(message.hashCode(),
notificationBuilder.build())
} else {
notificationManager.notify(message.hashCode(), notificationBuilder.build())
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With