Created
December 26, 2019 20:43
-
-
Save Lavanyagaur22/897f1e49a641c251cbd5dc681b237719 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 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