Skip to content

Commit 8d305b5

Browse files
authored
Merge pull request daneren2005#957 from KBerstene/bugfix/oreoWidgetIntents
Bugfix for widget PendingIntents on Android Oreo and higher
2 parents a496541 + 260bddd commit 8d305b5

File tree

1 file changed

+15
-5
lines changed

1 file changed

+15
-5
lines changed

Diff for: app/src/main/java/github/daneren2005/dsub/provider/DSubWidgetProvider.java

+15-5
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@
3434
import android.graphics.PorterDuffXfermode;
3535
import android.graphics.Rect;
3636
import android.graphics.RectF;
37+
import android.os.Build;
3738
import android.os.Environment;
3839
import android.util.Log;
3940
import android.view.View;
@@ -282,24 +283,33 @@ private void linkButtons(Context context, RemoteViews views, boolean playerActiv
282283
PendingIntent pendingIntent = PendingIntent.getActivity(context, 0, intent, 0);
283284
views.setOnClickPendingIntent(R.id.appwidget_coverart, pendingIntent);
284285
views.setOnClickPendingIntent(R.id.appwidget_top, pendingIntent);
285-
286+
286287
// Emulate media button clicks.
287288
intent = new Intent("DSub.PLAY_PAUSE");
288289
intent.setComponent(new ComponentName(context, DownloadService.class));
289290
intent.setAction(DownloadService.CMD_TOGGLEPAUSE);
290-
pendingIntent = PendingIntent.getService(context, 0, intent, 0);
291+
if (Build.VERSION.SDK_INT >= 26)
292+
pendingIntent = PendingIntent.getForegroundService(context, 0, intent, 0);
293+
else
294+
pendingIntent = PendingIntent.getService(context, 0, intent, 0);
291295
views.setOnClickPendingIntent(R.id.control_play, pendingIntent);
292296

293297
intent = new Intent("DSub.NEXT"); // Use a unique action name to ensure a different PendingIntent to be created.
294298
intent.setComponent(new ComponentName(context, DownloadService.class));
295299
intent.setAction(DownloadService.CMD_NEXT);
296-
pendingIntent = PendingIntent.getService(context, 0, intent, 0);
300+
if (Build.VERSION.SDK_INT >= 26)
301+
pendingIntent = PendingIntent.getForegroundService(context, 0, intent, 0);
302+
else
303+
pendingIntent = PendingIntent.getService(context, 0, intent, 0);
297304
views.setOnClickPendingIntent(R.id.control_next, pendingIntent);
298-
305+
299306
intent = new Intent("DSub.PREVIOUS"); // Use a unique action name to ensure a different PendingIntent to be created.
300307
intent.setComponent(new ComponentName(context, DownloadService.class));
301308
intent.setAction(DownloadService.CMD_PREVIOUS);
302-
pendingIntent = PendingIntent.getService(context, 0, intent, 0);
309+
if (Build.VERSION.SDK_INT >= 26)
310+
pendingIntent = PendingIntent.getForegroundService(context, 0, intent, 0);
311+
else
312+
pendingIntent = PendingIntent.getService(context, 0, intent, 0);
303313
views.setOnClickPendingIntent(R.id.control_previous, pendingIntent);
304314
}
305315
}

0 commit comments

Comments
 (0)