Android Network State Check hasNoConnectivity(Application application)

Here you can find the source of hasNoConnectivity(Application application)

Description

has No Connectivity

Declaration

static public boolean hasNoConnectivity(Application application) 

Method Source Code

//package com.java2s;
import android.app.Application;
import android.content.Context;
import android.net.ConnectivityManager;
import android.net.NetworkInfo;

public class Main {
    static public boolean hasNoConnectivity(Application application) {
        return !hasConnectivity(application);
    }//from ww  w .  ja  v a 2 s  . c  om

    static public boolean hasConnectivity(Application application) {
        // TODO - refactor to XMPPConnector
        ConnectivityManager cm = (ConnectivityManager) application
                .getSystemService(Context.CONNECTIVITY_SERVICE);

        NetworkInfo wifiNetwork = cm
                .getNetworkInfo(ConnectivityManager.TYPE_WIFI);
        if (wifiNetwork != null && wifiNetwork.isConnected()) {
            return true;
        }

        NetworkInfo mobileNetwork = cm
                .getNetworkInfo(ConnectivityManager.TYPE_MOBILE);
        if (mobileNetwork != null && mobileNetwork.isConnected()) {
            return true;
        }

        NetworkInfo activeNetwork = cm.getActiveNetworkInfo();
        if (activeNetwork != null && activeNetwork.isConnected()) {
            return true;
        }

        return false;
    }
}

Related

  1. hasConnectivity(Application application)
  2. hasConnectivity(final Context context, final int... networkTypes)
  3. hasConnectivity(final NetworkInfo info)
  4. hasInternetAvailable(Context context)
  5. hasMobileConnectivity(Context context)
  6. isConnected(Context context)
  7. isConnected(Context context)
  8. isConnected(Context context)
  9. isConnected(NetworkInfo info)