aboutsummaryrefslogtreecommitdiff
path: root/app/src/main/java/github/daneren2005
diff options
context:
space:
mode:
authorKevin T. Berstene <kberstene@gmail.com>2019-06-05 13:47:17 -0400
committerKevin T. Berstene <kberstene@gmail.com>2019-06-05 13:47:17 -0400
commit8aebc95681510909f4213dbb44c4caa0e26a6caa (patch)
treed1e3f1a092ad92a282d0e028486cd1117d1ca1f2 /app/src/main/java/github/daneren2005
parent166d395e3e5de223527fec96d8b17dd42ed9a991 (diff)
downloaddsub-8aebc95681510909f4213dbb44c4caa0e26a6caa.tar.gz
dsub-8aebc95681510909f4213dbb44c4caa0e26a6caa.tar.bz2
dsub-8aebc95681510909f4213dbb44c4caa0e26a6caa.zip
Bugfix for widget PendingIntents on Android Oreo and higher
Diffstat (limited to 'app/src/main/java/github/daneren2005')
-rw-r--r--app/src/main/java/github/daneren2005/dsub/provider/DSubWidgetProvider.java20
1 files changed, 15 insertions, 5 deletions
diff --git a/app/src/main/java/github/daneren2005/dsub/provider/DSubWidgetProvider.java b/app/src/main/java/github/daneren2005/dsub/provider/DSubWidgetProvider.java
index 5c90c250..4a1c22a5 100644
--- a/app/src/main/java/github/daneren2005/dsub/provider/DSubWidgetProvider.java
+++ b/app/src/main/java/github/daneren2005/dsub/provider/DSubWidgetProvider.java
@@ -34,6 +34,7 @@ import android.graphics.PorterDuff.Mode;
import android.graphics.PorterDuffXfermode;
import android.graphics.Rect;
import android.graphics.RectF;
+import android.os.Build;
import android.os.Environment;
import android.util.Log;
import android.view.View;
@@ -282,24 +283,33 @@ public class DSubWidgetProvider extends AppWidgetProvider {
PendingIntent pendingIntent = PendingIntent.getActivity(context, 0, intent, 0);
views.setOnClickPendingIntent(R.id.appwidget_coverart, pendingIntent);
views.setOnClickPendingIntent(R.id.appwidget_top, pendingIntent);
-
+
// Emulate media button clicks.
intent = new Intent("DSub.PLAY_PAUSE");
intent.setComponent(new ComponentName(context, DownloadService.class));
intent.setAction(DownloadService.CMD_TOGGLEPAUSE);
- pendingIntent = PendingIntent.getService(context, 0, intent, 0);
+ if (Build.VERSION.SDK_INT >= 26)
+ pendingIntent = PendingIntent.getForegroundService(context, 0, intent, 0);
+ else
+ pendingIntent = PendingIntent.getService(context, 0, intent, 0);
views.setOnClickPendingIntent(R.id.control_play, pendingIntent);
intent = new Intent("DSub.NEXT"); // Use a unique action name to ensure a different PendingIntent to be created.
intent.setComponent(new ComponentName(context, DownloadService.class));
intent.setAction(DownloadService.CMD_NEXT);
- pendingIntent = PendingIntent.getService(context, 0, intent, 0);
+ if (Build.VERSION.SDK_INT >= 26)
+ pendingIntent = PendingIntent.getForegroundService(context, 0, intent, 0);
+ else
+ pendingIntent = PendingIntent.getService(context, 0, intent, 0);
views.setOnClickPendingIntent(R.id.control_next, pendingIntent);
-
+
intent = new Intent("DSub.PREVIOUS"); // Use a unique action name to ensure a different PendingIntent to be created.
intent.setComponent(new ComponentName(context, DownloadService.class));
intent.setAction(DownloadService.CMD_PREVIOUS);
- pendingIntent = PendingIntent.getService(context, 0, intent, 0);
+ if (Build.VERSION.SDK_INT >= 26)
+ pendingIntent = PendingIntent.getForegroundService(context, 0, intent, 0);
+ else
+ pendingIntent = PendingIntent.getService(context, 0, intent, 0);
views.setOnClickPendingIntent(R.id.control_previous, pendingIntent);
}
}