Android network status judging WiFi mobile

Source: Internet
Author: User

/**
* Network Status WiFi Mobile
*
* @author jiangbing
*
*/
public class Networkutils {
/**
* Determine if the current network connection (valid connection) is not divided into WiFi mobile
*/
public static Boolean isconnectdeavailable (context context) {
try {
Connectivitymanager manager = (Connectivitymanager) context
. Getsystemservice (Context.connectivity_service);
if (manager! = null) {
Networkinfo networkinfo = Manager.getactivenetworkinfo ();
if (networkinfo! = null && networkinfo.isconnected ()) {
if (networkinfo.getstate () = = NetworkInfo.State.CONNECTED) {
return true;
}
}
}
} catch (Exception e) {
return false;
}
return false;
}

/**
* Determine if the current WiFi network
*/
public static Boolean ISWIFICONNECTDE (context context) {
Connectivitymanager manager = (Connectivitymanager) context
. Getsystemservice (Context.connectivity_service);
if (manager! = null) {
Networkinfo Networkinfo = Manager
. Getnetworkinfo (Connectivitymanager.type_wifi);
if (networkinfo! = null && networkinfo.isconnected ()) {
return true;
}
}
return false;
}

/**
* Determine whether the current WiFi network (whether the connection is valid)
*/
public static Boolean iswificonnectdeavailable (context context) {
Connectivitymanager manager = (Connectivitymanager) context
. Getsystemservice (Context.connectivity_service);
if (manager! = null) {
Networkinfo Networkinfo = Manager
. Getnetworkinfo (Connectivitymanager.type_wifi);
if (networkinfo! = null && networkinfo.isconnected ()) {
if (networkinfo.getstate () = = NetworkInfo.State.CONNECTED) {
return true;
}
}
}
return false;
}

/**
* Determine if the current network is moving the network
*
* @param context
* @return Boolean
*/
public static Boolean ISMOBILECONNECTDE (context context) {
Connectivitymanager manager = (Connectivitymanager) context
. Getsystemservice (Context.connectivity_service);
if (manager! = null) {
Networkinfo Networkinfo = Manager
. Getnetworkinfo (Connectivitymanager.type_mobile);
if (networkinfo! = null && networkinfo.isconnected ()) {
return true;
}
}
return false;
}

/**
* Determine if the current network is moving the network (whether the connection is valid)
*
* @param context
* @return Boolean
*/
public static Boolean ismobileconnectdeavailable (context context) {
Connectivitymanager manager = (Connectivitymanager) context
. Getsystemservice (Context.connectivity_service);
if (manager! = null) {
Networkinfo Networkinfo = Manager
. Getnetworkinfo (Connectivitymanager.type_mobile);
if (networkinfo! = null && networkinfo.isconnected ()) {
if (networkinfo.getstate () = = NetworkInfo.State.CONNECTED) {
return true;
}
}
}
return false;
}

/**
* Open the Network Settings screen
*/
public static void opensetting (activity activity) {
Intent Intent = new Intent ("/");
ComponentName cm = new ComponentName ("Com.android.settings",
"Com.android.settings.WirelessSettings");
Intent.setcomponent (CM);
Intent.setaction ("Android.intent.action.VIEW");
Activity.startactivityforresult (Intent, 0);
}

/**
* Whether the GPS is turned on
*
* @param context
* @return
*/
public static Boolean isgpsenabled (context context) {
Locationmanager Locationmanager = ((Locationmanager) context
. Getsystemservice (Context.location_service));
list<string> accessibleproviders = Locationmanager.getproviders (true);
return accessibleproviders! = null && accessibleproviders.size () > 0;
}
}

Android network status judging WiFi mobile

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.