How to check server connection is available or not in android
Posted
by
Kalai Selvan.G
on Stack Overflow
See other posts from Stack Overflow
or by Kalai Selvan.G
Published on 2012-03-31T11:04:34Z
Indexed on
2012/03/31
11:29 UTC
Read the original article
Hit count: 451
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!!
© Stack Overflow or respective owner