Skip to content

Instantly share code, notes, and snippets.

@danielgomezrico
Created September 19, 2014 02:00
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save danielgomezrico/6c1342047156db8e6ff8 to your computer and use it in GitHub Desktop.
Save danielgomezrico/6c1342047156db8e6ff8 to your computer and use it in GitHub Desktop.
Check internet connection on Android
public class InternetHelper {
public static boolean isConnectingToInternet(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