Skip to content

Instantly share code, notes, and snippets.

@jdsingh
Created November 20, 2018 19:38
Show Gist options
  • Save jdsingh/9ed1c4c7d51e0f36fe3e2194d8132066 to your computer and use it in GitHub Desktop.
Save jdsingh/9ed1c4c7d51e0f36fe3e2194d8132066 to your computer and use it in GitHub Desktop.
class LocationWorker(
context: Context,
params: WorkerParameters
) : ListenableWorker(context, params) {
private val future: ResolvableFuture<Payload> = ResolvableFuture.create()
override fun startWork(): ListenableFuture<Payload> {
if (hasLocationPermission()) {
getLocation(getFusedLocationProviderClient().lastLocation)
} else {
future.set(Payload(Result.FAILURE))
}
return future
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment