100% open-source IoT Platform - Integrate your devices, add intelligence, build custom apps
Java asset-managementbuildingdashboarddataplatformdevice-managementedge-computingenergyenergy-managementenergy-monitorfleet-managementfleet-telematicsiotiot-applicationiot-platformmodbusmqttmqtt-brokerota-updaterules-enginesmartcity
Bug fix for Android geofence
Rich Turner0bf5c29e5f08
diff --git a/console/android/src/main/java/org/openremote/android/service/GeofenceTransitionsIntentService.kt b/console/android/src/main/java/org/openremote/android/service/GeofenceTransitionsIntentService.ktindex 7ec809cb9..7e1c5ab11 100644--- a/console/android/src/main/java/org/openremote/android/service/GeofenceTransitionsIntentService.kt+++ b/console/android/src/main/java/org/openremote/android/service/GeofenceTransitionsIntentService.kt@@ -4,9 +4,11 @@ import android.app.IntentServiceimport android.content.ContentValues.TAGimport android.content.Intentimport android.util.Log+import android.util.Log.eimport com.fasterxml.jackson.databind.ObjectMapperimport com.google.android.gms.location.Geofenceimport com.google.android.gms.location.GeofencingEvent+import org.openremote.android.ORFirebaseMessagingServiceimport org.openremote.android.Rimport org.openremote.android.service.TokenService.getUnsafeOkHttpClientimport retrofit2.Retrofit@@ -15,20 +17,24 @@ import retrofit2.converter.scalars.ScalarsConverterFactoryimport java.io.DataOutputStreamimport java.net.HttpURLConnectionimport java.net.URL+import java.util.logging.Loggerimport kotlin.text.Charsets.UTF_8class GeofenceTransitionsIntentService : IntentService("or-geofence") {-+ private val LOG = Logger.getLogger(GeofenceTransitionsIntentService::class.java.name)override fun onHandleIntent(intent: Intent?) {val geofencingEvent = GeofencingEvent.fromIntent(intent)+if (geofencingEvent.hasError()) {- Log.e(TAG, "Error handling geofence event")+ LOG.warning("Error handling geofence event")return}+ LOG.fine("Geofence '" + geofencingEvent.geofenceTransition + "' occurred")+val baseUrl = intent!!.getStringExtra(GeofenceProvider.baseUrlKey)val geofenceTransition = geofencingEvent.geofenceTransitionval geofence = geofencingEvent.triggeringGeofences.first()@@ -39,15 +45,16 @@ class GeofenceTransitionsIntentService : IntentService("or-geofence") {connection.setRequestProperty("Content-Type", "application/json")connection.requestMethod = "POST"connection.connectTimeout = 10000+ connection.doInput = falseif (geofenceTransition == Geofence.GEOFENCE_TRANSITION_ENTER) {- val postJson = {- "objectValue" to {- "type" to "Point"+ val postJson = hashMapOf(+ "objectValue" to hashMapOf(+ "type" to "Point","coordinates" to arrayOf(geofencingEvent.triggeringLocation.longitude, geofencingEvent.triggeringLocation.latitude)- }- }+ )+ )connection.doOutput = trueconnection.setChunkedStreamingMode(0)@@ -57,8 +64,12 @@ class GeofenceTransitionsIntentService : IntentService("or-geofence") {try {connection.outputStream.flush()+ val responseCode = connection.responseCode+ LOG.fine("Location posted to server '" + postUrl + "': response=" + responseCode);} catch (exception: Exception) {print(exception)+ } finally {+ connection.disconnect()}}}\ No newline at end of file