diff --git a/src/main/java/de/dennisguse/opentracks/services/TrackRecordingService.java b/src/main/java/de/dennisguse/opentracks/services/TrackRecordingService.java index 44ac6d9c0..8fc6291c3 100644 --- a/src/main/java/de/dennisguse/opentracks/services/TrackRecordingService.java +++ b/src/main/java/de/dennisguse/opentracks/services/TrackRecordingService.java @@ -80,8 +80,6 @@ public class TrackRecordingService extends Service { // Anything faster than that (in meters per second) will be considered moving. private static final String TAG = TrackRecordingService.class.getSimpleName(); - private static final int NOTIFICATION_ID = 123; - public static final double MAX_NO_MOVEMENT_SPEED = 0.224; // The following variables are set in onCreate: @@ -741,10 +739,12 @@ public class TrackRecordingService extends Service { // Dijkstra If if (isRecording() && isPaused()) { stopForeground(true); + notificationManager.cancelNotification(); } if (!isRecording() && !isGpsStarted) { stopForeground(true); + notificationManager.cancelNotification(); } if (isRecording() && !isPaused()) { Intent intent = IntentUtils.newIntent(this, TrackDetailActivity.class) @@ -756,7 +756,7 @@ public class TrackRecordingService extends Service { notificationManager.updatePendingIntent(pendingIntent); notificationManager.updateContent(getString(R.string.gps_starting)); - startForeground(NOTIFICATION_ID, notificationManager.getNotification()); + startForeground(TrackRecordingServiceNotificationManager.NOTIFICATION_ID, notificationManager.getNotification()); } if (!isRecording() && isGpsStarted) { Intent intent = IntentUtils.newIntent(this, TrackListActivity.class); @@ -766,7 +766,7 @@ public class TrackRecordingService extends Service { notificationManager.updatePendingIntent(pendingIntent); notificationManager.updateContent(getString(R.string.gps_starting)); - startForeground(NOTIFICATION_ID, notificationManager.getNotification()); + startForeground(TrackRecordingServiceNotificationManager.NOTIFICATION_ID, notificationManager.getNotification()); } } } diff --git a/src/main/java/de/dennisguse/opentracks/services/TrackRecordingServiceNotificationManager.java b/src/main/java/de/dennisguse/opentracks/services/TrackRecordingServiceNotificationManager.java index ece482af6..7a30189ab 100644 --- a/src/main/java/de/dennisguse/opentracks/services/TrackRecordingServiceNotificationManager.java +++ b/src/main/java/de/dennisguse/opentracks/services/TrackRecordingServiceNotificationManager.java @@ -20,7 +20,7 @@ import de.dennisguse.opentracks.util.StringUtils; */ class TrackRecordingServiceNotificationManager { - private static final int NOTIFICATION_ID = 123; + static final int NOTIFICATION_ID = 123; private static final String CHANNEL_ID = TrackRecordingServiceNotificationManager.class.getSimpleName(); @@ -76,6 +76,7 @@ class TrackRecordingServiceNotificationManager { notificationBuilder.setContentText(context.getString(R.string.track_recording_notification_accuracy, formattedAccuracy)); updateNotification(); + notificationBuilder.setOnlyAlertOnce(true); } @@ -84,6 +85,10 @@ class TrackRecordingServiceNotificationManager { updateNotification(); } + void cancelNotification() { + notificationManager.cancel(NOTIFICATION_ID); + } + Notification getNotification() { return notificationBuilder.build(); }