Android Network State Check IsNetworkConnected(Context context)

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

Description

Is Network Connected

License

Open Source License

Declaration

public static Boolean IsNetworkConnected(Context context) 

Method Source Code

//package com.java2s;
//License from project: Open Source License 

import android.content.Context;
import android.net.ConnectivityManager;
import android.net.NetworkInfo;

public class Main {
    public static Boolean IsNetworkConnected(Context context) {
        ConnectivityManager manager = (ConnectivityManager) context
                .getSystemService(Context.CONNECTIVITY_SERVICE);
        NetworkInfo[] networks = manager.getAllNetworkInfo();
        for (NetworkInfo network : networks) {
            if (network.getTypeName().equalsIgnoreCase("WIFI")) {
                if (network.isConnected() && network.isAvailable()
                        && network.isConnectedOrConnecting()) {
                    return true;
                }/*from  w w w .  j  a  va 2s. com*/
            }
            if (network.getTypeName().equalsIgnoreCase("MOBILE")) {
                if (network.isConnected() && network.isAvailable()
                        && network.isConnectedOrConnecting()) {
                    return true;
                }
            }
        }
        return false;
    }
}

Related

  1. onNetwork(Context context)
  2. haveNetworkConnection(Context context)
  3. isNetworkConnected(Context context)
  4. isNetworkEnabled(Context context)
  5. check3GNetwork(Context context)
  6. isNetworkAvailableExt(Context paramContext)
  7. isNetworkAvailable(Context context)
  8. getNetworkState(Context context)
  9. isLocationEnabledNetwork(Context c)