# 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)

*** ** * ** ***


```
public final class MediaTransferReceiver extends BroadcastReceiver
```

<br />

|---|---|---|
| [java.lang.Object](https://developer.android.com/reference/java/lang/Object.html) |||
| ↳ | [android.content.BroadcastReceiver](https://developer.android.com/reference/android/content/BroadcastReceiver.html) ||
|   | ↳ | [androidx.mediarouter.media.MediaTransferReceiver](https://developer.android.com/reference/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/androidx/mediarouter/media/MediaRouterParams.Builder#setMediaTransferReceiverEnabled(boolean)` (see `https://developer.android.com/reference/androidx/mediarouter/media/MediaRouter#setRouterParams(androidx.mediarouter.media.MediaRouterParams)`). Or, alternatively, apps can declare this receiver in the app's manifest. For example:

```
<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/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/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/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/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/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/androidx/mediarouter/media/MediaTransferReceiver#MediaTransferReceiver()()` |

| ### Public methods |
|---|---|
| `void` | `https://developer.android.com/reference/androidx/mediarouter/media/MediaTransferReceiver#onReceive(android.content.Context,android.content.Intent)(@https://jspecify.dev/docs/api/org/jspecify/annotations/NonNull.html https://developer.android.com/reference/android/content/Context.html context, @https://jspecify.dev/docs/api/org/jspecify/annotations/NonNull.html https://developer.android.com/reference/android/content/Intent.html intent)` |

### Inherited methods

From [android.content.BroadcastReceiver](https://developer.android.com/reference/android/content/BroadcastReceiver.html) `final void` `https://developer.android.com/reference/android/content/BroadcastReceiver.html#abortBroadcast()()` `final void` `https://developer.android.com/reference/android/content/BroadcastReceiver.html#clearAbortBroadcast()()` `final boolean` `https://developer.android.com/reference/android/content/BroadcastReceiver.html#getAbortBroadcast()()` `final boolean` `https://developer.android.com/reference/android/content/BroadcastReceiver.html#getDebugUnregister()()` `final int` `https://developer.android.com/reference/android/content/BroadcastReceiver.html#getResultCode()()` `final https://developer.android.com/reference/java/lang/String.html` `https://developer.android.com/reference/android/content/BroadcastReceiver.html#getResultData()()` `final https://developer.android.com/reference/android/os/Bundle.html` `https://developer.android.com/reference/android/content/BroadcastReceiver.html#getResultExtras(boolean)(boolean makeMap)` `https://developer.android.com/reference/java/lang/String.html` `https://developer.android.com/reference/android/content/BroadcastReceiver.html#getSentFromPackage()()` `int` `https://developer.android.com/reference/android/content/BroadcastReceiver.html#getSentFromUid()()` `final https://developer.android.com/reference/android/content/BroadcastReceiver.PendingResult.html` `https://developer.android.com/reference/android/content/BroadcastReceiver.html#goAsync()()` `final boolean` `https://developer.android.com/reference/android/content/BroadcastReceiver.html#isInitialStickyBroadcast()()` `final boolean` `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)(https://developer.android.com/reference/android/content/Context.html myContext, https://developer.android.com/reference/android/content/Intent.html service)` `final void` `https://developer.android.com/reference/android/content/BroadcastReceiver.html#setDebugUnregister(boolean)(boolean debug)` `final void` `https://developer.android.com/reference/android/content/BroadcastReceiver.html#setOrderedHint(boolean)(boolean isOrdered)` `final void` `https://developer.android.com/reference/android/content/BroadcastReceiver.html#setResult(int, java.lang.String, android.os.Bundle)(int code, https://developer.android.com/reference/java/lang/String.html data, https://developer.android.com/reference/android/os/Bundle.html extras)` `final void` `https://developer.android.com/reference/android/content/BroadcastReceiver.html#setResultCode(int)(int code)` `final void` `https://developer.android.com/reference/android/content/BroadcastReceiver.html#setResultData(java.lang.String)(https://developer.android.com/reference/java/lang/String.html data)` `final void` `https://developer.android.com/reference/android/content/BroadcastReceiver.html#setResultExtras(android.os.Bundle)(https://developer.android.com/reference/android/os/Bundle.html extras)`

## Public constructors

### MediaTransferReceiver

Added in 1.2.0

```
public MediaTransferReceiver()
```

## Public methods

### onReceive

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

```
public void onReceive(@NonNull Context context, @NonNull Intent intent)
```