In Android development, many of my friends may determine the network type of the mobile phone, because the current Android mobile phone may be in a 4-digit status.
1. No network (this status may be due to the shutdown of the mobile phone, the network is not enabled, and the signal is poor)
2. Use wifi to access the Internet
3. cmwap (China Mobile proxy)
4. access the Internet through cmnet
If there is no network in these four statuses, you must be unable to request the Internet. If it is WAP, you need to add a China Mobile proxy for your mobile phone. For details about adding a China Mobile proxy for your mobile phone, please go
Http://blog.csdn.net/vipa1888/article/details/7004883 here write an example about adding China Mobile Agent!
The following is a network judgment method:
/*** @ Author spring sky * Email vipa1888@163.com * QQ: 840950105 my name: Shi mingzheng * Get the current network status-1: No network 1: WiFi network 2: WAP network 3: Net network * @ Param context * @ return */public static int getapntype (context) {int nettype =-1; connectivitymanager connmgr = (connectivitymanager) context. getsystemservice (context. connectivity_service); networkinfo = connmgr. getactivenetworkinfo (); If (networkinfo = NULL) {return nettype;} int ntype = networkinfo. getType (); If (ntype = connectivitymanager. type_mobile) {log. E ("networkinfo. getextrainfo () "," networkinfo. getextrainfo () is "+ networkinfo. getextrainfo (); If (networkinfo. getextrainfo (). tolowercase (). equals ("cmnet") {nettype = cmnet;} else {nettype = cmwap;} else if (ntype = connectivitymanager. type_wifi) {nettype = WiFi;} return nettype ;}
Because the service object is obtained, the network status is refreshed from time to time, so we only need to get the network status!
I hope to share my learning experience with you!