ConnectivityManager.NetworkCallback.OnAvailable(Network) Method
Definition
Important
Some information relates to prerelease product that may be substantially modified before it’s released. Microsoft makes no warranties, express or implied, with respect to the information provided here.
Called when the framework connects and has declared a new network ready for use.
[Android.Runtime.Register("onAvailable", "(Landroid/net/Network;)V", "GetOnAvailable_Landroid_net_Network_Handler")]
public virtual void OnAvailable (Android.Net.Network network);
[<Android.Runtime.Register("onAvailable", "(Landroid/net/Network;)V", "GetOnAvailable_Landroid_net_Network_Handler")>]
abstract member OnAvailable : Android.Net.Network -> unit
override this.OnAvailable : Android.Net.Network -> unit
Parameters
- network
- Network
The Network
of the satisfying network.
- Attributes
Remarks
Called when the framework connects and has declared a new network ready for use.
For callbacks registered with #registerNetworkCallback
, multiple networks may be available at the same time, and onAvailable will be called for each of these as they appear.
For callbacks registered with #requestNetwork
and #registerDefaultNetworkCallback
, this means the network passed as an argument is the new best network for this request and is now tracked by this callback ; this callback will no longer receive method calls about other networks that may have been passed to this method previously. The previously-best network may have disconnected, or it may still be around and the newly-best network may simply be better.
Starting with android.os.Build.VERSION_CODES#O
, this will always immediately be followed by a call to #onCapabilitiesChanged(Network, NetworkCapabilities)
then by a call to #onLinkPropertiesChanged(Network, LinkProperties)
, and a call to #onBlockedStatusChanged(Network, boolean)
.
Do NOT call #getNetworkCapabilities(Network)
or #getLinkProperties(Network)
or other synchronous ConnectivityManager methods in this callback as this is prone to race conditions (there is no guarantee the objects returned by these methods will be current). Instead, wait for a call to #onCapabilitiesChanged(Network, NetworkCapabilities)
and #onLinkPropertiesChanged(Network, LinkProperties)
whose arguments are guaranteed to be well-ordered with respect to other callbacks.
Portions of this page are modifications based on work created and shared by the Android Open Source Project and used according to terms described in the Creative Commons 2.5 Attribution License.