Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
//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
You can’t perform that action at this time.