List of usage examples for android.net NetworkInfo getSubtype
@Deprecated public int getSubtype()
From source file:Main.java
public static int getConnectedType(Context context) { ConnectivityManager cManager = (ConnectivityManager) context.getSystemService(Context.CONNECTIVITY_SERVICE); NetworkInfo nInfo = cManager.getActiveNetworkInfo(); if (nInfo != null && nInfo.isAvailable()) { int type = nInfo.getType(); int subType = nInfo.getSubtype(); switch (type) { case ConnectivityManager.TYPE_MOBILE: switch (subType) { case 1://TelephonyManager.NETWORK_TYPE_GPRS: case 2://TelephonyManager.NETWORK_TYPE_EDGE: case 4://TelephonyManager.NETWORK_TYPE_CDMA: case 7://TelephonyManager.NETWORK_TYPE_1xRTT: case 11://TelephonyManager.NETWORK_TYPE_IDEN: return NETWORK_CLASS_2_G; case 3://TelephonyManager.NETWORK_TYPE_UMTS: case 5://TelephonyManager.NETWORK_TYPE_EVDO_0: case 6://TelephonyManager.NETWORK_TYPE_EVDO_A: case 8://TelephonyManager.NETWORK_TYPE_HSDPA: case 9://TelephonyManager.NETWORK_TYPE_HSUPA: case 10://TelephonyManager.NETWORK_TYPE_HSPA: case 12://TelephonyManager.NETWORK_TYPE_EVDO_B: case 14://TelephonyManager.NETWORK_TYPE_EHRPD: case 15://TelephonyManager.NETWORK_TYPE_HSPAP: return NETWORK_CLASS_3_G; case 13://TelephonyManager.NETWORK_TYPE_LTE: return NETWORK_CLASS_4_G; default: return NETWORK_CLASS_UNKNOWN; }/*from w w w . j a v a 2 s . c o m*/ case ConnectivityManager.TYPE_WIFI: return NETWORK_CLASS_WIFI; } } return NETWORK_CLASS_UNKNOWN; }
From source file:Main.java
public static String checkNetType(Context context) { ConnectivityManager connectMgr = (ConnectivityManager) context .getSystemService(Context.CONNECTIVITY_SERVICE); NetworkInfo info = connectMgr.getActiveNetworkInfo(); String type = "no_network"; if (info == null) { return type; }/*from ww w. j a v a 2s. c o m*/ if (info.getType() == ConnectivityManager.TYPE_WIFI) { type = "wifi"; } else { switch (info.getSubtype()) { case TelephonyManager.NETWORK_TYPE_UNKNOWN: type = "UNKNOWN"; break; case TelephonyManager.NETWORK_TYPE_GPRS: type = "GPRS"; break; case TelephonyManager.NETWORK_TYPE_EDGE: type = "EDGE"; break; case TelephonyManager.NETWORK_TYPE_UMTS: type = "UMTS"; break; case TelephonyManager.NETWORK_TYPE_CDMA: type = "CDMA"; break; case TelephonyManager.NETWORK_TYPE_EVDO_0: type = "EVDO_0"; break; case TelephonyManager.NETWORK_TYPE_EVDO_A: type = "EVDO_A"; break; case TelephonyManager.NETWORK_TYPE_1xRTT: type = "1xRTT"; break; case TelephonyManager.NETWORK_TYPE_HSDPA: type = "HSDPA"; break; case TelephonyManager.NETWORK_TYPE_HSUPA: type = "HSUPA"; break; case TelephonyManager.NETWORK_TYPE_HSPA: type = "HSPA"; break; case TelephonyManager.NETWORK_TYPE_IDEN: type = "IDEN"; break; case TelephonyManager.NETWORK_TYPE_EVDO_B: type = "EVDO_B"; break; case TelephonyManager.NETWORK_TYPE_LTE: type = "LTE"; break; case TelephonyManager.NETWORK_TYPE_EHRPD: type = "EHRPD"; break; case TelephonyManager.NETWORK_TYPE_HSPAP: type = "HSPAP"; break; } } return type; }
From source file:Main.java
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;/* www.j a v a 2s . c o m*/ } 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; }
From source file:org.kei.android.phone.cellhistory.towers.MobileNetworkInfo.java
public static String getTheoreticalSpeed(final NetworkInfo ni) { if (ni.getType() == ConnectivityManager.TYPE_MOBILE) { switch (ni.getSubtype()) { case TelephonyManager.NETWORK_TYPE_1xRTT: return "~50-100 kbps"; case TelephonyManager.NETWORK_TYPE_CDMA: return "~14-64 kbps"; case TelephonyManager.NETWORK_TYPE_EDGE: return "~50-100 kbps"; case TelephonyManager.NETWORK_TYPE_EVDO_0: return "~400-1000 kbps"; case TelephonyManager.NETWORK_TYPE_EVDO_A: return "~600-1400 kbps"; case TelephonyManager.NETWORK_TYPE_GPRS: return "~100 kbps"; case TelephonyManager.NETWORK_TYPE_HSDPA: return "~2-14 Mbps"; case TelephonyManager.NETWORK_TYPE_HSPA: return "~700-1700 kbps"; case TelephonyManager.NETWORK_TYPE_HSUPA: return "~1-23 Mbps"; case TelephonyManager.NETWORK_TYPE_UMTS: return "~400-7000 kbps"; case TelephonyManager.NETWORK_TYPE_EHRPD: return "~1-2 Mbps"; case TelephonyManager.NETWORK_TYPE_EVDO_B: return "~5 Mbps"; case TelephonyManager.NETWORK_TYPE_HSPAP: return "~10-20 Mbps"; case TelephonyManager.NETWORK_TYPE_IDEN: return "~25 kbps"; case TelephonyManager.NETWORK_TYPE_LTE: return "~10+ Mbps"; }/*from www. j av a 2s .c om*/ } return TowerInfo.UNKNOWN; }
From source file:Main.java
static public synchronized boolean checkConnectivity(Context context) { SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(context); // mMobile = prefs.getBoolean(ENUMPrefs.ENUM_PREF_MOBILE, false); mOnline = false;/* www. j av a2 s .c o m*/ ConnectivityManager mCmgr = (ConnectivityManager) context.getSystemService(Service.CONNECTIVITY_SERVICE); NetworkInfo ni = mCmgr.getNetworkInfo(ConnectivityManager.TYPE_WIFI); if (ni != null && ni.isConnected()) { /* wifi is on */ mOnline = true; } else { if (mMobile) { /* if mobile is active and EDGE or better, we're good */ ni = mCmgr.getNetworkInfo(ConnectivityManager.TYPE_MOBILE); if (ni != null && ni.isConnected()) { mOnline = (ni.getSubtype() >= TelephonyManager.NETWORK_TYPE_EDGE); } } } return mOnline; }
From source file:org.basdroid.common.NetworkUtils.java
/** * Check if there is fast connectivity/*from w ww . j a v a2s. c o m*/ * @param context * @return */ public static boolean isConnectedFast(Context context) { NetworkInfo info = getNetworkInfo(context); return (info != null && info.isConnected() && isConnectionFast(info.getType(), info.getSubtype())); }
From source file:org.basdroid.common.NetworkUtils.java
public static boolean isLTE(Context context) { NetworkInfo info = getNetworkInfo(context); if (info == null || !info.isConnected()) { return false; }//from w w w .ja va 2 s . c om int type = info.getType(); int subType = info.getSubtype(); if (type == ConnectivityManager.TYPE_WIFI) { return false; } else if (type == ConnectivityManager.TYPE_MOBILE) { switch (subType) { case TelephonyManager.NETWORK_TYPE_1xRTT: case TelephonyManager.NETWORK_TYPE_CDMA: case TelephonyManager.NETWORK_TYPE_EDGE: case TelephonyManager.NETWORK_TYPE_EVDO_0: case TelephonyManager.NETWORK_TYPE_EVDO_A: case TelephonyManager.NETWORK_TYPE_GPRS: case TelephonyManager.NETWORK_TYPE_HSDPA: case TelephonyManager.NETWORK_TYPE_HSPA: case TelephonyManager.NETWORK_TYPE_HSUPA: case TelephonyManager.NETWORK_TYPE_UMTS: return false; // ~ 50-100 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 case TelephonyManager.NETWORK_TYPE_EVDO_B: // API level 9 case TelephonyManager.NETWORK_TYPE_HSPAP: // API level 13 case TelephonyManager.NETWORK_TYPE_IDEN: // API level 8 return false; // ~ 50-100 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; } }
From source file:hobby.wei.c.phone.Network.java
private static Type getType(NetworkInfo netInfo) { Type type;//from w w w . j a v a 2 s. com //?TYPE_WIFI?TYPE_MOBILE?TYPE_MOBILE_MMS if (netInfo.getType() == ConnectivityManager.TYPE_WIFI) { //wifi? type = Type.WIFI; } else { //TYPE_WIFI switch (netInfo.getSubtype()) { case TelephonyManager.NETWORK_TYPE_UNKNOWN: type = Type.NO_NET; break; case TelephonyManager.NETWORK_TYPE_GPRS: case TelephonyManager.NETWORK_TYPE_EDGE: type = Type.G2; break; case TelephonyManager.NETWORK_TYPE_UMTS: case TelephonyManager.NETWORK_TYPE_CDMA: //3G case TelephonyManager.NETWORK_TYPE_EVDO_0: case TelephonyManager.NETWORK_TYPE_EVDO_A: case TelephonyManager.NETWORK_TYPE_1xRTT: //2.5GCDMA case TelephonyManager.NETWORK_TYPE_HSDPA: case TelephonyManager.NETWORK_TYPE_HSUPA: case TelephonyManager.NETWORK_TYPE_HSPA: case TelephonyManager.NETWORK_TYPE_IDEN: case TelephonyManager.NETWORK_TYPE_EVDO_B: case TelephonyManager.NETWORK_TYPE_EHRPD: case TelephonyManager.NETWORK_TYPE_HSPAP: type = Type.G3; break; case TelephonyManager.NETWORK_TYPE_LTE: type = Type.G4; break; default: type = Type.G4; break; } } return type; }
From source file:com.adam.aslfms.util.Util.java
public static NetworkStatus checkForOkNetwork(Context ctx) { AppSettings settings = new AppSettings(ctx); PowerOptions powerOptions = checkPower(ctx); NetworkOptions networkOptions = settings.getNetworkOptions(powerOptions); boolean roaming = settings.getSubmitOnRoaming(powerOptions); ConnectivityManager connectivityManager = (ConnectivityManager) ctx .getSystemService(Context.CONNECTIVITY_SERVICE); NetworkInfo netInfo = connectivityManager.getActiveNetworkInfo(); if (netInfo == null) { Log.d(TAG, "netInfo == null"); }/*from w w w . ja va 2 s . c om*/ if (netInfo != null) { Log.d(TAG, "conn: " + netInfo.isConnected() + " : " + netInfo.toString()); } if (netInfo == null || !netInfo.isConnected()) { return NetworkStatus.DISCONNECTED; } if (netInfo.isRoaming() && !roaming) { return NetworkStatus.UNFIT; } int netType = netInfo.getType(); int netSubType = netInfo.getSubtype(); Log.d(TAG, "netType: " + netType); Log.d(TAG, "netSubType: " + netSubType); if (networkOptions.isNetworkTypeForbidden(netType)) { Log.d(TAG, "Network type forbidden"); return NetworkStatus.UNFIT; } if (networkOptions.isNetworkSubTypeForbidden(netType, netSubType)) { Log.d(TAG, "Network sub type forbidden"); return NetworkStatus.UNFIT; } return NetworkStatus.OK; }
From source file:android_network.hetnet.vpn_service.Util.java
public static int getNetworkType(Context context) { ConnectivityManager cm = (ConnectivityManager) context.getSystemService(Context.CONNECTIVITY_SERVICE); NetworkInfo ni = (cm == null ? null : cm.getActiveNetworkInfo()); return (ni == null ? TelephonyManager.NETWORK_TYPE_UNKNOWN : ni.getSubtype()); }