Android examples for Network:Network Operation
Whether is fast mobile network
//package com.java2s; import android.content.Context; import android.net.ConnectivityManager; import android.net.NetworkInfo; import android.telephony.TelephonyManager; public class Main { public static final String NETWORK_TYPE_UNKNOWN = "unknown"; /**//from ww w . j av a 2 s. c o m * Whether is fast mobile network * * @param context context * @return FastMobileNetwork */ 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; } } public static int getNetworkType(Context context) { ConnectivityManager connectivityManager = (ConnectivityManager) context .getSystemService(Context.CONNECTIVITY_SERVICE); NetworkInfo networkInfo = connectivityManager == null ? null : connectivityManager.getActiveNetworkInfo(); return networkInfo == null ? -1 : networkInfo.getType(); } }