Skip to content

Instantly share code, notes, and snippets.

@Pierry
Created November 22, 2014 17:41
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Pierry/48951570b23c42087112 to your computer and use it in GitHub Desktop.
Save Pierry/48951570b23c42087112 to your computer and use it in GitHub Desktop.
IsConnected class
public static boolean is(Context context) {
try {
ConnectivityManager cm = (ConnectivityManager) context.getSystemService(Context.CONNECTIVITY_SERVICE);
if (cm.getNetworkInfo(ConnectivityManager.TYPE_WIFI).isConnected()) {
return true;
} else if(cm.getNetworkInfo(ConnectivityManager.TYPE_MOBILE).isConnected()){
return true;
} else {
return false;
}
} catch (Exception e) {
return false;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment