forked from upstream-mirrors/OpenTracks
Always cancel TrackRecordingService's notification.
This commit is contained in:
@@ -80,8 +80,6 @@ public class TrackRecordingService extends Service {
|
|||||||
// Anything faster than that (in meters per second) will be considered moving.
|
// Anything faster than that (in meters per second) will be considered moving.
|
||||||
private static final String TAG = TrackRecordingService.class.getSimpleName();
|
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;
|
public static final double MAX_NO_MOVEMENT_SPEED = 0.224;
|
||||||
|
|
||||||
// The following variables are set in onCreate:
|
// The following variables are set in onCreate:
|
||||||
@@ -741,10 +739,12 @@ public class TrackRecordingService extends Service {
|
|||||||
// Dijkstra If
|
// Dijkstra If
|
||||||
if (isRecording() && isPaused()) {
|
if (isRecording() && isPaused()) {
|
||||||
stopForeground(true);
|
stopForeground(true);
|
||||||
|
notificationManager.cancelNotification();
|
||||||
|
|
||||||
}
|
}
|
||||||
if (!isRecording() && !isGpsStarted) {
|
if (!isRecording() && !isGpsStarted) {
|
||||||
stopForeground(true);
|
stopForeground(true);
|
||||||
|
notificationManager.cancelNotification();
|
||||||
}
|
}
|
||||||
if (isRecording() && !isPaused()) {
|
if (isRecording() && !isPaused()) {
|
||||||
Intent intent = IntentUtils.newIntent(this, TrackDetailActivity.class)
|
Intent intent = IntentUtils.newIntent(this, TrackDetailActivity.class)
|
||||||
@@ -756,7 +756,7 @@ public class TrackRecordingService extends Service {
|
|||||||
|
|
||||||
notificationManager.updatePendingIntent(pendingIntent);
|
notificationManager.updatePendingIntent(pendingIntent);
|
||||||
notificationManager.updateContent(getString(R.string.gps_starting));
|
notificationManager.updateContent(getString(R.string.gps_starting));
|
||||||
startForeground(NOTIFICATION_ID, notificationManager.getNotification());
|
startForeground(TrackRecordingServiceNotificationManager.NOTIFICATION_ID, notificationManager.getNotification());
|
||||||
}
|
}
|
||||||
if (!isRecording() && isGpsStarted) {
|
if (!isRecording() && isGpsStarted) {
|
||||||
Intent intent = IntentUtils.newIntent(this, TrackListActivity.class);
|
Intent intent = IntentUtils.newIntent(this, TrackListActivity.class);
|
||||||
@@ -766,7 +766,7 @@ public class TrackRecordingService extends Service {
|
|||||||
|
|
||||||
notificationManager.updatePendingIntent(pendingIntent);
|
notificationManager.updatePendingIntent(pendingIntent);
|
||||||
notificationManager.updateContent(getString(R.string.gps_starting));
|
notificationManager.updateContent(getString(R.string.gps_starting));
|
||||||
startForeground(NOTIFICATION_ID, notificationManager.getNotification());
|
startForeground(TrackRecordingServiceNotificationManager.NOTIFICATION_ID, notificationManager.getNotification());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
+6
-1
@@ -20,7 +20,7 @@ import de.dennisguse.opentracks.util.StringUtils;
|
|||||||
*/
|
*/
|
||||||
class TrackRecordingServiceNotificationManager {
|
class TrackRecordingServiceNotificationManager {
|
||||||
|
|
||||||
private static final int NOTIFICATION_ID = 123;
|
static final int NOTIFICATION_ID = 123;
|
||||||
|
|
||||||
private static final String CHANNEL_ID = TrackRecordingServiceNotificationManager.class.getSimpleName();
|
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));
|
notificationBuilder.setContentText(context.getString(R.string.track_recording_notification_accuracy, formattedAccuracy));
|
||||||
updateNotification();
|
updateNotification();
|
||||||
|
|
||||||
notificationBuilder.setOnlyAlertOnce(true);
|
notificationBuilder.setOnlyAlertOnce(true);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -84,6 +85,10 @@ class TrackRecordingServiceNotificationManager {
|
|||||||
updateNotification();
|
updateNotification();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void cancelNotification() {
|
||||||
|
notificationManager.cancel(NOTIFICATION_ID);
|
||||||
|
}
|
||||||
|
|
||||||
Notification getNotification() {
|
Notification getNotification() {
|
||||||
return notificationBuilder.build();
|
return notificationBuilder.build();
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user