|
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;
|
@@ -286,19 +287,28 @@ private void linkButtons(Context context, RemoteViews views) {
|
286 | 287 | intent = new Intent("Audinaut.PLAY_PAUSE");
|
287 | 288 | intent.setComponent(new ComponentName(context, DownloadService.class));
|
288 | 289 | intent.setAction(DownloadService.CMD_TOGGLEPAUSE);
|
289 |
| - pendingIntent = PendingIntent.getService(context, 0, intent, 0); |
| 290 | + if (Build.VERSION.SDK_INT >= 26) |
| 291 | + pendingIntent = PendingIntent.getForegroundService(context, 0, intent, 0); |
| 292 | + else |
| 293 | + pendingIntent = PendingIntent.getService(context, 0, intent, 0); |
290 | 294 | views.setOnClickPendingIntent(R.id.control_play, pendingIntent);
|
291 | 295 |
|
292 | 296 | intent = new Intent("Audinaut.NEXT"); // Use a unique action name to ensure a different PendingIntent to be created.
|
293 | 297 | intent.setComponent(new ComponentName(context, DownloadService.class));
|
294 | 298 | intent.setAction(DownloadService.CMD_NEXT);
|
295 |
| - pendingIntent = PendingIntent.getService(context, 0, intent, 0); |
| 299 | + if (Build.VERSION.SDK_INT >= 26) |
| 300 | + pendingIntent = PendingIntent.getForegroundService(context, 0, intent, 0); |
| 301 | + else |
| 302 | + pendingIntent = PendingIntent.getService(context, 0, intent, 0); |
296 | 303 | views.setOnClickPendingIntent(R.id.control_next, pendingIntent);
|
297 | 304 |
|
298 | 305 | intent = new Intent("Audinaut.PREVIOUS"); // Use a unique action name to ensure a different PendingIntent to be created.
|
299 | 306 | intent.setComponent(new ComponentName(context, DownloadService.class));
|
300 | 307 | intent.setAction(DownloadService.CMD_PREVIOUS);
|
301 |
| - pendingIntent = PendingIntent.getService(context, 0, intent, 0); |
| 308 | + if (Build.VERSION.SDK_INT >= 26) |
| 309 | + pendingIntent = PendingIntent.getForegroundService(context, 0, intent, 0); |
| 310 | + else |
| 311 | + pendingIntent = PendingIntent.getService(context, 0, intent, 0); |
302 | 312 | views.setOnClickPendingIntent(R.id.control_previous, pendingIntent);
|
303 | 313 | }
|
304 | 314 | }
|
0 commit comments