public static class ConnectivityManager.NetworkCallback
extends Object
| java.lang.Object | |
| android.net.ConnectivityManager.NetworkCallback | |
NetworkRequest回调的基类。 用于关于网络更改的通知。 应该由希望通知的应用程序扩展。
Public constructors |
|
|---|---|
ConnectivityManager.NetworkCallback() |
|
公共方法(Public methods) |
|
|---|---|
void |
onAvailable(Network network) 当框架连接并宣布可以使用新网络时调用。 |
void |
onCapabilitiesChanged(Network network, NetworkCapabilities networkCapabilities) 当连接到该请求的框架改变功能但仍满足所述需求时调用该网络。 |
void |
onLinkPropertiesChanged(Network network, LinkProperties linkProperties) 当网络连接到此请求的框架更改 |
void |
onLosing(Network network, int maxMsToLive) 当网络即将断开连接时调用。 |
void |
onLost(Network network) 当框架发生严重网络丢失或优美故障结束时调用。 |
继承方法(Inherited methods) |
|
|---|---|
java.lang.Object
|
|
void onAvailable (Network network)
当框架连接并宣布可以使用新网络时调用。 如果满足请求的Network更改,则可能会多次调用此回调。
| 参数(Parameters) | |
|---|---|
network |
Network: The Network of the satisfying network. |
void onCapabilitiesChanged (Network network, NetworkCapabilities networkCapabilities)
当连接到该请求的框架改变功能但仍满足所述需求时调用该网络。
| 参数(Parameters) | |
|---|---|
network |
Network: The Network whose capabilities have changed. |
networkCapabilities |
NetworkCapabilities: The new NetworkCapabilities for this network. |
void onLinkPropertiesChanged (Network network, LinkProperties linkProperties)
当连接到此请求的框架更改 LinkProperties 。
| 参数(Parameters) | |
|---|---|
network |
Network: The Network whose link properties have changed. |
linkProperties |
LinkProperties: The new LinkProperties for this network. |
void onLosing (Network network, int maxMsToLive)
当网络即将断开连接时调用。 通常配合onAvailable(Network)呼叫与新的替代网络进行优雅切换。 如果我们有很大的损失(损失没有警告),这可能不会被调用。 根据我们是否失去或重新获得,这可能会跟随一个onLost(Network)呼叫或一个onAvailable(Network)这个网络的呼叫。
| 参数(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. |
void onLost (Network network)
当框架发生严重网络丢失或优美故障结束时调用。
| 参数(Parameters) | |
|---|---|
network |
Network: The Network lost. |