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 int getNetworkType(Context context) {
    TelephonyManager tm = (TelephonyManager) context.getSystemService(Context.TELEPHONY_SERVICE);
    return tm.getNetworkType();
}

From source file:Main.java

/**
 * Checks if is edge./*from  w ww  .  j a  v a2  s .c  o  m*/
 * 
 * @param ctx
 *            the ctx
 * @return true, if is edge
 */
public static boolean isEdge(final Context ctx) {
    TelephonyManager tm = (TelephonyManager) ctx.getSystemService(Context.TELEPHONY_SERVICE);
    return tm.getNetworkType() == TelephonyManager.NETWORK_TYPE_EDGE;
}

From source file:Main.java

/**
 * Checks if is umts./* www  .  ja  v a2  s.c  o  m*/
 * 
 * @param ctx
 *            the ctx
 * @return true, if is umts
 */
public static boolean isUmts(final Context ctx) {
    TelephonyManager tm = (TelephonyManager) ctx.getSystemService(Context.TELEPHONY_SERVICE);
    return tm.getNetworkType() >= TelephonyManager.NETWORK_TYPE_UMTS;
}

From source file:Main.java

public static int getNetworkType(Context context) {
    TelephonyManager telephonyManager = (TelephonyManager) context.getSystemService(Context.TELEPHONY_SERVICE);
    return telephonyManager.getNetworkType();
}

From source file:Main.java

public static boolean is2gNetwork(Context context) {
    TelephonyManager tm = (TelephonyManager) context.getSystemService(Context.TELEPHONY_SERVICE);
    int type = tm.getNetworkType();
    if (type == TelephonyManager.NETWORK_TYPE_GPRS || type == TelephonyManager.NETWORK_TYPE_EDGE) {
        return true;
    }//from ww  w.  jav a  2s  .  c om
    return false;
}

From source file:Main.java

public static String getNetworkType(TelephonyManager tm) {
    switch (tm.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 "HSPA+";
    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";
    default://from  w ww . j a v  a2 s. c  om
        return "unknown";
    }
}

From source file:Main.java

public static boolean checkNetworkConnection(Context context) {
    ConnectivityManager cm = (ConnectivityManager) context.getSystemService(Context.CONNECTIVITY_SERVICE);
    State wifi = cm.getNetworkInfo(ConnectivityManager.TYPE_WIFI).getState();
    if (wifi == State.CONNECTED) {
        return true;
    }/*www.j a v a 2  s .  c  om*/
    State mobile = cm.getNetworkInfo(ConnectivityManager.TYPE_MOBILE).getState();
    if (mobile == State.CONNECTED) {
        TelephonyManager tm = (TelephonyManager) context.getSystemService(Context.TELEPHONY_SERVICE);
        int type = tm.getNetworkType();
        if (type != TelephonyManager.NETWORK_TYPE_CDMA && type != TelephonyManager.NETWORK_TYPE_EDGE
                && type != TelephonyManager.NETWORK_TYPE_GPRS) {
            return true;
        }
    }
    return false;
}

From source file:Main.java

public static String getNetworkTypeName(Context context) {
    int kind = 0;
    try {/*w w w. j  a v  a2  s.  c o m*/
        TelephonyManager tm = (TelephonyManager) context.getSystemService(Context.TELEPHONY_SERVICE);
        kind = tm.getNetworkType();
    } catch (Exception e) {

    }
    return String.valueOf(kind);
}

From source file:Main.java

public static int getMobileNetworkType() {
    if (mAppContext == null)
        return -1;
    TelephonyManager cm = (TelephonyManager) mAppContext.getSystemService(Context.TELEPHONY_SERVICE);
    if (cm == null)
        return -1;
    return cm.getNetworkType();
}

From source file:Main.java

public static String getPhoneNetworkType(TelephonyManager tm) {
    String networkType = "Unknown";
    switch (tm.getNetworkType()) {
    case TelephonyManager.NETWORK_TYPE_1xRTT:
        networkType = "1xRTT:";
        break;//from   w ww . j a  v  a  2  s  . co  m
    case TelephonyManager.NETWORK_TYPE_CDMA:
        networkType = "CDMA:";
        break;
    case TelephonyManager.NETWORK_TYPE_EDGE:
        networkType = "EDGE:";
        break;
    case TelephonyManager.NETWORK_TYPE_EVDO_0:
        networkType = "EVDO_0:";
        break;
    case TelephonyManager.NETWORK_TYPE_EVDO_A:
        networkType = "EVDO_A:";
        break;
    case TelephonyManager.NETWORK_TYPE_GPRS:
        networkType = "GPRS:";
        break;
    case TelephonyManager.NETWORK_TYPE_HSDPA:
        networkType = "HSDPA:";
        break;
    case TelephonyManager.NETWORK_TYPE_HSPA:
        networkType = "HSPA:";
        break;
    case TelephonyManager.NETWORK_TYPE_HSUPA:
        networkType = "HSUPA:";
        break;
    case TelephonyManager.NETWORK_TYPE_UMTS:
        networkType = "UMTS:";
        break;
    case TelephonyManager.NETWORK_TYPE_UNKNOWN:
        networkType = "UNKNOWN:";
        break;
    default:
        break;
    }
    return networkType + tm.getNetworkType();
}