Merge pull request #4256 from Slinger/fix_hardware_buttons
Fix hardware buttons registered as lockscreen/notification taps
This commit is contained in:
commit
410ebfe98c
|
@ -15,6 +15,7 @@ public class MediaButtonReceiver extends BroadcastReceiver {
|
|||
private static final String TAG = "MediaButtonReceiver";
|
||||
public static final String EXTRA_KEYCODE = "de.danoeh.antennapod.core.service.extra.MediaButtonReceiver.KEYCODE";
|
||||
public static final String EXTRA_SOURCE = "de.danoeh.antennapod.core.service.extra.MediaButtonReceiver.SOURCE";
|
||||
public static final String EXTRA_HARDWAREBUTTON = "de.danoeh.antennapod.core.service.extra.MediaButtonReceiver.HARDWAREBUTTON";
|
||||
|
||||
public static final String NOTIFY_BUTTON_RECEIVER = "de.danoeh.antennapod.NOTIFY_BUTTON_RECEIVER";
|
||||
|
||||
|
@ -30,6 +31,12 @@ public class MediaButtonReceiver extends BroadcastReceiver {
|
|||
Intent serviceIntent = new Intent(context, PlaybackService.class);
|
||||
serviceIntent.putExtra(EXTRA_KEYCODE, event.getKeyCode());
|
||||
serviceIntent.putExtra(EXTRA_SOURCE, event.getSource());
|
||||
//detect if this is a hardware button press
|
||||
if (event.getEventTime() > 0 || event.getDownTime() > 0) {
|
||||
serviceIntent.putExtra(EXTRA_HARDWAREBUTTON, true);
|
||||
} else {
|
||||
serviceIntent.putExtra(EXTRA_HARDWAREBUTTON, false);
|
||||
}
|
||||
ContextCompat.startForegroundService(context, serviceIntent);
|
||||
}
|
||||
|
||||
|
|
|
@ -450,6 +450,7 @@ public class PlaybackService extends MediaBrowserServiceCompat {
|
|||
notificationManager.cancel(R.id.notification_streaming_confirmation);
|
||||
|
||||
final int keycode = intent.getIntExtra(MediaButtonReceiver.EXTRA_KEYCODE, -1);
|
||||
final boolean hardwareButton = intent.getBooleanExtra(MediaButtonReceiver.EXTRA_HARDWAREBUTTON, false);
|
||||
final boolean castDisconnect = intent.getBooleanExtra(EXTRA_CAST_DISCONNECT, false);
|
||||
Playable playable = intent.getParcelableExtra(EXTRA_PLAYABLE);
|
||||
if (keycode == -1 && playable == null && !castDisconnect) {
|
||||
|
@ -463,8 +464,15 @@ public class PlaybackService extends MediaBrowserServiceCompat {
|
|||
stateManager.stopForeground(true);
|
||||
} else {
|
||||
if (keycode != -1) {
|
||||
Log.d(TAG, "Received media button event");
|
||||
boolean handled = handleKeycode(keycode, true);
|
||||
boolean notificationButton;
|
||||
if (hardwareButton) {
|
||||
Log.d(TAG, "Received hardware button event");
|
||||
notificationButton = false;
|
||||
} else {
|
||||
Log.d(TAG, "Received media button event");
|
||||
notificationButton = true;
|
||||
}
|
||||
boolean handled = handleKeycode(keycode, notificationButton);
|
||||
if (!handled && !stateManager.hasReceivedValidStartCommand()) {
|
||||
stateManager.stopService();
|
||||
return Service.START_NOT_STICKY;
|
||||
|
|
Loading…
Reference in New Issue