Last active
March 9, 2019 17:00
-
-
Save parahall/2058e6e80940632444886b94618424dc to your computer and use it in GitHub Desktop.
This file contains hidden or 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
//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