I want to display a message for user if he is out of internet availability. I am using the following snippet of code but its showing exception even in the case of network availability.
What I am doing wrong?
public boolean isInternetAvailable(){
ConnectivityManager cm = (ConnectivityManager) getSystemService(Context.CONNECTIVITY_SERVICE);
NetworkInfo netInfo = cm.getActiveNetworkInfo();
if (netInfo != null && netInfo.isConnectedOrConnecting()) {
return true;
}
return false;
}