Slide 61
Slide 61 text
private fun createForegroundInfo(): ForegroundInfo {
val title = "Example title"
//
Pending Intent to cancel the worker
val intent = WorkManager.getInstance(applicationContext)
.createCancelPendingIntent(getId())
createNotificationChannel("channel_id", "Example channel")
val notification = NotificationCompat.Builder(applicationContext, "CHANNEL ID")
.setContentTitle(title)
.setTicker(title)
.setContentText("Running in background
...
")
.setSmallIcon(R.mipmap.ic_launcher)
.setOngoing(true)
.addAction(android.R.drawable.ic_delete, "STOP", intent)
.build()
return ForegroundInfo(42, notification)
}
private val notificationManager =
appContext.getSystemService(Context.NOTIFICATION_SERVICE) as NotificationManager
@TargetApi(Build.VERSION_CODES.O)
private fun createNotificationChannel(
channelId: String,