Android gets the network status of the mobile phone

Source: Internet
Author: User

In Android development, many of my friends may determine the network type of the mobile phone, because the current Android mobile phone may be in a 4-digit status.
1. No network (this status may be due to the shutdown of the mobile phone, the network is not enabled, and the signal is poor)

2. Use wifi to access the Internet

3. cmwap (China Mobile proxy)

4. access the Internet through cmnet

If there is no network in these four statuses, you must be unable to request the Internet. If it is WAP, you need to add a China Mobile proxy for your mobile phone. For details about adding a China Mobile proxy for your mobile phone, please go
Http://blog.csdn.net/vipa1888/article/details/7004883 here write an example about adding China Mobile Agent!

The following is a network judgment method:

/*** @ Author spring sky * Email vipa1888@163.com * QQ: 840950105 my name: Shi mingzheng * Get the current network status-1: No network 1: WiFi network 2: WAP network 3: Net network * @ Param context * @ return */public static int getapntype (context) {int nettype =-1; connectivitymanager connmgr = (connectivitymanager) context. getsystemservice (context. connectivity_service); networkinfo = connmgr. getactivenetworkinfo (); If (networkinfo = NULL) {return nettype;} int ntype = networkinfo. getType (); If (ntype = connectivitymanager. type_mobile) {log. E ("networkinfo. getextrainfo () "," networkinfo. getextrainfo () is "+ networkinfo. getextrainfo (); If (networkinfo. getextrainfo (). tolowercase (). equals ("cmnet") {nettype = cmnet;} else {nettype = cmwap;} else if (ntype = connectivitymanager. type_wifi) {nettype = WiFi;} return nettype ;}

Because the service object is obtained, the network status is refreshed from time to time, so we only need to get the network status!

I hope to share my learning experience with you!

 

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.