From c0ec88154e5b16a44786178777f641998b9fb852 Mon Sep 17 00:00:00 2001 From: Tomas Mizera Date: Wed, 30 Aug 2023 08:37:02 +0200 Subject: [PATCH] Use GPS provider for Android versions lower than 12 --- .../PositionTrackingService.java | 21 +++++++++++++++++-- app/qml/main.qml | 4 +++- 2 files changed, 22 insertions(+), 3 deletions(-) diff --git a/app/android/src/uk/co/lutraconsulting/PositionTrackingService.java b/app/android/src/uk/co/lutraconsulting/PositionTrackingService.java index cac0221f6..e7c53310a 100644 --- a/app/android/src/uk/co/lutraconsulting/PositionTrackingService.java +++ b/app/android/src/uk/co/lutraconsulting/PositionTrackingService.java @@ -164,7 +164,24 @@ public int onStartCommand( Intent intent, int flags, int startId ) { locationManager = ( LocationManager ) getApplication().getSystemService( LOCATION_SERVICE ); - boolean isGPSAvailable = locationManager.isProviderEnabled( LocationManager.FUSED_PROVIDER ); + if ( Build.VERSION.SDK_INT < Build.VERSION_CODES.O ) { + sendStatusUpdateMessage( "ERROR #UNSUPPORTED: tracking is not supported on your Android version ( Android O (8.0) required )" ); + stopSelf(); + + return START_NOT_STICKY; // do not bother recreating it + } + + String positionProvider; + + // FUSED_PROVIDER is available since API 31 (Android 12) + if ( Build.VERSION.SDK_INT < Build.VERSION_CODES.S ) { + positionProvider = LocationManager.GPS_PROVIDER; + } + else { + positionProvider = LocationManager.FUSED_PROVIDER; + } + + boolean isGPSAvailable = locationManager.isProviderEnabled( positionProvider ); if ( !isGPSAvailable ) { sendStatusUpdateMessage( "ERROR #GPS_UNAVAILABLE: GPS is not available!" ); stopSelf(); @@ -192,7 +209,7 @@ public int onStartCommand( Intent intent, int flags, int startId ) { } locationManager.requestLocationUpdates( - LocationManager.GPS_PROVIDER, + positionProvider, timeInterval, distanceInterval, this diff --git a/app/qml/main.qml b/app/qml/main.qml index eb9e1b307..455552b9c 100644 --- a/app/qml/main.qml +++ b/app/qml/main.qml @@ -203,7 +203,9 @@ ApplicationWindow { formsStackManager.reopenAll() } - onNotify: showMessage( message ) + onNotify: function ( message ) { + showMessage( message ) + } onAccuracyButtonClicked: { gpsDataPageLoader.active = true gpsDataPageLoader.focus = true