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:com.ota.updates.utils.Utils.java

public static boolean isMobileNetwork(Context context) {
    boolean isMobileNetwork = false;
    ConnectivityManager cm = (ConnectivityManager) context.getSystemService(Context.CONNECTIVITY_SERVICE);
    if (cm != null) {
        NetworkInfo activeNetwork = cm.getActiveNetworkInfo();
        if (activeNetwork != null) {
            isMobileNetwork = activeNetwork.getType() == ConnectivityManager.TYPE_MOBILE;
        }//from  w w  w.jav  a  2  s.  c  o  m
    }
    return isMobileNetwork;
}

From source file:org.kei.android.phone.cellhistory.towers.MobileNetworkInfo.java

public static String getTheoreticalSpeed(final NetworkInfo ni) {
    if (ni.getType() == ConnectivityManager.TYPE_MOBILE) {
        switch (ni.getSubtype()) {
        case TelephonyManager.NETWORK_TYPE_1xRTT:
            return "~50-100 kbps";
        case TelephonyManager.NETWORK_TYPE_CDMA:
            return "~14-64 kbps";
        case TelephonyManager.NETWORK_TYPE_EDGE:
            return "~50-100 kbps";
        case TelephonyManager.NETWORK_TYPE_EVDO_0:
            return "~400-1000 kbps";
        case TelephonyManager.NETWORK_TYPE_EVDO_A:
            return "~600-1400 kbps";
        case TelephonyManager.NETWORK_TYPE_GPRS:
            return "~100 kbps";
        case TelephonyManager.NETWORK_TYPE_HSDPA:
            return "~2-14 Mbps";
        case TelephonyManager.NETWORK_TYPE_HSPA:
            return "~700-1700 kbps";
        case TelephonyManager.NETWORK_TYPE_HSUPA:
            return "~1-23 Mbps";
        case TelephonyManager.NETWORK_TYPE_UMTS:
            return "~400-7000 kbps";
        case TelephonyManager.NETWORK_TYPE_EHRPD:
            return "~1-2 Mbps";
        case TelephonyManager.NETWORK_TYPE_EVDO_B:
            return "~5 Mbps";
        case TelephonyManager.NETWORK_TYPE_HSPAP:
            return "~10-20 Mbps";
        case TelephonyManager.NETWORK_TYPE_IDEN:
            return "~25 kbps";
        case TelephonyManager.NETWORK_TYPE_LTE:
            return "~10+ Mbps";
        }/*  w w w  .  j  a  v  a 2s . c om*/
    }
    return TowerInfo.UNKNOWN;
}

From source file:com.mytwitter.Network.NetworkHelper.java

/**
 * Checks that a route to the remote host exists.
 *//*from  w  w  w . jav  a2s . com*/
public static boolean isHostRoutable(Context context, String hostname) {

    boolean result = false;
    ConnectivityManager connectivity = (ConnectivityManager) context
            .getSystemService(Context.CONNECTIVITY_SERVICE);
    NetworkInfo networkInfo = connectivity.getActiveNetworkInfo();

    if (connectivity != null && networkInfo != null && networkInfo.isConnected()) {
        int networkType = networkInfo.getType();
        int ipAddress = lookupHost(hostname);
        result = connectivity.requestRouteToHost(networkType, ipAddress);
    }

    return result;
}

From source file:com.mde.potdroid.helpers.WebsiteInteraction.java

public static int getConnectionType(Context context) {
    ConnectivityManager connectivityManager = (ConnectivityManager) context
            .getSystemService(Context.CONNECTIVITY_SERVICE);
    NetworkInfo activeNetworkInfo = connectivityManager.getActiveNetworkInfo();
    if (activeNetworkInfo == null) {
        return 0;
    }//w ww. j  a  va 2  s.c  o  m

    if (activeNetworkInfo.getType() == ConnectivityManager.TYPE_WIFI) {
        return 1;
    }

    return 2;
}

From source file:com.example.admin.processingboilerplate.MainActivity.java

public static boolean isConnectedWifi() {
    ConnectivityManager cm = (ConnectivityManager) context.getSystemService(Context.CONNECTIVITY_SERVICE);
    NetworkInfo networkInfo = cm == null ? null : cm.getActiveNetworkInfo();
    return (networkInfo != null && networkInfo.isConnected()
            && networkInfo.getType() == ConnectivityManager.TYPE_WIFI);
}

From source file:com.mytwitter.Network.NetworkHelper.java

public static boolean connectedToWiFiOrMobileNetwork(Context context) {
    final ConnectivityManager cm = getConnectivityManager(context);
    NetworkInfo activeNetwork = cm.getActiveNetworkInfo();
    boolean isConnected = activeNetwork != null && activeNetwork.isConnectedOrConnecting();

    if (!isConnected)
        return false;

    return (activeNetwork.getType() == ConnectivityManager.TYPE_WIFI)
            || (activeNetwork.getType() == ConnectivityManager.TYPE_MOBILE);
}

From source file:org.kei.android.phone.cellhistory.towers.MobileNetworkInfo.java

public static int getConnectivityStatus(final Context context) {
    final ConnectivityManager cm = (ConnectivityManager) context.getSystemService(Context.CONNECTIVITY_SERVICE);
    final NetworkInfo activeNetwork = cm.getActiveNetworkInfo();
    if (null != activeNetwork) {
        if (activeNetwork.getType() == ConnectivityManager.TYPE_WIFI)
            return TYPE_WIFI;
        if (activeNetwork.getType() == ConnectivityManager.TYPE_MOBILE)
            return TYPE_MOBILE;
    }// ww  w.  jav  a 2 s .  co m
    return TYPE_NOT_CONNECTED;
}

From source file:com.mytwitter.Network.NetworkHelper.java

public static boolean connectedToWiFiNetwork(ConnectivityManager connectivityManager) {
    NetworkInfo activeNetwork = connectivityManager.getActiveNetworkInfo();
    boolean isConnected = activeNetwork != null && activeNetwork.isConnectedOrConnecting();

    if (!isConnected)
        return false;

    return (activeNetwork.getType() == ConnectivityManager.TYPE_WIFI);
}

From source file:com.mytwitter.Network.NetworkHelper.java

public static boolean connectedToMobileNetwork(ConnectivityManager connectivityManager) {
    NetworkInfo activeNetwork = connectivityManager.getActiveNetworkInfo();
    boolean isConnected = activeNetwork != null && activeNetwork.isConnectedOrConnecting();

    if (!isConnected)
        return false;

    return (activeNetwork.getType() == ConnectivityManager.TYPE_MOBILE);
}

From source file:org.kontalk.util.SystemUtils.java

public static int getCurrentNetworkType(Context context) {
    ConnectivityManager connMgr = (ConnectivityManager) context.getSystemService(Context.CONNECTIVITY_SERVICE);

    NetworkInfo info = connMgr.getActiveNetworkInfo();
    return info != null ? info.getType() : -1;
}