Last active
August 29, 2015 13:57
-
-
Save jcordeiro/9771734 to your computer and use it in GitHub Desktop.
A method to determine whether or not an Android device has network connectivity
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 isNetworkConnected() { | |
// get Connectivity Manager to get network status | |
ConnectivityManager connMgr = (ConnectivityManager) | |
getSystemService(Context.CONNECTIVITY_SERVICE); | |
NetworkInfo networkInfo = connMgr.getActiveNetworkInfo(); | |
if (networkInfo != null && networkInfo.isConnected()) { | |
return true; //we have a connection | |
} else { | |
return false; // no connection! | |
} | |
} | |
/* Make Sure you add these permissions to your Android manifest | |
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE"/> | |
<uses-permission android:name="android.permission.INTERNET"/> | |
*/ |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment