Skip to content

Instantly share code, notes, and snippets.

@swarawan
Created March 13, 2018 12:51
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 swarawan/bb6a621b924e4bfe521b24e718bb74aa to your computer and use it in GitHub Desktop.
Save swarawan/bb6a621b924e4bfe521b24e718bb74aa to your computer and use it in GitHub Desktop.
Use this class to check connection availability
public class NetworkUtils {
private static boolean isConnected;
public NetworkUtils(Context context) {
ConnectivityManager connectivityManager = (ConnectivityManager) context.getSystemService(Context.CONNECTIVITY_SERVICE);
if (connectivityManager == null) return;
NetworkInfo networkInfo = connectivityManager.getActiveNetworkInfo();
if (networkInfo == null) return;
isConnected = networkInfo.isConnected();
}
public boolean isConnected() {
return isConnected;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment