Skip to content

Instantly share code, notes, and snippets.

@a7madev
Created October 16, 2014 09:30
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 a7madev/427694dcae675435ce53 to your computer and use it in GitHub Desktop.
Save a7madev/427694dcae675435ce53 to your computer and use it in GitHub Desktop.
Android - Check Internet Connection
private boolean checkForInternetConnection() {
Boolean internetIsAvailable = false;
//check for internet connection
try {
ConnectivityManager connectivityManager = (ConnectivityManager) getSystemService(Context.CONNECTIVITY_SERVICE);
activeNetworkInfo = connectivityManager.getActiveNetworkInfo();
} catch (Exception e) {
Log.d(TAG, "checkForInternetConnection Exception", e);
}
//validate internet connection
if (activeNetworkInfo != null && activeNetworkInfo.isConnected() && activeNetworkInfo.isAvailable()) {
internetIsAvailable = true;
}
return internetIsAvailable;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment