Public Code Reference (Connectivitymanager)

Source: Internet
Author: User

 PackageCom.fredric.util;ImportAndroid.content.Context;ImportAndroid.net.ConnectivityManager;ImportAndroid.net.NetworkInfo;Importandroid.net.NetworkInfo.State;/*-* Network Tool class*/ Public classNetUtils {//determine if the network is connected     Public Static Booleanisconnected (Context context) {Connectivitymanager Connectivity=(Connectivitymanager) context. Getsystemservice (Context.connectivity_service); //five states of WLAN//1, show that the connection has been saved, but the title bar does not, that is, no physical connection on the output as: Not Connect, available//2, show the connection is saved, the title bar also has a connected icon, the output is: Connect, available//3, select Do not save after output as: Not Connect, available//4, select connection, output when acquiring IP address: Not connect, not available//5. After connection, the output is: Connect, available        if(NULL!=connectivity) {Networkinfo Info=Connectivity.getactivenetworkinfo (); if(NULL! = Info &&info.isconnected ()) {                return true; }        }                return false; }        //determine if the WiFi connection     Public Static BooleanIswificonnect (Context context) {Connectivitymanager Connectivity=(Connectivitymanager) context. Getsystemservice (Context.connectivity_service); if(NULL!=connectivity) { State State=connectivity. Getnetworkinfo (Connectivitymanager.type_wifi). GetState (); if(state = =state.connected) {                return true; }        }                return false; }        //determine if GPRS is connected     Public Static BooleanIsgprsconnect (Context context) {Connectivitymanager Connectivity=(Connectivitymanager) context. Getsystemservice (Context.connectivity_service); if(NULL!=connectivity) { State State=connectivity. Getnetworkinfo (Connectivitymanager.type_mobile). GetState (); if(state = =state.connected) {                return true; }        }                return false; }}

Public Code Reference (Connectivitymanager)

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.