Android - NetworkInfo对象的isConnected()与isAvailable()

xiaoxiao2021-02-28  16

isAvailable表示网络是否可用(与当前有没有连接没关系)

Indicates whether network connectivity is possible. A network is unavailable when a persistent or semi-persistent condition prevents the possibility of connecting to that network. Examples include boolean isAvailable () The device is out of the coverage area for any network of this type.The device is on a network other than the home network (i.e., roaming), and data roaming has been disabled.The device's radio is turned off, e.g., because airplane mode is enabled.

isConnected表示网络是否已经连接(能够传输数据),能够连接的网络一定是可用的(这个可用是指客户端可以和这个热点通信,但是不一定能接入互联网,比如一台手机接入到一个没有插网线的路由器)

Indicates whether network connectivity exists and it is possible to establish connections and pass data.

Always call this before attempting to perform data transactions.

转载请注明原文地址: https://www.6miu.com/read-2350016.html

最新回复(0)