Created
November 22, 2012 20:37
-
-
Save danilao/4132844 to your computer and use it in GitHub Desktop.
Check network connection in Android
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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