Resolves #575 Location settings
This commit is contained in:
		| @@ -38,7 +38,7 @@ class LocationUtils { | ||||
|     static final long MIN_WORKER_LOCATION_UPDATE_INTERVAL_MS = 900000; //15 minutes | ||||
|  | ||||
|     static int getLocationUpdatesState(Context context) { | ||||
|         return (int) context.getSharedPreferences("FlutterSharedPreferences", Context.MODE_PRIVATE).getInt(KEY_REQUESTING_LOCATION_UPDATES, LOCATION_UPDATES_DISABLED); | ||||
|         return (int) context.getSharedPreferences("FlutterSharedPreferences", Context.MODE_PRIVATE).getLong(KEY_REQUESTING_LOCATION_UPDATES, LOCATION_UPDATES_DISABLED); | ||||
|     } | ||||
|  | ||||
|     static long getLocationUpdateIntervals(Context context) { | ||||
| @@ -60,6 +60,15 @@ class LocationUtils { | ||||
|                 .apply(); | ||||
|     } | ||||
|  | ||||
|     static void setLocationUpdatesSettings(Context context, int priority, long interval, boolean showNotification) { | ||||
|         context.getSharedPreferences("FlutterSharedPreferences", Context.MODE_PRIVATE) | ||||
|                 .edit() | ||||
|                 .putInt(KEY_LOCATION_UPDATE_PRIORITY, priority) | ||||
|                 .putBoolean(KEY_LOCATION_SHOW_NOTIFICATION, showNotification) | ||||
|                 .putLong(KEY_LOCATION_UPDATE_INTERVAL, interval/1000) | ||||
|                 .apply(); | ||||
|     } | ||||
|  | ||||
|     static String getLocationText(Location location) { | ||||
|         return location == null ? "Accuracy: unknown" : | ||||
|                 "Accuracy: " + location.getAccuracy(); | ||||
|   | ||||
| @@ -39,6 +39,7 @@ public class MainActivity extends FlutterActivity { | ||||
|                     Context context = getActivity(); | ||||
|                     switch (call.method) { | ||||
|                         case "getFCMToken": | ||||
|                             try { | ||||
|                                 if (checkPlayServices()) { | ||||
|                                     FirebaseInstanceId.getInstance().getInstanceId() | ||||
|                                             .addOnCompleteListener(task -> { | ||||
| @@ -59,15 +60,19 @@ public class MainActivity extends FlutterActivity { | ||||
|                                 } else { | ||||
|                                     result.error("google_play_service_error", "Google Play Services unavailable", null); | ||||
|                                 } | ||||
|                             } catch (Exception e) { | ||||
|                                 result.error("get_token_exception", e.getMessage(), e); | ||||
|                             } | ||||
|                             break; | ||||
|                         case "startLocationService": | ||||
|                             try { | ||||
|                                 locationUpdatesInterval = LocationUtils.getLocationUpdateIntervals(this); | ||||
|                                 locationUpdatesInterval = (long) call.argument("location-updates-interval") * 1000; | ||||
|                                 if (locationUpdatesInterval >= LocationUtils.MIN_WORKER_LOCATION_UPDATE_INTERVAL_MS) { | ||||
|                                     locationUpdatesType = LocationUtils.LOCATION_UPDATES_WORKER; | ||||
|                                 } else { | ||||
|                                     locationUpdatesType = LocationUtils.LOCATION_UPDATES_SERVICE; | ||||
|                                 } | ||||
|                                 LocationUtils.setLocationUpdatesSettings(this, (int)call.argument("location-updates-priority"), locationUpdatesInterval, (boolean)call.argument("location-updates-show-notification")); | ||||
|                                 if (isNoLocationPermissions()) { | ||||
|                                     requestLocationPermissions(); | ||||
|                                 } else { | ||||
| @@ -75,12 +80,16 @@ public class MainActivity extends FlutterActivity { | ||||
|                                 } | ||||
|                                 result.success(""); | ||||
|                             } catch (Exception e) { | ||||
|                                 result.error("location_error", e.getMessage(), null); | ||||
|                                 result.error("location_error", e.getMessage(), e); | ||||
|                             } | ||||
|                             break; | ||||
|                         case "stopLocationService": | ||||
|                             try { | ||||
|                                 stopLocationUpdates(); | ||||
|                                 result.success(""); | ||||
|                             } catch (Exception e) { | ||||
|                                 result.error("location_error", e.getMessage(), e); | ||||
|                             } | ||||
|                             break; | ||||
|                         case "cancelOldLocationWorker": | ||||
|                             WorkManager.getInstance(this).cancelAllWorkByTag("haclocation"); | ||||
|   | ||||
		Reference in New Issue
	
	Block a user