This example describes how Android determines the type of network. Share to everyone for your reference, specific as follows:
To determine whether the network type is WiFi, or 3G, or 2G network, different processing of different networks, now will be judged by the method of sorting out for reference
Note: The following data used to move 2G, Unicom 2G, Unicom 3g,wifi I have been tested, the temporary hand does not have a telecom card, so there is no verification, a colleague of the mobile phone, you can verify the results sent to everyone.
Connectivitymanager connectmgr = (Connectivitymanager) this
. Getsystemservice (context.connectivity_service);
Networkinfo info = Connectmgr.getactivenetworkinfo ();
First, to determine whether the network is WiFi, before the judge must make a non-null judgment, if there is no network connection
Info ==null
info.gettype () = = Connectivitymanager.type_wifi
Second, to determine whether the mobile phone network
Info!=null && info.gettype () = = Connectivitymanager.type_mobile
A detailed distinction between mobile networks:
Info.getsubtype () here uses Getsubtype (), not GetType (), GetType () returns 0, or 1, which distinguishes between a cell phone network or a WiFi
The Info.getsubtype () value list 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's 3G for UMTS or HSDPA, mobile and Unicom 2G for GPRS or EDGE, telecom 2G for CDMA, telecom 3G for 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
"";
}
For more information on Android-related content readers can view the site topics: "Android Development Introduction and Advanced Course", "Android Database Operating skills summary" and "Android Control usage Summary"
I hope this article will help you with the Android program.