Skip to content

Instantly share code, notes, and snippets.

@webkader
Created July 13, 2015 18:51
Show Gist options
  • Save webkader/dac56b234668f0f57bdf to your computer and use it in GitHub Desktop.
Save webkader/dac56b234668f0f57bdf to your computer and use it in GitHub Desktop.
Check network is available in Android
/**
* isNetworkAvailable() TRUE wenn eine Datenverbindung vorhanden ist
*
* @param mixed activity
* @return
*/
public static boolean isNetworkAvailable(Activity activity) {
ConnectivityManager connectivity = (ConnectivityManager) activity.getSystemService(Context.CONNECTIVITY_SERVICE);
if (connectivity == null) {
return false;
} 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