diff options
author | ByteHamster <ByteHamster@users.noreply.github.com> | 2024-03-18 07:28:17 +0100 |
---|---|---|
committer | GitHub <noreply@github.com> | 2024-03-18 07:28:17 +0100 |
commit | d40b9ef59b422ad6ccf0e31245e9a28757e39fc1 (patch) | |
tree | c9d5b1ad240aef08b480a02caf12cbc920313c39 /ui/app-start-intent | |
parent | 2d77b1f11802da28cbcd87c9456bcc7ee3abf2a0 (diff) | |
download | AntennaPod-d40b9ef59b422ad6ccf0e31245e9a28757e39fc1.zip |
Decouple media button starter and receiver (#6999)
Diffstat (limited to 'ui/app-start-intent')
-rw-r--r-- | ui/app-start-intent/src/main/java/de/danoeh/antennapod/ui/appstartintent/MediaButtonStarter.java | 24 |
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)); + } +} |