Android Network State Check checkNetState(Context context)

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

Description

check Net State

Declaration

public static boolean checkNetState(Context context) 

Method Source Code

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

public class Main {
    public static boolean checkNetState(Context context) {
        boolean netstate = false;
        ConnectivityManager connectivity = (ConnectivityManager) context
                .getSystemService(Context.CONNECTIVITY_SERVICE);
        if (connectivity != null) {
            NetworkInfo[] info = connectivity.getAllNetworkInfo();
            if (info != null) {
                for (int i = 0; i < info.length; i++) {
                    if (info[i].getState() == NetworkInfo.State.CONNECTED) {
                        netstate = true;
                        break;
                    }//from   w  w  w . ja  v a2  s . com
                }
            }
        }
        return netstate;
    }
}

Related

  1. checkNetWorkStatus(Context context)
  2. checkNetworkState(Context context)
  3. getMobileState(Context context)
  4. hasConnectivity(Application application)