Skip to content

Instantly share code, notes, and snippets.

@reflog
Created June 24, 2010 15:23
Show Gist options
  • Save reflog/451576 to your computer and use it in GitHub Desktop.
Save reflog/451576 to your computer and use it in GitHub Desktop.
public boolean isNetworkAvailable() {
Context context = getApplicationContext();
ConnectivityManager connectivity = (ConnectivityManager) context.getSystemService(Context.CONNECTIVITY_SERVICE);
if (connectivity == null) {
return true;
} else {
NetworkInfo[] info = connectivity.getAllNetworkInfo();
if (info != null) {
for (int i = 0; i < info.length; i++) {
if (info[i].getState() == NetworkInfo.State.CONNECTED) {
return true;
}
}
}
}
return false;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment