How to get access to the chromecast icon programaticailly

58 Views Asked by At

I am trying to get a reference to the MediaRouteButton which is the cast icon and I am getting a null value all the time. Just wanted to see if anyone knows how to get a reference to this button. I am using a onGlobalLayoutListener to get notifications.

1

There are 1 best solutions below

2
On

If you are using CCL, you should be easily able to use ShowCaseView; take a look at the CastVideos-android app and see how it does it, basically you can use the callback onCastDeviceDetected() to be notified when the cast button appears and then do something like:

        Menu menu = mToolbar.getMenu();
        View view = menu.findItem(R.id.media_route_menu_item).getActionView();
        if (view != null && view instanceof MediaRouteButton) {
            new ShowcaseView.Builder(this)
                    .setTarget(new ViewTarget(view))
                    .setContentTitle(R.string.touch_to_cast)
                    .build();
        }

This assumes you have a ToolBar.

EDIT: If you have an ActionBar, try the following:

new ShowcaseView.Builder(this)
    .setTarget(new ActionViewTarget(this, ActionViewTarget.Type.MEDIA_ROUTE_BUTTON))
    .setContentTitle(R.string.touch_to_cast)
    .build();

At some point, I had submitted a patch to ShowCaseView project to cover MediaRoute button so hopefully that still works; I haven't tried that lately since I am using Toolbar now.