Adding a throw button to an ActionBar using CastCompanionLibrary

I am trying to add a translation icon to an ActionBar using the CastCompanionLibrary 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 indicated in the PDF, which is part of 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 is displayed in the ActionBar. Errors do not arise, nothing is visible. If I add another menu item to check if everything with my menu is configured correctly, this item displays well - it is just an action action menu item that does not display.

I tried changing the prefixes "application" to "android", but then I got a NullPointerException somewhere deep in the library, and I tried to give this menu item a different, visible icon. Nothing helps.

In AndroidStudio, the menu preview displays a menu item that says "Play on ...", so it seems like this should work.

What am I doing wrong?

+6
source share
4 answers

You need to register chrome casting as a test application so that you can detect chrome casting from Android.

Check out the complete SDK manual
Check your console developer registration. Here you must register the chrome device in the console, otherwise it will not be detected

Update: If nothing works, you can try publishing your application to the Chromeecast console as a last resort.

As already mentioned, one of the chromatization developers will try to access http://<chromecast-ip>:9222 from the browser and see if you can see anything.

+2
source

Sometimes these types of errors occur because proguard changes the name of the object and / or function.

One possible solution is to add them to the 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 did not have the proper proguard settings for the support library.

+1
source

In my case, after registering the device, I forgot to restart the chromecast device

+1
source

CastCompanionLibrary and MediaRouteActionProvider are written for the AppCompat ActionBar, not for the Sherlock ActionBar. Moving your project to AppCompat is highly recommended since the Sherlock ActionBar is deprecated, so switching to AppCompat is usually a good move for your project; (see, for example, this article )

0
source

All Articles