2

I am trying to customize the Google Cast SDK's Cast Dialog (shown when you tap the cast button and shows the list of available devices), but i haven't found a way to do it.

Currently, it just shows an AlertDialog with a list of the available devices to connect.

What i want to do instead, is open an Activity that will show the list of devices with my own UI implementation.

This is the dialog i am trying to modify:

enter image description here

I've found many customization aspects about this SDK, but nothing related to this dialog.

Vishal G. Gohel
  • 1,008
  • 1
  • 16
  • 31
axebau24
  • 93
  • 8

2 Answers2

2

So i figured out a way to achieve this, First i created a class that overrides MediaRouteActionProvider (which is the main class that controls that button's functionality)

public class CustomMediaRouteActionProvider extends androidx.mediarouter.app.MediaRouteActionProvider {

    public CustomMediaRouteActionProvider(Context context) {
        super(context);
    }

    @Override
    public MediaRouteButton onCreateMediaRouteButton() {
        return new CastButton(getContext());
    }
}

Then you're gonna need to override the button's functionality with your own, in my case i open a new activity.

public class CastButton extends MediaRouteButton {


    public CastButton(Context context) {
        this(context, null);
    }

    public CastButton(Context context, AttributeSet attrs) {
        this(context, attrs, R.attr.mediaRouteButtonStyle);
    }

    public CastButton(Context context, AttributeSet attrs, int defStyleAttr) {
        super(context, attrs, defStyleAttr);
    }

    @Override
    public boolean performClick() {
        Intent i = new Intent(getContext(), RemoteDevicesActivity.class);
        getContext().startActivity(i);
        return true;
    }
}

Finally, you need to modify your xml that contains this button (i assume that you already implemented this part)

Change the field app:actionProviderClass with your custom class (in this case CustomMediaRouteActionProvider) and you're done.

<menu xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto">

    <item android:title="@string/connect_to"
        android:id="@+id/cast"
        app:actionProviderClass="CustomMediaRouteActionProvider"
        app:showAsAction="ifRoom" />

</menu>
axebau24
  • 93
  • 8
0

Are you have more details of final result of this? I need to do something similar but I don't get it how did you achieve it

gatosempai
  • 63
  • 1
  • 5
  • Not sure what you need, but in the activity created i get the list of remote devices, here's how: https://stackoverflow.com/questions/47506631/how-can-i-get-list-of-all-cast-devices-using-cast-sdk – axebau24 Jun 24 '19 at 17:00