Most visited

Recently visited

Added in API level 21

ConnectivityManager.NetworkCallback

public static class ConnectivityManager.NetworkCallback
extends Object

java.lang.Object
   ↳ android.net.ConnectivityManager.NetworkCallback


NetworkRequest回调的基类。 用于关于网络更改的通知。 应该由希望通知的应用程序扩展。

Summary

Public constructors

ConnectivityManager.NetworkCallback()

Public methods

void onAvailable(Network network)

当框架连接并宣布可以使用新网络时调用。

void onCapabilitiesChanged(Network network, NetworkCapabilities networkCapabilities)

当连接到该请求的框架改变功能但仍满足所述需求时调用该网络。

void onLinkPropertiesChanged(Network network, LinkProperties linkProperties)

当网络连接到此请求的框架更改 LinkProperties

void onLosing(Network network, int maxMsToLive)

当网络即将断开连接时调用。

void onLost(Network network)

当框架发生严重网络丢失或优美故障结束时调用。

Inherited methods

From class java.lang.Object

Public constructors

ConnectivityManager.NetworkCallback

Added in API level 21
ConnectivityManager.NetworkCallback ()

Public methods

onAvailable

Added in API level 21
void onAvailable (Network network)

当框架连接并宣布可以使用新网络时调用。 如果满足请求的Network更改,则可能会多次调用此回调。

Parameters
network Network: The Network of the satisfying network.

onCapabilitiesChanged

Added in API level 21
void onCapabilitiesChanged (Network network, 
                NetworkCapabilities networkCapabilities)

当连接到该请求的框架改变功能但仍满足所述需求时调用该网络。

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)

当连接到此请求的框架更改 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)

当网络即将断开连接时调用。 通常配合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.

onLost

Added in API level 21
void onLost (Network network)

当框架发生严重网络丢失或优美故障结束时调用。

Parameters
network Network: The Network lost.

Hooray!