@@ -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 }
@@ -226,6 +226,21 @@ protected boolean shouldStartForegroundService(Context context, Intent intent) {
226226 return true ;
227227 }
228228
229+ /**
230+ * @deprecated Use {@link #onForegroundServiceStartNotAllowedException(Context, Intent,
231+ * ForegroundServiceStartNotAllowedException)} instead.
232+ */
233+ @ Deprecated
234+ @ RequiresApi (31 )
235+ protected void onForegroundServiceStartNotAllowedException (
236+ Intent intent , ForegroundServiceStartNotAllowedException e ) {
237+ Log .e (
238+ TAG ,
239+ "caught exception when trying to start a foreground service from the "
240+ + "background: "
241+ + e .getMessage ());
242+ }
243+
229244 /**
230245 * This method is called when an exception is thrown when calling {@link
231246 * Context#startForegroundService(Intent)} as a result of receiving a media button event.
@@ -249,18 +264,16 @@ protected boolean shouldStartForegroundService(Context context, Intent intent) {
249264 * apps must use a {@link MediaBrowser} or {@link MediaController} to bind to the service instead
250265 * of broadcasting an intent.
251266 *
267+ * @param context The broadcast receiver's {@linkplain Context}
252268 * @param intent The intent that was used {@linkplain Context#startForegroundService(Intent) for
253269 * starting the foreground service}.
254270 * @param e The exception thrown by the system and caught by this broadcast receiver.
255271 */
272+ @ SuppressWarnings ("deprecation" )
256273 @ RequiresApi (31 )
257274 protected void onForegroundServiceStartNotAllowedException (
258- Intent intent , ForegroundServiceStartNotAllowedException e ) {
259- Log .e (
260- TAG ,
261- "caught exception when trying to start a foreground service from the "
262- + "background: "
263- + e .getMessage ());
275+ Context context , Intent intent , ForegroundServiceStartNotAllowedException e ) {
276+ onForegroundServiceStartNotAllowedException (intent , e );
264277 }
265278
266279 @ SuppressWarnings ("QueryPermissionsNeeded" ) // Needs to be provided in the app manifest.
0 commit comments