I'm trying to integrate Google Cast on my application, but the cast icon doesn't show on my Toolbar
.
Here is the step what I've tried.
Manifest.xml
<meta-data
android:name="com.google.android.gms.version"
android:value="@integer/google_play_services_version" />
<uses-permission android:name="android.permission.INTERNET" />
MainActivity.java
private MediaRouter mMediaRouter;
private MediaRouteSelector mMediaRouteSelector;
private MediaRouter.Callback mMediaRouterCallback;
onCreate()
mMediaRouter = MediaRouter.getInstance( getApplicationContext() );
mMediaRouteSelector = new MediaRouteSelector.Builder()
.addControlCategory(
CastMediaControlIntent.categoryForCast("MYAPPID"))
.build();
mMediaRouterCallback = new MediaRouterCallback();
onResume()
mMediaRouter.addCallback( mMediaRouteSelector, mMediaRouterCallback, MediaRouter.CALLBACK_FLAG_PERFORM_ACTIVE_SCAN );
onCreateOptionsMenu()
MenuItem mediaRouteMenuItem = menu.findItem( R.id.media_route_menu_item );
MediaRouteActionProvider mediaRouteActionProvider = (MediaRouteActionProvider) MenuItemCompat.getActionProvider( mediaRouteMenuItem );
mediaRouteActionProvider.setRouteSelector( mMediaRouteSelector );
This Callback class:
class MediaRouterCallback extends MediaRouter.Callback {
@Override
public void onRouteSelected(MediaRouter router, MediaRouter.RouteInfo info) {
}
@Override
public void onRouteUnselected( MediaRouter router, MediaRouter.RouteInfo info ) {
}
}
Menu.xml
<item android:id="@+id/media_route_menu_item"
android:title="Chromecast"
app:actionProviderClass="android.support.v7.app.MediaRouteActionProvider"
app:showAsAction="always"
/>
I also tried using the default receiver.
I read that you have to have a Google Cast device so that the icon is visible, there would be a way to test the application without having a device?
Yes you have read it right, you cannot see the icon without the ChromeCast
device being in the same network as your device is in,
You can look for LeapCast
here, but the repo says that its no longer supported, you can also look for AllCast and see if it fits your needs