Some applications need
Internet connectivity to run it. That's why Developer needs to check whether
Internet connection is there or not? If yes, then one can do task otherwise
need to alert user to connect his Smart Phone or Tablet to Internet.
I searched and found this
code be useful to check Internet Connectivity.
/**
* This method
will check whether Phone/Tablet has Internet connection or
* not
*
* @param
context
* :
Context
* @return
<b>True</b>
: If Internet is Connected<br>
*
<b>False</b>
: If Internet is not Connected
*/
public
static boolean checkNetworkConnectivity(Context
context) {
ConnectivityManager
connMgr = (ConnectivityManager) context
.getSystemService(Context.CONNECTIVITY_SERVICE);
/**
* check for
Wi-Fi and mobile Internet connection
*/
if
(connMgr.getNetworkInfo(ConnectivityManager.TYPE_WIFI).isConnected()
||
connMgr.getNetworkInfo(ConnectivityManager.TYPE_MOBILE)
.isConnected()) {
/**
* Internet
connected
*/
return
true;
}
/**
* no connection
*/
return
false;
}