private boolean isNetworkConnected()
{
ConnectivityManager cm = (ConnectivityManager) getSystemService(Context.CONNECTIVITY_SERVICE);
NetworkInfo ni = cm.getActiveNetworkInfo();
if (ni == null)
{
//There are no active networks. return false;
}
else
{
return true;
}
}
The above function will return true only if the device has internet connection otherwise false.
manifest file permissions,
<uses-permission android:name="android.permission.ACCESS_WIFI_STATE" />
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />