ConnectivityManager.NetworkCallback
public
static
class
ConnectivityManager.NetworkCallback
extends Object
| java.lang.Object | |
| ↳ | android.net.ConnectivityManager.NetworkCallback |
Base class for NetworkRequest callbacks. Used for notifications about network
changes. Should be extended by applications wanting notifications.
A NetworkCallback is registered by calling
ConnectivityManager.requestNetwork(android.net.NetworkRequest, android.net.ConnectivityManager.NetworkCallback),
ConnectivityManager.registerNetworkCallback(android.net.NetworkRequest, android.net.ConnectivityManager.NetworkCallback),
or ConnectivityManager.registerDefaultNetworkCallback(android.net.ConnectivityManager.NetworkCallback). A NetworkCallback is
unregistered by calling ConnectivityManager.unregisterNetworkCallback(android.net.ConnectivityManager.NetworkCallback).
A NetworkCallback should be registered at most once at any time.
A NetworkCallback that has been unregistered can be registered again.
Summary
Public constructors | |
|---|---|
ConnectivityManager.NetworkCallback()
|
|
Public methods | |
|---|---|
void
|
onAvailable(Network network)
Called when the framework connects and has declared a new network ready for use. |
void
|
onBlockedStatusChanged(Network network, boolean blocked)
Called when access to the specified network is blocked or unblocked. |
void
|
onCapabilitiesChanged(Network network, NetworkCapabilities networkCapabilities)
Called when the network the framework connected to for this request changes capabilities but still satisfies the stated need. |
void
|
onLinkPropertiesChanged(Network network, LinkProperties linkProperties)
Called when the network the framework connected to for this request
changes |
void
|
onLosing(Network network, int maxMsToLive)
Called when the network is about to be disconnected. |
void
|
onLost(Network network)
Called when the framework has a hard loss of the network or when the graceful failure ends. |
void
|
onUnavailable()
Called if no network is found in the timeout time specified in
|
Inherited methods | |
|---|---|
Public constructors
ConnectivityManager.NetworkCallback
public ConnectivityManager.NetworkCallback ()
Public methods
onAvailable
public void onAvailable (Network network)
Called when the framework connects and has declared a new network ready for use.
This callback may be called more than once if the Network that is
satisfying the request changes. This will always immediately be followed by a
call to onCapabilitiesChanged(android.net.Network, android.net.NetworkCapabilities) then by a
call to onLinkPropertiesChanged(android.net.Network, android.net.LinkProperties), and a call to
onBlockedStatusChanged(android.net.Network, boolean).
| Parameters | |
|---|---|
network |
Network: The Network of the satisfying network. |
onBlockedStatusChanged
public void onBlockedStatusChanged (Network network, boolean blocked)
Called when access to the specified network is blocked or unblocked.
| Parameters | |
|---|---|
network |
Network: The Network whose blocked status has changed. |
blocked |
boolean: The blocked status of this Network. |
onCapabilitiesChanged
public void onCapabilitiesChanged (Network network, NetworkCapabilities networkCapabilities)
Called when the network the framework connected to for this request changes capabilities but still satisfies the stated need.
| Parameters | |
|---|---|
network |
Network: The Network whose capabilities have changed. |
networkCapabilities |
NetworkCapabilities: The new NetworkCapabilities for this
network. |
onLinkPropertiesChanged
public void onLinkPropertiesChanged (Network network, LinkProperties linkProperties)
Called when the network the framework connected to for this request
changes LinkProperties.
| Parameters | |
|---|---|
network |
Network: The Network whose link properties have changed. |
linkProperties |
LinkProperties: The new LinkProperties for this network. |
onLosing
public void onLosing (Network network, int maxMsToLive)
Called when the network is about to be disconnected. Often paired with an
NetworkCallback#onAvailable call with the new replacement network
for graceful handover. This may not be called if we have a hard loss
(loss without warning). This may be followed by either a
NetworkCallback#onLost call or a
NetworkCallback#onAvailable call for this network depending
on whether we lose or regain it.
| Parameters | |
|---|---|
network |
Network: The Network that is about to be disconnected. |
maxMsToLive |
int: The time in ms the framework will attempt to keep the
network connected. Note that the network may suffer a
hard loss at any time. |
onLost
public void onLost (Network network)
Called when the framework has a hard loss of the network or when the graceful failure ends.
| Parameters | |
|---|---|
network |
Network: The Network lost. |
onUnavailable
public void onUnavailable ()
Called if no network is found in the timeout time specified in
ConnectivityManager.requestNetwork(android.net.NetworkRequest, android.net.ConnectivityManager.NetworkCallback, int) call or if the
requested network request cannot be fulfilled (whether or not a timeout was
specified). When this callback is invoked the associated
NetworkRequest will have already been removed and released, as if
ConnectivityManager.unregisterNetworkCallback(android.net.ConnectivityManager.NetworkCallback) had been called.