Why is my MediaRouteButton unavailable for finding any cast devices?

the following are my codes in the main action

public class MainActivity extends ActionBarActivity{
private MediaRouteButton mMediaRouteButton;
private MediaRouteSelector mMediaRouteSelector;
private MediaRouter mMediaRouter;
private CastDevice mSelectedDevice;
private MyMediaRouterCallback mMediaRouterCallback;
@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);
    if(this.checkGooglePlaySevices(this))
        Log.v("cc5zhenhua","googleplayservice okay");
    else
    {
        Log.v("cc5zhenhua","googleplayservice not ok");
        //GooglePlayServicesUtil.getErrorDialog(0, this, 0).show();
    }
    //initialize media cast objects
     mMediaRouter=MediaRouter.getInstance(getApplicationContext());      
     mMediaRouteSelector=new MediaRouteSelector.Builder()
     .addControlCategory(CastMediaControlIntent.CATEGORY_CAST).build();      
     mMediaRouterCallback= new MyMediaRouterCallback();
     mMediaRouter.addCallback(mMediaRouteSelector, mMediaRouterCallback);    
}

public void onStart() {
    super.onStart();
    mMediaRouter.addCallback(mMediaRouteSelector, mMediaRouterCallback
            );
    MediaRouter.RouteInfo route = mMediaRouter.updateSelectedRoute(mMediaRouteSelector);
    // do something with the route...
}
@Override
protected void onResume()
{
    super.onResume();
    mMediaRouter.addCallback(mMediaRouteSelector, mMediaRouterCallback);
}
@Override
public boolean onCreateOptionsMenu(Menu menu) {
    // Inflate the menu; this adds items to the action bar if it is present.
    super.onCreateOptionsMenu(menu);

    //mMediaRouteButton.setRouteSelector(mMediaRouteSelector);
    return true;
}
@Override
public boolean onPrepareOptionsMenu(Menu menu){
    getMenuInflater().inflate(R.menu.main, menu);
    MenuItem mediaRouteItem = menu.findItem( R.id.action_mediaroute01 );
    MediaRouteActionProvider mediaRouteActionProvider =
            (MediaRouteActionProvider)MenuItemCompat.getActionProvider(
                    mediaRouteItem);
    mediaRouteActionProvider.setRouteSelector(mMediaRouteSelector);
    mMediaRouteButton = (MediaRouteButton) mediaRouteItem.getActionView();
    return true;}

 public  boolean checkGooglePlaySevices(final Activity activity) {
        final int googlePlayServicesCheck = GooglePlayServicesUtil.isGooglePlayServicesAvailable(
                activity);
        switch (googlePlayServicesCheck) {
            case ConnectionResult.SUCCESS:
                return true;
            default:
               Log.v("cc5zhenhua","test");          }
        return false;
 }
private class MyMediaRouterCallback extends MediaRouter.Callback 
{
  @Override
  public void onRouteSelected(MediaRouter router, RouteInfo info) {
    mSelectedDevice = CastDevice.getFromBundle(info.getExtras());
    String routeId = info.getId();
    Log.v("cc5zhenhua", "MainActivity.onRouteSelected");        
  }
  @Override
  public void onRouteUnselected(MediaRouter router, RouteInfo info) {
    //teardown();
    mSelectedDevice = null;
  }
}

}

There is no build error. However, when I start the main action, the media channel button cannot be pressed at all. Please tell me where I missed? Thank!

My color chromatin is registered using APPID before the publication of the new SDK. I also can not use this appID for the management category, it does not exclude valida application exception.

My casting application is also available to expand the chrome in my computer.

+1
source share
2 answers

, . , sdk googlecast AVD, SDK. , , . .

0

, :

mMediaRouter.addCallback(mMediaRouteSelector, mMediaRouterCallback, MediaRouter.CALLBACK_FLAG_PERFORM_ACTIVE_SCAN);

, . , , ; Chrome http://<chromecast-ip>:9222, , ; , ,

+1

Source: https://habr.com/ru/post/1539057/


All Articles