# MediaRouterParams.Builder

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

*** ** * ** ***


```
public final class MediaRouterParams.Builder
```

<br />

*** ** * ** ***

Builder class for `https://developer.android.com/reference/androidx/mediarouter/media/MediaRouterParams`.

## Summary

| ### Public constructors |
|---|
| `https://developer.android.com/reference/androidx/mediarouter/media/MediaRouterParams.Builder#Builder()()` Constructor for builder to create `https://developer.android.com/reference/androidx/mediarouter/media/MediaRouterParams`. |
| `https://developer.android.com/reference/androidx/mediarouter/media/MediaRouterParams.Builder#Builder(androidx.mediarouter.media.MediaRouterParams)(@https://jspecify.dev/docs/api/org/jspecify/annotations/NonNull.html https://developer.android.com/reference/androidx/mediarouter/media/MediaRouterParams params)` Constructor for builder to create `https://developer.android.com/reference/androidx/mediarouter/media/MediaRouterParams` with existing `https://developer.android.com/reference/androidx/mediarouter/media/MediaRouterParams` instance. |

| ### Public methods |
|---|---|
| `@https://jspecify.dev/docs/api/org/jspecify/annotations/NonNull.html https://developer.android.com/reference/androidx/mediarouter/media/MediaRouterParams` | `https://developer.android.com/reference/androidx/mediarouter/media/MediaRouterParams.Builder#build()()` Builds the `https://developer.android.com/reference/androidx/mediarouter/media/MediaRouterParams` instance. |
| `@https://jspecify.dev/docs/api/org/jspecify/annotations/NonNull.html https://developer.android.com/reference/androidx/mediarouter/media/MediaRouterParams.Builder` | `https://developer.android.com/reference/androidx/mediarouter/media/MediaRouterParams.Builder#setDialogType(int)(int dialogType)` Sets the media route controller dialog type. |
| `@https://jspecify.dev/docs/api/org/jspecify/annotations/NonNull.html https://developer.android.com/reference/androidx/mediarouter/media/MediaRouterParams.Builder` | `https://developer.android.com/reference/androidx/mediarouter/media/MediaRouterParams.Builder#setMediaTransferReceiverEnabled(boolean)(boolean enabled)` Sets whether declared `https://developer.android.com/reference/androidx/mediarouter/media/MediaTransferReceiver` is enabled. |
| `@https://jspecify.dev/docs/api/org/jspecify/annotations/NonNull.html https://developer.android.com/reference/androidx/mediarouter/media/MediaRouterParams.Builder` | `https://developer.android.com/reference/androidx/mediarouter/media/MediaRouterParams.Builder#setMediaTransferRestrictedToSelfProviders(boolean)(boolean enabled)` Sets whether the declared `https://developer.android.com/reference/androidx/mediarouter/media/MediaTransferReceiver` feature is restricted to `https://developer.android.com/reference/androidx/mediarouter/media/MediaRouteProviderService` provider services that handle the action ` android.media.MediaRoute2ProviderService` declared by this app. |
| `@https://jspecify.dev/docs/api/org/jspecify/annotations/NonNull.html https://developer.android.com/reference/androidx/mediarouter/media/MediaRouterParams.Builder` | `https://developer.android.com/reference/androidx/mediarouter/media/MediaRouterParams.Builder#setOutputSwitcherEnabled(boolean)(boolean enabled)` Sets whether output switcher dialogs are enabled. |
| `@https://jspecify.dev/docs/api/org/jspecify/annotations/NonNull.html https://developer.android.com/reference/androidx/mediarouter/media/MediaRouterParams.Builder` | `https://developer.android.com/reference/androidx/mediarouter/media/MediaRouterParams.Builder#setTransferToLocalEnabled(boolean)(boolean enabled)` Enables media can be transferred from remote (e.g. TV) to local (e.g. phone, Bluetooth). |

## Public constructors

### Builder

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

```
public Builder()
```

Constructor for builder to create `https://developer.android.com/reference/androidx/mediarouter/media/MediaRouterParams`.

### Builder

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

```
public Builder(@NonNull MediaRouterParams params)
```

Constructor for builder to create `https://developer.android.com/reference/androidx/mediarouter/media/MediaRouterParams` with existing `https://developer.android.com/reference/androidx/mediarouter/media/MediaRouterParams` instance.

| Parameters |
|---|---|
| `@https://jspecify.dev/docs/api/org/jspecify/annotations/NonNull.html https://developer.android.com/reference/androidx/mediarouter/media/MediaRouterParams params` | the existing instance to copy data from. |

## Public methods

### build

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

```
public @NonNull MediaRouterParams build()
```

Builds the `https://developer.android.com/reference/androidx/mediarouter/media/MediaRouterParams` instance.

### setDialogType

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

```
public @NonNull MediaRouterParams.Builder setDialogType(int dialogType)
```

Sets the media route controller dialog type. Default value is `https://developer.android.com/reference/androidx/mediarouter/media/MediaRouterParams#DIALOG_TYPE_DEFAULT()`.

Note that from Android R, output switcher will be used rather than the dialog type set by this method if both `https://developer.android.com/reference/androidx/mediarouter/media/MediaRouterParams.Builder#setOutputSwitcherEnabled(boolean)` output switcher} and `https://developer.android.com/reference/androidx/mediarouter/media/MediaTransferReceiver` are enabled.

| Parameters |
|---|---|
| `int dialogType` | the dialog type |

| See also |
|---|---|
| `https://developer.android.com/reference/androidx/mediarouter/media/MediaRouterParams.Builder#setOutputSwitcherEnabled(boolean)` |   |
| `https://developer.android.com/reference/androidx/mediarouter/media/MediaRouterParams#DIALOG_TYPE_DEFAULT()` |   |
| `https://developer.android.com/reference/androidx/mediarouter/media/MediaRouterParams#DIALOG_TYPE_DYNAMIC_GROUP()` |   |

### setMediaTransferReceiverEnabled

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

```
public @NonNull MediaRouterParams.Builder setMediaTransferReceiverEnabled(boolean enabled)
```

Sets whether declared `https://developer.android.com/reference/androidx/mediarouter/media/MediaTransferReceiver` is enabled. The default value is `true`. This method will be no-op for Android versions earlier than Android R and it stays `false` on devices earlier than Android R.

It can be used to disable media transfer feature when `https://developer.android.com/reference/androidx/mediarouter/media/MediaTransferReceiver` is declared. If set to `false`, media transfer feature will be disabled even when `https://developer.android.com/reference/androidx/mediarouter/media/MediaTransferReceiver` is declared.

It is not recommended to change this value at runtime. It could result in getting invalid routes.

| See also |
|---|---|
| `https://developer.android.com/reference/androidx/mediarouter/media/MediaTransferReceiver` |   |

### setMediaTransferRestrictedToSelfProviders

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

```
public @NonNull MediaRouterParams.Builder setMediaTransferRestrictedToSelfProviders(boolean enabled)
```

Sets whether the declared `https://developer.android.com/reference/androidx/mediarouter/media/MediaTransferReceiver` feature is restricted to `https://developer.android.com/reference/androidx/mediarouter/media/MediaRouteProviderService` provider services that handle the action `
android.media.MediaRoute2ProviderService` declared by this app.

If this app restricts the `https://developer.android.com/reference/androidx/mediarouter/media/MediaTransferReceiver` feature to its own `https://developer.android.com/reference/androidx/mediarouter/media/MediaRouteProviderService` provider service that handles the action `
android.media.MediaRoute2ProviderService`, then all other media route providers that declare both the `android.media.MediaRouteProviderService` action and the `
android.media.MediaRoute2ProviderService` action would be treated as `https://developer.android.com/reference/androidx/mediarouter/media/MediaRouteProviderService` provider services with only the action `
android.media.MediaRouteProviderService`.

For `https://developer.android.com/reference/androidx/mediarouter/media/MediaRouteProviderService` provider services that only handle the action `android.media.MediaRouteProviderService`, they are not affected by this flag.

### setOutputSwitcherEnabled

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

```
public @NonNull MediaRouterParams.Builder setOutputSwitcherEnabled(boolean enabled)
```

Sets whether output switcher dialogs are enabled. This method will be no-op for Android versions earlier than Android R. Default value is `false`.

If set to `true`, and when `https://developer.android.com/reference/androidx/mediarouter/media/MediaTransferReceiver`, `https://developer.android.com/reference/androidx/mediarouter/app/MediaRouteButton` will show output switcher when clicked, no matter what type of dialog is set by `https://developer.android.com/reference/androidx/mediarouter/media/MediaRouterParams.Builder#setDialogType(int)`.

If set to `false`, `https://developer.android.com/reference/androidx/mediarouter/app/MediaRouteButton` will show the dialog type which is set by `https://developer.android.com/reference/androidx/mediarouter/media/MediaRouterParams.Builder#setDialogType(int)`.

### setTransferToLocalEnabled

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

```
public @NonNull MediaRouterParams.Builder setTransferToLocalEnabled(boolean enabled)
```

Enables media can be transferred from remote (e.g. TV) to local (e.g. phone, Bluetooth). Apps that enabling this feature should handle the case in their `https://developer.android.com/reference/androidx/mediarouter/media/MediaRouter.Callback#onRouteSelected(androidx.mediarouter.media.MediaRouter,androidx.mediarouter.media.MediaRouter.RouteInfo,int)` properly. Default value is `false`.

When this is enabled, `https://developer.android.com/reference/androidx/mediarouter/media/MediaRouter.Callback#onRouteSelected(androidx.mediarouter.media.MediaRouter,androidx.mediarouter.media.MediaRouter.RouteInfo,int,androidx.mediarouter.media.MediaRouter.RouteInfo)` will be called whenever the 'remote to local' transfer happens, regardless of the selector provided in `https://developer.android.com/reference/androidx/mediarouter/media/MediaRouter#addCallback(androidx.mediarouter.media.MediaRouteSelector,androidx.mediarouter.media.MediaRouter.Callback)`.

Note: This method will be no-op for Android versions earlier than Android R. It has effect only when `https://developer.android.com/reference/androidx/mediarouter/media/MediaTransferReceiver`.