summaryrefslogtreecommitdiff
path: root/core/src
diff options
context:
space:
mode:
authorDomingos Lopes <domingos86lopes+github@gmail.com>2016-06-03 16:44:19 -0400
committerDomingos Lopes <domingos86lopes+github@gmail.com>2016-06-08 22:49:03 -0400
commitb46b2247b46f36f28e14e536c9f8ce605091b015 (patch)
tree92ea7dcef1e8ccef1131711d9210e36af0cf7d7c /core/src
parent405630ee502819f7214f77ab49c484f4c7fd918c (diff)
downloadAntennaPod-b46b2247b46f36f28e14e536c9f8ce605091b015.zip
fixes NPE from #1974
Diffstat (limited to 'core/src')
-rw-r--r--core/src/play/java/de/danoeh/antennapod/core/cast/CastManager.java15
1 files changed, 12 insertions, 3 deletions
diff --git a/core/src/play/java/de/danoeh/antennapod/core/cast/CastManager.java b/core/src/play/java/de/danoeh/antennapod/core/cast/CastManager.java
index 5b1fdab61..b3f5038d7 100644
--- a/core/src/play/java/de/danoeh/antennapod/core/cast/CastManager.java
+++ b/core/src/play/java/de/danoeh/antennapod/core/cast/CastManager.java
@@ -24,6 +24,8 @@ package de.danoeh.antennapod.core.cast;
import android.content.Context;
import android.os.Build;
+import android.support.annotation.NonNull;
+import android.support.v4.view.ActionProvider;
import android.support.v4.view.MenuItemCompat;
import android.support.v7.media.MediaRouter;
import android.util.Log;
@@ -1739,9 +1741,16 @@ public class CastManager extends BaseCastManager implements OnFailedListener {
*
* @param menuItem MenuItem of the Media Router cast button.
*/
- public final SwitchableMediaRouteActionProvider addMediaRouterButton(MenuItem menuItem) {
- SwitchableMediaRouteActionProvider mediaRouteActionProvider = (SwitchableMediaRouteActionProvider)
- MenuItemCompat.getActionProvider(menuItem);
+ public final SwitchableMediaRouteActionProvider addMediaRouterButton(@NonNull MenuItem menuItem) {
+ ActionProvider actionProvider = MenuItemCompat.getActionProvider(menuItem);
+ if (!(actionProvider instanceof SwitchableMediaRouteActionProvider)) {
+ Log.wtf(TAG, "MenuItem provided to addMediaRouterButton() is not compatible with " +
+ "SwitchableMediaRouteActionProvider." +
+ ((actionProvider == null) ? " Its action provider is null!" : ""));
+ return null;
+ }
+ SwitchableMediaRouteActionProvider mediaRouteActionProvider =
+ (SwitchableMediaRouteActionProvider) actionProvider;
mediaRouteActionProvider.setRouteSelector(mMediaRouteSelector);
if (mCastConfiguration.getMediaRouteDialogFactory() != null) {
mediaRouteActionProvider.setDialogFactory(mCastConfiguration.getMediaRouteDialogFactory());