lperez lperez - 1 month ago 22
Android Question

Android NetworkInfo.State differences

I've been using the class NetworkInfo.State to know the status of the internet connection in my device, I wondered what exactly is the difference between NetworkInfo.State.CONNECTED and NetworkInfo.State.CONNECTING?

or between NetworkInfo.State.DISCONNECTING and NetworkInfo.State.DISCONNECTED

The official documentation does not say much about it.

In several examples use both, for example

if (conMgr.getNetworkInfo(0).getState() == NetworkInfo.State.CONNECTED
|| conMgr.getNetworkInfo(1).getState() == NetworkInfo.State.CONNECTING) {
//something.....
}


But I think there are two states for something in particular.

Answer

NetworkInfo.State.CONNECTING denotes if the network state is currently setting up data connection(like scanning, authenticating stuffs).

NetworkInfo.State.CONNECTED Voila! The network has successfully connected to a certain network and data traffic is now available.

NetworkInfo.State.DISCONNECTING is simply meaning that the data connection is now getting disconnected.

and NetworkInfo.State.DISCONNECTED means network is idle or unavailable or simply put, disconnected.