通過 Android 提供的 TelephonyManager 和 ConnectivityManager 都可以獲取到 NetworksInfo 對象,可以通過 getType() 獲取類型拉鹃,判斷是 wifi 還是 mobile 茶凳,如果是 mobile ,可以通過 NetworksInfo 對象的 getSubType() 和 getSubTypeName() 可以獲取到對于的網(wǎng)絡(luò)類型和名字。轉(zhuǎn)載請注明來自:http://www.binkery.com/
網(wǎng)絡(luò)類型和名字定義在 TelephonyManager 類里。(源代碼中有)
/** Network type is unknown */
public?static?final?int?NETWORK_TYPE_UNKNOWN?=?0;
/**?Current?network?is?GPRS?*/
public?static?final?int?NETWORK_TYPE_GPRS?=?1;
/**?Current?network?is?EDGE?*/
public?static?final?int?NETWORK_TYPE_EDGE?=?2;
/**?Current?network?is?UMTS?*/
public?static?final?int?NETWORK_TYPE_UMTS?=?3;
/**?Current?network?is?CDMA:?Either?IS95A?or?IS95B*/
public?static?final?int?NETWORK_TYPE_CDMA?=?4;
/**?Current?network?is?EVDO?revision?0*/
public?static?final?int?NETWORK_TYPE_EVDO_0?=?5;
/**?Current?network?is?EVDO?revision?A*/
public?static?final?int?NETWORK_TYPE_EVDO_A?=?6;
/**?Current?network?is?1xRTT*/
public?static?final?int?NETWORK_TYPE_1xRTT?=?7;
/**?Current?network?is?HSDPA?*/
public?static?final?int?NETWORK_TYPE_HSDPA?=?8;
/**?Current?network?is?HSUPA?*/
public?static?final?int?NETWORK_TYPE_HSUPA?=?9;
/**?Current?network?is?HSPA?*/
public?static?final?int?NETWORK_TYPE_HSPA?=?10;
/**?Current?network?is?iDen?*/
public?static?final?int?NETWORK_TYPE_IDEN?=?11;
/**?Current?network?is?EVDO?revision?B*/
public?static?final?int?NETWORK_TYPE_EVDO_B?=?12;
/**?Current?network?is?LTE?*/
public?static?final?int?NETWORK_TYPE_LTE?=?13;
/**?Current?network?is?eHRPD?*/
public?static?final?int?NETWORK_TYPE_EHRPD?=?14;
/**?Current?network?is?HSPA+?*/
public?static?final?int?NETWORK_TYPE_HSPAP?=?15;
那怎么判斷是 2G , 3G 還是 4G 網(wǎng)絡(luò)呢萎馅?TelephonyManager 還提供了另外一個方法,getNetworkClass(int networkType) 虹蒋,但這個方法被隱藏掉了糜芳,我把代碼貼一下。
public static int getNetworkClass(int networkType) {?
? ? ? switch (networkType) {?
? ? ? ? ? ? ?case NETWORK_TYPE_GPRS:
? ? ? ? ? ? ?case NETWORK_TYPE_EDGE:
? ? ? ? ? ? ? case NETWORK_TYPE_CDMA:?
? ? ? ? ? ? ? case NETWORK_TYPE_1xRTT:?
? ? ? ? ? ? ? case NETWORK_TYPE_IDEN:?
? ? ? ?return NETWORK_CLASS_2_G;?
? ? ? ? ? ? case NETWORK_TYPE_UMTS:?
? ? ? ? ? ? ?case NETWORK_TYPE_EVDO_0:
? ? ? ? ? ? ? case NETWORK_TYPE_EVDO_A:?
? ? ? ? ? ? ? case NETWORK_TYPE_HSDPA:?
? ? ? ? ? ? ? case NETWORK_TYPE_HSUPA:?
? ? ? ? ? ? ?case NETWORK_TYPE_HSPA:?
? ? ? ? ? ? ? case NETWORK_TYPE_EVDO_B:
? ? ? ? ? ? ? case NETWORK_TYPE_EHRPD:?
? ? ? ? ? ? ?case NETWORK_TYPE_HSPAP:
? ? ? ? ? return NETWORK_CLASS_3_G;?
? ? ? ? ? ? ?case NETWORK_TYPE_LTE:?
? ? ? ? return NETWORK_CLASS_4_G;?
? ? ? ? ? ? ?default:?
? ? ? ?return NETWORK_CLASS_UNKNOWN;
? ?}?
}
貼上我收集整理的一些資料千诬,可以參考一下耍目。
GPRS : 2G(2.5) General Packet Radia Service 114kbps
EDGE : 2G(2.75G) Enhanced Data Rate for GSM Evolution 384kbps
UMTS : 3G WCDMA 聯(lián)通3G Universal Mobile Telecommunication System 完整的3G移動通信技術(shù)標(biāo)準(zhǔn)
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 - 無線電傳輸技術(shù)) 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 集成數(shù)字增強(qiáng)型網(wǎng)絡(luò) (屬于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的中間產(chǎn)物 Evolved High Rate Packet Data HRPD的升級
HSPAP : 3G HSPAP 比 HSDPA 快些
本文作者:Binkery
本文地址:http://www.binkery.com/archives/368.html
版權(quán)聲明:歡迎任何形式的轉(zhuǎn)載,但請務(wù)必注明出處傲茄,尊重他人勞動成果