Cast Button未在我的应用程序的Actionbar中显示

时间:2016-10-26 07:09:18

标签: android

CastOptionsProvider类

public class CastOptionsProvider implements OptionsProvider {

 @Override
 public CastOptions getCastOptions(Context context) {

        return new CastOptions.Builder()
                .setReceiverApplicationId(context.getString(R.string.app_id))
                .build();
    }
    @Override
    public List<SessionProvider> getAdditionalSessionProviders(Context context) 
        return null;
    }
}

MainActivity

 @Override
    protected void onCreate(Bundle savedInstanceState) {

        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
 mCastContext = CastContext.getSharedInstance(this);
}

 private MenuItem mediaRouteMenuItem;

    @Override

    public boolean onCreateOptionsMenu(Menu menu) {

        super.onCreateOptionsMenu(menu);

        getMenuInflater().inflate(R.menu.menu2, menu);

        mediaRouteMenuItem =
                CastButtonFactory.setUpMediaRouteButton(getApplicationContext(),
                        menu,
                        R.id.media_route_menu_item);
        return true;
    }

依赖条件

dependencies{
compile 'com.android.support:appcompat-v7:23.1.1'
compile 'com.android.support:mediarouter-v7:23.0.0'
compile 'com.google.android.gms:play-services-cast-framework:9.4.0'
}

0 个答案:

没有答案