Here is code snippet. It returns true if network enable ,else false
private boolean netCheckin() {
try {
ConnectivityManager nInfo = (ConnectivityManager) getSystemService(
Context.CONNECTIVITY_SERVICE);
nInfo.getActiveNetworkInfo().isConnectedOrConnecting();
Log.d(tag, "Net avail:"
+ nInfo.getActiveNetworkInfo().isConnectedOrConnecting());
ConnectivityManager cm = (ConnectivityManager) getSystemService(
Context.CONNECTIVITY_SERVICE);
NetworkInfo netInfo = cm.getActiveNetworkInfo();
if (netInfo != null && netInfo.isConnectedOrConnecting()) {
Log.d(tag, "Network available:true");
return true;
} else {
Log.d(tag, "Network available:false");
return false;
}
} catch (Exception e) {
return false;
}
}
getActiveNetworkInfo()
ANDisConnectedOrConnecting()
3 times ! – Hayott