diff options
author | orionlee <orionlee@yahoo.com> | 2019-01-07 10:28:34 -0800 |
---|---|---|
committer | orionlee <orionlee@yahoo.com> | 2019-02-27 14:52:34 -0800 |
commit | ab78c1d4108551bb5691683bde81396612446c6e (patch) | |
tree | 26b75f1484d97895a2c1f034fecbf908f79ac8ec /core/src/main/java | |
parent | 2c5db08e256afa7e56fd40461691413eab5c0dfc (diff) | |
download | AntennaPod-ab78c1d4108551bb5691683bde81396612446c6e.zip |
bug fix for Android8+: revert context.startService() calls back to
ContextCompat.startForegroundService(), to ensure PlaybackService
can be started.
While PlaybackService itself ensures it will be raised to foreground
when appropriate, Android 8+ forbids creating the (background)
services to begin with (and throw IllegalStateException) in some
situation (e.g., BroadcastReceiver).
https://developer.android.com/about/versions/oreo/android-8.0-changes#atap
Diffstat (limited to 'core/src/main/java')
3 files changed, 5 insertions, 5 deletions
diff --git a/core/src/main/java/de/danoeh/antennapod/core/receiver/MediaButtonReceiver.java b/core/src/main/java/de/danoeh/antennapod/core/receiver/MediaButtonReceiver.java index 3b52ac212..b191dbf8b 100644 --- a/core/src/main/java/de/danoeh/antennapod/core/receiver/MediaButtonReceiver.java +++ b/core/src/main/java/de/danoeh/antennapod/core/receiver/MediaButtonReceiver.java @@ -3,6 +3,7 @@ package de.danoeh.antennapod.core.receiver; import android.content.BroadcastReceiver; import android.content.Context; import android.content.Intent; +import android.support.v4.content.ContextCompat; import android.util.Log; import android.view.KeyEvent; @@ -29,7 +30,7 @@ public class MediaButtonReceiver extends BroadcastReceiver { Intent serviceIntent = new Intent(context, PlaybackService.class); serviceIntent.putExtra(EXTRA_KEYCODE, event.getKeyCode()); serviceIntent.putExtra(EXTRA_SOURCE, event.getSource()); - context.startService(serviceIntent); // the service itself will determine if it needs to become a foreground service. + ContextCompat.startForegroundService(context, serviceIntent); } } diff --git a/core/src/main/java/de/danoeh/antennapod/core/service/playback/PlaybackService.java b/core/src/main/java/de/danoeh/antennapod/core/service/playback/PlaybackService.java index 065199f98..a0b368f86 100644 --- a/core/src/main/java/de/danoeh/antennapod/core/service/playback/PlaybackService.java +++ b/core/src/main/java/de/danoeh/antennapod/core/service/playback/PlaybackService.java @@ -79,10 +79,8 @@ import de.greenrobot.event.EventBus; * * Callers should connect to the service with either: * - .bindService() - * - .startService(), optionally with arguments such as media to be played. + * - ContextCompat.startForegroundService(), optionally with arguments, such as media to be played, in intent extras * - * Caller should not call startForegroundService(). The PlaybackService will make itself foreground - * when appropriate. */ public class PlaybackService extends MediaBrowserServiceCompat { /** diff --git a/core/src/main/java/de/danoeh/antennapod/core/util/playback/PlaybackServiceStarter.java b/core/src/main/java/de/danoeh/antennapod/core/util/playback/PlaybackServiceStarter.java index a6cf500c1..64cf61457 100644 --- a/core/src/main/java/de/danoeh/antennapod/core/util/playback/PlaybackServiceStarter.java +++ b/core/src/main/java/de/danoeh/antennapod/core/util/playback/PlaybackServiceStarter.java @@ -2,6 +2,7 @@ package de.danoeh.antennapod.core.util.playback; import android.content.Context; import android.content.Intent; +import android.support.v4.content.ContextCompat; import android.util.Log; import de.danoeh.antennapod.core.preferences.PlaybackPreferences; @@ -77,6 +78,6 @@ public class PlaybackServiceStarter { if (PlaybackService.isRunning && !callEvenIfRunning) { return; } - context.startService(getIntent()); // the service itself will decide if it needs to become foreground + ContextCompat.startForegroundService(context, getIntent()); } } |