MediaTransferReceiver


public final class MediaTransferReceiver extends BroadcastReceiver


A BroadcastReceiver 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 media transfer enabled parameter (see setRouterParams). 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 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 onStop. (See addCallback for how to add a callback.
  • Apps should handle media routing changes by another app. Apps can override onRouteSelected to handle routing changes. setOnPrepareTransferListener is also relevant.
  • In order to enable transferring media from remote to local (e.g. from TV to phone), media apps should enable 'transfer to local' feature. Otherwise, the local devices won't show up as a transfer target while playing on a remote device.

Summary

Public constructors

Public methods

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

Inherited methods

From android.content.BroadcastReceiver
final void
final void
final boolean
final boolean
final int
final String
final Bundle
getResultExtras(boolean makeMap)
String
int
final BroadcastReceiver.PendingResult
final boolean
final boolean
IBinder
peekService(Context myContext, Intent service)
final void
setDebugUnregister(boolean debug)
final void
setOrderedHint(boolean isOrdered)
final void
setResult(int code, String data, Bundle extras)
final void
setResultCode(int code)
final void
final void

Public constructors

MediaTransferReceiver

Added in 1.2.0
public MediaTransferReceiver()

Public methods

onReceive

Added in 1.2.0
public void onReceive(@NonNull Context context, @NonNull Intent intent)