Skip to content
This repository was archived by the owner on Oct 15, 2022. It is now read-only.

Commit e12fbf6

Browse files
committed
Fix widget PendingIntents on Oreo+
Thanks to KBerstene daneren2005/Subsonic#957
1 parent b943580 commit e12fbf6

File tree

1 file changed

+13
-3
lines changed

1 file changed

+13
-3
lines changed

Diff for: app/src/main/java/net/nullsum/audinaut/provider/AudinautWidgetProvider.java

+13-3
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;
@@ -286,19 +287,28 @@ private void linkButtons(Context context, RemoteViews views) {
286287
intent = new Intent("Audinaut.PLAY_PAUSE");
287288
intent.setComponent(new ComponentName(context, DownloadService.class));
288289
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);
290294
views.setOnClickPendingIntent(R.id.control_play, pendingIntent);
291295

292296
intent = new Intent("Audinaut.NEXT"); // Use a unique action name to ensure a different PendingIntent to be created.
293297
intent.setComponent(new ComponentName(context, DownloadService.class));
294298
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);
296303
views.setOnClickPendingIntent(R.id.control_next, pendingIntent);
297304

298305
intent = new Intent("Audinaut.PREVIOUS"); // Use a unique action name to ensure a different PendingIntent to be created.
299306
intent.setComponent(new ComponentName(context, DownloadService.class));
300307
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);
302312
views.setOnClickPendingIntent(R.id.control_previous, pendingIntent);
303313
}
304314
}

0 commit comments

Comments
 (0)