Skip to content

Instantly share code, notes, and snippets.

@aruke
Created March 10, 2019 14:30
Show Gist options
  • Save aruke/d242b59efc9a3ce4e46590c1f97969a9 to your computer and use it in GitHub Desktop.
Save aruke/d242b59efc9a3ce4e46590c1f97969a9 to your computer and use it in GitHub Desktop.
Gists to embed in WorkManager blog. Full code is available at https://github.com/aruke/WorkManagerDemo.
fun buildPeriodicRequest(secretKey: String, userData: Array<String>): PeriodicWorkRequest {
val inputData = Data.Builder()
.putString(KEY_SECRET_KEY, secretKey)
.putStringArray(KEY_USER_DATA, userData)
.build()
val constraints = Constraints.Builder()
.setRequiredNetworkType(NetworkType.CONNECTED)
.setRequiresCharging(true).build()
return PeriodicWorkRequest.Builder(NetworkWorker::class.java, 6, TimeUnit.HOURS)
.setInputData(inputData)
.setConstraints(constraints)
.setBackoffCriteria(BackoffPolicy.EXPONENTIAL, 15, TimeUnit.MINUTES)
.build()
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment