本文整理匯總了Java中android.telephony.TelephonyManager.NETWORK_TYPE_CDMA屬性的典型用法代碼示例。如果您正苦於以下問題:Java TelephonyManager.NETWORK_TYPE_CDMA屬性的具體用法?Java TelephonyManager.NETWORK_TYPE_CDMA怎麽用?Java TelephonyManager.NETWORK_TYPE_CDMA使用的例子?那麽, 這裏精選的屬性代碼示例或許可以為您提供幫助。您也可以進一步了解該屬性所在類android.telephony.TelephonyManager
的用法示例。
在下文中一共展示了TelephonyManager.NETWORK_TYPE_CDMA屬性的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: getNetworkClass
/**
* 獲取在Mobile網絡下的網絡類型. 2G,3G,4G
*
* @param context
* @return
*/
public static int getNetworkClass(Context context) {
ConnectivityManager connectivityManager = (ConnectivityManager) context
.getSystemService(Context.CONNECTIVITY_SERVICE);
if (connectivityManager != null) {
NetworkInfo networkInfo = connectivityManager.getActiveNetworkInfo();
if (networkInfo != null) {
if (networkInfo.getType() == ConnectivityManager.TYPE_MOBILE) {
switch (networkInfo.getSubtype()) {
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 NETWORK_CLASS_2_G;
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 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;
}
} else if (networkInfo.getType() == ConnectivityManager.TYPE_WIFI) {
return NETWORK_CLASS_WIFI;
}
}
}
return NETWORK_CLASS_UNKNOWN;
}
示例2: getAPNType
/**
* 獲取當前的網絡狀態 :沒有網絡-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;
}
示例3: checkNetworkType
public static int checkNetworkType(Context context) {
int netType = 0;
//連接管理對象
ConnectivityManager manager = (ConnectivityManager) context.getSystemService(Context.CONNECTIVITY_SERVICE);
//獲取NetworkInfo對象
NetworkInfo networkInfo = manager.getActiveNetworkInfo();
if (networkInfo == null)
return netType;
switch (networkInfo.getType()) {
case ConnectivityManager.TYPE_WIFI:
case ConnectivityManager.TYPE_WIMAX:
case ConnectivityManager.TYPE_ETHERNET:
return 1;
case ConnectivityManager.TYPE_MOBILE:
switch (networkInfo.getSubtype()) {
case TelephonyManager.NETWORK_TYPE_LTE: // 4G
case TelephonyManager.NETWORK_TYPE_HSPAP:
case TelephonyManager.NETWORK_TYPE_EHRPD:
return 2;
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 3;
case TelephonyManager.NETWORK_TYPE_GPRS: // 2G
case TelephonyManager.NETWORK_TYPE_EDGE:
return 4;
default:
return netType;
}
default:
return netType;
}
}
示例4: getNetworkType
/**
* 獲取當前網絡類型
* <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;
}
示例5: getNetworkType
/**
* @return netType 返回類型
* @throws
* @方法名: getAPNType
* @說 明: 獲取當前的網絡狀態 -1:沒有網絡 1:WIFI網絡2:wap 網絡3:net網絡
* @參 數: @param context
* @參 數: @return
*/
public static NetType getNetworkType(Context context) {
NetType netType = null;
ConnectivityManager manager = (ConnectivityManager) context.getSystemService(Context.CONNECTIVITY_SERVICE);
NetworkInfo networkInfo = manager.getActiveNetworkInfo();
if (networkInfo != null && networkInfo.isConnected()) {
if (networkInfo.getType() == ConnectivityManager.TYPE_WIFI) {
netType = NetType.NETWORK_WIFI;
} else if (networkInfo.getType() == ConnectivityManager.TYPE_MOBILE) {
// 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
netType = NetType.NETWORK_2_G;
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
netType = NetType.NETWORK_3_G;
break;
case TelephonyManager.NETWORK_TYPE_LTE: //api<11 : replace by 13
netType = NetType.NETWORK_4_G;
break;
default:
String typeName = networkInfo.getSubtypeName();
// http://baike.baidu.com/item/TD-SCDMA 中國移動 聯通 電信 三種3G製式
if (typeName.equalsIgnoreCase("TD-SCDMA") || typeName.equalsIgnoreCase("WCDMA") || typeName.equalsIgnoreCase("CDMA2000")) {
netType = NetType.NETWORK_3_G;
} else {
netType = NetType.NETWORK_UNKNOWN;
}
break;
}
}
}
return netType;
}
示例6: adjustThreadCount
void adjustThreadCount(NetworkInfo info) {
if (info == null || !info.isConnectedOrConnecting()) {
setThreadCount(DEFAULT_THREAD_COUNT);
return;
}
switch (info.getType()) {
case ConnectivityManager.TYPE_WIFI:
case ConnectivityManager.TYPE_WIMAX:
case ConnectivityManager.TYPE_ETHERNET:
setThreadCount(4);
break;
case ConnectivityManager.TYPE_MOBILE:
switch (info.getSubtype()) {
case TelephonyManager.NETWORK_TYPE_LTE: // 4G
case TelephonyManager.NETWORK_TYPE_HSPAP:
case TelephonyManager.NETWORK_TYPE_EHRPD:
setThreadCount(3);
break;
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:
setThreadCount(2);
break;
case TelephonyManager.NETWORK_TYPE_GPRS: // 2G
case TelephonyManager.NETWORK_TYPE_EDGE:
setThreadCount(1);
break;
default:
setThreadCount(DEFAULT_THREAD_COUNT);
}
break;
default:
setThreadCount(DEFAULT_THREAD_COUNT);
}
}
示例7: isFastMobileNetwork
/**
* 通過TelephonyManager服務獲取網絡連接的網速類別
* @param context
* @return
*/
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;
}
}
示例8: getCurrentNetState
/**
* get the net state of current
* @param context the context.
* @return the state code. see {@linkplain #STATE_2G} and etc.
*/
public static byte getCurrentNetState(Context context) {
byte code = STATE_NO;
ConnectivityManager cm = (ConnectivityManager) context.getSystemService(Context.CONNECTIVITY_SERVICE);
NetworkInfo ni = cm.getActiveNetworkInfo();
if (ni != null && ni.isConnectedOrConnecting()) {
switch (ni.getType()) {
//wifi
case ConnectivityManager.TYPE_WIFI:
code = STATE_WIFI;
break;
//mobile 網絡
case ConnectivityManager.TYPE_MOBILE:
switch (ni.getSubtype()) {
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:
code = STATE_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:
code = STATE_3G;
break;
case TelephonyManager.NETWORK_TYPE_LTE://4G
code = STATE_4G;
break;
default:
code = STATE_UNKNOWN;
}
break;
default:
code = STATE_UNKNOWN;
}
}
return code;
}
示例9: getNetworkType
/**
* GPRS 2G(2.5) General Packet Radia Service 114kbps
* EDGE 2G(2.75G) Enhanced Data Rate for GSM Evolution 384kbps
* UMTS 3G WCDMA 聯通3G Universal Mobile Telecommunication System 完整的3G移動通信技術標準
* CDMA 2G 電信 Code Division Multiple Access 碼分多址
* EVDO_0 3G (EVDO 全程 CDMA2000 1xEV-DO) Evolution - Data Only (Data Optimized) 153.6kps - 2.4mbps 屬於3G
* EVDO_A 3G 1.8mbps - 3.1mbps 屬於3G過渡,3.5G
* 1xRTT 2G CDMA2000 1xRTT (RTT - 無線電傳輸技術) 144kbps 2G的過渡,
* HSDPA 3.5G 高速下行分組接入 3.5G WCDMA High Speed Downlink Packet Access 14.4mbps
* HSUPA 3.5G High Speed Uplink Packet Access 高速上行鏈路分組接入 1.4 - 5.8 mbps
* HSPA 3G (分HSDPA,HSUPA) High Speed Packet Access
* IDEN 2G Integrated Dispatch Enhanced Networks 集成數字增強型網絡 (屬於2G,來自維基百科)
* EVDO_B 3G EV-DO Rev.B 14.7Mbps 下行 3.5G
* LTE 4G Long Term Evolution FDD-LTE 和 TDD-LTE , 3G過渡,升級版 LTE Advanced 才是4G
* EHRPD 3G CDMA2000向LTE 4G的中間產物 Evolved High Rate Packet Data HRPD的升級
* HSPAP 3G HSPAP 比 HSDPA 快些
*
* @return {@link NetWorkType}
*/
public static NetWorkType getNetworkType(Context context) {
int type = getConnectedTypeINT(context);
switch (type) {
case ConnectivityManager.TYPE_WIFI:
return NetWorkType.Wifi;
case ConnectivityManager.TYPE_MOBILE:
case ConnectivityManager.TYPE_MOBILE_DUN:
case ConnectivityManager.TYPE_MOBILE_HIPRI:
case ConnectivityManager.TYPE_MOBILE_MMS:
case ConnectivityManager.TYPE_MOBILE_SUPL:
int teleType = getTelephonyManager(context).getNetworkType();
switch (teleType) {
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 NetWorkType.Net2G;
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 NetWorkType.Net3G;
case TelephonyManager.NETWORK_TYPE_LTE:
return NetWorkType.Net4G;
default:
return NetWorkType.UnKnown;
}
default:
return NetWorkType.UnKnown;
}
}
示例10: updateBatchSize
/**
* Update batch size based on network type and status
*
* @param context the context, usually the application context
*/
public static int updateBatchSize(@Nullable final Context context) {
if (context == null) {
sBatchSize = 6;
return sBatchSize;
}
// No network, use small batch size
NetworkInfo info = getNetworkInfo(context);
if (info == null || !info.isConnected()) {
sBatchSize = 6;
return sBatchSize;
}
// In WiFi, use large batch size
if (info.getType() == ConnectivityManager.TYPE_WIFI) {
sBatchSize = 24;
return sBatchSize;
}
if (info.getType() == ConnectivityManager.TYPE_MOBILE) {
switch (info.getSubtype()) {
case TelephonyManager.NETWORK_TYPE_HSDPA: // ~ 2-14 Mbps
case TelephonyManager.NETWORK_TYPE_HSUPA: // ~ 1-23 Mbps
case TelephonyManager.NETWORK_TYPE_EHRPD: // ~ 1-2 Mbps
case TelephonyManager.NETWORK_TYPE_EVDO_B: // ~ 5 Mbps
case TelephonyManager.NETWORK_TYPE_HSPAP: // ~ 10-20 Mbps
case TelephonyManager.NETWORK_TYPE_LTE: // ~ 10+ Mbps
sBatchSize = 24;
break;
case TelephonyManager.NETWORK_TYPE_EVDO_0: // ~ 400-1000 kbps
case TelephonyManager.NETWORK_TYPE_EVDO_A: // ~ 600-1400 kbps
case TelephonyManager.NETWORK_TYPE_HSPA: // ~ 700-1700 kbps
case TelephonyManager.NETWORK_TYPE_UMTS: // ~ 400-7000 kbps
sBatchSize = 12;
break;
case TelephonyManager.NETWORK_TYPE_IDEN: // ~25 kbps
case TelephonyManager.NETWORK_TYPE_CDMA: // ~ 14-64 kbps
case TelephonyManager.NETWORK_TYPE_1xRTT: // ~ 50-100 kbps
case TelephonyManager.NETWORK_TYPE_EDGE: // ~ 50-100 kbps
case TelephonyManager.NETWORK_TYPE_GPRS: // ~ 100 kbps
case TelephonyManager.NETWORK_TYPE_UNKNOWN:
default:
sBatchSize = 6;
break;
}
} else {
// In other undetermined network, use small batch size
sBatchSize = 6;
}
return sBatchSize;
}
示例11: isFastMobileNetwork
/**
* Whether is fast mobile network
*
* @param context
* @return
*/
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;
}
}
示例12: isFastMobileNetwork
/**
* 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;
}
}
示例13: isConnectionFast
/**
* Check if the connection is fast
*
* @param type of connection
* @param subType of connection
* @return true if the connection is 3g or above
*/
public static boolean isConnectionFast(final int type, final int subType) {
switch (type) {
case ConnectivityManager.TYPE_WIFI:
return true;
case ConnectivityManager.TYPE_WIMAX:
return true;
case 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: // 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;
}
default:
return false;
}
}
示例14: isFastMobileNetwork
/**
* Whether is fast mobile network
*
* @param context
* @return
*/
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;
}
}
示例15: getAPNType
/**
* 獲取當前的網絡狀態 :沒有網絡-0:WIFI網絡1:4G網絡-4:3G網絡-3:2G網絡-2
* 自定義
*/
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;
}