Skip to content

Instantly share code, notes, and snippets.

@talhahasanzia
Created June 30, 2016 07:03
Show Gist options
  • Save talhahasanzia/c205bd7a477ca245d0797f33ace050d5 to your computer and use it in GitHub Desktop.
Save talhahasanzia/c205bd7a477ca245d0797f33ace050d5 to your computer and use it in GitHub Desktop.
Check internet connection. This will check internet connection status, not actual connection response from a server.
private boolean isNetworkAvailable() {
ConnectivityManager connectivityManager
= (ConnectivityManager) context.getSystemService(Context.CONNECTIVITY_SERVICE);
NetworkInfo activeNetworkInfo = connectivityManager.getActiveNetworkInfo();
return activeNetworkInfo != null && activeNetworkInfo.isConnected();
}
@talhahasanzia
Copy link
Author

This will check internet connection status, not actual connection response from a server. To check actual response from internet, create asyncTask and try to connect to a website.
Needs permission: ACCESS_NETWORK_STATE

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment