Use ServiceCompat.stopForeground

This commit is contained in:
TacoTheDank 2021-08-28 21:50:54 -04:00
parent f8779fbba2
commit 6c17cda0c9
2 changed files with 7 additions and 8 deletions

View File

@ -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();
});
}

View File

@ -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;