Example usage for android.telephony TelephonyManager getNetworkType

List of usage examples for android.telephony TelephonyManager getNetworkType

Introduction

In this page you can find the example usage for android.telephony TelephonyManager getNetworkType.

Prototype

@Deprecated
@RequiresPermission(android.Manifest.permission.READ_PHONE_STATE)
public @NetworkType int getNetworkType() 

Source Link

Document

Return the current data network type.

Usage

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;
        }//from   w w w.ja  va  2  s. co m
    }
    return false;
}

From source file:Main.java

public static String getCellularNetworkType(Context context) {
    TelephonyManager manager = (TelephonyManager) context.getSystemService(Context.TELEPHONY_SERVICE);
    switch (manager.getNetworkType()) {
    case TelephonyManager.NETWORK_TYPE_1xRTT:
        return "1xRTT";
    case TelephonyManager.NETWORK_TYPE_CDMA:
        return "CDMA";
    case TelephonyManager.NETWORK_TYPE_EDGE:
        return "EDGE";
    case TelephonyManager.NETWORK_TYPE_EHRPD:
        return "EHRPD";
    case TelephonyManager.NETWORK_TYPE_EVDO_0:
        return "EVDO_0";
    case TelephonyManager.NETWORK_TYPE_EVDO_A:
        return "EVDO_A";
    case TelephonyManager.NETWORK_TYPE_EVDO_B:
        return "EVDO_B";
    case TelephonyManager.NETWORK_TYPE_GPRS:
        return "GPRS";
    case TelephonyManager.NETWORK_TYPE_HSDPA:
        return "HSDPA";
    case TelephonyManager.NETWORK_TYPE_HSPA:
        return "HSPA";
    case TelephonyManager.NETWORK_TYPE_HSPAP:
        return "HSPAP";
    case TelephonyManager.NETWORK_TYPE_HSUPA:
        return "HSUPA";
    case TelephonyManager.NETWORK_TYPE_IDEN:
        return "IDEN";
    case TelephonyManager.NETWORK_TYPE_LTE:
        return "LTE";
    case TelephonyManager.NETWORK_TYPE_UMTS:
        return "UMTS";
    case TelephonyManager.NETWORK_TYPE_UNKNOWN:
        return "Unknown";
    default://from w  w  w. ja  v a2  s .co m
        return "";
    }
}

From source file:Main.java

public static String getNetClass(Context context) {
    TelephonyManager mTelephonyManager = (TelephonyManager) context.getSystemService(Context.TELEPHONY_SERVICE);
    int networkType = mTelephonyManager.getNetworkType();
    switch (networkType) {
    case TelephonyManager.NETWORK_TYPE_GPRS:
    case TelephonyManager.NETWORK_TYPE_EDGE:
    case TelephonyManager.NETWORK_TYPE_CDMA:
    case TelephonyManager.NETWORK_TYPE_1xRTT:
    case TelephonyManager.NETWORK_TYPE_IDEN:
        return "2G";
    case TelephonyManager.NETWORK_TYPE_UMTS:
    case TelephonyManager.NETWORK_TYPE_EVDO_0:
    case TelephonyManager.NETWORK_TYPE_EVDO_A:
    case TelephonyManager.NETWORK_TYPE_HSDPA:
    case TelephonyManager.NETWORK_TYPE_HSUPA:
    case TelephonyManager.NETWORK_TYPE_HSPA:
    case TelephonyManager.NETWORK_TYPE_EVDO_B:
    case TelephonyManager.NETWORK_TYPE_EHRPD:
    case TelephonyManager.NETWORK_TYPE_HSPAP:
        return "3G";
    case TelephonyManager.NETWORK_TYPE_LTE:
        return "4G";
    default://from  w w w  .  j a v a  2s .  com
        return "Unknown";
    }
}

From source file:Main.java

/**
 * @param context/*from   w  w  w  .  j a v  a  2s  .  c  o  m*/
 * @return boolean
 * @throws
 * @Title: isFastMobileNetwork
 * @Description: TODO
 */
public static boolean isFastMobileNetwork(Context context) {
    TelephonyManager telephonyManager = (TelephonyManager) context.getSystemService(Context.TELEPHONY_SERVICE);
    switch (telephonyManager.getNetworkType()) {
    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_EVDO_0:
        return true; // ~ 400-1000 kbps
    case TelephonyManager.NETWORK_TYPE_EVDO_A:
        return true; // ~ 600-1400 kbps
    case TelephonyManager.NETWORK_TYPE_GPRS:
        return false; // ~ 100 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 false; // ~25 kbps
    case TelephonyManager.NETWORK_TYPE_LTE:
        return true; // ~ 10+ Mbps
    case TelephonyManager.NETWORK_TYPE_UNKNOWN:
        return false;
    default:
        return false;
    }
}

From source file:Main.java

/**
 * @param context/*from w w w  .java2  s.co m*/
 * @return String
 * @throws
 * @Title: networkType
 * @Description: TODO
 */
public static String networkType(Context context) {
    TelephonyManager tm = (TelephonyManager) context.getSystemService(context.TELEPHONY_SERVICE);
    int type = tm.getNetworkType();
    String typeString = "UNKNOWN";
    if (type == TelephonyManager.NETWORK_TYPE_CDMA) {
        typeString = "CDMA";
    }
    if (type == TelephonyManager.NETWORK_TYPE_EDGE) {
        typeString = "EDGE";
    }
    if (type == TelephonyManager.NETWORK_TYPE_EVDO_0) {
        typeString = "EVDO_0";
    }
    if (type == TelephonyManager.NETWORK_TYPE_EVDO_A) {
        typeString = "EVDO_A";
    }
    if (type == TelephonyManager.NETWORK_TYPE_GPRS) {
        typeString = "GPRS";
    }
    if (type == TelephonyManager.NETWORK_TYPE_HSDPA) {
        typeString = "HSDPA";
    }
    if (type == TelephonyManager.NETWORK_TYPE_HSPA) {
        typeString = "HSPA";
    }
    if (type == TelephonyManager.NETWORK_TYPE_HSUPA) {
        typeString = "HSUPA";
    }
    if (type == TelephonyManager.NETWORK_TYPE_UMTS) {
        typeString = "UMTS";
    }
    if (type == TelephonyManager.NETWORK_TYPE_UNKNOWN) {
        typeString = "UNKNOWN";
    }
    if (type == TelephonyManager.NETWORK_TYPE_1xRTT) {
        typeString = "1xRTT";
    }
    if (type == 11) {
        typeString = "iDen";
    }
    if (type == 12) {
        typeString = "EVDO_B";
    }
    if (type == 13) {
        typeString = "LTE";
    }
    if (type == 14) {
        typeString = "eHRPD";
    }
    if (type == 15) {
        typeString = "HSPA+";
    }

    return typeString;
}

From source file:Main.java

public static String getNetworkType(Context context) {
    TelephonyManager telephonyManager = (TelephonyManager) context.getSystemService(Context.TELEPHONY_SERVICE);

    switch (telephonyManager.getNetworkType()) {

    case TelephonyManager.NETWORK_TYPE_1xRTT:
        return "1xRTT";

    case TelephonyManager.NETWORK_TYPE_CDMA:
        return "CDMA";

    case TelephonyManager.NETWORK_TYPE_EDGE:
        return "EDGE ";

    case TelephonyManager.NETWORK_TYPE_EHRPD:
        return "EHRPD ";

    case TelephonyManager.NETWORK_TYPE_EVDO_0:
        return "EVDO_0 ";

    case TelephonyManager.NETWORK_TYPE_EVDO_A:
        return "EVDO_A ";

    case TelephonyManager.NETWORK_TYPE_EVDO_B:
        return "EVDO_B ";

    case TelephonyManager.NETWORK_TYPE_GPRS:
        return "GPRS ";

    case TelephonyManager.NETWORK_TYPE_HSDPA:
        return "HSDPA ";

    case TelephonyManager.NETWORK_TYPE_HSPA:
        return "HSPA ";

    case TelephonyManager.NETWORK_TYPE_HSPAP:
        return "HSPAP ";

    case TelephonyManager.NETWORK_TYPE_HSUPA:
        return "HSUPA ";

    case TelephonyManager.NETWORK_TYPE_IDEN:
        return "IDEN ";

    case TelephonyManager.NETWORK_TYPE_LTE:
        return "LTE ";

    case TelephonyManager.NETWORK_TYPE_UMTS:
        return "UMTS ";

    case TelephonyManager.NETWORK_TYPE_UNKNOWN:
        return "UNKNOWN ";

    default:/*from  w w w . j  a  v  a 2s  . c o m*/
        return "UNKNOWN ";
    }
}

From source file:Main.java

public static int getNetType(Context context) {
    int netWorkType = NETWORK_CLASS_UNKNOWN;

    ConnectivityManager connectivityManager = (ConnectivityManager) context
            .getSystemService(Context.CONNECTIVITY_SERVICE);
    NetworkInfo networkInfo = connectivityManager.getActiveNetworkInfo();

    if (networkInfo != null && networkInfo.isConnected()) {
        int type = networkInfo.getType();

        if (type == ConnectivityManager.TYPE_WIFI) {
            netWorkType = NETWORK_WIFI;//from   ww  w .j ava 2  s . com
        } else if (type == ConnectivityManager.TYPE_MOBILE) {
            TelephonyManager telephonyManager = (TelephonyManager) context
                    .getSystemService(Context.TELEPHONY_SERVICE);
            switch (telephonyManager.getNetworkType()) {
            case TelephonyManager.NETWORK_TYPE_GPRS:
            case TelephonyManager.NETWORK_TYPE_EDGE:
            case TelephonyManager.NETWORK_TYPE_CDMA:
            case TelephonyManager.NETWORK_TYPE_1xRTT:
            case TelephonyManager.NETWORK_TYPE_IDEN:
                return NETWORK_CLASS_2_G;
            case TelephonyManager.NETWORK_TYPE_UMTS:
            case TelephonyManager.NETWORK_TYPE_EVDO_0:
            case TelephonyManager.NETWORK_TYPE_EVDO_A:
            case TelephonyManager.NETWORK_TYPE_HSDPA:
            case TelephonyManager.NETWORK_TYPE_HSUPA:
            case TelephonyManager.NETWORK_TYPE_HSPA:
            case TelephonyManager.NETWORK_TYPE_EVDO_B:
            case TelephonyManager.NETWORK_TYPE_EHRPD:
            case TelephonyManager.NETWORK_TYPE_HSPAP:
                return NETWORK_CLASS_3_G;

            case TelephonyManager.NETWORK_TYPE_LTE:
                return NETWORK_CLASS_4_G;
            default:
                return NETWORK_CLASS_UNKNOWN;
            }
        }
    }

    return netWorkType;
}

From source file:Main.java

public static boolean isWifiEnabled(Context context) {
    ConnectivityManager mgrConn = (ConnectivityManager) context.getSystemService(Context.CONNECTIVITY_SERVICE);
    TelephonyManager mgrTel = (TelephonyManager) context.getSystemService(Context.TELEPHONY_SERVICE);
    return ((mgrConn.getActiveNetworkInfo() != null
            && mgrConn.getActiveNetworkInfo().getState() == NetworkInfo.State.CONNECTED)
            || mgrTel.getNetworkType() == TelephonyManager.NETWORK_TYPE_UMTS);
}

From source file:Main.java

/**
 * Whether is fast mobile network//from   ww w . ja va 2  s.c  o  m
 * 
 * @param context
 * @return
 */
private static boolean isFastMobileNetwork(Context context) {
    TelephonyManager telephonyManager = (TelephonyManager) context.getSystemService(Context.TELEPHONY_SERVICE);
    if (telephonyManager == null) {
        return false;
    }

    switch (telephonyManager.getNetworkType()) {

    case TelephonyManager.NETWORK_TYPE_EVDO_0:
    case TelephonyManager.NETWORK_TYPE_EVDO_A:
    case TelephonyManager.NETWORK_TYPE_HSDPA:
    case TelephonyManager.NETWORK_TYPE_HSPA:
    case TelephonyManager.NETWORK_TYPE_HSUPA:
    case TelephonyManager.NETWORK_TYPE_UMTS:
    case TelephonyManager.NETWORK_TYPE_EHRPD:
    case TelephonyManager.NETWORK_TYPE_EVDO_B:
    case TelephonyManager.NETWORK_TYPE_HSPAP:
    case TelephonyManager.NETWORK_TYPE_LTE:
        return true;
    case TelephonyManager.NETWORK_TYPE_IDEN:
    case TelephonyManager.NETWORK_TYPE_UNKNOWN:
    case TelephonyManager.NETWORK_TYPE_1xRTT:
    case TelephonyManager.NETWORK_TYPE_CDMA:
    case TelephonyManager.NETWORK_TYPE_EDGE:
    case TelephonyManager.NETWORK_TYPE_GPRS:
    default:
        return false;

    }
}

From source file:Main.java

public static boolean isWiFiEnabled(Context context) {
    ConnectivityManager cm = (ConnectivityManager) context.getSystemService(Context.CONNECTIVITY_SERVICE);
    TelephonyManager tm = (TelephonyManager) context.getSystemService(Context.TELEPHONY_SERVICE);
    return ((cm != null && cm.getActiveNetworkInfo() != null
            && cm.getActiveNetworkInfo().getState() == NetworkInfo.State.CONNECTED)
            || tm != null && tm.getNetworkType() == TelephonyManager.NETWORK_TYPE_UMTS);
}