Android Network State Check haveNetworkConnection(Context context)

Here you can find the source of haveNetworkConnection(Context context)

Description

have Network Connection

Declaration

private static boolean haveNetworkConnection(Context context) 

Method Source Code

//package com.java2s;

import android.content.Context;

import android.net.ConnectivityManager;
import android.net.NetworkInfo;

public class Main {
    private static boolean haveNetworkConnection(Context context) {
        boolean haveConnectedWifi = false;
        boolean haveConnectedMobile = false;

        ConnectivityManager cm = (ConnectivityManager) context
                .getSystemService(Context.CONNECTIVITY_SERVICE);
        NetworkInfo[] netInfo = cm.getAllNetworkInfo();
        for (NetworkInfo ni : netInfo) {
            if (ni.getTypeName().equalsIgnoreCase("WIFI"))
                if (ni.isConnected())
                    haveConnectedWifi = true;
            if (ni.getTypeName().equalsIgnoreCase("MOBILE"))
                if (ni.isConnected())
                    haveConnectedMobile = true;
        }/*from   ww w . j  a  va 2 s. c om*/
        return haveConnectedWifi || haveConnectedMobile;
    }
}

Related

  1. isMobileConnected(Context context)
  2. isNetworkConnected(Context context)
  3. isNetworkAvailable(Context context)
  4. isNetworkConnected(Context context)
  5. onNetwork(Context context)
  6. isNetworkConnected(Context context)
  7. isNetworkEnabled(Context context)
  8. check3GNetwork(Context context)
  9. IsNetworkConnected(Context context)