# MediaTransferReceiver

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

*** ** * ** ***


```
class MediaTransferReceiver : BroadcastReceiver
```

<br />

|---|---|---|
| [kotlin.Any](https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-any/index.html) |||
| ↳ | [android.content.BroadcastReceiver](https://developer.android.com/reference/android/content/BroadcastReceiver.html) ||
|   | ↳ | [androidx.mediarouter.media.MediaTransferReceiver](https://developer.android.com/reference/kotlin/androidx/mediarouter/media/MediaTransferReceiver) |

*** ** * ** ***

A `https://developer.android.com/reference/android/content/BroadcastReceiver.html` class for enabling Media transfer feature.

Media transfer is a feature that allows system UI and other trusted components to control enabled apps' media routing. By using this, users can re-route the app's media while the application is in the background. Also, the media can be transferred from one device to another device seamlessly, depending on the devices. This feature is supported from Android 11.

To enable the media transfer feature, apps can enable the `https://developer.android.com/reference/kotlin/androidx/mediarouter/media/MediaRouterParams.Builder#setMediaTransferReceiverEnabled(boolean)` (see `https://developer.android.com/reference/kotlin/androidx/mediarouter/media/MediaRouter#setRouterParams(androidx.mediarouter.media.MediaRouterParams)`). Or, alternatively, apps can declare this receiver in the app's manifest. For example:

```kotlin
<application>
    <receiver android:name="androidx.mediarouter.media.MediaTransferReceiver"
        android:exported="false" />
</application>
```

Media apps that enable this feature should implement the `https://developer.android.com/reference/kotlin/androidx/mediarouter/media/MediaRouter.Callback` properly. Specifically:

- Apps should handle events even while in the background. For example, this means that the callback should not be removed in `https://developer.android.com/reference/android/app/Activity.html#onStop()`. (See `https://developer.android.com/reference/kotlin/androidx/mediarouter/media/MediaRouter#addCallback(androidx.mediarouter.media.MediaRouteSelector,androidx.mediarouter.media.MediaRouter.Callback,int)` for how to add a callback.
- Apps should handle media routing changes by another app. Apps can override `https://developer.android.com/reference/kotlin/androidx/mediarouter/media/MediaRouter.Callback#onRouteSelected(androidx.mediarouter.media.MediaRouter,androidx.mediarouter.media.MediaRouter.RouteInfo,int)` to handle routing changes. `https://developer.android.com/reference/kotlin/androidx/mediarouter/media/MediaRouter#setOnPrepareTransferListener(androidx.mediarouter.media.MediaRouter.OnPrepareTransferListener)` is also relevant.
- In order to enable transferring media from remote to local (e.g. from TV to phone), media apps should `https://developer.android.com/reference/kotlin/androidx/mediarouter/media/MediaRouterParams.Builder#setTransferToLocalEnabled(boolean)`. Otherwise, the local devices won't show up as a transfer target while playing on a remote device.

## Summary

| ### Public constructors |
|---|
| `https://developer.android.com/reference/kotlin/androidx/mediarouter/media/MediaTransferReceiver#MediaTransferReceiver()()` |

| ### Public functions |
|---|---|
| `https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-unit/index.html` | `https://developer.android.com/reference/kotlin/androidx/mediarouter/media/MediaTransferReceiver#onReceive(android.content.Context,android.content.Intent)(context: https://developer.android.com/reference/android/content/Context.html, intent: https://developer.android.com/reference/android/content/Intent.html)` |

### Inherited functions

From [android.content.BroadcastReceiver](https://developer.android.com/reference/android/content/BroadcastReceiver.html) `https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-unit/index.html` `https://developer.android.com/reference/android/content/BroadcastReceiver.html#abortBroadcast()()` `https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-unit/index.html` `https://developer.android.com/reference/android/content/BroadcastReceiver.html#clearAbortBroadcast()()` `https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-boolean/index.html` `https://developer.android.com/reference/android/content/BroadcastReceiver.html#getAbortBroadcast()()` `https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-boolean/index.html` `https://developer.android.com/reference/android/content/BroadcastReceiver.html#getDebugUnregister()()` `https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-int/index.html` `https://developer.android.com/reference/android/content/BroadcastReceiver.html#getResultCode()()` `https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-string/index.html!` `https://developer.android.com/reference/android/content/BroadcastReceiver.html#getResultData()()` `https://developer.android.com/reference/android/os/Bundle.html!` `https://developer.android.com/reference/android/content/BroadcastReceiver.html#getResultExtras(boolean)(makeMap: https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-boolean/index.html)` `https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-string/index.html!` `https://developer.android.com/reference/android/content/BroadcastReceiver.html#getSentFromPackage()()` `https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-int/index.html` `https://developer.android.com/reference/android/content/BroadcastReceiver.html#getSentFromUid()()` `https://developer.android.com/reference/android/content/BroadcastReceiver.PendingResult.html!` `https://developer.android.com/reference/android/content/BroadcastReceiver.html#goAsync()()` `https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-boolean/index.html` `https://developer.android.com/reference/android/content/BroadcastReceiver.html#isInitialStickyBroadcast()()` `https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-boolean/index.html` `https://developer.android.com/reference/android/content/BroadcastReceiver.html#isOrderedBroadcast()()` `https://developer.android.com/reference/android/os/IBinder.html!` `https://developer.android.com/reference/android/content/BroadcastReceiver.html#peekService(android.content.Context, android.content.Intent)(myContext: https://developer.android.com/reference/android/content/Context.html!, service: https://developer.android.com/reference/android/content/Intent.html!)` `https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-unit/index.html` `https://developer.android.com/reference/android/content/BroadcastReceiver.html#setDebugUnregister(boolean)(debug: https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-boolean/index.html)` `https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-unit/index.html` `https://developer.android.com/reference/android/content/BroadcastReceiver.html#setOrderedHint(boolean)(isOrdered: https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-boolean/index.html)` `https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-unit/index.html` `https://developer.android.com/reference/android/content/BroadcastReceiver.html#setResult(int, java.lang.String, android.os.Bundle)(code: https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-int/index.html, data: https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-string/index.html!, extras: https://developer.android.com/reference/android/os/Bundle.html!)` `https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-unit/index.html` `https://developer.android.com/reference/android/content/BroadcastReceiver.html#setResultCode(int)(code: https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-int/index.html)` `https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-unit/index.html` `https://developer.android.com/reference/android/content/BroadcastReceiver.html#setResultData(java.lang.String)(data: https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-string/index.html!)` `https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-unit/index.html` `https://developer.android.com/reference/android/content/BroadcastReceiver.html#setResultExtras(android.os.Bundle)(extras: https://developer.android.com/reference/android/os/Bundle.html!)`

## Public constructors

### MediaTransferReceiver

Added in 1.2.0

```
MediaTransferReceiver()
```

## Public functions

### onReceive

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

```
fun onReceive(context: Context, intent: Intent): Unit
```