Skip to content

Instantly share code, notes, and snippets.

@msomu
Created December 4, 2014 11:31
Show Gist options
  • Select an option

  • Save msomu/9ff7a5830cbb61dde11b to your computer and use it in GitHub Desktop.

Select an option

Save msomu/9ff7a5830cbb61dde11b to your computer and use it in GitHub Desktop.
To check the internet connections on the android
/*
* @return boolean return true if the application can access the internet
*/
private boolean haveInternet(){
NetworkInfo info = ((ConnectivityManager)getSystemService(Context.CONNECTIVITY_SERVICE)).getActiveNetworkInfo();
if (info==null || !info.isConnected()) {
return false;
}
if (info.isRoaming()) {
// here is the roaming option you can change it if you want to disable internet while roaming, just return false
return true;
}
return true;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment