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 isNetworkAvailable(Context ctx) {
    int networkStatePermission = ctx.checkCallingOrSelfPermission(Manifest.permission.ACCESS_NETWORK_STATE);

    if (networkStatePermission == PackageManager.PERMISSION_GRANTED) {

        ConnectivityManager mConnectivity = (ConnectivityManager) ctx
                .getSystemService(Context.CONNECTIVITY_SERVICE);

        // Skip if no connection, or background data disabled
        NetworkInfo info = mConnectivity.getActiveNetworkInfo();
        if (info == null) {
            return false;
        }//from  ww  w .j  ava  2s.c o  m
        // Only update if WiFi
        int netType = info.getType();
        // int netSubtype = info.getSubtype();
        if ((netType == ConnectivityManager.TYPE_WIFI) || (netType == ConnectivityManager.TYPE_MOBILE)) {
            return info.isConnected();
        } else {
            return false;
        }
    } else {
        return true;
    }
}

From source file:Main.java

private static boolean isWifiContected(Context context) {
    ConnectivityManager cm = (ConnectivityManager) context.getSystemService(Context.CONNECTIVITY_SERVICE);
    NetworkInfo ni = cm.getActiveNetworkInfo();
    return ni != null && ni.getType() == ConnectivityManager.TYPE_WIFI;

}

From source file:Main.java

public static int availableCommunication(Context context) {
    ConnectivityManager cm = (ConnectivityManager) context.getSystemService(Context.CONNECTIVITY_SERVICE);
    NetworkInfo ni = cm.getNetworkInfo(ConnectivityManager.TYPE_WIFI);
    boolean isWifiAvail = ni.isAvailable();
    boolean isWifiConn = ni.isConnected();
    ni = cm.getNetworkInfo(ConnectivityManager.TYPE_MOBILE);
    boolean isMobileAvail = ni.isAvailable();
    boolean isMobileConn = ni.isConnected();
    String status = "WiFi\nAvail = " + isWifiAvail + "\nConn = " + isWifiConn + "\nMobile\nAvail = "
            + isMobileAvail + "\nConn = " + isMobileConn + "\n";
    Log.d("Communication State! ", status);
    if (isWifiAvail == true && isWifiConn == true) {
        return ConnectivityManager.TYPE_WIFI;
    } else if (isMobileAvail == true && isMobileConn == true) {
        return ConnectivityManager.TYPE_MOBILE;
    } else {//from  www .  j a v a2 s  . com
        return -1;
    }
}

From source file:Main.java

public static boolean isWifiAvail(Context context) {
    if (context != null) {
        ConnectivityManager mConnectivityManager = (ConnectivityManager) context
                .getSystemService(Context.CONNECTIVITY_SERVICE);
        NetworkInfo mWiFiNetworkInfo = mConnectivityManager.getNetworkInfo(ConnectivityManager.TYPE_WIFI);
        if (mWiFiNetworkInfo != null) {
            return mWiFiNetworkInfo.isAvailable();
        }/*from   w w  w  .  ja  v a  2  s. c o m*/
    }
    return false;
}

From source file:Main.java

private static boolean isConnectionFast(int type, int subType) {
    if (type == ConnectivityManager.TYPE_WIFI) {
        return true;
    } else if (type == ConnectivityManager.TYPE_MOBILE) {
        switch (subType) {
        case TelephonyManager.NETWORK_TYPE_1xRTT:
            return false; // ~ 50-100 kbps
        case TelephonyManager.NETWORK_TYPE_CDMA:
            return false; // ~ 14-64 kbps
        case TelephonyManager.NETWORK_TYPE_EDGE:
            return false; // ~ 50-100 kbps
        case TelephonyManager.NETWORK_TYPE_GPRS:
            return false; // ~ 100 kbps
        case TelephonyManager.NETWORK_TYPE_EVDO_0:
            return false; // ~25 kbps 
        case TelephonyManager.NETWORK_TYPE_LTE:
            return true; // ~ 400-1000 kbps
        case TelephonyManager.NETWORK_TYPE_EVDO_A:
            return true; // ~ 600-1400 kbps
        case TelephonyManager.NETWORK_TYPE_HSDPA:
            return true; // ~ 2-14 Mbps
        case TelephonyManager.NETWORK_TYPE_HSPA:
            return true; // ~ 700-1700 kbps
        case TelephonyManager.NETWORK_TYPE_HSUPA:
            return true; // ~ 1-23 Mbps
        case TelephonyManager.NETWORK_TYPE_UMTS:
            return true; // ~ 400-7000 kbps
        case TelephonyManager.NETWORK_TYPE_EHRPD:
            return true; // ~ 1-2 Mbps
        case TelephonyManager.NETWORK_TYPE_EVDO_B:
            return true; // ~ 5 Mbps
        case TelephonyManager.NETWORK_TYPE_HSPAP:
            return true; // ~ 10-20 Mbps
        case TelephonyManager.NETWORK_TYPE_IDEN:
            return true; // ~ 10+ Mbps
        case TelephonyManager.NETWORK_TYPE_UNKNOWN:
        default://from w w  w .  j a v a 2s  .c  o m
            return false;
        }
    } else {
        return false;
    }
}

From source file:Main.java

public static boolean isLowBandwithNetwork(Context applicationContext) {

    //check for wifi
    ConnectivityManager connMgr = (ConnectivityManager) applicationContext
            .getSystemService(Context.CONNECTIVITY_SERVICE);
    android.net.NetworkInfo wifi = connMgr.getNetworkInfo(ConnectivityManager.TYPE_WIFI);

    if (!wifi.isConnectedOrConnecting()) {
        //if no wifi, check if we are on GPRS or EDGE
        TelephonyManager tm = (TelephonyManager) applicationContext.getSystemService(Context.TELEPHONY_SERVICE);
        if (tm != null && (tm.getNetworkType() == TelephonyManager.NETWORK_TYPE_EDGE
                || tm.getNetworkType() == TelephonyManager.NETWORK_TYPE_GPRS)) {
            return true;
        }//w  ww .j  av a 2 s .c o m
    }
    return false;
}

From source file:Main.java

public static boolean isWifiAvailable(Activity activity) {
    ConnectivityManager connManager = (ConnectivityManager) activity
            .getSystemService(Context.CONNECTIVITY_SERVICE);
    NetworkInfo mWifi = connManager.getNetworkInfo(ConnectivityManager.TYPE_WIFI);
    return mWifi.isConnected();
}

From source file:Main.java

public static boolean isWifiDataEnable(Context context) throws Exception {
    ConnectivityManager connectivityManager = (ConnectivityManager) context
            .getSystemService(Context.CONNECTIVITY_SERVICE);
    boolean isWifiDataEnable = false;
    isWifiDataEnable = connectivityManager.getNetworkInfo(ConnectivityManager.TYPE_WIFI)
            .isConnectedOrConnecting();//from www .j  a v  a  2  s  .  co m
    return isWifiDataEnable;
}

From source file:Main.java

public static boolean isNetworkAvaliable(Context context) {
    boolean isNetwokAvailable = false;
    ConnectivityManager connectionManager = (ConnectivityManager) context
            .getSystemService(Context.CONNECTIVITY_SERVICE);
    NetworkInfo wifiInfo = connectionManager.getNetworkInfo(ConnectivityManager.TYPE_WIFI);
    NetworkInfo mobileInfo = connectionManager.getNetworkInfo(ConnectivityManager.TYPE_MOBILE);

    if (wifiInfo != null && wifiInfo.isConnected()) {
        isNetwokAvailable = true;//w  w  w .  j  a  v  a 2 s. co m
    } else if (mobileInfo != null && mobileInfo.isConnected()) {
        isNetwokAvailable = true;
    } else {

        isNetwokAvailable = false;
    }

    return isNetwokAvailable;

}

From source file:Main.java

public static boolean isWifiConnected(Context context) {
    ConnectivityManager cm = (ConnectivityManager) context.getSystemService(Context.CONNECTIVITY_SERVICE);
    if (cm != null) {
        NetworkInfo networkInfo = cm.getActiveNetworkInfo();
        if (networkInfo != null && networkInfo.getType() == ConnectivityManager.TYPE_WIFI) {
            return true;
        }/*  www . j  a  v  a2  s .  c  o  m*/
    }
    return false;
}