public class NetworkInfo
extends Object implements Parcelable
| java.lang.Object | |
| android.net.NetworkInfo | |
描述网络接口的状态。
使用 getActiveNetworkInfo()获取表示当前网络连接的实例。
Nested classes |
|
|---|---|
枚举 |
NetworkInfo.DetailedState 网络连接的细粒度状态。 |
枚举 |
NetworkInfo.State 粗粒度的网络状态。 |
Inherited constants |
|---|
android.os.Parcelable
|
Fields |
|
|---|---|
public static final Creator<NetworkInfo> |
CREATOR |
公共方法(Public methods) |
|
|---|---|
int |
describeContents() 描述此Parcelable实例的封送表示中包含的特殊对象的种类。 |
NetworkInfo.DetailedState |
getDetailedState() 报告当前网络的细粒度状态。 |
String |
getExtraInfo() 报告有关网络状态的额外信息(如果有的话由较低的网络层提供)。 |
String |
getReason() 报告尝试建立连接失败的原因,如果有可用的话。 |
NetworkInfo.State |
getState() 报告网络当前的粗粒度状态。 |
int |
getSubtype() 返回描述网络子类型的网络类型特定的整数。 |
String |
getSubtypeName() 返回描述网络子类型的人类可读名称。 |
int |
getType() 报告此 |
String |
getTypeName() 返回描述网络类型的人类可读名称,例如“WIFI”或“MOBILE”。 |
boolean |
isAvailable() 指示网络连接是否可行。 |
boolean |
isConnected() 指示网络连接是否存在,并且可以建立连接并传递数据。 |
boolean |
isConnectedOrConnecting() 指示网络连接是否存在或正在建立。 |
boolean |
isFailover() 指示连接管理器尝试在与其他网络断开连接后故障转移到此网络是否导致当前连接到网络的尝试。 |
boolean |
isRoaming() 指示设备当前是否在此网络上漫游。 |
String |
toString() 返回对象的字符串表示形式。 |
void |
writeToParcel(Parcel dest, int flags) 将此对象平铺到一个包裹中。 |
继承方法(Inherited methods) |
|
|---|---|
java.lang.Object
|
|
android.os.Parcelable
|
|
int describeContents ()
描述此Parcelable实例的封送表示中包含的特殊对象的种类。 例如,如果对象将在writeToParcel(Parcel, int)的输出中包含writeToParcel(Parcel, int) ,则此方法的返回值必须包含CONTENTS_FILE_DESCRIPTOR位。
| 返回(Returns) | |
|---|---|
int |
a bitmask indicating the set of special object types marshaled by this Parcelable object instance. |
NetworkInfo.DetailedState getDetailedState ()
报告当前网络的细粒度状态。
| 返回(Returns) | |
|---|---|
NetworkInfo.DetailedState |
the fine-grained state |
String getExtraInfo ()
报告有关网络状态的额外信息(如果有的话由较低的网络层提供)。
| 返回(Returns) | |
|---|---|
String |
the extra information, or null if not available |
String getReason ()
报告尝试建立连接失败的原因,如果有可用的话。
| 返回(Returns) | |
|---|---|
String |
the reason for failure, or null if not available |
NetworkInfo.State getState ()
报告网络当前的粗粒度状态。
| 返回(Returns) | |
|---|---|
NetworkInfo.State |
the coarse-grained state |
int getSubtype ()
返回描述网络子类型的网络类型特定的整数。
| 返回(Returns) | |
|---|---|
int |
the network subtype |
String getSubtypeName ()
返回描述网络子类型的人类可读名称。
| 返回(Returns) | |
|---|---|
String |
the name of the network subtype |
int getType ()
报告此 NetworkInfo的信息所属的网络类型。
| 返回(Returns) | |
|---|---|
int |
one of TYPE_MOBILE, TYPE_WIFI, TYPE_WIMAX, TYPE_ETHERNET, TYPE_BLUETOOTH, or other types defined by ConnectivityManager |
String getTypeName ()
返回描述网络类型的人类可读名称,例如“WIFI”或“MOBILE”。
| 返回(Returns) | |
|---|---|
String |
the name of the network type |
boolean isAvailable ()
指示网络连接是否可行。 当持久或半持久状态阻止连接到该网络的可能性时,网络不可用。 例子包括
| 返回(Returns) | |
|---|---|
boolean |
true if the network is available, false otherwise |
boolean isConnected ()
指示网络连接是否存在,并且可以建立连接并传递数据。
在尝试执行数据事务之前始终调用它。
| 返回(Returns) | |
|---|---|
boolean |
true if network connectivity exists, false otherwise. |
boolean isConnectedOrConnecting ()
指示网络连接是否存在或正在建立。 这对于需要执行与读取或写入数据不同的与网络相关的任何应用程序很有用。 对于后者,请拨打isConnected() ,以确保网络完全可用。
| 返回(Returns) | |
|---|---|
boolean |
true if network connectivity exists or is in the process of being established, false otherwise. |
boolean isFailover ()
指示连接管理器尝试在与其他网络断开连接后故障转移到此网络是否导致当前连接到网络的尝试。
| 返回(Returns) | |
|---|---|
boolean |
true if this is a failover attempt, false otherwise. |
boolean isRoaming ()
指示设备当前是否在此网络上漫游。 当true ,它表明在这个网络上使用数据可能会产生额外的成本。
| 返回(Returns) | |
|---|---|
boolean |
true if roaming is in effect, false otherwise. |
String toString ()
返回对象的字符串表示形式。 通常, toString方法返回一个字符串,用于“文本地表示”该对象。 结果应该是一个简洁但内容丰富的表述,对于一个人来说很容易阅读。 建议所有子类重写此方法。
类Object的toString方法返回一个字符串,其中包含对象为实例的类的名称,符号字符“ @ ”以及对象的哈希代码的无符号十六进制表示形式。 换句话说,这个方法返回一个字符串,其值等于:
getClass().getName() + '@' + Integer.toHexString(hashCode())
| 返回(Returns) | |
|---|---|
String |
a string representation of the object. |
void writeToParcel (Parcel dest, int flags)
将此对象平铺到一个包裹中。
| 参数(Parameters) | |
|---|---|
dest |
Parcel: The Parcel in which the object should be written. |
flags |
int: Additional flags about how the object should be written. May be 0 or PARCELABLE_WRITE_RETURN_VALUE. |