Android gets the current type of mobile phone network (2g, 3g, 4g, WiFi) and mobile phone model, version number code _android

Source: Internet
Author: User

Get mobile phone Model: Android.os.Build.MODEL

Get the phone's SDK version number: Android.os.Build.VERSION.SDK

Get the phone's current network type code as follows: This is a tool class that you can save for later use.

Package com.iqtogether.qxueyou.support.util; 
Import Android.content.Context; 
Import Android.net.ConnectivityManager; 
Import Android.net.NetworkInfo; 
Import Android.telephony.TelephonyManager; 
/** * Gets the network connection tool class * Created by Chengguo on 2016/3/17. 
*/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 final 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; /** * Get Current network connection type * @param context * @return/public static int Getnetworkstate (context) {//Get the Network service of the system Con 
Nectivitymanager Connmanager = (connectivitymanager) context.getsystemservice (Context.connectivity_service); 
If there is currently no network if (null = Connmanager) return networn_none; 
Gets the current network type, if NULL, returns no network networkinfo activenetinfo = Connmanager.getactivenetworkinfo (); if (Activenetinfo = null | |!activenetinfo.isAvailable ()) {return networn_none; 
//Determine if the connection is not WIFI 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_w 
IFI; }//If it is not WiFi, determine which network of carriers is currently connected 2g, 3g, 4g, etc. networkinfo networkinfo = Connmanager.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 (activene Tinfo.getsubtype ()) {//If 2g type case TELEPHONYMANAGER.NETWORK_TYPE_GPRS://Unicom 2g TELEPHONYMANAGER.NETWORK_TYPE_CD MA://Telecom 2g Case Telephonymanager.network_type_edge://Mobile 2g Case TelephonyManager.NETWORK_TYPE_1xRTT:case Telephonyma Nager. Network_type_ideN:return networn_2g; If it is a 3g type case TELEPHONYMANAGER.NETWORK_TYPE_EVDO_A://Telecom 3g TelephonyManager.NETWORK_TYPE_UMTS:case Telephonyma Nager. 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 type case TelephonyManager.NETWORK_TYPE_LTE:return networn_4g; Default://China Mobile Unicom Telecom Three kinds of 3G format if (Strsubtypename.equalsignorecase ("TD-SCDMA") | | strsubtypename.equalsignorecase ("WCDMA ") || 
Strsubtypename.equalsignorecase ("CDMA2000")) {return networn_3g; 
else {return networn_mobile; 
}}} return networn_none;  } 
}

The above is a small series to introduce Android to get the current type of mobile phone network (2g, 3g, 4g, WiFi), as well as the phone model, version number of all the description, I hope to help you!

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.