NetworkTypeObserver


@UnstableApi
public final class NetworkTypeObserver


Observer for network type changes.

Registered listeners are informed at registration and whenever the network type changes.

The current network type can also be queried without registration.

Summary

Nested types

A listener for network type changes.

Public fields

int

Public methods

synchronized static NetworkTypeObserver

Returns a network type observer instance.

int

Returns the current network type.

void
@InlineMe(replacement = "this.register(listener, new Handler(Looper.getMainLooper())::post)", imports = [""android.os.Handler"", ""android.os.Looper""])
register(NetworkTypeObserver.Listener listener)

This method is deprecated.

Use register instead.

void

Registers a listener.

synchronized static void

Resets the network type observer for tests.

Public fields

networkType

@GuardedBy(value = "lock")
@C.NetworkType
public int networkType

Public methods

getInstance

synchronized public static NetworkTypeObserver getInstance(Context context)

Returns a network type observer instance.

Parameters
Context context

A Context.

getNetworkType

@C.NetworkType
public int getNetworkType()

Returns the current network type.

register

@InlineMe(replacement = "this.register(listener, new Handler(Looper.getMainLooper())::post)", imports = [""android.os.Handler"", ""android.os.Looper""])
public void register(NetworkTypeObserver.Listener listener)

register

public void register(NetworkTypeObserver.Listener listener, Executor executor)

Registers a listener.

The current network type will be reported to the listener after registration.

Parameters
NetworkTypeObserver.Listener listener

The Listener.

Executor executor

The Executor to call the listener on.

resetForTests

@VisibleForTesting
synchronized public static void resetForTests()

Resets the network type observer for tests.