Java Code Examples for android.telephony.TelephonyManager#getNetworkType()

The following examples show how to use android.telephony.TelephonyManager#getNetworkType() . These examples are extracted from open source projects. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
public MobileNetworkType getMobileNetworkType() {

    if (connectivityStatus != ConnectivityStatus.MOBILE_CONNECTED) {
      return MobileNetworkType.UNKNOWN;
    }

    TelephonyManager telephonyManager =
        (TelephonyManager) context.getSystemService(Context.TELEPHONY_SERVICE);

    switch (telephonyManager.getNetworkType()) {
      case (TelephonyManager.NETWORK_TYPE_LTE):
        return MobileNetworkType.LTE;
      case (TelephonyManager.NETWORK_TYPE_HSPAP):
        return MobileNetworkType.HSPAP;
      case (TelephonyManager.NETWORK_TYPE_EDGE):
        return MobileNetworkType.EDGE;
      case (TelephonyManager.NETWORK_TYPE_GPRS):
        return MobileNetworkType.GPRS;
      default:
        return MobileNetworkType.UNKNOWN;
    }
  }
 
Example 2
Source Project: NewsMe   File: VDMobileUtil.java    License: Apache License 2.0 6 votes vote down vote up
public static int getMobileDetail(Context context) {
    ConnectivityManager conn = (ConnectivityManager) context.getSystemService(Context.CONNECTIVITY_SERVICE);
    if (conn == null) {
        return NONE;
    }
    NetworkInfo networkInfo = conn.getActiveNetworkInfo();
    if (networkInfo == null) {
        // 网络不可用
        return NONE;
    }
    if (networkInfo.getType() == ConnectivityManager.TYPE_WIFI) {
        return WIFI;
    } else if (networkInfo.getType() == ConnectivityManager.TYPE_MOBILE) {
        TelephonyManager telephonyManager = (TelephonyManager) context.getSystemService(Context.TELEPHONY_SERVICE);
        return telephonyManager.getNetworkType();
    }
    return NONE;
}
 
Example 3
Source Project: RxTools-master   File: RxDeviceTool.java    License: Apache License 2.0 6 votes vote down vote up
/**
 * 获取手机状态信息
 * <p>需添加权限 {@code <uses-permission android:name="android.permission.READ_PHONE_STATE"/>}</p>
 *
 * @param context 上下文
 * @return DeviceId(IMEI) = 99000311726612<br>
 * DeviceSoftwareVersion = 00<br>
 * Line1Number =<br>
 * NetworkCountryIso = cn<br>
 * NetworkOperator = 46003<br>
 * NetworkOperatorName = 中国电信<br>
 * NetworkType = 6<br>
 * honeType = 2<br>
 * SimCountryIso = cn<br>
 * SimOperator = 46003<br>
 * SimOperatorName = 中国电信<br>
 * SimSerialNumber = 89860315045710604022<br>
 * SimState = 5<br>
 * SubscriberId(IMSI) = 460030419724900<br>
 * VoiceMailNumber = *86<br>
 */
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;
}
 
Example 4
Source Project: Cangol-appcore   File: DeviceInfo.java    License: Apache License 2.0 6 votes vote down vote up
public static int getNetworkType(Context context) {
    int networkType = TelephonyManager.NETWORK_TYPE_UNKNOWN;
    try {
        final NetworkInfo network = ((ConnectivityManager) context.getApplicationContext().getSystemService(Context.CONNECTIVITY_SERVICE))
                .getActiveNetworkInfo();
        if (network != null && network.isAvailable() && network.isConnected()) {
            final int type = network.getType();
            if (type == ConnectivityManager.TYPE_WIFI) {
                networkType = NETWORK_TYPE_WIFI;
            } else if (type == ConnectivityManager.TYPE_MOBILE) {
                final TelephonyManager telephonyManager = (TelephonyManager) context.getApplicationContext().getSystemService(Context.TELEPHONY_SERVICE);
                networkType = telephonyManager.getNetworkType();
            }
        } else {
            networkType = NETWORK_TYPE_UNAVAILABLE;
        }
    } catch (Exception e) {
        Log.e("getNetworkType", "" + e.getMessage(), e);
    }

    return networkType;
}
 
Example 5
/**
 * Called from native code to request reference location info
 */
private void requestRefLocation() {
    TelephonyManager phone = (TelephonyManager)
            mContext.getSystemService(Context.TELEPHONY_SERVICE);
    final int phoneType = phone.getPhoneType();
    if (phoneType == TelephonyManager.PHONE_TYPE_GSM) {
        GsmCellLocation gsm_cell = (GsmCellLocation) phone.getCellLocation();
        if ((gsm_cell != null) && (phone.getNetworkOperator() != null)
                && (phone.getNetworkOperator().length() > 3)) {
            int type;
            int mcc = Integer.parseInt(phone.getNetworkOperator().substring(0, 3));
            int mnc = Integer.parseInt(phone.getNetworkOperator().substring(3));
            int networkType = phone.getNetworkType();
            if (networkType == TelephonyManager.NETWORK_TYPE_UMTS
                    || networkType == TelephonyManager.NETWORK_TYPE_HSDPA
                    || networkType == TelephonyManager.NETWORK_TYPE_HSUPA
                    || networkType == TelephonyManager.NETWORK_TYPE_HSPA
                    || networkType == TelephonyManager.NETWORK_TYPE_HSPAP) {
                type = AGPS_REF_LOCATION_TYPE_UMTS_CELLID;
            } else {
                type = AGPS_REF_LOCATION_TYPE_GSM_CELLID;
            }
            native_agps_set_ref_location_cellid(type, mcc, mnc,
                    gsm_cell.getLac(), gsm_cell.getCid());
        } else {
            Log.e(TAG, "Error getting cell location info.");
        }
    } else if (phoneType == TelephonyManager.PHONE_TYPE_CDMA) {
        Log.e(TAG, "CDMA not supported.");
    }
}
 
Example 6
Source Project: Aria   File: NetUtils.java    License: Apache License 2.0 5 votes vote down vote up
private 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;
  }
}
 
Example 7
Source Project: MiBandDecompiled   File: l.java    License: Apache License 2.0 5 votes vote down vote up
public static String a(TelephonyManager telephonymanager)
{
    int i = 0;
    if (telephonymanager != null)
    {
        i = telephonymanager.getNetworkType();
    }
    return (String)f.l.get(i, "UNKNOWN");
}
 
Example 8
/**
 * Determines the type of network this device is connected to.
 *
 * @param context the context used to access the device's WIFI
 * @param telephonyManager The manager used to access telephony info
 * @return The type of network, or unknown if the information is unavailable
 */
public static String getNetworkType(final Context context, final TelephonyManager telephonyManager)
{
    try
    {
        if (context.getPackageManager().checkPermission(permission.ACCESS_WIFI_STATE, context.getPackageName()) == PackageManager.PERMISSION_GRANTED)
        {
            final NetworkInfo wifiInfo = ((ConnectivityManager) context.getSystemService(Context.CONNECTIVITY_SERVICE)).getNetworkInfo(ConnectivityManager.TYPE_WIFI);
            if (null != wifiInfo && wifiInfo.isConnectedOrConnecting())
            {
                return "wifi"; //$NON-NLS-1$
            }
        }
        else
        {
            if (Constants.IS_LOGGABLE)
            {
                Log.w(Constants.LOG_TAG, "Application does not have one more more of the following permissions: ACCESS_WIFI_STATE. Determining Wi-Fi connectivity is unavailable"); //$NON-NLS-1$
            }
        }
    }
    catch (final SecurityException e)
    {
        /*
         * Although the documentation doesn't declare it, sometimes the ConnectivityService will throw an exception for
         * permission ACCESS_NETWORK_STATE
         */
        if (Constants.IS_LOGGABLE)
        {
            Log.w(Constants.LOG_TAG, "Application does not have the permission ACCESS_NETWORK_STATE. Determining Wi-Fi connectivity is unavailable", e); //$NON-NLS-1$
        }
    }

    return "android_network_type_" + telephonyManager.getNetworkType(); //$NON-NLS-1$
}
 
Example 9
Source Project: EasyFeedback   File: DeviceInfo.java    License: Apache License 2.0 5 votes vote down vote up
public static String getDataType(Context activity) {
    String type = "Mobile Data";
    TelephonyManager tm = (TelephonyManager) activity.getSystemService(Context.TELEPHONY_SERVICE);
    switch (tm.getNetworkType()) {
        case TelephonyManager.NETWORK_TYPE_HSDPA:
            type = "Mobile Data 3G";
            Log.d("Type", "3g");
            // for 3g HSDPA networktype will be return as
            // per testing(real) in device with 3g enable
            // data
            // and speed will also matters to decide 3g network type
            break;
        case TelephonyManager.NETWORK_TYPE_HSPAP:
            type = "Mobile Data 4G";
            Log.d("Type", "4g");
            // No specification for the 4g but from wiki
            // i found(HSPAP used in 4g)
            break;
        case TelephonyManager.NETWORK_TYPE_GPRS:
            type = "Mobile Data GPRS";
            Log.d("Type", "GPRS");
            break;
        case TelephonyManager.NETWORK_TYPE_EDGE:
            type = "Mobile Data EDGE 2G";
            Log.d("Type", "EDGE 2g");
            break;

    }

    return type;
}
 
Example 10
Source Project: BaseProject   File: NetHelper.java    License: Apache License 2.0 5 votes vote down vote up
private 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;
    }
}
 
Example 11
Source Project: LRecyclerView   File: ImageLoaderUtil.java    License: Apache License 2.0 5 votes vote down vote up
private 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;
    }
}
 
Example 12
/**<br/>
 * http://www.binkery.com/post/368.html<br/>*/
private static boolean isSlowMobileNetwork(Context context){
	TelephonyManager telephonyManager = (TelephonyManager) context
			.getSystemService(Context.TELEPHONY_SERVICE);
	boolean result=true;
	if(telephonyManager!=null){
		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:
				result=true;//2g
				break;
			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:
				result=false;//3g
				break;
			case TelephonyManager.NETWORK_TYPE_LTE:
				result=false;//4g
				break;
			case TelephonyManager.NETWORK_TYPE_UNKNOWN:
				result=true;
				break;
		}
	}else{
		result=true;
	}
	return result;
}
 
Example 13
private String getNetworkType(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 CONNECTIVITY_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 CONNECTIVITY_3G;
    case TelephonyManager.NETWORK_TYPE_LTE:
      return CONNECTIVITY_4G;
    default:
      return CONNECTIVITY_UNKNOWN;
  }
}
 
Example 14
Source Project: Common   File: NetworkUtils.java    License: Apache License 2.0 5 votes vote down vote up
private static int telephonyNetworkType(Context context) {
    TelephonyManager telephonyManager = (TelephonyManager) context.getSystemService(Context.TELEPHONY_SERVICE);
    int networkType = telephonyManager.getNetworkType();
    if (networkType < 0 || networkType >= NETWORK_MATCH_TABLE.length) {
        networkType = 0;
    }

    return networkType;
}
 
Example 15
Source Project: AndroidHttpCapture   File: LDNetUtil.java    License: MIT License 4 votes vote down vote up
private static String mobileNetworkType(Context context) {
  TelephonyManager telephonyManager = (TelephonyManager) context
      .getSystemService(Context.TELEPHONY_SERVICE);
  if (telephonyManager == null) {
    return "TM==null";
  }
  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";
  }
}
 
Example 16
/**
 * Get the current connection type from the {@link ConnectivityManager}
 *
 * @param ctx the application Context
 * @return the integer constant of the connection type
 */
public static int getConnectionType(final Context ctx) {
    final NetworkInfo info = getActiveNetworkInfo(ctx);
    final int infoType = info.getType();

    switch (infoType) {

        case ConnectivityManager.TYPE_WIFI:
        case ConnectivityManager.TYPE_ETHERNET:
        case ConnectivityManager.TYPE_BLUETOOTH:
            if (DEBUG) {
                MyLog.i(CLS_NAME, "getConnectionType: CONNECTION_TYPE_WIFI");
            }
            return CONNECTION_TYPE_WIFI;

        case ConnectivityManager.TYPE_WIMAX:
            if (DEBUG) {
                MyLog.i(CLS_NAME, "getConnectionType: CONNECTION_TYPE_4G");
            }
            return CONNECTION_TYPE_4G;

        case ConnectivityManager.TYPE_MOBILE:

            final TelephonyManager tm = (TelephonyManager) ctx.getSystemService(Context.TELEPHONY_SERVICE);
            final int networkType = tm.getNetworkType();

            switch (networkType) {

                case TelephonyManager.NETWORK_TYPE_GPRS: // ~ 100 kbps
                case TelephonyManager.NETWORK_TYPE_EDGE: // ~ 50-100 kbps
                case TelephonyManager.NETWORK_TYPE_CDMA: // ~ 14-64 kbps
                case TelephonyManager.NETWORK_TYPE_1xRTT: // ~ 50-100 kbps
                case TelephonyManager.NETWORK_TYPE_IDEN: // ~25 kbps
                    if (DEBUG) {
                        MyLog.i(CLS_NAME, "getConnectionType: CONNECTION_TYPE_2G");
                    }
                    return CONNECTION_TYPE_2G;

                case TelephonyManager.NETWORK_TYPE_UMTS: // ~ 400-7000 kbps
                case TelephonyManager.NETWORK_TYPE_EVDO_0: // ~ 400-1000 kbps
                case TelephonyManager.NETWORK_TYPE_EVDO_A: // ~ 600-1400 kbps
                case TelephonyManager.NETWORK_TYPE_HSDPA: // ~ 2-14 Mbps
                case TelephonyManager.NETWORK_TYPE_HSUPA: // ~ 1-23 Mbps
                case TelephonyManager.NETWORK_TYPE_HSPA: // ~ 700-1700 kbps
                case TelephonyManager.NETWORK_TYPE_EVDO_B: // ~ 5 Mbps
                case TelephonyManager.NETWORK_TYPE_EHRPD: // ~ 1-2 Mbps
                    if (DEBUG) {
                        MyLog.i(CLS_NAME, "getConnectionType: CONNECTION_TYPE_3G");
                    }
                    return CONNECTION_TYPE_3G;

                case TelephonyManager.NETWORK_TYPE_LTE: // ~ 10+ Mbps
                    if (DEBUG) {
                        MyLog.i(CLS_NAME, "getConnectionType: CONNECTION_TYPE_4G");
                    }
                    return CONNECTION_TYPE_4G;
                case TelephonyManager.NETWORK_TYPE_HSPAP: // ~ 10-20 Mbps
                    if (DEBUG) {
                        MyLog.i(CLS_NAME, "getConnectionType: CONNECTION_TYPE_4G");
                    }
                    return CONNECTION_TYPE_4G;

                default:
                    if (DEBUG) {
                        MyLog.w(CLS_NAME, "getConnectionType: CONNECTION_TYPE_UNKNOWN");
                    }
                    return CONNECTION_TYPE_UNKNOWN;

            }

        default:
            if (DEBUG) {
                MyLog.w(CLS_NAME, "getConnectionType: CONNECTION_TYPE_UNKNOWN");
            }
            return CONNECTION_TYPE_UNKNOWN;
    }
}
 
Example 17
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;
	}
}
 
Example 18
Source Project: Ticket-Analysis   File: PhoneUtils.java    License: MIT License 4 votes vote down vote up
/**
 * 获取手机状态信息
 * <p>需添加权限<uses-permission android:name="android.permission.READ_PHONE_STATE"/>
 * <p>返回如下
 * <pre>
 * DeviceId(IMEI) = 99000311726612
 * DeviceSoftwareVersion = 00
 * Line1Number =
 * NetworkCountryIso = cn
 * NetworkOperator = 46003
 * NetworkOperatorName = 中国电信
 * NetworkType = 6
 * honeType = 2
 * SimCountryIso = cn
 * SimOperator = 46003
 * SimOperatorName = 中国电信
 * SimSerialNumber = 89860315045710604022
 * SimState = 5
 * SubscriberId(IMSI) = 460030419724900
 * VoiceMailNumber = *86
 * <pre/>
 */
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;
}
 
Example 19
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:
            return false;
    }
}
 
Example 20
Source Project: XDroidMvp   File: Kits.java    License: MIT License 4 votes vote down vote up
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;
    }
}