Determine whether the network type is WiFi, 3G, or 2G network, for different
Network for different processing, now the judgment method is collated to everyone, for reference
Note: The data used below move 2G, Unicom 2G, Unicom 3g,wifi I have already tested, temporarily hand
There is no telecom card, so there is no authentication, a colleague with a telecom phone, can verify the results after verification
Sent to everyone.
Connectivitymanager connectmgr = (Connectivitymanager) This
. Getsystemservice (Context.connectivity_service);
Networkinfo info = Connectmgr.getactivenetworkinfo ();
First, determine whether the network is WiFi, before judging the non-null judgment must be carried out, if there is no network
Connect Info ==null
Info.gettype () = = Connectivitymanager.type_wifi
Second, to determine whether the mobile network
Info!=null && info.gettype () = = Connectivitymanager.type_mobile
The cellular network makes a detailed distinction:
Info.getsubtype () here uses Getsubtype (), not GetType (), GetType () returns the
is 0, or 1, is a cell phone network or WiFi
The list of Info.getsubtype () values is as follows:
* NETWORK_TYPE_CDMA network type is CDMA
* Network_type_edge network type is EDGE
* Network_type_evdo_0 network type is EVDO0
* Network_type_evdo_a network type is EVDOA
* Network_type_gprs network type is GPRS
* NETWORK_TYPE_HSDPA network type is HSDPA
* Network_type_hspa network type is HSPA
* Network_type_hsupa network type is HSUPA
* Network_type_umts network type is UMTS
Unicom 3G for UMTS or HSDPA, mobile and Unicom 2G for GPRS or edge, telecommunications 2G for CDMA, telecommunications
The 3G is EVDO
Android Gets the IP address of the phone
Private string getphoneip () { try { for (enumeration< Networkinterface> en = networkinterface.getnetworkinterfaces (); en.hasMoreElements ();) { networkinterface intf = en.nextelement (); for (enumeration<inetaddress> Enumipaddr = intf.getinetaddresses (); enumipaddr.hasmoreelements ();) { inetaddress inetaddress = enumipaddr.nextelement (); if (!inetaddress.isloopbackaddress () && inetaddress instanceof inet4address) { //if (!inetaddress.isloopbackaddress () && inetaddress instanceof inet6address) { return inetaddress.gethostaddress (). toString (); } } } } catch (exception e) { } return ""; }
Android Network type judgment (2g, 3g, WiFi)