I am trying to add the cast icon to the ActionBar using the CastCompanionLibrary's helper method:
@Override
public boolean onCreateOptionsMenu(Menu menu) {
super.onCreateOptionsMenu(menu);
getMenuInflater().inflate(R.menu.main, menu);
mDataCastManager.addMediaRouterButton(menu, R.id.media_route_menu_item); // This one
return true;
}
I have this as my menu.xml as specified by the PDF that is included with the companion library:
<menu xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto">
<item
android:id="@+id/media_route_menu_item"
android:title="@string/media_route_menu_title"
app:actionProviderClass="android.support.v7.app.MediaRouteActionProvider"
app:showAsAction="always"/>
</menu>
However, nothing shows up in the ActionBar. No errors are thrown, nothing at all is visible. If I add a different menu item just to see if everything with my menu is set up correctly, that item shows up fine - it is just this cast action menu item that isn't showing up.
I have tried changing the "app" prefixes to "android", but then I get a NullPointerException
somewhere deep in the library, and I have tried giving the menu item a different, visible icon. Nothing helps.
In AndroidStudio, the menu preview shows a menu item with the title "Play on...", so it seems like this should work.
What am I doing wrong?
The Cast button will temporarily appear in your toolbar. To keep it there permanently, right-click on the Cast button and click Always show icon. If the Cast button is already pinned to your toolbar on your browser, you'll see the Cast button in the Chrome toolbar (near the top right).
The cast button opens a dialog to connect, control and disconnect from Cast receivers. See Cast icons to download the Cast button templates. Note that the Cast button is not specific to Google Cast; it can be used to represent both Cast and non-Cast receivers (e.g. bluetooth headsets).
You can right-click on the icon and choose the Always show icon option. Now the Cast icon will be added to the toolbar in the Microsoft Edge browser. Another method is by using the Registry Editor to add the Cast icon in the toolbar.
Show back button using actionBar.setDisplayHomeAsUpEnabled (true) this will enable the back button. Custom the back event at onOptionsItemSelected.
You have to register your chrome-cast as a testing devise for you to be able to detect the chromecast devise from the Android.
Check the full SDK guide
Check the developer console registration. You have to register you chromecast devise in the console here, or else it is not detectable
Update: If nothing works, you may try to publish your app in the chromecast dev console as a last resort.
As mentioned by one of the chromecast developer try to access http://<chromecast-ip>:9222
from browser and see if you are able to see any thing.
Sometimes, these types of errors happen because proguard changes the name of the object and/or functions.
One possible solution is to add these to your progaurd configuration files:
-dontwarn android.support.v7.**
-keep class android.support.v7.internal.** { *; }
-keep interface android.support.v7.internal.** { *; }
-keep class android.support.v7.** { *; }
-keep interface android.support.v7.** { *; }
I actually had this exact error on the exact line and I didn't have my proguard configured properly for the support library.
In my case after device registration I forgot reboot chromecast
device
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With