MediaRouter2.GetInstance Method

Definition

Overloads

GetInstance(Context)

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

GetInstance(Context, String, IExecutor, IRunnable)

Returns a proxy MediaRouter2 instance that allows you to control the routing of an app specified by clientPackageName.

GetInstance(Context)

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

[Android.Runtime.Register("getInstance", "(Landroid/content/Context;)Landroid/media/MediaRouter2;", "", ApiSince=30)]
public static Android.Media.MediaRouter2 GetInstance (Android.Content.Context context);
[<Android.Runtime.Register("getInstance", "(Landroid/content/Context;)Landroid/media/MediaRouter2;", "", ApiSince=30)>]
static member GetInstance : Android.Content.Context -> Android.Media.MediaRouter2

Parameters

context
Context

Returns

Attributes

Remarks

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

Java documentation for android.media.MediaRouter2.getInstance(android.content.Context).

Portions of this page are modifications based on work created and shared by the Android Open Source Project and used according to terms described in the Creative Commons 2.5 Attribution License.

Applies to

GetInstance(Context, String, IExecutor, IRunnable)

Returns a proxy MediaRouter2 instance that allows you to control the routing of an app specified by clientPackageName.

[Android.Runtime.Register("getInstance", "(Landroid/content/Context;Ljava/lang/String;Ljava/util/concurrent/Executor;Ljava/lang/Runnable;)Landroid/media/MediaRouter2;", "", ApiSince=35)]
public static Android.Media.MediaRouter2 GetInstance (Android.Content.Context context, string clientPackageName, Java.Util.Concurrent.IExecutor executor, Java.Lang.IRunnable onInstanceInvalidatedListener);
[<Android.Runtime.Register("getInstance", "(Landroid/content/Context;Ljava/lang/String;Ljava/util/concurrent/Executor;Ljava/lang/Runnable;)Landroid/media/MediaRouter2;", "", ApiSince=35)>]
static member GetInstance : Android.Content.Context * string * Java.Util.Concurrent.IExecutor * Java.Lang.IRunnable -> Android.Media.MediaRouter2

Parameters

context
Context

The Context of the caller.

clientPackageName
String

The package name of the app you want to control the routing of.

executor
IExecutor

The Executor on which to invoke onInstanceInvalidatedListener.

onInstanceInvalidatedListener
IRunnable

Callback for when the MediaRouter2 instance is invalidated due to lost permissions.

Returns

Attributes

Remarks

Returns a proxy MediaRouter2 instance that allows you to control the routing of an app specified by clientPackageName. Returns null if the specified package name does not exist.

Proxy MediaRouter2 instances operate differently than regular MediaRouter2 instances:

<ul> <li>

#registerRouteCallback ignores any RouteDiscoveryPreference discovery preference passed by a proxy router. Use RouteDiscoveryPreference#EMPTY when setting a route callback. <li>

Methods returning non-system RoutingController controllers always return new instances with the latest data. Do not attempt to compare or store them. Instead, use #getController(String) or #getControllers() to query the most up-to-date state. <li>

Calls to #setOnGetControllerHintsListener are ignored. </ul>

Use this method when you only hold a revocable version of Manifest.permission#MEDIA_ROUTING_CONTROL (e.g. acquired via the AppOpsManager). Otherwise, use #getInstance(Context, String).

onInstanceInvalidatedListener is called when the instance is invalidated because the calling app has lost Manifest.permission#MEDIA_ROUTING_CONTROL and does not hold Manifest.permission#MEDIA_CONTENT_CONTROL. Do not use the invalidated instance after receiving this callback, as the system will ignore all operations. Call #getInstance(Context, String, Executor, Runnable) again after reacquiring the relevant permissions.

Java documentation for android.media.MediaRouter2.getInstance(android.content.Context, java.lang.String, java.util.concurrent.Executor, java.lang.Runnable).

Portions of this page are modifications based on work created and shared by the Android Open Source Project and used according to terms described in the Creative Commons 2.5 Attribution License.

Applies to