Use this code to check the internet connection
ConnectivityManager connectivityManager = (ConnectivityManager) ctx
.getSystemService(Context.CONNECTIVITY_SERVICE);
if ((connectivityManager
.getNetworkInfo(ConnectivityManager.TYPE_MOBILE) != null && connectivityManager
.getNetworkInfo(ConnectivityManager.TYPE_MOBILE).getState() == NetworkInfo.State.CONNECTED)
|| (connectivityManager
.getNetworkInfo(ConnectivityManager.TYPE_WIFI) != null && connectivityManager
.getNetworkInfo(ConnectivityManager.TYPE_WIFI)
.getState() == NetworkInfo.State.CONNECTED)) {
return true;
} else {
return false;
}