Reputation: 4188
In my Chromecast Sender application, I have added a menu item to allow the user to stop the receiver app on the device (and made sure the "Disconnect" button in the Media Router Dialog doesn't stop the receiver, like it does in the CastHelloText-android sample app)
So, when the user taps the "Exit App" menu item, I am running the sample codes "teardown()" method (shown here). This code kills the reciever application, and should de-select the currently selected device.
However, whilst it does indeed kill the receiver app, it doesn't de-select the device, and the Cast icon stays in the selected state, and tapping it shows the dialog as if the phone was still connected to the Chromecast.
Obviously, if I then try to cast anything from my app, it can't.
So how do I fully disconnect from the device?
My teardown() method is 100% the same as in the linked code. Below is my menu code:
@Override
public boolean onOptionsItemSelected(MenuItem item) {
final SharedPreferences sharedPreferences = PreferenceManager.getDefaultSharedPreferences(this);
switch (item.getItemId()) {
case R.id.exit_app:
teardown();
return true;
default:
return super.onOptionsItemSelected(item);
}
}
Upvotes: 1
Views: 361
Reputation: 1185
Alternatively
mMediaRouter.unselect(UNSELECT_REASON_DISCONNECTED)
Upvotes: 0
Reputation: 19044
You can call
mMediaRouter.selectRoute(mMediaRouter.getDefaultRoute())
Upvotes: 2