Skip to content

Commit

Permalink
Android console geofence updates
Browse files Browse the repository at this point in the history
  • Loading branch information
richturner committed Sep 4, 2018
1 parent c91ce01 commit 69291b6
Showing 1 changed file with 6 additions and 3 deletions.
Expand Up @@ -26,7 +26,7 @@ class GeofenceTransitionsIntentService : BroadcastReceiver() {


val geofencingEvent = GeofencingEvent.fromIntent(intent) val geofencingEvent = GeofencingEvent.fromIntent(intent)


LOG.info("Geofence event received: transition=${geofencingEvent.geofenceTransition}") LOG.info("Geofence event received: transition=")


if (geofencingEvent.hasError()) { if (geofencingEvent.hasError()) {
LOG.warning("Geofence event error : ${geofencingEvent.errorCode}") LOG.warning("Geofence event error : ${geofencingEvent.errorCode}")
Expand All @@ -42,13 +42,15 @@ class GeofenceTransitionsIntentService : BroadcastReceiver() {


val baseUrl = intent!!.getStringExtra(GeofenceProvider.baseUrlKey) val baseUrl = intent!!.getStringExtra(GeofenceProvider.baseUrlKey)
val geofenceTransition = geofencingEvent.geofenceTransition val geofenceTransition = geofencingEvent.geofenceTransition
val trans = if (geofenceTransition == Geofence.GEOFENCE_TRANSITION_ENTER) "ENTER" else "EXIT"


geofencingEvent.triggeringGeofences.forEach { geofence -> geofencingEvent.triggeringGeofences.forEach { geofence ->
val geofenceDefinition = geofenceDefinitions.firstOrNull { it.id == geofence.requestId } val geofenceDefinition = geofenceDefinitions.firstOrNull { it.id == geofence.requestId }


if (geofenceDefinition != null) { if (geofenceDefinition != null) {


LOG.info("Triggered geofence: id=${geofenceDefinition.id}") LOG.info("Triggered geofence '$trans': $geofenceDefinition")

geofenceDefinition.url = baseUrl + geofenceDefinition.url geofenceDefinition.url = baseUrl + geofenceDefinition.url


val locationJson = when (geofenceTransition) { val locationJson = when (geofenceTransition) {
Expand All @@ -67,13 +69,14 @@ class GeofenceTransitionsIntentService : BroadcastReceiver() {
// Android often triggers an exit on one fence at the same time as triggering an enter // Android often triggers an exit on one fence at the same time as triggering an enter
// on another so we queue the sends to allow the server time to process the events // on another so we queue the sends to allow the server time to process the events
queueSendLocation(geofenceDefinition, locationJson) queueSendLocation(geofenceDefinition, locationJson)
} else {
LOG.info("Triggered geofence '$trans': unknown")
} }
} }
} }


@Synchronized @Synchronized
fun queueSendLocation(geofenceDefinition : GeofenceProvider.GeofenceDefinition, locationJson : String?) { fun queueSendLocation(geofenceDefinition : GeofenceProvider.GeofenceDefinition, locationJson : String?) {
var scheduleSend = false


if (locationJson == null) { if (locationJson == null) {
exitedLocation = Pair(geofenceDefinition, null) exitedLocation = Pair(geofenceDefinition, null)
Expand Down

0 comments on commit 69291b6

Please sign in to comment.