android 获取网络类型名称2G 3G 4G wifi

首先工程Manifest文件要引用:

 <uses-permission android:name="android.permission.ACCESS_WIFI_STATE" />
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />

//获取网络服务

 public static String getNetworkTypeName(Context context) {
if (context != null) {
ConnectivityManager connectMgr = (ConnectivityManager) context.getSystemService(Context.CONNECTIVITY_SERVICE);
if (connectMgr != null) {
NetworkInfo info = connectMgr.getActiveNetworkInfo();
if (info != null) {
switch (info.getType()) {
case ConnectivityManager.TYPE_WIFI:
return "WIFI";
case ConnectivityManager.TYPE_MOBILE:
return getNetworkTypeName(info.getSubtype());
}
}
}
}
return getNetworkTypeName(TelephonyManager.NETWORK_TYPE_UNKNOWN);
}

//网络型号

 public static String getNetworkTypeName(int type) {
switch (type) {
case TelephonyManager.NETWORK_TYPE_GPRS:
return "GPRS";
case TelephonyManager.NETWORK_TYPE_EDGE:
return "EDGE";
case TelephonyManager.NETWORK_TYPE_UMTS:
return "UMTS";
case TelephonyManager.NETWORK_TYPE_HSDPA:
return "HSDPA";
case TelephonyManager.NETWORK_TYPE_HSUPA:
return "HSUPA";
case TelephonyManager.NETWORK_TYPE_HSPA:
return "HSPA";
case TelephonyManager.NETWORK_TYPE_CDMA:
return "CDMA";
case TelephonyManager.NETWORK_TYPE_EVDO_0:
return "CDMA - EvDo rev. 0";
case TelephonyManager.NETWORK_TYPE_EVDO_A:
return "CDMA - EvDo rev. A";
case TelephonyManager.NETWORK_TYPE_EVDO_B:
return "CDMA - EvDo rev. B";
case TelephonyManager.NETWORK_TYPE_1xRTT:
return "CDMA - 1xRTT";
case TelephonyManager.NETWORK_TYPE_LTE:
return "LTE";
case TelephonyManager.NETWORK_TYPE_EHRPD:
return "CDMA - eHRPD";
case TelephonyManager.NETWORK_TYPE_IDEN:
return "iDEN";
case TelephonyManager.NETWORK_TYPE_HSPAP:
return "HSPA+";
default:
return "UNKNOWN";
}
}

调用:

 @Override
public void onClick(View view) {
// TODO Auto-generated method stub
switch (view.getId()) {
case R.id.btn_main:
String type =getNetworkTypeName(context);
if (type!=null){
if ( type.equals("GPRS") || type.equals("EGDE") )
type ="2G";
else if (type.equals("CDMA"))
type ="电信 2G";
else if (type.equals("EVDO"))
type ="电信 3G";
else if (type.equals("LTE"))
type ="电信 4G";
else if (type.equals("HSDPA") ||type.equals("UMTS") )
type ="3G"; }
btn_main.setText(type);
break;
}

注:

移动或联通的3G为UMTS或HSDPA,移动和联通的2G为GPRS或EGDE,电信的2G为CDMA,电信
的3G为EVDO,电信4G LTE

可以参考资料:

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

上一篇:ecshop二次开发添加快递


下一篇:[转]IPython Notebook简介1