Obtain the current network type (2g, 3g, 4g, wifi), mobile phone model, and version number of Android.
Obtain the mobile phone model: android. OS. build. MODEL: android. OS. build. VERSION. the code used to obtain the current network type of the mobile phone is as follows: This is a tool class, which can be saved for easy use.
Package com. iqtogether. qxueyou. support. util; import android. content. context; import android.net. connectivityManager; import android.net. networkInfo; import android. telephony. telephonyManager;/*** tool class for obtaining network connections * Created by chengguo on. */public class IntenetUtil {// No network connection public static final int NETWORN_NONE = 0; // wifi connection public static final int NETWORN_WIFI = 1; // mobile network data connection type public static fin Al int NETWORN_2G = 2; public static final int NETWORN_3G = 3; public static final int NETWORN_4G = 4; public static final int NETWORN_MOBILE = 5; /*** obtain the current network connection type * @ param context * @ return */public static int getNetworkState (Context context) {// obtain the system's network service ConnectivityManager connManager = (ConnectivityManager) context. getSystemService (Context. CONNECTIVITY_SERVICE); // if there is no network now if (null = connMa Nager) return NETWORN_NONE; // obtain the current network type. if it is null, NetworkInfo activeNetInfo = connManager. getActiveNetworkInfo (); if (activeNetInfo = null |! ActiveNetInfo. isAvailable () {return NETWORN_NONE;} // determines if the connection is wi-fi NetworkInfo wifiInfo = connManager. getNetworkInfo (ConnectivityManager. TYPE_WIFI); if (null! = WifiInfo) {NetworkInfo. State state = wifiInfo. getState (); if (null! = State) if (state = NetworkInfo. state. CONNECTED | state = NetworkInfo. state. CONNECTING) {return NETWORN_WIFI ;}// if it is not wifi, determine which network is connected to the carrier, NetworkInfo networkInfo = connManager, such as 2g, 3g, and 4g. getNetworkInfo (ConnectivityManager. TYPE_MOBILE); if (null! = NetworkInfo) {NetworkInfo. State state = networkInfo. getState (); String strSubTypeName = networkInfo. getSubtypeName (); if (null! = State) if (state = NetworkInfo. state. CONNECTED | state = NetworkInfo. state. CONNECTING) {switch (activeNetInfo. getSubtype () {// if it is a 2G case TelephonyManager. NETWORK_TYPE_GPRS: // China Unicom 2g case TelephonyManager. NETWORK_TYPE_CDMA: // China Telecom 2g case TelephonyManager. NETWORK_TYPE_EDGE: // move 2g case TelephonyManager. NETWORK_TYPE_1xRTT: case TelephonyManager. NETWORK_TYPE_IDEN: return NETWORN_2G; // if it is a 3G case TelephonyManager. NETWORK_TYPE_EVDO_A: // China Telecom 3g case TelephonyManager. NETWORK_TYPE_UMTS: case TelephonyManager. NETWORK_TYPE_EVDO_0: case TelephonyManager. NETWORK_TYPE_HSDPA: case TelephonyManager. NETWORK_TYPE_HSUPA: case TelephonyManager. NETWORK_TYPE_HSPA: case TelephonyManager. NETWORK_TYPE_EVDO_ B: case TelephonyManager. NETWORK_TYPE_EHRPD: case TelephonyManager. NETWORK_TYPE_HSPAP: return NETWORN_3G; // if it is a 4G case TelephonyManager. NETWORK_TYPE_LTE: return networn_4 g; default: // China Mobile Unicom China Telecom three G standard if (strSubTypeName. equalsIgnoreCase ("TD-SCDMA") | strSubTypeName. equalsIgnoreCase ("WCDMA") | strSubTypeName. equalsIgnoreCase ("CDMA 2000") {return NETWORN_3G;} else {return NETWORN_MOBILE ;}}} return NETWORN_NONE ;}}