Skip to content

Instantly share code, notes, and snippets.

@parahall
Last active March 9, 2019 17:00
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save parahall/2058e6e80940632444886b94618424dc to your computer and use it in GitHub Desktop.
Save parahall/2058e6e80940632444886b94618424dc to your computer and use it in GitHub Desktop.
//location obtained, need to send it to server
private void broadcastLocation(Location location) {
//release latch
reportFinished();
//We need to sure that device have internet live
Constraints constraints = new Constraints.Builder().setRequiredNetworkType
(NetworkType.CONNECTED).build();
//Parse our location to Data to use it as input for our worker
Data inputData = new Data.Builder()
.putDouble(LocationUploadWorker.LOCATION_LAT, location.getLatitude())
.putDouble(LocationUploadWorker.LOCATION_LONG, location.getLongitude())
.putLong(LocationUploadWorker.LOCATION_TIME, location.getTime())
.build();
//worker itself
OneTimeWorkRequest uploadWork = new OneTimeWorkRequest.Builder
(LocationUploadWorker.class).setConstraints(constraints).setInputData
(inputData).build();
//Schedule it
WorkManager.getInstance().enqueue(uploadWork);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment