The Android platform provides a wide range of Network Interfaces. It is even more difficult to obtain the network access method set by the mobile phone, so it is very convenient for development.
Activity provides the ConnectivityManager interface for obtaining the network management class. You can use ConnectivityManager to obtain the Network Information Class NetworkInfo. NetworkInfo contains a lot of network information. Example code:
// Obtain the Network Connection Manager
ConnectivityManager connectionManager = (ConnectivityManager)
GetSystemService (CONNECTIVITY_SERVICE );
// Obtain the network status information in the following three methods:
NetworkInfo networkInfo = connectionManager. getActiveNetworkInfo ();
NetworkInfo has the following methods:
GetDetailedState (): Get the detailed status.
GetExtraInfo (): Get additional information.
GetReason (): Get the reason for connection failure.
GetType (): gets the network type (generally mobile or Wi-Fi ).
GetTypeName (): Get the network type name (generally set to "WIFI" or "MOBILE ").
IsAvailable (): determines whether the Network is available.
IsConnected (): determines whether a connection is established.
IsConnectedOrConnecting (): determines whether a connection is established or is in progress.
IsFailover (): determines whether the connection fails.
IsRoaming (): determines whether to roam
When using wifi
GetType is WIFI
GetExtraInfo is empty.
GetType is MOBILE
Using mobile CMNET
The value of getExtraInfo is cmnet.
Mobile CMWAP
The value of getExtraInfo is cmwap, but it cannot be accessed by a common website without a proxy.
3gwap connection
The value of getExtraInfo is 3 gwap.
Using China Unicom ipvnet
The value of getExtraInfo is 3 gnet.
Using Unicom uniwap
The value of getExtraInfo is uniwap.
Using Unicom uninet
The value of getExtraInfo is uninet.
To be determined by Telecom
The following solutions
Author: Liu Yafei