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
Removed commented code and MainActivity passes requestPermissionResult to GeofeceProvider
Michael Rademaker8fe59ce10078
diff --git a/console/android/src/main/java/org/openremote/android/MainActivity.java b/console/android/src/main/java/org/openremote/android/MainActivity.javaindex 850cde908..e77a95023 100644--- a/console/android/src/main/java/org/openremote/android/MainActivity.java+++ b/console/android/src/main/java/org/openremote/android/MainActivity.java@@ -459,32 +459,7 @@ public class MainActivity extends Activity {Toast.makeText(getApplicationContext(), R.string.downloading_file, Toast.LENGTH_LONG).show();}} else if (requestCode == GeofenceProvider.Companion.getLocationReponseCode()) {- if (grantResults.length > 0 && grantResults[0] == PackageManager.PERMISSION_GRANTED) {-- geofenceProvider.enable(MainActivity.this,- String.format("%s/%s",- getString(R.string.OR_BASE_SERVER),- getString(R.string.OR_REALM)),- consoleId,- new GeofenceProvider.EnableCallback() {- @Override- public void accept(@NotNull Map<String, ?> responseData) {- try {- final String jsonString = new ObjectMapper().writeValueAsString(responseData);- MainActivity.this.runOnUiThread(new Runnable() {- @Override- public void run() {- webView.evaluateJavascript(String.format(- "openremote.INSTANCE.console.handleProviderResponse('%s')",- jsonString), null);- }- });- } catch (Exception e) {- e.printStackTrace();- }- }- });- }+ geofenceProvider.onRequestPermissionsResult(requestCode, permissions, grantResults);} else {super.onRequestPermissionsResult(requestCode, permissions, grantResults);}diff --git a/console/android/src/main/java/org/openremote/android/service/GeofenceProvider.kt b/console/android/src/main/java/org/openremote/android/service/GeofenceProvider.ktindex dd0d8dbf9..dbb57e7d8 100644--- a/console/android/src/main/java/org/openremote/android/service/GeofenceProvider.kt+++ b/console/android/src/main/java/org/openremote/android/service/GeofenceProvider.kt@@ -40,86 +40,6 @@ class GeofenceProvider(val context: Context) : ActivityCompat.OnRequestPermissio}}-// class LocationService : Service() {-//-// private lateinit var fusedLocationProviderClient: FusedLocationProviderClient-// private lateinit var locationCallback: LocationCallback-//-// override fun onCreate() {-// super.onCreate()-//-// fusedLocationProviderClient = LocationServices.getFusedLocationProviderClient(applicationContext)-//-// locationCallback = object : LocationCallback() {-// override fun onLocationResult(locationResult: LocationResult?) {-// locationResult ?: return-// Log.i("GeofenceProvider", "Location received: lat${locationResult.lastLocation.latitude}/lng${locationResult.lastLocation.longitude}")-// }-// }-// }-//-// @SuppressLint("MissingPermission", "NewApi")-// override fun onStartCommand(intent: Intent?, flags: Int, startId: Int): Int {-//-// val notificationBuilder = when {-// Build.VERSION.SDK_INT >= Build.VERSION_CODES.O -> {-// val channelId = createNotificationChannel()-// NotificationCompat.Builder(this, channelId)-// }-// else -> {-// NotificationCompat.Builder(this)-// }-// }-//-// val notification = notificationBuilder.setOngoing(true)-// .setSmallIcon(R.drawable.ic_notification)-// .setCategory(Notification.CATEGORY_SERVICE)-// .setContentTitle("Tracking location")-// .build()-//-// notification.flags = notification.flags or Notification.FLAG_ONGOING_EVENT or Notification.FLAG_FOREGROUND_SERVICE or Notification.FLAG_NO_CLEAR-//-// //Force location updates-// val locationRequest = LocationRequest().apply {-// interval = 60000//1min-// fastestInterval = 10000//10sec-// priority = LocationRequest.PRIORITY_HIGH_ACCURACY-// }-//-// fusedLocationProviderClient.requestLocationUpdates(locationRequest,-// locationCallback,-// null)-//-// startForeground(101, notification)-//-// return START_REDELIVER_INTENT-// }-//-// override fun onDestroy() {-// fusedLocationProviderClient.removeLocationUpdates(locationCallback)-//-// super.onDestroy()-// }-//-// override fun onBind(intent: Intent?): IBinder? {-// return null-// }-//-// @RequiresApi(Build.VERSION_CODES.O)-// private fun createNotificationChannel(): String {-// val channelId = "${BuildConfig.APPLICATION_ID}.OREindhovenLocationService"-// val channelName = "OR Eindhoven Location Service"-// val channel = NotificationChannel(channelId,-// channelName, NotificationManager.IMPORTANCE_LOW)-// channel.lightColor = Color.BLUE-// channel.lockscreenVisibility = Notification.VISIBILITY_PRIVATE-// channel.setShowBadge(false)-// val service = getSystemService(Context.NOTIFICATION_SERVICE) as NotificationManager?-// service!!.createNotificationChannel(channel)-// return channelId-// }-// }-companion object {val baseUrlKey = "baseUrl"val consoleIdKey = "consoleId"@@ -314,12 +234,6 @@ class GeofenceProvider(val context: Context) : ActivityCompat.OnRequestPermissioif (hasPermission) {LOG.info("Has permission so fetching geofences")-// if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {-// context.startForegroundService(Intent(context, LocationService::class.java))-// } else {-// context.startService(Intent(context, LocationService::class.java))-// }-if (getGeofences(context).isEmpty()) {// Could be first time getting geofences so wait a few seconds for backend to catch upTimer().schedule(10000) {