From 6c17cda0c956386e09c1e2f03e10c2961fbef515 Mon Sep 17 00:00:00 2001 From: TacoTheDank Date: Sat, 28 Aug 2021 21:50:54 -0400 Subject: [PATCH] Use ServiceCompat.stopForeground --- .../core/service/download/DownloadService.java | 3 ++- .../playback/PlaybackServiceStateManager.java | 12 +++++------- 2 files changed, 7 insertions(+), 8 deletions(-) diff --git a/core/src/main/java/de/danoeh/antennapod/core/service/download/DownloadService.java b/core/src/main/java/de/danoeh/antennapod/core/service/download/DownloadService.java index 9598e3bdd..26ab4a414 100644 --- a/core/src/main/java/de/danoeh/antennapod/core/service/download/DownloadService.java +++ b/core/src/main/java/de/danoeh/antennapod/core/service/download/DownloadService.java @@ -17,6 +17,7 @@ import android.util.Log; import androidx.annotation.NonNull; import androidx.annotation.Nullable; import androidx.annotation.VisibleForTesting; +import androidx.core.app.ServiceCompat; import de.danoeh.antennapod.core.R; import de.danoeh.antennapod.core.sync.SyncService; @@ -645,7 +646,7 @@ public class DownloadService extends Service { } handler.post(() -> { cancelNotificationUpdater(); - stopForeground(true); + ServiceCompat.stopForeground(this, ServiceCompat.STOP_FOREGROUND_REMOVE); stopSelf(); }); } diff --git a/core/src/main/java/de/danoeh/antennapod/core/service/playback/PlaybackServiceStateManager.java b/core/src/main/java/de/danoeh/antennapod/core/service/playback/PlaybackServiceStateManager.java index 2f6989bb1..83c065e0e 100644 --- a/core/src/main/java/de/danoeh/antennapod/core/service/playback/PlaybackServiceStateManager.java +++ b/core/src/main/java/de/danoeh/antennapod/core/service/playback/PlaybackServiceStateManager.java @@ -1,8 +1,8 @@ package de.danoeh.antennapod.core.service.playback; import android.app.Notification; -import android.app.Service; -import android.os.Build; + +import androidx.core.app.ServiceCompat; class PlaybackServiceStateManager { private final PlaybackService playbackService; @@ -27,12 +27,10 @@ class PlaybackServiceStateManager { void stopForeground(boolean removeNotification) { if (isInForeground) { - if (Build.VERSION.SDK_INT < 24) { - playbackService.stopForeground(removeNotification); - } else if (removeNotification) { - playbackService.stopForeground(Service.STOP_FOREGROUND_REMOVE); + if (removeNotification) { + ServiceCompat.stopForeground(playbackService, ServiceCompat.STOP_FOREGROUND_REMOVE); } else { - playbackService.stopForeground(Service.STOP_FOREGROUND_DETACH); + ServiceCompat.stopForeground(playbackService, ServiceCompat.STOP_FOREGROUND_DETACH); } } isInForeground = false;