CONNECTIVITY MANAGER CLASS.
A class that answers queries about the state of network connectivity and notifies applications when the network state change.
The responsibilities of this class are:
1. Monitor network connections (Wi-Fi, GPRS ,UMTC,...)
2.Send broadcast intent when network connectivity changes.
3.Attempt to connect to another network if the current network is lost.
4.Provide an API that allows applications to query state of available networks.
Context.getSystemService(Context.CONNECTIVITY_SERVICE) is called to get an instance of the Connectivity manager class.
PUBLIC METHODS IN THE CONNECTIVITY MANAGER CLASS.
- NetworkInfo getActiveNetworkInfo()
- NetworkInfo[] getAllNetworkInfo()
- NetworkInfo getNetworkInfo(int networkType)
- int getNetworkPreference()
- boolean isActiveNetworkMetered()
- static boolean isNetworkTypeValid(int networkType)
- boolean requestRouteToHost(int networkType, int hostAddress)
- void setNetworkPreference(int preference)
- int startUsingNetworkFeature(int networkType, String feature)
Tells the underlying networking system that the caller wants to begin using the named feature.
- int stopUsingNetworkFeature(int networkType, String feature)
CHECKING NETWORK AVAILABILITY SOURCE CODE.
private boolean isNetworkAvailable() {
ConnectivityManager connectivityManager = (ConnectivityManager) getSystemService(Context.CONNECTIVITY_SERVICE);
NetworkInfo activeNetworkInfo = connectivityManager.getActiveNetworkInfo();
return activeNetworkInfo != null && activeNetworkInfo.isConnected();
}