private MediaRouter mMediaRouter;
private MediaRouteSelector mMediaRouteSelector;
private MediaRouter.Callback mMediaRouterCallback;
private MediaRouteButton mMediaRouteButton;
private CastDevice mSelectedDevice;
private int mRouteCount = 0;
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.media_router_button);
mMediaRouter = MediaRouter.getInstance(getApplicationContext());
// Create a MediaRouteSelector for the type of routes your app supports
mMediaRouteSelector = new MediaRouteSelector.Builder()
.addControlCategory(MediaControlIntent.CATEGORY_REMOTE_PLAYBACK)
.build();
// Create a MediaRouter callback for discovery events
mMediaRouterCallback = new MyMediaRouterCallback();
// Set the MediaRouteButton selector for device discovery.
mMediaRouteButton = (MediaRouteButton) findViewById(R.id.media_route_button);
mMediaRouteButton.setRouteSelector(mMediaRouteSelector);
mMediaRouteButton.setVisibility(View.VISIBLE);
}