Java Code Examples for android.telephony.TelephonyManager#NETWORK_TYPE_GPRS

The following examples show how to use android.telephony.TelephonyManager#NETWORK_TYPE_GPRS . 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
Source File: Depr_CellsInfoDataCollector.java    From DataLogger with MIT License 6 votes vote down vote up
private static String networkTypeGeneral(int networkType) {
    switch (networkType) {
        case TelephonyManager.NETWORK_TYPE_EHRPD:
        case TelephonyManager.NETWORK_TYPE_LTE:
            return "4G";
        case TelephonyManager.NETWORK_TYPE_HSDPA:
        case TelephonyManager.NETWORK_TYPE_HSPA:
        case TelephonyManager.NETWORK_TYPE_HSPAP:
        case TelephonyManager.NETWORK_TYPE_HSUPA:
        case TelephonyManager.NETWORK_TYPE_UMTS:
            return "3G";
        case TelephonyManager.NETWORK_TYPE_EDGE:
        case TelephonyManager.NETWORK_TYPE_GPRS:
        case TelephonyManager.NETWORK_TYPE_IDEN:
            return "2G";
        case TelephonyManager.NETWORK_TYPE_1xRTT:
        case TelephonyManager.NETWORK_TYPE_CDMA:
        case TelephonyManager.NETWORK_TYPE_EVDO_0:
        case TelephonyManager.NETWORK_TYPE_EVDO_A:
        case TelephonyManager.NETWORK_TYPE_EVDO_B:
            return "CDMA";
        case TelephonyManager.NETWORK_TYPE_UNKNOWN:
        default:
            return "Unknown";
    }
}
 
Example 2
Source File: DeviceInfo.java    From clevertap-android-sdk with MIT License 5 votes vote down vote up
private String getNetworkType() {
    TelephonyManager mTelephonyManager = (TelephonyManager)
            context.getSystemService(Context.TELEPHONY_SERVICE);
    if (mTelephonyManager == null) {
        return null;
    }
    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:
            return null;
    }
}
 
Example 3
Source File: NetworkTypeUtils.java    From TowerCollector with Mozilla Public License 2.0 5 votes vote down vote up
public static NetworkGroup getNetworkGroup(int networkType) {
    switch (networkType) {
        case TelephonyManager.NETWORK_TYPE_GSM:
        case TelephonyManager.NETWORK_TYPE_GPRS:
        case TelephonyManager.NETWORK_TYPE_EDGE:
            return NetworkGroup.Gsm;
        case TelephonyManager.NETWORK_TYPE_UMTS:
        case TelephonyManager.NETWORK_TYPE_HSPA:
        case TelephonyManager.NETWORK_TYPE_HSDPA:
        case TelephonyManager.NETWORK_TYPE_HSUPA:
        case TelephonyManager.NETWORK_TYPE_HSPAP:
            return NetworkGroup.Wcdma;
        case TelephonyManager.NETWORK_TYPE_1xRTT:
        case TelephonyManager.NETWORK_TYPE_CDMA:
        case TelephonyManager.NETWORK_TYPE_EHRPD:
        case TelephonyManager.NETWORK_TYPE_EVDO_0:
        case TelephonyManager.NETWORK_TYPE_EVDO_A:
        case TelephonyManager.NETWORK_TYPE_EVDO_B:
            return NetworkGroup.Cdma;
        case TelephonyManager.NETWORK_TYPE_LTE:
            return NetworkGroup.Lte;
        case TelephonyManager.NETWORK_TYPE_TD_SCDMA:
            return NetworkGroup.Tdscdma;
        case TelephonyManager.NETWORK_TYPE_NR:
            return NetworkGroup.Nr;
        case TelephonyManager.NETWORK_TYPE_IDEN:
        case TelephonyManager.NETWORK_TYPE_UNKNOWN:
        case TelephonyManager.NETWORK_TYPE_IWLAN:
        default:
            return NetworkGroup.Unknown;
    }
}
 
Example 4
Source File: ConcatSourceProvider.java    From ParsingPlayer with GNU Lesser General Public License v2.1 5 votes vote down vote up
private
@Quality
int getHdByNetwork() {
    ConnectivityManager cm = (ConnectivityManager) mContext.get().getSystemService(Context.CONNECTIVITY_SERVICE);
    NetworkInfo networkInfo = cm.getActiveNetworkInfo();
    if (networkInfo == null || !networkInfo.isConnected()) {
        LogUtil.e(TAG, "No networking found");
        makeToast();
        return VideoInfoImpl.HD_UNSPECIFIED;
    }
    switch (networkInfo.getType()) {
        case ConnectivityManager.TYPE_WIFI:
        case ConnectivityManager.TYPE_WIMAX:
        case ConnectivityManager.TYPE_ETHERNET:
            return HD_HIGH;
        case ConnectivityManager.TYPE_MOBILE:
            switch (networkInfo.getSubtype()) {
                case TelephonyManager.NETWORK_TYPE_LTE:
                case TelephonyManager.NETWORK_TYPE_HSPAP:
                case TelephonyManager.NETWORK_TYPE_EHRPD:
                    return HD_STANDARD;
                case TelephonyManager.NETWORK_TYPE_UMTS: // 3G
                case TelephonyManager.NETWORK_TYPE_CDMA:
                case TelephonyManager.NETWORK_TYPE_EVDO_0:
                case TelephonyManager.NETWORK_TYPE_EVDO_A:
                case TelephonyManager.NETWORK_TYPE_EVDO_B:
                    return HD_MEDIUM;
                case TelephonyManager.NETWORK_TYPE_GPRS: // 2G
                case TelephonyManager.NETWORK_TYPE_EDGE:
                    return HD_LOW;
                default:
                    return HD_LOW;
            }
        default:
            return HD_LOW;
    }
}
 
Example 5
Source File: Util.java    From TelePlus-Android with GNU General Public License v2.0 5 votes vote down vote up
private static @C.NetworkType int getMobileNetworkType(NetworkInfo networkInfo) {
  switch (networkInfo.getSubtype()) {
    case TelephonyManager.NETWORK_TYPE_EDGE:
    case TelephonyManager.NETWORK_TYPE_GPRS:
      return C.NETWORK_TYPE_2G;
    case TelephonyManager.NETWORK_TYPE_1xRTT:
    case TelephonyManager.NETWORK_TYPE_CDMA:
    case TelephonyManager.NETWORK_TYPE_EVDO_0:
    case TelephonyManager.NETWORK_TYPE_EVDO_A:
    case TelephonyManager.NETWORK_TYPE_EVDO_B:
    case TelephonyManager.NETWORK_TYPE_HSDPA:
    case TelephonyManager.NETWORK_TYPE_HSPA:
    case TelephonyManager.NETWORK_TYPE_HSUPA:
    case TelephonyManager.NETWORK_TYPE_IDEN:
    case TelephonyManager.NETWORK_TYPE_UMTS:
    case TelephonyManager.NETWORK_TYPE_EHRPD:
    case TelephonyManager.NETWORK_TYPE_HSPAP:
    case TelephonyManager.NETWORK_TYPE_TD_SCDMA:
      return C.NETWORK_TYPE_3G;
    case TelephonyManager.NETWORK_TYPE_LTE:
      return C.NETWORK_TYPE_4G;
    case TelephonyManager.NETWORK_TYPE_IWLAN:
      return C.NETWORK_TYPE_WIFI;
    case TelephonyManager.NETWORK_TYPE_GSM:
    case TelephonyManager.NETWORK_TYPE_UNKNOWN:
    default: // Future mobile network types.
      return C.NETWORK_TYPE_CELLULAR_UNKNOWN;
  }
}
 
Example 6
Source File: NetworkChecker.java    From Kalle with Apache License 2.0 5 votes vote down vote up
private static boolean isMobileSubType(NetType netType, NetworkInfo networkInfo) {
    switch (networkInfo.getType()) {
        case TelephonyManager.NETWORK_TYPE_GSM:
        case TelephonyManager.NETWORK_TYPE_GPRS:
        case TelephonyManager.NETWORK_TYPE_CDMA:
        case TelephonyManager.NETWORK_TYPE_EDGE:
        case TelephonyManager.NETWORK_TYPE_1xRTT:
        case TelephonyManager.NETWORK_TYPE_IDEN: {
            return netType == Mobile2G;
        }
        case TelephonyManager.NETWORK_TYPE_TD_SCDMA:
        case TelephonyManager.NETWORK_TYPE_EVDO_A:
        case TelephonyManager.NETWORK_TYPE_UMTS:
        case TelephonyManager.NETWORK_TYPE_EVDO_0:
        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 netType == Mobile3G;
        }
        case TelephonyManager.NETWORK_TYPE_IWLAN:
        case TelephonyManager.NETWORK_TYPE_LTE: {
            return netType == Mobile4G;
        }
        default: {
            String subtypeName = networkInfo.getSubtypeName();
            if (subtypeName.equalsIgnoreCase("TD-SCDMA")
                    || subtypeName.equalsIgnoreCase("WCDMA")
                    || subtypeName.equalsIgnoreCase("CDMA2000")) {
                return netType == Mobile3G;
            }
            break;
        }
    }
    return false;
}
 
Example 7
Source File: AbstractNetworkUtils.java    From tenor-android-core with Apache License 2.0 4 votes vote down vote up
/**
 * Checks network type and subtype, to determine if network is fast (in kbps)
 *
 * @param type    ConnectivityManager type
 * @param subType TelephonyManager type for mobile
 * @return true if device is connected to a fast network connection
 */
private static boolean isNetworkConnected(int type, int subType) {
    if (type == ConnectivityManager.TYPE_WIFI) return true;

    if (type == ConnectivityManager.TYPE_MOBILE) {
        switch (subType) {
            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:
            default:
                return false;
        }
    }
    return false;
}
 
Example 8
Source File: ConnectivityUtil.java    From RxAndroidBootstrap with Apache License 2.0 4 votes vote down vote up
/**
 * Check if the connection is fast
 *
 * @param type
 * @param subType
 * @return
 */
public static boolean isConnectionFast(int type, int subType) {
    if (type == ConnectivityManager.TYPE_WIFI) {
        return true;
    } else if (type == ConnectivityManager.TYPE_MOBILE) {
        switch (subType) {
            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
        /*
         * Above API level 7, make sure to set android:targetSdkVersion
* to appropriate level to use these
*/
            case TelephonyManager.NETWORK_TYPE_EHRPD: // API level 11
                return true; // ~ 1-2 Mbps
            case TelephonyManager.NETWORK_TYPE_EVDO_B: // API level 9
                return true; // ~ 5 Mbps
            case TelephonyManager.NETWORK_TYPE_HSPAP: // API level 13
                return true; // ~ 10-20 Mbps
            case TelephonyManager.NETWORK_TYPE_IDEN: // API level 8
                return false; // ~25 kbps
            case TelephonyManager.NETWORK_TYPE_LTE: // API level 11
                return true; // ~ 10+ Mbps
            // Unknown
            case TelephonyManager.NETWORK_TYPE_UNKNOWN:
            default:
                return false;
        }
    } else {
        return false;
    }
}
 
Example 9
Source File: VenvyDeviceUtil.java    From VideoOS-Android-SDK with GNU General Public License v3.0 4 votes vote down vote up
public static String getNetWorkName(Context context) {
    String strNetworkType = "";
    ConnectivityManager connectivityManager = (ConnectivityManager) context.getSystemService
            (Context.CONNECTIVITY_SERVICE);
    NetworkInfo networkInfo = connectivityManager.getActiveNetworkInfo();
    if (networkInfo != null && networkInfo.isConnected()) {
        if (networkInfo.getType() == ConnectivityManager.TYPE_WIFI) {
            strNetworkType = "WIFI";
        } else if (networkInfo.getType() == ConnectivityManager.TYPE_MOBILE) {
            String _strSubTypeName = networkInfo.getSubtypeName();
            VenvyLog.i("cocos2d-x", "Network getSubtypeName : " + _strSubTypeName);

            // TD-SCDMA   networkType is 17
            int networkType = networkInfo.getSubtype();
            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: //api<8 : replace by 11
                    strNetworkType = "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: //api<9 : replace by 14
                case TelephonyManager.NETWORK_TYPE_EHRPD:  //api<11 : replace by 12
                case TelephonyManager.NETWORK_TYPE_HSPAP:  //api<13 : replace by 15
                    strNetworkType = "3G";
                    break;
                case TelephonyManager.NETWORK_TYPE_LTE:    //api<11 : replace by 13
                    strNetworkType = "4G";
                    break;
                default:
                    // http://baike.baidu.com/item/TD-SCDMA 中国移动 联通 电信 三种3G制式
                    if (_strSubTypeName.equalsIgnoreCase("TD-SCDMA") || _strSubTypeName
                            .equalsIgnoreCase("WCDMA") || _strSubTypeName.equalsIgnoreCase
                            ("CDMA2000")) {
                        strNetworkType = "3G";
                    } else {
                        strNetworkType = _strSubTypeName;
                    }
                    break;
            }
        }
    }
    return strNetworkType;
}
 
Example 10
Source File: DownloaderService.java    From Alite with GNU General Public License v3.0 4 votes vote down vote up
/**
 * Updates the network type based upon the type and subtype returned from
 * the connectivity manager. Subtype is only used for cellular signals.
 * 
 * @param type
 * @param subType
 */
private void updateNetworkType(int type, int subType) {
    switch (type) {
        case ConnectivityManager.TYPE_WIFI:
        case ConnectivityManager.TYPE_ETHERNET:
        case ConnectivityManager.TYPE_BLUETOOTH:
            mIsCellularConnection = false;
            mIsAtLeast3G = false;
            break;
        case ConnectivityManager.TYPE_WIMAX:
            mIsCellularConnection = true;
            mIsAtLeast3G = true;
            break;
        case ConnectivityManager.TYPE_MOBILE:
            mIsCellularConnection = true;
            switch (subType) {
                case TelephonyManager.NETWORK_TYPE_1xRTT:
                case TelephonyManager.NETWORK_TYPE_CDMA:
                case TelephonyManager.NETWORK_TYPE_EDGE:
                case TelephonyManager.NETWORK_TYPE_GPRS:
                case TelephonyManager.NETWORK_TYPE_IDEN:
                    mIsAtLeast3G = false;
                    break;
                case TelephonyManager.NETWORK_TYPE_HSDPA:
                case TelephonyManager.NETWORK_TYPE_HSUPA:
                case TelephonyManager.NETWORK_TYPE_HSPA:
                case TelephonyManager.NETWORK_TYPE_EVDO_0:
                case TelephonyManager.NETWORK_TYPE_EVDO_A:
                case TelephonyManager.NETWORK_TYPE_UMTS:
                    mIsAtLeast3G = true;
                    break;
                case TelephonyManager.NETWORK_TYPE_LTE: // 4G
                case TelephonyManager.NETWORK_TYPE_EHRPD: // 3G ++ interop
                                                          // with 4G
                case TelephonyManager.NETWORK_TYPE_HSPAP: // 3G ++ but
                                                          // marketed as
                                                          // 4G
                    mIsAtLeast3G = true;
                    break;
                default:
                    mIsCellularConnection = false;
                    mIsAtLeast3G = false;
            }
    }
}
 
Example 11
Source File: NetworkUtils.java    From pandroid with Apache License 2.0 4 votes vote down vote up
/**
 * Check if the connection is fast
 *
 * @param type
 * @param subType
 * @return
 */
public static boolean isConnectionFast(int type, int subType) {
    if (type == ConnectivityManager.TYPE_WIFI) {
        return true;
    } else if (type == ConnectivityManager.TYPE_MOBILE) {
        switch (subType) {
            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
        /*
         * Above API level 7, make sure to set android:targetSdkVersion
* to appropriate level to use these
*/
            case TelephonyManager.NETWORK_TYPE_EHRPD: // API level 11
                return true; // ~ 1-2 Mbps
            case TelephonyManager.NETWORK_TYPE_EVDO_B: // API level 9
                return true; // ~ 5 Mbps
            case TelephonyManager.NETWORK_TYPE_HSPAP: // API level 13
                return true; // ~ 10-20 Mbps
            case TelephonyManager.NETWORK_TYPE_IDEN: // API level 8
                return false; // ~25 kbps
            case TelephonyManager.NETWORK_TYPE_LTE: // API level 11
                return true; // ~ 10+ Mbps
            // Unknown
            case TelephonyManager.NETWORK_TYPE_UNKNOWN:
            default:
                return false;
        }
    } else {
        return false;
    }
}
 
Example 12
Source File: Connectivity.java    From talk-android with MIT License 4 votes vote down vote up
/**
 * Check if the connection is fast
 * @param type
 * @param subType
 * @return
 */
public static boolean isConnectionFast(int type, int subType){
    if(type==ConnectivityManager.TYPE_WIFI){
        return true;
    }else if(type==ConnectivityManager.TYPE_MOBILE){
        switch(subType){
        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
        /*
         * Above API level 7, make sure to set android:targetSdkVersion 
         * to appropriate level to use these
         */
        case TelephonyManager.NETWORK_TYPE_EHRPD: // API level 11 
            return true; // ~ 1-2 Mbps
        case TelephonyManager.NETWORK_TYPE_EVDO_B: // API level 9
            return true; // ~ 5 Mbps
        case TelephonyManager.NETWORK_TYPE_HSPAP: // API level 13
            return true; // ~ 10-20 Mbps
        case TelephonyManager.NETWORK_TYPE_IDEN: // API level 8
            return false; // ~25 kbps 
        case TelephonyManager.NETWORK_TYPE_LTE: // API level 11
            return true; // ~ 10+ Mbps
        // Unknown
        case TelephonyManager.NETWORK_TYPE_UNKNOWN:
        default:
            return false;
        }
    }else{
        return false;
    }
}
 
Example 13
Source File: KCApiPlatform.java    From kerkee_android with GNU General Public License v3.0 4 votes vote down vote up
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 14
Source File: VoIPBaseService.java    From Telegram-FOSS with GNU General Public License v2.0 4 votes vote down vote up
protected int getNetworkType() {
	final NetworkInfo info = lastNetInfo = getActiveNetworkInfo();
	int type = TgVoip.NET_TYPE_UNKNOWN;
	if (info != null) {
		switch (info.getType()) {
			case ConnectivityManager.TYPE_MOBILE:
				switch (info.getSubtype()) {
					case TelephonyManager.NETWORK_TYPE_GPRS:
						type = TgVoip.NET_TYPE_GPRS;
						break;
					case TelephonyManager.NETWORK_TYPE_EDGE:
					case TelephonyManager.NETWORK_TYPE_1xRTT:
						type = TgVoip.NET_TYPE_EDGE;
						break;
					case TelephonyManager.NETWORK_TYPE_UMTS:
					case TelephonyManager.NETWORK_TYPE_EVDO_0:
						type = TgVoip.NET_TYPE_3G;
						break;
					case TelephonyManager.NETWORK_TYPE_HSDPA:
					case TelephonyManager.NETWORK_TYPE_HSPA:
					case TelephonyManager.NETWORK_TYPE_HSPAP:
					case TelephonyManager.NETWORK_TYPE_HSUPA:
					case TelephonyManager.NETWORK_TYPE_EVDO_A:
					case TelephonyManager.NETWORK_TYPE_EVDO_B:
						type = TgVoip.NET_TYPE_HSPA;
						break;
					case TelephonyManager.NETWORK_TYPE_LTE:
						type = TgVoip.NET_TYPE_LTE;
						break;
					default:
						type = TgVoip.NET_TYPE_OTHER_MOBILE;
						break;
				}
				break;
			case ConnectivityManager.TYPE_WIFI:
				type = TgVoip.NET_TYPE_WIFI;
				break;
			case ConnectivityManager.TYPE_ETHERNET:
				type = TgVoip.NET_TYPE_ETHERNET;
				break;
		}
	}
	return type;
}
 
Example 15
Source File: PlayerUtils.java    From DKVideoPlayer with Apache License 2.0 4 votes vote down vote up
/**
 * 判断当前网络类型
 */
public static int getNetworkType(Context context) {
    //改为context.getApplicationContext(),防止在Android 6.0上发生内存泄漏
    ConnectivityManager connectMgr = (ConnectivityManager) context.getApplicationContext()
            .getSystemService(Context.CONNECTIVITY_SERVICE);

    if (connectMgr == null) {
        return NO_NETWORK;
    }

    NetworkInfo networkInfo = connectMgr.getActiveNetworkInfo();
    if (networkInfo == null) {
        // 没有任何网络
        return NO_NETWORK;
    }
    if (!networkInfo.isConnected()) {
        // 网络断开或关闭
        return NETWORK_CLOSED;
    }
    if (networkInfo.getType() == ConnectivityManager.TYPE_ETHERNET) {
        // 以太网网络
        return NETWORK_ETHERNET;
    } else if (networkInfo.getType() == ConnectivityManager.TYPE_WIFI) {
        // wifi网络,当激活时,默认情况下,所有的数据流量将使用此连接
        return NETWORK_WIFI;
    } else if (networkInfo.getType() == ConnectivityManager.TYPE_MOBILE) {
        // 移动数据连接,不能与连接共存,如果wifi打开,则自动关闭
        switch (networkInfo.getSubtype()) {
            // 2G
            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:
                // 3G
            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:
                // 4G
            case TelephonyManager.NETWORK_TYPE_LTE:
                // 5G
            case TelephonyManager.NETWORK_TYPE_NR:
                return NETWORK_MOBILE;
        }
    }
    // 未知网络
    return NETWORK_UNKNOWN;
}
 
Example 16
Source File: NetWorkUtils.java    From ZhihuDaily with Apache License 2.0 4 votes vote down vote up
/**
 * 获取当前的网络状态 :没有网络-0:WIFI网络1:4G网络-4:3G网络-3:2G网络-2
 * 自定义
 *
 * @param context
 * @return
 */
public static int getAPNType(Context context) {
    //结果返回值
    int netType = 0;
    //获取手机所有连接管理对象
    ConnectivityManager manager = (ConnectivityManager) context.getSystemService(Context.CONNECTIVITY_SERVICE);
    //获取NetworkInfo对象
    NetworkInfo networkInfo = manager.getActiveNetworkInfo();
    //NetworkInfo对象为空 则代表没有网络
    if (networkInfo == null) {
        return netType;
    }
    //否则 NetworkInfo对象不为空 则获取该networkInfo的类型
    int nType = networkInfo.getType();
    if (nType == ConnectivityManager.TYPE_WIFI) {
        //WIFI
        netType = 1;
    } else if (nType == ConnectivityManager.TYPE_MOBILE) {
        int nSubType = networkInfo.getSubtype();
        TelephonyManager telephonyManager = (TelephonyManager) context.getSystemService(Context.TELEPHONY_SERVICE);
        //3G   联通的3G为UMTS或HSDPA 电信的3G为EVDO
        if (nSubType == TelephonyManager.NETWORK_TYPE_LTE
                && !telephonyManager.isNetworkRoaming()) {
            netType = 4;
        } else if (nSubType == TelephonyManager.NETWORK_TYPE_UMTS
                || nSubType == TelephonyManager.NETWORK_TYPE_HSDPA
                || nSubType == TelephonyManager.NETWORK_TYPE_EVDO_0
                && !telephonyManager.isNetworkRoaming()) {
            netType = 3;
            //2G 移动和联通的2G为GPRS或EGDE,电信的2G为CDMA
        } else if (nSubType == TelephonyManager.NETWORK_TYPE_GPRS
                || nSubType == TelephonyManager.NETWORK_TYPE_EDGE
                || nSubType == TelephonyManager.NETWORK_TYPE_CDMA
                && !telephonyManager.isNetworkRoaming()) {
            netType = 2;
        } else {
            netType = 2;
        }
    }
    return netType;
}
 
Example 17
Source File: NetworkUtil.java    From AndroidWallet with GNU General Public License v3.0 4 votes vote down vote up
/**
 * 获取当前网络类型
 * 需添加权限 {@code <uses-permission android:name="android.permission.ACCESS_NETWORK_STATE"/>}
 */
@RequiresPermission("android.permission.ACCESS_NETWORK_STATE")
public static NetworkType getNetworkType(Context context) {
    NetworkType netType = NetworkType.NETWORK_NO;
    NetworkInfo info = getActiveNetworkInfo(context);
    if (info != null && info.isAvailable()) {

        if (info.getType() == ConnectivityManager.TYPE_WIFI) {
            netType = NetworkType.NETWORK_WIFI;
        } else if (info.getType() == ConnectivityManager.TYPE_MOBILE) {
            switch (info.getSubtype()) {

                case TelephonyManager.NETWORK_TYPE_TD_SCDMA:
                case TelephonyManager.NETWORK_TYPE_EVDO_A:
                case TelephonyManager.NETWORK_TYPE_UMTS:
                case TelephonyManager.NETWORK_TYPE_EVDO_0:
                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:
                    netType = NetworkType.NETWORK_3G;
                    break;

                case TelephonyManager.NETWORK_TYPE_LTE:
                case TelephonyManager.NETWORK_TYPE_IWLAN:
                    netType = NetworkType.NETWORK_4G;
                    break;

                case TelephonyManager.NETWORK_TYPE_GSM:
                case TelephonyManager.NETWORK_TYPE_GPRS:
                case TelephonyManager.NETWORK_TYPE_CDMA:
                case TelephonyManager.NETWORK_TYPE_EDGE:
                case TelephonyManager.NETWORK_TYPE_1xRTT:
                case TelephonyManager.NETWORK_TYPE_IDEN:
                    netType = NetworkType.NETWORK_2G;
                    break;
                default:
                    String subtypeName = info.getSubtypeName();
                    if (subtypeName.equalsIgnoreCase("TD-SCDMA")
                            || subtypeName.equalsIgnoreCase("WCDMA")
                            || subtypeName.equalsIgnoreCase("CDMA2000")) {
                        netType = NetworkType.NETWORK_3G;
                    } else {
                        netType = NetworkType.NETWORK_UNKNOWN;
                    }
                    break;
            }
        } else {
            netType = NetworkType.NETWORK_UNKNOWN;
        }
    }
    return netType;
}
 
Example 18
Source File: NetWorkUtil.java    From NetEasyNews with GNU General Public License v3.0 4 votes vote down vote up
/**
 * 获取当前的网络状态 :没有网络-0:WIFI网络1:4G网络-4:3G网络-3:2G网络-2
 * 自定义
 *
 * @param context
 * @return
 */
public static int getAPNType(Context context) {
    //结果返回值
    int netType = 0;
    //获取手机所有连接管理对象
    ConnectivityManager manager = (ConnectivityManager) context.getSystemService(Context.CONNECTIVITY_SERVICE);
    //获取NetworkInfo对象
    NetworkInfo networkInfo = manager.getActiveNetworkInfo();
    //NetworkInfo对象为空 则代表没有网络
    if (networkInfo == null) {
        return netType;
    }
    //否则 NetworkInfo对象不为空 则获取该networkInfo的类型
    int nType = networkInfo.getType();
    if (nType == ConnectivityManager.TYPE_WIFI) {
        //WIFI
        netType = 1;
    } else if (nType == ConnectivityManager.TYPE_MOBILE) {
        int nSubType = networkInfo.getSubtype();
        TelephonyManager telephonyManager = (TelephonyManager) context.getSystemService(Context.TELEPHONY_SERVICE);
        //3G   联通的3G为UMTS或HSDPA 电信的3G为EVDO
        if (nSubType == TelephonyManager.NETWORK_TYPE_LTE
                && !telephonyManager.isNetworkRoaming()) {
            netType = 4;
        } else if (nSubType == TelephonyManager.NETWORK_TYPE_UMTS
                || nSubType == TelephonyManager.NETWORK_TYPE_HSDPA
                || nSubType == TelephonyManager.NETWORK_TYPE_EVDO_0
                && !telephonyManager.isNetworkRoaming()) {
            netType = 3;
            //2G 移动和联通的2G为GPRS或EGDE,电信的2G为CDMA
        } else if (nSubType == TelephonyManager.NETWORK_TYPE_GPRS
                || nSubType == TelephonyManager.NETWORK_TYPE_EDGE
                || nSubType == TelephonyManager.NETWORK_TYPE_CDMA
                && !telephonyManager.isNetworkRoaming()) {
            netType = 2;
        } else {
            netType = 2;
        }
    }
    return netType;
}
 
Example 19
Source File: RxNetTool.java    From RxTools-master with Apache License 2.0 4 votes vote down vote up
/**
 * 需添加权限
 *      @code <uses-permission android:name="android.permission.ACCESS_NETWORK_STATE"/>
 *
 * 它主要负责的是
 *  1 监视网络连接状态 包括(Wi-Fi, 2G, 3G, 4G)
 *  2 当网络状态改变时发送广播通知
 *  3 网络连接失败尝试连接其他网络
 *  4 提供API,允许应用程序获取可用的网络状态
 *
 * netTyped 的结果
 * @link #NETWORK_NO      = -1; 当前无网络连接
 * @link #NETWORK_WIFI    =  1; wifi的情况下
 * @link #NETWORK_2G      =  2; 切换到2G环境下
 * @link #NETWORK_3G      =  3; 切换到3G环境下
 * @link #NETWORK_4G      =  4; 切换到4G环境下
 * @link #NETWORK_UNKNOWN =  5; 未知网络
 *
 * @param context 上下文
 * @return 网络类型
 */
public static int getNetWorkType(Context context) {
    // 获取ConnectivityManager
    ConnectivityManager cm = (ConnectivityManager) context.getSystemService(Context.CONNECTIVITY_SERVICE);

    NetworkInfo ni = cm.getActiveNetworkInfo();// 获取当前网络状态

    int netType = NETWORK_NO;

    if (ni != null && ni.isConnectedOrConnecting()) {

        switch (ni.getType()) {//获取当前网络的状态
            case ConnectivityManager.TYPE_WIFI:// wifi的情况下
                netType = NETWORK_WIFI;
                RxToast.success("切换到wifi环境下");
                break;
            case ConnectivityManager.TYPE_MOBILE:

                switch (ni.getSubtype()) {
                    case NETWORK_TYPE_GSM:
                    case TelephonyManager.NETWORK_TYPE_GPRS: // 联通2g
                    case TelephonyManager.NETWORK_TYPE_CDMA: // 电信2g
                    case TelephonyManager.NETWORK_TYPE_EDGE: // 移动2g
                    case TelephonyManager.NETWORK_TYPE_1xRTT:
                    case TelephonyManager.NETWORK_TYPE_IDEN:
                        netType = NETWORK_2G;
                        RxToast.info("切换到2G环境下");
                        break;
                    case TelephonyManager.NETWORK_TYPE_EVDO_A: // 电信3g
                    case TelephonyManager.NETWORK_TYPE_UMTS:
                    case TelephonyManager.NETWORK_TYPE_EVDO_0:
                    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:
                    case NETWORK_TYPE_TD_SCDMA:
                        netType = NETWORK_3G;
                        RxToast.info("切换到3G环境下");
                        break;
                    case TelephonyManager.NETWORK_TYPE_LTE:

                    case NETWORK_TYPE_IWLAN:
                        netType = NETWORK_4G;
                        RxToast.info("切换到4G环境下");
                        break;
                    default:

                        String subtypeName = ni.getSubtypeName();
                        if (subtypeName.equalsIgnoreCase("TD-SCDMA")
                                || subtypeName.equalsIgnoreCase("WCDMA")
                                || subtypeName.equalsIgnoreCase("CDMA2000")) {
                            netType = NETWORK_3G;
                        } else {
                            netType = NETWORK_UNKNOWN;
                        }
                        RxToast.normal("未知网络");
                }
                break;
            default:
                netType = 5;
                RxToast.normal("未知网络");
        }

    } else {
        netType = NETWORK_NO;
        RxToast.error(context, "当前无网络连接").show();
    }
    return netType;
}
 
Example 20
Source File: NetWorkUtils.java    From Simpler with Apache License 2.0 2 votes vote down vote up
/**
 * 判断当前网络的具体类型是否是GPRS
 * EVDO_Bam context 上下文
 *
 * @return false:当前网络的具体类型是否是GPRS。false:当前没有网络连接或者具体类型不是GPRS
 */
public static boolean isGPRSBySubtype(Context context) {
    return getCurrentNetworkSubtype(context) ==
            TelephonyManager.NETWORK_TYPE_GPRS;
}