Skip to content

Instantly share code, notes, and snippets.

@hu2di
Created April 10, 2017 02:48
Show Gist options
  • Save hu2di/2f8bc69df9c6b23516d804f6587bdc2c to your computer and use it in GitHub Desktop.
Save hu2di/2f8bc69df9c6b23516d804f6587bdc2c to your computer and use it in GitHub Desktop.
Android: Check connection
public static boolean isInternetConnection(Context context) {
ConnectivityManager connectivity = (ConnectivityManager) context.getSystemService(Context.CONNECTIVITY_SERVICE);
if (connectivity != null) {
NetworkInfo[] info = connectivity.getAllNetworkInfo();
if (info != null)
for (int i = 0; i < info.length; i++)
if (info[i].getState() == NetworkInfo.State.CONNECTED) {
return true;
}
}
return false;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment