Skip to content

armgit / core

Public Imported from GitHub
0

100% open-source IoT Platform - Integrate your devices, add intelligence, build custom apps

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.kt
index 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.IntentService
import android.content.ContentValues.TAG
import android.content.Intent
import android.util.Log
+import android.util.Log.e
import com.fasterxml.jackson.databind.ObjectMapper
import com.google.android.gms.location.Geofence
import com.google.android.gms.location.GeofencingEvent
+import org.openremote.android.ORFirebaseMessagingService
import org.openremote.android.R
import org.openremote.android.service.TokenService.getUnsafeOkHttpClient
import retrofit2.Retrofit
@@ -15,20 +17,24 @@ import retrofit2.converter.scalars.ScalarsConverterFactory
import java.io.DataOutputStream
import java.net.HttpURLConnection
import java.net.URL
+import java.util.logging.Logger
import kotlin.text.Charsets.UTF_8
class 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.geofenceTransition
val 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 = false
if (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 = true
connection.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