NetworkCallback

open class NetworkCallback
kotlin.Any
   ↳ 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 #requestNetwork(NetworkRequest, NetworkCallback), #registerNetworkCallback(NetworkRequest, NetworkCallback), or #registerDefaultNetworkCallback(NetworkCallback). A NetworkCallback is unregistered by calling #unregisterNetworkCallback(NetworkCallback). A NetworkCallback should be registered at most once at any time. A NetworkCallback that has been unregistered can be registered again.
Requires API level 21 (Android 5.0, Lollipop)

Summary

Public constructors

Public methods
open Unit
onCapabilitiesChanged(network: Network!, networkCapabilities: NetworkCapabilities!)

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

open Unit
onLost(network: Network!)

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

open Unit
onLinkPropertiesChanged(network: Network!, linkProperties: LinkProperties!)

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

open Unit

Called if no network is found in the timeout time specified in #requestNetwork(NetworkRequest, NetworkCallback, int) call.

open Unit
onLosing(network: Network!, maxMsToLive: Int)

Called when the network is about to be disconnected.

open Unit
onAvailable(network: Network!)

Called when the framework connects and has declared a new network ready for use.

Public constructors

<init>

NetworkCallback()

Public methods

onCapabilitiesChanged

added in API level 21
open fun onCapabilitiesChanged(network: Network!, networkCapabilities: NetworkCapabilities!): Unit

Called when the network the framework connected to for this request changes capabilities but still satisfies the stated need.
Requires API level 21 (Android 5.0, Lollipop)

Parameters
network Network!: The Network whose capabilities have changed.
networkCapabilities Network!: The new android.net.NetworkCapabilities for this network.

onLost

added in API level 21
open fun onLost(network: Network!): Unit

Called when the framework has a hard loss of the network or when the graceful failure ends.
Requires API level 21 (Android 5.0, Lollipop)

Parameters
network Network!: The Network lost.

onLinkPropertiesChanged

added in API level 21
open fun onLinkPropertiesChanged(network: Network!, linkProperties: LinkProperties!): Unit

Called when the network the framework connected to for this request changes LinkProperties.
Requires API level 21 (Android 5.0, Lollipop)

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

onUnavailable

added in API level 26
open fun onUnavailable(): Unit

Called if no network is found in the timeout time specified in #requestNetwork(NetworkRequest, NetworkCallback, int) call. This callback is not called for the version of #requestNetwork(NetworkRequest, NetworkCallback) without timeout. When this callback is invoked the associated NetworkRequest will have already been removed and released, as if #unregisterNetworkCallback(NetworkCallback) had been called.
Requires API level 26 (Android 8.0, Oreo)

onLosing

added in API level 21
open fun onLosing(network: Network!, maxMsToLive: Int): Unit

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.
Requires API level 21 (Android 5.0, Lollipop)

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

onAvailable

added in API level 21
open fun onAvailable(network: Network!): Unit

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(Network, NetworkCapabilities) then by a call to #onLinkPropertiesChanged(Network, LinkProperties).
Requires API level 21 (Android 5.0, Lollipop)

Parameters
network Network!: The Network of the satisfying network.