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
@GuardedBy(value = "networkTypeLock")
@C.NetworkType
networkType

Public methods

synchronized static NetworkTypeObserver

Returns a network type observer instance.

int

Returns the current network type.

void

Registers a listener.

synchronized static void

Resets the network type observer for tests.

Public fields

networkType

@GuardedBy(value = "networkTypeLock")
@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

public void register(NetworkTypeObserver.Listener listener)

Registers a listener.

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

Parameters
NetworkTypeObserver.Listener listener

The Listener.

resetForTests

@VisibleForTesting
synchronized public static void resetForTests()

Resets the network type observer for tests.