本文整理匯總了Java中android.net.NetworkInfo.getSubtype方法的典型用法代碼示例。如果您正苦於以下問題:Java NetworkInfo.getSubtype方法的具體用法?Java NetworkInfo.getSubtype怎麽用?Java NetworkInfo.getSubtype使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類android.net.NetworkInfo
的用法示例。
在下文中一共展示了NetworkInfo.getSubtype方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: adjustThreadCount
import android.net.NetworkInfo; //導入方法依賴的package包/類
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);
}
}
示例2: getCurrentNetworkType
import android.net.NetworkInfo; //導入方法依賴的package包/類
/**
* 獲取手機當前網絡類型
*/
public static String getCurrentNetworkType(Context context) {
String type = "";
ConnectivityManager cm = (ConnectivityManager) context
.getSystemService(Context.CONNECTIVITY_SERVICE);
NetworkInfo info = cm.getActiveNetworkInfo();
if (info == null) {
type = "null";
} else if (info.getType() == ConnectivityManager.TYPE_WIFI) {
type = "wifi";
} else if (info.getType() == ConnectivityManager.TYPE_MOBILE) {
int subType = info.getSubtype();
if (subType == TelephonyManager.NETWORK_TYPE_CDMA
|| subType == TelephonyManager.NETWORK_TYPE_GPRS
|| subType == TelephonyManager.NETWORK_TYPE_EDGE) {
type = "2g";
} else if (subType == TelephonyManager.NETWORK_TYPE_UMTS
|| subType == TelephonyManager.NETWORK_TYPE_HSDPA
|| subType == TelephonyManager.NETWORK_TYPE_EVDO_A
|| subType == TelephonyManager.NETWORK_TYPE_EVDO_0
|| subType == TelephonyManager.NETWORK_TYPE_EVDO_B) {
type = "3g";
} else if (subType == TelephonyManager.NETWORK_TYPE_LTE) {// LTE是3g到4g的過渡,是3.9G的全球標準
type = "4g";
}
}
return type;
}
示例3: getNetworkState
import android.net.NetworkInfo; //導入方法依賴的package包/類
/**
* Returns connection type and status information gleaned from networkInfo.
*/
NetworkState getNetworkState(NetworkInfo networkInfo) {
if (networkInfo == null || !networkInfo.isConnected()) {
return new NetworkState(false, -1, -1);
}
return new NetworkState(true, networkInfo.getType(), networkInfo.getSubtype());
}
示例4: getNetworkClass
import android.net.NetworkInfo; //導入方法依賴的package包/類
/**
* 獲取在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;
}
示例5: is2G
import android.net.NetworkInfo; //導入方法依賴的package包/類
/**
* is2G
*
* @return boolean
*/
public static boolean is2G() {
ConnectivityManager connectivityManager = (ConnectivityManager) ContextHolder.getContext()
.getSystemService(Context.CONNECTIVITY_SERVICE);
NetworkInfo activeNetInfo = connectivityManager.getActiveNetworkInfo();
if (activeNetInfo != null
&& (activeNetInfo.getSubtype() == TelephonyManager.NETWORK_TYPE_EDGE
|| activeNetInfo.getSubtype() == TelephonyManager.NETWORK_TYPE_GPRS || activeNetInfo
.getSubtype() == TelephonyManager.NETWORK_TYPE_CDMA)) {
return true;
}
return false;
}
示例6: getNetworkClass
import android.net.NetworkInfo; //導入方法依賴的package包/類
/**
* 獲取在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;
}
示例7: getAPNType
import android.net.NetworkInfo; //導入方法依賴的package包/類
/**
* 獲取當前的網絡狀態 :沒有網絡-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;
}
示例8: getNetworkType
import android.net.NetworkInfo; //導入方法依賴的package包/類
/**
* 獲取當前網絡類型
* <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;
}
示例9: getNetWorkType
import android.net.NetworkInfo; //導入方法依賴的package包/類
/**
* 獲取當前的網絡類型(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;
}
示例10: getNetworkType
import android.net.NetworkInfo; //導入方法依賴的package包/類
/**
* 判斷當前網絡類型-1為未知網絡0為沒有網絡連接1網絡斷開或關閉2為以太網3為WiFi4為2G5為3G6為4G
*/
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()) {
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:
// 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:
// 3G網絡
case TelephonyManager.NETWORK_TYPE_LTE:
// 4G網絡
return NETWORK_MOBILE;
}
}
// 未知網絡
return NETWORK_UNKNOWN;
}
示例11: getNetWorkType
import android.net.NetworkInfo; //導入方法依賴的package包/類
/**
* 獲取當前的網絡類型(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;
}
示例12: isValidMobileConnectionFor
import android.net.NetworkInfo; //導入方法依賴的package包/類
private boolean isValidMobileConnectionFor(NetworkInfo ni, String suffix) {
boolean valid_for_3g = getPreferenceBooleanValue("use_3g_" + suffix, false);
boolean valid_for_edge = getPreferenceBooleanValue("use_edge_" + suffix, false);
boolean valid_for_gprs = getPreferenceBooleanValue("use_gprs_" + suffix, false);
boolean valid_for_roaming = getPreferenceBooleanValue("use_roaming_" + suffix, true);
if(!valid_for_roaming && ni != null) {
if(ni.isRoaming()) {
return false;
}
}
if ((valid_for_3g || valid_for_edge || valid_for_gprs) &&
ni != null) {
int type = ni.getType();
// Any mobile network connected
if (ni.isConnected() &&
// Type 3,4,5 are other mobile data ways
(type == ConnectivityManager.TYPE_MOBILE || (type <= 5 && type >= 3))) {
int subType = ni.getSubtype();
// 3G (or better)
if (valid_for_3g &&
subType >= TelephonyManager.NETWORK_TYPE_UMTS) {
return true;
}
// GPRS (or unknown)
if (valid_for_gprs
&&
(subType == TelephonyManager.NETWORK_TYPE_GPRS || subType == TelephonyManager.NETWORK_TYPE_UNKNOWN)) {
return true;
}
// EDGE
if (valid_for_edge &&
subType == TelephonyManager.NETWORK_TYPE_EDGE) {
return true;
}
}
}
return false;
}
示例13: checkNetworkType
import android.net.NetworkInfo; //導入方法依賴的package包/類
static int checkNetworkType(Context context) {
int netType = 0;
//連接管理對象
ConnectivityManager manager = (ConnectivityManager) context.getSystemService(Context.CONNECTIVITY_SERVICE);
//獲取NetworkInfo對象
@SuppressLint("MissingPermission") 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;
}
}
示例14: getCurrentNetState
import android.net.NetworkInfo; //導入方法依賴的package包/類
/**
* 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;
}
示例15: getNetType
import android.net.NetworkInfo; //導入方法依賴的package包/類
public String getNetType() {
String netType = "";
NetworkInfo info = ((ConnectivityManager) this.context.getSystemService("connectivity")).getActiveNetworkInfo();
if (info == null) {
return netType;
}
int nType = info.getType();
if (nType == 0) {
switch (info.getSubtype()) {
case 1:
netType = "GPRS";
break;
case 2:
netType = "EDGE";
break;
case 3:
netType = "UMTS";
break;
case 4:
netType = "CDMA";
break;
case 5:
netType = "EVDO0";
break;
case 6:
netType = "EVDOA";
break;
case 8:
netType = "HSDPA";
break;
case 9:
netType = "HSUPA";
break;
case 10:
netType = "HSPA";
break;
default:
netType = "其他網絡";
break;
}
} else if (nType == 1) {
netType = "NETTYPE_WIFI";
}
return netType;
}