Android Development Get network status collation:
1 Packagecom.gzcivil.utils;2 3 ImportAndroid.content.Context;4 ImportAndroid.net.ConnectivityManager;5 ImportAndroid.net.NetworkInfo;6 ImportAndroid.telephony.TelephonyManager;7 Importandroid.text.TextUtils;8 9 Public classNetworkutils {Ten One /**No network*/ A Public Static Final intNetworktype_invalid = 0; - /**WAP Network*/ - Public Static Final intNetworktype_wap = 1; the /**2G Network*/ - Public Static Final intNETWORKTYPE_2G = 2; - /**networks above 3G and 3G, or collectively known as fast networks*/ - Public Static Final intNETWORKTYPE_3G = 3; + /**USB Network*/ - Public Static Final intNETWORKTYPE_USB = 4; + /**WiFi internet*/ A Public Static Final intNetworktype_wifi = 5; at - /** - * Get network status, wifi,wap,2g,3g. - * - * @paramContext - * Context in * @returnint network Status {@link#NETWORKTYPE_2G},{@link#NETWORKTYPE_3G}, * - * {@link#NETWORKTYPE_INVALID},{@link#NETWORKTYPE_WAP}* to * <p> + * {@link#NETWORKTYPE_WIFI} - */ the Public Static intGetnetworktype (Context context) { *Connectivitymanager Manager =(Connectivitymanager) Context.getsystemservice (context.connectivity_service); $Networkinfo Networkinfo =manager.getactivenetworkinfo ();Panax Notoginseng intMnetworktype = 0; - if(Networkinfo! =NULL&&networkinfo.isconnected ()) { theString type =networkinfo.gettypename (); + if(Type.equalsignorecase ("WIFI")) { AMnetworktype =Networktype_wifi; the}Else if(Type.equalsignorecase ("USB")) { +Mnetworktype =Networktype_usb; -}Else if(Type.equalsignorecase ("MOBILE")) { $@SuppressWarnings ("Deprecation") $String ProxyHost =android.net.Proxy.getDefaultHost (); -Mnetworktype = Textutils.isempty (proxyhost)? (Isfastmobilenetwork (context)?)networktype_3g:networktype_2g): Networktype_wap; - } the}Else { -Mnetworktype =Networktype_invalid;Wuyi } the returnMnetworktype; - } Wu - Private Static BooleanIsfastmobilenetwork (Context context) { AboutTelephonymanager Telephonymanager =(Telephonymanager) Context.getsystemservice (context.telephony_service); $ Switch(Telephonymanager.getnetworktype ()) { - CaseTelephonymanager.network_type_1xrtt: - return false;//~ 50-100 kbps - CaseTELEPHONYMANAGER.NETWORK_TYPE_CDMA: A return false;//~ 14-64 kbps + CaseTelephonymanager.network_type_edge: the return false;//~ 50-100 kbps - Casetelephonymanager.network_type_evdo_0: $ return true;//~ 400-1000 kbps the Casetelephonymanager.network_type_evdo_a: the return true;//~ 600-1400 kbps the CaseTelephonymanager.network_type_gprs: the return false;//~ kbps - CaseTELEPHONYMANAGER.NETWORK_TYPE_HSDPA: in return true;//~ 2-14 Mbps the CaseTelephonymanager.network_type_hspa: the return true;//~ 700-1700 kbps About CaseTelephonymanager.network_type_hsupa: the return true;//~ 1-23 Mbps the CaseTelephonymanager.network_type_umts: the return true;//~ 400-7000 kbps + CaseTELEPHONYMANAGER.NETWORK_TYPE_EHRPD: - return true;//~ 1-2 Mbps the CaseTelephonymanager.network_type_evdo_b:Bayi return true;//~ 5 Mbps the CaseTELEPHONYMANAGER.NETWORK_TYPE_HSPAP: the return true;//~ 10-20 Mbps - CaseTelephonymanager.network_type_iden: - return false;//~25 kbps the CaseTelephonymanager.network_type_lte: the return true;//~ + Mbps the CaseTelephonymanager.network_type_unknown: the return false; - default: the return false; the } the }94}
Android Development Get network status, wifi,wap,2g,3g. Tool Class (i)