public class

NetworkInfo

extends Object
implements Parcelable
java.lang.Object
   ↳ android.net.NetworkInfo

Class Overview

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

Summary

Nested Classes
public class NetworkInfo.DetailedState The fine-grained state of a network connection. 
public class NetworkInfo.State Coarse-grained network state. 
[Expand]
Inherited Constants
From interface android.os.Parcelable
Public Methods
NetworkInfo.DetailedState getDetailedState()
Reports the current fine-grained state of the network.
String getExtraInfo()
Report the extra information about the network state, if any was provided by the lower networking layers., if one is available.
String getReason()
Report the reason an attempt to establish connectivity failed, if one is available.
NetworkInfo.State getState()
Reports the current coarse-grained state of the network.
int getSubtype()
Return a network-type-specific integer describing the subtype of the network.
String getSubtypeName()
Return a human-readable name describing the subtype of the network.
int getType()
Reports the type of network (currently mobile or Wi-Fi) to which the info in this object pertains.
String getTypeName()
Return a human-readable name describe the type of the network, for example "WIFI" or "MOBILE".
boolean isAvailable()
Indicates whether network connectivity is possible.
boolean isConnected()
Indicates whether network connectivity exists and it is possible to establish connections and pass data.
boolean isConnectedOrConnecting()
Indicates whether network connectivity exists or is in the process of being established.
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.
boolean isRoaming()
Indicates whether the device is currently roaming on this network.
String toString()
Returns a string containing a concise, human-readable description of this object.
[Expand]
Inherited Methods
From class java.lang.Object
From interface android.os.Parcelable

Public Methods

public NetworkInfo.DetailedState getDetailedState ()

Reports the current fine-grained state of the network.

Returns
  • the fine-grained state

public String getExtraInfo ()

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

Returns
  • the extra information, or null if not available

public String getReason ()

Report the reason an attempt to establish connectivity failed, if one is available.

Returns
  • the reason for failure, or null if not available

public NetworkInfo.State getState ()

Reports the current coarse-grained state of the network.

Returns
  • the coarse-grained state

public int getSubtype ()

Return a network-type-specific integer describing the subtype of the network.

Returns
  • the network subtype

public String getSubtypeName ()

Return a human-readable name describing the subtype of the network.

Returns
  • the name of the network subtype

public int getType ()

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

Returns
  • the network type

public String getTypeName ()

Return a human-readable name describe the type of the network, for example "WIFI" or "MOBILE".

Returns
  • the name of the network type

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.

Returns
  • true if the network is available, false otherwise

public boolean isConnected ()

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

Returns
  • true if network connectivity exists, false otherwise.

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.

Returns
  • true if network connectivity exists or is in the process of being established, false otherwise.

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.

Returns
  • true if this is a failover attempt, false otherwise.

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.

Returns
  • true if roaming is in effect, false otherwise.

public String toString ()

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 hashCode(), that is, it is equivalent to the following expression:

 getClass().getName() + '@' + Integer.toHexString(hashCode())
 

Returns
  • a printable representation of this object.