@@ -174,8 +174,10 @@ protected final void handleIntentAndMaybeStartTheService(
174174 for (String action : ACTIONS ) {
175175 ComponentName mediaButtonServiceComponentName = getServiceComponentByAction (context , action );
176176 if (mediaButtonServiceComponentName != null ) {
177- intent .setComponent (mediaButtonServiceComponentName );
178- if (!shouldStartForegroundService (context , intent )) {
177+ Intent serviceIntent = new Intent ();
178+ serviceIntent .setComponent (mediaButtonServiceComponentName );
179+ serviceIntent .fillIn (intent , 0 );
180+ if (!shouldStartForegroundService (context , serviceIntent )) {
179181 Log .i (
180182 TAG ,
181183 "onReceive(Intent) does not start the media button event target service into the"
@@ -184,11 +186,11 @@ protected final void handleIntentAndMaybeStartTheService(
184186 return ;
185187 }
186188 try {
187- ContextCompat .startForegroundService (context , intent );
189+ ContextCompat .startForegroundService (context , serviceIntent );
188190 } catch (/* ForegroundServiceStartNotAllowedException */ IllegalStateException e ) {
189191 if (SDK_INT >= 31 && Api31 .instanceOfForegroundServiceStartNotAllowedException (e )) {
190192 onForegroundServiceStartNotAllowedException (
191- intent , Api31 .castToForegroundServiceStartNotAllowedException (e ));
193+ serviceIntent , Api31 .castToForegroundServiceStartNotAllowedException (e ));
192194 } else {
193195 throw e ;
194196 }
@@ -214,8 +216,8 @@ protected final void handleIntentAndMaybeStartTheService(
214216 *
215217 * @param context The {@link Context} that {@linkplain #onReceive(Context, Intent) was received by
216218 * the media button event receiver}.
217- * @param intent The intent that {@linkplain #onReceive(Context, Intent) was received by the media
218- * button event receiver }.
219+ * @param intent The intent that will be used by {@linkplain
220+ * Context#startForegroundService(Intent) for starting the foreground service }.
219221 * @return true if the service should be {@linkplain ContextCompat#startForegroundService(Context,
220222 * Intent) started as a foreground service}. If false is returned the service is not started
221223 * and the receiver call is a no-op.
0 commit comments