Skip to content

Most visited

Recently visited

navigation
Added in API level 1

NetworkInfo

public class NetworkInfo
extends Object implements Parcelable

java.lang.Object
   ↳ android.net.NetworkInfo


Describes the status of a network interface.

Use getActiveNetworkInfo() to get an instance that represents the current network connection.

Summary

Nested classes

enum NetworkInfo.DetailedState

The fine-grained state of a network connection. 

enum NetworkInfo.State

Coarse-grained network state. 

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.

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 to which the info in this NetworkInfo 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.

Inherited methods

From class java.lang.Object
From interface android.os.Parcelable

Public methods

getDetailedState

Added in API level 1
NetworkInfo.DetailedState getDetailedState ()

Reports the current fine-grained state of the network.

Returns
NetworkInfo.DetailedState the fine-grained state

getExtraInfo

Added in API level 1
String getExtraInfo ()

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

Returns
String the extra information, or null if not available

getReason

Added in API level 1
String getReason ()

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

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

getState

Added in API level 1
NetworkInfo.State getState ()

Reports the current coarse-grained state of the network.

Returns
NetworkInfo.State the coarse-grained state

getSubtype

Added in API level 3
int getSubtype ()

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

Returns
int the network subtype

getSubtypeName

Added in API level 3
String getSubtypeName ()

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

Returns
String the name of the network subtype

getType

Added in API level 1
int getType ()

Reports the type of network to which the info in this NetworkInfo pertains.

Returns
int one of TYPE_MOBILE, TYPE_WIFI, TYPE_WIMAX, TYPE_ETHERNET, TYPE_BLUETOOTH, or other types defined by ConnectivityManager

getTypeName

Added in API level 1
String getTypeName ()

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

Returns
String the name of the network type

isAvailable

Added in API level 1
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
boolean true if the network is available, false otherwise

isConnected

Added in API level 1
boolean 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.

Returns
boolean true if network connectivity exists, false otherwise.

isConnectedOrConnecting

Added in API level 1
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
boolean true if network connectivity exists or is in the process of being established, false otherwise.

isFailover

Added in API level 1
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
boolean true if this is a failover attempt, false otherwise.

isRoaming

Added in API level 3
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
boolean true if roaming is in effect, false otherwise.

toString

Added in API level 1
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 is equivalent to the following expression:

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

See Writing a useful toString method if you intend implementing your own toString method.

Returns
String a printable representation of this object.
This site uses cookies to store your preferences for site-specific language and display options.

Hooray!

This class requires API level or higher

This doc is hidden because your selected API level for the documentation is . You can change the documentation API level with the selector above the left navigation.

For more information about specifying the API level your app requires, read Supporting Different Platform Versions.