public class ConnectivityManager extends Object
| Modifier and Type | Class and Description |
|---|---|
static class |
ConnectivityManager.NetworkCallback
Base class for NetworkRequest callbacks.
|
| Modifier | Constructor and Description |
|---|---|
protected |
ConnectivityManager() |
| Modifier and Type | Method and Description |
|---|---|
protected void |
doNotifyAvailabilityChange(Network network,
boolean available,
ConnectivityManager.NetworkCallback[] networkCallbacks)
Notify the networkCallbacks about an availability change.
|
protected void |
doNotifyCapabilitiesChange(Network network,
NetworkCapabilities capabilities,
ConnectivityManager.NetworkCallback[] networkCallBacks)
Notify the callback of a capabilities change.
|
Network |
getActiveNetwork()
Returns a
Network object corresponding to the currently active default data network. |
NetworkInfo |
getActiveNetworkInfo()
Returns details about the currently active default data network.
|
Network[] |
getAllNetworks()
Returns an array of all
Network currently tracked by the framework. |
NetworkCapabilities |
getNetworkCapabilities(Network network)
Get the
NetworkCapabilities for the given Network. |
NetworkInfo |
getNetworkInfo(Network network)
Returns connection status information about a particular Network.
|
protected void |
notifyNetworkCallbacks(Network network,
boolean available)
Notifies a network availability change.
|
protected void |
notifyNetworkCallbacks(Network network,
NetworkCapabilities capabilities)
Notifies a network capability change.
|
void |
registerDefaultNetworkCallback(ConnectivityManager.NetworkCallback networkCallback)
Registers to receive notifications about changes in the system default network.
|
void |
registerNetworkCallback(NetworkRequest request,
ConnectivityManager.NetworkCallback networkCallback)
Registers to receive notifications about all networks which satisfy the given
NetworkRequest. |
protected void |
setActiveNetwork(Network network)
Sets the active network.
|
protected void |
setAvailable(boolean available,
Network network,
NetworkInfo networkInfo)
Sets the network availability.
|
void |
unregisterNetworkCallback(ConnectivityManager.NetworkCallback networkCallback)
Unregisters callbacks about and possibly releases networks originating from
registerNetworkCallback(android.net.NetworkRequest, android.net.ConnectivityManager.NetworkCallback)
calls. |
protected void doNotifyAvailabilityChange(Network network, boolean available, ConnectivityManager.NetworkCallback[] networkCallbacks)
network - the network.available - the availability.networkCallbacks - the callback to call.protected void doNotifyCapabilitiesChange(Network network, NetworkCapabilities capabilities, ConnectivityManager.NetworkCallback[] networkCallBacks)
network - the network.capabilities - the capabilities.networkCallBacks - the callback to call.public Network getActiveNetwork()
Network object corresponding to the currently active default data network. In the event that
the current active default data network disconnects, the returned Network object will no longer be
usable. This will return null when there is no default network.Network object for the current default network or null if no default network is
currently activepublic NetworkInfo getActiveNetworkInfo()
NetworkInfo.isConnected() before initiating
network traffic. This may return null when there is no default network.NetworkInfo object for the current default network or null if no network default
network is currently activepublic Network[] getAllNetworks()
Network currently tracked by the framework.Network objects.public NetworkCapabilities getNetworkCapabilities(Network network)
NetworkCapabilities for the given Network. This will return null if the network is
unknown.network - The Network object identifying the network in question.NetworkCapabilities for the network, or null.public NetworkInfo getNetworkInfo(Network network)
network - Network specifying which network in which you're interested.NetworkInfo object for the requested network or null if the Network is not valid.protected void notifyNetworkCallbacks(Network network, boolean available)
network - the network.available - true if the network is available.protected void notifyNetworkCallbacks(Network network, NetworkCapabilities capabilities)
network - the network.capabilities - the network capabilities.public void registerDefaultNetworkCallback(ConnectivityManager.NetworkCallback networkCallback)
unregisterNetworkCallback(NetworkCallback) is called.networkCallback - The ConnectivityManager.NetworkCallback that the system will call as the system default network changes. The
callback is invoked on the default internal Handler.public void registerNetworkCallback(NetworkRequest request, ConnectivityManager.NetworkCallback networkCallback)
NetworkRequest. The
callbacks will continue to be called until either the application exits or unregisterNetworkCallback(android.net.ConnectivityManager.NetworkCallback) is
calledrequest - NetworkRequest describing this request.networkCallback - The ConnectivityManager.NetworkCallback that the system will call as suitable networks change state.protected void setActiveNetwork(Network network)
network - the network to set.protected void setAvailable(boolean available,
Network network,
NetworkInfo networkInfo)
available - true if available.network - the network.networkInfo - the network info.public void unregisterNetworkCallback(ConnectivityManager.NetworkCallback networkCallback)
registerNetworkCallback(android.net.NetworkRequest, android.net.ConnectivityManager.NetworkCallback)
calls. If the given NetworkCallback had previosuly been used with #requestNetwork, any networks
that had been connected to only to satisfy that request will be disconnected.networkCallback - The ConnectivityManager.NetworkCallback used when making the request.