NetworkInfo(示例,出错代码)

来源:互联网 发布:派爱充值系统源码 编辑:程序博客网 时间:2024/05/22 11:38

NetworkInfo(示例,出错代码)

出处:Android API 作者:Android API 阅读:1529次

android.net
类 NetworkInfo

java.lang.Object  继承者 android.net.NetworkInfo
所有已实现的接口:
Parcelable

public class NetworkInfo
extends Object
implements Parcelable

Describes the status of a network interface of a given type (currently either Mobile or Wifi).


嵌套类摘要static classNetworkInfo.DetailedState 
          The fine-grained state of a network connection.static classNetworkInfo.State 
          Coarse-grained network state. 从接口 android.os.Parcelable 继承的嵌套类/接口Parcelable.Creator<T> 字段摘要static Parcelable.Creator<NetworkInfo>CREATOR 
          Implement the Parcelable interface. 从接口 android.os.Parcelable 继承的字段CONTENTS_FILE_DESCRIPTOR, PARCELABLE_WRITE_RETURN_VALUE 构造方法摘要NetworkInfo(int type) 
          已过时。   方法摘要 intdescribeContents() 
          Implement the Parcelable interface NetworkInfo.DetailedStategetDetailedState() 
          Reports the current fine-grained state of the network. StringgetExtraInfo() 
          Report the extra information about the network state, if any was provided by the lower networking layers., if one is available. StringgetReason() 
          Report the reason an attempt to establish connectivity failed, if one is available. NetworkInfo.StategetState() 
          Reports the current coarse-grained state of the network. intgetSubtype() 
          Return a network-type-specific integer describing the subtype of the network. StringgetSubtypeName() 
          Return a human-readable name describing the subtype of the network. intgetType() 
          Reports the type of network (currently mobile or Wi-Fi) to which the info in this object pertains. StringgetTypeName() 
          Return a human-readable name describe the type of the network, for example "WIFI" or "MOBILE". booleanisAvailable() 
          Indicates whether network connectivity is possible. booleanisConnected() 
          Indicates whether network connectivity exists and it is possible to establish connections and pass data. booleanisConnectedOrConnecting() 
          Indicates whether network connectivity exists or is in the process of being established. booleanisFailover() 
          Indicates whether the current attempt to connect to the network resulted from the ConnectivityManager trying to fail over to this network following a disconnect from another network. booleanisRoaming() 
          Indicates whether the device is currently roaming on this network. voidsetFailover(boolean isFailover) 
          Set the failover boolean. voidsetIsAvailable(boolean isAvailable) 
          Sets if the network is available, ie, if the connectivity is possible. StringtoString() 
          Returns a string containing a concise, human-readable description of this object. voidwriteToParcel(Parcel dest, int flags) 
          Implement the Parcelable interface. 从类 java.lang.Object 继承的方法equals, getClass, hashCode, notify, notifyAll, wait, wait, wait 

字段详细信息

CREATOR

public static final Parcelable.Creator<NetworkInfo> CREATOR
Implement the Parcelable interface.

构造方法详细信息

NetworkInfo

public NetworkInfo(int type)
已过时。 

参数:
type - network type
方法详细信息

getType

public int getType()
Reports the type of network (currently mobile or Wi-Fi) to which the info in this object pertains.

返回:
the network type

getSubtype

public int getSubtype()
Return a network-type-specific integer describing the subtype of the network.

返回:
the network subtype

getTypeName

public String getTypeName()
Return a human-readable name describe the type of the network, for example "WIFI" or "MOBILE".

返回:
the name of the network type

getSubtypeName

public String getSubtypeName()
Return a human-readable name describing the subtype of the network.

返回:
the name of the network subtype

isConnectedOrConnecting

public boolean isConnectedOrConnecting()
Indicates whether network connectivity exists or is in the process of being established. This is good for applications that need to do anything related to the network other than read or write data. For the latter, call isConnected() instead, which guarantees that the network is fully usable.

返回:
true if network connectivity exists or is in the process of being established, false otherwise.

isConnected

public boolean isConnected()
Indicates whether network connectivity exists and it is possible to establish connections and pass data.

返回:
true if network connectivity exists, false otherwise.

isAvailable

public boolean 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
  • 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.

返回:
true if the network is available, false otherwise

setIsAvailable

public void setIsAvailable(boolean isAvailable)
Sets if the network is available, ie, if the connectivity is possible.

参数:
isAvailable - the new availability value.

isFailover

public boolean isFailover()
Indicates whether the current attempt to connect to the network resulted from the ConnectivityManager trying to fail over to this network following a disconnect from another network.

返回:
true if this is a failover attempt, false otherwise.

setFailover

public void setFailover(boolean isFailover)
Set the failover boolean.

参数:
isFailover - true to mark the current connection attempt as a failover.

isRoaming

public boolean isRoaming()
Indicates whether the device is currently roaming on this network. When true, it suggests that use of data on this network may incur extra costs.

返回:
true if roaming is in effect, false otherwise.

getState

public NetworkInfo.State getState()
Reports the current coarse-grained state of the network.

返回:
the coarse-grained state

getDetailedState

public NetworkInfo.DetailedState getDetailedState()
Reports the current fine-grained state of the network.

返回:
the fine-grained state

getReason

public String getReason()
Report the reason an attempt to establish connectivity failed, if one is available.

返回:
the reason for failure, or null if not available

getExtraInfo

public String getExtraInfo()
Report the extra information about the network state, if any was provided by the lower networking layers., if one is available.

返回:
the extra information, or null if not available

toString

public String toString()
从类 Object 复制的描述
Returns a string containing a concise, human-readable description of this object. Subclasses are encouraged to override this method and provide an implementation that takes into account the object's type and data. The default implementation simply concatenates the class name, the '@' sign and a hexadecimal representation of the object's Object.hashCode(), that is, it is equivalent to the following expression:
 getClass().getName() + '@' + Integer.toHexString(hashCode()) 

覆盖:
类 Object 中的 toString
返回:
a printable representation of this object.

describeContents

public int describeContents()
Implement the Parcelable interface

指定者:
接口 Parcelable 中的 describeContents
返回:
a bitmask indicating the set of special object types marshalled by the Parcelable.

writeToParcel

public void writeToParcel(Parcel dest,                          int flags)
Implement the Parcelable interface.

指定者:
接口 Parcelable 中的 writeToParcel
参数:
dest - The Parcel in which the object should be written.
flags - Additional flags about how the object should be written.May be 0 or Parcelable.PARCELABLE_WRITE_RETURN_VALUE.

0 0
原创粉丝点击