I encountered a problem with Samsung Galaxy S7 Edge showing a popup notification every time I use startForeground()
in my foreground service for status update in its notification.
Firstly, this issue was present on all Android 8.0 devices but was easily fixed with my notification channel priority set to IMPORTANCE_LOW
. But the problem remains for the Samsung device.
So, the question is, how do I update my foreground service notification silently on Samsung 8.0+ devices?
My code is as follows.
Application class:
override fun onCreate() {
super.onCreate()
//other code
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
notificationManager.createNotificationChannels(listOf(
//
NotificationChannel(MY_NOTIFICATION_CHANNEL, "My channel", NotificationManager.IMPORTANCE_LOW).apply {
setSound(null, null)
}
//
))
}
}
Service starting foreground:
val notification = NotificationCompat.Builder(this, MY_NOTIFICATION_CHANNEL)
.setSmallIcon(android.R.drawable.stat_sys_warning)
.setColor(App.context().resources.getColor(R.color.primary_dark))
.setContentText(if (/*logic*/) "This" else "That")
.addAction(0, if (enable) "Disable" else "Enable", firstIntent)
.addAction(0, "Another action", secondIntent)
.build()
startForeground(MY_NOTIFICATION_ID, notification)
I've been investigating the same. Best you could do is create the notification without a channel. Service starts with nothing in the tray. Seems to work for me.
NotificationCompat.Builder(this)
However, this constructor is deprecated in 26.1.0
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