From 2f235fc46e8270ca86a9e9578a48bd365e306fcc Mon Sep 17 00:00:00 2001 From: Domingos Lopes Date: Sat, 2 Jul 2016 11:37:28 -0400 Subject: [PATCH] set pending activity intent on mediasession --- .../service/playback/PlaybackService.java | 23 +++++++++++-------- .../playback/PlaybackServiceFlavorHelper.java | 3 +-- 2 files changed, 14 insertions(+), 12 deletions(-) diff --git a/core/src/main/java/de/danoeh/antennapod/core/service/playback/PlaybackService.java b/core/src/main/java/de/danoeh/antennapod/core/service/playback/PlaybackService.java index 62321a91e..f33a1df85 100644 --- a/core/src/main/java/de/danoeh/antennapod/core/service/playback/PlaybackService.java +++ b/core/src/main/java/de/danoeh/antennapod/core/service/playback/PlaybackService.java @@ -29,6 +29,7 @@ import android.support.v4.media.MediaDescriptionCompat; import android.support.v4.media.MediaMetadataCompat; import android.support.v4.media.session.MediaSessionCompat; import android.support.v4.media.session.PlaybackStateCompat; +import android.support.v4.view.InputDeviceCompat; import android.support.v7.app.NotificationCompat; import android.text.TextUtils; import android.util.Log; @@ -41,8 +42,8 @@ import android.widget.Toast; import com.bumptech.glide.Glide; import com.bumptech.glide.request.target.Target; -import java.util.List; import java.util.ArrayList; +import java.util.List; import de.danoeh.antennapod.core.ClientConfig; import de.danoeh.antennapod.core.R; @@ -300,7 +301,7 @@ public class PlaybackService extends MediaBrowserServiceCompat { List queueItems = new ArrayList<>(); try { - for (FeedItem feedItem: taskManager.getQueue()) { + for (FeedItem feedItem : taskManager.getQueue()) { queueItems.add(new MediaSessionCompat.QueueItem(feedItem.getMedia().getMediaItem().getDescription(), feedItem.getId())); } mediaSession.setQueue(queueItems); @@ -343,7 +344,7 @@ public class PlaybackService extends MediaBrowserServiceCompat { } @Override - public BrowserRoot onGetRoot(String clientPackageName, int clientUid, Bundle rootHints) { + public BrowserRoot onGetRoot(@NonNull String clientPackageName, int clientUid, Bundle rootHints) { Log.d(TAG, "OnGetRoot: clientPackageName=" + clientPackageName + "; clientUid=" + clientUid + " ; rootHints=" + rootHints); return new BrowserRoot( @@ -361,10 +362,10 @@ public class PlaybackService extends MediaBrowserServiceCompat { } @Override - public void onLoadChildren(String parentId, - Result> result) { + public void onLoadChildren(@NonNull String parentId, + @NonNull Result> result) { Log.d(TAG, "OnLoadChildren: parentMediaId=" + parentId); - List mediaItems = new ArrayList(); + List mediaItems = new ArrayList<>(); if (parentId.equals(getResources().getString(R.string.app_name))) { // Root List mediaItems.add(createBrowsableMediaItemForRoot()); @@ -409,7 +410,7 @@ public class PlaybackService extends MediaBrowserServiceCompat { if (keycode != -1) { Log.d(TAG, "Received media button event"); handleKeycode(keycode, intent.getIntExtra(MediaButtonReceiver.EXTRA_SOURCE, - InputDevice.SOURCE_CLASS_NONE)); + InputDeviceCompat.SOURCE_CLASS_NONE)); } else if (!flavorHelper.castDisconnect(castDisconnect)) { started = true; boolean stream = intent.getBooleanExtra(EXTRA_SHOULD_STREAM, @@ -1024,7 +1025,9 @@ public class PlaybackService extends MediaBrowserServiceCompat { } } if (!Thread.currentThread().isInterrupted() && started) { - //TODO mediaSession.setSessionActivity(); + mediaSession.setSessionActivity(PendingIntent.getActivity(this, 0, + PlaybackService.getPlayerActivityIntent(this), + PendingIntent.FLAG_UPDATE_CURRENT)); mediaSession.setMetadata(builder.build()); } }; @@ -1171,8 +1174,8 @@ public class PlaybackService extends MediaBrowserServiceCompat { .setShowActionsInCompactView(compactActionList.toArray()) .setShowCancelButton(true) .setCancelButtonIntent(stopButtonPendingIntent)) - .setVisibility(Notification.VISIBILITY_PUBLIC) - .setColor(Notification.COLOR_DEFAULT); + .setVisibility(NotificationCompat.VISIBILITY_PUBLIC) + .setColor(NotificationCompat.COLOR_DEFAULT); notification = notificationBuilder.build(); diff --git a/core/src/play/java/de/danoeh/antennapod/core/service/playback/PlaybackServiceFlavorHelper.java b/core/src/play/java/de/danoeh/antennapod/core/service/playback/PlaybackServiceFlavorHelper.java index aef3e3c2b..93431d466 100644 --- a/core/src/play/java/de/danoeh/antennapod/core/service/playback/PlaybackServiceFlavorHelper.java +++ b/core/src/play/java/de/danoeh/antennapod/core/service/playback/PlaybackServiceFlavorHelper.java @@ -75,9 +75,8 @@ public class PlaybackServiceFlavorHelper { boolean castDisconnect(boolean castDisconnect) { if (castDisconnect) { castManager.disconnect(); - return true; } - return false; + return castDisconnect; } boolean onMediaPlayerInfo(Context context, int code, @StringRes int resourceId) {