Skip to content

Instantly share code, notes, and snippets.

@hanigamal
Created June 2, 2012 13:25
Show Gist options
  • Save hanigamal/2858431 to your computer and use it in GitHub Desktop.
Save hanigamal/2858431 to your computer and use it in GitHub Desktop.
Network Availability
public boolean isNetworkAvailable() {
Context context = getApplicationContext();
ConnectivityManager connectivity = (ConnectivityManager) context.getSystemService(Context.CONNECTIVITY_SERVICE);
if (connectivity == null) {
boitealerte(this.getString(R.string.alert),"getSystemService rend null");
} 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