Android Network Monitoring

Source: Internet
Author: User
Public class networkcheck {/*** network availability */public static Boolean isnetworkavailable (context) {connectivitymanager connectivity = (connectivitymanager) context. getsystemservice (context. connectivity_service); If (connectivity = NULL) {} else {networkinfo [] info = connectivity. getallnetworkinfo (); If (info! = NULL) {for (INT I = 0; I <info. length; I ++) {If (info [I]. getstate () = networkinfo. state. connected) {return true ;}}} return false;}/*** whether WiFi is enabled */public static Boolean iswifienabled (context) {connectivitymanager mgrconn = (connectivitymanager) context. getsystemservice (context. connectivity_service); telephonymanager mgrtel = (telephonymanager) context. getsystemservice (cont Ext. telephony_service); Return (mgrconn. getactivenetworkinfo ()! = NULL & mgrconn. getactivenetworkinfo (). getstate () = networkinfo. state. connected) | mgrtel. getnetworktype () = telephonymanager. network_type_umts);}/*** determines whether the current network is a Wi-Fi network * If (activenetinfo. getType () = connectivitymanager. type_mobile) {// determine the 3G network ** @ Param context * @ return Boolean */public static Boolean iswifi (context) {connectivitymanager = (connectivitymanager) Context. getsystemservice (context. connectivity_service); networkinfo activenetinfo = connectivitymanager. getactivenetworkinfo (); If (activenetinfo! = NULL & activenetinfo. getType () = connectivitymanager. type_wifi) {return true;} return false;}/*** determine whether the current network is a 3G network ** @ Param context * @ return Boolean */public static Boolean is3g (context) {connectivitymanager = (connectivitymanager) context. getsystemservice (context. connectivity_service); networkinfo activenetinfo = connectivitymanager. getactivenetworkinfo (); I F (activenetinfo! = NULL & activenetinfo. GetType () = connectivitymanager. type_mobile) {return true ;} return false ;}}

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.