# MediaRouter

Artifact: [androidx.mediarouter:mediarouter](https://developer.android.com/jetpack/androidx/releases/mediarouter) [View Source](https://cs.android.com/search?q=file:androidx/mediarouter/media/MediaRouter.java+class:androidx.mediarouter.media.MediaRouter) Added in [1.1.0](https://developer.android.com/jetpack/androidx/releases/mediarouter#1.1.0)

*** ** * ** ***


```
public final class MediaRouter
```

<br />

*** ** * ** ***

MediaRouter allows applications to control the routing of media channels and streams from the current device to external speakers and destination devices.

A MediaRouter instance is retrieved through `https://developer.android.com/reference/androidx/mediarouter/media/MediaRouter#getInstance(android.content.Context)`. Applications can query the media router about the currently selected route and its capabilities to determine how to send content to the route's destination. Applications can also `https://developer.android.com/reference/androidx/mediarouter/media/MediaRouter.RouteInfo#sendControlRequest(android.content.Intent,androidx.mediarouter.media.MediaRouter.ControlRequestCallback)` to the route to ask the route's destination to perform certain remote control functions such as playing media.

See also `https://developer.android.com/reference/androidx/mediarouter/media/MediaRouteProvider` for information on how an application can publish new media routes to the media router.

The media router API is not thread-safe; all interactions with it must be done from the main thread of the process.

## Summary

| ### Nested types |
|---|
| `public abstract class https://developer.android.com/reference/androidx/mediarouter/media/MediaRouter.Callback` Interface for receiving events about media routing changes. |
| `public abstract class https://developer.android.com/reference/androidx/mediarouter/media/MediaRouter.ControlRequestCallback` Callback which is invoked with the result of a media control request. |
| `public interface https://developer.android.com/reference/androidx/mediarouter/media/MediaRouter.DeviceSuggestionsUpdatesCallback` Callback for receiving events about `https://developer.android.com/reference/androidx/mediarouter/media/MediaRouter#getDeviceSuggestions()`. |
| `public class https://developer.android.com/reference/androidx/mediarouter/media/MediaRouter.GroupRouteInfo extends https://developer.android.com/reference/androidx/mediarouter/media/MediaRouter.RouteInfo` Provides information about a media route that represents a dynamic group. |
| `public interface https://developer.android.com/reference/androidx/mediarouter/media/MediaRouter.OnPrepareTransferListener` Listener for receiving events when the selected route is about to be changed. |
| `public final class https://developer.android.com/reference/androidx/mediarouter/media/MediaRouter.ProviderInfo` Provides information about a media route provider. |
| `public class https://developer.android.com/reference/androidx/mediarouter/media/MediaRouter.RouteInfo` Provides information about a media route. |

| ### Constants |
|---|---|
| `static final int` | `https://developer.android.com/reference/androidx/mediarouter/media/MediaRouter#AVAILABILITY_FLAG_IGNORE_DEFAULT_ROUTE() = 1` Flag for `https://developer.android.com/reference/androidx/mediarouter/media/MediaRouter#isRouteAvailable(androidx.mediarouter.media.MediaRouteSelector,int)`: Ignore the default route. |
| `static final int` | `https://developer.android.com/reference/androidx/mediarouter/media/MediaRouter#AVAILABILITY_FLAG_REQUIRE_MATCH() = 2` Flag for `https://developer.android.com/reference/androidx/mediarouter/media/MediaRouter#isRouteAvailable(androidx.mediarouter.media.MediaRouteSelector,int)`: Require an actual route to be matched. |
| `static final int` | `https://developer.android.com/reference/androidx/mediarouter/media/MediaRouter#CALLBACK_FLAG_FORCE_DISCOVERY() = 8` Flag for `https://developer.android.com/reference/androidx/mediarouter/media/MediaRouter#addCallback(androidx.mediarouter.media.MediaRouteSelector,androidx.mediarouter.media.MediaRouter.Callback)`: Request passive route discovery while this callback is registered, even on `https://developer.android.com/reference/android/app/ActivityManager.html#isLowRamDevice()`. |
| `static final int` | `https://developer.android.com/reference/androidx/mediarouter/media/MediaRouter#CALLBACK_FLAG_PERFORM_ACTIVE_SCAN() = 1` Flag for `https://developer.android.com/reference/androidx/mediarouter/media/MediaRouter#addCallback(androidx.mediarouter.media.MediaRouteSelector,androidx.mediarouter.media.MediaRouter.Callback)`: Actively scan for routes while this callback is registered. |
| `static final int` | `https://developer.android.com/reference/androidx/mediarouter/media/MediaRouter#CALLBACK_FLAG_REQUEST_DISCOVERY() = 4` Flag for `https://developer.android.com/reference/androidx/mediarouter/media/MediaRouter#addCallback(androidx.mediarouter.media.MediaRouteSelector,androidx.mediarouter.media.MediaRouter.Callback)`: Request passive route discovery while this callback is registered, except on `https://developer.android.com/reference/android/app/ActivityManager.html#isLowRamDevice()`. |
| `static final int` | `https://developer.android.com/reference/androidx/mediarouter/media/MediaRouter#CALLBACK_FLAG_UNFILTERED_EVENTS() = 2` Flag for `https://developer.android.com/reference/androidx/mediarouter/media/MediaRouter#addCallback(androidx.mediarouter.media.MediaRouteSelector,androidx.mediarouter.media.MediaRouter.Callback)`: Do not filter route events. |
| `static final int` | `https://developer.android.com/reference/androidx/mediarouter/media/MediaRouter#REASON_DISCONNECT_CALLED() = 1` The route connection is disconnected by `https://developer.android.com/reference/androidx/mediarouter/media/MediaRouter.RouteInfo#disconnect()`. |
| `static final int` | `https://developer.android.com/reference/androidx/mediarouter/media/MediaRouter#REASON_FAILED_TO_CREATE_DYNAMIC_GROUP_ROUTE_CONTROLLER() = 6` The route connection has failed because the provider for the requested route failed to create a dynamic group route controller. |
| `static final int` | `https://developer.android.com/reference/androidx/mediarouter/media/MediaRouter#REASON_REJECTED_FOR_SELECTED_ROUTE() = 4` The route connection has failed because the requested route is a selected route. |
| `static final int` | `https://developer.android.com/reference/androidx/mediarouter/media/MediaRouter#REASON_ROUTE_CONNECTION_TIMEOUT() = 7` The route connection has failed due to a timeout. |
| `static final int` | `https://developer.android.com/reference/androidx/mediarouter/media/MediaRouter#REASON_ROUTE_NOT_AVAILABLE() = 2` The route connection has failed because the requested route is no longer available. |
| `static final int` | `https://developer.android.com/reference/androidx/mediarouter/media/MediaRouter#REASON_ROUTE_NOT_ENABLED() = 3` The route connection has failed because the requested route is not enabled. |
| `static final int` | `https://developer.android.com/reference/androidx/mediarouter/media/MediaRouter#REASON_UNSUPPORTED_FOR_NON_DYNAMIC_CONTROLLER() = 5` The route connection has failed because the provider for the requested route doesn't support dynamic groups. |
| `static final int` | `https://developer.android.com/reference/androidx/mediarouter/media/MediaRouter#UNSELECT_REASON_DISCONNECTED() = 1` Passed to `https://developer.android.com/reference/androidx/mediarouter/media/MediaRouteProvider.RouteController#onUnselect(int)`, `https://developer.android.com/reference/androidx/mediarouter/media/MediaRouter.Callback#onRouteUnselected(androidx.mediarouter.media.MediaRouter,androidx.mediarouter.media.MediaRouter.RouteInfo,int)` and `https://developer.android.com/reference/androidx/mediarouter/media/MediaRouter.Callback#onRouteSelected(androidx.mediarouter.media.MediaRouter,androidx.mediarouter.media.MediaRouter.RouteInfo,int)` when the user pressed the disconnect button to disconnect and keep playing. |
| `static final int` | `https://developer.android.com/reference/androidx/mediarouter/media/MediaRouter#UNSELECT_REASON_ROUTE_CHANGED() = 3` Passed to `https://developer.android.com/reference/androidx/mediarouter/media/MediaRouteProvider.RouteController#onUnselect(int)`, `https://developer.android.com/reference/androidx/mediarouter/media/MediaRouter.Callback#onRouteUnselected(androidx.mediarouter.media.MediaRouter,androidx.mediarouter.media.MediaRouter.RouteInfo,int)` and `https://developer.android.com/reference/androidx/mediarouter/media/MediaRouter.Callback#onRouteSelected(androidx.mediarouter.media.MediaRouter,androidx.mediarouter.media.MediaRouter.RouteInfo,int)` when the user selected a different route. |
| `static final int` | `https://developer.android.com/reference/androidx/mediarouter/media/MediaRouter#UNSELECT_REASON_STOPPED() = 2` Passed to `https://developer.android.com/reference/androidx/mediarouter/media/MediaRouteProvider.RouteController#onUnselect(int)`, `https://developer.android.com/reference/androidx/mediarouter/media/MediaRouter.Callback#onRouteUnselected(androidx.mediarouter.media.MediaRouter,androidx.mediarouter.media.MediaRouter.RouteInfo,int)` and `https://developer.android.com/reference/androidx/mediarouter/media/MediaRouter.Callback#onRouteSelected(androidx.mediarouter.media.MediaRouter,androidx.mediarouter.media.MediaRouter.RouteInfo,int)` when the user pressed the stop casting button. |
| `static final int` | `https://developer.android.com/reference/androidx/mediarouter/media/MediaRouter#UNSELECT_REASON_UNKNOWN() = 0` Passed to `https://developer.android.com/reference/androidx/mediarouter/media/MediaRouteProvider.RouteController#onUnselect(int)`, `https://developer.android.com/reference/androidx/mediarouter/media/MediaRouter.Callback#onRouteUnselected(androidx.mediarouter.media.MediaRouter,androidx.mediarouter.media.MediaRouter.RouteInfo,int)` and `https://developer.android.com/reference/androidx/mediarouter/media/MediaRouter.Callback#onRouteSelected(androidx.mediarouter.media.MediaRouter,androidx.mediarouter.media.MediaRouter.RouteInfo,int)` when the reason the route was unselected is unknown. |

| ### Public methods |
|---|---|
| `void` | `@https://developer.android.com/reference/androidx/annotation/MainThread https://developer.android.com/reference/androidx/mediarouter/media/MediaRouter#addCallback(androidx.mediarouter.media.MediaRouteSelector,androidx.mediarouter.media.MediaRouter.Callback)( @https://jspecify.dev/docs/api/org/jspecify/annotations/NonNull.html https://developer.android.com/reference/androidx/mediarouter/media/MediaRouteSelector selector, @https://jspecify.dev/docs/api/org/jspecify/annotations/NonNull.html https://developer.android.com/reference/androidx/mediarouter/media/MediaRouter.Callback callback )` Registers a callback to discover routes that match the selector and to receive events when they change. |
| `void` | `@https://developer.android.com/reference/androidx/annotation/MainThread https://developer.android.com/reference/androidx/mediarouter/media/MediaRouter#addCallback(androidx.mediarouter.media.MediaRouteSelector,androidx.mediarouter.media.MediaRouter.Callback,int)( @https://jspecify.dev/docs/api/org/jspecify/annotations/NonNull.html https://developer.android.com/reference/androidx/mediarouter/media/MediaRouteSelector selector, @https://jspecify.dev/docs/api/org/jspecify/annotations/NonNull.html https://developer.android.com/reference/androidx/mediarouter/media/MediaRouter.Callback callback, int flags )` Registers a callback to discover routes that match the selector and to receive events when they change. |
| `void` | `@https://developer.android.com/reference/androidx/annotation/MainThread https://developer.android.com/reference/androidx/mediarouter/media/MediaRouter#addProvider(androidx.mediarouter.media.MediaRouteProvider)(@https://jspecify.dev/docs/api/org/jspecify/annotations/NonNull.html https://developer.android.com/reference/androidx/mediarouter/media/MediaRouteProvider providerInstance)` Registers a media route provider within this application process. |
| `void` | `@https://developer.android.com/reference/androidx/annotation/MainThread [addRemoteControlClient](https://developer.android.com/reference/androidx/mediarouter/media/MediaRouter#addRemoteControlClient(java.lang.Object))(@https://jspecify.dev/docs/api/org/jspecify/annotations/NonNull.html https://developer.android.com/reference/java/lang/Object.html remoteControlClient)` **This method is deprecated.** Use `https://developer.android.com/reference/androidx/mediarouter/media/MediaRouter#setMediaSessionCompat(android.support.v4.media.session.MediaSessionCompat)` instead. <br /> |
| `void` | `@https://developer.android.com/reference/androidx/annotation/MainThread https://developer.android.com/reference/androidx/mediarouter/media/MediaRouter#clearDeviceSuggestions()()` Clears the `https://developer.android.com/reference/androidx/mediarouter/media/SuggestedDeviceInfo` provided by this router. |
| `@https://jspecify.dev/docs/api/org/jspecify/annotations/Nullable.html https://developer.android.com/reference/androidx/mediarouter/media/MediaRouter.RouteInfo` | `@https://developer.android.com/reference/androidx/annotation/MainThread https://developer.android.com/reference/androidx/mediarouter/media/MediaRouter#getBluetoothRoute()()` Gets a bluetooth route for playing media content on the system. |
| `@https://jspecify.dev/docs/api/org/jspecify/annotations/NonNull.html https://developer.android.com/reference/java/util/List.html<https://developer.android.com/reference/androidx/mediarouter/media/MediaRouter.GroupRouteInfo>` | `@https://developer.android.com/reference/androidx/annotation/MainThread https://developer.android.com/reference/androidx/mediarouter/media/MediaRouter#getConnectedGroupRoutes()()` Returns the currently connected dynamic group routes. |
| `@https://jspecify.dev/docs/api/org/jspecify/annotations/NonNull.html https://developer.android.com/reference/androidx/mediarouter/media/MediaRouter.RouteInfo` | `@https://developer.android.com/reference/androidx/annotation/MainThread https://developer.android.com/reference/androidx/mediarouter/media/MediaRouter#getDefaultRoute()()` Gets the default route for playing media content on the system. |
| `@https://jspecify.dev/docs/api/org/jspecify/annotations/NonNull.html https://developer.android.com/reference/java/util/Map.html<https://developer.android.com/reference/java/lang/String.html, https://developer.android.com/reference/java/util/List.html<https://developer.android.com/reference/androidx/mediarouter/media/SuggestedDeviceInfo>>` | `@https://developer.android.com/reference/androidx/annotation/MainThread https://developer.android.com/reference/androidx/mediarouter/media/MediaRouter#getDeviceSuggestions()()` Gets the current suggested devices. |
| `static @https://jspecify.dev/docs/api/org/jspecify/annotations/NonNull.html https://developer.android.com/reference/androidx/mediarouter/media/MediaRouter` | `@https://developer.android.com/reference/androidx/annotation/MainThread https://developer.android.com/reference/androidx/mediarouter/media/MediaRouter#getInstance(android.content.Context)(@https://jspecify.dev/docs/api/org/jspecify/annotations/NonNull.html https://developer.android.com/reference/android/content/Context.html context)` Gets an instance of the media router service associated with the context. |
| `@https://jspecify.dev/docs/api/org/jspecify/annotations/Nullable.html https://developer.android.com/reference/android/support/v4/media/session/MediaSessionCompat.Token` | `https://developer.android.com/reference/androidx/mediarouter/media/MediaRouter#getMediaSessionToken()()` |
| `@https://jspecify.dev/docs/api/org/jspecify/annotations/NonNull.html https://developer.android.com/reference/java/util/List.html<https://developer.android.com/reference/androidx/mediarouter/media/MediaRouter.ProviderInfo>` | `@https://developer.android.com/reference/androidx/annotation/MainThread https://developer.android.com/reference/androidx/mediarouter/media/MediaRouter#getProviders()()` Gets information about the `https://developer.android.com/reference/androidx/mediarouter/media/MediaRouter.ProviderInfo` currently known to this media router. |
| `@https://jspecify.dev/docs/api/org/jspecify/annotations/Nullable.html https://developer.android.com/reference/androidx/mediarouter/media/MediaRouterParams` | `@https://developer.android.com/reference/androidx/annotation/MainThread https://developer.android.com/reference/androidx/mediarouter/media/MediaRouter#getRouterParams()()` Gets `https://developer.android.com/reference/androidx/mediarouter/media/MediaRouterParams` of the media router service associated with this media router. |
| `@https://jspecify.dev/docs/api/org/jspecify/annotations/NonNull.html https://developer.android.com/reference/java/util/List.html<https://developer.android.com/reference/androidx/mediarouter/media/MediaRouter.RouteInfo>` | `@https://developer.android.com/reference/androidx/annotation/MainThread https://developer.android.com/reference/androidx/mediarouter/media/MediaRouter#getRoutes()()` Gets information about the `https://developer.android.com/reference/androidx/mediarouter/media/MediaRouter.RouteInfo` currently known to this media router. |
| `@https://jspecify.dev/docs/api/org/jspecify/annotations/NonNull.html https://developer.android.com/reference/androidx/mediarouter/media/MediaRouter.RouteInfo` | `@https://developer.android.com/reference/androidx/annotation/MainThread https://developer.android.com/reference/androidx/mediarouter/media/MediaRouter#getSelectedRoute()()` Gets the currently selected route. |
| `static boolean` | `https://developer.android.com/reference/androidx/mediarouter/media/MediaRouter#isMediaTransferEnabled()()` Returns whether the media transfer feature is enabled. |
| `boolean` | `@https://developer.android.com/reference/androidx/annotation/MainThread https://developer.android.com/reference/androidx/mediarouter/media/MediaRouter#isRouteAvailable(androidx.mediarouter.media.MediaRouteSelector,int)(@https://jspecify.dev/docs/api/org/jspecify/annotations/NonNull.html https://developer.android.com/reference/androidx/mediarouter/media/MediaRouteSelector selector, int flags)` Returns true if there is a route that matches the specified selector. |
| `void` | `@https://developer.android.com/reference/androidx/annotation/MainThread https://developer.android.com/reference/androidx/mediarouter/media/MediaRouter#registerDeviceSuggestionsUpdatesCallback(androidx.mediarouter.media.MediaRouter.DeviceSuggestionsUpdatesCallback,java.util.concurrent.Executor)( @https://jspecify.dev/docs/api/org/jspecify/annotations/NonNull.html https://developer.android.com/reference/androidx/mediarouter/media/MediaRouter.DeviceSuggestionsUpdatesCallback deviceSuggestionsUpdatesCallback, @https://jspecify.dev/docs/api/org/jspecify/annotations/Nullable.html https://developer.android.com/reference/java/util/concurrent/Executor.html executor )` Registers the given callback to be invoked when the `https://developer.android.com/reference/androidx/mediarouter/media/SuggestedDeviceInfo` of the router changes. |
| `void` | `@https://developer.android.com/reference/androidx/annotation/MainThread https://developer.android.com/reference/androidx/mediarouter/media/MediaRouter#removeCallback(androidx.mediarouter.media.MediaRouter.Callback)(@https://jspecify.dev/docs/api/org/jspecify/annotations/NonNull.html https://developer.android.com/reference/androidx/mediarouter/media/MediaRouter.Callback callback)` Removes the specified callback. |
| `void` | `@https://developer.android.com/reference/androidx/annotation/MainThread https://developer.android.com/reference/androidx/mediarouter/media/MediaRouter#removeProvider(androidx.mediarouter.media.MediaRouteProvider)(@https://jspecify.dev/docs/api/org/jspecify/annotations/NonNull.html https://developer.android.com/reference/androidx/mediarouter/media/MediaRouteProvider providerInstance)` Unregisters a media route provider within this application process. |
| `void` | `@https://developer.android.com/reference/androidx/annotation/MainThread [removeRemoteControlClient](https://developer.android.com/reference/androidx/mediarouter/media/MediaRouter#removeRemoteControlClient(java.lang.Object))(@https://jspecify.dev/docs/api/org/jspecify/annotations/NonNull.html https://developer.android.com/reference/java/lang/Object.html remoteControlClient)` **This method is deprecated.** Call `https://developer.android.com/reference/androidx/mediarouter/media/MediaRouter#setMediaSessionCompat(android.support.v4.media.session.MediaSessionCompat)` instead of `https://developer.android.com/reference/androidx/mediarouter/media/MediaRouter#addRemoteControlClient(java.lang.Object)` so that there is no need to call this method. <br /> |
| `void` | `@https://developer.android.com/reference/androidx/annotation/MainThread https://developer.android.com/reference/androidx/mediarouter/media/MediaRouter#selectRoute(androidx.mediarouter.media.MediaRouter.RouteInfo)(@https://jspecify.dev/docs/api/org/jspecify/annotations/NonNull.html https://developer.android.com/reference/androidx/mediarouter/media/MediaRouter.RouteInfo route)` Selects the specified route. |
| `void` | `@https://developer.android.com/reference/androidx/annotation/MainThread https://developer.android.com/reference/androidx/mediarouter/media/MediaRouter#setDeviceSuggestions(java.util.List<androidx.mediarouter.media.MediaRouter.RouteInfo>)(@https://jspecify.dev/docs/api/org/jspecify/annotations/NonNull.html https://developer.android.com/reference/java/util/List.html<https://developer.android.com/reference/androidx/mediarouter/media/MediaRouter.RouteInfo> routes)` Sets a list of suggested routes. |
| `void` | `@https://developer.android.com/reference/androidx/annotation/MainThread https://developer.android.com/reference/androidx/mediarouter/media/MediaRouter#setMediaSession(java.lang.Object)(@https://jspecify.dev/docs/api/org/jspecify/annotations/Nullable.html https://developer.android.com/reference/java/lang/Object.html mediaSession)` Equivalent to `https://developer.android.com/reference/androidx/mediarouter/media/MediaRouter#setMediaSessionCompat(android.support.v4.media.session.MediaSessionCompat)`, except it takes an `https://developer.android.com/reference/android/media/session/MediaSession.html`. |
| `void` | `@https://developer.android.com/reference/androidx/annotation/MainThread https://developer.android.com/reference/androidx/mediarouter/media/MediaRouter#setMediaSessionCompat(android.support.v4.media.session.MediaSessionCompat)(@https://jspecify.dev/docs/api/org/jspecify/annotations/Nullable.html https://developer.android.com/reference/android/support/v4/media/session/MediaSessionCompat mediaSession)` Associates the provided `https://developer.android.com/reference/android/support/v4/media/session/MediaSessionCompat` to this router. |
| `void` | `@https://developer.android.com/reference/androidx/annotation/MainThread https://developer.android.com/reference/androidx/mediarouter/media/MediaRouter#setOnPrepareTransferListener(androidx.mediarouter.media.MediaRouter.OnPrepareTransferListener)( @https://jspecify.dev/docs/api/org/jspecify/annotations/Nullable.html https://developer.android.com/reference/androidx/mediarouter/media/MediaRouter.OnPrepareTransferListener listener )` Sets a listener for receiving events when the selected route is about to be changed. |
| `void` | `@https://developer.android.com/reference/androidx/annotation/MainThread https://developer.android.com/reference/androidx/mediarouter/media/MediaRouter#setRouteListingPreference(androidx.mediarouter.media.RouteListingPreference)( @https://jspecify.dev/docs/api/org/jspecify/annotations/Nullable.html https://developer.android.com/reference/androidx/mediarouter/media/RouteListingPreference routeListingPreference )` Sets the `https://developer.android.com/reference/androidx/mediarouter/media/RouteListingPreference` of the app associated to this media router. |
| `void` | `@https://developer.android.com/reference/androidx/annotation/MainThread https://developer.android.com/reference/androidx/mediarouter/media/MediaRouter#setRouterParams(androidx.mediarouter.media.MediaRouterParams)(@https://jspecify.dev/docs/api/org/jspecify/annotations/Nullable.html https://developer.android.com/reference/androidx/mediarouter/media/MediaRouterParams params)` Sets `https://developer.android.com/reference/androidx/mediarouter/media/MediaRouterParams` of the media router service associated with this media router. |
| `void` | `@https://developer.android.com/reference/androidx/annotation/MainThread https://developer.android.com/reference/androidx/mediarouter/media/MediaRouter#unregisterDeviceSuggestionsUpdatesCallback(androidx.mediarouter.media.MediaRouter.DeviceSuggestionsUpdatesCallback)( @https://jspecify.dev/docs/api/org/jspecify/annotations/NonNull.html https://developer.android.com/reference/androidx/mediarouter/media/MediaRouter.DeviceSuggestionsUpdatesCallback deviceSuggestionsUpdatesCallback )` Unregisters the given callback to be invoked when the `https://developer.android.com/reference/androidx/mediarouter/media/SuggestedDeviceInfo` of the router changes. |
| `void` | `@https://developer.android.com/reference/androidx/annotation/MainThread https://developer.android.com/reference/androidx/mediarouter/media/MediaRouter#unselect(int)(int reason)` Unselects the current route and selects the default route instead. |
| `@https://jspecify.dev/docs/api/org/jspecify/annotations/NonNull.html https://developer.android.com/reference/androidx/mediarouter/media/MediaRouter.RouteInfo` | `@https://developer.android.com/reference/androidx/annotation/MainThread https://developer.android.com/reference/androidx/mediarouter/media/MediaRouter#updateSelectedRoute(androidx.mediarouter.media.MediaRouteSelector)(@https://jspecify.dev/docs/api/org/jspecify/annotations/NonNull.html https://developer.android.com/reference/androidx/mediarouter/media/MediaRouteSelector selector)` Returns the selected route if it matches the specified selector, otherwise selects the default route and returns it. |

## Constants

### AVAILABILITY_FLAG_IGNORE_DEFAULT_ROUTE

Added in [1.1.0](https://developer.android.com/jetpack/androidx/releases/mediarouter#1.1.0)

```
public static final int AVAILABILITY_FLAG_IGNORE_DEFAULT_ROUTE = 1
```

Flag for `https://developer.android.com/reference/androidx/mediarouter/media/MediaRouter#isRouteAvailable(androidx.mediarouter.media.MediaRouteSelector,int)`: Ignore the default route.

This flag is used to determine whether a matching non-default route is available. This constraint may be used to decide whether to offer the route chooser dialog to the user. There is no point offering the chooser if there are no non-default choices.

### AVAILABILITY_FLAG_REQUIRE_MATCH

Added in [1.1.0](https://developer.android.com/jetpack/androidx/releases/mediarouter#1.1.0)

```
public static final int AVAILABILITY_FLAG_REQUIRE_MATCH = 2
```

Flag for `https://developer.android.com/reference/androidx/mediarouter/media/MediaRouter#isRouteAvailable(androidx.mediarouter.media.MediaRouteSelector,int)`: Require an actual route to be matched.

If this flag is not set, then `https://developer.android.com/reference/androidx/mediarouter/media/MediaRouter#isRouteAvailable(androidx.mediarouter.media.MediaRouteSelector,int)` will return true if it is possible to discover a matching route even if discovery is not in progress or if no matching route has yet been found. This feature is used to save resources by removing the need to perform passive route discovery on `https://developer.android.com/reference/android/app/ActivityManager.html#isLowRamDevice()`.

If this flag is set, then `https://developer.android.com/reference/androidx/mediarouter/media/MediaRouter#isRouteAvailable(androidx.mediarouter.media.MediaRouteSelector,int)` will only return true if a matching route has actually been discovered.

### CALLBACK_FLAG_FORCE_DISCOVERY

Added in [1.1.0](https://developer.android.com/jetpack/androidx/releases/mediarouter#1.1.0)

```
public static final int CALLBACK_FLAG_FORCE_DISCOVERY = 8
```

Flag for `https://developer.android.com/reference/androidx/mediarouter/media/MediaRouter#addCallback(androidx.mediarouter.media.MediaRouteSelector,androidx.mediarouter.media.MediaRouter.Callback)`: Request passive route discovery while this callback is registered, even on `https://developer.android.com/reference/android/app/ActivityManager.html#isLowRamDevice()`.

This flag has a significant performance impact on low-RAM devices since it may cause many media route providers to be started simultaneously. It is much better to use `https://developer.android.com/reference/androidx/mediarouter/media/MediaRouter#CALLBACK_FLAG_REQUEST_DISCOVERY()` instead to avoid performing passive discovery on these devices altogether. Refer to `https://developer.android.com/reference/androidx/mediarouter/media/MediaRouter#addCallback(androidx.mediarouter.media.MediaRouteSelector,androidx.mediarouter.media.MediaRouter.Callback,int)` for details.

| See also |
|---|---|
| `https://developer.android.com/reference/androidx/mediarouter/app/MediaRouteDiscoveryFragment` |   |

### CALLBACK_FLAG_PERFORM_ACTIVE_SCAN

Added in [1.1.0](https://developer.android.com/jetpack/androidx/releases/mediarouter#1.1.0)

```
public static final int CALLBACK_FLAG_PERFORM_ACTIVE_SCAN = 1
```

Flag for `https://developer.android.com/reference/androidx/mediarouter/media/MediaRouter#addCallback(androidx.mediarouter.media.MediaRouteSelector,androidx.mediarouter.media.MediaRouter.Callback)`: Actively scan for routes while this callback is registered.

When this flag is specified, the media router will actively scan for new routes. Certain routes, such as wifi display routes, may not be discoverable except when actively scanning. This flag is typically used when the route picker dialog has been opened by the user to ensure that the route information is up to date.

Active scanning may consume a significant amount of power and may have intrusive effects on wireless connectivity. Therefore it is important that active scanning only be requested when it is actually needed to satisfy a user request to discover and select a new route.

This flag implies `https://developer.android.com/reference/androidx/mediarouter/media/MediaRouter#CALLBACK_FLAG_REQUEST_DISCOVERY()` but performing active scans is much more expensive than a normal discovery request.

| See also |
|---|---|
| `https://developer.android.com/reference/androidx/mediarouter/media/MediaRouter#CALLBACK_FLAG_REQUEST_DISCOVERY()` |   |

### CALLBACK_FLAG_REQUEST_DISCOVERY

Added in [1.1.0](https://developer.android.com/jetpack/androidx/releases/mediarouter#1.1.0)

```
public static final int CALLBACK_FLAG_REQUEST_DISCOVERY = 4
```

Flag for `https://developer.android.com/reference/androidx/mediarouter/media/MediaRouter#addCallback(androidx.mediarouter.media.MediaRouteSelector,androidx.mediarouter.media.MediaRouter.Callback)`: Request passive route discovery while this callback is registered, except on `https://developer.android.com/reference/android/app/ActivityManager.html#isLowRamDevice()`.

When this flag is specified, the media router will try to discover routes. Although route discovery is intended to be efficient, checking for new routes may result in some network activity and could slowly drain the battery. Therefore applications should only specify this flag when they are running in the foreground and would like to provide the user with the option of connecting to new routes.

Applications should typically add a callback using this flag in the `https://developer.android.com/reference/android/app/Activity.html``https://developer.android.com/reference/android/app/Activity.html#onStart()` method and remove it in the `https://developer.android.com/reference/android/app/Activity.html#onStop()` method. The `https://developer.android.com/reference/androidx/mediarouter/app/MediaRouteDiscoveryFragment` fragment may also be used for this purpose.

On `https://developer.android.com/reference/android/app/ActivityManager.html#isLowRamDevice()` this flag will be ignored. Refer to `https://developer.android.com/reference/androidx/mediarouter/media/MediaRouter#addCallback(androidx.mediarouter.media.MediaRouteSelector,androidx.mediarouter.media.MediaRouter.Callback,int)` for details.

| See also |
|---|---|
| `https://developer.android.com/reference/androidx/mediarouter/app/MediaRouteDiscoveryFragment` |   |

### CALLBACK_FLAG_UNFILTERED_EVENTS

Added in [1.1.0](https://developer.android.com/jetpack/androidx/releases/mediarouter#1.1.0)

```
public static final int CALLBACK_FLAG_UNFILTERED_EVENTS = 2
```

Flag for `https://developer.android.com/reference/androidx/mediarouter/media/MediaRouter#addCallback(androidx.mediarouter.media.MediaRouteSelector,androidx.mediarouter.media.MediaRouter.Callback)`: Do not filter route events.

When this flag is specified, the callback will be invoked for events that affect any route even if they do not match the callback's filter.

### REASON_DISCONNECT_CALLED

Added in [1.8.0](https://developer.android.com/jetpack/androidx/releases/mediarouter#1.8.0)

```
public static final int REASON_DISCONNECT_CALLED = 1
```

The route connection is disconnected by `https://developer.android.com/reference/androidx/mediarouter/media/MediaRouter.RouteInfo#disconnect()`.

| See also |
|---|---|
| `https://developer.android.com/reference/androidx/mediarouter/media/MediaRouter.Callback#onRouteDisconnected(androidx.mediarouter.media.MediaRouter,androidx.mediarouter.media.MediaRouter.RouteInfo,androidx.mediarouter.media.MediaRouter.RouteInfo,int)` |   |

### REASON_FAILED_TO_CREATE_DYNAMIC_GROUP_ROUTE_CONTROLLER

Added in [1.8.0](https://developer.android.com/jetpack/androidx/releases/mediarouter#1.8.0)

```
public static final int REASON_FAILED_TO_CREATE_DYNAMIC_GROUP_ROUTE_CONTROLLER = 6
```

The route connection has failed because the provider for the requested route failed to create a dynamic group route controller.

| See also |
|---|---|
| `https://developer.android.com/reference/androidx/mediarouter/media/MediaRouter.Callback#onRouteDisconnected(androidx.mediarouter.media.MediaRouter,androidx.mediarouter.media.MediaRouter.RouteInfo,androidx.mediarouter.media.MediaRouter.RouteInfo,int)` |   |

### REASON_REJECTED_FOR_SELECTED_ROUTE

Added in [1.8.0](https://developer.android.com/jetpack/androidx/releases/mediarouter#1.8.0)

```
public static final int REASON_REJECTED_FOR_SELECTED_ROUTE = 4
```

The route connection has failed because the requested route is a selected route.

If a route is already selected, then calling `https://developer.android.com/reference/androidx/mediarouter/media/MediaRouter.RouteInfo#connect()` on the selected route will be rejected and do nothing.

| See also |
|---|---|
| `https://developer.android.com/reference/androidx/mediarouter/media/MediaRouter.Callback#onRouteDisconnected(androidx.mediarouter.media.MediaRouter,androidx.mediarouter.media.MediaRouter.RouteInfo,androidx.mediarouter.media.MediaRouter.RouteInfo,int)` |   |

### REASON_ROUTE_CONNECTION_TIMEOUT

Added in [1.8.0](https://developer.android.com/jetpack/androidx/releases/mediarouter#1.8.0)

```
public static final int REASON_ROUTE_CONNECTION_TIMEOUT = 7
```

The route connection has failed due to a timeout.

| See also |
|---|---|
| `https://developer.android.com/reference/androidx/mediarouter/media/MediaRouter.Callback#onRouteDisconnected(androidx.mediarouter.media.MediaRouter,androidx.mediarouter.media.MediaRouter.RouteInfo,androidx.mediarouter.media.MediaRouter.RouteInfo,int)` |   |

### REASON_ROUTE_NOT_AVAILABLE

Added in [1.8.0](https://developer.android.com/jetpack/androidx/releases/mediarouter#1.8.0)

```
public static final int REASON_ROUTE_NOT_AVAILABLE = 2
```

The route connection has failed because the requested route is no longer available.

| See also |
|---|---|
| `https://developer.android.com/reference/androidx/mediarouter/media/MediaRouter.Callback#onRouteDisconnected(androidx.mediarouter.media.MediaRouter,androidx.mediarouter.media.MediaRouter.RouteInfo,androidx.mediarouter.media.MediaRouter.RouteInfo,int)` |   |

### REASON_ROUTE_NOT_ENABLED

Added in [1.8.0](https://developer.android.com/jetpack/androidx/releases/mediarouter#1.8.0)

```
public static final int REASON_ROUTE_NOT_ENABLED = 3
```

The route connection has failed because the requested route is not enabled.

| See also |
|---|---|
| `https://developer.android.com/reference/androidx/mediarouter/media/MediaRouter.Callback#onRouteDisconnected(androidx.mediarouter.media.MediaRouter,androidx.mediarouter.media.MediaRouter.RouteInfo,androidx.mediarouter.media.MediaRouter.RouteInfo,int)` |   |

### REASON_UNSUPPORTED_FOR_NON_DYNAMIC_CONTROLLER

Added in [1.8.0](https://developer.android.com/jetpack/androidx/releases/mediarouter#1.8.0)

```
public static final int REASON_UNSUPPORTED_FOR_NON_DYNAMIC_CONTROLLER = 5
```

The route connection has failed because the provider for the requested route doesn't support dynamic groups.

| See also |
|---|---|
| `https://developer.android.com/reference/androidx/mediarouter/media/MediaRouter.Callback#onRouteDisconnected(androidx.mediarouter.media.MediaRouter,androidx.mediarouter.media.MediaRouter.RouteInfo,androidx.mediarouter.media.MediaRouter.RouteInfo,int)` |   |

### UNSELECT_REASON_DISCONNECTED

Added in [1.1.0](https://developer.android.com/jetpack/androidx/releases/mediarouter#1.1.0)

```
public static final int UNSELECT_REASON_DISCONNECTED = 1
```

Passed to `https://developer.android.com/reference/androidx/mediarouter/media/MediaRouteProvider.RouteController#onUnselect(int)`, `https://developer.android.com/reference/androidx/mediarouter/media/MediaRouter.Callback#onRouteUnselected(androidx.mediarouter.media.MediaRouter,androidx.mediarouter.media.MediaRouter.RouteInfo,int)` and `https://developer.android.com/reference/androidx/mediarouter/media/MediaRouter.Callback#onRouteSelected(androidx.mediarouter.media.MediaRouter,androidx.mediarouter.media.MediaRouter.RouteInfo,int)` when the user pressed the disconnect button to disconnect and keep playing.

| See also |
|---|---|
| `https://developer.android.com/reference/androidx/mediarouter/media/MediaRouteDescriptor#canDisconnectAndKeepPlaying()` |   |

### UNSELECT_REASON_ROUTE_CHANGED

Added in [1.1.0](https://developer.android.com/jetpack/androidx/releases/mediarouter#1.1.0)

```
public static final int UNSELECT_REASON_ROUTE_CHANGED = 3
```

Passed to `https://developer.android.com/reference/androidx/mediarouter/media/MediaRouteProvider.RouteController#onUnselect(int)`, `https://developer.android.com/reference/androidx/mediarouter/media/MediaRouter.Callback#onRouteUnselected(androidx.mediarouter.media.MediaRouter,androidx.mediarouter.media.MediaRouter.RouteInfo,int)` and `https://developer.android.com/reference/androidx/mediarouter/media/MediaRouter.Callback#onRouteSelected(androidx.mediarouter.media.MediaRouter,androidx.mediarouter.media.MediaRouter.RouteInfo,int)` when the user selected a different route.

### UNSELECT_REASON_STOPPED

Added in [1.1.0](https://developer.android.com/jetpack/androidx/releases/mediarouter#1.1.0)

```
public static final int UNSELECT_REASON_STOPPED = 2
```

Passed to `https://developer.android.com/reference/androidx/mediarouter/media/MediaRouteProvider.RouteController#onUnselect(int)`, `https://developer.android.com/reference/androidx/mediarouter/media/MediaRouter.Callback#onRouteUnselected(androidx.mediarouter.media.MediaRouter,androidx.mediarouter.media.MediaRouter.RouteInfo,int)` and `https://developer.android.com/reference/androidx/mediarouter/media/MediaRouter.Callback#onRouteSelected(androidx.mediarouter.media.MediaRouter,androidx.mediarouter.media.MediaRouter.RouteInfo,int)` when the user pressed the stop casting button.

Media should stop when this reason is passed.

### UNSELECT_REASON_UNKNOWN

Added in [1.1.0](https://developer.android.com/jetpack/androidx/releases/mediarouter#1.1.0)

```
public static final int UNSELECT_REASON_UNKNOWN = 0
```

Passed to `https://developer.android.com/reference/androidx/mediarouter/media/MediaRouteProvider.RouteController#onUnselect(int)`, `https://developer.android.com/reference/androidx/mediarouter/media/MediaRouter.Callback#onRouteUnselected(androidx.mediarouter.media.MediaRouter,androidx.mediarouter.media.MediaRouter.RouteInfo,int)` and `https://developer.android.com/reference/androidx/mediarouter/media/MediaRouter.Callback#onRouteSelected(androidx.mediarouter.media.MediaRouter,androidx.mediarouter.media.MediaRouter.RouteInfo,int)` when the reason the route was unselected is unknown.

## Public methods

### addCallback

Added in [1.1.0](https://developer.android.com/jetpack/androidx/releases/mediarouter#1.1.0)

```
@MainThread
public void addCallback(
    @NonNull MediaRouteSelector selector,
    @NonNull MediaRouter.Callback callback
)
```

Registers a callback to discover routes that match the selector and to receive events when they change.

This is a convenience method that has the same effect as calling `https://developer.android.com/reference/androidx/mediarouter/media/MediaRouter#addCallback(androidx.mediarouter.media.MediaRouteSelector,androidx.mediarouter.media.MediaRouter.Callback,int)` without flags.

Must be called on the main thread.

| Parameters |
|---|---|
| `@https://jspecify.dev/docs/api/org/jspecify/annotations/NonNull.html https://developer.android.com/reference/androidx/mediarouter/media/MediaRouteSelector selector` | A route selector that indicates the kinds of routes that the callback would like to discover. |
| `@https://jspecify.dev/docs/api/org/jspecify/annotations/NonNull.html https://developer.android.com/reference/androidx/mediarouter/media/MediaRouter.Callback callback` | The callback to add. |

| See also |
|---|---|
| `https://developer.android.com/reference/androidx/mediarouter/media/MediaRouter#removeCallback(androidx.mediarouter.media.MediaRouter.Callback)` |   |

### addCallback

Added in [1.1.0](https://developer.android.com/jetpack/androidx/releases/mediarouter#1.1.0)

```
@MainThread
public void addCallback(
    @NonNull MediaRouteSelector selector,
    @NonNull MediaRouter.Callback callback,
    int flags
)
```

Registers a callback to discover routes that match the selector and to receive events when they change.

The selector describes the kinds of routes that the application wants to discover. For example, if the application wants to use live audio routes then it should include the `https://developer.android.com/reference/androidx/mediarouter/media/MediaControlIntent#CATEGORY_LIVE_AUDIO()` in its selector when it adds a callback to the media router. The selector may include any number of categories.

If the callback has already been registered, then the selector is added to the set of selectors being monitored by the callback.

By default, the callback will only be invoked for events that affect routes that match the specified selector. Event filtering may be disabled by specifying the `https://developer.android.com/reference/androidx/mediarouter/media/MediaRouter#CALLBACK_FLAG_UNFILTERED_EVENTS()` flag when the callback is registered.

Applications should use the `https://developer.android.com/reference/androidx/mediarouter/media/MediaRouter#isRouteAvailable(androidx.mediarouter.media.MediaRouteSelector,int)` method to determine whether is it possible to discover a route with the desired capabilities and therefore whether the media route button should be shown to the user.

The `https://developer.android.com/reference/androidx/mediarouter/media/MediaRouter#CALLBACK_FLAG_REQUEST_DISCOVERY()` flag should be used while the application is in the foreground to request that passive discovery be performed if there are sufficient resources to allow continuous passive discovery. On `https://developer.android.com/reference/android/app/ActivityManager.html#isLowRamDevice()` this flag will be ignored to conserve resources.

The `https://developer.android.com/reference/androidx/mediarouter/media/MediaRouter#CALLBACK_FLAG_FORCE_DISCOVERY()` flag should be used when passive discovery absolutely must be performed, even on low-RAM devices. This flag has a significant performance impact on low-RAM devices since it may cause many media route providers to be started simultaneously. It is much better to use `https://developer.android.com/reference/androidx/mediarouter/media/MediaRouter#CALLBACK_FLAG_REQUEST_DISCOVERY()` instead to avoid performing passive discovery on these devices altogether.

The `https://developer.android.com/reference/androidx/mediarouter/media/MediaRouter#CALLBACK_FLAG_PERFORM_ACTIVE_SCAN()` flag should be used when the media route chooser dialog is showing to confirm the presence of available routes that the user may connect to. This flag may use substantially more power. Once active scan is requested, it will be effective for 30 seconds and will be suppressed after the delay. If you need active scan after this duration, you have to add your callback again with the `https://developer.android.com/reference/androidx/mediarouter/media/MediaRouter#CALLBACK_FLAG_PERFORM_ACTIVE_SCAN()` flag.

### Example

```
public class MyActivity extends Activity {
    private MediaRouter mRouter;
    private MediaRouter.Callback mCallback;
    private MediaRouteSelector mSelector;

    // Add the callback on start to tell the media router what kinds of routes
    // the application is interested in so that it can get events about media routing changes
    // from the system.
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);

        mRouter = MediaRouter.getInstance(this);
        mCallback = new MyCallback();
        mSelector = new MediaRouteSelector.Builder()
                .addControlCategory(MediaControlIntent.CATEGORY_LIVE_AUDIO)
                .addControlCategory(MediaControlIntent.CATEGORY_REMOTE_PLAYBACK)
                .build();
        mRouter.addCallback(mSelector, mCallback, /* flags= */ 0);
    }

    // Add the callback flag CALLBACK_FLAG_REQUEST_DISCOVERY on start by calling
    // addCallback() again so that the media router can try to discover suitable ones.
    public void onStart() {
        super.onStart();

        mRouter.addCallback(mSelector, mCallback,
                MediaRouter.CALLBACK_FLAG_REQUEST_DISCOVERY);

        MediaRouter.RouteInfo route = mRouter.updateSelectedRoute(mSelector);
        // do something with the route...
    }

    // Remove the callback flag CALLBACK_FLAG_REQUEST_DISCOVERY on stop by calling
    // addCallback() again in order to tell the media router that it no longer
    // needs to invest effort trying to discover routes of these kinds for now.
    public void onStop() {
        mRouter.addCallback(mSelector, mCallback, /* flags= */ 0);

        super.onStop();
    }

    // Remove the callback when the activity is destroyed.
    public void onDestroy() {
        mRouter.removeCallback(mCallback);

        super.onDestroy();
    }

    private final class MyCallback extends MediaRouter.Callback {
        // Implement callback methods as needed.
    }
}
```

Must be called on the main thread.

| Parameters |
|---|---|
| `@https://jspecify.dev/docs/api/org/jspecify/annotations/NonNull.html https://developer.android.com/reference/androidx/mediarouter/media/MediaRouteSelector selector` | A route selector that indicates the kinds of routes that the callback would like to discover. |
| `@https://jspecify.dev/docs/api/org/jspecify/annotations/NonNull.html https://developer.android.com/reference/androidx/mediarouter/media/MediaRouter.Callback callback` | The callback to add. |
| `int flags` | Flags to control the behavior of the callback. May be zero or a combination of `https://developer.android.com/reference/androidx/mediarouter/media/MediaRouter#CALLBACK_FLAG_PERFORM_ACTIVE_SCAN()` and `https://developer.android.com/reference/androidx/mediarouter/media/MediaRouter#CALLBACK_FLAG_UNFILTERED_EVENTS()`. |

| See also |
|---|---|
| `https://developer.android.com/reference/androidx/mediarouter/media/MediaRouter#removeCallback(androidx.mediarouter.media.MediaRouter.Callback)` |   |

### addProvider

Added in [1.1.0](https://developer.android.com/jetpack/androidx/releases/mediarouter#1.1.0)

```
@MainThread
public void addProvider(@NonNull MediaRouteProvider providerInstance)
```

Registers a media route provider within this application process.

The provider will be added to the list of providers that all `https://developer.android.com/reference/androidx/mediarouter/media/MediaRouter` instances within this process can use to discover routes.

Must be called on the main thread.

| Parameters |
|---|---|
| `@https://jspecify.dev/docs/api/org/jspecify/annotations/NonNull.html https://developer.android.com/reference/androidx/mediarouter/media/MediaRouteProvider providerInstance` | The media route provider instance to add. |

| See also |
|---|---|
| `https://developer.android.com/reference/androidx/mediarouter/media/MediaRouteProvider` |   |
| `https://developer.android.com/reference/androidx/mediarouter/media/MediaRouter#removeCallback(androidx.mediarouter.media.MediaRouter.Callback)` |   |

### addRemoteControlClient

Added in [1.1.0](https://developer.android.com/jetpack/androidx/releases/mediarouter#1.1.0) Deprecated in [1.6.0](https://developer.android.com/jetpack/androidx/releases/mediarouter#1.6.0)

```
@MainThread
public void [addRemoteControlClient](https://developer.android.com/reference/androidx/mediarouter/media/MediaRouter#addRemoteControlClient(java.lang.Object))(@NonNull Object remoteControlClient)
```

> [!CAUTION]
> **This method is deprecated.**   
>
> Use `https://developer.android.com/reference/androidx/mediarouter/media/MediaRouter#setMediaSessionCompat(android.support.v4.media.session.MediaSessionCompat)` instead.

Adds a remote control client to enable remote control of the volume of the selected route.

The remote control client must have previously been registered with the audio manager using the `https://developer.android.com/reference/android/media/AudioManager.html#registerRemoteControlClient(android.media.RemoteControlClient)` method.

Must be called on the main thread.

| Parameters |
|---|---|
| `@https://jspecify.dev/docs/api/org/jspecify/annotations/NonNull.html https://developer.android.com/reference/java/lang/Object.html remoteControlClient` | The `https://developer.android.com/reference/android/media/RemoteControlClient.html` to register. |

### clearDeviceSuggestions

Added in [1.9.0-rc01](https://developer.android.com/jetpack/androidx/releases/mediarouter#1.9.0-rc01)

```
@MainThread
public void clearDeviceSuggestions()
```

Clears the `https://developer.android.com/reference/androidx/mediarouter/media/SuggestedDeviceInfo` provided by this router.

If the router explicitly wants to recommend that no suggestions are appropriate, use `https://developer.android.com/reference/androidx/mediarouter/media/MediaRouter#setDeviceSuggestions(java.util.List<androidx.mediarouter.media.MediaRouter.RouteInfo>)` with an empty list.

### getBluetoothRoute

Added in [1.1.0](https://developer.android.com/jetpack/androidx/releases/mediarouter#1.1.0)

```
@MainThread
public @Nullable MediaRouter.RouteInfo getBluetoothRoute()
```

Gets a bluetooth route for playing media content on the system.

Must be called on the main thread.

| Returns |
|---|---|
| `@https://jspecify.dev/docs/api/org/jspecify/annotations/Nullable.html https://developer.android.com/reference/androidx/mediarouter/media/MediaRouter.RouteInfo` | A bluetooth route, if exist, otherwise null. |

### getConnectedGroupRoutes

Added in [1.8.0](https://developer.android.com/jetpack/androidx/releases/mediarouter#1.8.0)

```
@MainThread
public @NonNull List<MediaRouter.GroupRouteInfo> getConnectedGroupRoutes()
```

Returns the currently connected dynamic group routes.

If there is a selected route, the list of connected routes doesn't include it. The route connection doesn't affect the route selection. Apps can use `https://developer.android.com/reference/androidx/mediarouter/media/MediaRouter.RouteInfo#connect()` to create dynamic group route connections.

### getDefaultRoute

Added in [1.1.0](https://developer.android.com/jetpack/androidx/releases/mediarouter#1.1.0)

```
@MainThread
public @NonNull MediaRouter.RouteInfo getDefaultRoute()
```

Gets the default route for playing media content on the system.

The system always provides a default route.

Must be called on the main thread.

| Returns |
|---|---|
| `@https://jspecify.dev/docs/api/org/jspecify/annotations/NonNull.html https://developer.android.com/reference/androidx/mediarouter/media/MediaRouter.RouteInfo` | The default route, which is guaranteed to never be null. |

### getDeviceSuggestions

Added in [1.9.0-rc01](https://developer.android.com/jetpack/androidx/releases/mediarouter#1.9.0-rc01)

```
@MainThread
public @NonNull Map<String, List<SuggestedDeviceInfo>> getDeviceSuggestions()
```

Gets the current suggested devices.

The suggestions returned by this method include suggestions coming from other packages. For example, the route provider itself may include suggestions based on the likelihood of the user selecting a given route.

| Returns |
|---|---|
| `@https://jspecify.dev/docs/api/org/jspecify/annotations/NonNull.html https://developer.android.com/reference/java/util/Map.html<https://developer.android.com/reference/java/lang/String.html, https://developer.android.com/reference/java/util/List.html<https://developer.android.com/reference/androidx/mediarouter/media/SuggestedDeviceInfo>>` | the suggested devices, keyed by the package name providing each suggestion list. |

### getInstance

Added in [1.1.0](https://developer.android.com/jetpack/androidx/releases/mediarouter#1.1.0)

```
@MainThread
public static @NonNull MediaRouter getInstance(@NonNull Context context)
```

Gets an instance of the media router service associated with the context.

The application is responsible for holding a strong reference to the returned `https://developer.android.com/reference/androidx/mediarouter/media/MediaRouter` instance, such as by storing the instance in a field of the `https://developer.android.com/reference/android/app/Activity.html`, to ensure that the media router remains alive as long as the application is using its features.

In other words, the support library only holds a `https://developer.android.com/reference/java/lang/ref/WeakReference.html` to each media router instance. When there are no remaining strong references to the media router instance, all of its callbacks will be removed and route discovery will no longer be performed on its behalf.

Must be called on the main thread.

| Returns |
|---|---|
| `@https://jspecify.dev/docs/api/org/jspecify/annotations/NonNull.html https://developer.android.com/reference/androidx/mediarouter/media/MediaRouter` | The media router instance for the context. The application must hold a strong reference to this object as long as it is in use. |

### getMediaSessionToken

Added in [1.1.0](https://developer.android.com/jetpack/androidx/releases/mediarouter#1.1.0)

```
public @Nullable MediaSessionCompat.Token getMediaSessionToken()
```

### getProviders

Added in [1.1.0](https://developer.android.com/jetpack/androidx/releases/mediarouter#1.1.0)

```
@MainThread
public @NonNull List<MediaRouter.ProviderInfo> getProviders()
```

Gets information about the `https://developer.android.com/reference/androidx/mediarouter/media/MediaRouter.ProviderInfo` currently known to this media router.

Must be called on the main thread.

### getRouterParams

Added in [1.2.0](https://developer.android.com/jetpack/androidx/releases/mediarouter#1.2.0)

```
@MainThread
public @Nullable MediaRouterParams getRouterParams()
```

Gets `https://developer.android.com/reference/androidx/mediarouter/media/MediaRouterParams` of the media router service associated with this media router.

Must be called on the main thread.

### getRoutes

Added in [1.1.0](https://developer.android.com/jetpack/androidx/releases/mediarouter#1.1.0)

```
@MainThread
public @NonNull List<MediaRouter.RouteInfo> getRoutes()
```

Gets information about the `https://developer.android.com/reference/androidx/mediarouter/media/MediaRouter.RouteInfo` currently known to this media router.

Must be called on the main thread.

### getSelectedRoute

Added in [1.1.0](https://developer.android.com/jetpack/androidx/releases/mediarouter#1.1.0)

```
@MainThread
public @NonNull MediaRouter.RouteInfo getSelectedRoute()
```

Gets the currently selected route.

The application should examine the route's `https://developer.android.com/reference/androidx/mediarouter/media/MediaRouter.RouteInfo#getControlFilters()` to assess the capabilities of the route before attempting to use it.

### Example

```
public boolean playMovie() {
    MediaRouter mediaRouter = MediaRouter.getInstance(context);
    MediaRouter.RouteInfo route = mediaRouter.getSelectedRoute();

    // First try using the remote playback interface, if supported.
    if (route.supportsControlCategory(MediaControlIntent.CATEGORY_REMOTE_PLAYBACK)) {
        // The route supports remote playback.
        // Try to send it the Uri of the movie to play.
        Intent intent = new Intent(MediaControlIntent.ACTION_PLAY);
        intent.addCategory(MediaControlIntent.CATEGORY_REMOTE_PLAYBACK);
        intent.setDataAndType("http://example.com/videos/movie.mp4", "video/mp4");
        if (route.supportsControlRequest(intent)) {
            route.sendControlRequest(intent, null);
            return true; // sent the request to play the movie
        }
    }

    // If remote playback was not possible, then play locally.
    if (route.supportsControlCategory(MediaControlIntent.CATEGORY_LIVE_VIDEO)) {
        // The route supports live video streaming.
        // Prepare to play content locally in a window or in a presentation.
        return playMovieInWindow();
    }

    // Neither interface is supported, so we can't play the movie to this route.
    return false;
}
```

Must be called on the main thread.

| Returns |
|---|---|
| `@https://jspecify.dev/docs/api/org/jspecify/annotations/NonNull.html https://developer.android.com/reference/androidx/mediarouter/media/MediaRouter.RouteInfo` | The selected route, which is guaranteed to never be null. |

| See also |
|---|---|
| `https://developer.android.com/reference/androidx/mediarouter/media/MediaRouter.RouteInfo#getControlFilters()` |   |
| `https://developer.android.com/reference/androidx/mediarouter/media/MediaRouter.RouteInfo#supportsControlCategory(java.lang.String)` |   |
| `https://developer.android.com/reference/androidx/mediarouter/media/MediaRouter.RouteInfo#supportsControlRequest(android.content.Intent)` |   |

### isMediaTransferEnabled

Added in [1.9.0-rc01](https://developer.android.com/jetpack/androidx/releases/mediarouter#1.9.0-rc01)

```
public static boolean isMediaTransferEnabled()
```

Returns whether the media transfer feature is enabled.

Media transfer allows privileged apps such as SystemUI to control media routing for this application. This for example enables users to transfer media playback using SystemUI controls.

This feature requires Android 11 (API level 30) or higher and will always return `
false` on earlier Android versions.

Media transfer is considered enabled if *either* of the following conditions is met:

- The application explicitly enables it by calling `https://developer.android.com/reference/androidx/mediarouter/media/MediaRouterParams.Builder#setMediaTransferReceiverEnabled(boolean)` with `true`
- The application declares `https://developer.android.com/reference/androidx/mediarouter/media/MediaTransferReceiver` in its `
  AndroidManifest.xml` and has not explicitly disabled it via `https://developer.android.com/reference/androidx/mediarouter/media/MediaRouterParams`.

Please note that this method returning `true` is a necessary but not sufficient condition for media transfer. Actual media transfer through SystemUI controls also depends on the presence of route providers that support this capability.

| Returns |
|---|---|
| `boolean` | `true` if media transfer is enabled; `false` otherwise. |

| See also |
|---|---|
| `https://developer.android.com/reference/androidx/mediarouter/media/MediaRouterParams.Builder#setMediaTransferReceiverEnabled(boolean)` |   |
| `https://developer.android.com/reference/androidx/mediarouter/media/MediaRouterParams#isMediaTransferReceiverEnabled()` |   |
| `https://developer.android.com/reference/androidx/mediarouter/media/MediaTransferReceiver` |   |

### isRouteAvailable

Added in [1.1.0](https://developer.android.com/jetpack/androidx/releases/mediarouter#1.1.0)

```
@MainThread
public boolean isRouteAvailable(@NonNull MediaRouteSelector selector, int flags)
```

Returns true if there is a route that matches the specified selector.

This method returns true if there are any available routes that match the selector regardless of whether they are enabled or disabled. If the `https://developer.android.com/reference/androidx/mediarouter/media/MediaRouter#AVAILABILITY_FLAG_IGNORE_DEFAULT_ROUTE()` flag is specified, then the method will only consider non-default routes.

On `https://developer.android.com/reference/android/app/ActivityManager.html#isLowRamDevice()` this method will return true if it is possible to discover a matching route even if discovery is not in progress or if no matching route has yet been found. Use `https://developer.android.com/reference/androidx/mediarouter/media/MediaRouter#AVAILABILITY_FLAG_REQUIRE_MATCH()` to require an actual match.

Must be called on the main thread.

| Parameters |
|---|---|
| `@https://jspecify.dev/docs/api/org/jspecify/annotations/NonNull.html https://developer.android.com/reference/androidx/mediarouter/media/MediaRouteSelector selector` | The selector to match. |
| `int flags` | Flags to control the determination of whether a route may be available. May be zero or some combination of `https://developer.android.com/reference/androidx/mediarouter/media/MediaRouter#AVAILABILITY_FLAG_IGNORE_DEFAULT_ROUTE()` and `https://developer.android.com/reference/androidx/mediarouter/media/MediaRouter#AVAILABILITY_FLAG_REQUIRE_MATCH()`. |

| Returns |
|---|---|
| `boolean` | True if a matching route may be available. |

### registerDeviceSuggestionsUpdatesCallback

Added in [1.9.0-rc01](https://developer.android.com/jetpack/androidx/releases/mediarouter#1.9.0-rc01)

```
@MainThread
public void registerDeviceSuggestionsUpdatesCallback(
    @NonNull MediaRouter.DeviceSuggestionsUpdatesCallback deviceSuggestionsUpdatesCallback,
    @Nullable Executor executor
)
```

Registers the given callback to be invoked when the `https://developer.android.com/reference/androidx/mediarouter/media/SuggestedDeviceInfo` of the router changes.

| Parameters |
|---|---|
| `@https://jspecify.dev/docs/api/org/jspecify/annotations/NonNull.html https://developer.android.com/reference/androidx/mediarouter/media/MediaRouter.DeviceSuggestionsUpdatesCallback deviceSuggestionsUpdatesCallback` | the callback to register. |
| `@https://jspecify.dev/docs/api/org/jspecify/annotations/Nullable.html https://developer.android.com/reference/java/util/concurrent/Executor.html executor` | the executor to run the callback on. If the executor is passed in as null, the callback will run on the main thread. |

### removeCallback

Added in [1.1.0](https://developer.android.com/jetpack/androidx/releases/mediarouter#1.1.0)

```
@MainThread
public void removeCallback(@NonNull MediaRouter.Callback callback)
```

Removes the specified callback. It will no longer receive events about changes to media routes.

Must be called on the main thread.

| Parameters |
|---|---|
| `@https://jspecify.dev/docs/api/org/jspecify/annotations/NonNull.html https://developer.android.com/reference/androidx/mediarouter/media/MediaRouter.Callback callback` | The callback to remove. |

| See also |
|---|---|
| `https://developer.android.com/reference/androidx/mediarouter/media/MediaRouter#addCallback(androidx.mediarouter.media.MediaRouteSelector,androidx.mediarouter.media.MediaRouter.Callback)` |   |

### removeProvider

Added in [1.1.0](https://developer.android.com/jetpack/androidx/releases/mediarouter#1.1.0)

```
@MainThread
public void removeProvider(@NonNull MediaRouteProvider providerInstance)
```

Unregisters a media route provider within this application process.

The provider will be removed from the list of providers that all `https://developer.android.com/reference/androidx/mediarouter/media/MediaRouter` instances within this process can use to discover routes.

Must be called on the main thread.

| Parameters |
|---|---|
| `@https://jspecify.dev/docs/api/org/jspecify/annotations/NonNull.html https://developer.android.com/reference/androidx/mediarouter/media/MediaRouteProvider providerInstance` | The media route provider instance to remove. |

| See also |
|---|---|
| `https://developer.android.com/reference/androidx/mediarouter/media/MediaRouteProvider` |   |
| `https://developer.android.com/reference/androidx/mediarouter/media/MediaRouter#addCallback(androidx.mediarouter.media.MediaRouteSelector,androidx.mediarouter.media.MediaRouter.Callback)` |   |

### removeRemoteControlClient

Added in [1.1.0](https://developer.android.com/jetpack/androidx/releases/mediarouter#1.1.0) Deprecated in [1.7.0](https://developer.android.com/jetpack/androidx/releases/mediarouter#1.7.0)

```
@MainThread
public void [removeRemoteControlClient](https://developer.android.com/reference/androidx/mediarouter/media/MediaRouter#removeRemoteControlClient(java.lang.Object))(@NonNull Object remoteControlClient)
```

> [!CAUTION]
> **This method is deprecated.**   
>
> Call `https://developer.android.com/reference/androidx/mediarouter/media/MediaRouter#setMediaSessionCompat(android.support.v4.media.session.MediaSessionCompat)` instead of `https://developer.android.com/reference/androidx/mediarouter/media/MediaRouter#addRemoteControlClient(java.lang.Object)` so that there is no need to call this method.

Removes a remote control client.

Must be called on the main thread.

| Parameters |
|---|---|
| `@https://jspecify.dev/docs/api/org/jspecify/annotations/NonNull.html https://developer.android.com/reference/java/lang/Object.html remoteControlClient` | The `https://developer.android.com/reference/android/media/RemoteControlClient.html` to unregister. |

### selectRoute

Added in [1.1.0](https://developer.android.com/jetpack/androidx/releases/mediarouter#1.1.0)

```
@MainThread
public void selectRoute(@NonNull MediaRouter.RouteInfo route)
```

Selects the specified route.

Must be called on the main thread.

| Parameters |
|---|---|
| `@https://jspecify.dev/docs/api/org/jspecify/annotations/NonNull.html https://developer.android.com/reference/androidx/mediarouter/media/MediaRouter.RouteInfo route` | The route to select. |

### setDeviceSuggestions

Added in [1.9.0-rc01](https://developer.android.com/jetpack/androidx/releases/mediarouter#1.9.0-rc01)

```
@MainThread
public void setDeviceSuggestions(@NonNull List<MediaRouter.RouteInfo> routes)
```

Sets a list of suggested routes.

Use this method to advertise device suggestions for routing. UI elements in the system and within the app may use these suggestions to show one-tap transfer affordances to the user.

This feature requires Android 11 (API level 30) or higher and that the app has `https://developer.android.com/reference/androidx/mediarouter/media/MediaTransferReceiver` (either declared in the manifest or enabled via `https://developer.android.com/reference/androidx/mediarouter/media/MediaRouterParams.Builder#setMediaTransferReceiverEnabled(boolean)`). On earlier platform versions, this method is a no-op and all suggestions are dropped.

Suggestions may be expired automatically by the system, at which point you should call this method again if the suggestion is still relevant and should still be surfaced.

Call this method with an empty list to explicitly recommend that no suggestions are appropriate.

MediaRouter will drop unsupported suggestions, including:

- System routes (such as the built-in speaker or Bluetooth routes).
- Routes that are not accessible to the Android platform (via `https://developer.android.com/reference/android/media/MediaRouter2.html`). For example, custom in-process routes added via `https://developer.android.com/reference/androidx/mediarouter/media/MediaRouter#addProvider(androidx.mediarouter.media.MediaRouteProvider)` without an exported `https://developer.android.com/reference/androidx/mediarouter/media/MediaRouteProviderService` are not accessible to the platform and will be dropped.

| Parameters |
|---|---|
| `@https://jspecify.dev/docs/api/org/jspecify/annotations/NonNull.html https://developer.android.com/reference/java/util/List.html<https://developer.android.com/reference/androidx/mediarouter/media/MediaRouter.RouteInfo> routes` | The `https://developer.android.com/reference/androidx/mediarouter/media/MediaRouter.RouteInfo` routes the router suggests should be provided to the user. |

### setMediaSession

Added in [1.1.0](https://developer.android.com/jetpack/androidx/releases/mediarouter#1.1.0)

```
@MainThread
public void setMediaSession(@Nullable Object mediaSession)
```

Equivalent to `https://developer.android.com/reference/androidx/mediarouter/media/MediaRouter#setMediaSessionCompat(android.support.v4.media.session.MediaSessionCompat)`, except it takes an `https://developer.android.com/reference/android/media/session/MediaSession.html`.

### setMediaSessionCompat

Added in [1.1.0](https://developer.android.com/jetpack/androidx/releases/mediarouter#1.1.0)

```
@MainThread
public void setMediaSessionCompat(@Nullable MediaSessionCompat mediaSession)
```

Associates the provided `https://developer.android.com/reference/android/support/v4/media/session/MediaSessionCompat` to this router.

Maintains the internal state of the provided session to signal it's linked to the currently selected route at any given time. This guarantees that the system UI shows the correct route name when applicable.

Must be called on the main thread.

| Parameters |
|---|---|
| `@https://jspecify.dev/docs/api/org/jspecify/annotations/Nullable.html https://developer.android.com/reference/android/support/v4/media/session/MediaSessionCompat mediaSession` | The `https://developer.android.com/reference/android/support/v4/media/session/MediaSessionCompat` to associate to this media router, or null to clear the existing association. |

### setOnPrepareTransferListener

Added in [1.2.0](https://developer.android.com/jetpack/androidx/releases/mediarouter#1.2.0)

```
@MainThread
public void setOnPrepareTransferListener(
    @Nullable MediaRouter.OnPrepareTransferListener listener
)
```

Sets a listener for receiving events when the selected route is about to be changed.

Must be called on the main thread.

### setRouteListingPreference

Added in [1.6.0](https://developer.android.com/jetpack/androidx/releases/mediarouter#1.6.0)

```
@MainThread
public void setRouteListingPreference(
    @Nullable RouteListingPreference routeListingPreference
)
```

Sets the `https://developer.android.com/reference/androidx/mediarouter/media/RouteListingPreference` of the app associated to this media router.

This method does nothing on devices running API 33 or older.

Use this method to inform the system UI of the routes that you would like to list for media routing, via the Output Switcher.

You should call this method immediately after creating an instance and immediately after receiving any `https://developer.android.com/reference/androidx/mediarouter/media/MediaRouter.Callback` in order to keep the system UI in a consistent state. You can also call this method at any other point to update the listing preference dynamically (which reflect in the system's Output Switcher).

Notes:

- You should not include the ids of two or more routes with a match in their `https://developer.android.com/reference/androidx/mediarouter/media/MediaRouteDescriptor#getDeduplicationIds()`. If you do, the system will deduplicate them using its own criteria.
- You can use this method to rank routes in the output switcher, placing the more important routes first. The system might override the proposed ranking.
- You can use this method to change how routes are listed using dynamic criteria. For example, you can disable routing while an `https://developer.android.com/reference/androidx/mediarouter/media/RouteListingPreference.Item#SUBTEXT_AD_ROUTING_DISALLOWED()`).

| Parameters |
|---|---|
| `@https://jspecify.dev/docs/api/org/jspecify/annotations/Nullable.html https://developer.android.com/reference/androidx/mediarouter/media/RouteListingPreference routeListingPreference` | The `https://developer.android.com/reference/androidx/mediarouter/media/RouteListingPreference` for the system to use for route listing. When null, the system uses its default listing criteria. |

### setRouterParams

Added in [1.2.0](https://developer.android.com/jetpack/androidx/releases/mediarouter#1.2.0)

```
@MainThread
public void setRouterParams(@Nullable MediaRouterParams params)
```

Sets `https://developer.android.com/reference/androidx/mediarouter/media/MediaRouterParams` of the media router service associated with this media router.

Must be called on the main thread.

| Parameters |
|---|---|
| `@https://jspecify.dev/docs/api/org/jspecify/annotations/Nullable.html https://developer.android.com/reference/androidx/mediarouter/media/MediaRouterParams params` | The parameter to set |

### unregisterDeviceSuggestionsUpdatesCallback

Added in [1.9.0-rc01](https://developer.android.com/jetpack/androidx/releases/mediarouter#1.9.0-rc01)

```
@MainThread
public void unregisterDeviceSuggestionsUpdatesCallback(
    @NonNull MediaRouter.DeviceSuggestionsUpdatesCallback deviceSuggestionsUpdatesCallback
)
```

Unregisters the given callback to be invoked when the `https://developer.android.com/reference/androidx/mediarouter/media/SuggestedDeviceInfo` of the router changes.

| Parameters |
|---|---|
| `@https://jspecify.dev/docs/api/org/jspecify/annotations/NonNull.html https://developer.android.com/reference/androidx/mediarouter/media/MediaRouter.DeviceSuggestionsUpdatesCallback deviceSuggestionsUpdatesCallback` | the callback to unregister. |

### unselect

Added in [1.1.0](https://developer.android.com/jetpack/androidx/releases/mediarouter#1.1.0)

```
@MainThread
public void unselect(int reason)
```

Unselects the current route and selects the default route instead.

The reason given must be one of:

- `https://developer.android.com/reference/androidx/mediarouter/media/MediaRouter#UNSELECT_REASON_UNKNOWN()`
- `https://developer.android.com/reference/androidx/mediarouter/media/MediaRouter#UNSELECT_REASON_DISCONNECTED()`
- `https://developer.android.com/reference/androidx/mediarouter/media/MediaRouter#UNSELECT_REASON_STOPPED()`
- `https://developer.android.com/reference/androidx/mediarouter/media/MediaRouter#UNSELECT_REASON_ROUTE_CHANGED()`

Must be called on the main thread.

| Parameters |
|---|---|
| `int reason` | The reason for disconnecting the current route. |

### updateSelectedRoute

Added in [1.1.0](https://developer.android.com/jetpack/androidx/releases/mediarouter#1.1.0)

```
@MainThread
public @NonNull MediaRouter.RouteInfo updateSelectedRoute(@NonNull MediaRouteSelector selector)
```

Returns the selected route if it matches the specified selector, otherwise selects the default route and returns it. If there is one live audio route (usually Bluetooth A2DP), it will be selected instead of default route.

Must be called on the main thread.

| Parameters |
|---|---|
| `@https://jspecify.dev/docs/api/org/jspecify/annotations/NonNull.html https://developer.android.com/reference/androidx/mediarouter/media/MediaRouteSelector selector` | The selector to match. |

| Returns |
|---|---|
| `@https://jspecify.dev/docs/api/org/jspecify/annotations/NonNull.html https://developer.android.com/reference/androidx/mediarouter/media/MediaRouter.RouteInfo` | The previously selected route if it matched the selector, otherwise the newly selected default route which is guaranteed to never be null. |

| See also |
|---|---|
| `https://developer.android.com/reference/androidx/mediarouter/media/MediaRouteSelector` |   |
| `https://developer.android.com/reference/androidx/mediarouter/media/MediaRouter.RouteInfo#matchesSelector(androidx.mediarouter.media.MediaRouteSelector)` |   |