Skip to content

Instantly share code, notes, and snippets.

View akueisara's full-sized avatar
🎹

Kuei-Jung Hu akueisara

🎹
View GitHub Profile
@akueisara
akueisara / CancelWork.kt
Last active June 26, 2022 16:29 — forked from ceruleanotter/SimpleWorkStatusObservation.kt
WorkManager Basics: WorkStatus Observation
WorkManager.getInstance().cancelWorkById(uploadWorkRequest.id)
WorkManager.getInstance().cancelAllWorkByTag("sometag")
@akueisara
akueisara / SimpleChain.kt
Last active June 25, 2022 14:17 — forked from ceruleanotter/SimpleChain.kt
WorkManager Basics: Simple Chain Example
WorkManager.getInstance()
// These three work requests run in parallel
.beginWith(Arrays.asList(
filterImageOneWorkRequest,
filterImageTwoWorkRequest,
filterImageThreeWorkRequest))
// The output from the filter WorkRequests
// will be passed as the input of compress WorkRequest
.then(compressWorkRequest)
.then(uploadWorkRequest)
@akueisara
akueisara / WorkRequestCompleteExample.kt
Last active June 26, 2022 16:15 — forked from ceruleanotter/WorkRequestCompleteExample.kt
WorkManager Basics: Complete WorkRequest Example
// 1. Create the Constraints
val constraints = Constraints.Builder()
.setRequiredNetworkType(NetworkType.CONNECTED)
.build()
// Other supported Constraints
val exampleConstraints = Constraints.Builder()
.setRequiresBatteryNotLow(true)
.setRequiredNetworkType(NetworkType.CONNECTED)
.setRequiresCharging(true)
@akueisara
akueisara / UploadWorker.kt
Last active June 25, 2022 06:35 — forked from ceruleanotter/UploadWorker.kt
WorkManager Basics - UploadWorker.kt Example
class UploadWorker(appContext: Context, workerParams: WorkerParameters)
: Worker(appContext, workerParams) {
override fun doWork(): Result {
try {
// Get the input, where this inputData is set when building the WorkRequest
val imageUriInput = inputData.getString(Constants.KEY_IMAGE_URI)
// Do the work
val response = upload(imageUriInput)