1

From the Google documentation about adding a Cast button, https://developers.google.com/cast/docs/android_sender#adding-the-cast-button , it seems like the option they provide is for us to add a static button to the Action Bar. That said, what would I do if I wanted to add a Cast Button to my application only if there's a device on the network dynamically? Also, what are some ways you would create a custom button that mimic the functionality of a MediaRouter Button.

Any input would be appreciated!

jensiepoo
  • 571
  • 3
  • 9
  • 26
  • I am not clear on what you are asking; are you saying you want the cast button to show up when you are on "wifi" and there is a cast device on the wifi network but not when you are not on wifi? – Ali Naddaf Oct 09 '15 at 04:37
  • Exactly. I want the buttons to dynamically show up. – jensiepoo Oct 09 '15 at 07:32

2 Answers2

0

Based on your response in the comments, it seems like you want the normal behavior of a cast button, provided by, say, the MediaRouteActionProvider except that you don't want the cast discovery to include "guest mode". Is that a fair rephrasing of your question? If that is the case, then you can simply use the MediaRouteActionProvider and when you add your app in the developer console, you can uncheck the box that says "Supports Google Cast Guest Mode". Then guest mode (i.e. discovery of your app when not on wifi) is disabled for app and only devices that are on the same wifi network as your phone will be discoverable for your app.

Ali Naddaf
  • 16,951
  • 2
  • 21
  • 28
0

After following the steps for incorporating cast in your application. Eg https://github.com/googlecast/CastHelloText-android/blob/master/src/com/example/casthelloworld/MainActivity.java Create an android button and call the following method in the button

    public void connect() {
    android.media.MediaRouter mMediaRouter = (android.media.MediaRouter)getApplicationContext().getSystemService(Context.MEDIA_ROUTER_SERVICE);
    mMediaRouter.selectRoute(android.media.MediaRouter.ROUTE_TYPE_USER,mMediaRouter.getRouteAt(1));
}

This automatically connects to the chromecast and calls the @Override public void onRouteSelected(MediaRouter router, RouteInfo info) method.

nette
  • 575
  • 2
  • 8
  • 25