Android Network type determination (2g, 3G, WiFi)

Source: Internet
Author: User

From: http://blog.csdn.net/xxxsz/article/details/8199031

Determine whether the network type is WiFi, 3G, or 2G network, and perform different processing on different networks. Now we will sort out the judgment methods for your reference: I have tested the data Mobile 2g, China Unicom 2g, China Unicom 3G, and WiFi used below. Currently, I have no telecom card, so I have not verified it. I have a colleague from China Telecom mobile phone, you can verify the result and send it to you. Connectivitymanager connectmgr = (connectivitymanager) This. getsystemservice (context. connectivity_service); networkinfo info = connectmgr. getactivenetworkinfo (); 1. Determine whether the network is WiFi. before determining whether the network is WiFi, you must perform a non-null judgment. If no network connection is available, info = nullinfo. getType () = connectivitymanager. type_wifi 2. Determine if it is a mobile phone network info! = NULL & info. getType () = connectivitymanager. type_mobile phone network: info. getsubtype () Here getsubtype () is used, instead of GetType (), GetType () returns 0, or 1, which indicates whether it is a mobile phone network or WiFi info. the getsubtype () Value List is as follows: * network_type_cdma network type: CDMA * network_type_edge network type: edge * Listen network type: evdo0 * Listen network type: evdoa * network_type_gprs network type: GPRS * network_type_hsdpa network type: HSDPA * network_type_hspa network type for HSPA * network_type_hsupa, the network type is hsupa * network_type_umts, and the 3G network type of UMTS Unicom is UMTS or HSDPA, 2g of China Mobile and China Unicom is GPRS or edge, 2g of China Telecom is CDMA, and 3g of China Telecom is evdo
Related Article

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.