diff --git a/RELEASENOTES.md b/RELEASENOTES.md index 0a26472aa5..f3f1e861a3 100644 --- a/RELEASENOTES.md +++ b/RELEASENOTES.md @@ -335,6 +335,9 @@ This release includes the following changes since the * Improve interoperability behavior, so that a Media3 browser that is connected to a legacy `MediaBrowserService` doesn't request the children of a `parentId` twice when subscribing to a parent. + * Add 'Context' as a parameter to + 'MediaButtonReceiver.shouldStartForegroundService` + ([#1887](https://github.com/androidx/media/issues/1887)). * UI: * Make the stretched/cropped video in `PlayerView`-in-Compose-`AndroidView` workaround opt-in, due to issues diff --git a/libraries/session/src/main/java/androidx/media3/session/MediaButtonReceiver.java b/libraries/session/src/main/java/androidx/media3/session/MediaButtonReceiver.java index ab1774458d..c71dd52f7b 100644 --- a/libraries/session/src/main/java/androidx/media3/session/MediaButtonReceiver.java +++ b/libraries/session/src/main/java/androidx/media3/session/MediaButtonReceiver.java @@ -148,7 +148,7 @@ public class MediaButtonReceiver extends BroadcastReceiver { ComponentName mediaButtonServiceComponentName = getServiceComponentByAction(context, action); if (mediaButtonServiceComponentName != null) { intent.setComponent(mediaButtonServiceComponentName); - if (!shouldStartForegroundService(intent)) { + if (!shouldStartForegroundService(context, intent)) { Log.i( TAG, "onReceive(Intent) does not start the media button event target service into the" @@ -186,13 +186,15 @@ public class MediaButtonReceiver extends BroadcastReceiver { * playback to get into the foreground or the system will crash the service with a {@code * ForegroundServiceDidNotStartInTimeException} or an {@link IllegalStateException}. * + * @param context The {@link Context} that {@linkplain #onReceive(Context, Intent) was received by + * the media button event receiver}. * @param intent The intent that {@linkplain #onReceive(Context, Intent) was received by the media * button event receiver}. * @return true if the service should be {@linkplain ContextCompat#startForegroundService(Context, * Intent) started as a foreground service}. If false is returned the service is not started * and the receiver call is a no-op. */ - protected boolean shouldStartForegroundService(Intent intent) { + protected boolean shouldStartForegroundService(Context context, Intent intent) { return true; }