Skip to content

Instantly share code, notes, and snippets.

@arthtilva
Created June 3, 2016 17:07
Show Gist options
  • Save arthtilva/f5ab6893bb90b0c46a790b9af07193fa to your computer and use it in GitHub Desktop.
Save arthtilva/f5ab6893bb90b0c46a790b9af07193fa to your computer and use it in GitHub Desktop.
To check internet
public static boolean isConnectedToInternet(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