Android14: crash due to missing announcement of ForegroundServiceType.

Fixes #1655.
This commit is contained in:
Dennis Guse
2023-08-06 09:40:37 +02:00
parent 10e479ceb9
commit 42234515cb
3 changed files with 10 additions and 3 deletions
@@ -18,6 +18,8 @@ package de.dennisguse.opentracks.services;
import android.app.Service;
import android.content.Intent;
import android.content.pm.ServiceInfo;
import android.os.Build;
import android.os.Handler;
import android.os.Looper;
import android.os.PowerManager.WakeLock;
@@ -205,7 +207,11 @@ public class TrackRecordingService extends Service implements TrackPointCreator.
private void startSensors() {
wakeLock = SystemUtils.acquireWakeLock(this, wakeLock);
trackPointCreator.start(this, handler);
startForeground(TrackRecordingServiceNotificationManager.NOTIFICATION_ID, notificationManager.setGPSonlyStarted(this));
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.Q) {
startForeground(TrackRecordingServiceNotificationManager.NOTIFICATION_ID, notificationManager.setGPSonlyStarted(this), ServiceInfo.FOREGROUND_SERVICE_TYPE_CONNECTED_DEVICE);
} else {
startForeground(TrackRecordingServiceNotificationManager.NOTIFICATION_ID, notificationManager.setGPSonlyStarted(this));
}
}
public void endCurrentTrack() {
@@ -25,11 +25,11 @@ public class AltitudeCorrectionManager {
public AltitudeCorrectionManager() {
this.altitudeConverterFallback = new EGM2008Internal();
this.altitudeConverter = Build.VERSION.SDK_INT >= 34 ? new AltitudeConverter() : null;
this.altitudeConverter = Build.VERSION.SDK_INT >= Build.VERSION_CODES.UPSIDE_DOWN_CAKE ? new AltitudeConverter() : null;
}
public void correctAltitude(Context context, TrackPoint trackPoint) {
if (Build.VERSION.SDK_INT >= 34 && altitudeConverter != null) {
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.UPSIDE_DOWN_CAKE && altitudeConverter != null) {
try {
Location loc = trackPoint.getLocation();
altitudeConverter.addMslAltitudeToLocation(context, loc);