@@ -190,7 +190,7 @@ protected final void handleIntentAndMaybeStartTheService(
190
190
} catch (/* ForegroundServiceStartNotAllowedException */ IllegalStateException e ) {
191
191
if (SDK_INT >= 31 && Api31 .instanceOfForegroundServiceStartNotAllowedException (e )) {
192
192
onForegroundServiceStartNotAllowedException (
193
- serviceIntent , Api31 .castToForegroundServiceStartNotAllowedException (e ));
193
+ context , serviceIntent , Api31 .castToForegroundServiceStartNotAllowedException (e ));
194
194
} else {
195
195
throw e ;
196
196
}
@@ -226,6 +226,21 @@ protected boolean shouldStartForegroundService(Context context, Intent intent) {
226
226
return true ;
227
227
}
228
228
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
+
229
244
/**
230
245
* This method is called when an exception is thrown when calling {@link
231
246
* Context#startForegroundService(Intent)} as a result of receiving a media button event.
@@ -249,18 +264,16 @@ protected boolean shouldStartForegroundService(Context context, Intent intent) {
249
264
* apps must use a {@link MediaBrowser} or {@link MediaController} to bind to the service instead
250
265
* of broadcasting an intent.
251
266
*
267
+ * @param context The broadcast receiver's {@linkplain Context}
252
268
* @param intent The intent that was used {@linkplain Context#startForegroundService(Intent) for
253
269
* starting the foreground service}.
254
270
* @param e The exception thrown by the system and caught by this broadcast receiver.
255
271
*/
272
+ @ SuppressWarnings ("deprecation" )
256
273
@ RequiresApi (31 )
257
274
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 );
264
277
}
265
278
266
279
@ SuppressWarnings ("QueryPermissionsNeeded" ) // Needs to be provided in the app manifest.
0 commit comments