Created
March 10, 2019 14:30
-
-
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.
This file contains 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
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