Here is what I'm doing:
- Manually connecting to ChromeCast via Settings.
- Launching my app which manages Presentation to show custom layout using the ChromeCast device I'm already connected to.
- Finishing my app by manually closing it.
- By this time, I can still see my device screen casting. Here is where I want to disconnect from casting programmatically so I cannot longer see the screen casting.
While doing the presentation I have access to the Display I'm casting to:
MediaRouter.RouteInfo route = mMediaRouter.getSelectedRoute(MediaRouter.ROUTE_TYPE_LIVE_VIDEO);
return route != null ? route.getPresentationDisplay() : null;
Any ideas on how to achive this functionality?
UPDATE:
For those who are interested on this, this is how I did it (Thanks to Ali Naddaf response):
@TargetApi(Build.VERSION_CODES.JELLY_BEAN_MR2)
public void disconnect(){
MediaRouter mMediaRouter = (MediaRouter) getSystemService(Context.MEDIA_ROUTER_SERVICE);
mMediaRouter.selectRoute(MediaRouter.ROUTE_TYPE_LIVE_VIDEO, mMediaRouter.getDefaultRoute());
}