Java Code Examples for android.net.NetworkInfo#getSubtypeName()

The following examples show how to use android.net.NetworkInfo#getSubtypeName() . 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: Network.java    From MiBandDecompiled with Apache License 2.0 6 votes vote down vote up
public static String getActiveNetworkName(Context context)
{
    ConnectivityManager connectivitymanager = (ConnectivityManager)context.getSystemService("connectivity");
    if (connectivitymanager == null)
    {
        return "null";
    }
    NetworkInfo networkinfo = connectivitymanager.getActiveNetworkInfo();
    if (networkinfo == null)
    {
        return "null";
    }
    if (TextUtils.isEmpty(networkinfo.getSubtypeName()))
    {
        return networkinfo.getTypeName();
    } else
    {
        Object aobj[] = new Object[2];
        aobj[0] = networkinfo.getTypeName();
        aobj[1] = networkinfo.getSubtypeName();
        return String.format("%s-%s", aobj);
    }
}
 
Example 2
Source File: NetUtils.java    From NoHttp 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 3
Source File: GetDeviceInfo.java    From appium-uiautomator2-server with Apache License 2.0 5 votes vote down vote up
private static List<NetworkInfoModel> extractNetworkInfo(DeviceInfoHelper deviceInfoHelper) {
    List<NetworkInfoModel> result = new ArrayList<>();
    for (Network network : deviceInfoHelper.getNetworks()) {
        NetworkInfoModel resultItem = new NetworkInfoModel();
        NetworkInfo networkInfo = deviceInfoHelper.extractInfo(network);
        if (networkInfo != null) {
            resultItem.type = networkInfo.getType();
            resultItem.typeName = networkInfo.getTypeName();
            resultItem.subtype = networkInfo.getSubtype();
            resultItem.subtypeName = networkInfo.getSubtypeName();
            resultItem.isConnected = networkInfo.isConnected();
            resultItem.detailedState = networkInfo.getDetailedState().name();
            resultItem.state = networkInfo.getState().name();
            resultItem.extraInfo = networkInfo.getExtraInfo();
            resultItem.isAvailable = networkInfo.isAvailable();
            resultItem.isFailover = networkInfo.isFailover();
            resultItem.isRoaming = networkInfo.isRoaming();
        }

        NetworkCapabilities networkCaps = deviceInfoHelper.extractCapabilities(network);
        NetworkCapabilitiesModel caps = new NetworkCapabilitiesModel();
        if (networkCaps != null) {
            caps.transportTypes = DeviceInfoHelper.extractTransportTypes(networkCaps);
            caps.networkCapabilities = DeviceInfoHelper.extractCapNames(networkCaps);
            caps.linkUpstreamBandwidthKbps = networkCaps.getLinkUpstreamBandwidthKbps();
            caps.linkDownBandwidthKbps = networkCaps.getLinkDownstreamBandwidthKbps();
            caps.signalStrength = extractSafeValue("mSignalStrength", networkCaps);
            caps.SSID = extractSafeValue("mSSID", networkCaps);
        }
        resultItem.capabilities = networkCaps == null ? null : caps;

        if (networkInfo != null || networkCaps != null) {
            result.add(resultItem);
        }
    }
    return result;
}
 
Example 4
Source File: NetworkManager.java    From reader with MIT License 5 votes vote down vote up
/**
 * Determine the type of connection
 *
 * @param info the network info so we can determine connection type.
 * @return the type of mobile network we are on
 */
private String getType(NetworkInfo info) {
    if (info != null) {
        String type = info.getTypeName();

        if (type.toLowerCase().equals(WIFI)) {
            return TYPE_WIFI;
        }
        else if (type.toLowerCase().equals(MOBILE) || type.toLowerCase().equals(CELLULAR)) {
            type = info.getSubtypeName();
            if (type.toLowerCase().equals(GSM) ||
                    type.toLowerCase().equals(GPRS) ||
                    type.toLowerCase().equals(EDGE)) {
                return TYPE_2G;
            }
            else if (type.toLowerCase().startsWith(CDMA) ||
                    type.toLowerCase().equals(UMTS) ||
                    type.toLowerCase().equals(ONEXRTT) ||
                    type.toLowerCase().equals(EHRPD) ||
                    type.toLowerCase().equals(HSUPA) ||
                    type.toLowerCase().equals(HSDPA) ||
                    type.toLowerCase().equals(HSPA)) {
                return TYPE_3G;
            }
            else if (type.toLowerCase().equals(LTE) ||
                    type.toLowerCase().equals(UMB) ||
                    type.toLowerCase().equals(HSPA_PLUS)) {
                return TYPE_4G;
            }
        }
    }
    else {
        return TYPE_NONE;
    }
    return TYPE_UNKNOWN;
}
 
Example 5
Source File: NetworkManager.java    From cordova-android-chromeview with Apache License 2.0 5 votes vote down vote up
/**
 * Determine the type of connection
 *
 * @param info the network info so we can determine connection type.
 * @return the type of mobile network we are on
 */
private String getType(NetworkInfo info) {
    if (info != null) {
        String type = info.getTypeName();

        if (type.toLowerCase().equals(WIFI)) {
            return TYPE_WIFI;
        }
        else if (type.toLowerCase().equals(MOBILE)) {
            type = info.getSubtypeName();
            if (type.toLowerCase().equals(GSM) ||
                    type.toLowerCase().equals(GPRS) ||
                    type.toLowerCase().equals(EDGE)) {
                return TYPE_2G;
            }
            else if (type.toLowerCase().startsWith(CDMA) ||
                    type.toLowerCase().equals(UMTS) ||
                    type.toLowerCase().equals(ONEXRTT) ||
                    type.toLowerCase().equals(EHRPD) ||
                    type.toLowerCase().equals(HSUPA) ||
                    type.toLowerCase().equals(HSDPA) ||
                    type.toLowerCase().equals(HSPA)) {
                return TYPE_3G;
            }
            else if (type.toLowerCase().equals(LTE) ||
                    type.toLowerCase().equals(UMB) ||
                    type.toLowerCase().equals(HSPA_PLUS)) {
                return TYPE_4G;
            }
        }
    }
    else {
        return TYPE_NONE;
    }
    return TYPE_UNKNOWN;
}
 
Example 6
Source File: NetworkUtils.java    From Android-UtilCode with Apache License 2.0 4 votes vote down vote up
/**
 * 获取当前网络类型
 * <p>需添加权限 {@code <uses-permission android:name="android.permission.ACCESS_NETWORK_STATE"/>}</p>
 *
 * @return 网络类型
 * <ul>
 * <li>{@link NetworkUtils.NetworkType#NETWORK_WIFI   } </li>
 * <li>{@link NetworkUtils.NetworkType#NETWORK_4G     } </li>
 * <li>{@link NetworkUtils.NetworkType#NETWORK_3G     } </li>
 * <li>{@link NetworkUtils.NetworkType#NETWORK_2G     } </li>
 * <li>{@link NetworkUtils.NetworkType#NETWORK_UNKNOWN} </li>
 * <li>{@link NetworkUtils.NetworkType#NETWORK_NO     } </li>
 * </ul>
 */
public static NetworkType getNetworkType() {
    NetworkType netType = NetworkType.NETWORK_NO;
    NetworkInfo info = getActiveNetworkInfo();
    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 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;

                case 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 NETWORK_TYPE_IWLAN:
                case TelephonyManager.NETWORK_TYPE_LTE:
                    netType = NetworkType.NETWORK_4G;
                    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 7
Source File: NetworkUtils.java    From letv with Apache License 2.0 4 votes vote down vote up
public static void detectNetwork(Context context) {
    try {
        ConnectivityManager connectivityManager = (ConnectivityManager) context.getSystemService("connectivity");
        NetworkInfo networkInfo = connectivityManager != null ? connectivityManager.getActiveNetworkInfo() : null;
        String networkName = NETWORK_NAME_NO_NETWORK;
        if (networkInfo != null && networkInfo.isAvailable()) {
            networkName = networkInfo.getTypeName();
            switch (networkInfo.getType()) {
                case 0:
                    networkName = networkInfo.getSubtypeName();
                    switch (networkInfo.getSubtype()) {
                        case 1:
                        case 2:
                        case 4:
                        case 7:
                        case 11:
                            sNetworkType = 4;
                            sNetworkName = NETWORK_NAME_2G;
                            break;
                        case 3:
                        case 5:
                        case 6:
                        case 8:
                        case 9:
                        case 10:
                        case 12:
                        case 14:
                        case 15:
                            sNetworkType = 5;
                            sNetworkName = NETWORK_NAME_3G;
                            break;
                        case 13:
                            sNetworkType = 6;
                            sNetworkName = NETWORK_NAME_4G;
                            break;
                        default:
                            if (!NETWORK_NAME_TD_SCDMA.equalsIgnoreCase(networkName) && !NETWORK_NAME_WCDMA.equalsIgnoreCase(networkName) && !NETWORK_NAME_CDMA2000.equalsIgnoreCase(networkName)) {
                                sNetworkType = 2;
                                sNetworkName = NETWORK_NAME_MOBILE;
                                break;
                            }
                            sNetworkType = 5;
                            sNetworkName = NETWORK_NAME_3G;
                            break;
                            break;
                    }
                case 1:
                    sNetworkType = 3;
                    sNetworkName = NETWORK_NAME_WIFI;
                    break;
                case 9:
                    sNetworkType = 1;
                    sNetworkName = NETWORK_NAME_ETHERNET;
                    break;
                default:
                    if (!NETWORK_NAME_PPPOE.equalsIgnoreCase(networkName)) {
                        sNetworkType = 8;
                        sNetworkName = NETWORK_NAME_MORE;
                        break;
                    }
                    sNetworkType = 1;
                    sNetworkName = NETWORK_NAME_ETHERNET;
                    break;
            }
        }
        sNetworkType = 0;
        sNetworkName = NETWORK_NAME_NO_NETWORK;
        LogTool.i(TAG, "detectNetwork. network name(%s), network type(%s), ip(%s)", networkName, Integer.valueOf(sNetworkType), getIP());
    } catch (Exception e) {
        LogTool.e(TAG, "detectNetwork. " + e.toString());
        sNetworkType = -1;
        sNetworkName = NETWORK_NAME_NO_PERMISSION;
        LogTool.i(TAG, "detectNetwork. network name(%s), network type(%s), ip(%s)", sNetworkName, Integer.valueOf(sNetworkType), getIP());
    }
}
 
Example 8
Source File: NetworkStatus.java    From FriendlyDemo with Apache License 2.0 4 votes vote down vote up
private String getNetworkStatus(@NonNull NetworkInfo netInfo) {
    return (netInfo.getType() == TYPE_MOBILE) ? netInfo.getSubtypeName() : netInfo.getTypeName();
}
 
Example 9
Source File: NetworkUtils.java    From BookReader with Apache License 2.0 4 votes vote down vote up
/**
 * 获取当前的网络类型(WIFI,2G,3G,4G)
 * <p>需添加权限 {@code <uses-permission android:name="android.permission
 * .ACCESS_NETWORK_STATE"/>}</p>
 *
 * @param context 上下文
 * @return 网络类型
 * <ul>
 * <li>{@link #NETWORK_WIFI   } = 1;</li>
 * <li>{@link #NETWORK_4G     } = 4;</li>
 * <li>{@link #NETWORK_3G     } = 3;</li>
 * <li>{@link #NETWORK_2G     } = 2;</li>
 * <li>{@link #NETWORK_UNKNOWN} = 5;</li>
 * <li>{@link #NETWORK_NO     } = -1;</li>
 * </ul>
 */
public static int getNetWorkType(Context context) {
    int netType = NETWORK_NO;
    NetworkInfo info = getActiveNetworkInfo(context);
    if (info != null && info.isAvailable()) {

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

                case 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 = NETWORK_2G;
                    break;

                case 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 = NETWORK_3G;
                    break;

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

                    String subtypeName = info.getSubtypeName();
                    if (subtypeName.equalsIgnoreCase("TD-SCDMA")
                            || subtypeName.equalsIgnoreCase("WCDMA")
                            || subtypeName.equalsIgnoreCase("CDMA2000")) {
                        netType = NETWORK_3G;
                    } else {
                        netType = NETWORK_UNKNOWN;
                    }
                    break;
            }
        } else {
            netType = NETWORK_UNKNOWN;
        }
    }
    return netType;
}
 
Example 10
Source File: NetworkUtils.java    From GSYVideoPlayer with Apache License 2.0 4 votes vote down vote up
/**
 * 获取当前的网络类型(WIFI,2G,3G,4G)
 * <p>需添加权限 android.permission.ACCESS_NETWORK_STATE</p>
 *
 * @param context 上下文
 * @return 网络类型
 * <ul>
 * <li>NETWORK_WIFI    = 1;</li>
 * <li>NETWORK_4G      = 4;</li>
 * <li>NETWORK_3G      = 3;</li>
 * <li>NETWORK_2G      = 2;</li>
 * <li>NETWORK_UNKNOWN = 5;</li>
 * <li>NETWORK_NO      = -1;</li>
 * </ul>
 */
public static int getNetWorkType(Context context) {
    int netType = NETWORK_NO;
    NetworkInfo info = getActiveNetworkInfo(context);
    if (info != null && info.isAvailable()) {

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

                case 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 = NETWORK_2G;
                    break;

                case 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 = NETWORK_3G;
                    break;

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

                    String subtypeName = info.getSubtypeName();
                    if (subtypeName.equalsIgnoreCase("TD-SCDMA")
                            || subtypeName.equalsIgnoreCase("WCDMA")
                            || subtypeName.equalsIgnoreCase("CDMA2000")) {
                        netType = NETWORK_3G;
                    } else {
                        netType = NETWORK_UNKNOWN;
                    }
                    break;
            }
        } else {
            netType = NETWORK_UNKNOWN;
        }
    }
    return netType;
}
 
Example 11
Source File: NetworkUtils.java    From BaseProject with Apache License 2.0 4 votes vote down vote up
/**
 * 获取当前的网络类型(WIFI,2G,3G,4G)
 * <p>
 * 需添加权限
 * {@code <uses-permission android:name="android.permission.ACCESS_NETWORK_STATE"/>}
 * </p>
 * 
 * @param context
 *            上下文
 * @return 网络类型
 *         <ul>
 *         <li>{@link #NETWORK_WIFI   } = 1;</li>
 *         <li>{@link #NETWORK_4G     } = 4;</li>
 *         <li>{@link #NETWORK_3G     } = 3;</li>
 *         <li>{@link #NETWORK_2G     } = 2;</li>
 *         <li>{@link #NETWORK_UNKNOWN} = 5;</li>
 *         <li>{@link #NETWORK_NO     } = -1;</li>
 *         </ul>
 */
public static int getNetworkType(Context context) {
	int netType = NETWORK_NO;
	NetworkInfo info = getActiveNetworkInfo(context);
	if (info != null && info.isAvailable()) {

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

			case 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 = NETWORK_2G;
				break;

			case 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 = NETWORK_3G;
				break;

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

				String subtypeName = info.getSubtypeName();
				if (subtypeName.equalsIgnoreCase("TD-SCDMA") || subtypeName.equalsIgnoreCase("WCDMA")
						|| subtypeName.equalsIgnoreCase("CDMA2000")) {
					netType = NETWORK_3G;
				} else {
					netType = NETWORK_UNKNOWN;
				}
				break;
			}
		} else {
			netType = NETWORK_UNKNOWN;
		}
	}
	return netType;
}
 
Example 12
Source File: NeihanManager.java    From CrazyDaily with Apache License 2.0 4 votes vote down vote up
private String getNetworkType() {

        NetworkInfo info = ((ConnectivityManager) mNeihanPreference.getContext().getSystemService(Context.CONNECTIVITY_SERVICE)).getActiveNetworkInfo();
        if (info != null && info.isAvailable()) {
            if (info.getType() == ConnectivityManager.TYPE_WIFI) {
                return "wifi";
            } else if (info.getType() == ConnectivityManager.TYPE_MOBILE) {
                switch (info.getSubtype()) {
                    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 "2g";
                    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 "3g";
                    case TelephonyManager.NETWORK_TYPE_IWLAN:
                    case TelephonyManager.NETWORK_TYPE_LTE:
                        return "4g";
                    default:
                        String subtypeName = info.getSubtypeName();
                        if (subtypeName.equalsIgnoreCase("TD-SCDMA")
                                || subtypeName.equalsIgnoreCase("WCDMA")
                                || subtypeName.equalsIgnoreCase("CDMA2000")) {
                            return "3g";
                        } else {
                            return "wifi";
                        }
                }
            } else {
                return "wifi";
            }
        }
        return "wifi";
    }
 
Example 13
Source File: NetworkUtils.java    From fangzhuishushenqi with Apache License 2.0 4 votes vote down vote up
/**
 * 获取当前的网络类型(WIFI,2G,3G,4G)
 * <p>需添加权限 {@code <uses-permission android:name="android.permission
 * .ACCESS_NETWORK_STATE"/>}</p>
 *
 * @param context 上下文
 * @return 网络类型
 * <ul>
 * <li>{@link #NETWORK_WIFI   } = 1;</li>
 * <li>{@link #NETWORK_4G     } = 4;</li>
 * <li>{@link #NETWORK_3G     } = 3;</li>
 * <li>{@link #NETWORK_2G     } = 2;</li>
 * <li>{@link #NETWORK_UNKNOWN} = 5;</li>
 * <li>{@link #NETWORK_NO     } = -1;</li>
 * </ul>
 */
public static int getNetWorkType(Context context) {
    int netType = NETWORK_NO;
    NetworkInfo info = getActiveNetworkInfo(context);
    if (info != null && info.isAvailable()) {

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

                case 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 = NETWORK_2G;
                    break;

                case 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 = NETWORK_3G;
                    break;

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

                    String subtypeName = info.getSubtypeName();
                    if (subtypeName.equalsIgnoreCase("TD-SCDMA")
                            || subtypeName.equalsIgnoreCase("WCDMA")
                            || subtypeName.equalsIgnoreCase("CDMA2000")) {
                        netType = NETWORK_3G;
                    } else {
                        netType = NETWORK_UNKNOWN;
                    }
                    break;
            }
        } else {
            netType = NETWORK_UNKNOWN;
        }
    }
    return netType;
}
 
Example 14
Source File: DeviceStateReceiver.java    From Cake-VPN with GNU General Public License v2.0 4 votes vote down vote up
public void networkStateChange(Context context) {
     NetworkInfo networkInfo = getCurrentNetworkInfo(context);
     SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(context);
     boolean sendusr1 = prefs.getBoolean("netchangereconnect", true);
     String netstatestring;
     if (networkInfo == null) {
         netstatestring = "not connected";
     } else {
         String subtype = networkInfo.getSubtypeName();
         if (subtype == null) subtype = "";
         String extrainfo = networkInfo.getExtraInfo();
         if (extrainfo == null) extrainfo = "";
         /*
         if(networkInfo.getType()==android.net.ConnectivityManager.TYPE_WIFI) {
	WifiManager wifiMgr = (WifiManager) context.getSystemService(Context.WIFI_SERVICE);
	WifiInfo wifiinfo = wifiMgr.getConnectionInfo();
	extrainfo+=wifiinfo.getBSSID();
	subtype += wifiinfo.getNetworkId();
}*/
         netstatestring = String.format("%2$s %4$s to %1$s %3$s", networkInfo.getTypeName(), networkInfo.getDetailedState(), extrainfo, subtype);

     }
     if (networkInfo != null && networkInfo.getState() == State.CONNECTED) {
         int newnet = networkInfo.getType();
         boolean pendingDisconnect = (network == connectState.PENDINGDISCONNECT);
         network = connectState.SHOULDBECONNECTED;
         boolean sameNetwork;
         if (lastConnectedNetwork == null || lastConnectedNetwork.getType() != networkInfo.getType() || !equalsObj(lastConnectedNetwork.getExtraInfo(), networkInfo.getExtraInfo()))
             sameNetwork = false;
         else sameNetwork = true;
         /* Same network, connection still 'established' */
         if (pendingDisconnect && sameNetwork) {
             mDisconnectHandler.removeCallbacks(mDelayDisconnectRunnable);
             // Reprotect the sockets just be sure
             mManagement.networkChange(true);
         } else {
             /* Different network or connection not established anymore */
             if (screen == connectState.PENDINGDISCONNECT) screen = connectState.DISCONNECTED;
             if (shouldBeConnected()) {
                 mDisconnectHandler.removeCallbacks(mDelayDisconnectRunnable);
                 if (pendingDisconnect || !sameNetwork) mManagement.networkChange(sameNetwork);
                 else mManagement.resume();
             }
             lastNetwork = newnet;
             lastConnectedNetwork = networkInfo;
         }
     } else if (networkInfo == null) {
         // Not connected, stop openvpn, set last connected network to no network
         lastNetwork = -1;
         if (sendusr1) {
             network = connectState.PENDINGDISCONNECT;
             mDisconnectHandler.postDelayed(mDelayDisconnectRunnable, DISCONNECT_WAIT * 1000);
         }
     }
     if (!netstatestring.equals(lastStateMsg)) VpnStatus.logInfo(R.string.netstatus, netstatestring);
     lastStateMsg = netstatestring;
 }
 
Example 15
Source File: LocalNetHelper.java    From base-module with Apache License 2.0 4 votes vote down vote up
/**
 * 获取当前的网络类型(WIFI,2G,3G,4G)
 * <p>需添加权限 {@code <uses-permission android:name="android.permission.ACCESS_NETWORK_STATE"/>}</p>
 *
 * @param context 上下文
 * @return 网络类型
 * <ul>
 * <li>{@link #NETWORK_WIFI   } = 1;</li>
 * <li>{@link #NETWORK_4G     } = 4;</li>
 * <li>{@link #NETWORK_3G     } = 3;</li>
 * <li>{@link #NETWORK_2G     } = 2;</li>
 * <li>{@link #NETWORK_UNKNOWN} = 5;</li>
 * <li>{@link #NETWORK_NO     } = -1;</li>
 * </ul>
 */
public static int getNetWorkType(Context context) {
    int netType = NETWORK_NO;
    NetworkInfo info = getActiveNetworkInfo(context);
    if (info != null && info.isAvailable()) {

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

                case 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 = NETWORK_2G;
                    break;

                case 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 = NETWORK_3G;
                    break;

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

                    String subtypeName = info.getSubtypeName();
                    if (subtypeName.equalsIgnoreCase("TD-SCDMA")
                            || subtypeName.equalsIgnoreCase("WCDMA")
                            || subtypeName.equalsIgnoreCase("CDMA2000")) {
                        netType = NETWORK_3G;
                    } else {
                        netType = NETWORK_UNKNOWN;
                    }
                    break;
            }
        } else {
            netType = NETWORK_UNKNOWN;
        }
    }
    return netType;
}
 
Example 16
Source File: VenvyDeviceUtil.java    From VideoOS-Android-SDK with GNU General Public License v3.0 4 votes vote down vote up
public static int getNetWorkType(Context context) {
    int strNetworkType = 0;
    ConnectivityManager connectivityManager = (ConnectivityManager) context.getSystemService
            (Context.CONNECTIVITY_SERVICE);
    NetworkInfo networkInfo = connectivityManager.getActiveNetworkInfo();
    if (networkInfo != null && networkInfo.isConnected()) {
        if (networkInfo.getType() == ConnectivityManager.TYPE_WIFI) {
            strNetworkType = 1;
        } 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
                case TelephonyManager.NETWORK_TYPE_GSM:  // api<25: replace by 16
                    strNetworkType = 2;
                    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 12
                case TelephonyManager.NETWORK_TYPE_EHRPD:    // api<11: replace by 14
                case TelephonyManager.NETWORK_TYPE_HSPAP:    // api<13: replace by 15
                case TelephonyManager.NETWORK_TYPE_TD_SCDMA: // api<25: replace by 17
                    strNetworkType = 3;
                    break;
                case TelephonyManager.NETWORK_TYPE_LTE:      // api<11: replace by 13
                case TelephonyManager.NETWORK_TYPE_IWLAN:    // api<25: replace by 18
                    strNetworkType = 4;
                    break;
                case TelephonyManager.NETWORK_TYPE_NR:// api<29: replace by 20
                    strNetworkType = 5;
                    break;
            }
        }
    }
    return strNetworkType;
}
 
Example 17
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 18
Source File: NetworkUtils.java    From Trojan with Apache License 2.0 4 votes vote down vote up
public static int getNetworkType(Context context) {
    if (null == context) {
        return NETWORK_NONE;
    }
    ConnectivityManager connectivityManager = (ConnectivityManager) context.getSystemService(Context.CONNECTIVITY_SERVICE);
    if (null == connectivityManager) {
        return NETWORK_NONE;
    }

    final NetworkInfo activeNetInfo = connectivityManager.getActiveNetworkInfo();
    if (null == activeNetInfo || !activeNetInfo.isAvailable()) {
        return NETWORK_NONE;
    } else if (activeNetInfo.getType() == ConnectivityManager.TYPE_WIFI) {
        return NETWORK_WIFI;
    } else if (activeNetInfo.getType() == ConnectivityManager.TYPE_MOBILE) {
        final NetworkInfo.State state = activeNetInfo.getState();
        final String subTypeName = activeNetInfo.getSubtypeName();
        if (null != state) {
            switch (activeNetInfo.getSubtype()) {
                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 NETWORK_2G;
                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 NETWORK_3G;
                case TelephonyManager.NETWORK_TYPE_LTE:
                    return NETWORK_4G;
                default:
                    if (subTypeName.equalsIgnoreCase("TD-SCDMA")
                            || subTypeName.equalsIgnoreCase("WCDMA")
                            || subTypeName.equalsIgnoreCase("CDMA2000")) {
                        return NETWORK_3G;
                    } else {
                        return NETWORK_UNKNOWN_MOBILE;
                    }
            }
        }
    }
    return NETWORK_NONE;
}
 
Example 19
Source File: AppNetWorkUtil.java    From Ency with Apache License 2.0 4 votes vote down vote up
/**
 * 获取当前网络具体类型
 * <p>需添加权限 {@code <uses-permission android:name="android.permission.ACCESS_NETWORK_STATE"/>}</p>
 *
 * @return 网络类型
 */
public static String getNetworkSubType(Context context) {
    ConnectivityManager manager = (ConnectivityManager) context.getSystemService(Context.CONNECTIVITY_SERVICE);
    NetworkInfo info = manager.getActiveNetworkInfo();
    String subtype = NETWORK_NO;

    if (info != null && info.isAvailable()) {
        if (info.getType() == ConnectivityManager.TYPE_WIFI) {
            subtype = NETWORK_WIFI;
        } else if (info.getType() == ConnectivityManager.TYPE_MOBILE) {
            switch (info.getSubtype()) {
                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:
                    subtype = getOperatorName(context).concat(NETWORK_2G);
                    break;
                case TelephonyManager.NETWORK_TYPE_UMTS:
                case TelephonyManager.NETWORK_TYPE_EVDO_A:
                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:
                    subtype = getOperatorName(context).concat(NETWORK_3G);
                    break;
                case TelephonyManager.NETWORK_TYPE_LTE:
                    subtype = getOperatorName(context).concat(NETWORK_4G);
                    break;
                default:
                    String subtypeName = info.getSubtypeName();
                    if (subtypeName.equalsIgnoreCase("TD-SCDMA")
                            || subtypeName.equalsIgnoreCase("WCDMA")
                            || subtypeName.equalsIgnoreCase("CDMA2000")) {
                        subtype = getOperatorName(context).concat(NETWORK_3G);
                    } else {
                        subtype = NETWORK_UNKNOWN;
                    }
                    break;
            }
        } else {
            subtype = NETWORK_UNKNOWN;
        }
    }
    return subtype;
}
 
Example 20
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;
}