Skip to content

Instantly share code, notes, and snippets.

@Lavanyagaur22
Created December 26, 2019 20:43
Show Gist options
  • Save Lavanyagaur22/897f1e49a641c251cbd5dc681b237719 to your computer and use it in GitHub Desktop.
Save Lavanyagaur22/897f1e49a641c251cbd5dc681b237719 to your computer and use it in GitHub Desktop.
// NotificationRequestWorker extends the worker class which defines the work to be performed by the worker.
class NotificationRequestWorker(val context: Context, workerParameters: WorkerParameters) :
Worker(context, workerParameters) {
override fun doWork(): Result {
// Do the work here
val nm = context.getSystemService(Context.NOTIFICATION_SERVICE) as NotificationManager
val notification = NotificationCompat.Builder(context, "first").apply {
setContentTitle("Background task")
setContentText("Sample text")
setSmallIcon(R.drawable.ic_launcher_foreground)
priority = NotificationCompat.PRIORITY_DEFAULT
}.build()
nm.notify(System.currentTimeMillis().toInt(), notification)
// Indicate whether the task finished successfully with the Result
return Result.success()
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment