@@ -147,8 +147,10 @@ public final void onReceive(Context context, @Nullable Intent intent) {
147
147
for (String action : ACTIONS ) {
148
148
ComponentName mediaButtonServiceComponentName = getServiceComponentByAction (context , action );
149
149
if (mediaButtonServiceComponentName != null ) {
150
- intent .setComponent (mediaButtonServiceComponentName );
151
- if (!shouldStartForegroundService (context , intent )) {
150
+ Intent serviceIntent = new Intent ();
151
+ serviceIntent .setComponent (mediaButtonServiceComponentName );
152
+ serviceIntent .fillIn (intent , 0 );
153
+ if (!shouldStartForegroundService (context , serviceIntent )) {
152
154
Log .i (
153
155
TAG ,
154
156
"onReceive(Intent) does not start the media button event target service into the"
@@ -157,12 +159,12 @@ public final void onReceive(Context context, @Nullable Intent intent) {
157
159
return ;
158
160
}
159
161
try {
160
- ContextCompat .startForegroundService (context , intent );
162
+ ContextCompat .startForegroundService (context , serviceIntent );
161
163
} catch (/* ForegroundServiceStartNotAllowedException */ IllegalStateException e ) {
162
164
if (Build .VERSION .SDK_INT >= 31
163
165
&& Api31 .instanceOfForegroundServiceStartNotAllowedException (e )) {
164
166
onForegroundServiceStartNotAllowedException (
165
- intent , Api31 .castToForegroundServiceStartNotAllowedException (e ));
167
+ serviceIntent , Api31 .castToForegroundServiceStartNotAllowedException (e ));
166
168
} else {
167
169
throw e ;
168
170
}
@@ -188,8 +190,8 @@ public final void onReceive(Context context, @Nullable Intent intent) {
188
190
*
189
191
* @param context The {@link Context} that {@linkplain #onReceive(Context, Intent) was received by
190
192
* the media button event receiver}.
191
- * @param intent The intent that {@linkplain #onReceive(Context, Intent) was received by the media
192
- * button event receiver }.
193
+ * @param intent The intent that would be used {@linkplain Context#startForegroundService( Intent)
194
+ * for starting the foreground service }.
193
195
* @return true if the service should be {@linkplain ContextCompat#startForegroundService(Context,
194
196
* Intent) started as a foreground service}. If false is returned the service is not started
195
197
* and the receiver call is a no-op.
0 commit comments