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

/**
 * Whether is fast mobile network/*from ww  w.java  2  s  .  c o m*/
 */

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_1xRTT:
        return false;
    case TelephonyManager.NETWORK_TYPE_CDMA:
        return false;
    case TelephonyManager.NETWORK_TYPE_EDGE:
        return false;
    case TelephonyManager.NETWORK_TYPE_EVDO_0:
        return true;
    case TelephonyManager.NETWORK_TYPE_EVDO_A:
        return true;
    case TelephonyManager.NETWORK_TYPE_GPRS:
        return false;
    case TelephonyManager.NETWORK_TYPE_HSDPA:
        return true;
    case TelephonyManager.NETWORK_TYPE_HSPA:
        return true;
    case TelephonyManager.NETWORK_TYPE_HSUPA:
        return true;
    case TelephonyManager.NETWORK_TYPE_UMTS:
        return true;
    case TelephonyManager.NETWORK_TYPE_EHRPD:
        return true;
    case TelephonyManager.NETWORK_TYPE_EVDO_B:
        return true;
    case TelephonyManager.NETWORK_TYPE_HSPAP:
        return true;
    case TelephonyManager.NETWORK_TYPE_IDEN:
        return false;
    case TelephonyManager.NETWORK_TYPE_LTE:
        return true;
    case TelephonyManager.NETWORK_TYPE_UNKNOWN:
        return false;
    default:
        return false;
    }
}

From source file:Main.java

public static boolean isConnectivity(Context context) {

    ConnectivityManager connectivityManager = (ConnectivityManager) context
            .getSystemService(Context.CONNECTIVITY_SERVICE);
    TelephonyManager telephonyManager = (TelephonyManager) context.getSystemService(Context.TELEPHONY_SERVICE);
    return ((connectivityManager.getActiveNetworkInfo() != null
            && connectivityManager.getActiveNetworkInfo().getState() == NetworkInfo.State.CONNECTED)
            || telephonyManager.getNetworkType() == TelephonyManager.NETWORK_TYPE_UMTS);
}

From source file:Main.java

private static String mobileNetworkType(Context context) {
    TelephonyManager telephonyManager = (TelephonyManager) context.getSystemService(Context.TELEPHONY_SERVICE);
    if (telephonyManager == null) {
        return "TM==null";
    }/* w w w . j  a  va 2s.com*/
    switch (telephonyManager.getNetworkType()) {
    case TelephonyManager.NETWORK_TYPE_1xRTT:// ~ 50-100 kbps
        return "2G";
    case TelephonyManager.NETWORK_TYPE_CDMA:// ~ 14-64 kbps
        return "2G";
    case TelephonyManager.NETWORK_TYPE_EDGE:// ~ 50-100 kbps
        return "2G";
    case TelephonyManager.NETWORK_TYPE_EVDO_0:// ~ 400-1000 kbps
        return "3G";
    case TelephonyManager.NETWORK_TYPE_EVDO_A:// ~ 600-1400 kbps
        return "3G";
    case TelephonyManager.NETWORK_TYPE_GPRS:// ~ 100 kbps
        return "2G";
    case TelephonyManager.NETWORK_TYPE_HSDPA:// ~ 2-14 Mbps
        return "3G";
    case TelephonyManager.NETWORK_TYPE_HSPA:// ~ 700-1700 kbps
        return "3G";
    case TelephonyManager.NETWORK_TYPE_HSUPA: // ~ 1-23 Mbps
        return "3G";
    case TelephonyManager.NETWORK_TYPE_UMTS:// ~ 400-7000 kbps
        return "3G";
    case TelephonyManager.NETWORK_TYPE_EHRPD:// ~ 1-2 Mbps
        return "3G";
    case TelephonyManager.NETWORK_TYPE_EVDO_B: // ~ 5 Mbps
        return "3G";
    case TelephonyManager.NETWORK_TYPE_HSPAP:// ~ 10-20 Mbps
        return "3G";
    case TelephonyManager.NETWORK_TYPE_IDEN:// ~25 kbps
        return "2G";
    case TelephonyManager.NETWORK_TYPE_LTE:// ~ 10+ Mbps
        return "4G";
    case TelephonyManager.NETWORK_TYPE_UNKNOWN:
        return "UNKNOWN";
    default:
        return "4G";
    }
}

From source file:com.frame.network.utils.NetworkUtil.java

@TargetApi(11)
public static boolean is4GNetwork(Context cxt) {
    boolean isOpened4G = false;
    TelephonyManager telephonyManager = (TelephonyManager) cxt.getSystemService(Context.TELEPHONY_SERVICE);
    if (Build.VERSION.SDK_INT >= 11) {
        isOpened4G = telephonyManager.getNetworkType() == TelephonyManager.NETWORK_TYPE_LTE;
    }//from   w w w  .j av  a  2  s  . c  o m
    boolean isMobile = false;
    ConnectivityManager cm = (ConnectivityManager) cxt.getSystemService(Context.CONNECTIVITY_SERVICE);
    NetworkInfo info = cm.getNetworkInfo(ConnectivityManager.TYPE_MOBILE);
    isMobile = info == null ? false : info.isConnected();
    return isOpened4G && isMobile;
}

From source file:Main.java

public static boolean isFastMobileNetwork(Context context) {
    TelephonyManager telephonyManager = (TelephonyManager) context.getSystemService(Context.TELEPHONY_SERVICE);
    // System.out.println("request_http netType networkType = "
    // + telephonyManager.getNetworkType());
    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://www .  ja v  a2s  .c o  m
        return false;
    }
}

From source file:Main.java

/**
 * Whether is fast mobile network//from w  w w .j  ava 2s.  c om
 * 
 * @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_1xRTT:
        return false;
    case TelephonyManager.NETWORK_TYPE_CDMA:
        return false;
    case TelephonyManager.NETWORK_TYPE_EDGE:
        return false;
    case TelephonyManager.NETWORK_TYPE_EVDO_0:
        return true;
    case TelephonyManager.NETWORK_TYPE_EVDO_A:
        return true;
    case TelephonyManager.NETWORK_TYPE_GPRS:
        return false;
    case TelephonyManager.NETWORK_TYPE_HSDPA:
        return true;
    case TelephonyManager.NETWORK_TYPE_HSPA:
        return true;
    case TelephonyManager.NETWORK_TYPE_HSUPA:
        return true;
    case TelephonyManager.NETWORK_TYPE_UMTS:
        return true;
    case TelephonyManager.NETWORK_TYPE_EHRPD:
        return true;
    case TelephonyManager.NETWORK_TYPE_EVDO_B:
        return true;
    case TelephonyManager.NETWORK_TYPE_HSPAP:
        return true;
    case TelephonyManager.NETWORK_TYPE_IDEN:
        return false;
    case TelephonyManager.NETWORK_TYPE_LTE:
        return true;
    case TelephonyManager.NETWORK_TYPE_UNKNOWN:
        return false;
    default:
        return false;
    }
}

From source file:com.apptentive.android.sdk.storage.DeviceManager.java

private static Device generateNewDevice(Context context) {
    Device device = new Device();

    // First, get all the information we can load from static resources.
    device.setOsName("Android");
    device.setOsVersion(Build.VERSION.RELEASE);
    device.setOsBuild(Build.VERSION.INCREMENTAL);
    device.setOsApiLevel(String.valueOf(Build.VERSION.SDK_INT));
    device.setManufacturer(Build.MANUFACTURER);
    device.setModel(Build.MODEL);//from ww w  .  j  a v  a2  s.c  o  m
    device.setBoard(Build.BOARD);
    device.setProduct(Build.PRODUCT);
    device.setBrand(Build.BRAND);
    device.setCpu(Build.CPU_ABI);
    device.setDevice(Build.DEVICE);
    device.setUuid(GlobalInfo.androidId);
    device.setBuildType(Build.TYPE);
    device.setBuildId(Build.ID);

    // Second, set the stuff that requires querying system services.
    TelephonyManager tm = ((TelephonyManager) (context.getSystemService(Context.TELEPHONY_SERVICE)));
    device.setCarrier(tm.getSimOperatorName());
    device.setCurrentCarrier(tm.getNetworkOperatorName());
    device.setNetworkType(Constants.networkTypeAsString(tm.getNetworkType()));

    // Finally, use reflection to try loading from APIs that are not available on all Android versions.
    device.setBootloaderVersion(Reflection.getBootloaderVersion());
    device.setRadioVersion(Reflection.getRadioVersion());

    device.setLocaleCountryCode(Locale.getDefault().getCountry());
    device.setLocaleLanguageCode(Locale.getDefault().getLanguage());
    device.setLocaleRaw(Locale.getDefault().toString());
    device.setUtcOffset(String.valueOf((TimeZone.getDefault().getRawOffset() / 1000)));
    return device;
}

From source file:com.wiyun.engine.network.Network.java

static int getNetworkType() {
    NetworkType type = NetworkType.NONE;

    if (isWifiConnected()) {
        type = NetworkType.WIFI;/*from  w  w  w  . j a v  a  2s.  c  om*/
    } else {
        Context context = Director.getInstance().getContext();
        TelephonyManager tm = (TelephonyManager) context.getSystemService(Context.TELEPHONY_SERVICE);
        if (tm == null)
            type = NetworkType.NONE;
        else {
            int t = tm.getNetworkType();
            if (t == TelephonyManager.NETWORK_TYPE_GPRS || t == TelephonyManager.NETWORK_TYPE_UNKNOWN)
                type = NetworkType.G2;
            else if (t == TelephonyManager.NETWORK_TYPE_EDGE)
                type = NetworkType.EDGE;
            else
                type = NetworkType.G3;
        }
    }

    return type.ordinal();
}

From source file:Main.java

public static String getPhoneStatus(Context context) {
    TelephonyManager tm = (TelephonyManager) context.getSystemService(Context.TELEPHONY_SERVICE);
    String str = "";
    str += "DeviceId(IMEI) = " + tm.getDeviceId() + "\n";
    str += "DeviceSoftwareVersion = " + tm.getDeviceSoftwareVersion() + "\n";
    str += "Line1Number = " + tm.getLine1Number() + "\n";
    str += "NetworkCountryIso = " + tm.getNetworkCountryIso() + "\n";
    str += "NetworkOperator = " + tm.getNetworkOperator() + "\n";
    str += "NetworkOperatorName = " + tm.getNetworkOperatorName() + "\n";
    str += "NetworkType = " + tm.getNetworkType() + "\n";
    str += "honeType = " + tm.getPhoneType() + "\n";
    str += "SimCountryIso = " + tm.getSimCountryIso() + "\n";
    str += "SimOperator = " + tm.getSimOperator() + "\n";
    str += "SimOperatorName = " + tm.getSimOperatorName() + "\n";
    str += "SimSerialNumber = " + tm.getSimSerialNumber() + "\n";
    str += "SimState = " + tm.getSimState() + "\n";
    str += "SubscriberId(IMSI) = " + tm.getSubscriberId() + "\n";
    str += "VoiceMailNumber = " + tm.getVoiceMailNumber() + "\n";
    return str;/* www.  ja  va  2 s. co m*/
}

From source file:Main.java

public static String getDeviceInfo(Context context) {
    TelephonyManager tm = (TelephonyManager) context.getSystemService(Context.TELEPHONY_SERVICE);
    StringBuilder sb = new StringBuilder();
    sb.append("\nDeviceId(IMEI) = " + tm.getDeviceId());
    sb.append("\nDeviceSoftwareVersion = " + tm.getDeviceSoftwareVersion());
    sb.append("\nLine1Number = " + tm.getLine1Number());
    sb.append("\nNetworkCountryIso = " + tm.getNetworkCountryIso());
    sb.append("\nNetworkOperator = " + tm.getNetworkOperator());
    sb.append("\nNetworkOperatorName = " + tm.getNetworkOperatorName());
    sb.append("\nNetworkType = " + tm.getNetworkType());
    sb.append("\nPhoneType = " + tm.getPhoneType());
    sb.append("\nSimCountryIso = " + tm.getSimCountryIso());
    sb.append("\nSimOperator = " + tm.getSimOperator());
    sb.append("\nSimOperatorName = " + tm.getSimOperatorName());
    sb.append("\nSimSerialNumber = " + tm.getSimSerialNumber());
    sb.append("\nSimState = " + tm.getSimState());
    sb.append("\nSubscriberId(IMSI) = " + tm.getSubscriberId());
    sb.append("\nVoiceMailNumber = " + tm.getVoiceMailNumber());

    return sb.toString();
}