Skip to content

armgit / core

Public Imported from GitHub
0

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

Fix for opening url in MainActivity

Michael Rademakerbeffe9353b30
diff --git a/console/android/src/main/java/org/openremote/android/MainActivity.java b/console/android/src/main/java/org/openremote/android/MainActivity.java
index 9003fb574..9158caf0c 100644
--- a/console/android/src/main/java/org/openremote/android/MainActivity.java
+++ b/console/android/src/main/java/org/openremote/android/MainActivity.java
@@ -3,7 +3,11 @@ package org.openremote.android;
import android.Manifest;
import android.app.Activity;
import android.app.DownloadManager;
-import android.content.*;
+import android.content.BroadcastReceiver;
+import android.content.Context;
+import android.content.Intent;
+import android.content.IntentFilter;
+import android.content.SharedPreferences;
import android.content.pm.PackageManager;
import android.net.ConnectivityManager;
import android.net.NetworkInfo;
@@ -38,8 +42,8 @@ import android.widget.Toast;
import com.fasterxml.jackson.core.JsonProcessingException;
import com.fasterxml.jackson.databind.ObjectMapper;
-
import com.google.firebase.iid.FirebaseInstanceId;
+
import org.json.JSONException;
import org.json.JSONObject;
import org.openremote.android.service.GeofenceProvider;
@@ -145,10 +149,20 @@ public class MainActivity extends Activity {
webView.loadUrl(url);
}
}
+ openIntentUrl(getIntent());
+
+ errorViewHolder = new ErrorViewHolder(findViewById(R.id.errorView));
+ }
- if (getIntent().hasExtra("url")) {
+ @Override
+ protected void onNewIntent(Intent intent) {
+ openIntentUrl(intent);
+ }
+
+ protected void openIntentUrl(Intent intent) {
+ if (intent.hasExtra("url")) {
String url = getClientUrl();
- String intentUrl = getIntent().getStringExtra("url");
+ String intentUrl = intent.getStringExtra("url");
if (intentUrl != null) {
if (intentUrl.startsWith("http") || intentUrl.startsWith("https")) {
url = intentUrl;
@@ -160,17 +174,6 @@ public class MainActivity extends Activity {
LOG.fine("Loading web view: " + url);
webView.loadUrl(url);
}
-
- errorViewHolder = new ErrorViewHolder(findViewById(R.id.errorView));
- }
-
- @Override
- protected void onNewIntent(Intent intent) {
- if (intent.hasExtra("url")) {
- String url = getClientUrl() + getIntent().getStringExtra("url");
- LOG.fine("Loading web view: " + url);
- webView.loadUrl(url);
- }
}
@Override
@@ -459,9 +462,9 @@ public class MainActivity extends Activity {
String consoleId = data.getString("consoleId");
if (consoleId != null) {
Map<String, Object> enableData = geofenceProvider.enable(String.format("%s/%s",
- getString(R.string.OR_BASE_SERVER),
- getString(R.string.OR_REALM)),
- consoleId);
+ getString(R.string.OR_BASE_SERVER),
+ getString(R.string.OR_REALM)),
+ consoleId);
notifyClient(enableData);
}
}
@@ -488,7 +491,7 @@ public class MainActivity extends Activity {
notifyClient(response);
} else if (action.equalsIgnoreCase("PROVIDER_ENABLE")) {
// TODO: Implement topic support
- String fcmToken = FirebaseInstanceId.getInstance().getToken();
+ String fcmToken = FirebaseInstanceId.getInstance().getToken();
Map<String, Object> response = new HashMap<>();
response.put("action", "PROVIDER_ENABLE");
response.put("provider", "push");
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 7e1c5ab11..b04543d44 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
@@ -1,24 +1,13 @@
package org.openremote.android.service
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
-import retrofit2.converter.jackson.JacksonConverterFactory
-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") {
@@ -50,10 +39,10 @@ class GeofenceTransitionsIntentService : IntentService("or-geofence") {
if (geofenceTransition == Geofence.GEOFENCE_TRANSITION_ENTER) {
val postJson = hashMapOf(
- "objectValue" to hashMapOf(
- "type" to "Point",
- "coordinates" to arrayOf(geofencingEvent.triggeringLocation.longitude, geofencingEvent.triggeringLocation.latitude)
- )
+ "objectValue" to hashMapOf(
+ "type" to "Point",
+ "coordinates" to arrayOf(geofencingEvent.triggeringLocation.longitude, geofencingEvent.triggeringLocation.latitude)
+ )
)
connection.doOutput = true