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 |
|---|
public interface NetworkTypeObserver.ListenerA listener for network type changes. |
Public fields |
|
|---|---|
int |
@GuardedBy(value = "lock") |
Public methods |
|
|---|---|
synchronized static NetworkTypeObserver |
getInstance(Context context)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""])This method is deprecated. Use |
void |
register(NetworkTypeObserver.Listener listener, Executor executor)Registers a listener. |
synchronized static void |
Resets the network type observer for tests. |
Public fields
Public methods
getInstance
synchronized public static NetworkTypeObserver getInstance(Context context)
Returns a network type observer instance.
register
@InlineMe(replacement = "this.register(listener, new Handler(Looper.getMainLooper())::post)", imports = [""android.os.Handler"", ""android.os.Looper""])
public voidregister(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 |
Executor executor |
The |
resetForTests
@VisibleForTesting
synchronized public static void resetForTests()
Resets the network type observer for tests.