Skip to content

Instantly share code, notes, and snippets.

What would you like to do?
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