We know that Its not possible that our android device should be always connected with a network.
It might be a situation when we would not connected with any network, So to check it whether we are connected with any network or not.
We check it by using ConnectivityManager class and get network information by NetworkInfo.
We need to add this permission in manifest file : ACCESS_NETWORK_STATE
Here if nInfo returns null that means there is no network. And that is not null then we just check the connectivity.
This is the simple code/method for it.