1
0
mirror of https://codeberg.org/Freeyourgadget/Gadgetbridge synced 2024-11-28 04:46:51 +01:00

Set music info for PocketCasts

PocketCasts tells about its current media state via notifications. This
patch tries to parse incoming notifications from PocketCasts and if
successful tells the device about it. Currently supported are track and
artist.
This commit is contained in:
Steffen Liebergeld 2016-06-07 19:34:37 +02:00
parent 2b6ee41970
commit 389a143bdb

View File

@ -25,6 +25,7 @@ import org.slf4j.LoggerFactory;
import java.util.List; import java.util.List;
import nodomain.freeyourgadget.gadgetbridge.GBApplication; import nodomain.freeyourgadget.gadgetbridge.GBApplication;
import nodomain.freeyourgadget.gadgetbridge.model.MusicSpec;
import nodomain.freeyourgadget.gadgetbridge.model.NotificationSpec; import nodomain.freeyourgadget.gadgetbridge.model.NotificationSpec;
import nodomain.freeyourgadget.gadgetbridge.model.NotificationType; import nodomain.freeyourgadget.gadgetbridge.model.NotificationType;
import nodomain.freeyourgadget.gadgetbridge.service.DeviceCommunicationService; import nodomain.freeyourgadget.gadgetbridge.service.DeviceCommunicationService;
@ -182,6 +183,11 @@ public class NotificationListener extends NotificationListenerService {
String source = sbn.getPackageName(); String source = sbn.getPackageName();
Notification notification = sbn.getNotification(); Notification notification = sbn.getNotification();
if (source.equals("au.com.shiftyjelly.pocketcasts")) {
if (handlePocketCastNotification(notification))
return;
}
if ((notification.flags & Notification.FLAG_ONGOING_EVENT) == Notification.FLAG_ONGOING_EVENT) { if ((notification.flags & Notification.FLAG_ONGOING_EVENT) == Notification.FLAG_ONGOING_EVENT) {
return; return;
} }
@ -311,6 +317,36 @@ public class NotificationListener extends NotificationListenerService {
return false; return false;
} }
/**
* Try to handle pocket cast notifications that tell info about the current play state.
* @param notification The notification to handle.
* @return true if notification was handled, false otherwise
*/
public boolean handlePocketCastNotification(Notification notification) {
MusicSpec musicSpec = new MusicSpec();
Bundle extras = notification.extras;
if (extras == null)
return false;
CharSequence title = extras.getCharSequence(Notification.EXTRA_TITLE);
if (title != null)
musicSpec.artist = title.toString();
if (extras.containsKey(Notification.EXTRA_TEXT)) {
CharSequence contentCS = extras.getCharSequence(Notification.EXTRA_TEXT);
if (contentCS != null)
musicSpec.track = contentCS.toString();
}
musicSpec.album = "unknown";
LOG.info("handlePocketCastsNotification: artist " + musicSpec.artist + ", track " + musicSpec.track);
// finally, tell the device about it
GBApplication.deviceService().onSetMusicInfo(musicSpec);
return true;
}
@Override @Override
public void onNotificationRemoved(StatusBarNotification sbn) { public void onNotificationRemoved(StatusBarNotification sbn) {