How to check server connection is available or not in android
- by Kalai Selvan.G
Testing of Network Connection can be done by following method:
public boolean isNetworkAvailable()
{
ConnectivityManager cm = (ConnectivityManager) getSystemService(Context.CONNECTIVITY_SERVICE);
NetworkInfo networkInfo = cm.getActiveNetworkInfo();
if (networkInfo != null && networkInfo.isConnected())
{
return true;
}
return false;
}
But i don't know how to check the server connection.I had followed this method
public boolean isConnectedToServer(String url, long timeout) {
try{
URL myUrl = new URL(url);
URLConnection connection = myUrl.openConnection();
connection.setConnectTimetout(timeout);
connection.connect();
return true;
} catch (Exception e) {
// Handle your exceptions
return false;
}
}
it doesn't works....Any Ideas Guys!!