Skip to content

Instantly share code, notes, and snippets.

@akueisara
Last active June 26, 2022 23:37
Show Gist options
  • Save akueisara/0859ef41ce8aed13d61abaa5b7cdd1f3 to your computer and use it in GitHub Desktop.
Save akueisara/0859ef41ce8aed13d61abaa5b7cdd1f3 to your computer and use it in GitHub Desktop.
val constraints = Constraints.Builder()
.setRequiresCharging(true)
.build()
val work = PeriodicWorkRequestBuilder<MyWorker>(
// repeatInterval (the period cycle), its minimum is 15 minutes
1, TimeUnit.HOURS,
// flexInterval, its minimum is 5 minutes
15, TimeUnit.MINUTES)
.setConstraints(constraints)
.build()
val workManager = WorkManager.getInstance(context)
workManager.enqueuePeriodicWork(work)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment