Example usage for android.net.wifi WifiManager getWifiState

List of usage examples for android.net.wifi WifiManager getWifiState

Introduction

In this page you can find the example usage for android.net.wifi WifiManager getWifiState.

Prototype

public int getWifiState() 

Source Link

Document

Gets the Wi-Fi enabled state.

Usage

From source file:Main.java

public static boolean isWifiDisabled(WifiManager wifi) {
    return wifi.getWifiState() == WifiManager.WIFI_STATE_DISABLED;
}

From source file:Main.java

public static boolean isWifiEnabled(WifiManager wifi) {
    return wifi.getWifiState() == WifiManager.WIFI_STATE_ENABLED;
}

From source file:Main.java

public static boolean isWifiEnabledOrEnabling(WifiManager wifi) {
    int wifiState = wifi.getWifiState();
    return wifiState == WifiManager.WIFI_STATE_ENABLED || wifiState == WifiManager.WIFI_STATE_ENABLING;
}

From source file:Main.java

public static boolean isWifiEnable(Activity activitiy) {

    WifiManager wm = (WifiManager) activitiy.getSystemService(Context.WIFI_SERVICE);

    return wm.getWifiState() == WifiManager.WIFI_STATE_ENABLED;

}

From source file:Main.java

public static boolean isEnabledWifi(Context context) {
    WifiManager wifiMan = (WifiManager) context.getSystemService(Context.WIFI_SERVICE);
    return null != wifiMan && wifiMan.getWifiState() == WifiManager.WIFI_STATE_ENABLED;
}

From source file:Main.java

/**
 * Determines if the device's wifi is currently enabled or not.
 * /*from   ww  w. j ava  2  s .  c o m*/
 * @param context A context with which to access wifi system service
 * @return True if wifi is enabled or enabling, false otherwise
 */
public static boolean wifiIsEnabled(ContextWrapper context) {
    WifiManager wifiManager = (WifiManager) context.getSystemService(Context.WIFI_SERVICE);
    int wifiState = wifiManager.getWifiState();
    return (wifiState == WifiManager.WIFI_STATE_ENABLED || wifiState == WifiManager.WIFI_STATE_ENABLING);
}

From source file:Main.java

public static int getWifiState(Context context) {
    WifiManager wifiManager = (WifiManager) context.getSystemService(Context.WIFI_SERVICE);
    if (wifiManager != null) {
        return wifiManager.getWifiState();
    }/*from w  w w  .  ja  v  a  2 s  . co m*/
    return WifiManager.WIFI_STATE_DISABLED;
}

From source file:Main.java

public static int getWifiState(Context context) throws Exception {
    WifiManager wifiManager = (WifiManager) context.getSystemService(Context.WIFI_SERVICE);
    if (wifiManager != null) {
        return wifiManager.getWifiState();
    } else {//from  w  ww. j  a  v a2 s .co m
        throw new Exception("wifi device not found!");
    }
}

From source file:Main.java

public static boolean isWifiEnable(Context context) {
    WifiManager mgr = (WifiManager) context.getSystemService(Context.WIFI_SERVICE);
    if (mgr == null)
        return false;
    int state = mgr.getWifiState();
    return state == WifiManager.WIFI_STATE_ENABLED || state == WifiManager.WIFI_STATE_ENABLING;
}

From source file:Main.java

public static void toggleWifi(Context context) {
    WifiManager wifi_manager = (WifiManager) context.getSystemService(Context.WIFI_SERVICE);
    if (wifi_manager != null) {
        switch (wifi_manager.getWifiState()) {
        case WifiManager.WIFI_STATE_DISABLED:
            wifi_manager.setWifiEnabled(true);
            break;
        case WifiManager.WIFI_STATE_ENABLED:
            wifi_manager.setWifiEnabled(false);
            break;
        }/*from w  w  w . j a  v  a2 s  . c o m*/
    }
}