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 String isNetWorkType(Context cxt) {
    ConnectivityManager connectivityManager = (ConnectivityManager) cxt
            .getSystemService(Context.CONNECTIVITY_SERVICE);
    NetworkInfo activeNetInfo = connectivityManager.getActiveNetworkInfo();
    if (activeNetInfo != null && activeNetInfo.getType() == ConnectivityManager.TYPE_MOBILE) {
        return "3G";
    }//  w  w  w  .j a  va2 s.com
    if (activeNetInfo != null && activeNetInfo.getType() == ConnectivityManager.TYPE_WIFI) {
        return "WIFI";
    }
    return "";
}

From source file:Main.java

public static boolean isWifiActive(Context context) {
    ConnectivityManager connectivity = (ConnectivityManager) context
            .getSystemService(Context.CONNECTIVITY_SERVICE);
    NetworkInfo[] info;//w  w  w.  ja va  2 s  . c o m
    if (connectivity != null) {
        info = connectivity.getAllNetworkInfo();
        if (info != null) {
            for (int i = 0; i < info.length; i++) {
                if (info[i].getType() == ConnectivityManager.TYPE_WIFI && info[i].isConnected()) {
                    return true;
                }
            }
        }
    }
    return false;
}

From source file:Main.java

public static String getNetworkState(Context context) {
    ConnectivityManager cm = (ConnectivityManager) context.getSystemService(Context.CONNECTIVITY_SERVICE);
    NetworkInfo activeNetwork = cm.getActiveNetworkInfo();
    String returnValue = "";
    if (null != activeNetwork) {
        if (activeNetwork.getType() == ConnectivityManager.TYPE_WIFI)
            returnValue = "wifi";
        else if (activeNetwork.getType() == ConnectivityManager.TYPE_MOBILE)
            returnValue = "mobile" + "_" + getNetworkType(context);
        else/*from  w  w  w .jav  a  2 s .  co m*/
            returnValue = "Unknown";
    } else
        returnValue = "Not connected";
    return returnValue;
}

From source file:Main.java

/**
 * To check whether current network is wifi.
 *
 * @param context context/*w ww  .  j  a v a  2s.c  o m*/
 * @return true if network if wifi, otherwise return false
 */
protected static boolean isWifi(Context context) {
    if (context == null) {
        return false;
    }

    ConnectivityManager manager = (ConnectivityManager) context.getSystemService(Context.CONNECTIVITY_SERVICE);
    NetworkInfo info = manager.getActiveNetworkInfo();

    return info != null && (info.getType() == ConnectivityManager.TYPE_WIFI);
}

From source file:Main.java

static public boolean isDisconnectedIntent(Intent intent) {
    boolean res = false;
    NetworkInfo networkInfo = (NetworkInfo) intent.getParcelableExtra(ConnectivityManager.EXTRA_NETWORK_INFO);
    if (networkInfo != null) {
        NetworkInfo.State state = networkInfo.getState();
        res = (state.equals(NetworkInfo.State.DISCONNECTING) || state.equals(NetworkInfo.State.DISCONNECTED))
                && (networkInfo.getType() == ConnectivityManager.TYPE_WIFI);

    } else {/*from   ww  w .j a v a2  s.c  om*/
        int wifiState = intent.getIntExtra(WifiManager.EXTRA_WIFI_STATE, WifiManager.WIFI_STATE_UNKNOWN);
        if (wifiState == WifiManager.WIFI_STATE_DISABLED || wifiState == WifiManager.WIFI_STATE_DISABLING) {
            res = true;
        }
    }
    return res;
}

From source file:Main.java

public static boolean ensureWifi(Context context) {
    ConnectivityManager cm = (ConnectivityManager) context.getSystemService(Context.CONNECTIVITY_SERVICE);
    NetworkInfo netInfo = cm.getActiveNetworkInfo();
    if (netInfo == null || !netInfo.isConnectedOrConnecting())
        return false;
    // always OK if we're on wifi
    if (netInfo.getType() == ConnectivityManager.TYPE_WIFI)
        return true;
    // check for wifi only pref
    if (PreferenceManager.getDefaultSharedPreferences(context).getBoolean("wifiPref", true)) {
        Log.d("Podax", "Not downloading because Wifi is required and not connected");
        return false;
    }/*ww w . j av  a2s.  co  m*/
    // check for 3g data turned off
    if (!netInfo.isConnected()) {
        Log.d("Podax", "Not downloading because background data is turned off");
        return false;
    }

    return true;
}

From source file:Main.java

public static boolean isWIFIConnected(Context context) {
    ConnectivityManager cmg = (ConnectivityManager) context.getSystemService(Context.CONNECTIVITY_SERVICE);
    boolean result = true;
    NetworkInfo active = cmg.getNetworkInfo(ConnectivityManager.TYPE_WIFI);
    if (active == null || !active.isConnected()) {
        result = false;//from  w  w  w. ja  v a2 s  .c o m
    }
    return result;
}

From source file:Main.java

public static String checkNetType(Context context) {
    ConnectivityManager connectMgr = (ConnectivityManager) context
            .getSystemService(Context.CONNECTIVITY_SERVICE);
    NetworkInfo info = connectMgr.getActiveNetworkInfo();
    String type = "no_network";
    if (info == null) {
        return type;
    }//from ww  w  .ja  v a  2  s. co  m
    if (info.getType() == ConnectivityManager.TYPE_WIFI) {
        type = "wifi";
    } else {
        switch (info.getSubtype()) {
        case TelephonyManager.NETWORK_TYPE_UNKNOWN:
            type = "UNKNOWN";
            break;
        case TelephonyManager.NETWORK_TYPE_GPRS:
            type = "GPRS";
            break;
        case TelephonyManager.NETWORK_TYPE_EDGE:
            type = "EDGE";
            break;
        case TelephonyManager.NETWORK_TYPE_UMTS:
            type = "UMTS";
            break;
        case TelephonyManager.NETWORK_TYPE_CDMA:
            type = "CDMA";
            break;
        case TelephonyManager.NETWORK_TYPE_EVDO_0:
            type = "EVDO_0";
            break;
        case TelephonyManager.NETWORK_TYPE_EVDO_A:
            type = "EVDO_A";
            break;
        case TelephonyManager.NETWORK_TYPE_1xRTT:
            type = "1xRTT";
            break;
        case TelephonyManager.NETWORK_TYPE_HSDPA:
            type = "HSDPA";
            break;
        case TelephonyManager.NETWORK_TYPE_HSUPA:
            type = "HSUPA";
            break;
        case TelephonyManager.NETWORK_TYPE_HSPA:
            type = "HSPA";
            break;
        case TelephonyManager.NETWORK_TYPE_IDEN:
            type = "IDEN";
            break;
        case TelephonyManager.NETWORK_TYPE_EVDO_B:
            type = "EVDO_B";
            break;
        case TelephonyManager.NETWORK_TYPE_LTE:
            type = "LTE";
            break;
        case TelephonyManager.NETWORK_TYPE_EHRPD:
            type = "EHRPD";
            break;
        case TelephonyManager.NETWORK_TYPE_HSPAP:
            type = "HSPAP";
            break;
        }
    }
    return type;
}

From source file:Main.java

public static String getWifiName(Context context) {
    Log.v(TAG, "-- Calling WIFI NAME --");
    if (context != null) {
        ConnectivityManager conMgr = (ConnectivityManager) context
                .getSystemService(Context.CONNECTIVITY_SERVICE);
        WifiManager wifiMgr = (WifiManager) context.getSystemService(Context.WIFI_SERVICE);
        if (conMgr.getNetworkInfo(ConnectivityManager.TYPE_WIFI).isConnectedOrConnecting()) {
            WifiInfo wifiInfo = wifiMgr.getConnectionInfo();
            Log.v(TAG, "-- WIFI is Enabled Name = " + wifiInfo.getSSID());
            return wifiInfo.getSSID();
        }//w w w  .  j  a v  a2  s  . c o  m
    }
    return "";
}

From source file:Main.java

public static boolean checkWifiInternetConn() {
    //Create object for ConnectivityManager class which returns network related info
    ConnectivityManager connectivity = (ConnectivityManager) m_TempContext
            .getSystemService(m_TempContext.CONNECTIVITY_SERVICE);
    //If connectivity object is not null
    if (connectivity != null) {
        //Get network info - WIFI internet access
        NetworkInfo info = connectivity.getNetworkInfo(ConnectivityManager.TYPE_WIFI);
        if (info != null) {
            //Look for whether device is currently connected to WIFI network
            if (info.isConnected()) {
                return true;
            }//from   www  .j a va2 s  . com
        }
    }
    return false;
}