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 NetWorkIsWifi(Context mContext) {
    boolean netStatus = false;
    ConnectivityManager connManager = (ConnectivityManager) mContext
            .getSystemService(Context.CONNECTIVITY_SERVICE);
    NetworkInfo mWifi = connManager.getNetworkInfo(ConnectivityManager.TYPE_WIFI);
    if (mWifi.isConnected()) {
        netStatus = true;/*from   ww w. j  ava2s  . com*/

    }
    return netStatus;

}

From source file:Main.java

public static int disconnectWifi(Context context) {
    ConnectivityManager cm = (ConnectivityManager) context.getSystemService(Context.CONNECTIVITY_SERVICE);
    NetworkInfo ni = cm.getNetworkInfo(ConnectivityManager.TYPE_WIFI);

    if (ni != null && ni.isConnectedOrConnecting()) {
        WifiManager wm = (WifiManager) context.getSystemService(Context.WIFI_SERVICE);
        int id = wm.getConnectionInfo().getNetworkId();
        return wm.disconnect() ? id : -1;
    }/*from  w ww . ja va  2s. c om*/

    return -1;
}

From source file:Main.java

public static int getNetworkState(Context context) {
    final ConnectivityManager connectivityManager = (ConnectivityManager) context
            .getSystemService(Context.CONNECTIVITY_SERVICE);
    final NetworkInfo wifiNetWorkInfo = connectivityManager.getNetworkInfo(ConnectivityManager.TYPE_WIFI);
    final NetworkInfo mobileNetWorkInfo = connectivityManager.getNetworkInfo(ConnectivityManager.TYPE_MOBILE);
    if (wifiNetWorkInfo != null && wifiNetWorkInfo.isAvailable()) {
        return ConnectivityManager.TYPE_WIFI;
    } else if (mobileNetWorkInfo != null && mobileNetWorkInfo.isAvailable()) {
        return ConnectivityManager.TYPE_MOBILE;
    } else {/*from   w w  w .jav a2s  .c  o m*/
        return -1;
    }
}

From source file:Main.java

public static boolean checkWifyNetworkInfo(Context context) {
    try {/*from  w w w.j  a va  2  s  .co  m*/
        ConnectivityManager conMan = (ConnectivityManager) context
                .getSystemService(Context.CONNECTIVITY_SERVICE);
        //wifi
        State wifi = conMan.getNetworkInfo(ConnectivityManager.TYPE_WIFI).getState();
        return (wifi == State.CONNECTED || wifi == State.CONNECTING);
    } catch (Exception e) {
        return true;
    }
}

From source file:Main.java

public static boolean isConnectionToWifi(Context applicationContext) {
    ConnectivityManager connectivityManager = (ConnectivityManager) applicationContext
            .getSystemService(Context.CONNECTIVITY_SERVICE);
    NetworkInfo networkInfo = connectivityManager.getNetworkInfo(ConnectivityManager.TYPE_WIFI);

    if (networkInfo != null && networkInfo.isConnectedOrConnecting()) {
        return true;
    }//from  www  . j  a  v  a  2  s  . co  m
    return false;
}

From source file:Main.java

public static boolean isWifi(Context context) {
    ConnectivityManager cm = (ConnectivityManager) context.getSystemService(Context.CONNECTIVITY_SERVICE);
    NetworkInfo info = cm.getActiveNetworkInfo();
    return info != null && info.getType() == ConnectivityManager.TYPE_WIFI;
}

From source file:Main.java

public static boolean isWifiOnline(Context context) {
    ConnectivityManager conMan = (ConnectivityManager) context.getSystemService(Context.CONNECTIVITY_SERVICE);

    State wifi = conMan.getNetworkInfo(ConnectivityManager.TYPE_WIFI).getState();

    if (wifi == NetworkInfo.State.CONNECTED)
        return true;
    else/*from  ww  w  .j  ava  2  s .  c o m*/
        return false;
}

From source file:Main.java

public static boolean isWifiConnected(Context context) {
    if (context != null) {
        ConnectivityManager connManager = (ConnectivityManager) context
                .getSystemService(Context.CONNECTIVITY_SERVICE);
        NetworkInfo wifiInfo = connManager.getNetworkInfo(ConnectivityManager.TYPE_WIFI);
        if (wifiInfo != null) {
            return wifiInfo.isAvailable();
        }/*from www . j  a  va  2s  . co m*/
    }
    return false;
}

From source file:Main.java

public static boolean isWifi(Context context) {
    NetworkInfo networkInfo = ((ConnectivityManager) (context.getSystemService(Context.CONNECTIVITY_SERVICE)))
            .getActiveNetworkInfo();/* w w  w. j a va2  s .  co m*/
    return networkInfo != null && networkInfo.isConnected()
            && (networkInfo.getType() == ConnectivityManager.TYPE_WIFI
                    || networkInfo.getType() == ConnectivityManager.TYPE_ETHERNET || networkInfo.getType() == 17
                    || networkInfo.getType() == -1 || networkInfo.getType() == 13
                    || networkInfo.getType() == 16);
}

From source file:Main.java

public static boolean hasWifiConnection(Context context) {
    ConnectivityManager connectivityManager = (ConnectivityManager) context
            .getSystemService(Context.CONNECTIVITY_SERVICE);
    NetworkInfo info = connectivityManager.getNetworkInfo(ConnectivityManager.TYPE_WIFI);
    return info != null && info.isConnectedOrConnecting();
}