title: Android Chromecast sender app, cast button doesn't appear in action bar
body: <p>I went through this <a href="https://developers.google.com/cast/docs/android_sender" rel="nofollow noreferrer">https://developers.google.com/cast/docs/android_sender</a>
  up to "Handling device selection" paragraph including.
  I expect that cast button should appear in action bar, but it isn't. And I suppose that Chromecast device was not been discovered.</p>
  
  <p>I have real Chromecast device and I registered it in Google Cast SDK Developer Console.
  And I suppose that device whitelisted because I have access to http:// chromecast_device_ip:9222</p>
  
  <p>I set "checked" for option "Send this Chromecast's serial number when checking for updates" 2 days ago. And I rebooted the device after that.</p>
  
  <p>Also, I registered an application in Google Cast SDK Developer Console. But it's not published yet.
  I think it can't be the reason, isn't it?</p>
  
  <p>I use DEFAULT_MEDIA_RECEIVER_APPLICATION_ID as APP_ID. But I also tried APP_ID of my registered application.</p>
  
  <p>I tried sample apps from GitHub:
  <a href="https://github.com/googlecast" rel="nofollow noreferrer">https://github.com/googlecast</a>
  Cast Tic-Tac-Toe, 
  CastVideos-android,
  MediaRouter-Cast-Button-android.
  And in all sample apps was the same problem. Cast button doesn't appear.</p>
  
  <p>In DIAL CLient app (author entertailion) all work fine. But I'm not sure that it is what I need to implement Chromecast sender app...</p>
  
  <p>here is my code:</p>
  
  <p>AndroidManifest.xml</p>
  
  <pre><code>&lt;manifest xmlns:android="http://schemas.android.com/apk/res/android"
  package="com.example.testcastbtn"
  android:versionCode="1"
  android:versionName="1.0" &gt;
  
  &lt;uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" /&gt;
  &lt;uses-permission android:name="android.permission.INTERNET" /&gt;
  &lt;uses-permission android:name="android.permission.ACCESS_WIFI_STATE" /&gt;
  &lt;uses-permission android:name="android.permission.CHANGE_WIFI_STATE" /&gt;
  
  &lt;uses-sdk
      android:minSdkVersion="9"
      android:targetSdkVersion="21" /&gt;
  
  &lt;application
      android:allowBackup="true"
      android:icon="@drawable/ic_launcher"
      android:label="@string/app_name"
      android:theme="@style/Theme.AppCompat" &gt;
      &lt;meta-data
          android:name="com.google.android.gms.version"
          android:value="@integer/google_play_services_version" /&gt;
      &lt;activity
          android:name=".MainActivity"
          android:label="@string/app_name" &gt;
          &lt;intent-filter&gt;
              &lt;action android:name="android.intent.action.MAIN" /&gt;
  
              &lt;category android:name="android.intent.category.LAUNCHER" /&gt;
          &lt;/intent-filter&gt;
      &lt;/activity&gt;
  &lt;/application&gt;
  </code></pre>
  
  <p></p>
  
  <p>MainActivity.java</p>
  
  <pre><code>package com.example.testcastbtn;
  
  import com.google.android.gms.cast.CastDevice;
  import com.google.android.gms.cast.CastMediaControlIntent;
  import com.google.android.gms.common.GooglePlayServicesUtil;
  
  import android.support.v4.view.MenuItemCompat;
  import android.support.v7.app.ActionBarActivity;
  import android.support.v7.app.MediaRouteActionProvider;
  import android.support.v7.media.MediaRouteSelector;
  import android.support.v7.media.MediaRouter;
  import android.support.v7.media.MediaRouter.RouteInfo;
  import android.os.Bundle;
  import android.util.Log;
  import android.view.Menu;
  import android.view.MenuItem;
  
  public class MainActivity extends ActionBarActivity {
  
  private MediaRouter mMediaRouter;
  private MediaRouteSelector mMediaRouteSelector;
  private MyMediaRouterCallback mMediaRouterCallback;
  public CastDevice mSelectedDevice;
  
  @Override
  protected void onCreate(Bundle savedInstanceState) {
      super.onCreate(savedInstanceState);
      setContentView(R.layout.activity_main);
      mMediaRouter = MediaRouter.getInstance(getApplicationContext());
      mMediaRouteSelector = new MediaRouteSelector.Builder()
          .addControlCategory(CastMediaControlIntent.categoryForCast(
                  CastMediaControlIntent.DEFAULT_MEDIA_RECEIVER_APPLICATION_ID))
          .build();        
      mMediaRouterCallback = new MyMediaRouterCallback();
      int isGAvailable = GooglePlayServicesUtil.isGooglePlayServicesAvailable(this);
  }
  
  private class MyMediaRouterCallback extends MediaRouter.Callback {    
  
      @Override
      public void onRouteSelected(MediaRouter router, RouteInfo info) {
          mSelectedDevice = CastDevice.getFromBundle(info.getExtras());
      }
  
      @Override
      public void onRouteUnselected(MediaRouter router, RouteInfo info) {
          mSelectedDevice = null;
      }
  }
  
  @Override
  protected void onStart() {      
      super.onStart();
      mMediaRouter.addCallback(mMediaRouteSelector, mMediaRouterCallback,
              MediaRouter.CALLBACK_FLAG_PERFORM_ACTIVE_SCAN);
  }
  
  @Override
  protected void onResume() {
    super.onResume();
    mMediaRouter.addCallback(mMediaRouteSelector, mMediaRouterCallback,
                                  MediaRouter.CALLBACK_FLAG_PERFORM_ACTIVE_SCAN);
  }
  
  @Override
  protected void onPause() {
    if (isFinishing()) {
      mMediaRouter.removeCallback(mMediaRouterCallback);
    }
    super.onPause();
  }
  
  @Override
  protected void onStop() {
      mMediaRouter.removeCallback(mMediaRouterCallback);
      super.onStop();
  }
  
  @Override
  public boolean onCreateOptionsMenu(Menu menu) {
      getMenuInflater().inflate(R.menu.main, menu);
      MenuItem mediaRouteMenuItem = menu.findItem(R.id.media_route_menu_item);
      MediaRouteActionProvider mediaRouteActionProvider = 
        (MediaRouteActionProvider) MenuItemCompat.getActionProvider(mediaRouteMenuItem);
      mediaRouteActionProvider.setRouteSelector(mMediaRouteSelector);
      return true;
  }
  
  @Override
  public boolean onOptionsItemSelected(MenuItem item) {
      int id = item.getItemId();
      if (id == R.id.media_route_menu_item) {
          return true;
      }
      return super.onOptionsItemSelected(item);
  }
  
  }
  </code></pre>
  
  <p>menu.xml</p>
  
  <pre><code>&lt;menu xmlns:android="http://schemas.android.com/apk/res/android"
  xmlns:app="http://schemas.android.com/apk/res-auto"
  xmlns:tools="http://schemas.android.com/tools"
  tools:context="com.example.testcastbtn.MainActivity" &gt;
  
  &lt;item
      android:id="@+id/test_menu_item"
      android:title="@string/test_menu_title"
      app:showAsAction="always"/&gt;
  &lt;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"/&gt;
  
  
  &lt;/menu&gt;
  </code></pre>
  
  <p>Also, I got next errors in LogCat. But it not crashes app.</p>
  
  <pre><code>08-01 16:21:17.644: E/ExternalAccountType(547): Unsupported attribute readOnly
  08-01 16:21:19.196: E/MediaProvider(21126): invalid album art, error creating album thumb file
  08-01 16:21:22.249: E/dalvikvm(21520): Could not find class 'com.google.android.apps.youtube.app.remote.bi', referenced from method com.google.android.apps.youtube.app.remote.bh.&lt;init&gt;
  08-01 16:21:22.269: E/dalvikvm(21520): Could not find class 'com.google.android.apps.youtube.core.player.notification.a', referenced from method com.google.android.apps.youtube.core.player.notification.ExternalPlaybackControllerV14.&lt;init&gt;
  </code></pre>
  
  <p><strong>UPDATE</strong></p>
  
  <p>Leon Nicholls said that it is known discovery issue in the previous release of the Cast SDK. A new version 5.0.89 of Google Play Services should work fine.</p>
  
  <p>I suppose that I have an old release of the Cast SDK.
  In google-play-services_lib/AndroidManifest.xml I see next</p>
  
  <pre><code>&lt;manifest xmlns:android="http://schemas.android.com/apk/res/android" android:versionCode="5077000" android:versionName="5.0.77-000"
  </code></pre>
  
  <p>But I have no idea how to update it. In Android SDK Manager Google Play Services marked as installed and there is nothing to update....</p>