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";
|
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_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_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";
|
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);
|
Intent serviceIntent = new Intent(context, PlaybackService.class);
|
||||||
serviceIntent.putExtra(EXTRA_KEYCODE, event.getKeyCode());
|
serviceIntent.putExtra(EXTRA_KEYCODE, event.getKeyCode());
|
||||||
serviceIntent.putExtra(EXTRA_SOURCE, event.getSource());
|
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);
|
ContextCompat.startForegroundService(context, serviceIntent);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -450,6 +450,7 @@ public class PlaybackService extends MediaBrowserServiceCompat {
|
|||||||
notificationManager.cancel(R.id.notification_streaming_confirmation);
|
notificationManager.cancel(R.id.notification_streaming_confirmation);
|
||||||
|
|
||||||
final int keycode = intent.getIntExtra(MediaButtonReceiver.EXTRA_KEYCODE, -1);
|
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);
|
final boolean castDisconnect = intent.getBooleanExtra(EXTRA_CAST_DISCONNECT, false);
|
||||||
Playable playable = intent.getParcelableExtra(EXTRA_PLAYABLE);
|
Playable playable = intent.getParcelableExtra(EXTRA_PLAYABLE);
|
||||||
if (keycode == -1 && playable == null && !castDisconnect) {
|
if (keycode == -1 && playable == null && !castDisconnect) {
|
||||||
@ -463,8 +464,15 @@ public class PlaybackService extends MediaBrowserServiceCompat {
|
|||||||
stateManager.stopForeground(true);
|
stateManager.stopForeground(true);
|
||||||
} else {
|
} else {
|
||||||
if (keycode != -1) {
|
if (keycode != -1) {
|
||||||
Log.d(TAG, "Received media button event");
|
boolean notificationButton;
|
||||||
boolean handled = handleKeycode(keycode, true);
|
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()) {
|
if (!handled && !stateManager.hasReceivedValidStartCommand()) {
|
||||||
stateManager.stopService();
|
stateManager.stopService();
|
||||||
return Service.START_NOT_STICKY;
|
return Service.START_NOT_STICKY;
|
||||||
|
Loading…
x
Reference in New Issue
Block a user