Android Wifi State Check getWifiState(Context context)

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

Description

get Wifi State

Declaration

public static boolean getWifiState(Context context) 

Method Source Code

//package com.java2s;

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

import android.net.NetworkInfo.State;

public class Main {
    public static boolean getWifiState(Context context) {
        ConnectivityManager cm = (ConnectivityManager) context
                .getSystemService(Context.CONNECTIVITY_SERVICE);
        State wifistate = cm.getNetworkInfo(ConnectivityManager.TYPE_WIFI)
                .getState();/*from   ww  w  . j a v  a2 s.  c o  m*/
        if (wifistate != State.CONNECTED) {
            return false;
        }

        State mobileState = cm.getNetworkInfo(
                ConnectivityManager.TYPE_MOBILE).getState();
        boolean ret = State.CONNECTED != mobileState;
        return ret;
    }
}

Related

  1. isConnectedWifi(Context context)
  2. isConnectedWifi(Context context)
  3. isWifiAvailable(Context context)
  4. isWifiDisabled(WifiManager wifi)