|
34 | 34 | import android.graphics.PorterDuffXfermode;
|
35 | 35 | import android.graphics.Rect;
|
36 | 36 | import android.graphics.RectF;
|
| 37 | +import android.os.Build; |
37 | 38 | import android.os.Environment;
|
38 | 39 | import android.util.Log;
|
39 | 40 | import android.view.View;
|
@@ -282,24 +283,33 @@ private void linkButtons(Context context, RemoteViews views, boolean playerActiv
|
282 | 283 | PendingIntent pendingIntent = PendingIntent.getActivity(context, 0, intent, 0);
|
283 | 284 | views.setOnClickPendingIntent(R.id.appwidget_coverart, pendingIntent);
|
284 | 285 | views.setOnClickPendingIntent(R.id.appwidget_top, pendingIntent);
|
285 |
| - |
| 286 | + |
286 | 287 | // Emulate media button clicks.
|
287 | 288 | intent = new Intent("DSub.PLAY_PAUSE");
|
288 | 289 | intent.setComponent(new ComponentName(context, DownloadService.class));
|
289 | 290 | 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); |
291 | 295 | views.setOnClickPendingIntent(R.id.control_play, pendingIntent);
|
292 | 296 |
|
293 | 297 | intent = new Intent("DSub.NEXT"); // Use a unique action name to ensure a different PendingIntent to be created.
|
294 | 298 | intent.setComponent(new ComponentName(context, DownloadService.class));
|
295 | 299 | 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); |
297 | 304 | views.setOnClickPendingIntent(R.id.control_next, pendingIntent);
|
298 |
| - |
| 305 | + |
299 | 306 | intent = new Intent("DSub.PREVIOUS"); // Use a unique action name to ensure a different PendingIntent to be created.
|
300 | 307 | intent.setComponent(new ComponentName(context, DownloadService.class));
|
301 | 308 | 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); |
303 | 313 | views.setOnClickPendingIntent(R.id.control_previous, pendingIntent);
|
304 | 314 | }
|
305 | 315 | }
|
0 commit comments