Skip to content

Instantly share code, notes, and snippets.

@j-onathan
Created August 24, 2014 17:20
Show Gist options
  • Save j-onathan/a957ac5632c00e8671ef to your computer and use it in GitHub Desktop.
Save j-onathan/a957ac5632c00e8671ef to your computer and use it in GitHub Desktop.
public static boolean haveNetworkConnection(Context context) {
ConnectivityManager cm = (ConnectivityManager)context.getSystemService(Context.CONNECTIVITY_SERVICE);
NetworkInfo activeNetwork = cm.getActiveNetworkInfo();
if(activeNetwork == null) return false;
return activeNetwork.isConnected();
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment