summaryrefslogtreecommitdiff
path: root/ui/app-start-intent/src/main
diff options
context:
space:
mode:
Diffstat (limited to 'ui/app-start-intent/src/main')
-rw-r--r--ui/app-start-intent/src/main/java/de/danoeh/antennapod/ui/appstartintent/MediaButtonStarter.java24
1 files changed, 24 insertions, 0 deletions
diff --git a/ui/app-start-intent/src/main/java/de/danoeh/antennapod/ui/appstartintent/MediaButtonStarter.java b/ui/app-start-intent/src/main/java/de/danoeh/antennapod/ui/appstartintent/MediaButtonStarter.java
new file mode 100644
index 000000000..1c2053a56
--- /dev/null
+++ b/ui/app-start-intent/src/main/java/de/danoeh/antennapod/ui/appstartintent/MediaButtonStarter.java
@@ -0,0 +1,24 @@
+package de.danoeh.antennapod.ui.appstartintent;
+
+import android.app.PendingIntent;
+import android.content.Context;
+import android.content.Intent;
+import android.os.Build;
+import android.view.KeyEvent;
+
+public abstract class MediaButtonStarter {
+ private static final String INTENT = "de.danoeh.antennapod.NOTIFY_BUTTON_RECEIVER";
+
+ public static Intent createIntent(Context context, int eventCode) {
+ KeyEvent event = new KeyEvent(KeyEvent.ACTION_DOWN, eventCode);
+ Intent startingIntent = new Intent(INTENT);
+ startingIntent.setPackage(context.getPackageName());
+ startingIntent.putExtra(Intent.EXTRA_KEY_EVENT, event);
+ return startingIntent;
+ }
+
+ public static PendingIntent createPendingIntent(Context context, int eventCode) {
+ return PendingIntent.getBroadcast(context, eventCode, createIntent(context, eventCode),
+ (Build.VERSION.SDK_INT >= 23 ? PendingIntent.FLAG_IMMUTABLE : 0));
+ }
+}