Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add support for position tracking for Android versions lower than 12 #2777

Merged
merged 1 commit into from
Aug 30, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 19 additions & 2 deletions app/android/src/uk/co/lutraconsulting/PositionTrackingService.java
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down Expand Up @@ -192,7 +209,7 @@ public int onStartCommand( Intent intent, int flags, int startId ) {
}

locationManager.requestLocationUpdates(
LocationManager.GPS_PROVIDER,
positionProvider,
timeInterval,
distanceInterval,
this
Expand Down
4 changes: 3 additions & 1 deletion app/qml/main.qml
Original file line number Diff line number Diff line change
Expand Up @@ -203,7 +203,9 @@ ApplicationWindow {
formsStackManager.reopenAll()
}

onNotify: showMessage( message )
onNotify: function ( message ) {
showMessage( message )
}
onAccuracyButtonClicked: {
gpsDataPageLoader.active = true
gpsDataPageLoader.focus = true
Expand Down