Android Get network type name 2G 3G 4G wifi

Source: Internet
Author: User

First the project manifest file to be referenced:

1 <uses-permission android:name= "Android.permission.ACCESS_WIFI_STATE"/>2 < Uses-permission android:name= "Android.permission.ACCESS_NETWORK_STATE"/>

Get Network Services

1  Public StaticString Getnetworktypename (context context) {2      if(Context! =NULL) {3Connectivitymanager connectmgr =(Connectivitymanager) Context.getsystemservice (context.connectivity_service);4           if(Connectmgr! =NULL) {5Networkinfo info =connectmgr.getactivenetworkinfo ();6                   if(Info! =NULL) {7                        Switch(Info.gettype ()) {8                              CaseConnectivitymanager.type_wifi:9                                   return"WIFI";Ten                              CaseConnectivitymanager.type_mobile: One                                   returnGetnetworktypename (Info.getsubtype ()); A                        } -                   } -           } the      } -      returnGetnetworktypename (telephonymanager.network_type_unknown); -}

Network model

1  Public StaticString Getnetworktypename (inttype) {2      Switch(type) {3            CaseTelephonymanager.network_type_gprs:4                return"GPRS";5            CaseTelephonymanager.network_type_edge:6                return"EDGE";7            CaseTelephonymanager.network_type_umts:8                return"UMTS";9            CaseTELEPHONYMANAGER.NETWORK_TYPE_HSDPA:Ten                return"HSDPA"; One            CaseTelephonymanager.network_type_hsupa: A                return"HSUPA"; -            CaseTelephonymanager.network_type_hspa: -                return"HSPA"; the            CaseTELEPHONYMANAGER.NETWORK_TYPE_CDMA: -                return"CDMA"; -            Casetelephonymanager.network_type_evdo_0: -                return"Cdma-evdo Rev. 0"; +            Casetelephonymanager.network_type_evdo_a: -                return"Cdma-evdo Rev. A; +            CaseTelephonymanager.network_type_evdo_b: A                return"Cdma-evdo Rev. B"; at            CaseTelephonymanager.network_type_1xrtt: -                return"Cdma-1xrtt"; -            CaseTelephonymanager.network_type_lte: -                return"LTE"; -            CaseTELEPHONYMANAGER.NETWORK_TYPE_EHRPD: -                return"CDMA-EHRPD"; in            CaseTelephonymanager.network_type_iden: -                return"IDEN"; to            CaseTELEPHONYMANAGER.NETWORK_TYPE_HSPAP: +                return"Hspa+"; -           default: the                return"UNKNOWN"; *      } $}


1 @Override2      Public voidOnClick (view view) {3         //TODO auto-generated Method Stub4         Switch(View.getid ()) {5 type =getnetworktypename (context);7              if(type!=NULL){8                  if(Type.equals ("GPRS") | | type.equals ("EGDE") )9Type = "2G";Ten                  Else      if(Type.equals ("CDMA")) OneType = "Telecom 2G"; A                  Else if(Type.equals ("EVDO")) -Type = "Telecom 3G"; -                  Else if(Type.equals ("LTE")) theType = "Telecom 4G"; -                  Else if(Type.equals ("HSDPA") | | Type.equals ("UMTS")  ) -Type = "3G";  -                   +              } - btn_main.settext (type); +              Break; A}


Mobile or Unicom 3G for UMTS or HSDPA, mobile and Unicom 2G for GPRS or EGDE, telecom 2G for CDMA, telecom 3G for EVDO, telecom 4G LTE

Android Get network type name 2G 3G 4G wifi

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: 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.