Created
October 16, 2014 09:30
-
-
Save a7madev/427694dcae675435ce53 to your computer and use it in GitHub Desktop.
Android - Check Internet Connection
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
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