I am trying to check internet connection of device first, if Internet is available...I need to check server is online or not. I have searched lot of in stackflow for it but there no where latest solution is available like below
but none of it is working properly as people comments and my trial. I am checking internet status of device with below code
public static boolean isInternetAvailable(Context context) {
ConnectivityManager connectivity = (ConnectivityManager) context
.getSystemService(Context.CONNECTIVITY_SERVICE);
boolean isActiveNetworkConnected = false;
if (connectivity != null) {
NetworkInfo info = connectivity.getActiveNetworkInfo();
if (info != null) {
if (info.getState() == NetworkInfo.State.CONNECTED) {
isActiveNetworkConnected = true;
} else {
isActiveNetworkConnected = false;
}
}
} else {
isActiveNetworkConnected = false;
}
return isActiveNetworkConnected;
}
Let me know anyone have proper solution which can check server available or not with this code.