Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save codeswimmer/894775 to your computer and use it in GitHub Desktop.
Save codeswimmer/894775 to your computer and use it in GitHub Desktop.
Android: determine if the device currently has any network connectivity (mobile internet or wifi).
public static final boolean hasNetworkConnectivity(Context context) {
ConnectivityManager connectivityManager = (ConnectivityManager) context.getSystemService(Context.CONNECTIVITY_SERVICE);
NetworkInfo wifi = connectivityManager.getNetworkInfo(ConnectivityManager.TYPE_WIFI);
NetworkInfo mobile = connectivityManager.getNetworkInfo(ConnectivityManager.TYPE_MOBILE);
return (wifi.isAvailable() || mobile.isAvailable())
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment