Android APIs
public static class

ConnectivityManager.NetworkCallback

extends Object
java.lang.Object
   ↳ android.net.ConnectivityManager.NetworkCallback

Class Overview

Base class for NetworkRequest callbacks. Used for notifications about network changes. Should be extended by applications wanting notifications.

Summary

Public Constructors
ConnectivityManager.NetworkCallback()
Public Methods
void onAvailable(Network network)
Called when the framework connects and has declared new network ready for use.
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 LinkProperties.
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.
[Expand]
Inherited Methods
From class java.lang.Object

Public Constructors

public ConnectivityManager.NetworkCallback ()

Added in API level 21

Public Methods

public void onAvailable (Network network)

Added in API level 21

Called when the framework connects and has declared new network ready for use. This callback may be called more than once if the Network that is satisfying the request changes.

Parameters
network The Network of the satisfying network.

public void onCapabilitiesChanged (Network network, NetworkCapabilities networkCapabilities)

Added in API level 21

Called when the network the framework connected to for this request changes capabilities but still satisfies the stated need.

Parameters
network The Network whose capabilities have changed.
networkCapabilities The new NetworkCapabilities for this network.

public void onLinkPropertiesChanged (Network network, LinkProperties linkProperties)

Added in API level 21

Called when the network the framework connected to for this request changes LinkProperties.

Parameters
network The Network whose link properties have changed.
linkProperties The new LinkProperties for this network.

public void onLosing (Network network, int maxMsToLive)

Added in API level 21

Called when the network is about to be disconnected. Often paired with an onAvailable(Network) 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 onLost(Network) call or a onAvailable(Network) call for this network depending on whether we lose or regain it.

Parameters
network The Network that is about to be disconnected.
maxMsToLive 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.

public void onLost (Network network)

Added in API level 21

Called when the framework has a hard loss of the network or when the graceful failure ends.

Parameters
network The Network lost.