Example usage for android.net NetworkInfo getType

List of usage examples for android.net NetworkInfo getType

Introduction

In this page you can find the example usage for android.net NetworkInfo getType.

Prototype

@Deprecated
public int getType() 

Source Link

Document

Reports the type of network to which the info in this NetworkInfo pertains.

Usage

From source file:hobby.wei.c.phone.Network.java

public static boolean isRoaming(Context context) {
    NetworkInfo networkInfo = getConnectManager(context).getActiveNetworkInfo();
    boolean isMobile = (networkInfo != null && networkInfo.getType() == ConnectivityManager.TYPE_MOBILE);
    boolean isRoaming = isMobile && getTelephonyManager(context).isNetworkRoaming();
    return isRoaming;
}

From source file:dev.ukanth.ufirewall.InterfaceTracker.java

private static InterfaceDetails getInterfaceDetails(Context context) {
    InterfaceDetails ret = new InterfaceDetails();

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

    if (info == null || info.isConnected() == false) {
        return ret;
    }//  ww  w  .ja v a2  s  .  co  m

    switch (info.getType()) {
    case ConnectivityManager.TYPE_MOBILE:
    case ConnectivityManager.TYPE_MOBILE_DUN:
    case ConnectivityManager.TYPE_MOBILE_HIPRI:
    case ConnectivityManager.TYPE_MOBILE_MMS:
    case ConnectivityManager.TYPE_MOBILE_SUPL:
    case ConnectivityManager.TYPE_WIMAX:
        ret.isRoaming = info.isRoaming();
        ret.netType = ConnectivityManager.TYPE_MOBILE;
        ret.netEnabled = true;
        break;
    case ConnectivityManager.TYPE_WIFI:
    case ConnectivityManager.TYPE_BLUETOOTH:
    case ConnectivityManager.TYPE_ETHERNET:
        ret.netType = ConnectivityManager.TYPE_WIFI;
        ret.netEnabled = true;
        break;
    }
    getTetherStatus(context, ret);

    if (Build.VERSION.SDK_INT < Build.VERSION_CODES.GINGERBREAD) {
        OldInterfaceScanner.populateLanMasks(context, ITFS_WIFI, ret);
    } else {
        NewInterfaceScanner.populateLanMasks(context, ITFS_WIFI, ret);
    }

    return ret;
}

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

/**
 * Check if there is any connectivity to a Wifi network
 * @param context//  www  . j av a2s . c  om
 * @return
 */
public static boolean isConnectedWifi(Context context) {
    NetworkInfo info = getNetworkInfo(context);
    return (info != null && info.isConnected() && info.getType() == ConnectivityManager.TYPE_WIFI);
}

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

/**
 * Check if there is any connectivity to a mobile network
 * @param context//  w w w . j a va2 s. c o m
 * @return
 */
public static boolean isConnectedMobile(Context context) {
    NetworkInfo info = getNetworkInfo(context);
    return (info != null && info.isConnected() && info.getType() == ConnectivityManager.TYPE_MOBILE);
}

From source file:crow.util.Util.java

/**
 * ??wifi//from  w w  w  .jav a2s  . co m
 * 
 * @param context
 * @return true ?wifi false 
 */
public static boolean isWifi(Context context) {
    ConnectivityManager connManager = (ConnectivityManager) context
            .getSystemService(Context.CONNECTIVITY_SERVICE);
    NetworkInfo netInfo = connManager.getActiveNetworkInfo();
    if (netInfo != null) {
        int type = netInfo.getType();
        if (type == ConnectivityManager.TYPE_WIFI) {
            return true;
        }
    }
    return false;
}

From source file:hobby.wei.c.phone.Network.java

private static Type getType(NetworkInfo netInfo) {
    Type type;/*from ww w .  j  a v a2  s .co m*/
    //?TYPE_WIFI?TYPE_MOBILE?TYPE_MOBILE_MMS
    if (netInfo.getType() == ConnectivityManager.TYPE_WIFI) { //wifi?
        type = Type.WIFI;
    } else { //TYPE_WIFI
        switch (netInfo.getSubtype()) {
        case TelephonyManager.NETWORK_TYPE_UNKNOWN:
            type = Type.NO_NET;
            break;
        case TelephonyManager.NETWORK_TYPE_GPRS:
        case TelephonyManager.NETWORK_TYPE_EDGE:
            type = Type.G2;
            break;
        case TelephonyManager.NETWORK_TYPE_UMTS:
        case TelephonyManager.NETWORK_TYPE_CDMA: //3G
        case TelephonyManager.NETWORK_TYPE_EVDO_0:
        case TelephonyManager.NETWORK_TYPE_EVDO_A:
        case TelephonyManager.NETWORK_TYPE_1xRTT: //2.5GCDMA
        case TelephonyManager.NETWORK_TYPE_HSDPA:
        case TelephonyManager.NETWORK_TYPE_HSUPA:
        case TelephonyManager.NETWORK_TYPE_HSPA:
        case TelephonyManager.NETWORK_TYPE_IDEN:
        case TelephonyManager.NETWORK_TYPE_EVDO_B:
        case TelephonyManager.NETWORK_TYPE_EHRPD:
        case TelephonyManager.NETWORK_TYPE_HSPAP:
            type = Type.G3;
            break;
        case TelephonyManager.NETWORK_TYPE_LTE:
            type = Type.G4;
            break;
        default:
            type = Type.G4;
            break;
        }
    }
    return type;
}

From source file:com.DGSD.DGUtils.Http.BetterHttp.java

public static void updateProxySettings() {
    if (appContext == null) {
        return;/*from w  w w  .j a  v  a  2  s.  c o m*/
    }
    HttpParams httpParams = httpClient.getParams();
    ConnectivityManager connectivity = (ConnectivityManager) appContext
            .getSystemService(Context.CONNECTIVITY_SERVICE);
    NetworkInfo nwInfo = connectivity.getActiveNetworkInfo();
    if (nwInfo == null) {
        return;
    }
    Log.i(LOG_TAG, nwInfo.toString());
    if (nwInfo.getType() == ConnectivityManager.TYPE_MOBILE) {
        String proxyHost = Proxy.getHost(appContext);
        if (proxyHost == null) {
            proxyHost = Proxy.getDefaultHost();
        }
        int proxyPort = Proxy.getPort(appContext);
        if (proxyPort == -1) {
            proxyPort = Proxy.getDefaultPort();
        }
        if (proxyHost != null && proxyPort > -1) {
            HttpHost proxy = new HttpHost(proxyHost, proxyPort);
            httpParams.setParameter(ConnRoutePNames.DEFAULT_PROXY, proxy);
        } else {
            httpParams.setParameter(ConnRoutePNames.DEFAULT_PROXY, null);
        }
    } else {
        httpParams.setParameter(ConnRoutePNames.DEFAULT_PROXY, null);
    }
}

From source file:com.iflytek.android.framework.volley.toolbox.HurlStack.java

/**
 * @param context/*w  w  w.j  a  v  a 2s . c o m*/
 * @return ???<br\>
 *         -1: 1:WIFI <br\>
 *           2:cmnet 3:cmwap <br\>
 *           4:ctnet 5:ctwap <br\>
 *         ?  6:uninet 7:uniwap
 */
public static int getAPNType(Context context) {
    // ?wificmnet?cmwap??noneNet
    // ?wifi > cmnet >cmwap > noneNet
    ConnectivityManager connMgr = (ConnectivityManager) context.getSystemService(Context.CONNECTIVITY_SERVICE);
    NetworkInfo networkInfo = connMgr.getActiveNetworkInfo();
    if (networkInfo == null) {
        return -1;
    }
    int nType = networkInfo.getType();
    if (nType == ConnectivityManager.TYPE_WIFI) {
        // wifi
        return 1;
    } else if (nType == ConnectivityManager.TYPE_MOBILE) {
        String type = networkInfo.getExtraInfo();
        Log.d("netType", "netType : " + type);
        if (type.equalsIgnoreCase("cmnet")) {
            // cmnet
            return 2;
        } else if (type.equalsIgnoreCase("cmwap")) {
            // cmwap
            return 3;
        } else if (type.equalsIgnoreCase("ctnet")) {
            // ctnet
            return 4;
        } else if (type.equalsIgnoreCase("ctwap")) {
            // ctwap
            return 5;
        } else if (type.equalsIgnoreCase("uninet")) {
            // uninet
            return 6;
        } else if (type.equalsIgnoreCase("uniwap")) {
            // uniwap
            return 7;
        } else {
            return 2;
        }
    }
    return -1;

}

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

/**
 * Check if there is fast connectivity//from   w  w w. j  a  va 2 s .  c o m
 * @param context
 * @return
 */
public static boolean isConnectedFast(Context context) {
    NetworkInfo info = getNetworkInfo(context);
    return (info != null && info.isConnected() && isConnectionFast(info.getType(), info.getSubtype()));
}

From source file:com.otaupdater.utils.Utils.java

public static boolean wifiConnected(Context ctx) {
    ConnectivityManager cm = (ConnectivityManager) ctx.getSystemService(Context.CONNECTIVITY_SERVICE);
    NetworkInfo ni = cm.getActiveNetworkInfo();
    return ni != null && ni.isConnected() && ni.getType() == ConnectivityManager.TYPE_WIFI;
}