After analyzing the source code of MediaRouteButton, this works:
public void handleCastButton() {
final FragmentManager fm = fragmentActivity.getSupportFragmentManager();
MediaRouteChooserDialogFragment f = MediaRouteDialogFactory.getDefault().onCreateChooserDialogFragment();
f.setRouteSelector(mediaRouteSelector);
f.show(fm, "android.support.v7.mediarouter:MediaRouteChooserDialogFragment");
}
What is it! Make sure your base activity is FragmentActivityand all import data is from android.support.v7.*. The dialog fragment will be used Callbackassociated with the specified selector.
There is also MediaRouteControllerDialogFragmentif you are already connected and want to adjust the volume or mute.
source
share