From 6b6753ad84d42bd0cf0b7225241594b694c4f10d Mon Sep 17 00:00:00 2001 From: ByteHamster Date: Mon, 6 Mar 2023 22:08:49 +0100 Subject: Hide 'reconnect' settings (#6367) Android 12+ doesn't let us start the foreground service from an event like "headset reconnected". Hide the corresponding settings and avoid crashing. --- .../de/danoeh/antennapod/core/receiver/MediaButtonReceiver.java | 6 +++++- .../de/danoeh/antennapod/core/service/playback/PlaybackService.java | 4 ++++ 2 files changed, 9 insertions(+), 1 deletion(-) (limited to 'core') 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 e91e24ec6..08bdd39bc 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 @@ -37,7 +37,11 @@ public class MediaButtonReceiver extends BroadcastReceiver { serviceIntent.putExtra(EXTRA_KEYCODE, event.getKeyCode()); serviceIntent.putExtra(EXTRA_SOURCE, event.getSource()); serviceIntent.putExtra(EXTRA_HARDWAREBUTTON, event.getEventTime() > 0 || event.getDownTime() > 0); - ContextCompat.startForegroundService(context, serviceIntent); + try { + ContextCompat.startForegroundService(context, serviceIntent); + } catch (Exception e) { + e.printStackTrace(); + } } } 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 4f352aa15..92119e31e 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 @@ -1460,6 +1460,10 @@ public class PlaybackService extends MediaBrowserServiceCompat { } if (transientPause) { transientPause = false; + if (Build.VERSION.SDK_INT >= 31) { + stateManager.stopService(); + return; + } if (!bluetooth && UserPreferences.isUnpauseOnHeadsetReconnect()) { mediaPlayer.resume(); } else if (bluetooth && UserPreferences.isUnpauseOnBluetoothReconnect()) { -- cgit v1.2.3