diff --git a/android/app/src/main/AndroidManifest.xml b/android/app/src/main/AndroidManifest.xml
index c9ace20..d178d2b 100644
--- a/android/app/src/main/AndroidManifest.xml
+++ b/android/app/src/main/AndroidManifest.xml
@@ -50,13 +50,6 @@
-
-
-
-
-
-
locations) {
- print("[GPS isolate #${Isolate.current.hashCode}] Got device location update");
- SharedPreferences.getInstance().then((prefs){
- print("[GPS isolate #${Isolate.current.hashCode}] loading settings");
- String webhookId = prefs.getString('app-webhook-id');
- String domain = prefs.getString('hassio-domain');
- String port = prefs.getString('hassio-port');
- String httpWebHost =
- "${prefs.getString('hassio-res-protocol')}://$domain:$port";
- if (webhookId != null && webhookId.isNotEmpty) {
- int battery = DateTime.now().hour;
- try {
- print("[GPS isolate #${Isolate.current.hashCode}] Sending data home...");
- String url = "$httpWebHost/api/webhook/$webhookId";
- Map headers = {};
- headers["Content-Type"] = "application/json";
- var data = {
- "type": "update_location",
- "data": {
- "gps": [locations[0].latitude, locations[0].longitude],
- "gps_accuracy": locations[0].accuracy,
- "battery": battery
- }
- };
- http.post(
- url,
- headers: headers,
- body: json.encode(data)
- );
- } on PlatformException catch (e) {
- if (e.code == 'PERMISSION_DENIED') {
- print("[GPS isolate #${Isolate.current.hashCode}] No location permission. Aborting");
- }
- }
- } else {
- print("[GPS isolate #${Isolate.current.hashCode}] No webhook id. Aborting");
- }
- });
- }
-
- static void updateTestEntity() {
+ static void updateDeviceLocation() {
print("[Test isolate #${Isolate.current.hashCode}] alarm service callback");
SharedPreferences.getInstance().then((prefs){
print("[Test isolate #${Isolate.current.hashCode}] loading settings");
@@ -55,7 +15,7 @@ class LocationManager {
DateTime currentTime = DateTime.now();
String timeData = "${currentTime.year}-${currentTime.month}-${currentTime.day} ${currentTime.hour}:${currentTime.minute}";
try {
- print("[Test isolate #${Isolate.current.hashCode}] Sending data home...");
+ print("[Test isolate #${Isolate.current.hashCode}] Sending test time data home...");
String url = "$httpWebHost/api/webhook/$webhookId";
Map headers = {};
headers["Content-Type"] = "application/json";
@@ -78,6 +38,32 @@ class LocationManager {
} catch (e) {
print("[Test isolate #${Isolate.current.hashCode}] Error: ${e.toString()}");
}
+ Logger.d("[Test isolate #${Isolate.current.hashCode}] Getting device location...");
+ Geolocator().getCurrentPosition(desiredAccuracy: LocationAccuracy.medium).then((location) {
+ Logger.d("[Test isolate #${Isolate.current.hashCode}] Got location: ${location.latitude} ${location.longitude}. Sending home...");
+ int battery = DateTime.now().hour;
+ try {
+ String url = "$httpWebHost/api/webhook/$webhookId";
+ Map headers = {};
+ headers["Content-Type"] = "application/json";
+ var data = {
+ "type": "update_location",
+ "data": {
+ "gps": [location.latitude, location.longitude],
+ "gps_accuracy": location.accuracy,
+ "battery": battery
+ }
+ };
+ http.post(
+ url,
+ headers: headers,
+ body: json.encode(data)
+ );
+ } catch (e) {
+ print("[Test isolate #${Isolate.current.hashCode}] Error sending location: ${e.toString()}");
+ }
+ });
+
} else {
print("[Test isolate #${Isolate.current.hashCode}] No webhook id. Aborting");
}
@@ -95,29 +81,17 @@ class LocationManager {
_registerLocationListener();
}
- final int alarmId = 349011;
- final Duration testAlarmUpdateInterval = Duration(minutes: 1);
- final Duration locationUpdateInterval = Duration(minutes: 1);
+ final int alarmId = 34901199;
+ final Duration locationUpdateInterval = Duration(minutes: 5);
void _registerLocationListener() async {
- var _locationService = Location();
- bool _permission = await _locationService.requestPermission();
- if (_permission) {
- Logger.d("Activating device location tracking");
- _locationService.changeSettings(interval: locationUpdateInterval.inMilliseconds, accuracy: LocationAccuracy.BALANCED);
- bool statusBackgroundLocation = await _locationService.registerBackgroundLocation(LocationManager.updateDeviceLocation);
- Logger.d("Location listener status: $statusBackgroundLocation");
- } else {
- Logger.e("Location permission not granted");
- }
- //await AndroidAlarmManager.cancel(alarmId);
Logger.d("Activating alarm service test");
await AndroidAlarmManager.periodic(
- testAlarmUpdateInterval,
+ locationUpdateInterval,
alarmId,
- LocationManager.updateTestEntity,
+ LocationManager.updateDeviceLocation,
wakeup: true,
- rescheduleOnReboot: false
+ rescheduleOnReboot: true
);
}
diff --git a/pubspec.lock b/pubspec.lock
index 8526946..c4fd655 100644
--- a/pubspec.lock
+++ b/pubspec.lock
@@ -172,6 +172,20 @@ packages:
url: "https://pub.dartlang.org"
source: hosted
version: "0.3.7"
+ geolocator:
+ dependency: "direct main"
+ description:
+ name: geolocator
+ url: "https://pub.dartlang.org"
+ source: hosted
+ version: "5.1.3"
+ google_api_availability:
+ dependency: transitive
+ description:
+ name: google_api_availability
+ url: "https://pub.dartlang.org"
+ source: hosted
+ version: "2.0.1"
http:
dependency: transitive
description:
@@ -214,15 +228,13 @@ packages:
url: "https://pub.dartlang.org"
source: hosted
version: "2.4.0"
- location:
- dependency: "direct main"
+ location_permissions:
+ dependency: transitive
description:
- path: "."
- ref: background_location
- resolved-ref: "7c089fad38acbb7be7c46f207f601ac8e6b21caf"
- url: "git://github.com/Lyokone/flutterlocation.git"
- source: git
- version: "2.3.5"
+ name: location_permissions
+ url: "https://pub.dartlang.org"
+ source: hosted
+ version: "2.0.2"
logging:
dependency: transitive
description:
diff --git a/pubspec.yaml b/pubspec.yaml
index a206a04..3451b99 100644
--- a/pubspec.yaml
+++ b/pubspec.yaml
@@ -18,7 +18,7 @@ dependencies:
date_format: any
charts_flutter: any
flutter_markdown: any
- in_app_purchase: ^0.2.1
+ in_app_purchase: ^0.2.1+2
# flutter_svg: ^0.10.3
flutter_custom_tabs: ^0.6.0
firebase_messaging: ^5.1.4
@@ -27,11 +27,7 @@ dependencies:
device_info: ^0.4.0+2
flutter_local_notifications: ^0.8.2
android_alarm_manager: ^0.4.4
- location:
- git:
- url: git://github.com/Lyokone/flutterlocation.git
- ref: background_location
-
+ geolocator: ^5.1.3
dev_dependencies:
flutter_test: