Passer directement au contenu

Les plus consultés

Consultés récemment

navigation

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 requestNetwork(NetworkRequest, NetworkCallback), registerNetworkCallback(NetworkRequest, NetworkCallback), or {@link #registerDefaultNetworkCallback(NetworkCallback). A {@code NetworkCallback} is unregistered by calling {@link #unregisterNetworkCallback(NetworkCallback)}. A {@code NetworkCallback} should be registered at most once at any time. A {@code 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 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.

void onUnavailable()

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

Inherited methods

Public constructors

ConnectivityManager.NetworkCallback

added in API level 21
ConnectivityManager.NetworkCallback ()

Public methods

onAvailable

added in API level 21
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.

Parameters
network Network: The Network of the satisfying network.

onCapabilitiesChanged

added in API level 21
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

added in API level 21
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

added in API level 21
void onLosing (Network network, 
                int maxMsToLive)

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 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

added in API level 21
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

added in API level 26
void onUnavailable ()

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.

Ce site Web utilise des cookies pour enregistrer vos préférences relatives à la langue du site et aux options d'affichage.

Recevez les dernières actualités destinées aux développeurs Android, ainsi que des conseils qui vous mèneront vers le succès sur Google Play.

* Champs obligatoires

Super !

Suivez Google Developers sur WeChat

Consulter ce site en  ?

Vous avez demandé une page en , mais la langue indiquée dans vos préférences linguistiques pour ce site est la suivante : .

Souhaitez-vous modifier vos préférences linguistiques et parcourir ce site en  ? Pour modifier ultérieurement vos préférences linguistiques, utilisez le menu "Langue" au bas de chaque page.

Cette classe nécessite le niveau d'API  ou supérieur

Ce document est masqué, car vous avez sélectionné le niveau d'API  pour la documentation. Vous pouvez modifier le niveau d'API pour la documentation avec le sélecteur situé au-dessus du menu de navigation de gauche.

Pour découvrir comment déterminer le niveau d'API nécessaire pour votre application, consultez le guide sur la prise en charge des différentes versions de plate-forme (en anglais).

Take a short survey?
Help us improve the Android developer experience. (April 2018 — Developer Survey)