Most simplest and easy way is: ping to any server like here. I ping to google, check whether a response is empty or no ;) ... This function call within android activity, when you have a doubt regard connectivity.
public void GET(){
String result = "";
HttpResponse response;
HttpEntity entity;
try {
HttpPost httppost = new HttpPost("http://google.com");
DefaultHttpClient httpclient = getHttpClientImpl();
response = httpclient.execute(httppost);
entity = response.getEntity();
if (entity != null) {
InputStream is = entity.getContent();
if (is != null) {
StringBuilder sb = new StringBuilder();
String line;
try {
BufferedReader reader = new BufferedReader(
new InputStreamReader(is, "UTF-8"), 8 * 1024);
while ((line = reader.readLine()) != null) {
sb.append(line);// .append("\n");
}
} catch (Exception e) {
e.printStackTrace();
} finally {
is.close();
}
result = sb.toString();
if (responseXML.equals("")){
// Internet connectivity is lost.
}else {
// Internet connectivity still here xnjoy.
}
}
entity.consumeContent();
}
httpclient.getConnectionManager().shutdown();
} catch (Exception e) {
Log.d("InputStream", e.getLocalizedMessage());
}
}