Example usage for android.net ConnectivityManager TYPE_WIFI

List of usage examples for android.net ConnectivityManager TYPE_WIFI

Introduction

In this page you can find the example usage for android.net ConnectivityManager TYPE_WIFI.

Prototype

int TYPE_WIFI

To view the source code for android.net ConnectivityManager TYPE_WIFI.

Click Source Link

Document

A WIFI data connection.

Usage

From source file:Main.java

public static boolean isWifiConnected(Context mContext) {
    ConnectivityManager connectivityManager = (ConnectivityManager) mContext
            .getSystemService(Context.CONNECTIVITY_SERVICE);
    NetworkInfo activeNetInfo = connectivityManager.getActiveNetworkInfo();
    if (activeNetInfo != null && activeNetInfo.getType() == ConnectivityManager.TYPE_WIFI) {
        return true;
    }/*w w  w.  ja  v  a 2  s  .  co m*/
    return false;
}

From source file:Main.java

/**
 * Determine the current networking is WIFI
 * /*from  w w w  .  j a  va  2  s  .com*/
 * @param context
 * @return
 */
public static boolean CurrentNoteworkTypeIsWIFI(Context context) {
    ConnectivityManager connectionManager = (ConnectivityManager) context
            .getSystemService(Context.CONNECTIVITY_SERVICE);
    return connectionManager.getActiveNetworkInfo().getType() == ConnectivityManager.TYPE_WIFI;
}

From source file:Main.java

/**
 * Determine the current networking is WIFI
 * //from  w  w w.j ava 2 s. c  o m
 * @param context
 * @return
 */
public static boolean currentNoteworkTypeIsWIFI(Context context) {
    ConnectivityManager connectionManager = (ConnectivityManager) context
            .getSystemService(Context.CONNECTIVITY_SERVICE);
    return connectionManager.getActiveNetworkInfo().getType() == ConnectivityManager.TYPE_WIFI;
}

From source file:Main.java

public static boolean isWifi(Context context) {
    ConnectivityManager cm = (ConnectivityManager) context.getSystemService(Context.CONNECTIVITY_SERVICE);

    if (null == cm) {
        return false;
    }/* w w w .j a  va2  s.  co  m*/

    NetworkInfo info = cm.getActiveNetworkInfo();
    if (null != info) {
        if (info.getType() == ConnectivityManager.TYPE_WIFI) {
            return true;
        }
    }
    return false;

}

From source file:Main.java

@Deprecated
public static boolean isWifi(Context mContext) {
    ConnectivityManager connectivityManager = (ConnectivityManager) mContext
            .getSystemService(Context.CONNECTIVITY_SERVICE);
    NetworkInfo activeNetInfo = connectivityManager.getActiveNetworkInfo();
    if (activeNetInfo != null && activeNetInfo.getType() == ConnectivityManager.TYPE_WIFI) {
        return true;
    }/*from www.j a  v  a  2  s. c om*/
    return false;
}

From source file:Main.java

public static boolean hasInternetAccess(Context context) {
    try {/*from w w  w . j av a 2s  .c om*/
        boolean hasInternet = false;

        ConnectivityManager cm = (ConnectivityManager) context.getSystemService(Context.CONNECTIVITY_SERVICE);
        NetworkInfo networkInfo = cm.getActiveNetworkInfo();
        NetworkInfo wifi = cm.getNetworkInfo(ConnectivityManager.TYPE_WIFI);
        NetworkInfo mobile = cm.getNetworkInfo(ConnectivityManager.TYPE_MOBILE);
        if ((wifi.isAvailable() || mobile.isAvailable()) && networkInfo != null
                && networkInfo.isConnectedOrConnecting()) {
            hasInternet = true;
        }

        return hasInternet;
    } catch (Exception e) {
        return false;
    }
}

From source file:Main.java

/**
 * Check WIFI connection./*  www.  j  a va 2 s  .c om*/
 *
 * @return
 */
public static boolean isWifiConnected(Context context) {
    ConnectivityManager cm = (ConnectivityManager) context.getSystemService(Context.CONNECTIVITY_SERVICE);
    NetworkInfo info = cm.getActiveNetworkInfo();
    return (info != null && ConnectivityManager.TYPE_WIFI == info.getType());
}

From source file:Main.java

private static boolean checkNetWork_b(Context context) {
    ConnectivityManager connectMgr = (ConnectivityManager) context
            .getSystemService(context.CONNECTIVITY_SERVICE);
    NetworkInfo mobNetInfo = connectMgr.getNetworkInfo(ConnectivityManager.TYPE_MOBILE);
    NetworkInfo wifiNetInfo = connectMgr.getNetworkInfo(ConnectivityManager.TYPE_WIFI);
    NetworkInfo mNetworkInfo = connectMgr.getActiveNetworkInfo();
    boolean bmob = mobNetInfo.isConnected();
    boolean bwifi = wifiNetInfo.isConnected();
    if (!bmob && !bwifi) {
        // Log.i(TAG, "unconnect");
        // unconnect network
        return false;
    } else {/*from  w  ww.j a v  a  2  s. c om*/
        // connect network
        return true;
    }

}

From source file:Main.java

public static boolean isWifiConnected(Context context) {
    if (context != null) {
        ConnectivityManager connectivityManager = (ConnectivityManager) context
                .getSystemService(Context.CONNECTIVITY_SERVICE);
        NetworkInfo wiFiNetworkInfo = connectivityManager.getNetworkInfo(ConnectivityManager.TYPE_WIFI);
        if (wiFiNetworkInfo != null) {
            return wiFiNetworkInfo.isAvailable();
        }//from  w  w w. j a  v  a 2  s . c  o m
    }
    return false;
}

From source file:Main.java

public static boolean isConnectedWifi(Context context) {
    ConnectivityManager connectivityManager = (ConnectivityManager) context
            .getSystemService(Context.CONNECTIVITY_SERVICE);

    NetworkInfo networkInfo = null;//from   w ww .  j  a va 2  s  .com
    if (connectivityManager != null) {
        networkInfo = connectivityManager.getNetworkInfo(ConnectivityManager.TYPE_WIFI);
    }

    return networkInfo == null ? false : networkInfo.isConnected();
}