Skip to content

Commit 3e21911

Browse files
committed
Provide context to onForegroundServiceStartNotAllowedException
The intended use of this method is to "post a notification from where the user journey can continue", but posting a notification requires a context.
1 parent 7cdd4ea commit 3e21911

File tree

1 file changed

+3
-2
lines changed

1 file changed

+3
-2
lines changed

libraries/session/src/main/java/androidx/media3/session/MediaButtonReceiver.java

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -190,7 +190,7 @@ protected final void handleIntentAndMaybeStartTheService(
190190
} catch (/* ForegroundServiceStartNotAllowedException */ IllegalStateException e) {
191191
if (SDK_INT >= 31 && Api31.instanceOfForegroundServiceStartNotAllowedException(e)) {
192192
onForegroundServiceStartNotAllowedException(
193-
serviceIntent, Api31.castToForegroundServiceStartNotAllowedException(e));
193+
context, serviceIntent, Api31.castToForegroundServiceStartNotAllowedException(e));
194194
} else {
195195
throw e;
196196
}
@@ -249,13 +249,14 @@ protected boolean shouldStartForegroundService(Context context, Intent intent) {
249249
* apps must use a {@link MediaBrowser} or {@link MediaController} to bind to the service instead
250250
* of broadcasting an intent.
251251
*
252+
* @param context The broadcast receiver's {@linkplain Context}
252253
* @param intent The intent that was used {@linkplain Context#startForegroundService(Intent) for
253254
* starting the foreground service}.
254255
* @param e The exception thrown by the system and caught by this broadcast receiver.
255256
*/
256257
@RequiresApi(31)
257258
protected void onForegroundServiceStartNotAllowedException(
258-
Intent intent, ForegroundServiceStartNotAllowedException e) {
259+
Context context, Intent intent, ForegroundServiceStartNotAllowedException e) {
259260
Log.e(
260261
TAG,
261262
"caught exception when trying to start a foreground service from the "

0 commit comments

Comments
 (0)