Our app has some services and intent-services that starts running when the user starts the app. These components needs to be started to continue the process running even if the user minimize the app.
On Android Oreo our app started crashing due the missing initialization of these services using startForegroundService(:intent)
and startForeground(:id, :notification)
. We've fixed it attaching these notifications as requerested but we discovered a strange behaviour. These notifications appear even if the app is in foreground, since it doesn't make sense because our services are really short-running almost all the time, but it needs to be guaranteed to run 100% of the time. That's why the process runs on a service and not in the activity's context. I would like to show these notifications only when the user minimize the app and the service is up.
Is there any way to do it?
I can't change this message, very annoying!
Here is some code used to create the channel:
const val SERVICE_CHANNEL_ID = "com.myFunnyApp.notifications"
//.....
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
val notificationService = context.getSystemService(Context.NOTIFICATION_SERVICE)
(notificationService as? NotificationManager)?.let { notificationManager ->
if (notificationManager.getNotificationChannel(SERVICE_CHANNEL_ID) == null) {
val channel = NotificationChannel(
SERVICE_CHANNEL_ID,
context.resources.getString(R.string.test),
NotificationManager.IMPORTANCE_MIN)
channel.lockscreenVisibility = Notification.VISIBILITY_PUBLIC
notificationManager.createNotificationChannel(channel)
return
}
}
}
On the service, the code runs:
val notification = Notification.Builder(context, SERVICE_CHANNEL_ID)
.setSubText("subText") //Not working
.setContentText("contentText") //Not working
.setSettingsText("settingsText") //Not working
.setContentTitle("title") //Not working
.build()
startForeground(1, notification)
Currently I am testing on the emulator, I don't have any Android Oreo device.
Thanks!
EDIT 1: The text only changes if you set the small icon.