The FIT Radio app uses MediaRoute.Callback, which is initialized in my CommandInterface class, which controls the playback of normal sound as well as Chromecast audio. Now NowPlayingActivity is set as mMediaRouteButtonHandler inside MediaRoute.Callback only if MediaRouteButton exists.
Now now_playing.xml is in the default layout, with safeguards in the java source code. Our first measure of protection against null pointer exceptions (with G2) was to remove MediaRouteButton from the default layout. The second measure that was taken to stop null pointer exceptions was to add a null check in the NowPlayingActivity.setVisibility (int visibility) code example below for any other version that might not contain a button (N7, etc.).
The MediaRouter callback is added to NowPlayingActvity.onResume () and deleted in NowPlayingActvity.onPause (). The following example displays visibility processing in MediaRoute.Callback.onRouteAdded:
public void onRouteAdded(MediaRouter router, RouteInfo route) {
if(hasMediaRouteButtonHandler()) mMediaRouteButtonHandler.setVisibility(View.VISIBLE);
++mRouteCount;
}
Google G2, Note 3, Samsung S III, HTC One M7 Nexus 7. MediaRoute.Callback MediaRoute [ NowPlayingActivity.setVisibility(int )], Nexus 7 Google G2.
public void setVisibility(int visibility) {
if(getMediaRouteButton() != null) getMediaRouteButton().setVisibility(visibility);
}
findViewById (int) NowPlayingActvity null (Nexus 7 G2), S III, HTC One Note 3.
public MediaRouteButton getMediaRouteButton() {
return (MediaRouteButton) findViewById(R.id.media_route_button);
}
StackOverflow , :
, , , .
android.support.v7.app.MediaRouteButton
, :
MediaRouteButton - ?
, (My Contractee) ! , !
,
, Dirk @Fit Radio.