Skip to content

Instantly share code, notes, and snippets.

@danilao
Created November 22, 2012 20:37
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save danilao/4132844 to your computer and use it in GitHub Desktop.
Save danilao/4132844 to your computer and use it in GitHub Desktop.
Check network connection in Android
public boolean isOnline() {
ConnectivityManager cm = (ConnectivityManager) getSystemService(Context.CONNECTIVITY_SERVICE);
NetworkInfo netInfo = cm.getActiveNetworkInfo();
if (netInfo != null && netInfo.isConnectedOrConnecting()) {
return true;
}
Toast .makeText ( this, "Please, check your network connection" , Toast.LENGTH_LONG ).show();
return false;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment