Example usage for android.net.wifi WifiManager isWifiEnabled

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

Introduction

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

Prototype

public boolean isWifiEnabled() 

Source Link

Document

Return whether Wi-Fi is enabled or disabled.

Usage

From source file:Main.java

public static boolean isWiFiActive(Context inContext) {
    WifiManager wm = null;
    try {//from  ww w. ja v  a2  s . c o m
        wm = (WifiManager) inContext.getSystemService(Context.WIFI_SERVICE);
    } catch (Exception e) {
        e.printStackTrace();
    }
    if (wm == null || wm.isWifiEnabled() == false)
        return false;
    return true;
}

From source file:Main.java

public static boolean isWiFiActive(Context context) {
    WifiManager wm = null;
    try {/*ww  w.j a v  a2 s. c  o  m*/
        wm = (WifiManager) context.getSystemService(Context.WIFI_SERVICE);
    } catch (Exception e) {
        e.printStackTrace();
    }

    if (wm == null || wm.isWifiEnabled() == false)
        return false;

    return true;
}

From source file:Main.java

public static boolean isNetworkPresent(Context context) {
    boolean isNetworkAvailable = false;
    if (context != null) {
        ConnectivityManager cm = (ConnectivityManager) context.getSystemService(Context.CONNECTIVITY_SERVICE);

        try {//from w  w w  .  j  av a  2  s . co m

            if (cm != null) {
                NetworkInfo netInfo = cm.getActiveNetworkInfo();
                if (netInfo != null) {

                    isNetworkAvailable = netInfo.isConnected();
                    //                    Toast.makeText(context, "Connecting...", Toast.LENGTH_SHORT).show();
                    //Log.d("NETWORK<<","Connecting...."+netInfo.getReason());
                }
            }
        } catch (Exception ex) {
            //Log.e("Network Avail Error", ex.getMessage());

        }
        //        check for wifi also
        if (!isNetworkAvailable) {

            WifiManager connec = (WifiManager) context.getSystemService(Context.WIFI_SERVICE);

            State wifi = cm.getNetworkInfo(1).getState();
            if (connec.isWifiEnabled() && wifi.toString().equalsIgnoreCase("CONNECTED")) {
                isNetworkAvailable = true;
                //Log.d("WIFI NETWORK<<","WIFI connected");
            } else {

                isNetworkAvailable = false;
                // Log.d("WIFI Network<<","WIFI not connected");
            }

        }
    }

    return isNetworkAvailable;

}

From source file:Main.java

public static boolean isWiFiActive(Context inContext) {
    WifiManager mWifiManager = (WifiManager) inContext.getSystemService(Context.WIFI_SERVICE);
    WifiInfo wifiInfo = mWifiManager.getConnectionInfo();
    int ipAddress = wifiInfo == null ? 0 : wifiInfo.getIpAddress();
    if (mWifiManager.isWifiEnabled() && ipAddress != 0) {
        System.out.println("**** WIFI is on");
        return true;
    } else {/*from  www .j  av  a2s.  com*/
        System.out.println("**** WIFI is off");
        return false;
    }
}

From source file:org.wahtod.wififixer.ui.StatusFragment.java

private static WifiInfo getNetwork(Context context) {
    WifiManager wm = AsyncWifiManager.getWifiManager(context);
    if (wm.isWifiEnabled()) {
        return wm.getConnectionInfo();
    } else//w ww .j a  v a2s .  c o m
        return null;
}

From source file:com.conferenceengineer.android.iosched.util.WiFiUtils.java

/**
 * Helper method to decide whether to bypass conference WiFi setup.  Return true if
 * WiFi AP is already configured (WiFi adapter enabled) or WiFi configuration is complete
 * as per shared preference.//from  w  w  w  .java  2 s  . c om
 */
public static boolean shouldBypassWiFiSetup(final Context context) {
    final WifiManager wifiManager = (WifiManager) context.getSystemService(Context.WIFI_SERVICE);

    // Is WiFi on?
    if (wifiManager.isWifiEnabled()) {
        // Check for existing APs.
        final List<WifiConfiguration> configs = wifiManager.getConfiguredNetworks();
        final String conferenceSSID = String.format("\"%s\"", Config.WIFI_SSID);
        for (WifiConfiguration config : configs) {
            if (conferenceSSID.equalsIgnoreCase(config.SSID))
                return true;
        }
    }

    return WIFI_CONFIG_DONE.equals(getWiFiConfigStatus(context));
}

From source file:ca.frozen.curlingtv.classes.Utils.java

public static String getWifiName() {
    String ssid = "";
    WifiManager manager = (WifiManager) App.getContext().getSystemService(Context.WIFI_SERVICE);
    if (manager.isWifiEnabled()) {
        WifiInfo wifiInfo = manager.getConnectionInfo();
        if (wifiInfo != null) {
            NetworkInfo.DetailedState state = WifiInfo.getDetailedStateOf(wifiInfo.getSupplicantState());
            if (state == NetworkInfo.DetailedState.CONNECTED
                    || state == NetworkInfo.DetailedState.OBTAINING_IPADDR) {
                ssid = wifiInfo.getSSID();
                if (ssid == null)
                    ssid = "";
                ssid = ssid.replaceAll("^\"|\"$", "");
            }/*w w w  .  ja  v  a2  s .  c  o  m*/
        }
    }
    return ssid;
}

From source file:org.openremote.android.console.net.ORNetworkCheck.java

/**
 * Detects the current WiFi status./*from www .j  av  a2  s.  c  o m*/
 *
 * @param ctx     global Android application context
 *
 * @return true if WiFi is available, false otherwise
 */
private static boolean canReachWifiNetwork(Context ctx) {

    WifiManager wifiManager = (WifiManager) ctx.getSystemService(Context.WIFI_SERVICE);
    ConnectivityManager connectivityManager = (ConnectivityManager) ctx
            .getSystemService(Context.CONNECTIVITY_SERVICE);

    if (!wifiManager.isWifiEnabled() || wifiManager.getWifiState() != WifiManager.WIFI_STATE_ENABLED) {
        Log.i(LOG_CATEGORY, "WiFi not enabled or WiFi network not detected.");

        return false;
    }

    NetworkInfo wifiNetworkInfo = connectivityManager.getNetworkInfo(ConnectivityManager.TYPE_WIFI);

    if (!wifiNetworkInfo.isAvailable()) {
        Log.i(LOG_CATEGORY, "Wifi network detected but wasn't available.");

        return false;
    }

    else {
        return true;
    }
}

From source file:org.basdroid.common.NetworkUtils.java

/**
 * check if enable wifi device/*from   w  w  w  .java 2  s  . c om*/
 * @param context
 * @return
 */
public static boolean isWifiEnabled(Context context) {
    WifiManager wifiManager = (WifiManager) context.getSystemService(Context.WIFI_SERVICE);
    return wifiManager.isWifiEnabled();
}

From source file:org.basdroid.common.NetworkUtils.java

/**
 * enable wifi device//from w w  w . j a va 2s  .co  m
 * @param context
 */
public static void enableWifiNetwork(Context context) {
    WifiManager wifiManager = (WifiManager) context.getSystemService(Context.WIFI_SERVICE);
    if (wifiManager.isWifiEnabled()) {
        // WIFI ALREADY ENABLED. GRAB THE MAC ADDRESS HERE
        Log.d(TAG, "WIFI ALREADY ENABLED.");
    } else {
        // ENABLE THE WIFI FIRST
        Log.d(TAG, "WIFI DISABLED. ENABLE THE WIFI FIRST");
        wifiManager.setWifiEnabled(true);
    }

    return;
}